@opencode-ai/protocol 0.0.0-dev-17471

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 (71) hide show
  1. package/dist/api.d.ts +53 -0
  2. package/dist/api.js +73 -0
  3. package/dist/client.d.ts +61 -0
  4. package/dist/client.js +47 -0
  5. package/dist/errors.d.ts +133 -0
  6. package/dist/errors.js +105 -0
  7. package/dist/groups/agent.d.ts +194 -0
  8. package/dist/groups/agent.js +30 -0
  9. package/dist/groups/command.d.ts +63 -0
  10. package/dist/groups/command.js +20 -0
  11. package/dist/groups/config.d.ts +9 -0
  12. package/dist/groups/config.js +16 -0
  13. package/dist/groups/credential.d.ts +23 -0
  14. package/dist/groups/credential.js +29 -0
  15. package/dist/groups/debug.d.ts +17 -0
  16. package/dist/groups/debug.js +23 -0
  17. package/dist/groups/event.d.ts +12882 -0
  18. package/dist/groups/event.js +42 -0
  19. package/dist/groups/form.d.ts +781 -0
  20. package/dist/groups/form.js +97 -0
  21. package/dist/groups/fs.d.ts +35 -0
  22. package/dist/groups/fs.js +51 -0
  23. package/dist/groups/generate.d.ts +38 -0
  24. package/dist/groups/generate.js +27 -0
  25. package/dist/groups/health.d.ts +27 -0
  26. package/dist/groups/health.js +34 -0
  27. package/dist/groups/integration.d.ts +1152 -0
  28. package/dist/groups/integration.js +149 -0
  29. package/dist/groups/location.d.ts +16 -0
  30. package/dist/groups/location.js +34 -0
  31. package/dist/groups/mcp.d.ts +82 -0
  32. package/dist/groups/mcp.js +78 -0
  33. package/dist/groups/message.d.ts +592 -0
  34. package/dist/groups/message.js +37 -0
  35. package/dist/groups/migration.d.ts +28 -0
  36. package/dist/groups/migration.js +21 -0
  37. package/dist/groups/model.d.ts +218 -0
  38. package/dist/groups/model.js +33 -0
  39. package/dist/groups/permission.d.ts +153 -0
  40. package/dist/groups/permission.js +99 -0
  41. package/dist/groups/plugin.d.ts +14 -0
  42. package/dist/groups/plugin.js +20 -0
  43. package/dist/groups/project.d.ts +41 -0
  44. package/dist/groups/project.js +27 -0
  45. package/dist/groups/provider.d.ts +82 -0
  46. package/dist/groups/provider.js +34 -0
  47. package/dist/groups/pty.d.ts +145 -0
  48. package/dist/groups/pty.js +112 -0
  49. package/dist/groups/reference.d.ts +29 -0
  50. package/dist/groups/reference.js +20 -0
  51. package/dist/groups/server.d.ts +5 -0
  52. package/dist/groups/server.js +11 -0
  53. package/dist/groups/session.d.ts +9247 -0
  54. package/dist/groups/session.js +515 -0
  55. package/dist/groups/shell.d.ts +152 -0
  56. package/dist/groups/shell.js +82 -0
  57. package/dist/groups/skill.d.ts +20 -0
  58. package/dist/groups/skill.js +20 -0
  59. package/dist/groups/vcs.d.ts +46 -0
  60. package/dist/groups/vcs.js +47 -0
  61. package/dist/groups/websearch.d.ts +28 -0
  62. package/dist/groups/websearch.js +34 -0
  63. package/dist/groups/worktree.d.ts +42 -0
  64. package/dist/groups/worktree.js +54 -0
  65. package/dist/middleware/authorization.d.ts +13 -0
  66. package/dist/middleware/authorization.js +6 -0
  67. package/dist/middleware/schema-error.d.ts +13 -0
  68. package/dist/middleware/schema-error.js +4 -0
  69. package/dist/simulation.d.ts +1590 -0
  70. package/dist/simulation.js +460 -0
  71. package/package.json +44 -0
