@agentrouter-top/relay-dsh-plugin-codex 0.2.2-agentrouter.2 → 0.2.2-agentrouter.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTROUTER-FORK.md +1 -1
- package/docs/context-admission.md +27 -0
- package/docs/kernel-policy.md +12 -0
- package/docs/transcript-presentation.md +20 -0
- package/lib/client.js +77 -0
- package/lib/client.js.map +1 -1
- package/lib/host-plugin.js +31 -5
- package/lib/host-plugin.js.map +1 -1
- package/package.json +6 -3
package/lib/host-plugin.js
CHANGED
|
@@ -1752,6 +1752,16 @@ async function appendPersistedEvents(persistence, id, events) {
|
|
|
1752
1752
|
}
|
|
1753
1753
|
}
|
|
1754
1754
|
//#endregion
|
|
1755
|
+
//#region kernel-policy.mjs
|
|
1756
|
+
/** Execution ownership, not a model-name or provider-brand allowlist. */
|
|
1757
|
+
function assertKernelRoute(codexSession, options) {
|
|
1758
|
+
if (options.purpose) return;
|
|
1759
|
+
if (codexSession === (options.provider === "relay-codex")) return;
|
|
1760
|
+
const error = /* @__PURE__ */ new Error(codexSession ? "Codex 内核只能使用 Codex 适配器的模型。请重新选择 Codex 模型;不会忽略当前选择或自动换用其他模型。" : "当前会话不是 Codex 内核,不能使用 Codex 适配器的模型。请新建 Codex 会话。既有会话的内核不会被替换。");
|
|
1761
|
+
error.code = "CODEX_KERNEL_MODEL_MISMATCH";
|
|
1762
|
+
throw error;
|
|
1763
|
+
}
|
|
1764
|
+
//#endregion
|
|
1755
1765
|
//#region codex-activity-wire.mjs
|
|
1756
1766
|
const CODEX_ACTIVITY_TOOL = "relay_codex_activity";
|
|
1757
1767
|
//#endregion
|
|
@@ -2279,6 +2289,14 @@ var CodexDshAdapter = class extends LlmAdapter {
|
|
|
2279
2289
|
servesAgent(agent) {
|
|
2280
2290
|
return effectivePreset(agent.session) === CODEX_PRESET;
|
|
2281
2291
|
}
|
|
2292
|
+
admitStepMessages(agent, decision) {
|
|
2293
|
+
if (!this.servesAgent(agent) || decision.kind !== "enter") return decision;
|
|
2294
|
+
const messages = decision.messages.filter((message) => acceptsCodexInputSource(message.source));
|
|
2295
|
+
return messages.length === decision.messages.length ? decision : {
|
|
2296
|
+
...decision,
|
|
2297
|
+
messages
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2282
2300
|
detachAgent(sessionId) {
|
|
2283
2301
|
const key = String(sessionId);
|
|
2284
2302
|
this.agents.delete(key);
|
|
@@ -2625,6 +2643,7 @@ var CodexDshAdapter = class extends LlmAdapter {
|
|
|
2625
2643
|
return binding ? this.activeTurnSignals.get(binding.rootThreadId) : void 0;
|
|
2626
2644
|
}
|
|
2627
2645
|
async *stream(options) {
|
|
2646
|
+
assertKernelRoute(true, options);
|
|
2628
2647
|
if (options.purpose) {
|
|
2629
2648
|
yield* this.streamAuxiliary(options);
|
|
2630
2649
|
return;
|
|
@@ -2638,8 +2657,8 @@ var CodexDshAdapter = class extends LlmAdapter {
|
|
|
2638
2657
|
const events = sessionEvents(agent.session);
|
|
2639
2658
|
const nativePermissions = permissionConfiguration(events);
|
|
2640
2659
|
const config = this.configure(sessionId, {
|
|
2641
|
-
|
|
2642
|
-
|
|
2660
|
+
model: options.model,
|
|
2661
|
+
effort: options.reasoningEffort,
|
|
2643
2662
|
...nativePermissions,
|
|
2644
2663
|
cwd: agent.session.header.cwd
|
|
2645
2664
|
});
|
|
@@ -3486,7 +3505,7 @@ async function latestUserInput(messages, attachments, signal, codexHome) {
|
|
|
3486
3505
|
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
3487
3506
|
const message = messages[index];
|
|
3488
3507
|
if (message?.role !== "user") continue;
|
|
3489
|
-
if (
|
|
3508
|
+
if (!acceptsCodexInputSource(message.source)) continue;
|
|
3490
3509
|
const text = (message.content ?? []).filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
|
|
3491
3510
|
const localImages = [];
|
|
3492
3511
|
for (const block of message.content ?? []) {
|
|
@@ -3545,8 +3564,8 @@ function completeAuxiliaryItem(state, item) {
|
|
|
3545
3564
|
if (item.type === "agentMessage") return completeTextItem(state, item.id, "text", item.text ?? "");
|
|
3546
3565
|
return [];
|
|
3547
3566
|
}
|
|
3548
|
-
function
|
|
3549
|
-
return source?.kind === "plugin" && source.plugin === "relay";
|
|
3567
|
+
function acceptsCodexInputSource(source) {
|
|
3568
|
+
return source?.kind === "user" || source?.kind === "plugin" && source.plugin === "relay";
|
|
3550
3569
|
}
|
|
3551
3570
|
function compact(value) {
|
|
3552
3571
|
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0 && item !== null));
|
|
@@ -4991,11 +5010,18 @@ function createDshCodexPlugin(ctx, config = {}) {
|
|
|
4991
5010
|
defer(ctx.on("llm/stream", (options, next) => {
|
|
4992
5011
|
if (options.purpose || !options.sessionId) return next();
|
|
4993
5012
|
const agent = ctx.agents.get(options.sessionId);
|
|
5013
|
+
if (agent) assertKernelRoute(adapter.servesAgent(agent), options);
|
|
4994
5014
|
return agent && adapter.servesAgent(agent) ? adapter.stream(options) : next();
|
|
4995
5015
|
}, {
|
|
4996
5016
|
global: true,
|
|
4997
5017
|
prepend: true
|
|
4998
5018
|
}));
|
|
5019
|
+
defer(ctx.on("agent/pre-step", async ({ agent }, next) => {
|
|
5020
|
+
return adapter.admitStepMessages(agent, await next());
|
|
5021
|
+
}, {
|
|
5022
|
+
global: true,
|
|
5023
|
+
prepend: true
|
|
5024
|
+
}));
|
|
4999
5025
|
defer(ctx.on("agent/created", ({ agent }) => {
|
|
5000
5026
|
adapter.attachAgent(agent);
|
|
5001
5027
|
}));
|