@radheim/protocol 0.0.0-stage → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/api.d.ts +60 -0
  2. package/dist/api.js +81 -0
  3. package/dist/client.d.ts +69 -0
  4. package/dist/client.js +102 -0
  5. package/dist/errors.d.ts +273 -0
  6. package/dist/errors.js +227 -0
  7. package/dist/groups/agent.d.ts +299 -0
  8. package/dist/groups/agent.js +30 -0
  9. package/dist/groups/artifact.d.ts +173 -0
  10. package/dist/groups/artifact.js +80 -0
  11. package/dist/groups/automation.d.ts +480 -0
  12. package/dist/groups/automation.js +55 -0
  13. package/dist/groups/blob.d.ts +415 -0
  14. package/dist/groups/blob.js +79 -0
  15. package/dist/groups/command.d.ts +15 -0
  16. package/dist/groups/command.js +20 -0
  17. package/dist/groups/config.d.ts +27 -0
  18. package/dist/groups/config.js +32 -0
  19. package/dist/groups/credential.d.ts +93 -0
  20. package/dist/groups/credential.js +50 -0
  21. package/dist/groups/debug.d.ts +22 -0
  22. package/dist/groups/debug.js +49 -0
  23. package/dist/groups/event.d.ts +16442 -0
  24. package/dist/groups/event.js +68 -0
  25. package/dist/groups/experimental/browser-tunnel.d.ts +20 -0
  26. package/dist/groups/experimental/browser-tunnel.js +29 -0
  27. package/dist/groups/experimental.d.ts +1519 -0
  28. package/dist/groups/experimental.js +12 -0
  29. package/dist/groups/flag.d.ts +12 -0
  30. package/dist/groups/flag.js +19 -0
  31. package/dist/groups/form.d.ts +138 -0
  32. package/dist/groups/form.js +18 -0
  33. package/dist/groups/fs.d.ts +60 -0
  34. package/dist/groups/fs.js +101 -0
  35. package/dist/groups/generate.d.ts +397 -0
  36. package/dist/groups/generate.js +77 -0
  37. package/dist/groups/integration.d.ts +1724 -0
  38. package/dist/groups/integration.js +169 -0
  39. package/dist/groups/job.d.ts +95 -0
  40. package/dist/groups/job.js +45 -0
  41. package/dist/groups/location.d.ts +23 -0
  42. package/dist/groups/location.js +47 -0
  43. package/dist/groups/machine.d.ts +91 -0
  44. package/dist/groups/machine.js +61 -0
  45. package/dist/groups/mcp.d.ts +104 -0
  46. package/dist/groups/mcp.js +125 -0
  47. package/dist/groups/media.d.ts +8 -0
  48. package/dist/groups/media.js +18 -0
  49. package/dist/groups/message.d.ts +3696 -0
  50. package/dist/groups/message.js +102 -0
  51. package/dist/groups/migration.d.ts +28 -0
  52. package/dist/groups/migration.js +21 -0
  53. package/dist/groups/model.d.ts +536 -0
  54. package/dist/groups/model.js +39 -0
  55. package/dist/groups/permission.d.ts +175 -0
  56. package/dist/groups/permission.js +115 -0
  57. package/dist/groups/persistent-pty.d.ts +251 -0
  58. package/dist/groups/persistent-pty.js +109 -0
  59. package/dist/groups/plugin.d.ts +102 -0
  60. package/dist/groups/plugin.js +59 -0
  61. package/dist/groups/project.d.ts +83 -0
  62. package/dist/groups/project.js +37 -0
  63. package/dist/groups/provider.d.ts +354 -0
  64. package/dist/groups/provider.js +34 -0
  65. package/dist/groups/pty.d.ts +151 -0
  66. package/dist/groups/pty.js +117 -0
  67. package/dist/groups/push.d.ts +123 -0
  68. package/dist/groups/push.js +60 -0
  69. package/dist/groups/reference.d.ts +25 -0
  70. package/dist/groups/reference.js +33 -0
  71. package/dist/groups/rpc.d.ts +21 -0
  72. package/dist/groups/rpc.js +24 -0
  73. package/dist/groups/server.d.ts +46 -0
  74. package/dist/groups/server.js +55 -0
  75. package/dist/groups/session.d.ts +11874 -0
  76. package/dist/groups/session.js +663 -0
  77. package/dist/groups/shell.d.ts +125 -0
  78. package/dist/groups/shell.js +65 -0
  79. package/dist/groups/skill.d.ts +26 -0
  80. package/dist/groups/skill.js +34 -0
  81. package/dist/groups/space.d.ts +56 -0
  82. package/dist/groups/space.js +59 -0
  83. package/dist/groups/usage.d.ts +96 -0
  84. package/dist/groups/usage.js +22 -0
  85. package/dist/groups/vcs.d.ts +89 -0
  86. package/dist/groups/vcs.js +94 -0
  87. package/dist/groups/voice.d.ts +81 -0
  88. package/dist/groups/voice.js +75 -0
  89. package/dist/groups/websearch.d.ts +29 -0
  90. package/dist/groups/websearch.js +34 -0
  91. package/dist/groups/worktree.d.ts +41 -0
  92. package/dist/groups/worktree.js +52 -0
  93. package/dist/middleware/authorization.d.ts +13 -0
  94. package/dist/middleware/authorization.js +6 -0
  95. package/dist/middleware/schema-error.d.ts +13 -0
  96. package/dist/middleware/schema-error.js +4 -0
  97. package/dist/simulation/image.d.ts +35 -0
  98. package/dist/simulation/image.js +21 -0
  99. package/dist/simulation/terminal.d.ts +81 -0
  100. package/dist/simulation/terminal.js +49 -0
  101. package/dist/simulation.d.ts +1784 -0
  102. package/dist/simulation.js +485 -0
  103. package/package.json +46 -4
  104. package/README.md +0 -3
