listspace 0.6.0 → 0.7.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  One version runs through the CLI, the skill and the Claude Code plugin, so each entry covers all three.
4
4
 
5
+ ## 0.7.0
6
+
7
+ - Upload links for several files in one call: `get_upload_link` takes `files`, up to 25 entries each with `item_id`, `filename` and `size_bytes`, and the REST API has `POST /v1/upload-links` for the same. `listspace attach` uses it when it sends two or more files over 8 MB: it asks for the links of a few files at a time, right before sending them: a file joins a chunk only while the bytes queued ahead of it stay under about 500 MB, since a link for a large file holds room in storage and its upload must start within 15 minutes. A link that has run out or runs out within a minute is replaced by a fresh one before its upload. The CLI sends the files that got a link, names the ones that did not, and goes back to one link a file on a server that does not have the route yet. Publish this CLI after the server (the functions) is deployed.
8
+ - The upload limit counts files and bytes, not calls: 200 upload links or 10 GB an hour per account. A refusal says when to come back (`Try again after 14:32 UTC (in 12 minutes)`), with `retry_after_seconds` and `retry_at` in the error, and the CLI passes it on.
9
+ - The answer to an upload says in `attachment.is_cover` whether the file became the item's cover.
10
+ - The skill's file pages tell agents to send a batch in one call and to wait for the time the error names.
11
+
5
12
  ## 0.6.0
6
13
 
7
14
  - `listspace attach` takes files up to the plan's size of one file (Free 25 MB, Pro 2 GB, a team's boards 5 GB), at most 4 GB from the CLI. Up to 8 MB a file goes in the request as before; a larger one goes straight to Listspace's file storage: the CLI asks for an upload link with the file's size, sends the file from disk (it is never read into memory) and then finishes the upload. A file over the plan's size is refused before any byte is sent.
