mindwire 0.1.43 → 0.1.45

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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { MindwireError, TimeoutError, ApiError, RunFailedError } from './chunk-T6TD76UA.js';
2
- export { ApiError, MindwireError, RunFailedError, TimeoutError } from './chunk-T6TD76UA.js';
1
+ import { MindwireError, TimeoutError, ApiError, RunFailedError, executableChecksum } from './chunk-PFYKJ6LX.js';
2
+ export { ApiError, MindwireError, RunFailedError, TimeoutError } from './chunk-PFYKJ6LX.js';
3
3
 
4
4
  // src/http.ts
5
5
  var DEFAULT_TIMEOUT_MS = 12e4;
@@ -341,8 +341,8 @@ var Run = class _Run {
341
341
  * Steer a follow-up message into the running turn without cancelling it. Requires the agent's
342
342
  * `input` capability.
343
343
  */
344
- async sendInput(text) {
345
- await this.http.request("POST", `/runs/${encodeURIComponent(this.id)}/input`, { body: { text } });
344
+ async sendInput(text, options = {}) {
345
+ await this.http.request("POST", `/runs/${encodeURIComponent(this.id)}/input`, { body: { text, ...options } });
346
346
  }
347
347
  /**
348
348
  * Soft-stop the running turn (ask the agent to halt current work) without the hard process kill
@@ -1114,7 +1114,7 @@ function computerPairingURI(invitation) {
1114
1114
  }
1115
1115
 
1116
1116
  // src/version.ts
1117
- var SDK_VERSION = "0.1.43" ;
1117
+ var SDK_VERSION = "0.1.45" ;
1118
1118
  function versionAtLeast(actual, desired) {
1119
1119
  if (actual === desired) return true;
1120
1120
  if (!actual || !/^\d+\.\d+\.\d+$/.test(actual) || !/^\d+\.\d+\.\d+$/.test(desired)) return false;
@@ -1153,7 +1153,7 @@ async function ensureDaemonBinary(opts = {}) {
1153
1153
  throw new MindwireError(`mindwire: cannot download daemon for non-release SDK version ${version}`);
1154
1154
  }
1155
1155
  const path = await import('path');
1156
- const { binaryCacheDirectory, cachedExecutable, cacheExecutable } = await import('./binary-cache-ZTEYICUF.js');
1156
+ const { binaryCacheDirectory, cachedExecutable, cacheExecutable } = await import('./binary-cache-CG52TXCZ.js');
1157
1157
  const dir = path.join(opts.cacheDir ?? await binaryCacheDirectory(daemonPlatform), version, `${daemonPlatform}-${daemonArch}`);
1158
1158
  const asset = assetName(version, daemonPlatform, daemonArch);
1159
1159
  const bin = path.join(dir, asset);
@@ -1543,6 +1543,45 @@ var Mindwire = class _Mindwire {
1543
1543
  body: { title }
1544
1544
  });
1545
1545
  }
1546
+ /** Resumable upload over the same connection as chat. Retrying an identical chunk is safe. */
1547
+ uploadAttachmentChunk(chatId, id, chunk, signal) {
1548
+ return this.http.request("PUT", `/chats/${encodeURIComponent(chatId)}/attachments/${encodeURIComponent(id)}`, { body: chunk, signal });
1549
+ }
1550
+ /** Store a file with its conversation, then pass the returned reference in turn options. */
1551
+ async uploadAttachment(chatId, file, options = {}) {
1552
+ if (file.data.byteLength > 16 * 1024 * 1024) throw new RangeError("Attachments must be at most 16 MiB");
1553
+ const data = new Uint8Array(file.data);
1554
+ const hash = async (bytes) => {
1555
+ if (!globalThis.crypto?.subtle) return executableChecksum(bytes);
1556
+ const digest = new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", bytes));
1557
+ return Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
1558
+ };
1559
+ const sha256 = await hash(data);
1560
+ const id = (await hash(new TextEncoder().encode(`${chatId}\0${file.name}\0${sha256}`))).slice(0, 32);
1561
+ let offset = 0;
1562
+ for (; ; ) {
1563
+ options.signal?.throwIfAborted();
1564
+ const end = Math.min(data.length, offset + 384 * 1024);
1565
+ let binary = "";
1566
+ for (let start = offset; start < end; start += 16384) {
1567
+ binary += String.fromCharCode(...data.subarray(start, Math.min(end, start + 16384)));
1568
+ }
1569
+ const state = await this.uploadAttachmentChunk(chatId, id, {
1570
+ name: file.name,
1571
+ mime: file.mime ?? "application/octet-stream",
1572
+ bytes: data.length,
1573
+ sha256,
1574
+ offset,
1575
+ data: btoa(binary)
1576
+ }, options.signal);
1577
+ if (state.id !== id || state.bytes !== data.length || state.offset < end || state.offset > data.length || state.complete && state.offset !== data.length || !state.complete && state.offset <= offset) {
1578
+ throw new Error("Invalid attachment upload acknowledgement");
1579
+ }
1580
+ options.onProgress?.(data.length === 0 ? 1 : state.offset / data.length);
1581
+ if (state.complete) return { artifactId: id, name: state.name, mime: state.mime, bytes: state.bytes };
1582
+ offset = state.offset;
1583
+ }
1584
+ }
1546
1585
  /**
1547
1586
  * `DELETE /chats/{id}` — a true, irreversible delete: purges ALL of the chat's mindwire
1548
1587
  * bookkeeping and, for every session the chat mapped to, removes that agent's native transcript
@@ -1624,6 +1663,7 @@ var Mindwire = class _Mindwire {
1624
1663
  message: input.message
1625
1664
  };
1626
1665
  if (input.requestId !== void 0) body.requestId = input.requestId;
1666
+ if (input.queueIfRunning !== void 0) body.queueIfRunning = input.queueIfRunning;
1627
1667
  if (input.cwd !== void 0) body.cwd = input.cwd;
1628
1668
  if (input.options !== void 0) body.options = input.options;
1629
1669
  if (input.mode !== void 0) body.mode = input.mode;