@opencode/server 2.1.3 → 2.2.0

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 (132) hide show
  1. package/dist/api.d.ts +854 -969
  2. package/dist/api.js +5 -5
  3. package/dist/auth.js +1 -1
  4. package/dist/chunks/server-info-1gwc8nvb.js +69 -0
  5. package/dist/chunks/{service-status-z554rpg5.js → server-info-1v577ncx.js} +4 -2
  6. package/dist/chunks/{service-status-79n3507d.js → server-info-1wd9c1m3.js} +3 -3
  7. package/dist/chunks/{service-status-jwf0kwqx.js → server-info-2eaky32g.js} +12 -3
  8. package/dist/chunks/{service-status-a30hykaf.js → server-info-2h6qktqa.js} +24 -6
  9. package/dist/chunks/{service-status-6tj91hdj.js → server-info-4fy84009.js} +3 -3
  10. package/dist/chunks/{service-status-yzwm8eeq.js → server-info-4q6e7fh8.js} +2 -2
  11. package/dist/chunks/{service-status-gymtz25n.js → server-info-50bbk3b2.js} +3 -3
  12. package/dist/chunks/{service-status-rj8tbp10.js → server-info-5b42hxrf.js} +1 -1
  13. package/dist/chunks/{service-status-x2cwbfak.js → server-info-5pdfedjd.js} +7 -7
  14. package/dist/chunks/{service-status-1qc831kp.js → server-info-5s6gh8sx.js} +7 -3
  15. package/dist/chunks/{service-status-vg0x3zn0.js → server-info-6z9pvq7p.js} +1 -1
  16. package/dist/chunks/{service-status-6v4wsps6.js → server-info-7b9xm1qg.js} +3 -2
  17. package/dist/chunks/{service-status-7qrtcnv4.js → server-info-a8jcac9a.js} +1 -1
  18. package/dist/chunks/{service-status-5ewqf72w.js → server-info-az0609r6.js} +4 -2
  19. package/dist/chunks/server-info-b0f38s3n.js +105 -0
  20. package/dist/chunks/server-info-b105zy65.js +22 -0
  21. package/dist/chunks/{service-status-x74w7e1f.js → server-info-b3bmdkga.js} +1 -1
  22. package/dist/chunks/{service-status-erzfdgke.js → server-info-bd8755ek.js} +16 -1
  23. package/dist/chunks/server-info-bhbc7551.js +107 -0
  24. package/dist/chunks/{service-status-11d378s5.js → server-info-btahnm2b.js} +3 -3
  25. package/dist/chunks/{service-status-c2hv5jmf.js → server-info-cezwbsk5.js} +1 -1
  26. package/dist/chunks/{service-status-crt28xe4.js → server-info-d0edqfxx.js} +4 -11
  27. package/dist/chunks/{service-status-e6e4kz0w.js → server-info-e6e4kz0w.js} +1 -1
  28. package/dist/chunks/{service-status-5adf1am9.js → server-info-f559fakr.js} +2 -2
  29. package/dist/chunks/{service-status-pf9k0dqe.js → server-info-h29xjj1e.js} +2 -2
  30. package/dist/chunks/{service-status-3154e7fk.js → server-info-htyf2qs7.js} +5 -3
  31. package/dist/chunks/{service-status-5680j7c4.js → server-info-j2d131x1.js} +23 -20
  32. package/dist/chunks/{service-status-j4at0y5c.js → server-info-j4at0y5c.js} +1 -1
  33. package/dist/chunks/{service-status-r82dtfrk.js → server-info-j87xz9bt.js} +3 -3
  34. package/dist/chunks/{service-status-y89d99mz.js → server-info-kkdkqt8j.js} +2 -2
  35. package/dist/chunks/{service-status-vb61dkrm.js → server-info-kqr36gas.js} +8 -8
  36. package/dist/chunks/server-info-n321d8vm.js +46 -0
  37. package/dist/chunks/{service-status-rkmbbexc.js → server-info-nx6f5k7a.js} +4 -4
  38. package/dist/chunks/{service-status-0znmasm1.js → server-info-ny1j968n.js} +2 -2
  39. package/dist/chunks/server-info-qcg3sqtb.js +38 -0
  40. package/dist/chunks/{service-status-6e6jjne7.js → server-info-qd0r787n.js} +2 -2
  41. package/dist/chunks/{service-status-xcxwzp6z.js → server-info-rha2aq18.js} +4 -4
  42. package/dist/chunks/{service-status-6tjqh8g4.js → server-info-rw1dfckh.js} +8 -4
  43. package/dist/chunks/{service-status-2e16a9cc.js → server-info-s282vggx.js} +1 -1
  44. package/dist/chunks/{service-status-k6dz4enc.js → server-info-s802fzg1.js} +21 -20
  45. package/dist/chunks/{service-status-10kexchg.js → server-info-te8jwba1.js} +2 -2
  46. package/dist/chunks/{service-status-53jj3zgg.js → server-info-tjtyxt9h.js} +32 -12
  47. package/dist/chunks/server-info-xthc02cw.js +6 -0
  48. package/dist/chunks/server-info-yqhefp4s.js +83 -0
  49. package/dist/chunks/{service-status-7scj3y0h.js → server-info-yxw63vq5.js} +10 -8
  50. package/dist/chunks/{service-status-krqg3gd2.js → server-info-zcvan105.js} +1 -1
  51. package/dist/chunks/{service-status-q6jxy1hn.js → server-info-zpr61asr.js} +15 -38
  52. package/dist/cors.js +1 -1
  53. package/dist/event-feed.d.ts +1 -1
  54. package/dist/event-feed.js +3 -3
  55. package/dist/fetch.js +50 -48
  56. package/dist/handlers/agent.js +6 -6
  57. package/dist/handlers/command.js +6 -6
  58. package/dist/handlers/config.js +6 -6
  59. package/dist/handlers/credential.js +6 -6
  60. package/dist/handlers/debug.d.ts +2 -1
  61. package/dist/handlers/debug.js +6 -6
  62. package/dist/handlers/event.js +7 -7
  63. package/dist/handlers/form.js +6 -6
  64. package/dist/handlers/fs.d.ts +2 -1
  65. package/dist/handlers/fs.js +6 -6
  66. package/dist/handlers/generate.d.ts +1 -1
  67. package/dist/handlers/generate.js +6 -6
  68. package/dist/handlers/integration.js +6 -6
  69. package/dist/handlers/location.js +6 -6
  70. package/dist/handlers/mcp.d.ts +3 -1
  71. package/dist/handlers/mcp.js +8 -6
  72. package/dist/handlers/media.d.ts +6 -0
  73. package/dist/handlers/media.js +6 -0
  74. package/dist/handlers/message.js +7 -6
  75. package/dist/handlers/migration.js +6 -6
  76. package/dist/handlers/model.js +6 -6
  77. package/dist/handlers/permission.js +6 -6
  78. package/dist/handlers/persistent-pty.d.ts +1 -1
  79. package/dist/handlers/persistent-pty.js +9 -8
  80. package/dist/handlers/plugin.js +6 -6
  81. package/dist/handlers/project.d.ts +1 -1
  82. package/dist/handlers/project.js +6 -6
  83. package/dist/handlers/provider.js +6 -6
  84. package/dist/handlers/pty-socket.js +1 -1
  85. package/dist/handlers/pty.d.ts +1 -2
  86. package/dist/handlers/pty.js +8 -9
  87. package/dist/handlers/reference.js +6 -6
  88. package/dist/handlers/rpc.js +6 -6
  89. package/dist/handlers/server.js +9 -9
  90. package/dist/handlers/session-error.js +1 -1
  91. package/dist/handlers/session.d.ts +3 -1
  92. package/dist/handlers/session.js +7 -6
  93. package/dist/handlers/shell.js +6 -6
  94. package/dist/handlers/skill.js +6 -6
  95. package/dist/handlers/usage.d.ts +1 -0
  96. package/dist/handlers/usage.js +11 -0
  97. package/dist/handlers/vcs.js +6 -6
  98. package/dist/handlers/voice.d.ts +1 -1
  99. package/dist/handlers/voice.js +6 -6
  100. package/dist/handlers/websearch.js +6 -6
  101. package/dist/handlers/worktree.js +6 -6
  102. package/dist/handlers.d.ts +1 -1
  103. package/dist/handlers.js +46 -44
  104. package/dist/location.js +4 -4
  105. package/dist/media-uri.d.ts +6 -0
  106. package/dist/media-uri.js +6 -0
  107. package/dist/middleware/authorization.js +2 -2
  108. package/dist/middleware/form-location.js +3 -3
  109. package/dist/middleware/schema-error.js +1 -1
  110. package/dist/middleware/session-location.js +3 -3
  111. package/dist/pairing.js +5 -5
  112. package/dist/process.js +54 -51
  113. package/dist/request-tracing.js +1 -1
  114. package/dist/routes.d.ts +5 -3
  115. package/dist/routes.js +49 -47
  116. package/dist/server-info.js +5 -5
  117. package/dist/service-status.js +1 -1
  118. package/dist/workerd.js +51 -49
  119. package/package.json +12 -10
  120. package/dist/chunks/service-status-0f489yfb.js +0 -102
  121. package/dist/chunks/service-status-2f9g7rg2.js +0 -20
  122. package/dist/chunks/service-status-hwdnjend.js +0 -40
  123. package/dist/chunks/service-status-j3461ttv.js +0 -59
  124. package/dist/chunks/service-status-z9g9xjb3.js +0 -30
  125. package/dist/chunks/service-status-zy1wt1f8.js +0 -23
  126. package/dist/pty-environment.d.ts +0 -13
  127. package/dist/pty-environment.js +0 -12
  128. /package/dist/chunks/{service-status-9rqn6x4v.js → server-info-9rqn6x4v.js} +0 -0
  129. /package/dist/chunks/{service-status-h6rt5k9s.js → server-info-h6rt5k9s.js} +0 -0
  130. /package/dist/chunks/{service-status-q4bn6dy8.js → server-info-q4bn6dy8.js} +0 -0
  131. /package/dist/chunks/{service-status-smaf4a18.js → server-info-smaf4a18.js} +0 -0
  132. /package/dist/chunks/{service-status-yc7nft6q.js → server-info-yc7nft6q.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./service-status-r82dtfrk.js";
3
+ } from "./server-info-j87xz9bt.js";
4
4
 
