@opencode/client 2.1.4 → 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 (73) hide show
  1. package/dist/chunks/service-timing-6mq2wh8y.js +33 -0
  2. package/dist/chunks/{contract-y2etg5bs.js → service-timing-7f0py9js.js} +2 -2
  3. package/dist/chunks/{contract-c46qzyff.js → service-timing-8we1dz3p.js} +5 -1
  4. package/dist/chunks/{contract-2ny4vxct.js → service-timing-8ye1ye6f.js} +2 -2
  5. package/dist/chunks/{contract-skhp7hxc.js → service-timing-ab9bm97w.js} +1 -1
  6. package/dist/chunks/service-timing-b80wmp2t.js +30 -0
  7. package/dist/chunks/{contract-1x65x4hv.js → service-timing-cyxwqteg.js} +97 -56
  8. package/dist/chunks/{contract-8bbb028w.js → service-timing-gecjxyvt.js} +5 -1
  9. package/dist/chunks/{contract-hg9t2gnm.js → service-timing-jpd9ebw3.js} +17 -17
  10. package/dist/chunks/{contract-nwcpakzx.js → service-timing-js54wxgp.js} +2 -2
  11. package/dist/chunks/{contract-9kmsh4jj.js → service-timing-knyqkv17.js} +2 -2
  12. package/dist/chunks/{contract-15p82y03.js → service-timing-myz4ngx9.js} +5 -5
  13. package/dist/chunks/{contract-w10x3kfx.js → service-timing-rxd7awy0.js} +51 -21
  14. package/dist/chunks/{contract-ryy6kscr.js → service-timing-ryy6kscr.js} +1 -1
  15. package/dist/chunks/{contract-s2hya144.js → service-timing-wcsbjfhx.js} +110 -36
  16. package/dist/contract.js +1 -1
  17. package/dist/effect/api/api.d.ts +72 -13
  18. package/dist/effect/api.d.ts +1 -0
  19. package/dist/effect/client.d.ts +126 -114
  20. package/dist/effect/client.js +12 -12
  21. package/dist/effect/generated/client-error.js +3 -3
  22. package/dist/effect/generated/client.d.ts +27 -19
  23. package/dist/effect/generated/client.js +5 -5
  24. package/dist/effect/generated/index.js +8 -8
  25. package/dist/effect/index.js +12 -12
  26. package/dist/effect/rpc.js +4 -4
  27. package/dist/effect/service.js +6 -6
  28. package/dist/promise/api.d.ts +1 -0
  29. package/dist/promise/client.d.ts +12 -5
  30. package/dist/promise/client.js +11 -11
  31. package/dist/promise/generated/client-error.js +3 -3
  32. package/dist/promise/generated/client.d.ts +13 -6
  33. package/dist/promise/generated/client.js +4 -4
  34. package/dist/promise/generated/index.js +16 -8
  35. package/dist/promise/generated/types.d.ts +1151 -3533
  36. package/dist/promise/generated/types.js +9 -1
  37. package/dist/promise/index.d.ts +1 -0
  38. package/dist/promise/index.js +20 -12
  39. package/dist/promise/rpc.js +2 -2
  40. package/dist/promise/service.d.ts +2 -2
  41. package/dist/promise/service.js +7 -6
  42. package/dist/pty-handoff.js +4 -4
  43. package/dist/rpc-runtime.js +1 -1
  44. package/dist/service-contender.js +1 -1
  45. package/dist/service-probe.js +3 -3
  46. package/dist/service-timing.js +1 -1
  47. package/dist/service-version.js +1 -1
  48. package/dist/service.js +1 -1
  49. package/dist/shared-events.d.ts +7 -2
  50. package/dist/shared-events.js +1 -1
  51. package/dist/solid/connection.js +1 -1
  52. package/dist/solid/data.d.ts +11 -1
  53. package/dist/solid/data.js +9 -9
  54. package/dist/solid/index.d.ts +1 -0
  55. package/dist/solid/index.js +16 -12
  56. package/dist/solid/pty.js +1 -1
  57. package/dist/solid/retention.d.ts +10 -0
  58. package/dist/solid/retention.js +6 -0
  59. package/dist/solid/usage.js +1 -1
  60. package/package.json +7 -6
  61. package/dist/chunks/contract-vwtmm97t.js +0 -30
  62. /package/dist/chunks/{contract-6mptkzbc.js → service-timing-6mptkzbc.js} +0 -0
  63. /package/dist/chunks/{contract-8s2anffy.js → service-timing-8s2anffy.js} +0 -0
  64. /package/dist/chunks/{contract-9rqn6x4v.js → service-timing-9rqn6x4v.js} +0 -0
  65. /package/dist/chunks/{contract-gne7h7mq.js → service-timing-gne7h7mq.js} +0 -0
  66. /package/dist/chunks/{contract-m2eywc8w.js → service-timing-m2eywc8w.js} +0 -0
  67. /package/dist/chunks/{contract-qav6mfdz.js → service-timing-qav6mfdz.js} +0 -0
  68. /package/dist/chunks/{contract-sxt88q69.js → service-timing-sxt88q69.js} +0 -0
  69. /package/dist/chunks/{contract-ve4aws36.js → service-timing-ve4aws36.js} +0 -0
  70. /package/dist/chunks/{contract-vmytr4q8.js → service-timing-vmytr4q8.js} +0 -0
  71. /package/dist/chunks/{contract-vyas3vgt.js → service-timing-vyas3vgt.js} +0 -0
  72. /package/dist/chunks/{contract-xgnj2w4v.js → service-timing-xgnj2w4v.js} +0 -0
  73. /package/dist/chunks/{contract-ydhz1zrh.js → service-timing-ydhz1zrh.js} +0 -0