@@ -0,0 +1,485 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Rpc, RpcGroup } from "effect/rpc";
3
+ const JsonRpcID = Schema.Union([Schema.String, Schema.Number, Schema.Null]);
4
+ const decodeJson = Schema.decodeUnknownSync(Schema.Json);
5
+ export var JsonRpc;
6
+ (function (JsonRpc) {
7
+ JsonRpc.RequestFields = {
8
+ jsonrpc: Schema.Literal("2.0"),
9
+ id: Schema.optional(JsonRpcID),
10
+ };
11
+ JsonRpc.Request = Schema.Struct({
12
+ ...JsonRpc.RequestFields,
13
+ method: Schema.String,
14
+ params: Schema.optional(Schema.Json),
15
+ });
16
+ JsonRpc.ErrorObject = Schema.Struct({
17
+ code: Schema.Number,
18
+ message: Schema.String,
19
+ data: Schema.optional(Schema.Json),
20
+ });
21
+ JsonRpc.Response = Schema.Union([
22
+ Schema.Struct({
23
+ jsonrpc: Schema.Literal("2.0"),
24
+ id: JsonRpcID,
25
+ result: Schema.Json,
26
+ error: Schema.optionalKey(Schema.Never),
27
+ }),
28
+ Schema.Struct({
29
+ jsonrpc: Schema.Literal("2.0"),
30
+ id: JsonRpcID,
31
+ result: Schema.optionalKey(Schema.Never),
32
+ error: JsonRpc.ErrorObject,
33
+ }),
34
+ ], { mode: "oneOf" });
35
+ JsonRpc.decodeRequest = Schema.decodeUnknownSync(JsonRpc.Request);
36
+ function success(id, result) {
37
+ if (id === undefined)
38
+ return undefined;
39
+ return { jsonrpc: "2.0", id, result: decodeJson(result) };
40
+ }
41
+ JsonRpc.success = success;
42
+ function failure(id, error) {
43
+ return {
44
+ jsonrpc: "2.0",
45
+ id: id ?? null,
46
+ error: {
47
+ code: -32000,
48
+ message: error instanceof Error ? error.message : String(error),
49
+ },
50
+ };
51
+ }
52
+ JsonRpc.failure = failure;
53
+ })(JsonRpc || (JsonRpc = {}));
54
+ export class SimulationRequestError extends Schema.TaggedError()("SimulationRequestError", {
55
+ method: Schema.String,
56
+ code: Schema.Number,
57
+ message: Schema.String,
58
+ data: Schema.optionalKey(Schema.Json),
59
+ }) {
60
+ }
61
+ /** One simulation RPC: every request fails with `SimulationRequestError`. Surface modules build their groups with it. */
62
+ export const request = (tag, options) => Rpc.make(tag, { ...options, error: SimulationRequestError });
63
+ export var Handshake;
64
+ (function (Handshake) {
65
+ Handshake.ProtocolVersion = Schema.Literal(1);
66
+ Handshake.Capability = Schema.NonEmptyString;
67
+ Handshake.EndpointRole = Schema.Literals(["ui", "backend"]);
68
+ /**
69
+ * What a `ui` endpoint draws, declared in its handshake response. Each surface has a schema module next to
70
+ * this one (`simulation/terminal`, `simulation/image`) with its own capabilities and RPC group; a new surface
71
+ * adds a module. Absent means `DefaultSurface`, so endpoints from before surfaces keep working.
72
+ */
73
+ Handshake.Surface = Schema.NonEmptyString;
74
+ Handshake.DefaultSurface = "terminal";
75
+ /** The surface a handshake response declares. */
76
+ Handshake.surfaceOf = (response) => response.surface ?? Handshake.DefaultSurface;
77
+ Handshake.Identity = Schema.Struct({
78
+ name: Schema.NonEmptyString,
79
+ version: Schema.NonEmptyString,
80
+ });
81
+ Handshake.Params = Schema.Struct({
82
+ client: Handshake.Identity,
83
+ expectedRole: Handshake.EndpointRole,
84
+ offeredVersions: Schema.Array(Schema.Int.check(Schema.isGreaterThan(0))).check(Schema.isMinLength(1), Schema.isUnique()),
85
+ requiredCapabilities: Schema.Array(Handshake.Capability).check(Schema.isUnique()),
86
+ optionalCapabilities: Schema.Array(Handshake.Capability).check(Schema.isUnique()),
87
+ });
88
+ Handshake.Response = Schema.Struct({
89
+ protocolVersion: Handshake.ProtocolVersion,
90
+ role: Handshake.EndpointRole,
91
+ server: Handshake.Identity,
92
+ capabilities: Schema.Array(Handshake.Capability).check(Schema.isUnique()),
93
+ surface: Schema.optionalKey(Handshake.Surface),
94
+ });
95
+ Handshake.Request = Schema.Struct({
96
+ ...JsonRpc.RequestFields,
97
+ method: Schema.Literal("simulation.handshake"),
98
+ params: Handshake.Params,
99
+ });
100
+ class RoleMismatchError extends Schema.TaggedError()("SimulationHandshake.RoleMismatchError", {
101
+ expected: Handshake.EndpointRole,
102
+ actual: Handshake.EndpointRole,
103
+ message: Schema.String,
104
+ }) {
105
+ }
106
+ Handshake.RoleMismatchError = RoleMismatchError;
107
+ class UnsupportedProtocolError extends Schema.TaggedError()("SimulationHandshake.UnsupportedProtocolError", {
108
+ offered: Schema.Array(Schema.Number),
109
+ supported: Schema.Array(Handshake.ProtocolVersion),
110
+ message: Schema.String,
111
+ }) {
112
+ }
113
+ Handshake.UnsupportedProtocolError = UnsupportedProtocolError;
114
+ class MissingCapabilityError extends Schema.TaggedError()("SimulationHandshake.MissingCapabilityError", {
115
+ missing: Schema.Array(Handshake.Capability),
116
+ message: Schema.String,
117
+ }) {
118
+ }
119
+ Handshake.MissingCapabilityError = MissingCapabilityError;
120
+ function dispatch(action, params) {
121
+ return Effect.gen(function* () {
122
+ if (params.expectedRole !== action.role) {
123
+ return yield* Effect.fail(new RoleMismatchError({
124
+ expected: params.expectedRole,
125
+ actual: action.role,
126
+ message: `Expected simulation endpoint role ${params.expectedRole}, received ${action.role}`,
127
+ }));
128
+ }
129
+ if (!params.offeredVersions.includes(1)) {
130
+ return yield* Effect.fail(new UnsupportedProtocolError({
131
+ offered: params.offeredVersions,
132
+ supported: [1],
133
+ message: "No mutually supported simulation protocol version",
134
+ }));
135
+ }
136
+ const installed = new Set(action.capabilities);
137
+ const missing = params.requiredCapabilities.filter((capability) => !installed.has(capability));
138
+ if (missing.length > 0) {
139
+ return yield* Effect.fail(new MissingCapabilityError({
140
+ missing,
141
+ message: `Simulation endpoint is missing required capabilities: ${missing.join(", ")}`,
142
+ }));
143
+ }
144
+ return {
145
+ protocolVersion: 1,
146
+ role: action.role,
147
+ server: action.server,
148
+ capabilities: Array.from(installed),
149
+ ...(action.surface === undefined ? {} : { surface: action.surface }),
150
+ };
151
+ });
152
+ }
153
+ Handshake.dispatch = dispatch;
154
+ })(Handshake || (Handshake = {}));
155
+ /**
156
+ * The core frontend protocol: methods that mean the same on every surface. Coordinates and sizes (`ui.mouse`,
157
+ * `ui.click`, `ui.resize`, `Element`) are in the surface's units: cells for a terminal, logical points for an
158
+ * image. Surface-specific methods (frame capture, recording) live in that surface's module.
159
+ */
160
+ export var Frontend;
161
+ (function (Frontend) {
162
+ Frontend.Capabilities = [
163
+ "ui.type",
164
+ "ui.press",
165
+ "ui.enter",
166
+ "ui.arrow",
167
+ "ui.focus",
168
+ "ui.click",
169
+ "ui.click.semantic",
170
+ "ui.mouse",
171
+ "ui.resize",
172
+ "ui.matches",
173
+ "ui.state",
174
+ "ui.snapshot",
175
+ ];
176
+ Frontend.KeyModifiers = Schema.Struct({
177
+ ctrl: Schema.optional(Schema.Boolean),
178
+ shift: Schema.optional(Schema.Boolean),
179
+ meta: Schema.optional(Schema.Boolean),
180
+ super: Schema.optional(Schema.Boolean),
181
+ hyper: Schema.optional(Schema.Boolean),
182
+ });
183
+ Frontend.SemanticClickTarget = Schema.Struct({
184
+ id: Schema.NonEmptyString,
185
+ instance: Schema.optionalKey(Schema.NonEmptyString),
186
+ element: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)),
187
+ });
188
+ const MousePosition = {
189
+ x: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
190
+ y: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
191
+ modifiers: Schema.optionalKey(Schema.Struct({
192
+ shift: Schema.optionalKey(Schema.Boolean),
193
+ alt: Schema.optionalKey(Schema.Boolean),
194
+ ctrl: Schema.optionalKey(Schema.Boolean),
195
+ })),
196
+ };
197
+ Frontend.MouseParams = Schema.Union([
198
+ Schema.Struct({ ...MousePosition, action: Schema.Literal("move") }),
199
+ Schema.Struct({
200
+ ...MousePosition,
201
+ action: Schema.Literals(["down", "up"]),
202
+ button: Schema.optionalKey(Schema.Literals(["left", "middle", "right"])),
203
+ }),
204
+ Schema.Struct({
205
+ ...MousePosition,
206
+ action: Schema.Literal("scroll"),
207
+ direction: Schema.Literals(["up", "down", "left", "right"]),
208
+ }),
209
+ ]);
210
+ Frontend.Action = Schema.Union([
211
+ Schema.Struct({ type: Schema.Literal("ui.type"), text: Schema.String }),
212
+ Schema.Struct({ type: Schema.Literal("ui.press"), key: Schema.String, modifiers: Schema.optional(Frontend.KeyModifiers) }),
213
+ Schema.Struct({ type: Schema.Literal("ui.enter") }),
214
+ Schema.Struct({ type: Schema.Literal("ui.arrow"), direction: Schema.Literals(["up", "down", "left", "right"]) }),
215
+ Schema.Struct({ type: Schema.Literal("ui.focus"), target: Schema.Number }),
216
+ Schema.Struct({ type: Schema.Literal("ui.mouse"), params: Frontend.MouseParams }),
217
+ Schema.Struct({
218
+ type: Schema.Literal("ui.click"),
219
+ target: Schema.Number,
220
+ x: Schema.Number,
221
+ y: Schema.Number,
222
+ semantic: Schema.optionalKey(Frontend.SemanticClickTarget),
223
+ }),
224
+ Schema.Struct({ type: Schema.Literal("ui.resize"), cols: Schema.Number, rows: Schema.Number }),
225
+ ]);
226
+ Frontend.Element = Schema.Struct({
227
+ id: Schema.String,
228
+ num: Schema.Number,
229
+ x: Schema.Number,
230
+ y: Schema.Number,
231
+ width: Schema.Number,
232
+ height: Schema.Number,
233
+ focusable: Schema.Boolean,
234
+ focused: Schema.Boolean,
235
+ clickable: Schema.Boolean,
236
+ editor: Schema.Boolean,
237
+ });
238
+ Frontend.State = Schema.Struct({
239
+ focused: Schema.Struct({
240
+ renderable: Schema.optional(Schema.Number),
241
+ editor: Schema.Boolean,
242
+ }),
243
+ elements: Schema.Array(Frontend.Element),
244
+ });
245
+ Frontend.SemanticNode = Schema.Struct({
246
+ id: Schema.NonEmptyString,
247
+ instance: Schema.optionalKey(Schema.NonEmptyString),
248
+ parent: Schema.optionalKey(Schema.NonEmptyString),
249
+ role: Schema.NonEmptyString,
250
+ label: Schema.optionalKey(Schema.NonEmptyString),
251
+ element: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)),
252
+ focused: Schema.optionalKey(Schema.Boolean),
253
+ selected: Schema.optionalKey(Schema.Boolean),
254
+ expanded: Schema.optionalKey(Schema.Boolean),
255
+ disabled: Schema.optionalKey(Schema.Boolean),
256
+ });
257
+ Frontend.SemanticSnapshot = Schema.Struct({
258
+ format: Schema.Literal("opencode-ui-snapshot-v1"),
259
+ nodes: Schema.Array(Frontend.SemanticNode).check(Schema.makeFilter((nodes) => {
260
+ const ids = new Set(nodes.map((node) => node.id));
261
+ if (ids.size !== nodes.length)
262
+ return "semantic node ids must be unique";
263
+ if (new Set(nodes.map((node) => node.element)).size !== nodes.length)
264
+ return "semantic node elements must be unique";
265
+ if (nodes.some((node) => node.parent !== undefined && !ids.has(node.parent)))
266
+ return "semantic node parents must reference another node";
267
+ const parents = new Map(nodes.map((node) => [node.id, node.parent]));
268
+ for (const node of nodes) {
269
+ const visited = new Set();
270
+ let current = node.id;
271
+ while (current !== undefined) {
272
+ if (visited.has(current))
273
+ return "semantic node hierarchy must be acyclic";
274
+ visited.add(current);
275
+ current = parents.get(current);
276
+ }
277
+ }
278
+ return undefined;
279
+ })),
280
+ });
281
+ Frontend.Matches = Schema.Boolean;
282
+ Frontend.TypeParams = Schema.Struct({ text: Schema.String });
283
+ Frontend.MatchesParams = Schema.Struct({ text: Schema.String });
284
+ Frontend.PressParams = Schema.Struct({ key: Schema.String, modifiers: Schema.optional(Frontend.KeyModifiers) });
285
+ Frontend.pressParams = (key, modifiers) => ({
286
+ key,
287
+ ...(modifiers === undefined ? {} : { modifiers }),
288
+ });
289
+ Frontend.ArrowParams = Schema.Struct({ direction: Schema.Literals(["up", "down", "left", "right"]) });
290
+ Frontend.FocusParams = Schema.Struct({ target: Schema.Number });
291
+ Frontend.ClickParams = Schema.Struct({
292
+ target: Schema.Number,
293
+ x: Schema.Number,
294
+ y: Schema.Number,
295
+ semantic: Schema.optionalKey(Frontend.SemanticClickTarget),
296
+ });
297
+ Frontend.ResizeParams = Schema.Struct({ cols: Schema.Number, rows: Schema.Number });
298
+ Frontend.Request = Schema.Union([
299
+ Handshake.Request,
300
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.type"), params: Frontend.TypeParams }),
301
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.press"), params: Frontend.PressParams }),
302
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.arrow"), params: Frontend.ArrowParams }),
303
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.focus"), params: Frontend.FocusParams }),
304
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.click"), params: Frontend.ClickParams }),
305
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.mouse"), params: Frontend.MouseParams }),
306
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.resize"), params: Frontend.ResizeParams }),
307
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.matches"), params: Frontend.MatchesParams }),
308
+ Schema.Struct({
309
+ ...JsonRpc.RequestFields,
310
+ method: Schema.Literals(["ui.enter", "ui.state", "ui.snapshot"]),
311
+ }),
312
+ ]);
313
+ Frontend.decodeRequest = Schema.decodeUnknownSync(Frontend.Request);
314
+ Frontend.decodeRequestEffect = Schema.decodeUnknownEffect(Schema.fromJsonString(Frontend.Request));
315
+ })(Frontend || (Frontend = {}));
316
+ export var Backend;
317
+ (function (Backend) {
318
+ Backend.Capabilities = [
319
+ "llm.attach",
320
+ "llm.chunk",
321
+ "llm.finish",
322
+ "llm.disconnect",
323
+ "llm.pending",
324
+ "llm.request",
325
+ "llm.tool-input-delta",
326
+ "tool.attach",
327
+ "tool.update",
328
+ "tool.finish",
329
+ "tool.fail",
330
+ "tool.invocation",
331
+ "tool.cancel",
332
+ ];
333
+ Backend.Item = Schema.Union([
334
+ Schema.Struct({ type: Schema.Literal("textDelta"), text: Schema.String }),
335
+ Schema.Struct({ type: Schema.Literal("reasoningDelta"), text: Schema.String }),
336
+ Schema.Struct({
337
+ type: Schema.Literal("toolInputStart"),
338
+ index: Schema.Number,
339
+ id: Schema.String,
340
+ name: Schema.String,
341
+ }),
342
+ Schema.Struct({
343
+ type: Schema.Literal("toolInputDelta"),
344
+ index: Schema.Number,
345
+ text: Schema.String,
346
+ }),
347
+ Schema.Struct({
348
+ type: Schema.Literal("toolCall"),
349
+ index: Schema.Number,
350
+ id: Schema.String,
351
+ name: Schema.String,
352
+ input: Schema.Json,
353
+ }),
354
+ Schema.Struct({ type: Schema.Literal("raw"), chunk: Schema.Json }),
355
+ ]);
356
+ Backend.FinishReason = Schema.Literals(["stop", "tool-calls", "length", "content-filter"]);
357
+ Backend.ToolContent = Schema.Union([
358
+ Schema.Struct({ type: Schema.Literal("text"), text: Schema.String }),
359
+ Schema.Struct({
360
+ type: Schema.Literal("file"),
361
+ data: Schema.String,
362
+ mime: Schema.NonEmptyString,
363
+ name: Schema.optionalKey(Schema.String),
364
+ }),
365
+ ]);
366
+ const ProviderSafeName = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
367
+ const ToolName = Schema.NonEmptyString.check(Schema.makeFilter((name) => ProviderSafeName.test(name) ? undefined : "simulated tool names must be provider-safe"));
368
+ const ToolNamespace = Schema.NonEmptyString.check(Schema.makeFilter((namespace) => namespace.split(".").every((segment) => ProviderSafeName.test(segment))
369
+ ? undefined
370
+ : "simulated tool namespaces must contain provider-safe segments"));
371
+ Backend.ToolRegistration = Schema.Struct({
372
+ name: ToolName,
373
+ description: Schema.String,
374
+ inputSchema: Schema.Record(Schema.String, Schema.Json),
375
+ outputSchema: Schema.optionalKey(Schema.Record(Schema.String, Schema.Json)),
376
+ permission: Schema.optionalKey(Schema.NonEmptyString),
377
+ options: Schema.optionalKey(Schema.Struct({
378
+ namespace: Schema.optionalKey(ToolNamespace),
379
+ codemode: Schema.optionalKey(Schema.Boolean),
380
+ })),
381
+ });
382
+ Backend.ToolAttachParams = Schema.Struct({
383
+ tools: Schema.Array(Backend.ToolRegistration).check(Schema.makeFilter((tools) => {
384
+ const names = tools.map(exposedToolName);
385
+ if (names.some((name) => !ProviderSafeName.test(name)))
386
+ return "simulated tool names including namespaces must be provider-safe";
387
+ if (new Set(names).size !== names.length)
388
+ return "simulated tool registrations must have unique exposed names";
389
+ if (tools.some((tool) => tool.name === "execute" && tool.options?.namespace === undefined && tool.options?.codemode === false))
390
+ return 'direct simulated tool name "execute" is reserved';
391
+ return undefined;
392
+ })),
393
+ });
394
+ function exposedToolName(registration) {
395
+ return registration.options?.namespace === undefined
396
+ ? registration.name
397
+ : `${registration.options.namespace.replaceAll(".", "_")}_${registration.name}`;
398
+ }
399
+ Backend.exposedToolName = exposedToolName;
400
+ Backend.ToolProgress = Schema.Record(Schema.String, Schema.Json);
401
+ Backend.ToolOutput = Schema.Struct({
402
+ structured: Schema.Json,
403
+ content: Schema.Array(Backend.ToolContent),
404
+ });
405
+ Backend.ToolUpdateParams = Schema.Struct({
406
+ id: Schema.String,
407
+ sequence: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
408
+ update: Backend.ToolProgress,
409
+ });
410
+ Backend.ToolFinishParams = Schema.Struct({ id: Schema.String, output: Backend.ToolOutput });
411
+ Backend.ToolFailParams = Schema.Struct({ id: Schema.String, message: Schema.String });
412
+ Backend.ToolInvocation = Schema.Struct({
413
+ id: Schema.String,
414
+ name: Schema.String,
415
+ input: Schema.Json,
416
+ context: Schema.Struct({
417
+ sessionID: Schema.String,
418
+ agent: Schema.String,
419
+ messageID: Schema.String,
420
+ id: Schema.String,
421
+ }),
422
+ });
423
+ Backend.ToolCancellation = Schema.Struct({
424
+ id: Schema.String,
425
+ reason: Schema.Literal("interrupted"),
426
+ });
427
+ Backend.Attached = Schema.Struct({ attached: Schema.Literal(true) });
428
+ Backend.Ok = Schema.Struct({ ok: Schema.Literal(true) });
429
+ Backend.ChunkParams = Schema.Struct({ id: Schema.String, items: Schema.Array(Backend.Item) });
430
+ Backend.FinishParams = Schema.Struct({
431
+ id: Schema.String,
432
+ reason: Backend.FinishReason.pipe(Schema.withDecodingDefault(Effect.succeed("stop"))),
433
+ });
434
+ Backend.FinishPayload = Schema.Struct({
435
+ id: Schema.String,
436
+ reason: Schema.optionalKey(Backend.FinishReason),
437
+ });
438
+ Backend.DisconnectParams = Schema.Struct({ id: Schema.String });
439
+ Backend.Request = Schema.Union([
440
+ Handshake.Request,
441
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("llm.chunk"), params: Backend.ChunkParams }),
442
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("llm.finish"), params: Backend.FinishParams }),
443
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("llm.disconnect"), params: Backend.DisconnectParams }),
444
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.attach"), params: Backend.ToolAttachParams }),
445
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.update"), params: Backend.ToolUpdateParams }),
446
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.finish"), params: Backend.ToolFinishParams }),
447
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.fail"), params: Backend.ToolFailParams }),
448
+ Schema.Struct({
449
+ ...JsonRpc.RequestFields,
450
+ method: Schema.Literals(["llm.attach", "llm.pending"]),
451
+ }),
452
+ ]);
453
+ Backend.decodeRequest = Schema.decodeUnknownSync(Backend.Request);
454
+ Backend.decodeRequestEffect = Schema.decodeUnknownEffect(Schema.fromJsonString(Backend.Request));
455
+ Backend.ProviderInvocation = Schema.Struct({ id: Schema.String, url: Schema.String, body: Schema.Json });
456
+ Backend.Pending = Schema.Struct({ invocations: Schema.Array(Backend.ProviderInvocation) });
457
+ Backend.NetworkLogEntry = Schema.Struct({
458
+ time: Schema.Number,
459
+ method: Schema.String,
460
+ url: Schema.String,
461
+ matched: Schema.Boolean,
462
+ });
463
+ Backend.Notification = Schema.Union([
464
+ Schema.Struct({
465
+ jsonrpc: Schema.Literal("2.0"),
466
+ method: Schema.Literal("llm.request"),
467
+ params: Backend.ProviderInvocation,
468
+ }),
469
+ Schema.Struct({
470
+ jsonrpc: Schema.Literal("2.0"),
471
+ method: Schema.Literal("tool.invocation"),
472
+ params: Backend.ToolInvocation,
473
+ }),
474
+ Schema.Struct({
475
+ jsonrpc: Schema.Literal("2.0"),
476
+ method: Schema.Literal("tool.cancel"),
477
+ params: Backend.ToolCancellation,
478
+ }),
479
+ ]);
480
+ Backend.decodeNotification = Schema.decodeUnknownSync(Backend.Notification);
481
+ Backend.decodeNotificationEffect = Schema.decodeUnknownEffect(Schema.fromJsonString(Backend.Notification));
482
+ })(Backend || (Backend = {}));
483
+ /** The core frontend RPCs. A client merges the group of the surface it drives (`Terminal.Rpcs`, `Image.Rpcs`). */
484
+ export const UiRpcs = RpcGroup.make(request("simulation.handshake", { payload: Handshake.Params, success: Handshake.Response }), request("ui.state", { success: Frontend.State }), request("ui.snapshot", { success: Frontend.SemanticSnapshot }), request("ui.matches", { payload: Frontend.MatchesParams, success: Frontend.Matches }), request("ui.type", { payload: Frontend.TypeParams, success: Frontend.State }), request("ui.press", { payload: Frontend.PressParams, success: Frontend.State }), request("ui.enter", { success: Frontend.State }), request("ui.arrow", { payload: Frontend.ArrowParams, success: Frontend.State }), request("ui.focus", { payload: Frontend.FocusParams, success: Frontend.State }), request("ui.click", { payload: Frontend.ClickParams, success: Frontend.State }), request("ui.mouse", { payload: Frontend.MouseParams, success: Frontend.State }), request("ui.resize", { payload: Frontend.ResizeParams, success: Frontend.State }));
485
+ export const BackendRpcs = RpcGroup.make(request("simulation.handshake", { payload: Handshake.Params, success: Handshake.Response }), request("llm.attach", { success: Backend.Attached }), request("llm.pending", { success: Backend.Pending }), request("llm.chunk", { payload: Backend.ChunkParams, success: Backend.Ok }), request("llm.finish", { payload: Backend.FinishPayload, success: Backend.Ok }), request("llm.disconnect", { payload: Backend.DisconnectParams, success: Backend.Ok }), request("tool.attach", { payload: Backend.ToolAttachParams, success: Backend.Attached }), request("tool.update", { payload: Backend.ToolUpdateParams, success: Backend.Ok }), request("tool.finish", { payload: Backend.ToolFinishParams, success: Backend.Ok }), request("tool.fail", { payload: Backend.ToolFailParams, success: Backend.Ok }));
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package.json",
2
3
  "name": "@radheim/protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
