@mininglamp-oss/octo-runtime 1.1.10 → 1.1.11
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/README.md +1 -1
- package/apps/cli/README.md +1 -1
- package/apps/cli/dist/adapters.js +40 -14
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/command-tree.js +2 -3
- package/apps/cli/dist/extras.js +11 -1
- package/apps/cli/dist/index.js +14 -1
- package/apps/cli/dist/main.js +58 -23
- package/apps/cli/dist/module-manifest.js +21 -3
- package/apps/cli/dist/output.d.ts +19 -1
- package/apps/cli/dist/output.js +179 -27
- package/apps/cli/dist/playboard.js +2 -2
- package/apps/cli/dist/state.d.ts +5 -2
- package/apps/cli/dist/state.js +48 -13
- package/dist/public/codex.d.ts +1 -0
- package/dist/public/codex.js +1 -0
- package/dist/public/executor-kernel.d.ts +4 -0
- package/dist/public/executor-kernel.js +2 -0
- package/dist/public/extra.d.ts +1 -1
- package/dist/public/host.d.ts +5 -0
- package/dist/public/host.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +20 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +68 -253
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +11 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +198 -52
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +58 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +650 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/stdin-writer.js +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +25 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +40 -14
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/command-tree.js +2 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/extras.js +11 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/index.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +58 -23
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/module-manifest.js +21 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +19 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +179 -27
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/state.js +48 -13
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +23 -23
- package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.d.ts +30 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/async-question-reply.js +199 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/browser.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +465 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/index.js +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/internal.js +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.d.ts +59 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/invocation-lifecycle.js +287 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/notification.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/protocol.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.d.ts +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/runtime-path.js +138 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.d.ts +8 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-catalog.js +65 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.d.ts +82 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/startup-diagnostics.js +371 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.d.ts +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/submission-error.js +23 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.d.ts +72 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/dist/types.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +54 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +1219 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +5988 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +56 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc-fixtures.json +53 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +538 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +116 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +4525 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +761 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +663 -0
- package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +191 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +26 -18
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +151 -11
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.d.ts +1 -30
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js +2 -199
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.d.ts +1 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/client.js +2 -446
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/endpoint.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/host-run-service.js +13 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.d.ts +1 -53
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -280
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.d.ts +5 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/lifecycle.js +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.d.ts +20 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/runtime-home.js +180 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +31 -8
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/service.js +48 -5
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-catalog.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-diagnostics.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/startup-logging.js +18 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +1 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +2 -23
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.d.ts +2 -72
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/types.js +2 -10
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/extra.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/ports.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/extra.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/ports.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/index.js +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/endpoint.js +12 -5
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/errors.js +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.d.ts +44 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/execution.js +207 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +23 -3
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.d.ts +27 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-service.js +133 -25
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.d.ts +10 -3
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extras.js +18 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.d.ts +5 -6
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +33 -45
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/identity.js +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/index.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +5 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +19 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +65 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +33 -27
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +42 -0
package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/async-question-reply.js
CHANGED
|
@@ -1,199 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { KernelError } from "./types.js";
|
|
4
|
-
/**
|
|
5
|
-
* 宿主持有的一份旁路问题控制者,不拥有 Kernel 或数据库。
|
|
6
|
-
* 活动时 steer,确认正常完成后复用 invoke;宿主须串行管理同会话、
|
|
7
|
-
* 保存提交状态并消费新 Run 尾流。新流返回不代表 Provider 接纳。
|
|
8
|
-
*/
|
|
9
|
-
export class AsyncQuestionReply {
|
|
10
|
-
client;
|
|
11
|
-
continuation;
|
|
12
|
-
environment;
|
|
13
|
-
#snapshot;
|
|
14
|
-
constructor(client, snapshot, continuation, environment) {
|
|
15
|
-
this.client = client;
|
|
16
|
-
this.continuation = continuation;
|
|
17
|
-
this.environment = environment;
|
|
18
|
-
assertJsonValue(snapshot);
|
|
19
|
-
if (snapshot.schema !== "octo.async-question-reply/v1" ||
|
|
20
|
-
!["pending", "submitting", "answered", "cancelled", "invalidated", "unknown"].includes(snapshot.phase) ||
|
|
21
|
-
typeof snapshot.completed !== "boolean" ||
|
|
22
|
-
snapshot.ref.protocol_mode !== "canonical" ||
|
|
23
|
-
snapshot.ref.protocol !== "codex.app-server" ||
|
|
24
|
-
snapshot.question.delivery !== "async" ||
|
|
25
|
-
snapshot.question.kind !== "question" ||
|
|
26
|
-
snapshot.question.executionInstanceId !== snapshot.ref.invocation_id ||
|
|
27
|
-
!snapshot.providerSession.sessionId ||
|
|
28
|
-
snapshot.providerSession.resumable === false)
|
|
29
|
-
throw new KernelError("INVALID_ASYNC_QUESTION_SNAPSHOT");
|
|
30
|
-
const { kernel_instance_id, ...receipt } = snapshot.ref;
|
|
31
|
-
if (!kernel_instance_id)
|
|
32
|
-
throw new KernelError("INVALID_ASYNC_QUESTION_SNAPSHOT");
|
|
33
|
-
assertHostRunReceipt(receipt);
|
|
34
|
-
assertCanonicalEvent({
|
|
35
|
-
protocolVersion: 2,
|
|
36
|
-
type: "interaction.requested",
|
|
37
|
-
payload: snapshot.question
|
|
38
|
-
});
|
|
39
|
-
assertQuestionRequest(snapshot.question.request);
|
|
40
|
-
this.#snapshot = structuredClone(snapshot);
|
|
41
|
-
}
|
|
42
|
-
/** 独立 JSON 副本供宿主保存;恢复 submitting/unknown 不会再次投递。 */
|
|
43
|
-
snapshot() {
|
|
44
|
-
return structuredClone(this.#snapshot);
|
|
45
|
-
}
|
|
46
|
-
/** 只接受原源流事实;消息 final 或查不到 Run 不能证明正常完成。 */
|
|
47
|
-
observe(frame) {
|
|
48
|
-
assertHostFrame(frame);
|
|
49
|
-
const { kernel_instance_id: _instance, ...receipt } = this.#snapshot.ref;
|
|
50
|
-
void _instance;
|
|
51
|
-
assertHostFrameIdentity(frame, receipt);
|
|
52
|
-
if (frame.kind === "control" && frame.control.type === "state") {
|
|
53
|
-
if (frame.control.state === "completed")
|
|
54
|
-
this.#snapshot.completed = true;
|
|
55
|
-
else if (["failed", "cancelled", "lost"].includes(frame.control.state))
|
|
56
|
-
this.#snapshot.phase = "invalidated";
|
|
57
|
-
}
|
|
58
|
-
if (frame.kind === "canonical" &&
|
|
59
|
-
frame.event.type === "interaction.resolved" &&
|
|
60
|
-
frame.event.payload.interactionId === this.#snapshot.question.interactionId) {
|
|
61
|
-
const payload = frame.event.payload;
|
|
62
|
-
this.#snapshot.phase =
|
|
63
|
-
payload.reasonCode === "provider_accepted"
|
|
64
|
-
? "answered"
|
|
65
|
-
: payload.reasonCode === "submission_outcome_unknown"
|
|
66
|
-
? "unknown"
|
|
67
|
-
: "invalidated";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/** 关闭旁路,不中断模型;原活动交互同步关闭,未知响应不重试。 */
|
|
71
|
-
async cancel() {
|
|
72
|
-
this.#assertPending();
|
|
73
|
-
this.#snapshot.phase = "cancelled";
|
|
74
|
-
if (!this.#snapshot.completed) {
|
|
75
|
-
try {
|
|
76
|
-
await this.client.respond(this.#snapshot.ref, {
|
|
77
|
-
interactionId: this.#snapshot.question.interactionId,
|
|
78
|
-
outcome: "cancelled"
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
if (!(error instanceof KernelError) || error.code !== "INTERACTION_NOT_ACTIVE")
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/** 整批一次。steer 等待 Provider ACK;new_run 必须消费返回流,沿原 invoke 管理执行。 */
|
|
88
|
-
async respond(value) {
|
|
89
|
-
this.#assertPending();
|
|
90
|
-
const original = this.#snapshot;
|
|
91
|
-
assertQuestionRequest(original.question.request);
|
|
92
|
-
const answer = structuredClone(value);
|
|
93
|
-
assertQuestionResponse(answer);
|
|
94
|
-
const text = questionAnswerText(original.question.request, answer);
|
|
95
|
-
const next = structuredClone(this.continuation());
|
|
96
|
-
assertInvokeInput(next);
|
|
97
|
-
// 现有会话由宿主显式提供,旧题不能跨 reset 或 Provider binding 改投。
|
|
98
|
-
if (next.sessionId !== original.ref.agent_session_id ||
|
|
99
|
-
(next.sessionGeneration ?? 0) !== original.ref.session_generation ||
|
|
100
|
-
next.providerSession?.sessionId !== original.providerSession.sessionId ||
|
|
101
|
-
next.providerSession?.resumable === false ||
|
|
102
|
-
next.providerEpoch !== original.providerEpoch)
|
|
103
|
-
throw new KernelError("ASYNC_QUESTION_SESSION_STALE");
|
|
104
|
-
original.phase = "submitting";
|
|
105
|
-
let attempted = false;
|
|
106
|
-
try {
|
|
107
|
-
if (!original.completed) {
|
|
108
|
-
const current = await this.client.get(original.ref, original.ref.kernel_instance_id);
|
|
109
|
-
if (current.terminal)
|
|
110
|
-
this.observe(current.terminal);
|
|
111
|
-
if (this.snapshot().phase === "invalidated")
|
|
112
|
-
throw new KernelError("INTERACTION_NOT_ACTIVE");
|
|
113
|
-
}
|
|
114
|
-
if (!original.completed) {
|
|
115
|
-
attempted = true;
|
|
116
|
-
try {
|
|
117
|
-
this.#assertNotExpired();
|
|
118
|
-
await this.client.respond(original.ref, {
|
|
119
|
-
interactionId: original.question.interactionId,
|
|
120
|
-
outcome: "answered",
|
|
121
|
-
value: answer
|
|
122
|
-
});
|
|
123
|
-
original.phase = "answered";
|
|
124
|
-
return { route: "steer", acceptance: "provider_accepted" };
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
if (!(error instanceof KernelError) ||
|
|
128
|
-
!["INTERACTION_NOT_ACTIVE", "ASYNC_ANSWER_REJECTED"].includes(error.code))
|
|
129
|
-
throw error;
|
|
130
|
-
// 仅明确未接纳才可在正常终态之后续跑;ACK 丢失和写后失联绝不进入此分支。
|
|
131
|
-
attempted = false;
|
|
132
|
-
const current = await this.client.get(original.ref, original.ref.kernel_instance_id);
|
|
133
|
-
if (current.terminal)
|
|
134
|
-
this.observe(current.terminal);
|
|
135
|
-
if (!original.completed) {
|
|
136
|
-
original.phase = "invalidated";
|
|
137
|
-
throw error;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const input = {
|
|
142
|
-
...next,
|
|
143
|
-
runId: randomUUID(),
|
|
144
|
-
invocationId: randomUUID(),
|
|
145
|
-
protocol_mode: "canonical",
|
|
146
|
-
continuityMode: "continue",
|
|
147
|
-
inputs: [{ type: "text", text }],
|
|
148
|
-
prompt: text,
|
|
149
|
-
modelInput: text,
|
|
150
|
-
providerSession: { ...original.providerSession, requireResume: true },
|
|
151
|
-
freshFallbackModelInput: text,
|
|
152
|
-
freshFallbackModelInputParts: [{ type: "text", text }]
|
|
153
|
-
};
|
|
154
|
-
const client = this.client, environment = this.environment;
|
|
155
|
-
const beforeInvoke = () => {
|
|
156
|
-
this.#assertNotExpired();
|
|
157
|
-
const currentInput = this.continuation();
|
|
158
|
-
if (currentInput.sessionId !== input.sessionId ||
|
|
159
|
-
(currentInput.sessionGeneration ?? 0) !== original.ref.session_generation ||
|
|
160
|
-
currentInput.providerSession?.sessionId !== original.providerSession.sessionId ||
|
|
161
|
-
currentInput.providerEpoch !== original.providerEpoch)
|
|
162
|
-
throw new KernelError("ASYNC_QUESTION_SESSION_STALE");
|
|
163
|
-
};
|
|
164
|
-
const events = (async function* () {
|
|
165
|
-
try {
|
|
166
|
-
beforeInvoke();
|
|
167
|
-
for await (const event of client.invoke(input, environment)) {
|
|
168
|
-
if (event.type === "session.update" &&
|
|
169
|
-
event.payload.providerSession?.sessionId === original.providerSession.sessionId &&
|
|
170
|
-
event.payload.providerSession.resumeOutcome === "resumed")
|
|
171
|
-
original.phase = "answered";
|
|
172
|
-
yield event;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
finally {
|
|
176
|
-
if (original.phase === "submitting")
|
|
177
|
-
original.phase = "unknown";
|
|
178
|
-
}
|
|
179
|
-
})();
|
|
180
|
-
return { route: "new_run", input: structuredClone(input), events };
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
if (original.phase === "submitting")
|
|
184
|
-
original.phase = attempted ? "unknown" : "pending";
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
#assertPending() {
|
|
189
|
-
const snapshot = this.#snapshot;
|
|
190
|
-
if (snapshot.phase !== "pending")
|
|
191
|
-
throw new KernelError("INTERACTION_NOT_ACTIVE");
|
|
192
|
-
this.#assertNotExpired();
|
|
193
|
-
}
|
|
194
|
-
#assertNotExpired() {
|
|
195
|
-
const expiresAt = this.#snapshot.question.expiresAt;
|
|
196
|
-
if (expiresAt !== undefined && Date.parse(expiresAt) <= Date.now())
|
|
197
|
-
throw new KernelError("INTERACTION_NOT_ACTIVE");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
1
|
+
// 兼容旧入口;客户端状态、错误身份和恢复实现由独立包统一持有。
|
|
2
|
+
export { AsyncQuestionReply } from "@mininglamp-oss/octo-runtime-client";
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* 连接本机 socket/Windows Pipe,返回不拥有 Kernel 进程的客户端。
|
|
4
|
-
* 宿主接入层只在 CLI 模式跨进程连接已有服务时显式调用;原生 SDK 使用 kernel.client。
|
|
5
|
-
* Kernel/Extra 服务内部也复用本函数构造 RPC 客户端,不要求 SDK 调用方额外 attach。
|
|
6
|
-
* invoke 提供登记、取消和尾流观察;关闭连接或迭代器不会隐式取消已接纳 Run。
|
|
7
|
-
*/
|
|
8
|
-
export declare function attachKernel(options: {
|
|
9
|
-
endpoint: string;
|
|
10
|
-
}): KernelClient;
|
|
1
|
+
export { attachKernel } from "@mininglamp-oss/octo-runtime-client";
|
|
@@ -1,446 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { assertHostFrame, assertHostFrameIdentity, assertHostRunReceipt, createInputInvoke, identifyInvokeInput, isHostTerminal, HOST_RPC_MAX_LINE_BYTES, INVOKE_REQUEST_MAX_BYTES } from "@mininglamp-oss/octo-runtime-protocol";
|
|
4
|
-
import { KernelError } from "./types.js";
|
|
5
|
-
import { InvocationRegistry } from "./invocation-lifecycle.js";
|
|
6
|
-
import { markSubmissionRejected } from "./submission-error.js";
|
|
7
|
-
/**
|
|
8
|
-
* 连接本机 socket/Windows Pipe,返回不拥有 Kernel 进程的客户端。
|
|
9
|
-
* 宿主接入层只在 CLI 模式跨进程连接已有服务时显式调用;原生 SDK 使用 kernel.client。
|
|
10
|
-
* Kernel/Extra 服务内部也复用本函数构造 RPC 客户端,不要求 SDK 调用方额外 attach。
|
|
11
|
-
* invoke 提供登记、取消和尾流观察;关闭连接或迭代器不会隐式取消已接纳 Run。
|
|
12
|
-
*/
|
|
13
|
-
export function attachKernel(options) {
|
|
14
|
-
const sockets = new Set();
|
|
15
|
-
let closed = false;
|
|
16
|
-
const open = async (signal, timeout = 5000) => {
|
|
17
|
-
if (closed)
|
|
18
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
19
|
-
if (sockets.size >= 32)
|
|
20
|
-
throw new KernelError("CLIENT_CAPACITY_EXHAUSTED");
|
|
21
|
-
signal?.throwIfAborted();
|
|
22
|
-
const socket = net.createConnection(options.endpoint);
|
|
23
|
-
sockets.add(socket);
|
|
24
|
-
socket.once("close", () => sockets.delete(socket));
|
|
25
|
-
socket.on("error", () => { });
|
|
26
|
-
const abort = () => socket.destroy(new KernelError("SUBSCRIPTION_ABORTED"));
|
|
27
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
28
|
-
socket.once("close", () => signal?.removeEventListener("abort", abort));
|
|
29
|
-
await new Promise((resolve, reject) => {
|
|
30
|
-
const finish = (error) => {
|
|
31
|
-
clearTimeout(timer);
|
|
32
|
-
socket.off("connect", connected);
|
|
33
|
-
socket.off("error", failed);
|
|
34
|
-
socket.off("close", disconnected);
|
|
35
|
-
if (error)
|
|
36
|
-
reject(error);
|
|
37
|
-
else
|
|
38
|
-
resolve();
|
|
39
|
-
};
|
|
40
|
-
const connected = () => finish();
|
|
41
|
-
const failed = (error) => finish(error);
|
|
42
|
-
const disconnected = () => finish(new KernelError(closed ? "CLIENT_CLOSED" : "CONNECTION_CLOSED"));
|
|
43
|
-
const timer = setTimeout(() => {
|
|
44
|
-
socket.destroy();
|
|
45
|
-
finish(new KernelError("KERNEL_UNAVAILABLE"));
|
|
46
|
-
}, Math.min(5000, timeout));
|
|
47
|
-
socket.once("connect", connected);
|
|
48
|
-
socket.once("error", failed);
|
|
49
|
-
socket.once("close", disconnected);
|
|
50
|
-
}).catch(() => {
|
|
51
|
-
socket.destroy();
|
|
52
|
-
throw new KernelError(closed ? "CLIENT_CLOSED" : "KERNEL_UNAVAILABLE");
|
|
53
|
-
});
|
|
54
|
-
return socket;
|
|
55
|
-
};
|
|
56
|
-
const exchange = async (method, params = {}, timeout = 5000, signal, beforeSend, sent) => {
|
|
57
|
-
const until = Date.now() + timeout;
|
|
58
|
-
const socket = await open(signal, timeout);
|
|
59
|
-
const timer = setTimeout(() => socket.destroy(new KernelError("KERNEL_TIMEOUT")), Math.max(1, until - Date.now()));
|
|
60
|
-
const id = randomUUID();
|
|
61
|
-
try {
|
|
62
|
-
signal?.throwIfAborted();
|
|
63
|
-
beforeSend?.();
|
|
64
|
-
send(socket, id, method, params);
|
|
65
|
-
sent?.();
|
|
66
|
-
for await (const value of lines(socket))
|
|
67
|
-
return response(value, id);
|
|
68
|
-
throw new KernelError(closed ? "CLIENT_CLOSED" : "CONNECTION_CLOSED");
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (closed)
|
|
72
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
clearTimeout(timer);
|
|
77
|
-
socket.destroy();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const query = async (key, expectedInstance, deadline = Date.now() + 5000, signal) => {
|
|
81
|
-
const info = (await exchange("agent_run.get", {
|
|
82
|
-
key: lookupForKey(key),
|
|
83
|
-
kernel_instance_id: expectedInstance
|
|
84
|
-
}, remaining(deadline), signal));
|
|
85
|
-
assertHostRunReceipt(receiptFor(info.ref));
|
|
86
|
-
if (expectedInstance !== undefined && info.ref.kernel_instance_id !== expectedInstance)
|
|
87
|
-
throw new KernelError("KERNEL_INSTANCE_CHANGED");
|
|
88
|
-
if (!sameLookup(info.ref, key))
|
|
89
|
-
throw new KernelError("RUN_IDENTITY_MISMATCH");
|
|
90
|
-
if (info.terminal) {
|
|
91
|
-
assertHostFrame(info.terminal);
|
|
92
|
-
assertHostFrameIdentity(info.terminal, receiptFor(info.ref));
|
|
93
|
-
if (!isHostTerminal(info.terminal))
|
|
94
|
-
throw new KernelError("HOST_FRAME_INVALID");
|
|
95
|
-
}
|
|
96
|
-
registry.reconcile(info.ref, info.terminal);
|
|
97
|
-
return info;
|
|
98
|
-
};
|
|
99
|
-
const cancel = async (ref, reason, deadline = Date.now() + 5000, signal) => {
|
|
100
|
-
try {
|
|
101
|
-
const result = (await exchange("agent_run.cancel", { ref, reason }, remaining(deadline), signal));
|
|
102
|
-
if (typeof result?.accepted !== "boolean")
|
|
103
|
-
throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
if (error instanceof KernelError &&
|
|
108
|
-
!["CONNECTION_CLOSED", "KERNEL_TIMEOUT", "SUBSCRIPTION_ABORTED"].includes(error.code))
|
|
109
|
-
throw error;
|
|
110
|
-
throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
const registry = new InvocationRegistry({ get: query, cancel });
|
|
114
|
-
const control = async (method, params) => {
|
|
115
|
-
try {
|
|
116
|
-
await exchange(method, params);
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
if (error instanceof KernelError &&
|
|
120
|
-
!["CONNECTION_CLOSED", "KERNEL_TIMEOUT"].includes(error.code))
|
|
121
|
-
throw error;
|
|
122
|
-
throw new KernelError("OPERATION_OUTCOME_UNKNOWN");
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
const client = {
|
|
126
|
-
topology: "kernel-ipc",
|
|
127
|
-
ownership: "attached",
|
|
128
|
-
invocations: registry,
|
|
129
|
-
invoke: createInputInvoke(async function* (input, environment = {}) {
|
|
130
|
-
if (closed)
|
|
131
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
132
|
-
environment.signal?.throwIfAborted();
|
|
133
|
-
const request = identifyInvokeInput(input);
|
|
134
|
-
const record = registry.begin(lookupFor(request));
|
|
135
|
-
// signal 属于执行控制,不传给 subscribe:取消后仍须读到 Provider 会话更新与真实终态。
|
|
136
|
-
const abort = () => {
|
|
137
|
-
void registry.cancel(record, "caller_aborted").catch(() => undefined);
|
|
138
|
-
};
|
|
139
|
-
environment.signal?.addEventListener("abort", abort, { once: true });
|
|
140
|
-
try {
|
|
141
|
-
let ref;
|
|
142
|
-
try {
|
|
143
|
-
ref = (await submit(request, environment, record)).ref;
|
|
144
|
-
registry.accepted(record, ref);
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
registry.rejected(record, error);
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
150
|
-
// 终态会释放登记,但 yield 后的业务持久化/投递仍由消费者负责,owner 不能据此提前 close。
|
|
151
|
-
let terminal = false;
|
|
152
|
-
for await (const frame of client.subscribe(ref)) {
|
|
153
|
-
terminal = isHostTerminal(frame);
|
|
154
|
-
if (request.protocol_mode === "canonical" &&
|
|
155
|
-
frame.kind === "control" &&
|
|
156
|
-
frame.control.type === "error") {
|
|
157
|
-
const snapshot = await query(ref, ref.kernel_instance_id).catch(() => undefined);
|
|
158
|
-
if (snapshot?.terminal?.kind === "control" &&
|
|
159
|
-
snapshot.terminal.control.type === "state" &&
|
|
160
|
-
snapshot.terminal.control.state === "lost")
|
|
161
|
-
throw new KernelError("RUN_OUTCOME_UNKNOWN");
|
|
162
|
-
}
|
|
163
|
-
yield frame;
|
|
164
|
-
if (terminal &&
|
|
165
|
-
frame.kind === "control" &&
|
|
166
|
-
frame.control.type === "state" &&
|
|
167
|
-
frame.control.state === "lost")
|
|
168
|
-
throw new KernelError("RUN_OUTCOME_UNKNOWN");
|
|
169
|
-
}
|
|
170
|
-
if (!terminal)
|
|
171
|
-
throw new KernelError("HOST_ENDED_WITHOUT_TERMINAL");
|
|
172
|
-
if (record.cancelTask)
|
|
173
|
-
await record.cancelTask;
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
registry.interrupted(record, error);
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
environment.signal?.removeEventListener("abort", abort);
|
|
181
|
-
registry.interrupted(record);
|
|
182
|
-
}
|
|
183
|
-
}),
|
|
184
|
-
cancelInvocation: async (id, reason) => registry.cancel(registry.active(id), reason),
|
|
185
|
-
respondInteraction: async (id, response) => client.respond(registry.ref(id), response),
|
|
186
|
-
respondNativeInteraction: async (id, response) => client.respondNative(registry.ref(id), response),
|
|
187
|
-
status: async () => (await exchange("status")),
|
|
188
|
-
list: async () => (await exchange("adapter.list")),
|
|
189
|
-
get: query,
|
|
190
|
-
submit: (input, environment) => submit(input, environment),
|
|
191
|
-
async *subscribe(ref, afterSeq = 0, signal) {
|
|
192
|
-
// 断线仅续读同一实例、同一流的连续序号;不能把恢复观察变成再次执行 Provider。
|
|
193
|
-
let after = afterSeq;
|
|
194
|
-
let repair = 0;
|
|
195
|
-
let repairUntil;
|
|
196
|
-
while (true) {
|
|
197
|
-
signal?.throwIfAborted();
|
|
198
|
-
if (closed)
|
|
199
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
200
|
-
let socket;
|
|
201
|
-
let timer;
|
|
202
|
-
try {
|
|
203
|
-
if (repairUntil !== undefined && Date.now() >= repairUntil)
|
|
204
|
-
throw new KernelError("KERNEL_UNAVAILABLE");
|
|
205
|
-
socket = await open(signal, repairUntil === undefined ? 5000 : Math.max(1, repairUntil - Date.now()));
|
|
206
|
-
const current = socket;
|
|
207
|
-
timer = setTimeout(() => current.destroy(new KernelError("KERNEL_TIMEOUT")), repairUntil === undefined ? 5000 : Math.max(1, Math.min(5000, repairUntil - Date.now())));
|
|
208
|
-
const id = randomUUID();
|
|
209
|
-
send(socket, id, "agent_run.subscribe", { ref, after_seq: after });
|
|
210
|
-
let acknowledged = false;
|
|
211
|
-
let terminalAt;
|
|
212
|
-
for await (const value of lines(socket)) {
|
|
213
|
-
if (!acknowledged) {
|
|
214
|
-
const info = response(value, id);
|
|
215
|
-
if (info.ref.kernel_instance_id !== ref.kernel_instance_id)
|
|
216
|
-
throw new KernelError("KERNEL_INSTANCE_CHANGED");
|
|
217
|
-
assertHostRunReceipt(receiptFor(info.ref));
|
|
218
|
-
if (!sameLookup(info.ref, ref) ||
|
|
219
|
-
info.ref.stream_id !== ref.stream_id ||
|
|
220
|
-
info.ref.protocol !== ref.protocol)
|
|
221
|
-
throw new KernelError("RUN_IDENTITY_MISMATCH");
|
|
222
|
-
acknowledged = true;
|
|
223
|
-
clearTimeout(timer);
|
|
224
|
-
if (info.terminal) {
|
|
225
|
-
assertHostFrame(info.terminal);
|
|
226
|
-
assertHostFrameIdentity(info.terminal, receiptFor(ref));
|
|
227
|
-
if (!isHostTerminal(info.terminal))
|
|
228
|
-
throw new KernelError("HOST_FRAME_INVALID");
|
|
229
|
-
registry.reconcile(info.ref, info.terminal);
|
|
230
|
-
terminalAt = info.latest_seq;
|
|
231
|
-
}
|
|
232
|
-
if (terminalAt !== undefined && after >= terminalAt)
|
|
233
|
-
return;
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
const notification = value;
|
|
237
|
-
if (notification.method === "agent_run.stream_error")
|
|
238
|
-
throw new KernelError(notification.params?.code ?? "STREAM_FAILED");
|
|
239
|
-
if (notification.method !== "agent_run.event" ||
|
|
240
|
-
notification.params?.kernel_instance_id !== ref.kernel_instance_id)
|
|
241
|
-
throw new KernelError("HOST_FRAME_INVALID");
|
|
242
|
-
const frame = notification.params.event;
|
|
243
|
-
assertHostFrame(frame);
|
|
244
|
-
assertHostFrameIdentity(frame, receiptFor(ref));
|
|
245
|
-
if (frame.seq !== after + 1 || notification.params.seq !== frame.seq)
|
|
246
|
-
throw new KernelError("STREAM_GAP");
|
|
247
|
-
after = frame.seq;
|
|
248
|
-
registry.observe(ref, frame);
|
|
249
|
-
yield frame;
|
|
250
|
-
if (isHostTerminal(frame))
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
throw new KernelError("CONNECTION_CLOSED");
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
if (closed)
|
|
257
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
258
|
-
signal?.throwIfAborted();
|
|
259
|
-
if (!(error instanceof KernelError) &&
|
|
260
|
-
error instanceof Error &&
|
|
261
|
-
"code" in error &&
|
|
262
|
-
typeof error.code === "string")
|
|
263
|
-
throw new KernelError(error.code);
|
|
264
|
-
if (error instanceof KernelError &&
|
|
265
|
-
!["CONNECTION_CLOSED", "KERNEL_UNAVAILABLE", "KERNEL_TIMEOUT"].includes(error.code))
|
|
266
|
-
throw error;
|
|
267
|
-
if (repair >= 3)
|
|
268
|
-
throw new KernelError("KERNEL_UNAVAILABLE");
|
|
269
|
-
repairUntil ??= Date.now() + 10_000;
|
|
270
|
-
if (Date.now() >= repairUntil)
|
|
271
|
-
throw new KernelError("KERNEL_UNAVAILABLE");
|
|
272
|
-
await new Promise((resolve) => setTimeout(resolve, [100, 250, 500][repair++]));
|
|
273
|
-
}
|
|
274
|
-
finally {
|
|
275
|
-
clearTimeout(timer);
|
|
276
|
-
socket?.destroy();
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
},
|
|
280
|
-
cancel,
|
|
281
|
-
respond: (ref, response) => control("agent_run.respond", { ref, response }),
|
|
282
|
-
respondNative: (ref, response) => control("agent_run.native.respond", { ref, response }),
|
|
283
|
-
close() {
|
|
284
|
-
closed = true;
|
|
285
|
-
registry.close();
|
|
286
|
-
for (const socket of sockets)
|
|
287
|
-
socket.destroy();
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
async function submit(input, environment = {}, record) {
|
|
291
|
-
if (closed)
|
|
292
|
-
throw new KernelError("CLIENT_CLOSED");
|
|
293
|
-
environment.signal?.throwIfAborted();
|
|
294
|
-
if (environment.streamLimits !== undefined)
|
|
295
|
-
throw new KernelError("KERNEL_STREAM_LIMITS_UNSUPPORTED");
|
|
296
|
-
const request = identifyInvokeInput(input);
|
|
297
|
-
const requestLine = JSON.stringify({
|
|
298
|
-
jsonrpc: "2.0",
|
|
299
|
-
id: "0".repeat(36),
|
|
300
|
-
method: "agent_run.invoke",
|
|
301
|
-
params: { input: request, executionEnvOverrides: environment.executionEnvOverrides }
|
|
302
|
-
});
|
|
303
|
-
if (Buffer.byteLength(requestLine) + 1 > INVOKE_REQUEST_MAX_BYTES)
|
|
304
|
-
throw new KernelError("INVOKE_REQUEST_TOO_LARGE");
|
|
305
|
-
const instance = (await client.status()).kernel_instance_id;
|
|
306
|
-
environment.signal?.throwIfAborted();
|
|
307
|
-
if (record)
|
|
308
|
-
record.instance = instance;
|
|
309
|
-
let ref;
|
|
310
|
-
let submitted = false;
|
|
311
|
-
try {
|
|
312
|
-
const result = (await exchange("agent_run.invoke", {
|
|
313
|
-
input: request,
|
|
314
|
-
executionEnvOverrides: environment.executionEnvOverrides,
|
|
315
|
-
kernel_instance_id: instance
|
|
316
|
-
}, 30_000,
|
|
317
|
-
// 请求发出后中断等待会让接纳结果不明;先取得/查询 ACK,再按原身份请求取消。
|
|
318
|
-
undefined, () => {
|
|
319
|
-
environment.signal?.throwIfAborted();
|
|
320
|
-
if (record)
|
|
321
|
-
registry.assertSubmission();
|
|
322
|
-
}, () => {
|
|
323
|
-
submitted = true;
|
|
324
|
-
if (record)
|
|
325
|
-
record.submitted = true;
|
|
326
|
-
}));
|
|
327
|
-
assertHostRunReceipt(result.receipt);
|
|
328
|
-
if (result.kernel_instance_id !== instance)
|
|
329
|
-
throw new KernelError("KERNEL_INSTANCE_CHANGED");
|
|
330
|
-
ref = { ...result.receipt, kernel_instance_id: result.kernel_instance_id };
|
|
331
|
-
if (!sameLookup(ref, lookupFor(request)))
|
|
332
|
-
throw new KernelError("RUN_IDENTITY_MISMATCH");
|
|
333
|
-
}
|
|
334
|
-
catch (error) {
|
|
335
|
-
if (!submitted)
|
|
336
|
-
throw error;
|
|
337
|
-
markSubmissionRejected(error, instance);
|
|
338
|
-
if (error instanceof KernelError &&
|
|
339
|
-
!["KERNEL_TIMEOUT", "CONNECTION_CLOSED"].includes(error.code))
|
|
340
|
-
throw error;
|
|
341
|
-
// ACK 丢失后只按原身份查询,不重新提交,避免创建第二次执行。
|
|
342
|
-
const key = lookupFor(request);
|
|
343
|
-
let recovered;
|
|
344
|
-
const until = Date.now() + 10_000;
|
|
345
|
-
for (const delay of [100, 250, 500]) {
|
|
346
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
347
|
-
if (Date.now() >= until)
|
|
348
|
-
break;
|
|
349
|
-
try {
|
|
350
|
-
recovered = (await query(key, instance, Math.min(until, Date.now() + 5000))).ref;
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
catch (queryError) {
|
|
354
|
-
if (queryError instanceof KernelError &&
|
|
355
|
-
["KERNEL_INSTANCE_CHANGED", "RUN_IDENTITY_MISMATCH"].includes(queryError.code))
|
|
356
|
-
throw queryError;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
if (!recovered)
|
|
360
|
-
throw new KernelError("ACCEPTANCE_UNKNOWN");
|
|
361
|
-
ref = recovered;
|
|
362
|
-
}
|
|
363
|
-
if (!record && environment.signal?.aborted)
|
|
364
|
-
await client.cancel(ref, "caller_aborted");
|
|
365
|
-
return { ref };
|
|
366
|
-
}
|
|
367
|
-
return client;
|
|
368
|
-
}
|
|
369
|
-
function remaining(deadline) {
|
|
370
|
-
const timeout = deadline - Date.now();
|
|
371
|
-
if (timeout <= 0)
|
|
372
|
-
throw new KernelError("KERNEL_TIMEOUT");
|
|
373
|
-
return timeout;
|
|
374
|
-
}
|
|
375
|
-
function receiptFor(ref) {
|
|
376
|
-
const { kernel_instance_id: _instance, ...receipt } = ref;
|
|
377
|
-
void _instance;
|
|
378
|
-
return receipt;
|
|
379
|
-
}
|
|
380
|
-
function lookupForKey(key) {
|
|
381
|
-
return {
|
|
382
|
-
run_id: key.run_id,
|
|
383
|
-
invocation_id: key.invocation_id,
|
|
384
|
-
agent_session_id: key.agent_session_id,
|
|
385
|
-
session_generation: key.session_generation,
|
|
386
|
-
protocol_mode: key.protocol_mode
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
function sameLookup(left, right) {
|
|
390
|
-
return (left.run_id === right.run_id &&
|
|
391
|
-
left.invocation_id === right.invocation_id &&
|
|
392
|
-
left.agent_session_id === right.agent_session_id &&
|
|
393
|
-
left.session_generation === right.session_generation &&
|
|
394
|
-
left.protocol_mode === right.protocol_mode);
|
|
395
|
-
}
|
|
396
|
-
function lookupFor(input) {
|
|
397
|
-
return {
|
|
398
|
-
run_id: input.runId,
|
|
399
|
-
invocation_id: input.invocationId,
|
|
400
|
-
agent_session_id: input.sessionId,
|
|
401
|
-
session_generation: input.sessionGeneration ?? 0,
|
|
402
|
-
protocol_mode: input.protocol_mode ?? "native"
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function send(socket, id, method, params) {
|
|
406
|
-
const line = `${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`;
|
|
407
|
-
if (Buffer.byteLength(line) > INVOKE_REQUEST_MAX_BYTES)
|
|
408
|
-
throw new KernelError("INVOKE_REQUEST_TOO_LARGE");
|
|
409
|
-
socket.write(line);
|
|
410
|
-
}
|
|
411
|
-
function response(value, id) {
|
|
412
|
-
const reply = value;
|
|
413
|
-
if (reply.id !== id)
|
|
414
|
-
throw new KernelError("INVALID_RESPONSE");
|
|
415
|
-
if (reply.error)
|
|
416
|
-
throw new KernelError(typeof reply.error.data?.code === "string" ? reply.error.data.code : "KERNEL_REQUEST_FAILED", reply.error.data);
|
|
417
|
-
return reply.result;
|
|
418
|
-
}
|
|
419
|
-
async function* lines(socket) {
|
|
420
|
-
let pending = Buffer.alloc(0);
|
|
421
|
-
try {
|
|
422
|
-
for await (const chunk of socket) {
|
|
423
|
-
const bytes = chunk;
|
|
424
|
-
pending = pending.length ? Buffer.concat([pending, bytes]) : bytes;
|
|
425
|
-
let offset;
|
|
426
|
-
while ((offset = pending.indexOf(10)) >= 0) {
|
|
427
|
-
if (offset > HOST_RPC_MAX_LINE_BYTES)
|
|
428
|
-
throw new KernelError("HOST_FRAME_TOO_LARGE");
|
|
429
|
-
const line = pending.subarray(0, offset);
|
|
430
|
-
pending = pending.subarray(offset + 1);
|
|
431
|
-
yield JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(line));
|
|
432
|
-
}
|
|
433
|
-
if (pending.length > HOST_RPC_MAX_LINE_BYTES)
|
|
434
|
-
throw new KernelError("HOST_FRAME_TOO_LARGE");
|
|
435
|
-
}
|
|
436
|
-
if (pending.length)
|
|
437
|
-
throw new KernelError("CONNECTION_CLOSED");
|
|
438
|
-
}
|
|
439
|
-
catch (error) {
|
|
440
|
-
if (error instanceof KernelError)
|
|
441
|
-
throw error;
|
|
442
|
-
if (error instanceof Error && /^[A-Z][A-Z0-9_]+$/.test(error.message))
|
|
443
|
-
throw new KernelError(error.message);
|
|
444
|
-
throw new KernelError("CONNECTION_CLOSED");
|
|
445
|
-
}
|
|
446
|
-
}
|
|
1
|
+
// 兼容旧入口;客户端状态、错误身份和恢复实现由独立包统一持有。
|
|
2
|
+
export { attachKernel } from "@mininglamp-oss/octo-runtime-client";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import net from "node:net";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { lstat, open, readFile, rm } from "node:fs/promises";
|
|
4
|
+
import { assertIpcEndpoint } from "./runtime-home.js";
|
|
4
5
|
/** 端点租约保护启动竞争;只移除已确认无人监听的旧 socket,不替换用户文件。 */
|
|
5
6
|
export async function acquireEndpoint(endpoint) {
|
|
7
|
+
assertIpcEndpoint(endpoint);
|
|
6
8
|
if (process.platform === "win32")
|
|
7
9
|
return async () => { };
|
|
8
10
|
const file = `${endpoint}.owner`;
|