@@ -0,0 +1,33 @@
1
+ // src/solid/retention.ts
2
+ import { createEffect, untrack } from "solid-js";
3
+ function createSessionRetention2(input) {
4
+ let previous;
5
+ let recent = [];
6
+ let evicted = new Map;
7
+ createEffect(() => {
8
+ const viewed = input.current();
9
+ const current = viewed === undefined ? undefined : input.session.root(viewed);
10
+ const keep = new Set(input.keep().map((id) => input.session.root(id)));
11
+ recent = [
12
+ ...new Set([
13
+ ...viewed !== previous && current !== undefined ? [current] : [],
14
+ ...recent.map((id) => input.session.root(id))
15
+ ])
16
+ ];
17
+ previous = viewed;
18
+ const retained = new Set([...keep, ...recent.filter((id) => !keep.has(id)).slice(0, input.limit)]);
19
+ if (current !== undefined)
20
+ retained.add(current);
21
+ recent = recent.filter((id) => retained.has(id));
22
+ const count = (id) => untrack(() => input.session.message?.list(id).length ?? 0);
23
+ const excluded = new Map(input.session.list().flatMap((session) => {
24
+ const root = input.session.root(session.id);
25
+ return retained.has(root) ? [] : [[session.id, root]];
26
+ }));
27
+ const roots = new Set([...excluded].filter(([id, root]) => evicted.get(id) !== `${root}:${count(id)}`).map(([, root]) => root));
28
+ untrack(() => roots.forEach((root) => input.session.evict(root)));
29
+ evicted = new Map([...excluded].map(([id, root]) => [id, `${root}:${count(id)}`]));
30
+ });
31
+ }
32
+
33
+ export { createSessionRetention2 };
@@ -1,9 +1,9 @@
1
1
  // src/effect/generated/client-error.ts
2
2
  import { Schema } from "effect";
3
3
 