4
+ "version": "2.4.3",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/anomalyco/opencode.git",
10
+ "directory": "packages/protocol"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "exports": {
19
+ "./simulation": {
20
+ "types": "./dist/simulation.d.ts",
21
+ "import": "./dist/simulation.js"
22
+ },
23
+ "./*": {
24
+ "types": "./dist/*.d.ts",
25
+ "import": "./dist/*.js"
26
+ }
27
+ },
28
+ "scripts": {
29
+ "build": "bun run script/build.ts",
30
+ "pack": "bun run script/pack.ts",
31
+ "generate": "bun run script/generate-openapi.ts && bun run --cwd ../core generate:api-skill",
32
+ "check:generated": "bun run script/generate-openapi.ts --check",
33
+ "test": "bun test --only-failures",
34
+ "typecheck": "bun check --no-script",
35
+ "typecheck:tsc": "tsc --noEmit"
36
+ },
37
+ "dependencies": {
38
+ "@radheim/schema": "2.4.3",
39
+ "effect": "4.1.0"
40
+ },
41
+ "devDependencies": {
42
+ "@tsconfig/bun": "1.0.9",
43
+ "@types/bun": "1.4.3",
44
+ "@typescript/native": "npm:typescript@7.1.0-beta",
45
+ "prettier": "3.6.2",
46
+ "typescript": "npm:@typescript/typescript6@6.0.2"
47
+ }
48
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
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.