@xemahq/worker-runtime-opencode 0.1.1
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/LICENSE +201 -0
- package/README.md +60 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/factory.d.ts +4 -0
- package/dist/lib/factory.d.ts.map +1 -0
- package/dist/lib/factory.js +37 -0
- package/dist/lib/factory.js.map +1 -0
- package/dist/lib/opencode-worker-runtime.d.ts +43 -0
- package/dist/lib/opencode-worker-runtime.d.ts.map +1 -0
- package/dist/lib/opencode-worker-runtime.js +211 -0
- package/dist/lib/opencode-worker-runtime.js.map +1 -0
- package/dist/lib/runtime-events.d.ts +11 -0
- package/dist/lib/runtime-events.d.ts.map +1 -0
- package/dist/lib/runtime-events.js +127 -0
- package/dist/lib/runtime-events.js.map +1 -0
- package/dist/lib/session-bundle.d.ts +26 -0
- package/dist/lib/session-bundle.d.ts.map +1 -0
- package/dist/lib/session-bundle.js +86 -0
- package/dist/lib/session-bundle.js.map +1 -0
- package/dist/lib/worker-ref.d.ts +19 -0
- package/dist/lib/worker-ref.d.ts.map +1 -0
- package/dist/lib/worker-ref.js +3 -0
- package/dist/lib/worker-ref.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 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 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 those 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 describing the origin of the Work and
|
|
141
|
+
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 Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend, and
|
|
172
|
+
hold each Contributor harmless for any liability incurred by, or
|
|
173
|
+
claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Xema
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<svg width="680" height="120" viewBox="0 0 680 120" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="@xemahq/worker-runtime-opencode">
|
|
3
|
+
<rect width="680" height="120" rx="14" fill="#0B1020"/>
|
|
4
|
+
<g transform="translate(28,34)">
|
|
5
|
+
<path d="M26 0 L52 15 L52 45 L26 60 L0 45 L0 15 Z" fill="#8B5CF6" opacity="0.18"/>
|
|
6
|
+
<path d="M26 12 L41 21 L41 39 L26 48 L11 39 L11 21 Z" fill="#8B5CF6"/>
|
|
7
|
+
</g>
|
|
8
|
+
<text x="92" y="52" font-family="ui-monospace,SFMono-Regular,Menlo,monospace" font-size="22" fill="#F8FAFC" font-weight="700">@xemahq/worker-runtime-opencode</text>
|
|
9
|
+
<text x="92" y="80" font-family="ui-sans-serif,system-ui,sans-serif" font-size="15" fill="#94A3B8">Opencode driver for the worker-runtime contract</text>
|
|
10
|
+
<text x="652" y="105" text-anchor="end" font-family="ui-sans-serif,system-ui,sans-serif" font-size="12" fill="#475569">xema.dev</text>
|
|
11
|
+
</svg>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://xema.dev">Website</a> ·
|
|
16
|
+
<a href="https://www.npmjs.com/package/@xemahq/worker-runtime-opencode">npm</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img alt="npm" src="https://img.shields.io/npm/v/%40xemahq%2Fworker-runtime-opencode?color=2563eb&label=npm">
|
|
21
|
+
<img alt="license" src="https://img.shields.io/npm/l/%40xemahq%2Fworker-runtime-opencode?color=10b981">
|
|
22
|
+
<img alt="types" src="https://img.shields.io/npm/types/%40xemahq%2Fworker-runtime-opencode?color=3178c6">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
# @xemahq/worker-runtime-opencode
|
|
26
|
+
|
|
27
|
+
> Opencode driver for the worker-runtime contract
|
|
28
|
+
|
|
29
|
+
## Overview
|
|
30
|
+
|
|
31
|
+
An Opencode driver implementing the kernel worker-runtime contract. It is a thin
|
|
32
|
+
adapter over the existing workspace control plane, speaking the same HTTP and SSE
|
|
33
|
+
protocol it already exposes — no new wire format. A runtime instance is bound to
|
|
34
|
+
a single worker at construction time and translates session bundles, user
|
|
35
|
+
messages, and the event stream into the shared runtime interface so orchestration
|
|
36
|
+
stays runtime-agnostic.
|
|
37
|
+
|
|
38
|
+
## When to use it
|
|
39
|
+
|
|
40
|
+
- Use it to drive an Opencode-backed agent session behind the shared
|
|
41
|
+
worker-runtime interface.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pnpm add @xemahq/worker-runtime-opencode
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createOpencodeWorkerRuntime } from '@xemahq/worker-runtime-opencode';
|
|
53
|
+
|
|
54
|
+
const runtime = createOpencodeWorkerRuntime(config);
|
|
55
|
+
await runtime.sendUserMessage(message);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
Apache-2.0 © Xema — [xema.dev](https://xema.dev)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { OpencodeWorkerRuntime, OPENCODE_CONNECTOR_KIND, type OpencodePodSpec, } from './lib/opencode-worker-runtime';
|
|
2
|
+
export { createOpencodeWorkerRuntime } from './lib/factory';
|
|
3
|
+
export { buildOpencodeSessionBundle, computeBundleFingerprint, decodeOpencodeSessionBundle, type OpencodeBundleSubAgent, type OpencodeSessionBundlePayload, } from './lib/session-bundle';
|
|
4
|
+
export { parseSseChunk, translateProxyFrame, type ProxySseFrame, } from './lib/runtime-events';
|
|
5
|
+
export type { BundleCallerContext, OpencodeRuntimeConfig, WorkerRef, } from './lib/worker-ref';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,eAAe,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,GAClC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,mBAAmB,EACnB,qBAAqB,EACrB,SAAS,GACV,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateProxyFrame = exports.parseSseChunk = exports.decodeOpencodeSessionBundle = exports.computeBundleFingerprint = exports.buildOpencodeSessionBundle = exports.createOpencodeWorkerRuntime = exports.OPENCODE_CONNECTOR_KIND = exports.OpencodeWorkerRuntime = void 0;
|
|
4
|
+
var opencode_worker_runtime_1 = require("./lib/opencode-worker-runtime");
|
|
5
|
+
Object.defineProperty(exports, "OpencodeWorkerRuntime", { enumerable: true, get: function () { return opencode_worker_runtime_1.OpencodeWorkerRuntime; } });
|
|
6
|
+
Object.defineProperty(exports, "OPENCODE_CONNECTOR_KIND", { enumerable: true, get: function () { return opencode_worker_runtime_1.OPENCODE_CONNECTOR_KIND; } });
|
|
7
|
+
var factory_1 = require("./lib/factory");
|
|
8
|
+
Object.defineProperty(exports, "createOpencodeWorkerRuntime", { enumerable: true, get: function () { return factory_1.createOpencodeWorkerRuntime; } });
|
|
9
|
+
var session_bundle_1 = require("./lib/session-bundle");
|
|
10
|
+
Object.defineProperty(exports, "buildOpencodeSessionBundle", { enumerable: true, get: function () { return session_bundle_1.buildOpencodeSessionBundle; } });
|
|
11
|
+
Object.defineProperty(exports, "computeBundleFingerprint", { enumerable: true, get: function () { return session_bundle_1.computeBundleFingerprint; } });
|
|
12
|
+
Object.defineProperty(exports, "decodeOpencodeSessionBundle", { enumerable: true, get: function () { return session_bundle_1.decodeOpencodeSessionBundle; } });
|
|
13
|
+
var runtime_events_1 = require("./lib/runtime-events");
|
|
14
|
+
Object.defineProperty(exports, "parseSseChunk", { enumerable: true, get: function () { return runtime_events_1.parseSseChunk; } });
|
|
15
|
+
Object.defineProperty(exports, "translateProxyFrame", { enumerable: true, get: function () { return runtime_events_1.translateProxyFrame; } });
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,yEAIuC;AAHrC,gIAAA,qBAAqB,OAAA;AACrB,kIAAA,uBAAuB,OAAA;AAGzB,yCAA4D;AAAnD,sHAAA,2BAA2B,OAAA;AACpC,uDAM8B;AAL5B,4HAAA,0BAA0B,OAAA;AAC1B,0HAAA,wBAAwB,OAAA;AACxB,6HAAA,2BAA2B,OAAA;AAI7B,uDAI8B;AAH5B,+GAAA,aAAa,OAAA;AACb,qHAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { OpencodeWorkerRuntime } from './opencode-worker-runtime';
|
|
2
|
+
import type { OpencodeRuntimeConfig } from './worker-ref';
|
|
3
|
+
export declare function createOpencodeWorkerRuntime(config: OpencodeRuntimeConfig): OpencodeWorkerRuntime;
|
|
4
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/lib/factory.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAQ1D,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,qBAAqB,GAC5B,qBAAqB,CAGvB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOpencodeWorkerRuntime = createOpencodeWorkerRuntime;
|
|
4
|
+
const opencode_worker_runtime_1 = require("./opencode-worker-runtime");
|
|
5
|
+
function createOpencodeWorkerRuntime(config) {
|
|
6
|
+
validate(config);
|
|
7
|
+
return new opencode_worker_runtime_1.OpencodeWorkerRuntime(config);
|
|
8
|
+
}
|
|
9
|
+
function validate(config) {
|
|
10
|
+
const ref = config.workerRef;
|
|
11
|
+
if (!ref.workerId.trim()) {
|
|
12
|
+
throw new Error('OpencodeRuntimeConfig.workerRef.workerId is required.');
|
|
13
|
+
}
|
|
14
|
+
if (!ref.controlPlaneUrl.trim()) {
|
|
15
|
+
throw new Error('OpencodeRuntimeConfig.workerRef.controlPlaneUrl is required.');
|
|
16
|
+
}
|
|
17
|
+
if (!ref.region.trim()) {
|
|
18
|
+
throw new Error('OpencodeRuntimeConfig.workerRef.region is required.');
|
|
19
|
+
}
|
|
20
|
+
if (!ref.allocationId.trim()) {
|
|
21
|
+
throw new Error('OpencodeRuntimeConfig.workerRef.allocationId is required.');
|
|
22
|
+
}
|
|
23
|
+
if (!ref.workerServiceToken.trim()) {
|
|
24
|
+
throw new Error('OpencodeRuntimeConfig.workerRef.workerServiceToken is required.');
|
|
25
|
+
}
|
|
26
|
+
const caller = config.caller;
|
|
27
|
+
if (!caller.orgId.trim()) {
|
|
28
|
+
throw new Error('OpencodeRuntimeConfig.caller.orgId is required.');
|
|
29
|
+
}
|
|
30
|
+
if (!caller.projectId.trim()) {
|
|
31
|
+
throw new Error('OpencodeRuntimeConfig.caller.projectId is required.');
|
|
32
|
+
}
|
|
33
|
+
if (!caller.authToken.trim()) {
|
|
34
|
+
throw new Error('OpencodeRuntimeConfig.caller.authToken is required.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/lib/factory.ts"],"names":[],"mappings":";;AAkBA,kEAKC;AAdD,uEAAkE;AASlE,SAAgB,2BAA2B,CACzC,MAA6B;IAE7B,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjB,OAAO,IAAI,+CAAqB,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,QAAQ,CAAC,MAA6B;IAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC;IAC7B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACrF,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { WorkerRuntimeKind, type BuildBundleInput, type BuildPodSpecInput, type RuntimeEvent, type SessionBundle, type UserMessage, type WorkerRuntime, type WorkerRuntimeCapabilityBits } from '@xemahq/kernel-contracts/worker-runtime';
|
|
2
|
+
import type { AbstractMount } from '@xemahq/kernel-contracts/workspace-storage';
|
|
3
|
+
import { type ProxySseFrame } from './runtime-events';
|
|
4
|
+
import type { OpencodeRuntimeConfig } from './worker-ref';
|
|
5
|
+
export declare const OPENCODE_CONNECTOR_KIND = "opencode-default";
|
|
6
|
+
export interface OpencodePodSpec {
|
|
7
|
+
readonly runtimeKind: WorkerRuntimeKind;
|
|
8
|
+
readonly image: string;
|
|
9
|
+
readonly env: Readonly<Record<string, string>>;
|
|
10
|
+
readonly mounts: readonly AbstractMount[];
|
|
11
|
+
readonly region?: string;
|
|
12
|
+
readonly nodeAffinity?: {
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly values: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
readonly requestedCapabilities: BuildPodSpecInput['capabilities'];
|
|
17
|
+
}
|
|
18
|
+
export declare class OpencodeWorkerRuntime implements WorkerRuntime {
|
|
19
|
+
readonly kind = WorkerRuntimeKind.Opencode;
|
|
20
|
+
readonly capabilities: WorkerRuntimeCapabilityBits;
|
|
21
|
+
readonly connectorKindRequired = "opencode-default";
|
|
22
|
+
readonly autoCommitHookSupported = true;
|
|
23
|
+
private workerRef;
|
|
24
|
+
private opencodeSessionId?;
|
|
25
|
+
private caller;
|
|
26
|
+
constructor(config: OpencodeRuntimeConfig);
|
|
27
|
+
attachOpencodeSession(sessionId: string): void;
|
|
28
|
+
buildPodSpec(input: BuildPodSpecInput): Promise<OpencodePodSpec>;
|
|
29
|
+
buildSessionBundle(input: BuildBundleInput): Promise<SessionBundle>;
|
|
30
|
+
applySessionBundle(bundle: SessionBundle): Promise<void>;
|
|
31
|
+
sendUserMessage(message: UserMessage): AsyncIterable<RuntimeEvent>;
|
|
32
|
+
pause(): Promise<void>;
|
|
33
|
+
resume(): Promise<void>;
|
|
34
|
+
private authHeaders;
|
|
35
|
+
}
|
|
36
|
+
declare function joinUrl(base: string, path: string): string;
|
|
37
|
+
declare function iterateSseEvents(body: ReadableStream<Uint8Array>): AsyncGenerator<RuntimeEvent>;
|
|
38
|
+
export declare const __testInternals: {
|
|
39
|
+
iterateSseEvents: typeof iterateSseEvents;
|
|
40
|
+
joinUrl: typeof joinUrl;
|
|
41
|
+
};
|
|
42
|
+
export type { ProxySseFrame };
|
|
43
|
+
//# sourceMappingURL=opencode-worker-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-worker-runtime.d.ts","sourceRoot":"","sources":["../../src/lib/opencode-worker-runtime.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,iBAAiB,EACjB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,2BAA2B,EACjC,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAOhF,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,qBAAqB,EAAa,MAAM,cAAc,CAAC;AAarE,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAwB1D,MAAM,WAAW,eAAe;IAC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;IAe7B,OAAO,CAAC,WAAW;CAMpB;AAmDD,iBAAS,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAInD;AAQD,iBAAgB,gBAAgB,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAC/B,cAAc,CAAC,YAAY,CAAC,CAuC9B;AAGD,eAAO,MAAM,eAAe;;;CAG3B,CAAC;AAGF,YAAY,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__testInternals = exports.OpencodeWorkerRuntime = exports.OPENCODE_CONNECTOR_KIND = void 0;
|
|
4
|
+
const worker_runtime_1 = require("@xemahq/kernel-contracts/worker-runtime");
|
|
5
|
+
const session_bundle_1 = require("./session-bundle");
|
|
6
|
+
const runtime_events_1 = require("./runtime-events");
|
|
7
|
+
exports.OPENCODE_CONNECTOR_KIND = 'opencode-default';
|
|
8
|
+
const OPENCODE_CAPABILITIES = {
|
|
9
|
+
hotMcp: true,
|
|
10
|
+
hotModelSwap: true,
|
|
11
|
+
sessionFork: true,
|
|
12
|
+
subAgentCrud: true,
|
|
13
|
+
hooks: [
|
|
14
|
+
worker_runtime_1.HookKind.ToolExecuteBefore,
|
|
15
|
+
worker_runtime_1.HookKind.ToolExecuteAfter,
|
|
16
|
+
worker_runtime_1.HookKind.SessionIdle,
|
|
17
|
+
worker_runtime_1.HookKind.SessionStart,
|
|
18
|
+
],
|
|
19
|
+
previewSupervisor: true,
|
|
20
|
+
gatewayAttributedCalls: true,
|
|
21
|
+
llmEndpointOverride: true,
|
|
22
|
+
};
|
|
23
|
+
class OpencodeWorkerRuntime {
|
|
24
|
+
kind = worker_runtime_1.WorkerRuntimeKind.Opencode;
|
|
25
|
+
capabilities = OPENCODE_CAPABILITIES;
|
|
26
|
+
connectorKindRequired = exports.OPENCODE_CONNECTOR_KIND;
|
|
27
|
+
autoCommitHookSupported = true;
|
|
28
|
+
workerRef;
|
|
29
|
+
opencodeSessionId;
|
|
30
|
+
caller;
|
|
31
|
+
constructor(config) {
|
|
32
|
+
this.workerRef = config.workerRef;
|
|
33
|
+
if (config.opencodeSessionId !== undefined) {
|
|
34
|
+
this.opencodeSessionId = config.opencodeSessionId;
|
|
35
|
+
}
|
|
36
|
+
this.caller = config.caller;
|
|
37
|
+
}
|
|
38
|
+
attachOpencodeSession(sessionId) {
|
|
39
|
+
if (!sessionId.trim()) {
|
|
40
|
+
throw new Error('OpencodeWorkerRuntime: opencode session id must be non-empty.');
|
|
41
|
+
}
|
|
42
|
+
this.opencodeSessionId = sessionId;
|
|
43
|
+
}
|
|
44
|
+
buildPodSpec(input) {
|
|
45
|
+
const spec = {
|
|
46
|
+
runtimeKind: this.kind,
|
|
47
|
+
image: input.image,
|
|
48
|
+
env: input.env,
|
|
49
|
+
mounts: input.mounts,
|
|
50
|
+
...(input.region !== undefined ? { region: input.region } : {}),
|
|
51
|
+
...(input.region !== undefined
|
|
52
|
+
? {
|
|
53
|
+
nodeAffinity: {
|
|
54
|
+
key: 'topology.kubernetes.io/region',
|
|
55
|
+
values: [input.region],
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
59
|
+
requestedCapabilities: input.capabilities,
|
|
60
|
+
};
|
|
61
|
+
return Promise.resolve(spec);
|
|
62
|
+
}
|
|
63
|
+
async buildSessionBundle(input) {
|
|
64
|
+
const { bundle } = (0, session_bundle_1.buildOpencodeSessionBundle)(input, this.workerRef.allocationId, this.caller);
|
|
65
|
+
return bundle;
|
|
66
|
+
}
|
|
67
|
+
async applySessionBundle(bundle) {
|
|
68
|
+
const payload = (0, session_bundle_1.decodeOpencodeSessionBundle)(bundle);
|
|
69
|
+
const url = joinUrl(this.workerRef.controlPlaneUrl, '/control/session-bundle');
|
|
70
|
+
const response = await fetch(url, {
|
|
71
|
+
method: 'PUT',
|
|
72
|
+
headers: this.authHeaders(),
|
|
73
|
+
body: JSON.stringify(payload),
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const body = await safeReadText(response);
|
|
77
|
+
throw new Error(`applySessionBundle failed: HTTP ${response.status} from ${url} — ${body}`);
|
|
78
|
+
}
|
|
79
|
+
const parsed = (await response.json());
|
|
80
|
+
assertApplyResponseOk(parsed, payload);
|
|
81
|
+
}
|
|
82
|
+
async *sendUserMessage(message) {
|
|
83
|
+
if (!this.opencodeSessionId) {
|
|
84
|
+
throw new Error('OpencodeWorkerRuntime.sendUserMessage: no opencode session id attached. Call `attachOpencodeSession` after workspace-proxy reports opencode ready.');
|
|
85
|
+
}
|
|
86
|
+
const url = joinUrl(this.workerRef.controlPlaneUrl, '/session/prompt');
|
|
87
|
+
const requestBody = {
|
|
88
|
+
opencodeSessionId: this.opencodeSessionId,
|
|
89
|
+
actor: message.actor,
|
|
90
|
+
content: message.content,
|
|
91
|
+
...(message.attachments ? { attachments: message.attachments } : {}),
|
|
92
|
+
};
|
|
93
|
+
const response = await fetch(url, {
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: {
|
|
96
|
+
...this.authHeaders(),
|
|
97
|
+
Accept: 'text/event-stream',
|
|
98
|
+
},
|
|
99
|
+
body: JSON.stringify(requestBody),
|
|
100
|
+
});
|
|
101
|
+
if (!response.ok || !response.body) {
|
|
102
|
+
const body = await safeReadText(response);
|
|
103
|
+
throw new Error(`sendUserMessage failed: HTTP ${response.status} from ${url} — ${body}`);
|
|
104
|
+
}
|
|
105
|
+
yield* iterateSseEvents(response.body);
|
|
106
|
+
}
|
|
107
|
+
async pause() {
|
|
108
|
+
const url = joinUrl(this.workerRef.controlPlaneUrl, '/control/pause');
|
|
109
|
+
const body = {
|
|
110
|
+
allocationId: this.workerRef.allocationId,
|
|
111
|
+
};
|
|
112
|
+
const response = await fetch(url, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: this.authHeaders(),
|
|
115
|
+
body: JSON.stringify(body),
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
const text = await safeReadText(response);
|
|
119
|
+
throw new Error(`OpencodeWorkerRuntime.pause failed: HTTP ${response.status} from ${url} — ${text}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async resume() {
|
|
123
|
+
const url = joinUrl(this.workerRef.controlPlaneUrl, '/control/resume');
|
|
124
|
+
const response = await fetch(url, {
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers: this.authHeaders(),
|
|
127
|
+
body: JSON.stringify({}),
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
const text = await safeReadText(response);
|
|
131
|
+
throw new Error(`OpencodeWorkerRuntime.resume failed: HTTP ${response.status} from ${url} — ${text}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
authHeaders() {
|
|
135
|
+
return {
|
|
136
|
+
Authorization: `Bearer ${this.workerRef.workerServiceToken}`,
|
|
137
|
+
'Content-Type': 'application/json',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.OpencodeWorkerRuntime = OpencodeWorkerRuntime;
|
|
142
|
+
function assertApplyResponseOk(parsed, payload) {
|
|
143
|
+
if (parsed.unchanged === true)
|
|
144
|
+
return;
|
|
145
|
+
if (parsed.applied === true) {
|
|
146
|
+
const stateAllocationId = parsed.state?.allocationId ?? null;
|
|
147
|
+
if (stateAllocationId !== payload.allocationId) {
|
|
148
|
+
throw new Error(`applySessionBundle returned a state allocationId (${String(stateAllocationId)}) that disagrees with the requested allocationId (${payload.allocationId}). The worker rebound to another session — fail fast.`);
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`applySessionBundle: workspace-proxy returned an unexpected shape — ${JSON.stringify(parsed)}`);
|
|
153
|
+
}
|
|
154
|
+
async function safeReadText(response) {
|
|
155
|
+
try {
|
|
156
|
+
return await response.text();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return '<unreadable response body>';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function joinUrl(base, path) {
|
|
163
|
+
const trimmedBase = base.endsWith('/') ? base.slice(0, -1) : base;
|
|
164
|
+
const prefixedPath = path.startsWith('/') ? path : `/${path}`;
|
|
165
|
+
return `${trimmedBase}${prefixedPath}`;
|
|
166
|
+
}
|
|
167
|
+
async function* iterateSseEvents(body) {
|
|
168
|
+
const reader = body.getReader();
|
|
169
|
+
const decoder = new TextDecoder('utf-8');
|
|
170
|
+
let buffer = '';
|
|
171
|
+
try {
|
|
172
|
+
while (true) {
|
|
173
|
+
const { value, done } = await reader.read();
|
|
174
|
+
if (done)
|
|
175
|
+
break;
|
|
176
|
+
buffer += decoder.decode(value, { stream: true });
|
|
177
|
+
const { frames, remainder } = (0, runtime_events_1.parseSseChunk)(buffer);
|
|
178
|
+
buffer = remainder;
|
|
179
|
+
for (const frame of frames) {
|
|
180
|
+
const events = (0, runtime_events_1.translateProxyFrame)(frame);
|
|
181
|
+
for (const evt of events) {
|
|
182
|
+
yield evt;
|
|
183
|
+
if (evt.kind === 'turn-end' || evt.kind === 'error') {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const tail = buffer + decoder.decode();
|
|
190
|
+
if (tail.length > 0) {
|
|
191
|
+
const { frames } = (0, runtime_events_1.parseSseChunk)(tail.endsWith('\n\n') ? tail : `${tail}\n\n`);
|
|
192
|
+
for (const frame of frames) {
|
|
193
|
+
for (const evt of (0, runtime_events_1.translateProxyFrame)(frame)) {
|
|
194
|
+
yield evt;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
try {
|
|
201
|
+
reader.releaseLock();
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.__testInternals = {
|
|
208
|
+
iterateSseEvents,
|
|
209
|
+
joinUrl,
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=opencode-worker-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-worker-runtime.js","sourceRoot":"","sources":["../../src/lib/opencode-worker-runtime.ts"],"names":[],"mappings":";;;AAaA,4EAUiD;AAGjD,qDAI0B;AAC1B,qDAI0B;AAcb,QAAA,uBAAuB,GAAG,kBAAkB,CAAC;AAE1D,MAAM,qBAAqB,GAAgC;IACzD,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE;QACL,yBAAQ,CAAC,iBAAiB;QAC1B,yBAAQ,CAAC,gBAAgB;QACzB,yBAAQ,CAAC,WAAW;QACpB,yBAAQ,CAAC,YAAY;KACtB;IACD,iBAAiB,EAAE,IAAI;IACvB,sBAAsB,EAAE,IAAI;IAC5B,mBAAmB,EAAE,IAAI;CAC1B,CAAC;AA+BF,MAAa,qBAAqB;IACvB,IAAI,GAAG,kCAAiB,CAAC,QAAQ,CAAC;IAClC,YAAY,GAAG,qBAAqB,CAAC;IACrC,qBAAqB,GAAG,+BAAuB,CAAC;IAChD,uBAAuB,GAAG,IAAI,CAAC;IAEhC,SAAS,CAAY;IACrB,iBAAiB,CAAU;IAC3B,MAAM,CAAkC;IAEhD,YAAY,MAA6B;QACvC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,MAAM,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;YAC3C,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACpD,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAOD,qBAAqB,CAAC,SAAiB;QACrC,IAAI,CAAC,SAAS,C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AE,CAAC;wBACpD,OAAO;oBACT,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,8BAAa,EAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC;YAC/E,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;gBAC3B,KAAK,MAAM,GAAG,IAAI,IAAA,oCAAmB,EAAC,KAAK,CAAC,EAAE,CAAC;oBAC7C,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;QAGT,CAAC;IACH,CAAC;AACH,CAAC;AAGY,QAAA,eAAe,GAAG;IAC7B,gBAAgB;IAChB,OAAO;CACR,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RuntimeEvent } from '@xemahq/kernel-contracts/worker-runtime';
|
|
2
|
+
export interface ProxySseFrame {
|
|
3
|
+
readonly event: string;
|
|
4
|
+
readonly data: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare function translateProxyFrame(frame: ProxySseFrame): readonly RuntimeEvent[];
|
|
7
|
+
export declare function parseSseChunk(buffer: string): {
|
|
8
|
+
readonly frames: readonly ProxySseFrame[];
|
|
9
|
+
readonly remainder: string;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=runtime-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-events.d.ts","sourceRoot":"","sources":["../../src/lib/runtime-events.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAO5E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAOD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,YAAY,EAAE,CAMjF;AAWD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG;IAC7C,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAYA"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateProxyFrame = translateProxyFrame;
|
|
4
|
+
exports.parseSseChunk = parseSseChunk;
|
|
5
|
+
function translateProxyFrame(frame) {
|
|
6
|
+
if (frame.event === 'opencode_error') {
|
|
7
|
+
return [translateError(frame.data)];
|
|
8
|
+
}
|
|
9
|
+
if (frame.event !== 'opencode_event')
|
|
10
|
+
return [];
|
|
11
|
+
return translateOpencodeEvent(frame.data);
|
|
12
|
+
}
|
|
13
|
+
function parseSseChunk(buffer) {
|
|
14
|
+
const frames = [];
|
|
15
|
+
let cursor = 0;
|
|
16
|
+
while (true) {
|
|
17
|
+
const boundary = buffer.indexOf('\n\n', cursor);
|
|
18
|
+
if (boundary === -1)
|
|
19
|
+
break;
|
|
20
|
+
const raw = buffer.slice(cursor, boundary);
|
|
21
|
+
cursor = boundary + 2;
|
|
22
|
+
const frame = parseSingleFrame(raw);
|
|
23
|
+
if (frame)
|
|
24
|
+
frames.push(frame);
|
|
25
|
+
}
|
|
26
|
+
return { frames, remainder: buffer.slice(cursor) };
|
|
27
|
+
}
|
|
28
|
+
function parseSingleFrame(raw) {
|
|
29
|
+
let event = 'message';
|
|
30
|
+
const dataLines = [];
|
|
31
|
+
for (const line of raw.split('\n')) {
|
|
32
|
+
if (!line || line.startsWith(':'))
|
|
33
|
+
continue;
|
|
34
|
+
const colon = line.indexOf(':');
|
|
35
|
+
if (colon === -1)
|
|
36
|
+
continue;
|
|
37
|
+
const field = line.slice(0, colon);
|
|
38
|
+
const value = line.charAt(colon + 1) === ' '
|
|
39
|
+
? line.slice(colon + 2)
|
|
40
|
+
: line.slice(colon + 1);
|
|
41
|
+
if (field === 'event')
|
|
42
|
+
event = value;
|
|
43
|
+
else if (field === 'data')
|
|
44
|
+
dataLines.push(value);
|
|
45
|
+
}
|
|
46
|
+
if (dataLines.length === 0)
|
|
47
|
+
return null;
|
|
48
|
+
const dataString = dataLines.join('\n');
|
|
49
|
+
let data;
|
|
50
|
+
try {
|
|
51
|
+
data = JSON.parse(dataString);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return { event, data };
|
|
57
|
+
}
|
|
58
|
+
function translateError(data) {
|
|
59
|
+
const obj = (data && typeof data === 'object' ? data : {});
|
|
60
|
+
const messageRaw = obj['message'] ?? obj['error'] ?? 'opencode error';
|
|
61
|
+
const message = typeof messageRaw === 'string' ? messageRaw : JSON.stringify(messageRaw);
|
|
62
|
+
const retryableRaw = obj['retryable'];
|
|
63
|
+
const retryable = typeof retryableRaw === 'boolean' ? retryableRaw : false;
|
|
64
|
+
return { kind: 'error', message, retryable };
|
|
65
|
+
}
|
|
66
|
+
function translateOpencodeEvent(data) {
|
|
67
|
+
if (!data || typeof data !== 'object')
|
|
68
|
+
return [];
|
|
69
|
+
const evt = data;
|
|
70
|
+
const type = typeof evt.type === 'string' ? evt.type : '';
|
|
71
|
+
const props = evt.properties && typeof evt.properties === 'object'
|
|
72
|
+
? evt.properties
|
|
73
|
+
: {};
|
|
74
|
+
switch (type) {
|
|
75
|
+
case 'message.part.updated':
|
|
76
|
+
return translatePartUpdated(props);
|
|
77
|
+
case 'session.idle':
|
|
78
|
+
return [{ kind: 'turn-end' }];
|
|
79
|
+
case 'session.error':
|
|
80
|
+
case 'message.error':
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
kind: 'error',
|
|
84
|
+
message: typeof props['message'] === 'string'
|
|
85
|
+
? props['message']
|
|
86
|
+
: `opencode ${type}`,
|
|
87
|
+
retryable: false,
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
default:
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function translatePartUpdated(props) {
|
|
95
|
+
const part = (props['part'] ?? {});
|
|
96
|
+
const partType = typeof part['type'] === 'string' ? part['type'] : '';
|
|
97
|
+
if (partType === 'text') {
|
|
98
|
+
const text = typeof part['text'] === 'string' ? part['text'] : '';
|
|
99
|
+
return text ? [{ kind: 'text-delta', text }] : [];
|
|
100
|
+
}
|
|
101
|
+
if (partType === 'tool') {
|
|
102
|
+
const tool = typeof part['tool'] === 'string' ? part['tool'] : '';
|
|
103
|
+
if (!tool)
|
|
104
|
+
return [];
|
|
105
|
+
const state = (part['state'] ?? {});
|
|
106
|
+
const status = typeof state['status'] === 'string' ? state['status'] : '';
|
|
107
|
+
if (status === 'running' || status === 'pending') {
|
|
108
|
+
return [{ kind: 'tool-use', tool, input: state['input'] ?? null }];
|
|
109
|
+
}
|
|
110
|
+
if (status === 'completed' || status === 'success') {
|
|
111
|
+
return [
|
|
112
|
+
{
|
|
113
|
+
kind: 'tool-result',
|
|
114
|
+
tool,
|
|
115
|
+
output: state['output'] ?? state['result'] ?? null,
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
if (status === 'error' || status === 'failed') {
|
|
120
|
+
const msgRaw = state['error'] ?? state['message'] ?? `tool ${tool} failed`;
|
|
121
|
+
const message = typeof msgRaw === 'string' ? msgRaw : JSON.stringify(msgRaw);
|
|
122
|
+
return [{ kind: 'error', message, retryable: false }];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=runtime-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-events.js","sourceRoot":"","sources":["../../src/lib/runtime-events.ts"],"names":[],"mappings":";;AAkCA,kDAMC;AAWD,sCAeC;AAhCD,SAAgB,mBAAmB,CAAC,KAAoB;IACtD,IAAI,KAAK,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;QACrC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,KAAK,CAAC,KAAK,KAAK,gBAAgB;QAAE,OAAO,EAAE,CAAC;IAChD,OAAO,sBAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAWD,SAAgB,aAAa,CAAC,MAAc;IAI1C,MAAM,MAAM,GAAoB,EAAE,CAAC;IACnC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChD,IAAI,QAAQ,KAAK,CAAC,CAAC;YAAE,MAAM;QAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC3C,MAAM,GAAG,QAAQ,GAAG,CAAC,CAAC;QACtB,MAAM,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAW;IACnC,IAAI,KAAK,GAAG,SAAS,CAAC;IACtB,MAAM,SAAS,GAAa,EAAE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K,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACjD,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACnD,OAAO;gBACL;oBACE,IAAI,EAAE,aAAa;oBACnB,IAAI;oBACJ,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,IAAI;iBACnD;aACF,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,QAAQ,IAAI,SAAS,CAAC;YAC3E,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC7E,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BuildBundleInput, SessionBundle } from '@xemahq/kernel-contracts/worker-runtime';
|
|
2
|
+
import type { BundleCallerContext } from './worker-ref';
|
|
3
|
+
export interface OpencodeBundleSubAgent {
|
|
4
|
+
readonly slug: string;
|
|
5
|
+
readonly alias?: string;
|
|
6
|
+
readonly phaseKey?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface OpencodeSessionBundlePayload {
|
|
9
|
+
readonly allocationId: string;
|
|
10
|
+
readonly caller: BundleCallerContext;
|
|
11
|
+
readonly opencodeConfigBase64: string;
|
|
12
|
+
readonly primaryAgent: {
|
|
13
|
+
readonly slug: string;
|
|
14
|
+
};
|
|
15
|
+
readonly subAgents: readonly OpencodeBundleSubAgent[];
|
|
16
|
+
readonly modelOverride?: string;
|
|
17
|
+
readonly mcpConfig?: string;
|
|
18
|
+
readonly fingerprint: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function computeBundleFingerprint(input: BuildBundleInput): string;
|
|
21
|
+
export declare function buildOpencodeSessionBundle(input: BuildBundleInput, allocationId: string, caller: BundleCallerContext): {
|
|
22
|
+
readonly payload: OpencodeSessionBundlePayload;
|
|
23
|
+
readonly bundle: SessionBundle;
|
|
24
|
+
};
|
|
25
|
+
export declare function decodeOpencodeSessionBundle(bundle: SessionBundle): OpencodeSessionBundlePayload;
|
|
26
|
+
//# sourceMappingURL=session-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-bundle.d.ts","sourceRoot":"","sources":["../../src/lib/session-bundle.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAQxD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAMD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;IACrC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACtD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AA8BD,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,gBAAgB,GACtB,MAAM,CAYR;AAQD,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,EACvB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,mBAAmB,GAC1B;IAAE,QAAQ,CAAC,OAAO,EAAE,4BAA4B,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CA2CpF;AAQD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,aAAa,GACpB,4BAA4B,CAqB9B"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeBundleFingerprint = computeBundleFingerprint;
|
|
4
|
+
exports.buildOpencodeSessionBundle = buildOpencodeSessionBundle;
|
|
5
|
+
exports.decodeOpencodeSessionBundle = decodeOpencodeSessionBundle;
|
|
6
|
+
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
function canonicalize(value) {
|
|
8
|
+
if (value === null || typeof value !== 'object')
|
|
9
|
+
return value;
|
|
10
|
+
if (Array.isArray(value))
|
|
11
|
+
return value.map((v) => canonicalize(v));
|
|
12
|
+
const obj = value;
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const key of Object.keys(obj).sort()) {
|
|
15
|
+
const v = obj[key];
|
|
16
|
+
if (v === undefined)
|
|
17
|
+
continue;
|
|
18
|
+
out[key] = canonicalize(v);
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
function computeBundleFingerprint(input) {
|
|
23
|
+
const sortedSubAgents = [...input.subAgents].sort();
|
|
24
|
+
const canonical = canonicalize({
|
|
25
|
+
primaryAgent: input.primaryAgent,
|
|
26
|
+
subAgents: sortedSubAgents,
|
|
27
|
+
modelOverride: input.modelOverride,
|
|
28
|
+
opencodeConfigBase64: input.opencodeConfigBase64,
|
|
29
|
+
mcpConfig: input.mcpConfig,
|
|
30
|
+
});
|
|
31
|
+
const hash = (0, node_crypto_1.createHash)('sha256');
|
|
32
|
+
hash.update(JSON.stringify(canonical));
|
|
33
|
+
return hash.digest('hex');
|
|
34
|
+
}
|
|
35
|
+
function buildOpencodeSessionBundle(input, allocationId, caller) {
|
|
36
|
+
if (!input.primaryAgent.trim()) {
|
|
37
|
+
throw new Error('BuildBundleInput.primaryAgent must be a non-empty slug.');
|
|
38
|
+
}
|
|
39
|
+
if (!allocationId.trim()) {
|
|
40
|
+
throw new Error('allocationId must be a non-empty string.');
|
|
41
|
+
}
|
|
42
|
+
const opencodeConfigBase64 = input.opencodeConfigBase64 ?? '';
|
|
43
|
+
if (!opencodeConfigBase64) {
|
|
44
|
+
throw new Error('BuildBundleInput.opencodeConfigBase64 is required by the opencode runtime — the workspace-proxy bundle handler treats an empty config as a 400.');
|
|
45
|
+
}
|
|
46
|
+
const fingerprint = computeBundleFingerprint(input);
|
|
47
|
+
const subAgents = input.subAgents.map((slug) => ({ slug }));
|
|
48
|
+
const payload = {
|
|
49
|
+
allocationId,
|
|
50
|
+
caller,
|
|
51
|
+
opencodeConfigBase64,
|
|
52
|
+
primaryAgent: { slug: input.primaryAgent },
|
|
53
|
+
subAgents,
|
|
54
|
+
fingerprint,
|
|
55
|
+
...(input.modelOverride === undefined
|
|
56
|
+
? {}
|
|
57
|
+
: { modelOverride: input.modelOverride }),
|
|
58
|
+
...(input.mcpConfig === undefined ? {} : { mcpConfig: input.mcpConfig }),
|
|
59
|
+
};
|
|
60
|
+
const payloadJson = JSON.stringify(payload);
|
|
61
|
+
const payloadBase64 = Buffer.from(payloadJson, 'utf8').toString('base64');
|
|
62
|
+
return {
|
|
63
|
+
payload,
|
|
64
|
+
bundle: { fingerprint, payloadBase64 },
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function decodeOpencodeSessionBundle(bundle) {
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
const json = Buffer.from(bundle.payloadBase64, 'base64').toString('utf8');
|
|
71
|
+
parsed = JSON.parse(json);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
75
|
+
throw new Error(`SessionBundle.payloadBase64 is not a valid base64-encoded JSON object: ${msg}`);
|
|
76
|
+
}
|
|
77
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
78
|
+
throw new Error('SessionBundle payload must decode to a JSON object.');
|
|
79
|
+
}
|
|
80
|
+
const obj = parsed;
|
|
81
|
+
if (obj.fingerprint !== bundle.fingerprint) {
|
|
82
|
+
throw new Error(`SessionBundle.fingerprint (${bundle.fingerprint}) disagrees with the encoded payload.fingerprint (${String(obj.fingerprint)}). Refusing to apply a tampered bundle.`);
|
|
83
|
+
}
|
|
84
|
+
return parsed;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=session-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-bundle.js","sourceRoot":"","sources":["../../src/lib/session-bundle.ts"],"names":[],"mappings":";;AA+EA,4DAcC;AAQD,gEA+CC;AAQD,kEAuBC;AApKD,6CAAyC;AAyCzC,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC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M,CAAC,CAAC;QAC1E,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7D,MAAM,IAAI,KAAK,CACb,0EAA0E,GAAG,EAAE,CAChF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,GAAG,GAAG,MAA4C,CAAC;IACzD,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,8BAA8B,MAAM,CAAC,WAAW,qDAAqD,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,yCAAyC,CACtK,CAAC;IACJ,CAAC;IACD,OAAO,MAAsC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface WorkerRef {
|
|
2
|
+
readonly workerId: string;
|
|
3
|
+
readonly controlPlaneUrl: string;
|
|
4
|
+
readonly region: string;
|
|
5
|
+
readonly allocationId: string;
|
|
6
|
+
readonly workerServiceToken: string;
|
|
7
|
+
}
|
|
8
|
+
export interface OpencodeRuntimeConfig {
|
|
9
|
+
readonly workerRef: WorkerRef;
|
|
10
|
+
readonly opencodeSessionId?: string;
|
|
11
|
+
readonly caller: BundleCallerContext;
|
|
12
|
+
}
|
|
13
|
+
export interface BundleCallerContext {
|
|
14
|
+
readonly orgId: string;
|
|
15
|
+
readonly projectId: string;
|
|
16
|
+
readonly sessionId?: string;
|
|
17
|
+
readonly authToken: string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=worker-ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-ref.d.ts","sourceRoot":"","sources":["../../src/lib/worker-ref.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,SAAS;IAExB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAO1B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAMxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAQ9B,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;CACrC;AASD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAO9B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAQpC,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAC;CACtC;AAQD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-ref.js","sourceRoot":"","sources":["../../src/lib/worker-ref.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xemahq/worker-runtime-opencode",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Opencode WorkerRuntime driver — wraps the workspace-proxy /control/session-bundle handshake and the opencode SSE event stream behind the kernel WorkerRuntime contract (Phase A.4 of xema-os-plan §1 WorkerRuntime).",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://npm.pkg.github.com"
|
|
7
|
+
},
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@xemahq/kernel-contracts": "^0.2.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/jest": "^30.0.0",
|
|
18
|
+
"@types/node": "25.2.3",
|
|
19
|
+
"jest": "^30.3.0",
|
|
20
|
+
"prettier": "3.6.2",
|
|
21
|
+
"ts-jest": "^29.4.9",
|
|
22
|
+
"typescript": "5.9.3"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"xema-source": "./src/index.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./dist/lib/*": {
|
|
31
|
+
"types": "./dist/lib/*.d.ts",
|
|
32
|
+
"default": "./dist/lib/*.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"clean": "rm -rf dist",
|
|
37
|
+
"build": "tsc -p tsconfig.json",
|
|
38
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
39
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
40
|
+
"test": "jest --config jest.config.ts"
|
|
41
|
+
}
|
|
42
|
+
}
|