commit 9116735997714bc3e35fe9483e7d2b1a36a6cf61
parent 409361dfcb98341e6b4bea1094dffb35e4a34289
Author: Henry Unite <unitehenry@gmail.com>
Date: Thu, 26 Feb 2026 07:55:38 +0000
refactor: prompt
Diffstat:
3 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/app.ts b/app.ts
@@ -1,51 +1,10 @@
-import { createOpencodeClient } from "@opencode-ai/sdk";
import express, { type Request, type Response } from "express";
+import { prompt } from './prompt.ts';
const app = express();
app.use(express.urlencoded());
-interface PromptResult {
- sessionId: string;
- text: string;
-}
-
-async function prompt(
- message: string,
- sessionId: string | null,
-): Promise<PromptResult> {
- console.log(`Session ID Param: ${sessionId}`);
-
- const client = createOpencodeClient({
- baseUrl: "http://127.0.0.1:36967",
- });
-
- const id: string = await (async (): Promise<string> => {
- if (sessionId) {
- return sessionId;
- }
-
- const sessionResult = await client.session.create();
-
- return sessionResult.data.id;
- })();
-
- console.log(`Session ID: ${id}`);
-
- const result = await client.session.prompt({
- path: { id },
- body: {
- parts: [{ type: "text", text: message }],
- },
- });
-
- const text: string = result.data.parts
- .filter((part) => part.type === "text")
- .reduce((response: string, part) => response + " " + part.text, "");
-
- return { sessionId: id, text };
-}
-
function agentResponse(res: Response, message: string): void {
res.set("Content-Type", "text/xml");
diff --git a/prompt.ts b/prompt.ts
@@ -0,0 +1,42 @@
+import { createOpencodeClient } from "@opencode-ai/sdk";
+
+interface PromptResult {
+ sessionId: string;
+ text: string;
+}
+
+export async function prompt(
+ message: string,
+ sessionId: string | null,
+): Promise<PromptResult> {
+ console.log(`Session ID Param: ${sessionId}`);
+
+ const client = createOpencodeClient({
+ baseUrl: "http://127.0.0.1:36967",
+ });
+
+ const id: string = await (async (): Promise<string> => {
+ if (sessionId) {
+ return sessionId;
+ }
+
+ const sessionResult = await client.session.create();
+
+ return sessionResult.data.id;
+ })();
+
+ console.log(`Session ID: ${id}`);
+
+ const result = await client.session.prompt({
+ path: { id },
+ body: {
+ parts: [{ type: "text", text: message }],
+ },
+ });
+
+ const text: string = result.data.parts
+ .filter((part) => part.type === "text")
+ .reduce((response: string, part) => response + " " + part.text, "");
+
+ return { sessionId: id, text };
+}
diff --git a/scripts/typecheck.sh b/scripts/typecheck.sh
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
-npx tsc --noEmit --target ES2022 --module NodeNext *.ts
+npx tsc --allowImportingTsExtensions --noEmit --target ES2022 --module NodeNext *.ts