4
- class ClientError2 extends Schema.TaggedError()("ClientError", {
4
+ class ClientError3 extends Schema.TaggedError()("ClientError", {
5
5
  cause: Schema.Defect()
6
6
  }) {
7
7
  }
8
8
 
9
- export { ClientError2 };
9
+ export { ClientError3 };
@@ -4,6 +4,7 @@ var isUnauthorizedError2 = (value) => typeof value === "object" && value !== nul
4
4
  var isLocationNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "LocationNotFoundError";
5
5
  var isServiceUnavailableError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ServiceUnavailableError";
6
6
  var isAgentNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "AgentNotFoundError";
7
+ var isPluginNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "PluginNotFoundError";
7
8
  var isInvalidCursorError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "InvalidCursorError";
8
9
  var isSessionNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "SessionNotFoundError";
9
10
  var isConflictError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ConflictError";
@@ -18,6 +19,9 @@ var isFormNotFoundError2 = (value) => typeof value === "object" && value !== nul
18
19
  var isFormInvalidAnswerError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FormInvalidAnswerError";
19
20
  var isFormAlreadySettledError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "FormAlreadySettledError";
20
21
  var isProviderNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProviderNotFoundError";
22
+ var isModelNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ModelNotFoundError";
23
+ var isUnsupportedModelError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "UnsupportedModelError";
24
+ var isProviderRequestError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "ProviderRequestError";
21
25
  var isIntegrationNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationNotFoundError";
22
26
  var isIntegrationAttemptNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationAttemptNotFoundError";
23
27
  var isIntegrationMethodNotFoundError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "IntegrationMethodNotFoundError";
@@ -34,4 +38,4 @@ var isShellNotFoundError2 = (value) => typeof value === "object" && value !== nu
34
38
  var isWorktreeError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "WorktreeError";
35
39
  var isVcsInitNotSupportedError2 = (value) => typeof value === "object" && value !== null && ("_tag" in value) && value["_tag"] === "VcsInitNotSupportedError";
36
40
 
37
- export { isInvalidRequestError2, isUnauthorizedError2, isLocationNotFoundError2, isServiceUnavailableError2, isAgentNotFoundError2, isInvalidCursorError2, isSessionNotFoundError2, isConflictError2, isUnknownError2, isMessageNotFoundError2, isCommandNotFoundError2, isCommandExecutionError2, isSkillNotFoundError2, isSessionBusyError2, isInstructionEntryValueTooLargeError2, isFormNotFoundError2, isFormInvalidAnswerError2, isFormAlreadySettledError2, isProviderNotFoundError2, isIntegrationNotFoundError2, isIntegrationAttemptNotFoundError2, isIntegrationMethodNotFoundError2, isMcpServerNotFoundError2, isForbiddenError2, isProjectNotFoundError2, isPermissionSavedNotFoundError2, isPermissionNotFoundError2, isFileNotFoundError2, isRpcError2, isRpcInternalError2, isPtyNotFoundError2, isShellNotFoundError2, isWorktreeError2, isVcsInitNotSupportedError2 };
41
+ export { isInvalidRequestError2, isUnauthorizedError2, isLocationNotFoundError2, isServiceUnavailableError2, isAgentNotFoundError2, isPluginNotFoundError2, isInvalidCursorError2, isSessionNotFoundError2, isConflictError2, isUnknownError2, isMessageNotFoundError2, isCommandNotFoundError2, isCommandExecutionError2, isSkillNotFoundError2, isSessionBusyError2, isInstructionEntryValueTooLargeError2, isFormNotFoundError2, isFormInvalidAnswerError2, isFormAlreadySettledError2, isProviderNotFoundError2, isModelNotFoundError2, isUnsupportedModelError2, isProviderRequestError2, isIntegrationNotFoundError2, isIntegrationAttemptNotFoundError2, isIntegrationMethodNotFoundError2, isMcpServerNotFoundError2, isForbiddenError2, isProjectNotFoundError2, isPermissionSavedNotFoundError2, isPermissionNotFoundError2, isFileNotFoundError2, isRpcError2, isRpcInternalError2, isPtyNotFoundError2, isShellNotFoundError2, isWorktreeError2, isVcsInitNotSupportedError2 };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  defaultEnsureTiming2
3
- } from "./contract-xgnj2w4v.js";
3
+ } from "./service-timing-xgnj2w4v.js";
4
4
  import {
5
5
  matchesVersion2
6
- } from "./contract-sxt88q69.js";
6
+ } from "./service-timing-sxt88q69.js";
7
7
 
8
8
  // src/service-probe.ts
9
9
  import { homedir } from "node:os";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isRpcError2,
3
3
  isRpcInternalError2
4
- } from "./contract-c46qzyff.js";
4
+ } from "./service-timing-8we1dz3p.js";
5
5
 
6
6
  // src/promise/rpc.ts
7
7
  function makeRpc2(raw, events) {
@@ -0,0 +1,30 @@
1
+ import {
2
+ make7
3
+ } from "./service-timing-gecjxyvt.js";
4
+ import {
5
+ make3
6
+ } from "./service-timing-wcsbjfhx.js";
7
+ import {
8
+ makeRpc2
9
+ } from "./service-timing-ab9bm97w.js";
10
+ import {
11
+ __export
12
+ } from "./service-timing-9rqn6x4v.js";
13
+
14
+ // src/promise/client.ts
15
+ var exports_client = {};
16
+ __export(exports_client, {
17
+ OpenCode: () => exports_client,
18
+ make: () => make2
19
+ });
20
+ function make2(options) {
21
+ const raw = make3(options);
22
+ const events = make7((signal, onActivity) => raw.event.subscribe(undefined, { signal, onActivity }));
23
+ return {
24
+ ...raw,
25
+ rpc: Object.assign(makeRpc2(raw, events), raw.rpc),
26
+ event: events
27
+ };
28
+ }
29
+
30
+ export { make2, exports_client };
@@ -2,7 +2,7 @@ import {
2
2
  isFormNotFoundError2,
3
3
  isFormAlreadySettledError2,
4
4
  isPermissionNotFoundError2
5
- } from "./contract-c46qzyff.js";
5
+ } from "./service-timing-8we1dz3p.js";
6
6
 
