feat(runtime): forward Flynn prompt to pi and harden backend mode commands

This commit is contained in:
William Valentin
2026-02-24 10:41:27 -08:00
parent 4188c68130
commit 2e192ef407
9 changed files with 305 additions and 6 deletions
+77
View File
@@ -60,6 +60,54 @@ describe('PiEmbeddedBackend', () => {
}
});
it('injects Flynn system prompt fields into session payload in hybrid mode', async () => {
const mod = createModule(`
export function createAgentSession() {
return {
run(payload) {
return { text: payload.systemPrompt ?? payload.system ?? "missing" };
},
};
}
`);
try {
const backend = new PiEmbeddedBackend({ module: mod.moduleUrl, timeoutMs: 2000, systemPromptMode: 'hybrid' });
const result = await backend.process({
prompt: 'hello',
history: [],
systemPrompt: 'SOUL + IDENTITY + USER + TOOLS',
});
expect(result).toBe('SOUL + IDENTITY + USER + TOOLS');
} finally {
mod.cleanup();
}
});
it('omits Flynn system prompt injection in pi_default mode', async () => {
const mod = createModule(`
export function createAgentSession() {
return {
run(payload) {
return { text: payload.systemPrompt ? "present" : "absent" };
},
};
}
`);
try {
const backend = new PiEmbeddedBackend({ module: mod.moduleUrl, timeoutMs: 2000, systemPromptMode: 'pi_default' });
const result = await backend.process({
prompt: 'hello',
history: [],
systemPrompt: 'should not be forwarded',
});
expect(result).toBe('absent');
} finally {
mod.cleanup();
}
});
it('throws when module has no supported session factory', async () => {
const mod = createModule('export const version = "0.0.0";');
@@ -100,6 +148,35 @@ describe('PiEmbeddedBackend', () => {
}
});
it('applies Flynn system prompt in Agent runtime via setSystemPrompt()', async () => {
const mod = createModule(`
export class Agent {
constructor() {
this.systemPrompt = "";
this.state = { messages: [] };
}
setSystemPrompt(prompt) {
this.systemPrompt = prompt;
}
async prompt(input) {
this.state.messages.push({ role: "assistant", content: [{ type: "text", text: this.systemPrompt + " :: " + input }] });
}
}
`);
try {
const backend = new PiEmbeddedBackend({ module: mod.moduleUrl, timeoutMs: 2000, systemPromptMode: 'flynn' });
const result = await backend.process({
prompt: 'hello',
history: [],
systemPrompt: 'use flynn prompt',
});
expect(result).toBe('use flynn prompt :: hello');
} finally {
mod.cleanup();
}
});
it('surfaces agent state error when no assistant text is produced', async () => {
const mod = createModule(`
export class Agent {