feat(pi): support Agent runtime export in pi_embedded backend
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user