@opencode/client 0.0.0-dev-1259 → 0.0.0-dev-1263

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.
@@ -13,10 +13,10 @@ var exports_rpc = {};
13
13
  __export(exports_rpc, {
14
14
  RpcClientRuntime: () => exports_rpc,
15
15
  aborted: () => aborted2,
16
- make: () => make4
16
+ make: () => make3
17
17
  });
18
18
  import { Effect, Stream } from "effect";
19
- function make4(call, subscribe) {
19
+ function make3(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 { make4, aborted2, exports_rpc };
62
+ export { make3, aborted2, exports_rpc };
@@ -11,7 +11,7 @@ import {
11
11
  // src/effect/generated/client.ts
12
12
  var exports_client2 = {};
13
13
  __export(exports_client2, {
14
- make: () => make3
14
+ make: () => make4
15
15
  });
16
16
  import { Effect, Stream, Schema } from "effect";
17
17
  import { Sse } from "effect/encoding";
@@ -832,6 +832,6 @@ var adaptClient = (raw) => {
832
832
  }
833
833
  };
834
834
  };
835
- var make3 = (options) => HttpApiClient.make(ClientApi2, options).pipe(Effect.map(adaptClient));
835
+ var make4 = (options) => HttpApiClient.make(ClientApi2, options).pipe(Effect.map(adaptClient));
836
836
 
837
- export { make3, exports_client2 };
837
+ export { make4, exports_client2 };
@@ -5,12 +5,12 @@ import {
5
5
  ClientError2
6
6
  } from "./service-y2etg5bs.js";
7
7
  import {
8
- make3
9
- } from "./service-k38jn95v.js";
8
+ make4
9
+ } from "./service-2r38e168.js";
10
10
  import {
11
- make4,
11
+ make3,
12
12
  aborted2
13
- } from "./service-9j12j8xw.js";
13
+ } from "./service-15p82y03.js";
14
14
  import {
15
15
  __export
16
16
  } from "./service-9rqn6x4v.js";
@@ -30,7 +30,7 @@ var CurrentHeaders = Context.Reference("@opencode/client/effect/rpc/headers", {
30
30
  });
