@mininglamp-oss/octo-runtime-client 0.0.0-stage → 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.
Files changed (87) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +38 -2
  3. package/build-info.json +5 -0
  4. package/dist/async-question-reply.d.ts +30 -0
  5. package/dist/async-question-reply.js +199 -0
  6. package/dist/browser.d.ts +1 -0
  7. package/dist/browser.js +1 -0
  8. package/dist/client.d.ts +10 -0
  9. package/dist/client.js +465 -0
  10. package/dist/index.d.ts +6 -0
  11. package/dist/index.js +6 -0
  12. package/dist/internal.d.ts +4 -0
  13. package/dist/internal.js +5 -0
  14. package/dist/invocation-lifecycle.d.ts +59 -0
  15. package/dist/invocation-lifecycle.js +287 -0
  16. package/dist/notification.d.ts +1 -0
  17. package/dist/notification.js +1 -0
  18. package/dist/protocol.d.ts +1 -0
  19. package/dist/protocol.js +1 -0
  20. package/dist/runtime-path.d.ts +21 -0
  21. package/dist/runtime-path.js +138 -0
  22. package/dist/startup-catalog.d.ts +8 -0
  23. package/dist/startup-catalog.js +65 -0
  24. package/dist/startup-diagnostics.d.ts +82 -0
  25. package/dist/startup-diagnostics.js +371 -0
  26. package/dist/submission-error.d.ts +10 -0
  27. package/dist/submission-error.js +23 -0
  28. package/dist/types.d.ts +72 -0
  29. package/dist/types.js +10 -0
  30. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/actmode.d.ts +4 -0
  31. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/actmode.js +36 -0
  32. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +7 -0
  33. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.js +1 -0
  34. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.d.ts +7 -0
  35. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +6 -0
  36. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.d.ts +11 -0
  37. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.js +33 -0
  38. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-configuration.d.ts +5 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-configuration.js +58 -0
  40. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-hash.d.ts +2 -0
  41. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-hash.js +5 -0
  42. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +29 -0
  43. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +566 -0
  44. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.d.ts +3 -0
  45. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.js +80 -0
  46. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/experience.d.ts +4 -0
  47. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/experience.js +166 -0
  48. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +82 -0
  49. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +562 -0
  50. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +3022 -0
  51. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.js +6 -0
  52. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +124 -0
  53. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +709 -0
  54. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +129 -0
  55. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +177 -0
  56. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-size.d.ts +3 -0
  57. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-size.js +11 -0
  58. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/json-size.d.ts +2 -0
  59. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/json-size.js +91 -0
  60. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.d.ts +3 -0
  61. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.js +9 -0
  62. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/multimodal.d.ts +15 -0
  63. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/multimodal.js +166 -0
  64. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/notification.d.ts +2 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/notification.js +137 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.d.ts +9 -0
  67. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/questions.js +84 -0
  68. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +20 -0
  69. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +294 -0
  70. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/runtime-selection.d.ts +3 -0
  71. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/runtime-selection.js +68 -0
  72. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.d.ts +5 -0
  73. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +65 -0
  74. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/stream-limits.d.ts +27 -0
  75. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/stream-limits.js +56 -0
  76. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +15 -0
  77. package/package.json +55 -4
  78. package/schema/context-configuration-fixtures.json +1219 -0
  79. package/schema/context-fixtures.json +5988 -0
  80. package/schema/kernel-client.behavior.json +56 -0
  81. package/schema/kernel-ipc-fixtures.json +53 -0
  82. package/schema/kernel-ipc.schema.json +538 -0
  83. package/schema/native-invoke-fixtures.json +116 -0
  84. package/schema/protocol.schema.json +4525 -0
  85. package/schema/run-protocol-fixtures.json +761 -0
  86. package/schema/runtime-selection-fixtures.json +663 -0
  87. package/schema/session-name-fixtures.json +191 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Mininglamp Technology
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # @mininglamp-oss/octo-runtime-client
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Standalone Node.js SDK for an **existing local Executor Kernel**. No CLI, server, Core, Provider Adapter or Extra is installed. Node.js 24 or 26 is required.
4
+
5
+ ```sh
6
+ npm install @mininglamp-oss/octo-runtime-client
7
+ ```
8
+
9
+ ```ts
10
+ import { attachKernel } from "@mininglamp-oss/octo-runtime-client";
11
+ import type { InvokeInput } from "@mininglamp-oss/octo-runtime-client/protocol";
12
+
13
+ // The host supplies an existing Unix socket or Windows named pipe endpoint.
14
+ async function execute(endpoint: string, input: InvokeInput) {
15
+ const client = attachKernel({ endpoint });
16
+ try {
17
+ for await (const event of client.invoke({ ...input, protocol_mode: "canonical" })) {
18
+ console.log(event);
19
+ }
20
+ } finally {
21
+ // Close releases this client's connections; it does not stop the Kernel or cancel runs.
22
+ client.close();
23
+ }
24
+ }
25
+ ```
26
+
27
+ The root exports `attachKernel`, `KernelClient`, `KernelError`, `AsyncQuestionReply`, invocation lifecycle types and common protocol types. `/protocol` exports all shared public protocol types, constants and validators. `/protocol/browser` and `/protocol/notification` retain specialized protocol entrypoints. Raw schemas are available at `/protocol/schema.json`, `/protocol/ipc-schema.json`, `/protocol/ipc-fixtures.json` and `/protocol/behavior.json`. Schemas are copied from the authoritative private protocol package, which is bundled rather than independently published.
28
+
29
+ `/internal` contains same-version Runtime composition helpers, including pure path validation and invocation bookkeeping. It is not a stable application API and does not construct services. Ordinary applications use the root API.
30
+
31
+ `invoke` owns bounded call registration and observation recovery. Cancellation ACK is distinct from execution completion. Consumers must finish their own persistence/delivery work and explicitly cancel unwanted runs. Owners stop admission, drain their registered calls within a deadline, finish business cleanup, then close. `submit`/`subscribe` are advanced APIs whose callers manage their own run references, cancellation and observation. A lost ACK is queried using the original identity; execution and control actions with unknown outcomes are never automatically resubmitted.
32
+
33
+ Both public npm packages are released from one stable tag with matching versions. The full Runtime bundles its own client and protocol under its internal node_modules, preserving single-archive offline installation. The standalone client bundles only the private protocol. Both use the same source implementation; neither requires downloading the other public artifact. Existing full SDK `/executor-kernel` and `/protocol` imports remain supported. Service creation, direct Core use and Extra construction require `@mininglamp-oss/octo-runtime`.
34
+
35
+ Values and error classes are shared within each distribution. Installing both distributions may create separate module instances even at the same version: do not compare functions/classes across distributions or rely on cross-copy `instanceof` or invocation rejection evidence. Use the error class from the producing API, or inspect its public `code`. Client interfaces and protocol data remain structurally compatible.
36
+
37
+ Package versions are distinct from IPC v1, Run 7, Context v3 and Adapter transport 2. Matching release pairs are supported. Cross-version attachment requires the same wire contracts and support for every field/method used; arbitrary older combinations are not guaranteed. There is no negotiation or compatibility translation. `status()` rejects unsupported IPC versions with `KERNEL_IPC_VERSION_UNSUPPORTED` and malformed status with `INVALID_RESPONSE`; submission uses that existing status query before writing an invocation. Existing RPC and frame validators report unsupported requests/frames; the client does not silently retry execution or downgrade. Schema provenance is the same tagged repository revision as the package, with build source recorded in build-info.json. This extraction does not add browser/network transport, remote authentication, Provider installation or Home initialization.
38
+
39
+ 中文:本包只连接宿主提供的本地 Kernel,不拥有服务。根入口提供客户端、错误、调用登记和旁路问题接口;`/protocol` 提供共享类型与校验,`/protocol/*.json` 提供原始 schema。完整 Runtime 原入口继续兼容。两个 npm 包从同一 tag 同版本发布,完整包内置 client/protocol,独立 client 仅内置 protocol;任一 tgz 均可单独离线安装。每个发行物内部共享错误与协议值;跨发行物可能是两个模块副本,不承诺 ===、instanceof 或 WeakSet 证据互认。npm 版本与 IPC/Run/Context 版本分别管理;跨版本须满足实际 wire 合同,无自动协商、降级或重放。取消回执不等于执行完成,关闭连接不取消 Run,业务收尾及服务生命周期始终归宿主。
@@ -0,0 +1,5 @@
1
+ {
2
+ "commit": "780cd7cd5e67e4868df895a2e74a826097f349fd",
3
+ "dirty": false,
4
+ "buildTime": "2026-11-05T06:19:50.356Z"
5
+ }
@@ -0,0 +1,30 @@
1
+ import { type AsyncQuestionReplySnapshot, type CanonicalEvent, type HostFrame, type InvokeEnvironment, type InvokeInput } from "@mininglamp-oss/octo-runtime-protocol";
2
+ import { type KernelClient } from "./types.js";
3
+ export type AsyncQuestionReplyResult = {
4
+ route: "steer";
5
+ acceptance: "provider_accepted";
6
+ } | {
7
+ route: "new_run";
8
+ input: InvokeInput;
9
+ events: AsyncGenerator<CanonicalEvent>;
10
+ };
11
+ /**
12
+ * 宿主持有的一份旁路问题控制者,不拥有 Kernel 或数据库。
13
+ * 活动时 steer,确认正常完成后复用 invoke;宿主须串行管理同会话、
14
+ * 保存提交状态并消费新 Run 尾流。新流返回不代表 Provider 接纳。
15
+ */
16
+ export declare class AsyncQuestionReply {
17
+ #private;
18
+ readonly client: KernelClient;
19
+ readonly continuation: () => InvokeInput;
20
+ readonly environment?: InvokeEnvironment | undefined;
21
+ constructor(client: KernelClient, snapshot: AsyncQuestionReplySnapshot, continuation: () => InvokeInput, environment?: InvokeEnvironment | undefined);
22
+ /** 独立 JSON 副本供宿主保存;恢复 submitting/unknown 不会再次投递。 */
23
+ snapshot(): AsyncQuestionReplySnapshot;
24
+ /** 只接受原源流事实;消息 final 或查不到 Run 不能证明正常完成。 */
25
+ observe(frame: HostFrame): void;
26
+ /** 关闭旁路,不中断模型;原活动交互同步关闭,未知响应不重试。 */
27
+ cancel(): Promise<void>;
28
+ /** 整批一次。steer 等待 Provider ACK;new_run 必须消费返回流,沿原 invoke 管理执行。 */
29
+ respond(value: unknown): Promise<AsyncQuestionReplyResult>;
30
+ }
@@ -0,0 +1,199 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { assertCanonicalEvent, assertHostFrame, assertHostFrameIdentity, assertHostRunReceipt, assertInvokeInput, assertJsonValue, assertQuestionRequest, assertQuestionResponse, questionAnswerText } from "@mininglamp-oss/octo-runtime-protocol";
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
+ }
@@ -0,0 +1 @@
1
+ export * from "@mininglamp-oss/octo-runtime-protocol/browser";
@@ -0,0 +1 @@
1
+ export * from "@mininglamp-oss/octo-runtime-protocol/browser";
@@ -0,0 +1,10 @@
1
+ import { type KernelClient } from "./types.js";
2
+ /**
3
+ * 连接本机 socket/Windows Pipe,返回不拥有 Kernel 进程的客户端。
4
+ * 独立应用显式连接已有服务;原生 SDK 服务宿主使用 kernel.client。
5
+ * Kernel/Extra 服务内部也复用本函数构造 RPC 客户端,不要求 SDK 调用方额外 attach。
6
+ * invoke 提供登记、取消和尾流观察;关闭连接或迭代器不会隐式取消已接纳 Run。
7
+ */
8
+ export declare function attachKernel(options: {
9
+ endpoint: string;
10
+ }): KernelClient;