Files
template-app/modules/agent/__tests__/plan-model.ts
T
2026-11-14 09:56:45 +00:00

36 lines
1.4 KiB
TypeScript

// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
// Follow the offered step using a public gateway adapter with an in-process transport.
// No network/provider call and no SDK-private or transitive TanStack testing import.
import { conusaiText } from "@conusai-sdk/ai/tanstack"
export function planFollower() {
return conusaiText("scripted-agent-test", {
apiUrl: "https://gateway.example.invalid/api",
token: "synthetic-test-token",
maxRetries: 0,
fetch: async (_input, init) => {
const body = JSON.parse(String(init?.body ?? "{}")) as { tool_choice?: { function?: { name?: string } } }
const step = body.tool_choice?.function?.name
const delta =
step === undefined
? { role: "assistant", content: "Done." }
: {
role: "assistant",
tool_calls: [
{ index: 0, id: `call-${step}`, type: "function", function: { name: step, arguments: "{}" } },
],
}
const chunk = {
id: "synthetic-completion",
object: "chat.completion.chunk",
created: 1,
model: "scripted-agent-test",
choices: [{ index: 0, delta, finish_reason: step === undefined ? "stop" : "tool_calls" }],
}
return new Response(`data: ${JSON.stringify(chunk)}\n\ndata: [DONE]\n\n`, {
headers: { "content-type": "text/event-stream" },
})
},
})
}