5
5
  // src/handlers/rpc.ts
6
6
  import { Rpc } from "@opencode/core/rpc";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "./service-status-9rqn6x4v.js";
3
+ } from "./server-info-9rqn6x4v.js";
4
4
 
5
5
  // src/event-feed.ts
6
6
  var exports_event_feed = {};
@@ -11,7 +11,7 @@ __export(exports_event_feed, {
11
11
  SubscriberCapacity: () => SubscriberCapacity2,
12
12
  SubscriberOverflowError: () => SubscriberOverflowError2,
13
13
  frame: () => frame2,
14
- layer: () => layer4,
14
+ layer: () => layer3,
15
15
  make: () => make4
16
16
  });
17
17
  import { Bus } from "@opencode/core/bus";
@@ -40,9 +40,9 @@ function frame2(event) {
40
40
  var make4 = Effect.fn("EventFeed.make")(function* (observe, options) {
41
41
  const capacity = options?.capacity ?? SubscriberCapacity2;
42
42
  const render = options?.encode ?? frame2;
43
- const subscribers = new Set;
43
+ const subscribers = new Map;
44
44
  const fail = (error) => Effect.sync(() => {
45
- const current = Array.from(subscribers);
45
+ const current = Array.from(subscribers.keys());
46
46
  subscribers.clear();
47
47
  for (const subscriber of current)
48
48
  Queue.failCauseUnsafe(subscriber, Cause.fail(error));
@@ -50,19 +50,20 @@ var make4 = Effect.fn("EventFeed.make")(function* (observe, options) {
50
50
  const publish = Effect.fnUntraced(function* (event) {
51
51
  if (!isOpenCodeEvent(event))
52
52
  return;
53
- if (subscribers.size === 0)
54
- return;
55
- const encoded = yield* Effect.try({
56
- try: () => render(event),
57
- catch: (cause) => new EncodingError2({ eventID: event.id, eventType: event.type, cause })
58
- }).pipe(Effect.catch((error) => Effect.logError("Failed to encode public event", {
59
- eventID: error.eventID,
60
- eventType: error.eventType,
61
- cause: error.cause
62
- }).pipe(Effect.andThen(fail(error)), Effect.as(undefined))));
63
- if (encoded === undefined)
64
- return;
65
- for (const subscriber of subscribers) {
53
+ let encoded;
54
+ for (const [subscriber, types] of subscribers) {
55
+ if (types && !types.has(event.type))
56
+ continue;
57
+ encoded ??= yield* Effect.try({
58
+ try: () => render(event),
59
+ catch: (cause) => new EncodingError2({ eventID: event.id, eventType: event.type, cause })
60
+ }).pipe(Effect.catch((error) => Effect.logError("Failed to encode public event", {
61
+ eventID: error.eventID,
62
+ eventType: error.eventType,
63
+ cause: error.cause
64
+ }).pipe(Effect.andThen(fail(error)), Effect.as(undefined))));
65
+ if (encoded === undefined)
66
+ return;
66
67
  if (Queue.offerUnsafe(subscriber, encoded))
67
68
  continue;
68
69
  subscribers.delete(subscriber);
@@ -72,12 +73,12 @@ var make4 = Effect.fn("EventFeed.make")(function* (observe, options) {
72
73
  const unsubscribe = yield* observe(publish);
73
74
  yield* Effect.addFinalizer(() => unsubscribe);
74
75
  return Service4.of({
75
- subscribe: Effect.acquireRelease(Queue.dropping(capacity).pipe(Effect.tap((queue) => Effect.sync(() => subscribers.add(queue)))), (queue) => Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue)), Effect.asVoid)).pipe(Effect.map(Stream.fromQueue))
76
+ subscribe: (types) => Effect.acquireRelease(Queue.dropping(capacity).pipe(Effect.tap((queue) => Effect.sync(() => subscribers.set(queue, types?.length ? new Set(types) : undefined)))), (queue) => Effect.sync(() => subscribers.delete(queue)).pipe(Effect.andThen(Queue.shutdown(queue)), Effect.asVoid)).pipe(Effect.map(Stream.fromQueue))
76
77
  });
77
78
  });
78
- var layer4 = Layer.effect(Service4, Effect.gen(function* () {
79
+ var layer3 = Layer.effect(Service4, Effect.gen(function* () {
79
80
  const bus = yield* Bus.Service;
80
81
  return yield* make4(bus.listen);
81
82
  }));
82
83
 
83
- export { SubscriberCapacity2, SubscriberOverflowError2, EncodingError2, Service4, frame2, make4, layer4, exports_event_feed };
84
+ export { SubscriberCapacity2, SubscriberOverflowError2, EncodingError2, Service4, frame2, make4, layer3, exports_event_feed };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  response2
3
- } from "./service-status-gymtz25n.js";
3
+ } from "./server-info-50bbk3b2.js";
4
4
  import {
5
5
  Api2
6
- } from "./service-status-r82dtfrk.js";
6
+ } from "./server-info-j87xz9bt.js";
7
7
 
8
8
  // src/handlers/reference.ts
9
9
  import { Reference } from "@opencode/core/reference";
@@ -3,15 +3,19 @@ import {
3
3
  missingMessage2,
4
4
  failedMessageDecode2,
5
5
  failedSnapshot2
6
- } from "./service-status-smaf4a18.js";
6
+ } from "./server-info-smaf4a18.js";
7
7
  import {
8
8
  locationErrors2
9
- } from "./service-status-gymtz25n.js";
9
+ } from "./server-info-50bbk3b2.js";
10
10
  import {
11
11
  Api2
12
- } from "./service-status-r82dtfrk.js";
12
+ } from "./server-info-j87xz9bt.js";
13
+ import {
14
+ wantsMediaRefs2
15
+ } from "./server-info-xthc02cw.js";
13
16
 
14
17
  // src/handlers/session.ts
18
+ import { Instance } from "@opencode/core/instance/service";
15
19
  import { Session } from "@opencode/core/session";
16
20
  import { SessionStats } from "@opencode/core/session/stats";
17
21
  import { SessionTitle } from "@opencode/core/session/title";
@@ -19,7 +23,10 @@ import { SessionTransfer } from "@opencode/core/session/transfer";
19
23
  import { InstructionEntry } from "@opencode/core/session/instruction-entry";
20
24
  import { Form } from "@opencode/core/form";
21
25
  import { DateTime, Effect, Stream } from "effect";
26
+ import { HttpServerResponse } from "effect/http";
22
27
  import { HttpApiBuilder, HttpApiSchema } from "effect/http-api";
28
+ import { SessionMediaMessageResponse } from "@opencode/protocol/groups/message";
29
+ import { SessionMediaInboxResponse } from "@opencode/protocol/groups/session";
23
30
  import {
24
31
  ConflictError,
25
32
  CommandExecutionError,
@@ -41,6 +48,9 @@ function missingForm(id) {
41
48
  var SessionHandler2 = HttpApiBuilder.group(Api2, "server.session", (handlers) => Effect.gen(function* () {
42
49
  const session = yield* Session.Service;
43
50
  const transfer = yield* SessionTransfer.Service;
51
+ const instructions = yield* InstructionEntry.Service;
52
+ const instances = yield* Instance.Service;
53
+ const requireSession = (sessionID) => session.get(sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
44
54
  const requireOwnedForm = Effect.fnUntraced(function* (sessionID, formID) {
45
55
  const form = yield* Form.Service;
46
56
  const info = yield* form.get(formID).pipe(Effect.catchTag("Form.NotFoundError", () => missingForm(formID)));
@@ -125,13 +135,12 @@ var SessionHandler2 = HttpApiBuilder.group(Api2, "server.session", (handlers) =>
125
135
  yield* session.switchModel({ sessionID: ctx.params.sessionID, model: ctx.payload.model }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
126
136
  return HttpApiSchema.NoContent.make();
127
137
  })).handle("session.update", Effect.fn(function* (ctx) {
128
- yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
138
+ const info = yield* requireSession(ctx.params.sessionID);
129
139
  if (ctx.payload.title !== undefined) {
130
140
  if (ctx.payload.title) {
131
141
  yield* session.rename({ sessionID: ctx.params.sessionID, title: ctx.payload.title }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
132
142
  } else {
133
- const title = yield* SessionTitle.Service;
134
- yield* title.generate(ctx.params.sessionID);
143
+ yield* SessionTitle.Service.use((title) => title.generate(ctx.params.sessionID)).pipe(instances.provide(info), locationErrors2);
135
144
  }
136
145
  }
137
146
  if (ctx.payload.metadata !== undefined)
@@ -242,6 +251,10 @@ var SessionHandler2 = HttpApiBuilder.group(Api2, "server.session", (handlers) =>
242
251
  data: yield* session.diff({ sessionID: ctx.params.sessionID, ...ctx.query }).pipe(Effect.catchTag("Session.NotFoundError", missingSession2), Effect.catchTag("Session.MessageNotFoundError", missingMessage2), Effect.catchTag("Session.TurnRangeError", (error) => new InvalidRequestError({ message: error.message, field: error.field })), Effect.catchTag("Snapshot.Error", failedSnapshot2("diff session turn", ctx.params.sessionID)), locationErrors2)
243
252
  };
244
253
  })).handle("session.inbox.list", Effect.fn(function* (ctx) {
254
+ if (wantsMediaRefs2(ctx.request))
255
+ return yield* HttpServerResponse.schemaJson(SessionMediaInboxResponse)({
256
+ data: yield* session.inboxWithRefs(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
257
+ }).pipe(Effect.orDie);
245
258
  return {
246
259
  data: yield* session.inbox(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2))
247
260
  };
@@ -251,14 +264,14 @@ var SessionHandler2 = HttpApiBuilder.group(Api2, "server.session", (handlers) =>
251
264
  })).handle("session.inbox.update", Effect.fn(function* (ctx) {
252
265
  return yield* pendingMutation(ctx.payload.delivery === "steer" ? session.steerInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }) : session.queueInbox({ sessionID: ctx.params.sessionID, inboxID: ctx.params.inboxID }), `Pending input cannot change to ${ctx.payload.delivery}`);
253
266
  })).handle("session.instructions.entry.list", Effect.fn(function* (ctx) {
254
- const instructions = yield* InstructionEntry.Service;
267
+ yield* requireSession(ctx.params.sessionID);
255
268
  return { data: yield* instructions.list(ctx.params.sessionID) };
256
269
  })).handle("session.instructions.entry.put", Effect.fn(function* (ctx) {
257
- const instructions = yield* InstructionEntry.Service;
270
+ yield* requireSession(ctx.params.sessionID);
258
271
  yield* instructions.put({ sessionID: ctx.params.sessionID, key: ctx.params.key, value: ctx.payload.value });
259
272
  return HttpApiSchema.NoContent.make();
260
273
  })).handle("session.instructions.entry.remove", Effect.fn(function* (ctx) {
261
- const instructions = yield* InstructionEntry.Service;
274
+ yield* requireSession(ctx.params.sessionID);
262
275
  yield* instructions.remove({ sessionID: ctx.params.sessionID, key: ctx.params.key });
263
276
  return HttpApiSchema.NoContent.make();
264
277
  })).handle("session.generate", Effect.fn(function* (ctx) {
@@ -268,15 +281,22 @@ var SessionHandler2 = HttpApiBuilder.group(Api2, "server.session", (handlers) =>
268
281
  yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
269
282
  return session.log({ sessionID: ctx.params.sessionID, after: ctx.query.after, follow: ctx.query.follow }).pipe(Stream.orDie);
270
283
  })).handle("session.interrupt", Effect.fn(function* (ctx) {
284
+ yield* requireSession(ctx.params.sessionID);
271
285
  return { interrupted: yield* session.interrupt(ctx.params.sessionID, { resume: ctx.query.resume }) };
272
286
  })).handle("session.background", Effect.fn(function* (ctx) {
273
287
  yield* session.background(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
274
288
  return HttpApiSchema.NoContent.make();
275
289
  })).handle("session.message", Effect.fn(function* (ctx) {
276
290
  yield* session.get(ctx.params.sessionID).pipe(Effect.catchTag("Session.NotFoundError", missingSession2));
277
- const message = yield* session.message(ctx.params);
278
- if (message)
279
- return { data: message };
291
+ if (wantsMediaRefs2(ctx.request)) {
292
+ const message = yield* session.messageWithRefs(ctx.params);
293
+ if (message)
294
+ return yield* HttpServerResponse.schemaJson(SessionMediaMessageResponse)({ data: message }).pipe(Effect.orDie);
295
+ } else {
296
+ const message = yield* session.message(ctx.params);
297
+ if (message)
298
+ return { data: message };
299
+ }
280
300
  return yield* new MessageNotFoundError({
281
301
  sessionID: ctx.params.sessionID,
282
302
  messageID: ctx.params.messageID,
@@ -0,0 +1,6 @@
1
+ // src/media-uri.ts
2
+ var CAPABILITIES_HEADER = "x-opencode-capabilities";
3
+ var MEDIA_URI_CAPABILITY = "experimental-media-uri";
4
+ var wantsMediaRefs2 = (request) => request.headers[CAPABILITIES_HEADER]?.split(",").some((token) => token.trim().toLowerCase() === MEDIA_URI_CAPABILITY) ?? false;
5
+
6
+ export { wantsMediaRefs2 };
@@ -0,0 +1,83 @@
1
+ import {
2
+ locationErrors2,
3
+ awaitPlugins2
4
+ } from "./server-info-50bbk3b2.js";
5
+ import {
6
+ Api2
7
+ } from "./server-info-j87xz9bt.js";
8
+
9
+ // src/handlers/generate.ts
10
+ import { Generate } from "@opencode/core/generate";
11
+ import { Location } from "@opencode/core/location";
12
+ import { LocationServiceMap } from "@opencode/core/location-services";
13
+ import { AbsolutePath } from "@opencode/core/schema";
14
+ import {
15
+ InvalidRequestError,
16
+ ModelNotFoundError,
17
+ ProviderRequestError,
18
+ ServiceUnavailableError,
19
+ UnsupportedModelError
20
+ } from "@opencode/protocol/errors";
21
+ import { Global } from "@opencode/util/global";
22
+ import { Effect } from "effect";
23
+ import { HttpApiBuilder } from "effect/http-api";
24
+ var GenerateHandler2 = HttpApiBuilder.group(Api2, "server.generate", (handlers) => Effect.gen(function* () {
25
+ const global = yield* Global.Service;
26
+ const locations = yield* LocationServiceMap.Service;
27
+ const services = locations.get(Location.Ref.make({ directory: AbsolutePath.make(global.config) }));
28
+ const text = Effect.fn("server.generate.text")(function* (request) {
29
+ yield* awaitPlugins2;
30
+ const generate = yield* Generate.Service;
31
+ return { data: { text: yield* generate.text(request.payload).pipe(Effect.mapError(generateError)) } };
32
+ }, Effect.provide(services), locationErrors2);
33
+ const image = Effect.fn("server.generate.image")(function* (request) {
34
+ yield* awaitPlugins2;
35
+ const generate = yield* Generate.Service;
36
+ return { data: yield* generate.image(request.payload).pipe(Effect.mapError(generateError)) };
37
+ }, Effect.provide(services), locationErrors2);
38
+ const decisions = Effect.fn("server.generate.decisions")(function* (request) {
39
+ const names = new Set(request.payload.questions.map((question) => question.name));
40
+ if (names.size !== request.payload.questions.length)
41
+ return yield* new InvalidRequestError({
42
+ message: "Decision question names must be unique",
43
+ field: "questions"
44
+ });
45
+ yield* awaitPlugins2;
46
+ const generate = yield* Generate.Service;
47
+ return { data: yield* generate.decisions(request.payload).pipe(Effect.mapError(generateError)) };
48
+ }, Effect.provide(services), locationErrors2);
49
+ return handlers.handle("generate.text", text).handle("generate.textLegacy", text).handle("generate.image", image).handle("generate.decisions", decisions);
50
+ }));
51
+ function generateError(error) {
52
+ switch (error._tag) {
53
+ case "Generate.ModelNotFoundError":
54
+ return new ModelNotFoundError({ providerID: error.providerID, modelID: error.modelID, message: error.message });
55
+ case "Generate.UnsupportedModelError":
56
+ return new UnsupportedModelError({
57
+ providerID: error.providerID,
58
+ modelID: error.modelID,
59
+ capability: error.capability,
60
+ message: error.message
61
+ });
62
+ case "Generate.InvalidRequestError":
63
+ return new InvalidRequestError({
64
+ message: error.message,
65
+ ...error.field === undefined ? {} : { field: error.field }
66
+ });
67
+ case "Generate.ProviderRequestError":
68
+ return new ProviderRequestError({
69
+ providerID: error.providerID,
70
+ reason: error.reason,
71
+ message: error.message,
72
+ ...error.status === undefined ? {} : { status: error.status },
73
+ ...error.retryAfterMs === undefined ? {} : { retryAfterMs: error.retryAfterMs }
74
+ });
75
+ case "Generate.UnavailableError":
76
+ return new ServiceUnavailableError({
77
+ message: error.message,
78
+ ...error.service === undefined ? {} : { service: error.service }
79
+ });
80
+ }
81
+ }
82
+
83
+ export { GenerateHandler2 };
@@ -1,33 +1,35 @@
1
1
  import {
2
2
  Api2
3
- } from "./service-status-r82dtfrk.js";
3
+ } from "./server-info-j87xz9bt.js";
4
4
  import {
5
5
  SESSION_TTL_SECONDS2,
6
6
  Config2,
7
7
  issueSession2,
8
8
  sessionCookieName2
9
- } from "./service-status-j4at0y5c.js";
10
- import {
11
- Service5
12
- } from "./service-status-x2cwbfak.js";
9
+ } from "./server-info-j4at0y5c.js";
13
10
  import {
14
11
  Service3
15
- } from "./service-status-vb61dkrm.js";
12
+ } from "./server-info-5pdfedjd.js";
13
+ import {
14
+ Service2
15
+ } from "./server-info-kqr36gas.js";
16
16
 
17
17
  // src/handlers/server.ts
18
+ import { hostname } from "node:os";
18
19
  import { Duration, Effect } from "effect";
19
20
  import { HttpServerRequest, HttpServerResponse } from "effect/http";
20
21
  import { HttpApiBuilder } from "effect/http-api";
21
22
  import { PersistentPty } from "@opencode/core/persistent-pty";
22
23
  import { UnauthorizedError } from "@opencode/protocol/errors";
23
24
  var ServerHandler2 = HttpApiBuilder.group(Api2, "server.server", (handlers) => Effect.gen(function* () {
24
- const pairing = yield* Service3;
25
+ const pairing = yield* Service2;
25
26
  const auth = yield* Config2;
26
27
  return handlers.handle("server.info", () => Effect.gen(function* () {
27
- const info = yield* Service5;
28
+ const info = yield* Service3;
28
29
  return {
29
30
  version: info.app.version ?? "unknown",
30
31
  pid: process.pid ?? 0,
32
+ hostname: hostname() || undefined,
31
33
  urls: info.urls(),
32
34
  paths: info.paths,
33
35
  capabilities: { persistentPty: PersistentPty.available }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Api2
3
- } from "./service-status-r82dtfrk.js";
3
+ } from "./server-info-j87xz9bt.js";
4
4
 
5
5
  // src/handlers/location.ts
6
6
  import { Location } from "@opencode/core/location";
@@ -2,20 +2,17 @@ import {
2
2
  locationErrors2,
3
3
  response2,
4
4
  requestRef2
5
- } from "./service-status-gymtz25n.js";
5
+ } from "./server-info-50bbk3b2.js";
6
6
  import {
7
7
  Api2
8
- } from "./service-status-r82dtfrk.js";
8
+ } from "./server-info-j87xz9bt.js";
9
9
  import {
10
10
  CorsConfig2,
11
11
  isAllowedRequestOrigin2
12
- } from "./service-status-q4bn6dy8.js";
13
- import {
14
- Service2
15
- } from "./service-status-zy1wt1f8.js";
12
+ } from "./server-info-q4bn6dy8.js";
16
13
  import {
17
14
  runPtySocket2
18
- } from "./service-status-h6rt5k9s.js";
15
+ } from "./server-info-h6rt5k9s.js";
19
16
 
20
17
  // src/handlers/pty.ts
21
18
  import { Pty } from "@opencode/core/pty";
@@ -33,63 +30,43 @@ import {
33
30
  PTY_CONNECT_TOKEN_HEADER,
34
31
  PTY_CONNECT_TOKEN_HEADER_VALUE
35
32
  } from "@opencode/protocol/groups/pty";
36
- var ticketScope = Effect.gen(function* () {
37
- const location = yield* Location.Service;
38
- return { directory: location.directory, workspaceID: location.workspaceID };
39
- });
33
+ var notFound = (ptyID) => new PtyNotFoundError({ ptyID, message: `PTY session not found: ${ptyID}` });
40
34
  var PtyHandler2 = HttpApiBuilder.group(Api2, "server.pty", (handlers) => Effect.gen(function* () {
41
35
  const locations = yield* LocationServiceMap.Service;
42
36
  const tickets = yield* PtyTicket.Service;
43
37
  const cors = yield* CorsConfig2;
44
- const environment = yield* Service2;
45
38
  return handlers.handle("pty.list", Effect.fn(function* () {
46
39
  const pty = yield* Pty.Service;
47
40
  return yield* response2(pty.list());
48
41
  })).handle("pty.create", Effect.fn(function* (ctx) {
49
42
  const pty = yield* Pty.Service;
50
43
  const location = yield* Location.Service;
51
- const cwd = ctx.payload.cwd || location.directory;
52
44
  return yield* response2(pty.create({
53
45
  ...ctx.payload,
54
- args: ctx.payload.args ? [...ctx.payload.args] : undefined,
55
- cwd,
56
- env: {
57
- ...ctx.payload.env,
58
- ...yield* environment.get({ directory: location.directory, cwd })
59
- }
46
+ cwd: ctx.payload.cwd || location.directory
60
47
  }));
61
48
  })).handle("pty.get", Effect.fn(function* (ctx) {
62
49
  const pty = yield* Pty.Service;
63
- return yield* response2(pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
64
- ptyID: ctx.params.ptyID,
65
- message: `PTY session not found: ${ctx.params.ptyID}`
66
- }))));
50
+ return yield* response2(pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID))));
67
51
  })).handle("pty.update", Effect.fn(function* (ctx) {
68
52
  const pty = yield* Pty.Service;
69
- return yield* response2(pty.update(ctx.params.ptyID, {
70
- ...ctx.payload,
71
- size: ctx.payload.size ? { ...ctx.payload.size } : undefined
72
- }).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
73
- ptyID: ctx.params.ptyID,
74
- message: `PTY session not found: ${ctx.params.ptyID}`
75
- }))));
53
+ return yield* response2(pty.update(ctx.params.ptyID, ctx.payload).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID))));
76
54
  })).handle("pty.remove", Effect.fn(function* (ctx) {
77
55
  const pty = yield* Pty.Service;
78
- yield* pty.remove(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
79
- ptyID: ctx.params.ptyID,
80
- message: `PTY session not found: ${ctx.params.ptyID}`
81
- })));
56
+ yield* pty.remove(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID)));
82
57
  return HttpApiSchema.NoContent.make();
83
58
  })).handle("pty.connectToken", Effect.fn(function* (ctx) {
84
59
  const request = yield* HttpServerRequest.HttpServerRequest;
85
60
  if (request.headers[PTY_CONNECT_TOKEN_HEADER] !== PTY_CONNECT_TOKEN_HEADER_VALUE || !isAllowedRequestOrigin2(request.headers.origin, request.headers.host, cors))
86
61
  return yield* new ForbiddenError({ message: "Invalid PTY connect token request" });
87
62
  const pty = yield* Pty.Service;
88
- yield* pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => new PtyNotFoundError({
63
+ const location = yield* Location.Service;
64
+ yield* pty.get(ctx.params.ptyID).pipe(Effect.catchTag("Pty.NotFoundError", () => notFound(ctx.params.ptyID)));
65
+ return yield* response2(tickets.issue({
89
66
  ptyID: ctx.params.ptyID,
90
- message: `PTY session not found: ${ctx.params.ptyID}`
91
- })));
92
- return yield* response2(tickets.issue({ ptyID: ctx.params.ptyID, ...yield* ticketScope }));
67
+ directory: location.directory,
68
+ workspaceID: location.workspaceID
69
+ }));
93
70
  })).handleRaw("pty.connect", Effect.fn("PtyHandler.connect")(function* (ctx) {
94
71
  if (!isAllowedRequestOrigin2(ctx.request.headers.origin, ctx.request.headers.host, cors))
95
72
  return HttpServerResponse.empty({ status: 403 });
package/dist/cors.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  CorsConfig2,
3
3
  isAllowedCorsOrigin2,
4
4
  isAllowedRequestOrigin2
5
- } from "./chunks/service-status-q4bn6dy8.js";
5
+ } from "./chunks/server-info-q4bn6dy8.js";
6
6
  export {
7
7
  CorsConfig2 as CorsConfig,
8
8
  isAllowedCorsOrigin2 as isAllowedCorsOrigin,
@@ -19,7 +19,7 @@ export declare class EncodingError extends EncodingError_base {
19
19
  }
20
20
  export type Error = SubscriberOverflowError | EncodingError;
21
21
  export interface Interface {
22
- readonly subscribe: Effect.Effect<Stream.Stream<string, Error>, never, Scope.Scope>;
22
+ readonly subscribe: (types?: ReadonlyArray<string>) => Effect.Effect<Stream.Stream<string, Error>, never, Scope.Scope>;
23
23
  }
24
24
  declare const Service_base: Context.ServiceClass<Service, "@opencode/server/EventFeed", Interface>;
25
25
  export declare class Service extends Service_base {
@@ -5,9 +5,9 @@ import {
5
5
  Service4,
6
6
  frame2,
7
7
  make4,
8
- layer4,
8
+ layer3,
9
9
  exports_event_feed
10
- } from "./chunks/service-status-k6dz4enc.js";
10
+ } from "./chunks/server-info-s802fzg1.js";
11
11
  export {
12
12
  EncodingError2 as EncodingError,
13
13
  exports_event_feed as EventFeed,
@@ -15,6 +15,6 @@ export {
15
15
  SubscriberCapacity2 as SubscriberCapacity,
16
16
  SubscriberOverflowError2 as SubscriberOverflowError,
17
17
  frame2 as frame,
18
- layer4 as layer,
18
+ layer3 as layer,
19
19
  make4 as make
20
20
  };
package/dist/fetch.js CHANGED
@@ -1,54 +1,56 @@
1
1
  import {
2
2
  make2,
3
3
  exports_fetch
4
- } from "./chunks/service-status-79n3507d.js";
5
- import"./chunks/service-status-5680j7c4.js";
6
- import"./chunks/service-status-6v4wsps6.js";
7
- import"./chunks/service-status-erzfdgke.js";
8
- import"./chunks/service-status-0f489yfb.js";
9
- import"./chunks/service-status-xcxwzp6z.js";
10
- import"./chunks/service-status-6tj91hdj.js";
11
- import"./chunks/service-status-5ewqf72w.js";
12
- import"./chunks/service-status-7scj3y0h.js";
13
- import"./chunks/service-status-10kexchg.js";
14
- import"./chunks/service-status-11d378s5.js";
15
- import"./chunks/service-status-2f9g7rg2.js";
16
- import"./chunks/service-status-q6jxy1hn.js";
17
- import"./chunks/service-status-yzwm8eeq.js";
18
- import"./chunks/service-status-y89d99mz.js";
19
- import"./chunks/service-status-pf9k0dqe.js";
20
- import"./chunks/service-status-krqg3gd2.js";
21
- import"./chunks/service-status-0znmasm1.js";
22
- import"./chunks/service-status-5adf1am9.js";
23
- import"./chunks/service-status-6tjqh8g4.js";
24
- import"./chunks/service-status-h6rt5k9s.js";
25
- import"./chunks/service-status-c2hv5jmf.js";
26
- import"./chunks/service-status-6e6jjne7.js";
27
- import"./chunks/service-status-7qrtcnv4.js";
28
- import"./chunks/service-status-hwdnjend.js";
29
- import"./chunks/service-status-z9g9xjb3.js";
30
- import"./chunks/service-status-crt28xe4.js";
31
- import"./chunks/service-status-1qc831kp.js";
32
- import"./chunks/service-status-2e16a9cc.js";
33
- import"./chunks/service-status-vg0x3zn0.js";
34
- import"./chunks/service-status-z554rpg5.js";
35
- import"./chunks/service-status-rj8tbp10.js";
36
- import"./chunks/service-status-rkmbbexc.js";
37
- import"./chunks/service-status-53jj3zgg.js";
38
- import"./chunks/service-status-j3461ttv.js";
39
- import"./chunks/service-status-a30hykaf.js";
40
- import"./chunks/service-status-jwf0kwqx.js";
41
- import"./chunks/service-status-r82dtfrk.js";
42
- import"./chunks/service-status-x74w7e1f.js";
43
- import"./chunks/service-status-3154e7fk.js";
44
- import"./chunks/service-status-gymtz25n.js";
45
- import"./chunks/service-status-smaf4a18.js";
46
- import"./chunks/service-status-zy1wt1f8.js";
47
- import"./chunks/service-status-vb61dkrm.js";
48
- import"./chunks/service-status-q4bn6dy8.js";
49
- import"./chunks/service-status-k6dz4enc.js";
50
- import"./chunks/service-status-x2cwbfak.js";
51
- import"./chunks/service-status-j4at0y5c.js";
4
+ } from "./chunks/server-info-1wd9c1m3.js";
5
+ import"./chunks/server-info-j2d131x1.js";
6
+ import"./chunks/server-info-bd8755ek.js";
7
+ import"./chunks/server-info-7b9xm1qg.js";
8
+ import"./chunks/server-info-b0f38s3n.js";
9
+ import"./chunks/server-info-b105zy65.js";
10
+ import"./chunks/server-info-kkdkqt8j.js";
11
+ import"./chunks/server-info-1gwc8nvb.js";
12
+ import"./chunks/server-info-ny1j968n.js";
13
+ import"./chunks/server-info-zpr61asr.js";
14
+ import"./chunks/server-info-yxw63vq5.js";
15
+ import"./chunks/server-info-6z9pvq7p.js";
16
+ import"./chunks/server-info-f559fakr.js";
17
+ import"./chunks/server-info-btahnm2b.js";
18
+ import"./chunks/server-info-rw1dfckh.js";
19
+ import"./chunks/server-info-n321d8vm.js";
20
+ import"./chunks/server-info-1v577ncx.js";
21
+ import"./chunks/server-info-h29xjj1e.js";
22
+ import"./chunks/server-info-rha2aq18.js";
23
+ import"./chunks/server-info-te8jwba1.js";
24
+ import"./chunks/server-info-5b42hxrf.js";
25
+ import"./chunks/server-info-zcvan105.js";
26
+ import"./chunks/server-info-az0609r6.js";
27
+ import"./chunks/server-info-qcg3sqtb.js";
28
+ import"./chunks/server-info-qd0r787n.js";
29
+ import"./chunks/server-info-2h6qktqa.js";
30
+ import"./chunks/server-info-4q6e7fh8.js";
31
+ import"./chunks/server-info-yqhefp4s.js";
32
+ import"./chunks/server-info-cezwbsk5.js";
33
+ import"./chunks/server-info-bhbc7551.js";
34
+ import"./chunks/server-info-h6rt5k9s.js";
35
+ import"./chunks/server-info-d0edqfxx.js";
36
+ import"./chunks/server-info-a8jcac9a.js";
37
+ import"./chunks/server-info-4fy84009.js";
38
+ import"./chunks/server-info-2eaky32g.js";
39
+ import"./chunks/server-info-5s6gh8sx.js";
40
+ import"./chunks/server-info-tjtyxt9h.js";
41
+ import"./chunks/server-info-nx6f5k7a.js";
42
+ import"./chunks/server-info-s282vggx.js";
43
+ import"./chunks/server-info-j87xz9bt.js";
44
+ import"./chunks/server-info-htyf2qs7.js";
45
+ import"./chunks/server-info-b3bmdkga.js";
46
+ import"./chunks/server-info-j4at0y5c.js";
47
+ import"./chunks/server-info-kqr36gas.js";
48
+ import"./chunks/server-info-q4bn6dy8.js";
49
+ import"./chunks/server-info-5pdfedjd.js";
50
+ import"./chunks/server-info-xthc02cw.js";
51
+ import"./chunks/server-info-s802fzg1.js";
52
+ import"./chunks/server-info-50bbk3b2.js";
53
+ import"./chunks/server-info-smaf4a18.js";
52
54
  export {
53
55
  exports_fetch as ServerFetch,
54
56
  make2 as make
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  AgentHandler2
3
- } from "../chunks/service-status-z554rpg5.js";
4
- import"../chunks/service-status-r82dtfrk.js";
5
- import"../chunks/service-status-x74w7e1f.js";
6
- import"../chunks/service-status-3154e7fk.js";
7
- import"../chunks/service-status-gymtz25n.js";
8
- import"../chunks/service-status-smaf4a18.js";
3
+ } from "../chunks/server-info-1v577ncx.js";
4
+ import"../chunks/server-info-j87xz9bt.js";
5
+ import"../chunks/server-info-htyf2qs7.js";
6
+ import"../chunks/server-info-b3bmdkga.js";
7
+ import"../chunks/server-info-50bbk3b2.js";
8
+ import"../chunks/server-info-smaf4a18.js";
9
9
  export {
10
10
  AgentHandler2 as AgentHandler
11
11
  };