31
31
  var make2 = Effect.fn("OpenCode.make")(function* (options) {
32
32
  const httpClient = yield* HttpClient.HttpClient;
33
- const raw = yield* make3(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* make4(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
 
@@ -45,7 +45,7 @@ var make2 = Effect.fn("OpenCode.make")(function* (options) {
45
45
  return {
46
46
  ...raw,
47
47
  event: { ...raw.event, subscribe },
48
- rpc: Object.assign(make4((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
48
+ rpc: Object.assign(make3((input, options) => raw.rpc.call(input).pipe(Effect.provideService(CurrentHeaders, options?.headers)), subscribe), raw.rpc)
49
49
  };
50
50
  });
51
51
 
@@ -50,8 +50,11 @@ function omitFileData(content) {
50
50
  const omit = (item) => item.type === "file" && item.uri.startsWith("data:") ? { ...item, uri: `data:${item.mime};base64,` } : item;
51
51
  return [omit(content[0]), ...content.slice(1).map(omit)];
52
52
  }
53
+ var hasFileData = (part) => part.type === "tool" && ("content" in part.state) && !!part.state.content?.some((item) => item.type === "file" && item.uri.startsWith("data:"));
54
+ var isDroppedFile = (item) => item.type === "file" && item.uri === `data:${item.mime};base64,`;
55
+ var hasDroppedFileData = (message) => message.type === "assistant" && message.content.some((part) => part.type === "tool" && ("content" in part.state) && !!part.state.content?.some(isDroppedFile));
53
56
  function omitMessageFileData(message) {
54
- if (message.type !== "assistant")
57
+ if (message.type !== "assistant" || !message.content.some(hasFileData))
55
58
  return message;
56
59
  return {
57
60
  ...message,
@@ -137,20 +140,36 @@ function createData2(config) {
137
140
  function refresh(load) {
138
141
  if (disposed || config.connection && config.connection.status() !== "connected")
139
142
  return;
140
- load().catch((error) => {
141
- if (disposed || config.connection && config.connection.status() !== "connected")
142
- return;
143
- if (isSessionNotFoundError2(error)) {
144
- markDeleted(error.sessionID);
145
- return;
146
- }
147
- if (isMessageNotFoundError2(error))
143
+ load().catch(refreshFailed);
144
+ }
145
+ function restoreMessageFiles(sessionID, messageID) {
146
+ return api().session.message.get({ sessionID, messageID }).then((item) => {
147
+ if (item.type !== "assistant" || omitFiles())
148
148
  return;
149
- if (config.onError)
150
- return config.onError(error);
151
- console.error("Failed to refresh client data", error);
149
+ message.editAssistant(sessionID, item.id, (assistant) => {
150
+ assistant.content.forEach((part) => {
151
+ if (part.type !== "tool" || !("content" in part.state) || !part.state.content?.some(isDroppedFile))
152
+ return;
153
+ const fetched = item.content.findLast((other) => other.type === "tool" && other.id === part.id);
154
+ if (fetched?.type === "tool" && "content" in fetched.state && fetched.state.content)
155
+ part.state.content = fetched.state.content;
156
+ });
157
+ });
152
158
  });
153
159
  }
160
+ function refreshFailed(error) {
161
+ if (disposed || config.connection && config.connection.status() !== "connected")
162
+ return;
163
+ if (isSessionNotFoundError2(error)) {
164
+ markDeleted(error.sessionID);
165
+ return;
166
+ }
167
+ if (isMessageNotFoundError2(error))
168
+ return;
169
+ if (config.onError)
170
+ return config.onError(error);
171
+ console.error("Failed to refresh client data", error);
172
+ }
154
173
  const settling = new Map;
155
174
  onCleanup(() => settling.forEach((timer) => clearTimeout(timer)));
156
175
  function settle(key, load) {
@@ -182,7 +201,8 @@ function createData2(config) {
182
201
  const [defaultLocation, setDefaultLocation] = createSignal({ directory: config.directory });
183
202
  const sessions = createMemo(() => Object.values(store.session.info).toSorted((a, b) => b.time.updated - a.time.updated));
184
203
  const messageIndex = new Map;
185
- const stored = (message) => config.omitToolFileData ? omitMessageFileData(message) : message;
204
+ const omitFiles = () => typeof config.omitToolFileData === "function" ? config.omitToolFileData() : config.omitToolFileData === true;
205
+ const stored = (message) => omitFiles() ? omitMessageFileData(message) : message;
186
206
  const sync = createSync();
187
207
  let activeUpdates;
188
208
  const pendingUpdates = new Map;
@@ -878,7 +898,7 @@ function createData2(config) {
878
898
  status: "completed",
879
899
  input: tool.state.input,
880
900
  metadata: event.data.metadata,
881
- content: config.omitToolFileData ? omitFileData(event.data.content) : [...event.data.content]
901
+ content: omitFiles() ? omitFileData(event.data.content) : [...event.data.content]
882
902
  };
883
903
  tool.executed = event.data.executed || tool.executed === true;
884
904
  if (event.data.native)
@@ -895,7 +915,7 @@ function createData2(config) {
895
915
  error: event.data.error,
896
916
  input: typeof tool.state.input === "string" ? {} : tool.state.input,
897
917
  metadata: event.data.metadata,
898
- content: config.omitToolFileData && event.data.content ? omitFileData(event.data.content) : event.data.content
918
+ content: omitFiles() && event.data.content ? omitFileData(event.data.content) : event.data.content
899
919
  };
900
920
  tool.executed = event.data.executed || tool.executed === true;
901
921
  if (event.data.native)
@@ -1511,6 +1531,13 @@ function createData2(config) {
1511
1531
  const position = messageIndex.get(sessionID)?.get(messageID);
1512
1532
  return position === undefined ? undefined : messages?.[position];
1513
1533
  },
1534
+ restoreFiles() {
1535
+ const sessions = Object.entries(store.session.message).flatMap(([sessionID, messages]) => {
1536
+ const ids = (messages ?? []).filter(hasDroppedFileData).map((item) => item.id);
1537
+ return ids.length === 0 ? [] : [{ sessionID, ids }];
1538
+ });
1539
+ return Promise.all(sessions.map((session) => session.ids.reduce((previous, messageID) => previous.then(() => restoreMessageFiles(session.sessionID, messageID).catch(refreshFailed)), Promise.resolve())));
1540
+ },
1514
1541
  sync(sessionID) {
1515
1542
  return sync.run(`session.message:${sessionID}`, async () => {
1516
1543
  const started = deletionEpoch;
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  make2,
3
3
  exports_client
4
- } from "../chunks/service-qz6wsvtn.js";
4
+ } from "../chunks/service-c49mnkv6.js";
5
+ import"../chunks/service-15p82y03.js";
5
6
  import"../chunks/service-6mptkzbc.js";
6
- import"../chunks/service-k38jn95v.js";
7
+ import"../chunks/service-2r38e168.js";
7
8
  import"../chunks/service-y2etg5bs.js";
8
- import"../chunks/service-9j12j8xw.js";
9
9
  import"../chunks/service-ryy6kscr.js";
10
- import"../chunks/service-60xe5cbf.js";
11
10
  import"../chunks/service-gecjxyvt.js";
11
+ import"../chunks/service-60xe5cbf.js";
12
12
  export {
13
13
  exports_client as OpenCode,
14
14
  make2 as make
@@ -1,8 +1,8 @@
1
1
  import {
2
- make3
3
- } from "../../chunks/service-k38jn95v.js";
2
+ make4
3
+ } from "../../chunks/service-2r38e168.js";
4
4
  import"../../chunks/service-y2etg5bs.js";
5
5
  import"../../chunks/service-60xe5cbf.js";
6
6
  export {
7
- make3 as make
7
+ make4 as make
8
8
  };
@@ -1,7 +1,7 @@
1
1
  import"../../chunks/service-6mptkzbc.js";
2
2
  import {
3
3
  exports_client2
4
- } from "../../chunks/service-k38jn95v.js";
4
+ } from "../../chunks/service-2r38e168.js";
5
5
  import {
6
6
  ClientError2
7
7
  } from "../../chunks/service-y2etg5bs.js";
@@ -2,14 +2,14 @@ import {
2
2
  ClientError2
3
3
  } from "../chunks/service-y2etg5bs.js";
4
4
  import"../chunks/service-60xe5cbf.js";
5
- import"../chunks/service-k38jn95v.js";
5
+ import"../chunks/service-2r38e168.js";
6
6
  import"../chunks/service-6mptkzbc.js";
7
7
  import"../chunks/service-gecjxyvt.js";
8
8
  import"../chunks/service-ryy6kscr.js";
9
- import"../chunks/service-9j12j8xw.js";
9
+ import"../chunks/service-15p82y03.js";
10
10
  import {
11
11
  exports_client
12
- } from "../chunks/service-qz6wsvtn.js";
12
+ } from "../chunks/service-c49mnkv6.js";
13
13
 
14
14
  // src/effect/index.ts
15
15
  import { Agent } from "@opencode/schema/agent";
@@ -1,11 +1,11 @@
1
1
  import {
2
- make4,
2
+ make3,
3
3
  aborted2,
4
4
  exports_rpc
5
- } from "../chunks/service-9j12j8xw.js";
5
+ } from "../chunks/service-15p82y03.js";
6
6
  import"../chunks/service-ryy6kscr.js";
7
7
  export {
8
8
  exports_rpc as RpcClientRuntime,
9
9
  aborted2 as aborted,
10
- make4 as make
10
+ make3 as make
11
11
  };
@@ -21,7 +21,7 @@ import {
21
21
  environment2,
22
22
  complete2,
23
23
  clear2
24
- } from "../chunks/service-2gyxdvzc.js";
24
+ } from "../chunks/service-xf396ev0.js";
25
25
  import"../chunks/service-qav6mfdz.js";
26
26
 
27
27
  // src/effect/service.ts
@@ -1,8 +1,4 @@
1
1
  import"../chunks/service-6r38tsk5.js";
2
- import {
3
- mediaHashFromUri2,
4
- withMediaRefs2
5
- } from "../chunks/service-mwrzahmf.js";
6
2
  import {
7
3
  exports_client3
8
4
  } from "../chunks/service-d4rtfcxf.js";
@@ -11,6 +7,10 @@ import"../chunks/service-qdgaygb4.js";
11
7
  import {
12
8
  ClientError3
13
9
  } from "../chunks/service-nwcpakzx.js";
10
+ import {
11
+ mediaHashFromUri2,
12
+ withMediaRefs2
13
+ } from "../chunks/service-mwrzahmf.js";
14
14
  import"../chunks/service-xqwq6bgr.js";
15
15
  import {
16
16
  isInvalidRequestError2,
@@ -21,7 +21,7 @@ import {
21
21
  environment2,
22
22
  complete2,
23
23
  clear2
24
- } from "../chunks/service-2gyxdvzc.js";
24
+ } from "../chunks/service-xf396ev0.js";
25
25
  import"../chunks/service-qav6mfdz.js";
26
26
 
27
27
  // src/promise/service.ts
@@ -4,7 +4,7 @@ import {
4
4
  complete2,
5
5
  clear2,
6
6
  exports_pty_handoff
7
- } from "./chunks/service-2gyxdvzc.js";
7
+ } from "./chunks/service-xf396ev0.js";
8
8
  import"./chunks/service-2ny4vxct.js";
9
9
  import"./chunks/service-sxt88q69.js";
10
10
  import"./chunks/service-xgnj2w4v.js";
@@ -31,9 +31,10 @@ export type CreateDataInput = {
31
31
  readonly onError?: (error: unknown) => void;
32
32
  /**
33
33
  * Drops the payload of inline `data:` files in tool results before they enter the store. For clients that never
34
- * render tool-result files: a session full of screenshots otherwise keeps hundreds of MB of base64 alive.
34
+ * render tool-result files: a session full of screenshots otherwise keeps hundreds of MB of base64 alive. A function
35
+ * is read for each message and event, so a client can follow a setting that changes while it runs.
35
36
  */
36
- readonly omitToolFileData?: boolean;
37
+ readonly omitToolFileData?: boolean | (() => boolean);
37
38
  };
38
39
  export declare const settleMs = 150;
39
40
  export type FormWithLocation = FormInfo & {
@@ -100,6 +101,8 @@ export declare function createData(config: CreateDataInput): {
100
101
  message: {
101
102
  list(sessionID: string): SessionMessageInfo[];
102
103
  get(sessionID: string, messageID: string): SessionMessageInfo | undefined;
104
+ /** Re-reads every loaded message whose tool file data was dropped, for a client that starts showing tool files. */
105
+ restoreFiles(): Promise<void[]>;
103
106
  sync(sessionID: string): Promise<void>;
104
107
  more(sessionID: string): boolean;
105
108
  loading(sessionID: string): boolean;
@@ -2,13 +2,13 @@ import {
2
2
  settleMs2,
3
3
  locationKey2,
4
4
  createData2
5
- } from "../chunks/service-s8aavqyg.js";
5
+ } from "../chunks/service-tztyfz1b.js";
6
6
  import"../chunks/service-6r38tsk5.js";
7
- import"../chunks/service-mwrzahmf.js";
8
7
  import"../chunks/service-d4rtfcxf.js";
9
8
  import"../chunks/service-vyas3vgt.js";
10
9
  import"../chunks/service-qdgaygb4.js";
11
10
  import"../chunks/service-nwcpakzx.js";
11
+ import"../chunks/service-mwrzahmf.js";
12
12
  import"../chunks/service-xqwq6bgr.js";
13
13
  import"../chunks/service-sdjh9vmn.js";
14
14
  import"../chunks/service-gecjxyvt.js";
@@ -11,7 +11,7 @@ import {
11
11
  settleMs2,
12
12
  locationKey2,
13
13
  createData2
14
- } from "../chunks/service-s8aavqyg.js";
14
+ } from "../chunks/service-tztyfz1b.js";
15
15
  import {
16
16
  defaultIdleTimeout2,
17
17
  foregroundIdleThreshold2,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/client",
4
- "version": "0.0.0-dev-1259",
4
+ "version": "0.0.0-dev-1263",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -63,8 +63,8 @@
63
63
  "typecheck:tsc": "tsc --noEmit"
64
64
  },
65
65
  "dependencies": {
66
- "@opencode/schema": "0.0.0-dev-1259",
67
- "@opencode/protocol": "0.0.0-dev-1259"
66
+ "@opencode/schema": "0.0.0-dev-1263",
67
+ "@opencode/protocol": "0.0.0-dev-1263"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "effect": "4.1.0",
@@ -81,7 +81,7 @@
81
81
  "devDependencies": {
82
82
  "@effect/platform-node": "4.1.0",
83
83
  "@modelcontextprotocol/client": "2.4.0",
84
- "@opencode/httpapi-codegen": "0.0.0-dev-1259",
84
+ "@opencode/httpapi-codegen": "0.0.0-dev-1263",
85
85
  "@tsconfig/bun": "1.0.9",
86
86
  "@types/bun": "1.4.3",
87
87
  "@typescript/native": "npm:typescript@7.1.0-beta",