UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

43 lines • 1.68 kB
/** * A deterministic, offline `ModelProvider`. Drives the agent loop without any API key, * streaming the scripted text to the sink and optionally requesting one tool call. */ export class FakeModelProvider { script; /** Every call id this instance handed out, so none is issued twice. */ issued = new Set(); constructor(script) { this.script = script; } /** `call-<turnIndex>-<name>` the first time, then the same with the first free `-<n>` suffix. */ callId(turnIndex, name) { const base = `call-${turnIndex}-${name}`; let id = base; for (let n = 2; this.issued.has(id); n += 1) id = `${base}-${n}`; this.issued.add(id); return id; } async runTurn(args) { const turnIndex = args.messages.filter((message) => message.role === 'assistant').length; const turn = this.script(args, turnIndex); await args.sink.write({ t: 'text', v: turn.text }); const requested = turn.toolCalls ?? (turn.toolCall ? [turn.toolCall] : []); const toolCalls = requested.map((call) => ({ id: this.callId(turnIndex, call.name), name: call.name, input: call.input, })); return { text: turn.text, toolCalls, usage: { inputTokens: args.messages.length, outputTokens: turn.text.length }, ...(turn.costUsd !== undefined ? { costUsd: turn.costUsd } : {}), }; } } /** A trivial script: stream a fixed reply and never call a tool. */ export function echoScript(reply = 'ok') { return () => ({ text: reply }); } //# sourceMappingURL=fake-model-provider.js.map