7
7
  // src/solid/data.ts
8
8
  import { Worktree } from "@opencode/schema/worktree";
@@ -44,6 +44,18 @@ function optimisticFiles(files) {
44
44
  });
45
45
  return items?.length ? items : undefined;
46
46
  }
47
+ function omitFileData(content) {
48
+ const omit = (item) => item.type === "file" && item.uri.startsWith("data:") ? { ...item, uri: `data:${item.mime};base64,` } : item;
49
+ return [omit(content[0]), ...content.slice(1).map(omit)];
50
+ }
51
+ function omitMessageFileData(message) {
52
+ if (message.type !== "assistant")
53
+ return message;
54
+ return {
55
+ ...message,
56
+ content: message.content.map((part) => part.type === "tool" && ("content" in part.state) && part.state.content ? { ...part, state: { ...part.state, content: omitFileData(part.state.content) } } : part)
57
+ };
58
+ }
47
59
  function formRequestOptions(sessionID, ref) {
48
60
  if (sessionID !== "global" || !ref)
49
61
  return;
@@ -160,6 +172,7 @@ function createData2(config) {
160
172
  const [defaultLocation, setDefaultLocation] = createSignal({ directory: config.directory });
161
173
  const sessions = createMemo(() => Object.values(store.session.info).toSorted((a, b) => b.time.updated - a.time.updated));
162
174
  const messageIndex = new Map;
175
+ const stored = (message) => config.omitToolFileData ? omitMessageFileData(message) : message;
163
176
  const sync = createSync();
164
177
  let activeUpdates;
165
178
  const pendingUpdates = new Map;
@@ -294,6 +307,8 @@ function createData2(config) {
294
307
  message.update(sessionID, (draft, index) => message.append(draft, index, item));
295
308
  },
296
309
  editAssistant(sessionID, messageID, fn) {
310
+ if (!messageIndex.get(sessionID)?.has(messageID))
311
+ return;
297
312
  message.update(sessionID, (draft, index) => {
298
313
  const position = index.get(messageID);
299
314
  const item = position === undefined ? undefined : draft[position];
@@ -454,6 +469,10 @@ function createData2(config) {
454
469
  });
455
470
  activeUpdates = undefined;
456
471
  setStore("session", "active", reconcile(Object.fromEntries(snapshot)));
472
+ snapshot.forEach((status, id) => {
473
+ if (status === "running" && !store.session.info[id])
474
+ refresh(() => result.session.sync(id));
475
+ });
457
476
  }).catch(() => {
458
477
  if (activeUpdates === updates)
459
478
  activeUpdates = undefined;
@@ -667,6 +686,8 @@ function createData2(config) {
667
686
  });
668
687
  return;
669
688
  case "session.shell.ended":
689
+ if (!store.session.message[event.data.sessionID])
690
+ return;
670
691
  message.update(event.data.sessionID, (draft) => {
671
692
  const match = message.shell(draft, event.data.shell.id);
672
693
  if (!match)
@@ -732,6 +753,8 @@ function createData2(config) {
732
753
  return;
733
754
  }
734
755
  case "session.step.failed":
756
+ if (event.location && (event.data.error.type === "provider.budget-limit" || event.data.error.type === "provider.model-budget-limit"))
757
+ refreshUsageLimits(event.location);
735
758
  message.editAssistant(event.data.sessionID, event.data.assistantMessageID, (assistant) => {
736
759
  assistant.time.completed = event.created;
737
760
  assistant.finish = event.data.finish ?? "error";
@@ -805,7 +828,7 @@ function createData2(config) {
805
828
  status: "completed",
806
829
  input: tool.state.input,
807
830
  metadata: event.data.metadata,
808
- content: [...event.data.content]
831
+ content: config.omitToolFileData ? omitFileData(event.data.content) : [...event.data.content]
809
832
  };
810
833
  tool.executed = event.data.executed || tool.executed === true;
811
834
  if (event.data.native)
@@ -822,7 +845,7 @@ function createData2(config) {
822
845
  error: event.data.error,
823
846
  input: typeof tool.state.input === "string" ? {} : tool.state.input,
824
847
  metadata: event.data.metadata,
825
- content: event.data.content
848
+ content: config.omitToolFileData && event.data.content ? omitFileData(event.data.content) : event.data.content
826
849
  };
827
850
  tool.executed = event.data.executed || tool.executed === true;
828
851
  if (event.data.native)
@@ -930,6 +953,8 @@ function createData2(config) {
930
953
  });
931
954
  return;
932
955
  case "session.compaction.delta":
956
+ if (!store.session.message[event.data.sessionID])
957
+ return;
933
958
  message.update(event.data.sessionID, (draft) => {
934
959
  const current = message.compaction(draft);
935
960
  if (current?.status === "running")
@@ -1012,27 +1037,30 @@ function createData2(config) {
1012
1037
  Object.keys(store.location).forEach((key) => {
1013
1038
  const ref = JSON.parse(key);
1014
1039
  const location = { directory: ref[0], workspaceID: ref[1] ?? undefined };
1040
+ refreshUsageLimits(location);
1015
1041
  if (event.type === "credential.updated") {
1016
- result.location.integration.invalidate(location);
1017
- refresh(() => result.location.integration.sync(location));
1042
+ refreshLocation("integration", result.location.integration, location);
1018
1043
  return;
1019
1044
  }
1020
- setStore("location", key, (data) => ({
1021
- integration: data?.integration?.map((integration) => {
1022
- if (integration.id !== event.data.integrationID)
1023
- return integration;
1024
- const active = integration.connections.find((connection) => connection.type === "credential" && connection.id === event.data.credentialID);
1025
- if (!active)
1026
- return integration;
1027
- return {
1028
- ...integration,
1029
- connections: [active, ...integration.connections.filter((connection) => connection !== active)]
1030
- };
1031
- })
1032
- }));
1045
+ if (store.location[key]?.integration)
1046
+ setStore("location", key, (data) => ({
1047
+ integration: data?.integration?.map((integration) => {
1048
+ if (integration.id !== event.data.integrationID)
1049
+ return integration;
1050
+ const active = integration.connections.find((connection) => connection.type === "credential" && connection.id === event.data.credentialID);
1051
+ if (!active)
1052
+ return integration;
1053
+ return {
1054
+ ...integration,
1055
+ connections: [active, ...integration.connections.filter((connection) => connection !== active)]
1056
+ };
1057
+ })
1058
+ }));
1059
+ const active = hasLocation("integration", location) || hasLocation("model", location) || hasLocation("provider", location);
1033
1060
  result.location.model.invalidate(location);
1034
1061
  result.location.provider.invalidate(location);
1035
- refresh(() => Promise.all([result.location.model.sync(location), result.location.provider.sync(location)]));
1062
+ if (active)
1063
+ refresh(() => Promise.all([result.location.model.sync(location), result.location.provider.sync(location)]));
1036
1064
  });
1037
1065
  return;
1038
1066
  }
@@ -1041,34 +1069,22 @@ function createData2(config) {
1041
1069
  const location = event.location;
1042
1070
  switch (event.type) {
1043
1071
  case "provider.updated":
1044
- result.location.provider.invalidate(location);
1045
- refresh(() => result.location.provider.sync(location));
1072
+ refreshLocation("provider", result.location.provider, location);
1046
1073
  break;
1047
1074
  case "model.updated":
1048
- result.location.model.invalidate(location);
1049
- refresh(() => result.location.model.sync(location));
1075
+ refreshLocation("model", result.location.model, location);
1050
1076
  break;
1051
1077
  case "agent.updated":
1052
- result.location.agent.invalidate(location);
1053
- refresh(() => result.location.agent.sync(location));
1078
+ refreshLocation("agent", result.location.agent, location);
1054
1079
  break;
1055
1080
  case "command.updated":
1056
- result.location.command.invalidate(location);
1057
- refresh(() => result.location.command.sync(location));
1081
+ refreshLocation("command", result.location.command, location);
1058
1082
  break;
1059
1083
  case "skill.updated":
1060
- result.location.skill.invalidate(location);
1061
- refresh(() => result.location.skill.sync(location));
1084
+ refreshLocation("skill", result.location.skill, location);
1062
1085
  break;
1063
1086
  case "vcs.branch.updated":
1064
- setStore("location", locationKey2(location), (data) => ({
1065
- vcs: {
1066
- branch: {
1067
- ...data?.vcs?.branch,
1068
- current: event.data.branch
1069
- }
1070
- }
1071
- }));
1087
+ refreshLocation("vcs", result.location.vcs, location);
1072
1088
  break;
1073
1089
  case "form.created":
1074
1090
  if (store.session.form[event.data.form.sessionID]?.some((form) => form.id === event.data.form.id))
@@ -1088,43 +1104,66 @@ function createData2(config) {
1088
1104
  break;
1089
1105
  case "shell.exited":
1090
1106
  case "shell.deleted":
1107
+ if (!store.location[locationKey2(location)]?.shell?.[event.data.id])
1108
+ break;
1091
1109
  setStore("location", locationKey2(location), (data) => ({
1092
1110
  shell: Object.fromEntries(Object.entries(data?.shell ?? {}).filter(([id]) => id !== event.data.id))
1093
1111
  }));
1094
1112
  break;
1095
1113
  case "reference.updated":
1096
- result.location.reference.invalidate(location);
1097
- refresh(() => result.location.reference.sync(location));
1114
+ refreshLocation("reference", result.location.reference, location);
1098
1115
  break;
1099
- case "integration.updated":
1116
+ case "integration.updated": {
1117
+ refreshUsageLimits(location);
1118
+ const active = hasLocation("integration", location) || hasLocation("model", location) || hasLocation("provider", location);
1100
1119
  result.location.integration.invalidate(location);
1101
1120
  result.location.model.invalidate(location);
1102
1121
  result.location.provider.invalidate(location);
1103
- refresh(() => Promise.all([
1104
- result.location.integration.sync(location),
1105
- result.location.model.sync(location),
1106
- result.location.provider.sync(location)
1107
- ]));
1122
+ if (active)
1123
+ refresh(() => Promise.all([
1124
+ result.location.integration.sync(location),
1125
+ result.location.model.sync(location),
1126
+ result.location.provider.sync(location)
1127
+ ]));
1108
1128
  break;
1129
+ }
1109
1130
  case "config.updated":
1110
- result.location.config.invalidate(location);
1111
- if (result.location.config.list(location) !== undefined || sync.has(`location.config:${locationKey2(location)}`))
1112
- refresh(() => result.location.config.sync(location));
1113
- refresh(() => result.location.websearch.refresh(location));
1131
+ refreshLocation("config", result.location.config, location);
1132
+ if (hasLocation("websearch", location))
1133
+ refresh(() => result.location.websearch.refresh(location));
1114
1134
  break;
1115
1135
  case "websearch.updated":
1116
- refresh(() => result.location.websearch.refresh(location));
1136
+ if (hasLocation("websearch", location))
1137
+ refresh(() => result.location.websearch.refresh(location));
1117
1138
  break;
1118
- case "mcp.status.changed":
1139
+ case "mcp.status.changed": {
1140
+ const active = hasLocation("mcpServer", location);
1119
1141
  result.location.mcp.server.invalidate(location);
1120
- settle(`mcp.status:${locationKey2(location)}`, () => result.location.mcp.server.sync(location));
1142
+ if (active)
1143
+ settle(`mcp.status:${locationKey2(location)}`, () => result.location.mcp.server.sync(location));
1121
1144
  break;
1145
+ }
1122
1146
  case "mcp.resources.changed":
1123
- result.location.mcp.resource.invalidate(location);
1124
- refresh(() => result.location.mcp.resource.sync(location));
1147
+ refreshLocation("mcpResource", result.location.mcp.resource, location);
1125
1148
  break;
1126
1149
  }
1127
1150
  }
1151
+ function hasLocation(field, ref) {
1152
+ const id = locationKey2(ref ?? defaultLocation());
1153
+ return store.location[id]?.[field] !== undefined || sync.has(`location.${field}:${id}`);
1154
+ }
1155
+ function refreshLocation(field, resource, location) {
1156
+ const active = hasLocation(field, location);
1157
+ resource.invalidate(location);
1158
+ if (active)
1159
+ refresh(() => resource.sync(location));
1160
+ }
1161
+ function refreshUsageLimits(location) {
1162
+ const loaded = store.location[locationKey2(location)]?.usageLimits !== undefined || sync.has(`location.usageLimits:${locationKey2(location)}`);
1163
+ usageLimits.invalidate(location);
1164
+ if (loaded)
1165
+ refresh(() => usageLimits.sync(location));
1166
+ }
1128
1167
  function locationResource(field, load, options) {
1129
1168
  const publish = (key, value) => setStore("location", key, { [field]: value });
1130
1169
  return {
@@ -1144,6 +1183,7 @@ function createData2(config) {
1144
1183
  };
1145
1184
  }
1146
1185
  const vcs = locationResource("vcs", (location) => api().vcs.get({ location }));
1186
+ const usageLimits = locationResource("usageLimits", (location) => api().usage.limits({ location }));
1147
1187
  const shells = locationResource("shell", async (location) => {
1148
1188
  const response = await api().shell.list({ location });
1149
1189
  const ref = { directory: response.location.directory };
@@ -1411,7 +1451,7 @@ function createData2(config) {
1411
1451
  limit: config.initialMessageLimit?.() ?? messagePageLimit,
1412
1452
  order: "desc"
1413
1453
  });
1414
- const fetched = response.data.toReversed();
1454
+ const fetched = response.data.toReversed().map(stored);
1415
1455
  const ids = new Set(fetched.map((item) => item.id));
1416
1456
  const admitted = new Set((store.session.pending[sessionID] ?? []).flatMap((item) => item.type === "user" || item.type === "synthetic" ? [item.id] : []));
1417
1457
  const local = (store.session.message[sessionID] ?? []).filter((item) => !ids.has(item.id) && (outbox.has(item.id) || admitted.has(item.id)));
@@ -1464,7 +1504,7 @@ function createData2(config) {
1464
1504
  }, { signal });
1465
1505
  if (signal?.aborted)
1466
1506
  return;
1467
- fetched.push(...response.data);
1507
+ fetched.push(...response.data.map(stored));
1468
1508
  next = response.cursor.next ?? undefined;
1469
1509
  if (!options?.all)
1470
1510
  break;
@@ -1656,6 +1696,7 @@ function createData2(config) {
1656
1696
  result.session.form.invalidate("global", location);
1657
1697
  },
1658
1698
  vcs: { info: vcs.list, sync: vcs.sync, invalidate: vcs.invalidate },
1699
+ usage: { limits: usageLimits.list, sync: usageLimits.sync, invalidate: usageLimits.invalidate },
1659
1700
  agent: locationResource("agent", (location) => api().agent.list({ location })),
1660
1701
  command: locationResource("command", (location) => api().command.list({ location })),
1661
1702
  config: locationResource("config", async (location) => ({
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __export
3
- } from "./contract-9rqn6x4v.js";
3
+ } from "./service-timing-9rqn6x4v.js";
4
4
 
5
5
  // src/shared-events.ts
6
6
  var exports_shared_events = {};
@@ -56,6 +56,8 @@ function make7(connect) {
56
56
  let started = false;
57
57
  let completion;
58
58
  let connection;
59
+ const types = options?.types?.length ? new Set(options.types) : undefined;
60
+ const selected = (value) => !types || value.type === "server.connected" || types.has(value.type);
59
61
  function finish(result, discard = true) {
60
62
  completion = result;
61
63
  if (discard)
@@ -81,6 +83,8 @@ function make7(connect) {
81
83
  push(value) {
82
84
  if (completion)
83
85
  return;
86
+ if (!selected(value))
87
+ return;
84
88
  const request = pending.shift();
85
89
  if (request) {
86
90
  request.resolve({ done: false, value });
@@ -1,25 +1,25 @@
1
1
  import {
2
2
  make7
3
- } from "./contract-8bbb028w.js";
3
+ } from "./service-timing-gecjxyvt.js";
4
4
  import {
5
- ClientError2
6
- } from "./contract-y2etg5bs.js";
5
+ ClientError3
6
+ } from "./service-timing-7f0py9js.js";
7
7
  import {
8
- make4
9
- } from "./contract-w10x3kfx.js";
8
+ make5
9
+ } from "./service-timing-rxd7awy0.js";
10
10
  import {
11
- make3,
11
+ make6,
12
12
  aborted2
13
- } from "./contract-15p82y03.js";
13
+ } from "./service-timing-myz4ngx9.js";
14
14
  import {
15
15
  __export
16
- } from "./contract-9rqn6x4v.js";
16
+ } from "./service-timing-9rqn6x4v.js";
17
17
 
18
18
  // src/effect/client.ts
19
- var exports_client = {};
20
- __export(exports_client, {
21
- OpenCode: () => exports_client,
22
- make: () => make2
19
+ var exports_client3 = {};
20
+ __export(exports_client3, {
21
+ OpenCode: () => exports_client3,
22
+ make: () => make4
23
23
  });
24
24
  import { Cause, Context, Effect, Stream } from "effect";
25
25
  import { HttpClient, HttpClientRequest } from "effect/http";
@@ -28,9 +28,9 @@ var CurrentHeaders = Context.Reference("@opencode/client/effect/rpc/headers", {
28
28
  return;
29
29
  }
30
30
  });
31
- var make2 = Effect.fn("OpenCode.make")(function* (options) {
31
+ var make4 = Effect.fn("OpenCode.make")(function* (options) {
32
32
  const httpClient = yield* HttpClient.HttpClient;
33
- const raw = yield* make4(options).pipe(Effect.provideService(HttpClient.HttpClient, HttpClient.mapRequestEffect(httpClient, (request) => Effect.map(CurrentHeaders, (headers) => headers ? HttpClientRequest.setHeaders(request, new Headers(headers)) : request))));
33
+ const raw = yield* make5(options).pipe(Effect.provideService(HttpClient.HttpClient, HttpClient.mapRequestEffect(httpClient, (request) => Effect.map(CurrentHeaders, (headers) => headers ? HttpClientRequest.setHeaders(request, new Headers(headers)) : request))));
34
34
  const context = yield* Effect.context();
35
35
  const native = raw.event.subscribe();
36
36
 
@@ -41,12 +41,12 @@ var make2 = Effect.fn("OpenCode.make")(function* (options) {
41
41
  }
42
42
  }
43
43
  const shared = make7((signal) => Stream.toAsyncIterableWith(native.pipe(Stream.interruptWhen(aborted2(signal)), Stream.catchCause((cause) => Stream.fail(new EventFailure(cause)))), context));
44
- const subscribe = () => Stream.fromAsyncIterable(shared.subscribe(), (error) => error).pipe(Stream.catch((error) => Stream.failCause(error instanceof EventFailure ? error.cause : Cause.fail(new ClientError2({ cause: error })))));
44
+ const subscribe = (input) => Stream.fromAsyncIterable(shared.subscribe({ types: input?.types }), (error) => error).pipe(Stream.catch((error) => Stream.failCause(error instanceof EventFailure ? error.cause : Cause.fail(new ClientError3({ cause: error })))));
45
45
  return {
46
46
  ...raw,
47
47
  event: { ...raw.event, subscribe },
48
- rpc: Object.assign(make3((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
48
+ rpc: Object.assign(make6((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
49
49
  };
50
50
  });
51
51
 
52
- export { make2, exports_client };
52
+ export { make4, exports_client3 };
@@ -1,5 +1,5 @@
1
1
  // src/promise/generated/client-error.ts
2
- class ClientError3 extends Error {
2
+ class ClientError2 extends Error {
3
3
  reason;
4
4
  name = "ClientError";
5
5
  constructor(reason, options) {
@@ -9,4 +9,4 @@ class ClientError3 extends Error {
9
9
  }
10
10
  }
11
11
 
12
- export { ClientError3 };
12
+ export { ClientError2 };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  headers2
3
- } from "./contract-2ny4vxct.js";
3
+ } from "./service-timing-8ye1ye6f.js";
4
4
  import {
5
5
  __export
6
- } from "./contract-9rqn6x4v.js";
6
+ } from "./service-timing-9rqn6x4v.js";
7
7
 
8
8
  // src/pty-handoff.ts
9
9
  var exports_pty_handoff = {};
@@ -3,20 +3,20 @@ import {
3
3
  readError2,
4
4
  event2,
5
5
  eventType2
6
- } from "./contract-ryy6kscr.js";
6
+ } from "./service-timing-ryy6kscr.js";
7
7
  import {
8
8
  __export
9
- } from "./contract-9rqn6x4v.js";
9
+ } from "./service-timing-9rqn6x4v.js";
10
10
 
11
11
  // src/effect/rpc.ts
12
12
  var exports_rpc = {};
13
13
  __export(exports_rpc, {
14
14
  RpcClientRuntime: () => exports_rpc,
15
15
  aborted: () => aborted2,
16
- make: () => make3
16
+ make: () => make6
17
17
  });
18
18
  import { Effect, Stream } from "effect";
19
- function make3(call, subscribe) {
19
+ function make6(call, subscribe) {
20
20
  return (definition) => {
21
21
  const methods = Object.fromEntries(Object.entries(definition.methods).map(([name, method]) => [
22
22
  name,
@@ -59,4 +59,4 @@ function aborted2(signal) {
59
59
  });
60
60
  }
61
61
 
62
- export { make3, aborted2, exports_rpc };
62
+ export { make6, aborted2, exports_rpc };