@@ -216,7 +216,7 @@ var nextResult = union(
216
216
  function page(entry) {
217
217
  return object({ data: array(entry), next_cursor: nullable(string) });
218
218
  }
219
- var errorBody = object({ error: object({ code: string, message: string }) });
219
+ var errorBody = object({ error: object({ code: string, message: string, retry_after_seconds: withDefault(nullable(number), null) }) });
220
220
  var attached = object({
221
221
  outcome: literal("applied"),
222
222
  level,
@@ -231,11 +231,17 @@ var attached = object({
231
231
  });
232
232
  var largeUploadLink = object({
233
233
  upload_url: string,
234
- finish_url: nullable(string)
234
+ finish_url: nullable(string),
235
+ /** When upload_url stops working to start a PUT (15 minutes after the answer); null from a server that does not say. */
236
+ expires_at: withDefault(nullable(string), null)
237
+ });
238
+ var largeUploadLinks = object({
239
+ links: array(object({ index: number, upload_url: string, finish_url: nullable(string), expires_at: withDefault(nullable(string), null) })),
240
+ refused: array(object({ index: number, filename: string, message: string }))
235
241
  });
236
242
 
237
243
  // src/version.ts
238
- var VERSION = "0.6.0";
244
+ var VERSION = "0.7.0";
239
245
 
240
246
  // src/api.ts
241
247
  var DEFAULT_API_URL = "https://api.listspace.app/v1";
@@ -442,16 +448,19 @@ function decodeOrFail(decoder, value, path2) {
442
448
  function errorFor(response, json) {
443
449
  let code2 = "unknown";
444
450
  let message = `Listspace answered ${response.status}.`;
451
+ let retryAfter = null;
445
452
  try {
446
453
  const parsed = errorBody(json, "body");
447
454
  code2 = parsed.error.code;
448
455
  message = parsed.error.message;
456
+ retryAfter = parsed.error.retry_after_seconds;
449
457
  } catch {
450
458
  }
451
459
  if (response.status === 401) return { kind: "auth", message: `${message} ${LOGIN_HINT}` };
452
460
  if (response.status === 429) {
453
461
  const header = response.headers.get("Retry-After");
454
- const seconds = header !== null && /^\d+$/.test(header) ? Number(header) : null;
462
+ const seconds = retryAfter ?? (header !== null && /^\d+$/.test(header) ? Number(header) : null);
463
+ if (/try again after/i.test(message)) return { kind: "rate_limited", message, retryAfterSeconds: seconds };
455
464
  const wait = seconds === null ? "Wait a minute" : `Wait ${seconds} seconds`;
456
465
  return { kind: "rate_limited", message: `${message} ${wait} before trying again.`, retryAfterSeconds: seconds };
457
466
  }
@@ -901,34 +910,88 @@ async function prepareFiles(paths, read) {
901
910
  }
902
911
  return out;
903
912
  }
913
+ var CHUNK_BYTES = 500 * 1024 * 1024;
914
+ var CHUNK_FILES = 10;
915
+ var STALE_MS = 6e4;
904
916
  async function attachCommand(client, input) {
905
917
  if (!UUID.test(input.item)) return fail({ kind: "usage", message: `"${input.item}" is not an item id. Item ids come from \`listspace board <board>\`.` });
906
918
  const results = [];
907
919
  const raw = [];
908
- for (const file of input.files) {
920
+ const skipped = [];
921
+ const links = /* @__PURE__ */ new Map();
922
+ let batches = true;
923
+ for (const [position, file] of input.files.entries()) {
909
924
  try {
910
- const answer = await attachOne(client, input.item, file);
925
+ let made;
926
+ if (file.content.kind === "blob") {
927
+ if (batches && !links.has(file)) batches = await askForLinks(client, input.item, input.files.slice(position), links);
928
+ const got = links.get(file);
929
+ if (got !== void 0 && "refused" in got) {
930
+ skipped.push({ name: file.fileName, reason: got.refused });
931
+ continue;
932
+ }
933
+ made = got;
934
+ }
935
+ const answer = await attachOne(client, input.item, file, made);
911
936
  results.push(answer.value);
912
937
  raw.push(answer.raw);
913
938
  } catch (error) {
914
- if (!(error instanceof CliFailure) || results.length === 0) throw error;
939
+ if (!(error instanceof CliFailure) || results.length === 0 && skipped.length === 0) throw error;
915
940
  const done = results.map((result) => result.attachment.filename).join(", ");
916
- throw new CliFailure({ ...error.error, message: `Attached ${done}; ${file.fileName} and the rest were not: ${error.error.message}` });
941
+ throw new CliFailure({ ...error.error, message: `Attached ${done === "" ? "nothing" : done}; ${file.fileName} and the rest were not: ${error.error.message}` });
917
942
  }
918
943
  }
944
+ if (skipped.length > 0) {
945
+ const done = results.map((result) => result.attachment.filename).join(", ");
946
+ return fail({
947
+ kind: "api",
948
+ status: 400,
949
+ code: "invalid_request",
950
+ message: `Attached ${done === "" ? "nothing" : done}; not attached: ${skipped.map((s) => `${s.name} (${s.reason})`).join("; ")}`
951
+ });
952
+ }
919
953
  return { raw: { data: raw }, text: formatAttached(results) };
920
954
  }
921
- async function attachOne(client, item2, file) {
955
+ async function askForLinks(client, item2, rest, links) {
956
+ const next = rest.filter((file) => file.content.kind === "blob" && !links.has(file));
957
+ if (next.length < 2) return true;
958
+ const chunk = [];
959
+ let queued = 0;
960
+ for (const file of next) {
961
+ if (chunk.length >= CHUNK_FILES || chunk.length > 0 && queued >= CHUNK_BYTES) break;
962
+ chunk.push(file);
963
+ queued += file.content.kind === "blob" ? file.content.sizeBytes : 0;
964
+ }
965
+ const body = { files: chunk.map((file) => ({ item_id: item2, filename: file.fileName, size_bytes: file.content.kind === "blob" ? file.content.sizeBytes : 0 })) };
966
+ let answer;
967
+ try {
968
+ answer = (await client.data("POST", "/upload-links", largeUploadLinks, { body })).value;
969
+ } catch (error) {
970
+ if (error instanceof CliFailure && error.error.kind === "api" && error.error.status === 404 && error.error.code === "not_found" && error.error.message.startsWith("No such endpoint")) return false;
971
+ throw error;
972
+ }
973
+ for (const link of answer.links) {
974
+ const file = chunk[link.index];
975
+ if (file !== void 0) links.set(file, link);
976
+ }
977
+ for (const entry of answer.refused) {
978
+ const file = chunk[entry.index];
979
+ if (file !== void 0) links.set(file, { refused: entry.message });
980
+ }
981
+ return true;
982
+ }
983
+ async function attachOne(client, item2, file, made) {
922
984
  switch (file.content.kind) {
923
985
  case "bytes": {
924
986
  const body = { filename: file.fileName, mime_type: file.mimeType, content_base64: Buffer.from(file.content.bytes).toString("base64") };
925
987
  return client.data("POST", `/items/${path(item2)}/attachments`, attached, { body });
926
988
  }
927
989
  case "blob": {
928
- const link = await client.data("POST", `/items/${path(item2)}/upload-links`, largeUploadLink, { body: { filename: file.fileName, size_bytes: file.content.sizeBytes } });
929
- if (link.value.finish_url === null) return fail({ kind: "unexpected", message: "Listspace answered without a link to finish a large upload. Update the CLI, or the server is older than it." });
930
- await client.putToStorage(link.value.upload_url, file.content.blob);
931
- return client.finishUpload(link.value.finish_url, attached);
990
+ const stale = made !== void 0 && made.expires_at !== null && Date.parse(made.expires_at) - Date.now() < STALE_MS;
991
+ const link = made === void 0 || stale ? (await client.data("POST", `/items/${path(item2)}/upload-links`, largeUploadLink, { body: { filename: file.fileName, size_bytes: file.content.sizeBytes } })).value : made;
992
+ if (link.finish_url === null) return fail({ kind: "unexpected", message: "Listspace answered without a link to finish a large upload. Update the CLI, or the server is older than it." });
993
+ await client.putToStorage(link.upload_url, file.content.blob);
994
+ return client.finishUpload(link.finish_url, attached);
932
995
  }
933
996
  default: {
934
997
  const exhaustive = file.content;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listspace",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Listspace from the command line: the agentic project memory, for people and coding agents.",
5
5
  "keywords": [
6
6
  "listspace",