@reinsjs/lowering-fetch 0.6.7 → 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
@@ -1,5 +1,25 @@
1
1
  # @reinsjs/lowering-fetch
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c47e62b: An image reference that reaches the lowering unhydrated (its blob was deleted, or no `BlobStore` is configured) is replaced with `[image unavailable]` and the event is recorded `lossy`, instead of sending a broken image. When the model takes no images the usual "this model does not accept images" placeholder is used, as for inline images. Loss matrices mention the new case.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [c47e62b]
12
+ - Updated dependencies [12d9343]
13
+ - @reinsjs/core@0.16.0
14
+
15
+ ## 0.6.8
16
+
17
+ ### Patch Changes
18
+
19
+ - 6a03481: Loss matrix: the note for `core.run_paused` / `core.run_resumed` no longer claims the perception module relays them to the model (it only reads `core.budget_usage`). Wording only; landings are unchanged.
20
+ - Updated dependencies [f8a3550]
21
+ - @reinsjs/core@0.15.0
22
+
3
23
  ## 0.6.7
4
24
 
5
25
  ### Patch Changes
package/dist/index.js CHANGED
@@ -309,6 +309,8 @@ function omittedNote(kinds) {
309
309
  const names = mediaNouns(kinds);
310
310
  return names ? `the model takes no ${names}, so they are replaced with placeholder text` : void 0;
311
311
  }
312
+ var IMAGE_UNAVAILABLE = "[image unavailable]";
313
+ var IMAGE_UNAVAILABLE_NOTE = "an image stored by reference could not be loaded (blob unavailable: it was removed, or no BlobStore is configured), so it is replaced with placeholder text";
312
314
  var RELAY_DIALECT_NOTE = "relay dialect: video / audio travel in the image slot; official endpoints reject this, so declare video / audio only for endpoints that take it";
313
315
 
314
316
  // src/chat/loss-matrix.ts
@@ -325,9 +327,11 @@ var NOT_SENT = {
325
327
  dropped("none", "the approval outcome reaches the model through tool_result(isError)")
326
328
  ],
327
329
  "core.approval_decision": [dropped("none", "same as above")],
328
- "core.run_paused": [dropped("none", "a run record; the perception module distills it into a system_note")],
330
+ "core.run_paused": [dropped("none", "a run record for the host; nothing relays it to the model")],
329
331
  "core.run_resumed": [dropped("none", "same as above")],
