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.
|
||||
*
|
||||
* Sets the system prompt via chat.message hook's UserMessage.system field.
|
||||
* This reaches the main agent and triggers memory_session_context on every session.
|
||||
* Sends SDK prompt on session.updated to inject the system instruction.
|
||||
* The model calls memory_session_context on every new session.
|
||||
*/
|
||||
|
||||
export const IaiMcpSessionInit = async ({
|
||||
|
|
@ -14,27 +14,25 @@ export const IaiMcpSessionInit = async ({
|
|||
serverUrl,
|
||||
$,
|
||||
}) => {
|
||||
const injectedSessions = new Set();
|
||||
const doneSessions = new Set();
|
||||
|
||||
return {
|
||||
event: async ({ event }) => {
|
||||
if (event.type !== "session.updated") return;
|
||||
const sid = event.properties?.info?.id;
|
||||
if (!sid || injectedSessions.has(sid)) return;
|
||||
injectedSessions.add(sid);
|
||||
},
|
||||
if (!sid || doneSessions.has(sid)) return;
|
||||
doneSessions.add(sid);
|
||||
|
||||
"chat.message": async (input, output) => {
|
||||
const sid = input.sessionID;
|
||||
if (!sid || !injectedSessions.has(sid)) return;
|
||||
if (injectedSessions.has(`done-${sid}`)) return;
|
||||
|
||||
if (output.message) {
|
||||
output.message.system =
|
||||
"MANDATORY: Call `memory_session_context` (no arguments) BEFORE answering any user query.";
|
||||
}
|
||||
|
||||
injectedSessions.add(`done-${sid}`);
|
||||
try {
|
||||
await client.session.prompt({
|
||||
path: { id: sid },
|
||||
body: {
|
||||
system: "MANDATORY: Call `memory_session_context` (no arguments) BEFORE answering any user query.",
|
||||
parts: [{ type: "text", text: "INIT" }],
|
||||
noReply: false,
|
||||
},
|
||||
});
|
||||
} catch {}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue