Simplify session-init: only send SDK prompt, accept session title tradeoff
This commit is contained in:
parent
87c43219d7
commit
a6d6e46b4c
1 changed files with 15 additions and 17 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* iai-mcp session-init plugin for OpenCode.
|
* iai-mcp session-init plugin for OpenCode.
|
||||||
*
|
*
|
||||||
* Sets the system prompt via chat.message hook's UserMessage.system field.
|
* Sends SDK prompt on session.updated to inject the system instruction.
|
||||||
* This reaches the main agent and triggers memory_session_context on every session.
|
* The model calls memory_session_context on every new session.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const IaiMcpSessionInit = async ({
|
export const IaiMcpSessionInit = async ({
|
||||||
|
|
@ -14,27 +14,25 @@ export const IaiMcpSessionInit = async ({
|
||||||
serverUrl,
|
serverUrl,
|
||||||
$,
|
$,
|
||||||
}) => {
|
}) => {
|
||||||
const injectedSessions = new Set();
|
const doneSessions = new Set();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
event: async ({ event }) => {
|
event: async ({ event }) => {
|
||||||
if (event.type !== "session.updated") return;
|
if (event.type !== "session.updated") return;
|
||||||
const sid = event.properties?.info?.id;
|
const sid = event.properties?.info?.id;
|
||||||
if (!sid || injectedSessions.has(sid)) return;
|
if (!sid || doneSessions.has(sid)) return;
|
||||||
injectedSessions.add(sid);
|
doneSessions.add(sid);
|
||||||
},
|
|
||||||
|
|
||||||
"chat.message": async (input, output) => {
|
try {
|
||||||
const sid = input.sessionID;
|
await client.session.prompt({
|
||||||
if (!sid || !injectedSessions.has(sid)) return;
|
path: { id: sid },
|
||||||
if (injectedSessions.has(`done-${sid}`)) return;
|
body: {
|
||||||
|
system: "MANDATORY: Call `memory_session_context` (no arguments) BEFORE answering any user query.",
|
||||||
if (output.message) {
|
parts: [{ type: "text", text: "INIT" }],
|
||||||
output.message.system =
|
noReply: false,
|
||||||
"MANDATORY: Call `memory_session_context` (no arguments) BEFORE answering any user query.";
|
},
|
||||||
}
|
});
|
||||||
|
} catch {}
|
||||||
injectedSessions.add(`done-${sid}`);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue