feat(pi): support Agent runtime export in pi_embedded backend

This commit is contained in:
William Valentin
2026-02-23 21:59:51 -08:00
parent 559fe61168
commit e8204f5d42
2 changed files with 225 additions and 27 deletions
+29 -1
View File
@@ -66,7 +66,35 @@ describe('PiEmbeddedBackend', () => {
try {
const backend = new PiEmbeddedBackend({ module: mod.moduleUrl, timeoutMs: 2000 });
await expect(backend.process({ prompt: 'hello', history: [] }))
.rejects.toThrow('supported session factory');
.rejects.toThrow('supported runtime API');
} finally {
mod.cleanup();
}
});
it('uses Agent class runtime when session factory exports are absent', async () => {
const mod = createModule(`
export class Agent {
constructor() {
this.state = { messages: [] };
}
replaceMessages(messages) {
this.state.messages = messages.slice();
}
async prompt(input) {
this.state.messages.push({ role: "user", content: [{ type: "text", text: input }] });
this.state.messages.push({ role: "assistant", content: [{ type: "text", text: "agent says: " + input }] });
}
}
`);
try {
const backend = new PiEmbeddedBackend({ module: mod.moduleUrl, timeoutMs: 2000 });
const result = await backend.process({
prompt: 'hello',
history: [{ role: 'assistant', content: 'previous answer' }],
});
expect(result).toBe('agent says: hello');
} finally {
mod.cleanup();
}