feat(runtime): forward Flynn prompt to pi and harden backend mode commands
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user