commit bcf46c759145c96c2235f02e1c8dcb0abb1501d1
parent 34317cfc06852a72609ebfe8801ad4a1e45e9dbf
Author: Henry Unite <unitehenry@gmail.com>
Date: Thu, 26 Feb 2026 08:45:25 +0000
refactor: prompt
Diffstat:
4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/app.ts b/app.ts
@@ -1,9 +1,8 @@
-import express, { type Request, type Response } from "express";
+import express from 'express';
import log from "./log.ts";
import message from './message.ts';
import voice from './voice.ts';
import health from './health.ts';
-import { prompt } from "./prompt.ts";
const app = express();
diff --git a/message.ts b/message.ts
@@ -1,5 +1,5 @@
import { type Request, type Response } from "express";
-import { prompt } from './prompt.ts';
+import prompt from './prompt.ts';
import log from './log.ts';
function buildResponse(message: string): string {
@@ -23,7 +23,7 @@ export default async (req: Request, res: Response): Promise<void> => {
log("INFO", "User message received", { messageResult });
- const { sessionId, text } = await prompt(messageResult, null);
+ const { sessionId, text } = await prompt({ message: messageResult });
log("INFO", "Agent responded", { sessionId, text });
diff --git a/prompt.ts b/prompt.ts
@@ -6,12 +6,16 @@ interface PromptResult {
text: string;
}
-export async function prompt(
+interface PromptParams {
message: string,
- sessionId: string | null,
-): Promise<PromptResult> {
+ sessionId?: string
+}
+
+export default async (params : PromptParams): Promise<PromptResult> => {
const baseUrl = "http://127.0.0.1:36967";
+ const { message, sessionId } = params;
+
log("INFO", "Prompting agent", { sessionId, baseUrl, message });
const client = createOpencodeClient({ baseUrl });
diff --git a/voice.ts b/voice.ts
@@ -1,5 +1,5 @@
import { type Request, type Response } from "express";
-import { prompt } from './prompt.ts';
+import prompt from './prompt.ts';
import log from './log.ts';
function buildResponse(message : string) : string {
@@ -35,10 +35,10 @@ export default async (req: Request, res: Response): Promise<void> => {
log("INFO", "Caller message received", { callId, speechResult });
- const { sessionId, text } = await prompt(
- speechResult,
- app.get(callId) as string | null,
- );
+ const { sessionId, text } = await prompt({
+ message: speechResult,
+ sessionId: app.get(callId) as string | null,
+ });
log("INFO", "Agent responded", { callId, sessionId, text });