@@ -0,0 +1,460 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Rpc, RpcGroup } from "effect/unstable/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.TaggedErrorClass()("SimulationRequestError", {
55
+ method: Schema.String,
56
+ code: Schema.Number,
57
+ message: Schema.String,
58
+ data: Schema.optionalKey(Schema.Json),
59
+ }) {
60
+ }
61
+ const request = (tag, options) => Rpc.make(tag, { ...options, error: SimulationRequestError });
62
+ export var Handshake;
63
+ (function (Handshake) {
64
+ Handshake.ProtocolVersion = Schema.Literal(1);
65
+ Handshake.Capability = Schema.NonEmptyString;
66
+ Handshake.EndpointRole = Schema.Literals(["ui", "backend"]);
67
+ Handshake.Identity = Schema.Struct({
68
+ name: Schema.NonEmptyString,
69
+ version: Schema.NonEmptyString,
70
+ });
71
+ Handshake.Params = Schema.Struct({
72
+ client: Handshake.Identity,
73
+ expectedRole: Handshake.EndpointRole,
74
+ offeredVersions: Schema.Array(Schema.Int.check(Schema.isGreaterThan(0))).check(Schema.isMinLength(1), Schema.isUnique()),
75
+ requiredCapabilities: Schema.Array(Handshake.Capability).check(Schema.isUnique()),
76
+ optionalCapabilities: Schema.Array(Handshake.Capability).check(Schema.isUnique()),
77
+ });
78
+ Handshake.Response = Schema.Struct({
79
+ protocolVersion: Handshake.ProtocolVersion,
80
+ role: Handshake.EndpointRole,
81
+ server: Handshake.Identity,
82
+ capabilities: Schema.Array(Handshake.Capability).check(Schema.isUnique()),
83
+ });
84
+ Handshake.Request = Schema.Struct({
85
+ ...JsonRpc.RequestFields,
86
+ method: Schema.Literal("simulation.handshake"),
87
+ params: Handshake.Params,
88
+ });
89
+ class RoleMismatchError extends Schema.TaggedErrorClass()("SimulationHandshake.RoleMismatchError", {
90
+ expected: Handshake.EndpointRole,
91
+ actual: Handshake.EndpointRole,
92
+ message: Schema.String,
93
+ }) {
94
+ }
95
+ Handshake.RoleMismatchError = RoleMismatchError;
96
+ class UnsupportedProtocolError extends Schema.TaggedErrorClass()("SimulationHandshake.UnsupportedProtocolError", {
97
+ offered: Schema.Array(Schema.Number),
98
+ supported: Schema.Array(Handshake.ProtocolVersion),
99
+ message: Schema.String,
100
+ }) {
101
+ }
102
+ Handshake.UnsupportedProtocolError = UnsupportedProtocolError;
103
+ class MissingCapabilityError extends Schema.TaggedErrorClass()("SimulationHandshake.MissingCapabilityError", {
104
+ missing: Schema.Array(Handshake.Capability),
105
+ message: Schema.String,
106
+ }) {
107
+ }
108
+ Handshake.MissingCapabilityError = MissingCapabilityError;
109
+ function dispatch(action, params) {
110
+ return Effect.gen(function* () {
111
+ if (params.expectedRole !== action.role) {
112
+ return yield* Effect.fail(new RoleMismatchError({
113
+ expected: params.expectedRole,
114
+ actual: action.role,
115
+ message: `Expected simulation endpoint role ${params.expectedRole}, received ${action.role}`,
116
+ }));
117
+ }
118
+ if (!params.offeredVersions.includes(1)) {
119
+ return yield* Effect.fail(new UnsupportedProtocolError({
120
+ offered: params.offeredVersions,
121
+ supported: [1],
122
+ message: "No mutually supported simulation protocol version",
123
+ }));
124
+ }
125
+ const installed = new Set(action.capabilities);
126
+ const missing = params.requiredCapabilities.filter((capability) => !installed.has(capability));
127
+ if (missing.length > 0) {
128
+ return yield* Effect.fail(new MissingCapabilityError({
129
+ missing,
130
+ message: `Simulation endpoint is missing required capabilities: ${missing.join(", ")}`,
131
+ }));
132
+ }
133
+ return {
134
+ protocolVersion: 1,
135
+ role: action.role,
136
+ server: action.server,
137
+ capabilities: Array.from(installed),
138
+ };
139
+ });
140
+ }
141
+ Handshake.dispatch = dispatch;
142
+ })(Handshake || (Handshake = {}));
143
+ export var Frontend;
144
+ (function (Frontend) {
145
+ Frontend.Capabilities = [
146
+ "ui.type",
147
+ "ui.press",
148
+ "ui.enter",
149
+ "ui.arrow",
150
+ "ui.focus",
151
+ "ui.click",
152
+ "ui.click.semantic",
153
+ "ui.resize",
154
+ "ui.matches",
155
+ "ui.state",
156
+ "ui.snapshot",
157
+ "ui.capture",
158
+ "ui.recording.finish",
159
+ ];
160
+ Frontend.KeyModifiers = Schema.Struct({
161
+ ctrl: Schema.optional(Schema.Boolean),
162
+ shift: Schema.optional(Schema.Boolean),
163
+ meta: Schema.optional(Schema.Boolean),
164
+ super: Schema.optional(Schema.Boolean),
165
+ hyper: Schema.optional(Schema.Boolean),
166
+ });
167
+ Frontend.SemanticClickTarget = Schema.Struct({
168
+ id: Schema.NonEmptyString,
169
+ instance: Schema.optionalKey(Schema.NonEmptyString),
170
+ element: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)),
171
+ });
172
+ Frontend.Action = Schema.Union([
173
+ Schema.Struct({ type: Schema.Literal("ui.type"), text: Schema.String }),
174
+ Schema.Struct({ type: Schema.Literal("ui.press"), key: Schema.String, modifiers: Schema.optional(Frontend.KeyModifiers) }),
175
+ Schema.Struct({ type: Schema.Literal("ui.enter") }),
176
+ Schema.Struct({ type: Schema.Literal("ui.arrow"), direction: Schema.Literals(["up", "down", "left", "right"]) }),
177
+ Schema.Struct({ type: Schema.Literal("ui.focus"), target: Schema.Number }),
178
+ Schema.Struct({
179
+ type: Schema.Literal("ui.click"),
180
+ target: Schema.Number,
181
+ x: Schema.Number,
182
+ y: Schema.Number,
183
+ semantic: Schema.optionalKey(Frontend.SemanticClickTarget),
184
+ }),
185
+ Schema.Struct({ type: Schema.Literal("ui.resize"), cols: Schema.Number, rows: Schema.Number }),
186
+ ]);
187
+ Frontend.Element = Schema.Struct({
188
+ id: Schema.String,
189
+ num: Schema.Number,
190
+ x: Schema.Number,
191
+ y: Schema.Number,
192
+ width: Schema.Number,
193
+ height: Schema.Number,
194
+ focusable: Schema.Boolean,
195
+ focused: Schema.Boolean,
196
+ clickable: Schema.Boolean,
197
+ editor: Schema.Boolean,
198
+ });
199
+ Frontend.State = Schema.Struct({
200
+ focused: Schema.Struct({
201
+ renderable: Schema.optional(Schema.Number),
202
+ editor: Schema.Boolean,
203
+ }),
204
+ elements: Schema.Array(Frontend.Element),
205
+ });
206
+ Frontend.SemanticNode = Schema.Struct({
207
+ id: Schema.NonEmptyString,
208
+ instance: Schema.optionalKey(Schema.NonEmptyString),
209
+ parent: Schema.optionalKey(Schema.NonEmptyString),
210
+ role: Schema.NonEmptyString,
211
+ label: Schema.optionalKey(Schema.NonEmptyString),
212
+ element: Schema.Number.check(Schema.isInt(), Schema.isGreaterThan(0)),
213
+ focused: Schema.optionalKey(Schema.Boolean),
214
+ selected: Schema.optionalKey(Schema.Boolean),
215
+ expanded: Schema.optionalKey(Schema.Boolean),
216
+ disabled: Schema.optionalKey(Schema.Boolean),
217
+ });
218
+ Frontend.SemanticSnapshot = Schema.Struct({
219
+ format: Schema.Literal("opencode-ui-snapshot-v1"),
220
+ nodes: Schema.Array(Frontend.SemanticNode).check(Schema.makeFilter((nodes) => {
221
+ const ids = new Set(nodes.map((node) => node.id));
222
+ if (ids.size !== nodes.length)
223
+ return "semantic node ids must be unique";
224
+ if (new Set(nodes.map((node) => node.element)).size !== nodes.length)
225
+ return "semantic node elements must be unique";
226
+ if (nodes.some((node) => node.parent !== undefined && !ids.has(node.parent)))
227
+ return "semantic node parents must reference another node";
228
+ const parents = new Map(nodes.map((node) => [node.id, node.parent]));
229
+ for (const node of nodes) {
230
+ const visited = new Set();
231
+ let current = node.id;
232
+ while (current !== undefined) {
233
+ if (visited.has(current))
234
+ return "semantic node hierarchy must be acyclic";
235
+ visited.add(current);
236
+ current = parents.get(current);
237
+ }
238
+ }
239
+ return undefined;
240
+ })),
241
+ });
242
+ Frontend.Color = Schema.Tuple([Schema.Number, Schema.Number, Schema.Number, Schema.Number]);
243
+ Frontend.CapturedFrame = Schema.Struct({
244
+ cols: Schema.Number,
245
+ rows: Schema.Number,
246
+ cursor: Schema.Tuple([Schema.Number, Schema.Number]),
247
+ lines: Schema.Array(Schema.Struct({
248
+ spans: Schema.Array(Schema.Struct({
249
+ text: Schema.String,
250
+ fg: Frontend.Color,
251
+ bg: Frontend.Color,
252
+ attributes: Schema.Number,
253
+ width: Schema.Number,
254
+ })),
255
+ })),
256
+ });
257
+ Frontend.RecordingFinish = Schema.String;
258
+ Frontend.Matches = Schema.Boolean;
259
+ Frontend.TypeParams = Schema.Struct({ text: Schema.String });
260
+ Frontend.MatchesParams = Schema.Struct({ text: Schema.String });
261
+ Frontend.PressParams = Schema.Struct({ key: Schema.String, modifiers: Schema.optional(Frontend.KeyModifiers) });
262
+ Frontend.pressParams = (key, modifiers) => ({
263
+ key,
264
+ ...(modifiers === undefined ? {} : { modifiers }),
265
+ });
266
+ Frontend.ArrowParams = Schema.Struct({ direction: Schema.Literals(["up", "down", "left", "right"]) });
267
+ Frontend.FocusParams = Schema.Struct({ target: Schema.Number });
268
+ Frontend.ClickParams = Schema.Struct({
269
+ target: Schema.Number,
270
+ x: Schema.Number,
271
+ y: Schema.Number,
272
+ semantic: Schema.optionalKey(Frontend.SemanticClickTarget),
273
+ });
274
+ Frontend.ResizeParams = Schema.Struct({ cols: Schema.Number, rows: Schema.Number });
275
+ Frontend.Request = Schema.Union([
276
+ Handshake.Request,
277
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.type"), params: Frontend.TypeParams }),
278
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.press"), params: Frontend.PressParams }),
279
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.arrow"), params: Frontend.ArrowParams }),
280
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.focus"), params: Frontend.FocusParams }),
281
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.click"), params: Frontend.ClickParams }),
282
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.resize"), params: Frontend.ResizeParams }),
283
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.matches"), params: Frontend.MatchesParams }),
284
+ Schema.Struct({
285
+ ...JsonRpc.RequestFields,
286
+ method: Schema.Literals(["ui.enter", "ui.state", "ui.snapshot", "ui.recording.finish"]),
287
+ }),
288
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("ui.capture") }),
289
+ ]);
290
+ Frontend.decodeRequest = Schema.decodeUnknownSync(Frontend.Request);
291
+ Frontend.decodeRequestEffect = Schema.decodeUnknownEffect(Schema.fromJsonString(Frontend.Request));
292
+ })(Frontend || (Frontend = {}));
293
+ export var Backend;
294
+ (function (Backend) {
295
+ Backend.Capabilities = [
296
+ "llm.attach",
297
+ "llm.chunk",
298
+ "llm.finish",
299
+ "llm.disconnect",
300
+ "llm.pending",
301
+ "llm.request",
302
+ "llm.tool-input-delta",
303
+ "tool.attach",
304
+ "tool.update",
305
+ "tool.finish",
306
+ "tool.fail",
307
+ "tool.invocation",
308
+ "tool.cancel",
309
+ ];
310
+ Backend.Item = Schema.Union([
311
+ Schema.Struct({ type: Schema.Literal("textDelta"), text: Schema.String }),
312
+ Schema.Struct({ type: Schema.Literal("reasoningDelta"), text: Schema.String }),
313
+ Schema.Struct({
314
+ type: Schema.Literal("toolInputStart"),
315
+ index: Schema.Number,
316
+ id: Schema.String,
317
+ name: Schema.String,
318
+ }),
319
+ Schema.Struct({
320
+ type: Schema.Literal("toolInputDelta"),
321
+ index: Schema.Number,
322
+ text: Schema.String,
323
+ }),
324
+ Schema.Struct({
325
+ type: Schema.Literal("toolCall"),
326
+ index: Schema.Number,
327
+ id: Schema.String,
328
+ name: Schema.String,
329
+ input: Schema.Json,
330
+ }),
331
+ Schema.Struct({ type: Schema.Literal("raw"), chunk: Schema.Json }),
332
+ ]);
333
+ Backend.FinishReason = Schema.Literals(["stop", "tool-calls", "length", "content-filter"]);
334
+ Backend.ToolContent = Schema.Union([
335
+ Schema.Struct({ type: Schema.Literal("text"), text: Schema.String }),
336
+ Schema.Struct({
337
+ type: Schema.Literal("file"),
338
+ data: Schema.String,
339
+ mime: Schema.NonEmptyString,
340
+ name: Schema.optionalKey(Schema.String),
341
+ }),
342
+ ]);
343
+ const ToolName = Schema.NonEmptyString.check(Schema.makeFilter((name) => /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(name) ? undefined : "simulated tool names must be provider-safe"));
344
+ const ToolNamespace = Schema.NonEmptyString.check(Schema.makeFilter((namespace) => namespace.split(".").every((segment) => /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(segment))
345
+ ? undefined
346
+ : "simulated tool namespaces must contain provider-safe segments"));
347
+ Backend.ToolRegistration = Schema.Struct({
348
+ name: ToolName,
349
+ description: Schema.String,
350
+ inputSchema: Schema.Record(Schema.String, Schema.Json),
351
+ outputSchema: Schema.optionalKey(Schema.Record(Schema.String, Schema.Json)),
352
+ permission: Schema.optionalKey(Schema.NonEmptyString),
353
+ options: Schema.optionalKey(Schema.Struct({
354
+ namespace: Schema.optionalKey(ToolNamespace),
355
+ codemode: Schema.optionalKey(Schema.Boolean),
356
+ })),
357
+ });
358
+ Backend.ToolAttachParams = Schema.Struct({
359
+ tools: Schema.Array(Backend.ToolRegistration).check(Schema.makeFilter((tools) => {
360
+ const names = tools.map(exposedToolName);
361
+ if (names.some((name) => !/^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(name)))
362
+ return "simulated tool names including namespaces must be provider-safe";
363
+ if (new Set(names).size !== names.length)
364
+ return "simulated tool registrations must have unique exposed names";
365
+ if (tools.some((tool) => tool.name === "execute" && tool.options?.namespace === undefined && tool.options?.codemode === false))
366
+ return 'direct simulated tool name "execute" is reserved';
367
+ return undefined;
368
+ })),
369
+ });
370
+ function exposedToolName(registration) {
371
+ return registration.options?.namespace === undefined
372
+ ? registration.name
373
+ : `${registration.options.namespace.replaceAll(".", "_")}_${registration.name}`;
374
+ }
375
+ Backend.exposedToolName = exposedToolName;
376
+ Backend.ToolProgress = Schema.Record(Schema.String, Schema.Json);
377
+ Backend.ToolOutput = Schema.Struct({
378
+ structured: Schema.Json,
379
+ content: Schema.Array(Backend.ToolContent),
380
+ });
381
+ Backend.ToolUpdateParams = Schema.Struct({
382
+ id: Schema.String,
383
+ sequence: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
384
+ update: Backend.ToolProgress,
385
+ });
386
+ Backend.ToolFinishParams = Schema.Struct({ id: Schema.String, output: Backend.ToolOutput });
387
+ Backend.ToolFailParams = Schema.Struct({ id: Schema.String, message: Schema.String });
388
+ Backend.ToolInvocation = Schema.Struct({
389
+ id: Schema.String,
390
+ name: Schema.String,
391
+ input: Schema.Json,
392
+ context: Schema.Struct({
393
+ sessionID: Schema.String,
394
+ agent: Schema.String,
395
+ messageID: Schema.String,
396
+ id: Schema.String,
397
+ }),
398
+ });
399
+ Backend.ToolCancellation = Schema.Struct({
400
+ id: Schema.String,
401
+ reason: Schema.Literal("interrupted"),
402
+ });
403
+ Backend.Attached = Schema.Struct({ attached: Schema.Literal(true) });
404
+ Backend.Ok = Schema.Struct({ ok: Schema.Literal(true) });
405
+ Backend.ChunkParams = Schema.Struct({ id: Schema.String, items: Schema.Array(Backend.Item) });
406
+ Backend.FinishParams = Schema.Struct({
407
+ id: Schema.String,
408
+ reason: Backend.FinishReason.pipe(Schema.withDecodingDefault(Effect.succeed("stop"))),
409
+ });
410
+ Backend.FinishPayload = Schema.Struct({
411
+ id: Schema.String,
412
+ reason: Schema.optionalKey(Backend.FinishReason),
413
+ });
414
+ Backend.DisconnectParams = Schema.Struct({ id: Schema.String });
415
+ Backend.Request = Schema.Union([
416
+ Handshake.Request,
417
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("llm.chunk"), params: Backend.ChunkParams }),
418
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("llm.finish"), params: Backend.FinishParams }),
419
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("llm.disconnect"), params: Backend.DisconnectParams }),
420
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.attach"), params: Backend.ToolAttachParams }),
421
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.update"), params: Backend.ToolUpdateParams }),
422
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.finish"), params: Backend.ToolFinishParams }),
423
+ Schema.Struct({ ...JsonRpc.RequestFields, method: Schema.Literal("tool.fail"), params: Backend.ToolFailParams }),
424
+ Schema.Struct({
425
+ ...JsonRpc.RequestFields,
426
+ method: Schema.Literals(["llm.attach", "llm.pending"]),
427
+ }),
428
+ ]);
429
+ Backend.decodeRequest = Schema.decodeUnknownSync(Backend.Request);
430
+ Backend.decodeRequestEffect = Schema.decodeUnknownEffect(Schema.fromJsonString(Backend.Request));
431
+ Backend.ProviderInvocation = Schema.Struct({ id: Schema.String, url: Schema.String, body: Schema.Json });
432
+ Backend.Pending = Schema.Struct({ invocations: Schema.Array(Backend.ProviderInvocation) });
433
+ Backend.NetworkLogEntry = Schema.Struct({
434
+ time: Schema.Number,
435
+ method: Schema.String,
436
+ url: Schema.String,
437
+ matched: Schema.Boolean,
438
+ });
439
+ Backend.Notification = Schema.Union([
440
+ Schema.Struct({
441
+ jsonrpc: Schema.Literal("2.0"),
442
+ method: Schema.Literal("llm.request"),
443
+ params: Backend.ProviderInvocation,
444
+ }),
445
+ Schema.Struct({
446
+ jsonrpc: Schema.Literal("2.0"),
447
+ method: Schema.Literal("tool.invocation"),
448
+ params: Backend.ToolInvocation,
449
+ }),
450
+ Schema.Struct({
451
+ jsonrpc: Schema.Literal("2.0"),
452
+ method: Schema.Literal("tool.cancel"),
453
+ params: Backend.ToolCancellation,
454
+ }),
455
+ ]);
456
+ Backend.decodeNotification = Schema.decodeUnknownSync(Backend.Notification);
457
+ Backend.decodeNotificationEffect = Schema.decodeUnknownEffect(Schema.fromJsonString(Backend.Notification));
458
+ })(Backend || (Backend = {}));
459
+ 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.capture", { success: Frontend.CapturedFrame }), request("ui.matches", { payload: Frontend.MatchesParams, success: Frontend.Matches }), request("ui.recording.finish", { success: Frontend.RecordingFinish }), 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.resize", { payload: Frontend.ResizeParams, success: Frontend.State }));
460
+ 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 ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@opencode-ai/protocol",
4
+ "version": "0.0.0-dev-17471",
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
+ "import": "./dist/simulation.js",
21
+ "types": "./dist/simulation.d.ts"
22
+ },
23
+ "./*": {
24
+ "import": "./dist/*.js",
25
+ "types": "./dist/*.d.ts"
26
+ }
27
+ },
28
+ "scripts": {
29
+ "build": "bun run script/build.ts",
30
+ "generate": "bun run script/generate-openapi.ts",
31
+ "check:generated": "bun run script/generate-openapi.ts --check",
32
+ "typecheck": "tsgo --noEmit"
33
+ },
34
+ "dependencies": {
35
+ "@opencode-ai/schema": "0.0.0-dev-17471",
36
+ "effect": "4.0.0-beta.101"
37
+ },
38
+ "devDependencies": {
39
+ "@tsconfig/bun": "1.0.9",
40
+ "@types/bun": "1.3.13",
41
+ "@typescript/native-preview": "7.0.0-dev.20251207.1",
42
+ "typescript": "5.8.2"
43
+ }
44
+ }