330
- "core.budget_usage": [dropped("none", "same as above")],
332
+ "core.budget_usage": [
333
+ dropped("none", "a run record; the perception module distills it into a system_note")
334
+ ],
331
335
  "core.memory_op": [
332
336
  dropped(
333
337
  "none",
@@ -376,8 +380,8 @@ var CHAT_LOSS_MATRIX = {
376
380
  ),
377
381
  lossy(
378
382
  "user",
379
- "moved after that batch of tool results (the order changes), untrusted content escaped, or images / video / audio replaced with placeholder text because the model takes none of that kind",
380
- "the user speaks up before all tool results are in / the content holds a </untrusted / it carries images / video / audio the model does not take"
383
+ "moved after that batch of tool results (the order changes), untrusted content escaped, images / video / audio replaced with placeholder text because the model takes none of that kind, or an image reference whose blob is unavailable replaced with placeholder text",
384
+ "the user speaks up before all tool results are in / the content holds a </untrusted / it carries images / video / audio the model does not take / it carries an image reference whose blob is unavailable"
381
385
  )
382
386
  ],
383
387
  "core.model_text": [
@@ -412,13 +416,13 @@ var CHAT_LOSS_MATRIX = {
412
416
  ),
413
417
  lossy(
414
418
  "tool+lifted-images",
415
- `a tool message takes text only, so it keeps a pointer where each image (or video / audio) was and they move into a user message right after the whole batch of tool messages (the order and the role change); that message labels them as tool output, with the tool name, call id and index, and keeps the result's untrusted marking; kinds the model does not take are replaced with placeholder text; ${RELAY_DIALECT_NOTE}`,
419
+ `a tool message takes text only, so it keeps a pointer where each image (or video / audio) was and they move into a user message right after the whole batch of tool messages (the order and the role change); that message labels them as tool output, with the tool name, call id and index, and keeps the result's untrusted marking; kinds the model does not take, and image references whose blob is unavailable, are replaced with placeholder text; ${RELAY_DIALECT_NOTE}`,
416
420
  "the result carries images / video / audio of a kind the model takes (chat.liftToolImages is on by default)"
417
421
  ),
418
422
  lossy(
419
423
  "tool-text-only",
420
- "a tool message takes text only, so images / video / audio are replaced with placeholder text",
421
- "the result carries images / video / audio and the model takes none of those kinds, or chat.liftToolImages is false"
424
+ "a tool message takes text only, so images / video / audio are replaced with placeholder text (an image reference whose blob is unavailable has no bytes to lift either)",
425
+ "the result carries images / video / audio and the model takes none of those kinds, or chat.liftToolImages is false, or it carries an image reference whose blob is unavailable"
422
426
  )
423
427
  ],
424
428
  "core.system_note": [
@@ -464,8 +468,8 @@ var ANTHROPIC_LOSS_MATRIX = {
464
468
  ),
465
469
  lossy2(
466
470
  "user",
467
- "moved after that batch of tool results (the order changes), untrusted content escaped, or images / video / audio replaced with placeholder text because the model takes none of that kind",
468
- "the user speaks up before all tool results are in / the content holds a </untrusted / it carries images / video / audio the model does not take"
471
+ "moved after that batch of tool results (the order changes), untrusted content escaped, images / video / audio replaced with placeholder text because the model takes none of that kind, or an image reference whose blob is unavailable replaced with placeholder text",
472
+ "the user speaks up before all tool results are in / the content holds a </untrusted / it carries images / video / audio the model does not take / it carries an image reference whose blob is unavailable"
469
473
  ),
470
474
  dropped2(
471
475
  "none",
@@ -511,7 +515,7 @@ var ANTHROPIC_LOSS_MATRIX = {
511
515
  ),
512
516
  lossy2(
513
517
  "tool_result",
514
- "untrusted content is escaped, or images / video / audio are replaced with placeholder text because the model takes none of that kind, or the referenced tool is absent from this request's tool table and its definition is expanded into text"
518
+ "untrusted content is escaped, or images / video / audio are replaced with placeholder text because the model takes none of that kind (or an image reference's blob is unavailable), or the referenced tool is absent from this request's tool table and its definition is expanded into text"
515
519
  ),
516
520
  exact2(
517
521
  "tool-reference",
@@ -552,6 +556,7 @@ var ANTHROPIC_LOSS_MATRIX = {
552
556
 
553
557
  // src/anthropic/to-request.ts
554
558
  import {
559
+ isImageRef,
555
560
  renderToolReference
556
561
  } from "@reinsjs/core";
557
562
 
@@ -756,6 +761,7 @@ function isPlainObject(v) {
756
761
  function blocksOf(parts, capabilities) {
757
762
  const omitted = /* @__PURE__ */ new Set();
758
763
  let relayed = false;
764
+ let unavailable = false;
759
765
  const blocks = [];
760
766
  for (const p of parts) {
761
767
  switch (p.type) {
@@ -769,6 +775,11 @@ function blocksOf(parts, capabilities) {
769
775
  case "video":
770
776
  case "audio":
771
777
  if (acceptsMedia(p.type, capabilities)) {
778
+ if (isImageRef(p)) {
779
+ unavailable = true;
780
+ blocks.push({ type: "text", text: IMAGE_UNAVAILABLE });
781
+ break;
782
+ }
772
783
  if (p.type !== "image") relayed = true;
773
784
  blocks.push({ type: "image", source: { type: "base64", media_type: p.mime, data: p.data } });
774
785
  } else {
@@ -782,7 +793,7 @@ function blocksOf(parts, capabilities) {
782
793
  }
783
794
  }
784
795
  }
785
- return { blocks, omitted, relayed };
796
+ return { blocks, omitted, relayed, unavailable };
786
797
  }
787
798
  function encodeAnthropicRequest(input) {
788
799
  const { model, capabilities } = input;
@@ -857,7 +868,7 @@ function encodeAnthropicRequest(input) {
857
868
  break;
858
869
  }
859
870
  openUser().push(...c.blocks);
860
- const lossy4 = item.deferred || item.escaped || c.omitted.size > 0;
871
+ const lossy4 = item.deferred || item.escaped || c.omitted.size > 0 || c.unavailable;
861
872
  land(
862
873
  landings,
863
874
  item.event,
@@ -866,6 +877,7 @@ function encodeAnthropicRequest(input) {
866
877
  item.deferred ? `the user message sits between a tool call and its results; ${DEFERRED_NOTE}` : void 0,
867
878
  item.escaped ? ESCAPED_NOTE : void 0,
868
879
  omittedNote(c.omitted),
880
+ c.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
869
881
  c.relayed ? RELAY_DIALECT_NOTE : void 0
870
882
  );
871
883
  break;
@@ -889,10 +901,11 @@ function encodeAnthropicRequest(input) {
889
901
  land(
890
902
  landings,
891
903
  item.event,
892
- aside || item.escaped || rest.omitted.size > 0 ? "lossy" : "exact",
904
+ aside || item.escaped || rest.omitted.size > 0 || rest.unavailable ? "lossy" : "exact",
893
905
  "tool-reference",
894
906
  aside ? REF_TEXT_ASIDE_NOTE : void 0,
895
907
  omittedNote(rest.omitted),
908
+ rest.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
896
909
  rest.relayed ? RELAY_DIALECT_NOTE : void 0,
897
910
  item.escaped ? ESCAPED_NOTE : void 0
898
911
  );
@@ -903,7 +916,7 @@ function encodeAnthropicRequest(input) {
903
916
  openUser().push(block);
904
917
  const unbound = refs.length > 0 && capabilities.deferredTools && trusted;
905
918
  const untrustedRefs = refs.length > 0 && capabilities.deferredTools && !trusted;
906
- const lossy4 = item.escaped || c.omitted.size > 0 || unbound;
919
+ const lossy4 = item.escaped || c.omitted.size > 0 || c.unavailable || unbound;
907
920
  land(
908
921
  landings,
909
922
  item.event,
@@ -912,6 +925,7 @@ function encodeAnthropicRequest(input) {
912
925
  unbound ? REF_UNBOUND_NOTE : void 0,
913
926
  untrustedRefs ? REF_UNTRUSTED_NOTE : void 0,
914
927
  omittedNote(c.omitted),
928
+ c.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
915
929
  c.relayed ? RELAY_DIALECT_NOTE : void 0,
916
930
  item.escaped ? ESCAPED_NOTE : void 0
917
931
  );
@@ -1322,6 +1336,7 @@ function errorText2(err) {
1322
1336
 
1323
1337
  // src/chat/to-request.ts
1324
1338
  import {
1339
+ isImageRef as isImageRef2,
1325
1340
  markUntrusted as markUntrusted2,
1326
1341
  renderToolReference as renderToolReference2
1327
1342
  } from "@reinsjs/core";
@@ -1338,6 +1353,7 @@ function land2(out, e, kind, landing, ...notes) {
1338
1353
  function userContent(parts, capabilities) {
1339
1354
  const omitted = /* @__PURE__ */ new Set();
1340
1355
  let relayed = false;
1356
+ let unavailable = false;
1341
1357
  const out = parts.map((p) => {
1342
1358
  switch (p.type) {
1343
1359
  case "text":
@@ -1351,6 +1367,10 @@ function userContent(parts, capabilities) {
1351
1367
  omitted.add(p.type);
1352
1368
  return { type: "text", text: mediaOmitted(p) };
1353
1369
  }
1370
+ if (isImageRef2(p)) {
1371
+ unavailable = true;
1372
+ return { type: "text", text: IMAGE_UNAVAILABLE };
1373
+ }
1354
1374
  if (p.type !== "image") relayed = true;
1355
1375
  return { type: "image_url", image_url: { url: `data:${p.mime};base64,${p.data}` } };
1356
1376
  default: {
@@ -1359,14 +1379,16 @@ function userContent(parts, capabilities) {
1359
1379
  }
1360
1380
  }
1361
1381
  });
1362
- if (out.length === 1 && out[0]?.type === "text") return { content: out[0].text, omitted, relayed };
1363
- return { content: out, omitted, relayed };
1382
+ if (out.length === 1 && out[0]?.type === "text")
1383
+ return { content: out[0].text, omitted, relayed, unavailable };
1384
+ return { content: out, omitted, relayed, unavailable };
1364
1385
  }
1365
1386
  function toolContent(parts, capabilities, lift) {
1366
1387
  const unsupported = /* @__PURE__ */ new Set();
1367
1388
  const textOnly = /* @__PURE__ */ new Set();
1368
1389
  const media = [];
1369
1390
  let relayed = false;
1391
+ let unavailable = false;
1370
1392
  const text = parts.map((p) => {
1371
1393
  switch (p.type) {
1372
1394
  case "text":
@@ -1377,6 +1399,10 @@ function toolContent(parts, capabilities, lift) {
1377
1399
  case "video":
1378
1400
  case "audio": {
1379
1401
  const accepted = acceptsMedia(p.type, capabilities);
1402
+ if (accepted && isImageRef2(p)) {
1403
+ unavailable = true;
1404
+ return IMAGE_UNAVAILABLE;
1405
+ }
1380
1406
  if (accepted && lift) {
1381
1407
  media.push(p);
1382
1408
  if (p.type !== "image") relayed = true;
@@ -1395,7 +1421,7 @@ function toolContent(parts, capabilities, lift) {
1395
1421
  }
1396
1422
  }
1397
1423
  }).join("\n");
1398
- return { text, media, unsupported, textOnly, relayed };
1424
+ return { text, media, unsupported, textOnly, relayed, unavailable };
1399
1425
  }
1400
1426
  function toolOmittedNote(kinds) {
1401
1427
  const names = mediaNouns(kinds);
@@ -1436,7 +1462,7 @@ function encodeChatRequest(input) {
1436
1462
  case "user": {
1437
1463
  const c = userContent(item.parts, capabilities);
1438
1464
  messages.push({ role: "user", content: c.content });
1439
- const lossy4 = item.deferred || item.escaped || c.omitted.size > 0;
1465
+ const lossy4 = item.deferred || item.escaped || c.omitted.size > 0 || c.unavailable;
1440
1466
  land2(
1441
1467
  landings,
1442
1468
  item.event,
@@ -1445,6 +1471,7 @@ function encodeChatRequest(input) {
1445
1471
  item.deferred ? `the user message sits between a tool call and its results; ${DEFERRED_NOTE}` : void 0,
1446
1472
  item.escaped ? ESCAPED_NOTE : void 0,
1447
1473
  omittedNote(c.omitted),
1474
+ c.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
1448
1475
  c.relayed ? RELAY_DIALECT_NOTE : void 0
1449
1476
  );
1450
1477
  break;
@@ -1465,7 +1492,7 @@ function encodeChatRequest(input) {
1465
1492
  });
1466
1493
  const mediaLifted = c.media.length > 0;
1467
1494
  if (mediaLifted) lifted.push(...liftedAttachment(item, c.media));
1468
- const dropped4 = c.unsupported.size > 0 || c.textOnly.size > 0;
1495
+ const dropped4 = c.unsupported.size > 0 || c.textOnly.size > 0 || c.unavailable;
1469
1496
  const lossy4 = item.escaped || item.isError || dropped4 || mediaLifted;
1470
1497
  land2(
1471
1498
  landings,
@@ -1476,6 +1503,7 @@ function encodeChatRequest(input) {
1476
1503
  item.isError ? "a Chat tool message has no error flag, so isError is expressed with a [tool error] prefix" : void 0,
1477
1504
  toolOmittedNote(c.textOnly),
1478
1505
  omittedNote(c.unsupported),
1506
+ c.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
1479
1507
  mediaLifted ? c.media.every((m) => m.type === "image") ? "a tool message takes text only, so its images move into a user message after this batch of tool messages, labelled as tool output" : "a tool message takes text only, so its media move into a user message after this batch of tool messages, labelled as tool output" : void 0,
1480
1508
  c.relayed ? RELAY_DIALECT_NOTE : void 0,
1481
1509
  item.escaped ? ESCAPED_NOTE : void 0
@@ -2149,6 +2177,7 @@ function errorText3(err) {
2149
2177
 
2150
2178
  // src/responses/to-request.ts
2151
2179
  import {
2180
+ isImageRef as isImageRef3,
2152
2181
  renderToolReference as renderToolReference3
2153
2182
  } from "@reinsjs/core";
2154
2183
  var ERROR_PREFIX2 = "[tool error]\n";
@@ -2163,6 +2192,7 @@ function land3(out, e, kind, landing, ...notes) {
2163
2192
  function contentOf(parts, capabilities) {
2164
2193
  const omitted = /* @__PURE__ */ new Set();
2165
2194
  let relayed = false;
2195
+ let unavailable = false;
2166
2196
  const content = [];
2167
2197
  for (const p of parts) {
2168
2198
  switch (p.type) {
@@ -2176,6 +2206,11 @@ function contentOf(parts, capabilities) {
2176
2206
  case "video":
2177
2207
  case "audio":
2178
2208
  if (acceptsMedia(p.type, capabilities)) {
2209
+ if (isImageRef3(p)) {
2210
+ unavailable = true;
2211
+ content.push({ type: "input_text", text: IMAGE_UNAVAILABLE });
2212
+ break;
2213
+ }
2179
2214
  if (p.type !== "image") relayed = true;
2180
2215
  content.push({ type: "input_image", image_url: `data:${p.mime};base64,${p.data}`, detail: "auto" });
2181
2216
  } else {
@@ -2189,7 +2224,7 @@ function contentOf(parts, capabilities) {
2189
2224
  }
2190
2225
  }
2191
2226
  }
2192
- return { content, omitted, relayed };
2227
+ return { content, omitted, relayed, unavailable };
2193
2228
  }
2194
2229
  function argumentsOf2(args) {
2195
2230
  return typeof args === "string" ? args : JSON.stringify(args ?? {});
@@ -2239,7 +2274,7 @@ function encodeResponsesRequest(input) {
2239
2274
  break;
2240
2275
  }
2241
2276
  items.push({ role: "user", content: c.content });
2242
- const lossy4 = item.deferred || item.escaped || c.omitted.size > 0;
2277
+ const lossy4 = item.deferred || item.escaped || c.omitted.size > 0 || c.unavailable;
2243
2278
  land3(
2244
2279
  landings,
2245
2280
  item.event,
@@ -2248,6 +2283,7 @@ function encodeResponsesRequest(input) {
2248
2283
  item.deferred ? `the user message sits between a tool call and its results; ${DEFERRED_NOTE}` : void 0,
2249
2284
  item.escaped ? ESCAPED_NOTE : void 0,
2250
2285
  omittedNote(c.omitted),
2286
+ c.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
2251
2287
  c.relayed ? RELAY_DIALECT_NOTE : void 0
2252
2288
  );
2253
2289
  break;
@@ -2262,7 +2298,7 @@ function encodeResponsesRequest(input) {
2262
2298
  ...c.content.filter((b) => b.type === "input_image")
2263
2299
  ] : prefixed;
2264
2300
  items.push({ type: "function_call_output", call_id: item.toolCallId, output });
2265
- const lossy4 = item.escaped || item.isError || c.omitted.size > 0;
2301
+ const lossy4 = item.escaped || item.isError || c.omitted.size > 0 || c.unavailable;
2266
2302
  land3(
2267
2303
  landings,
2268
2304
  item.event,
@@ -2270,6 +2306,7 @@ function encodeResponsesRequest(input) {
2270
2306
  "function_call_output",
2271
2307
  item.isError ? "the Responses function_call_output has no error flag, so isError is expressed with a [tool error] prefix" : void 0,
2272
2308
  omittedNote(c.omitted),
2309
+ c.unavailable ? IMAGE_UNAVAILABLE_NOTE : void 0,
2273
2310
  c.relayed ? RELAY_DIALECT_NOTE : void 0,
2274
2311
  item.escaped ? ESCAPED_NOTE : void 0
2275
2312
  );
@@ -2742,8 +2779,8 @@ var RESPONSES_LOSS_MATRIX = {
2742
2779
  ),
2743
2780
  lossy3(
2744
2781
  "user",
2745
- "moved after that batch of tool results (the order changes), untrusted content escaped, or images / video / audio replaced with placeholder text because the model takes none of that kind",
2746
- "the user speaks up before all tool results are in / the content holds a </untrusted / it carries images / video / audio the model does not take"
2782
+ "moved after that batch of tool results (the order changes), untrusted content escaped, images / video / audio replaced with placeholder text because the model takes none of that kind, or an image reference whose blob is unavailable replaced with placeholder text",
2783
+ "the user speaks up before all tool results are in / the content holds a </untrusted / it carries images / video / audio the model does not take / it carries an image reference whose blob is unavailable"
2747
2784
  ),
2748
2785
  dropped3(
2749
2786
  "none",
@@ -2782,7 +2819,7 @@ var RESPONSES_LOSS_MATRIX = {
2782
2819
  ),
2783
2820
  lossy3(
2784
2821
  "function_call_output",
2785
- "isError is expressed with a [tool error] prefix (the protocol has no error flag), or untrusted content is escaped, or images / video / audio are replaced with placeholder text because the model takes none of that kind"
2822
+ "isError is expressed with a [tool error] prefix (the protocol has no error flag), or untrusted content is escaped, or images / video / audio are replaced with placeholder text because the model takes none of that kind (or an image reference's blob is unavailable)"
2786
2823
  )
2787
2824
  ],
2788
2825
  "core.system_note": [