omnigateway 0.12.11 → 0.12.12

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 (3) hide show
  1. package/bin/omni.js +111 -99
  2. package/gateway.js +143 -99
  3. package/package.json +1 -1
package/bin/omni.js CHANGED
@@ -27073,6 +27073,69 @@ function systemText(system, provider, note2) {
27073
27073
  `);
27074
27074
  }
27075
27075
 
27076
+ // packages/providers/src/toolResultFiles.ts
27077
+ function isTextual(mediaType) {
27078
+ const type = mediaType.split(";")[0]?.trim().toLowerCase() ?? "";
27079
+ return type.startsWith("text/") || type.endsWith("+json") || type.endsWith("+xml") || TEXTUAL.has(type);
27080
+ }
27081
+ var TEXTUAL = new Set([
27082
+ "application/json",
27083
+ "application/x-ndjson",
27084
+ "application/xml",
27085
+ "application/yaml",
27086
+ "application/x-yaml",
27087
+ "application/toml",
27088
+ "application/javascript",
27089
+ "application/typescript",
27090
+ "application/sql",
27091
+ "application/x-sh",
27092
+ "message/rfc822"
27093
+ ]);
27094
+ function fileText(file2) {
27095
+ return Buffer.from(file2.data, "base64").toString("utf8");
27096
+ }
27097
+ function splitFiles(files, carries) {
27098
+ const text = [];
27099
+ const carried = [];
27100
+ let dropped = false;
27101
+ for (const file2 of files) {
27102
+ if (isTextual(file2.mediaType))
27103
+ text.push(fileText(file2));
27104
+ else if (carries(file2.mediaType))
27105
+ carried.push(file2);
27106
+ else
27107
+ dropped = true;
27108
+ }
27109
+ return { text, carried, dropped };
27110
+ }
27111
+ function withFileText(content, text) {
27112
+ return [content, ...text].filter((t) => t.length > 0).join(`
27113
+
27114
+ `);
27115
+ }
27116
+ var RESPONSES_FILE_TYPES = Object.assign(Object.create(null), {
27117
+ "application/pdf": "pdf",
27118
+ "application/rtf": "rtf",
27119
+ "application/msword": "doc",
27120
+ "application/vnd.ms-excel": "xls",
27121
+ "application/vnd.ms-powerpoint": "ppt",
27122
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
27123
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
27124
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx"
27125
+ });
27126
+ function fileName(file2) {
27127
+ return file2.filename ?? `file.${RESPONSES_FILE_TYPES[file2.mediaType] ?? "bin"}`;
27128
+ }
27129
+ function responsesFiles(files) {
27130
+ const { text, carried, dropped } = splitFiles(files, (t) => (t in RESPONSES_FILE_TYPES));
27131
+ const parts = carried.map((file2) => ({
27132
+ type: "input_file",
27133
+ filename: fileName(file2),
27134
+ file_data: `data:${file2.mediaType};base64,${file2.data}`
27135
+ }));
27136
+ return { parts, text, dropped };
27137
+ }
27138
+
27076
27139
  // packages/providers/src/anthropic/wire.ts
27077
27140
  var OAUTH_IDENTITY = "You are Claude Code, Anthropic's official CLI for Claude.";
27078
27141
  function wireCacheControl(c) {
@@ -27110,22 +27173,13 @@ function encodeBlock(b, cloak) {
27110
27173
  ...cache
27111
27174
  };
27112
27175
  case "toolResult": {
27113
- const documents = (b.files ?? []).flatMap((file2) => {
27114
- const source = file2.mediaType === "application/pdf" ? { type: "base64", media_type: file2.mediaType, data: file2.data } : file2.mediaType === "text/plain" ? {
27115
- type: "text",
27116
- media_type: file2.mediaType,
27117
- data: Buffer.from(file2.data, "base64").toString("utf8")
27118
- } : undefined;
27119
- if (source === undefined)
27120
- return [];
27121
- return [
27122
- {
27123
- type: "document",
27124
- source,
27125
- ...file2.filename !== undefined && { title: file2.filename }
27126
- }
27127
- ];
27128
- });
27176
+ const files = splitFiles(b.files ?? [], (t) => t === "application/pdf");
27177
+ const text = withFileText(b.content, files.text);
27178
+ const documents = files.carried.map((file2) => ({
27179
+ type: "document",
27180
+ source: { type: "base64", media_type: file2.mediaType, data: file2.data },
27181
+ ...file2.filename !== undefined && { title: file2.filename }
27182
+ }));
27129
27183
  const parts = [
27130
27184
  ...(b.images ?? []).map((image) => encodeBlock(image, cloak)),
27131
27185
  ...documents,
@@ -27134,7 +27188,7 @@ function encodeBlock(b, cloak) {
27134
27188
  return {
27135
27189
  type: "tool_result",
27136
27190
  tool_use_id: b.toolUseId,
27137
- content: parts.length === 0 ? b.content : [...b.content.length > 0 ? [{ type: "text", text: b.content }] : [], ...parts],
27191
+ content: parts.length === 0 ? text : [...text.length > 0 ? [{ type: "text", text }] : [], ...parts],
27138
27192
  is_error: b.isError,
27139
27193
  ...cache
27140
27194
  };
@@ -27310,8 +27364,12 @@ function toWire(req, model, opts) {
27310
27364
  note2("anthropic:system-turn-cache-control-dropped");
27311
27365
  for (const m of req.messages) {
27312
27366
  for (const b of m.content) {
27313
- if (b.type === "toolResult" && b.files?.some((f) => f.mediaType !== "application/pdf" && f.mediaType !== "text/plain")) {
27314
- note2("anthropic:files-dropped");
27367
+ if (b.type === "toolResult" && b.files !== undefined) {
27368
+ const files = splitFiles(b.files, (t) => t === "application/pdf");
27369
+ if (files.text.length > 0)
27370
+ note2("anthropic:tool-result-files-inlined");
27371
+ if (files.dropped)
27372
+ note2("anthropic:files-dropped");
27315
27373
  }
27316
27374
  }
27317
27375
  }
@@ -28406,16 +28464,19 @@ function toAntigravityWire(req, model, identity) {
28406
28464
  note2("antigravity:tool-result-unmatched");
28407
28465
  if (block.isError === true)
28408
28466
  note2("antigravity:tool-result-error-flag-dropped");
28467
+ const files = splitFiles(block.files ?? [], () => true);
28468
+ if (files.text.length > 0)
28469
+ note2("antigravity:tool-result-files-inlined");
28409
28470
  parts.push({
28410
28471
  functionResponse: {
28411
28472
  name: cloakName2(cloak, name ?? block.toolUseId),
28412
- response: { output: block.content }
28473
+ response: { output: withFileText(block.content, files.text) }
28413
28474
  }
28414
28475
  });
28415
28476
  for (const image of block.images ?? []) {
28416
28477
  parts.push({ inlineData: { mimeType: image.mediaType, data: image.data } });
28417
28478
  }
28418
- for (const file2 of block.files ?? []) {
28479
+ for (const file2 of files.carried) {
28419
28480
  parts.push({ inlineData: { mimeType: file2.mediaType, data: file2.data } });
28420
28481
  }
28421
28482
  role = "user";
@@ -30158,61 +30219,6 @@ async function* decodeCustomResponses(messages) {
30158
30219
  }
30159
30220
  }
30160
30221
 
30161
- // packages/providers/src/responsesFile.ts
30162
- var ACCEPTED = new Set([
30163
- "application/pdf",
30164
- "text/plain",
30165
- "text/csv",
30166
- "text/markdown",
30167
- "text/html",
30168
- "text/css",
30169
- "text/xml",
30170
- "text/calendar",
30171
- "text/tab-separated-values",
30172
- "text/javascript",
30173
- "text/x-python",
30174
- "text/x-c",
30175
- "text/x-java",
30176
- "text/x-sh",
30177
- "text/x-sql",
30178
- "text/x-typescript",
30179
- "text/x-yaml",
30180
- "application/json",
30181
- "application/javascript",
30182
- "application/typescript",
30183
- "application/toml",
30184
- "application/yaml",
30185
- "application/x-yaml",
30186
- "message/rfc822",
30187
- "application/rtf",
30188
- "application/msword",
30189
- "application/vnd.ms-excel",
30190
- "application/vnd.ms-powerpoint",
30191
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
30192
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
30193
- "application/vnd.openxmlformats-officedocument.presentationml.presentation"
30194
- ]);
30195
- var TEXTUAL = new Set(["application/xml", "application/sql", "application/x-sh"]);
30196
- function responsesFiles(files) {
30197
- const parts = [];
30198
- const text = [];
30199
- let dropped = false;
30200
- for (const file2 of files) {
30201
- if (ACCEPTED.has(file2.mediaType)) {
30202
- parts.push({
30203
- type: "input_file",
30204
- ...file2.filename !== undefined && { filename: file2.filename },
30205
- file_data: `data:${file2.mediaType};base64,${file2.data}`
30206
- });
30207
- } else if (file2.mediaType.startsWith("text/") || TEXTUAL.has(file2.mediaType)) {
30208
- text.push(Buffer.from(file2.data, "base64").toString("utf8"));
30209
- } else {
30210
- dropped = true;
30211
- }
30212
- }
30213
- return { parts, text, dropped };
30214
- }
30215
-
30216
30222
  // packages/providers/src/custom/wire.ts
30217
30223
  function encodeChatToolChoice(c) {
30218
30224
  switch (c.type) {
@@ -30276,19 +30282,23 @@ function toCustomChatWire(req, model) {
30276
30282
  function: { name: block.name, arguments: JSON.stringify(block.input) }
30277
30283
  });
30278
30284
  break;
30279
- case "toolResult":
30285
+ case "toolResult": {
30280
30286
  if (block.native !== undefined)
30281
30287
  note2("custom:anthropic-native-block-dropped");
30288
+ const files = splitFiles(block.files ?? [], () => false);
30282
30289
  messages.push({
30283
30290
  role: "tool",
30284
30291
  tool_call_id: block.toolUseId,
30285
- content: block.content
30292
+ content: withFileText(block.content, files.text)
30286
30293
  });
30287
30294
  if (block.images !== undefined)
30288
30295
  note2("custom:images-dropped");
30289
- if (block.files !== undefined)
30296
+ if (files.text.length > 0)
30297
+ note2("custom:tool-result-files-inlined");
30298
+ if (files.dropped)
30290
30299
  note2("custom:files-dropped");
30291
30300
  break;
30301
+ }
30292
30302
  case "providerNative":
30293
30303
  note2("custom:anthropic-native-block-dropped");
30294
30304
  break;
@@ -30410,9 +30420,7 @@ function toCustomResponsesWire(req, model) {
30410
30420
  input2.push({
30411
30421
  type: "function_call_output",
30412
30422
  call_id: block.toolUseId,
30413
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
30414
-
30415
- `)
30423
+ output: withFileText(block.content, files.text)
30416
30424
  });
30417
30425
  if (block.images !== undefined) {
30418
30426
  note2("custom:tool-result-images-moved");
@@ -30798,9 +30806,7 @@ function toGrokWire(req, model) {
30798
30806
  input2.push({
30799
30807
  type: "function_call_output",
30800
30808
  call_id: block.toolUseId,
30801
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
30802
-
30803
- `)
30809
+ output: withFileText(block.content, files.text)
30804
30810
  });
30805
30811
  if (block.images !== undefined) {
30806
30812
  note2("grok:tool-result-images-moved");
@@ -31258,15 +31264,20 @@ function toKiloWire(req, model) {
31258
31264
  function: { name: block.name, arguments: JSON.stringify(block.input) }
31259
31265
  });
31260
31266
  break;
31261
- case "toolResult":
31267
+ case "toolResult": {
31262
31268
  if (block.native !== undefined)
31263
31269
  note2("kilo:anthropic-native-block-dropped");
31264
31270
  flush();
31271
+ const files = splitFiles(block.files ?? [], (t) => t === "application/pdf");
31265
31272
  messages.push({
31266
31273
  role: "tool",
31267
31274
  tool_call_id: block.toolUseId,
31268
- content: block.content
31275
+ content: withFileText(block.content, files.text)
31269
31276
  });
31277
+ if (files.text.length > 0)
31278
+ note2("kilo:tool-result-files-inlined");
31279
+ if (files.dropped)
31280
+ note2("kilo:files-dropped");
31270
31281
  for (const image of block.images ?? []) {
31271
31282
  note2("kilo:tool-result-images-moved");
31272
31283
  toolImages.push({
@@ -31274,17 +31285,18 @@ function toKiloWire(req, model) {
31274
31285
  image_url: { url: `data:${image.mediaType};base64,${image.data}` }
31275
31286
  });
31276
31287
  }
31277
- for (const file2 of block.files ?? []) {
31288
+ for (const file2 of files.carried) {
31278
31289
  note2("kilo:tool-result-files-moved");
31279
31290
  toolImages.push({
31280
31291
  type: "file",
31281
31292
  file: {
31282
- ...file2.filename !== undefined && { filename: file2.filename },
31293
+ filename: fileName(file2),
31283
31294
  file_data: `data:${file2.mediaType};base64,${file2.data}`
31284
31295
  }
31285
31296
  });
31286
31297
  }
31287
31298
  break;
31299
+ }
31288
31300
  case "providerNative":
31289
31301
  note2("kilo:anthropic-native-block-dropped");
31290
31302
  break;
@@ -31538,19 +31550,23 @@ function toChatWire(req, model, vendor = "kimi") {
31538
31550
  function: { name: block.name, arguments: JSON.stringify(block.input) }
31539
31551
  });
31540
31552
  break;
31541
- case "toolResult":
31553
+ case "toolResult": {
31542
31554
  if (block.native !== undefined)
31543
31555
  note2("kimi:anthropic-native-block-dropped");
31556
+ const files = splitFiles(block.files ?? [], () => false);
31544
31557
  messages.push({
31545
31558
  role: "tool",
31546
31559
  tool_call_id: block.toolUseId,
31547
- content: block.content
31560
+ content: withFileText(block.content, files.text)
31548
31561
  });
31549
31562
  if (block.images !== undefined)
31550
31563
  note2("kimi:images-dropped");
31551
- if (block.files !== undefined)
31564
+ if (files.text.length > 0)
31565
+ note2("kimi:tool-result-files-inlined");
31566
+ if (files.dropped)
31552
31567
  note2("kimi:files-dropped");
31553
31568
  break;
31569
+ }
31554
31570
  case "providerNative":
31555
31571
  note2("kimi:anthropic-native-block-dropped");
31556
31572
  break;
@@ -31957,9 +31973,7 @@ function toMuseWire(req, model) {
31957
31973
  input2.push({
31958
31974
  type: "function_call_output",
31959
31975
  call_id: block.toolUseId,
31960
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
31961
-
31962
- `)
31976
+ output: withFileText(block.content, files.text)
31963
31977
  });
31964
31978
  if (block.images !== undefined) {
31965
31979
  note2("muse:tool-result-images-moved");
@@ -32385,9 +32399,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
32385
32399
  input2.push({
32386
32400
  type: "function_call_output",
32387
32401
  call_id: block.toolUseId,
32388
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
32389
-
32390
- `)
32402
+ output: withFileText(block.content, files.text)
32391
32403
  });
32392
32404
  if (block.images !== undefined) {
32393
32405
  note2("openai:tool-result-images-moved");
@@ -38143,7 +38155,7 @@ function createServiceDeps(input2) {
38143
38155
  }
38144
38156
 
38145
38157
  // apps/cli/src/version.ts
38146
- var VERSION = "0.12.11";
38158
+ var VERSION = "0.12.12";
38147
38159
 
38148
38160
  // apps/cli/src/commands/service.ts
38149
38161
  function gatewayArgv(root) {
package/gateway.js CHANGED
@@ -32635,6 +32635,69 @@ function systemText(system, provider, note) {
32635
32635
  `);
32636
32636
  }
32637
32637
 
32638
+ // packages/providers/src/toolResultFiles.ts
32639
+ function isTextual(mediaType) {
32640
+ const type = mediaType.split(";")[0]?.trim().toLowerCase() ?? "";
32641
+ return type.startsWith("text/") || type.endsWith("+json") || type.endsWith("+xml") || TEXTUAL.has(type);
32642
+ }
32643
+ var TEXTUAL = new Set([
32644
+ "application/json",
32645
+ "application/x-ndjson",
32646
+ "application/xml",
32647
+ "application/yaml",
32648
+ "application/x-yaml",
32649
+ "application/toml",
32650
+ "application/javascript",
32651
+ "application/typescript",
32652
+ "application/sql",
32653
+ "application/x-sh",
32654
+ "message/rfc822"
32655
+ ]);
32656
+ function fileText(file2) {
32657
+ return Buffer.from(file2.data, "base64").toString("utf8");
32658
+ }
32659
+ function splitFiles(files, carries) {
32660
+ const text = [];
32661
+ const carried = [];
32662
+ let dropped = false;
32663
+ for (const file2 of files) {
32664
+ if (isTextual(file2.mediaType))
32665
+ text.push(fileText(file2));
32666
+ else if (carries(file2.mediaType))
32667
+ carried.push(file2);
32668
+ else
32669
+ dropped = true;
32670
+ }
32671
+ return { text, carried, dropped };
32672
+ }
32673
+ function withFileText(content, text) {
32674
+ return [content, ...text].filter((t) => t.length > 0).join(`
32675
+
32676
+ `);
32677
+ }
32678
+ var RESPONSES_FILE_TYPES = Object.assign(Object.create(null), {
32679
+ "application/pdf": "pdf",
32680
+ "application/rtf": "rtf",
32681
+ "application/msword": "doc",
32682
+ "application/vnd.ms-excel": "xls",
32683
+ "application/vnd.ms-powerpoint": "ppt",
32684
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
32685
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
32686
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx"
32687
+ });
32688
+ function fileName(file2) {
32689
+ return file2.filename ?? `file.${RESPONSES_FILE_TYPES[file2.mediaType] ?? "bin"}`;
32690
+ }
32691
+ function responsesFiles(files) {
32692
+ const { text, carried, dropped } = splitFiles(files, (t) => (t in RESPONSES_FILE_TYPES));
32693
+ const parts = carried.map((file2) => ({
32694
+ type: "input_file",
32695
+ filename: fileName(file2),
32696
+ file_data: `data:${file2.mediaType};base64,${file2.data}`
32697
+ }));
32698
+ return { parts, text, dropped };
32699
+ }
32700
+
32638
32701
  // packages/providers/src/anthropic/wire.ts
32639
32702
  var OAUTH_IDENTITY = "You are Claude Code, Anthropic's official CLI for Claude.";
32640
32703
  function wireCacheControl(c) {
@@ -32672,22 +32735,13 @@ function encodeBlock(b, cloak) {
32672
32735
  ...cache
32673
32736
  };
32674
32737
  case "toolResult": {
32675
- const documents = (b.files ?? []).flatMap((file2) => {
32676
- const source = file2.mediaType === "application/pdf" ? { type: "base64", media_type: file2.mediaType, data: file2.data } : file2.mediaType === "text/plain" ? {
32677
- type: "text",
32678
- media_type: file2.mediaType,
32679
- data: Buffer.from(file2.data, "base64").toString("utf8")
32680
- } : undefined;
32681
- if (source === undefined)
32682
- return [];
32683
- return [
32684
- {
32685
- type: "document",
32686
- source,
32687
- ...file2.filename !== undefined && { title: file2.filename }
32688
- }
32689
- ];
32690
- });
32738
+ const files = splitFiles(b.files ?? [], (t) => t === "application/pdf");
32739
+ const text = withFileText(b.content, files.text);
32740
+ const documents = files.carried.map((file2) => ({
32741
+ type: "document",
32742
+ source: { type: "base64", media_type: file2.mediaType, data: file2.data },
32743
+ ...file2.filename !== undefined && { title: file2.filename }
32744
+ }));
32691
32745
  const parts = [
32692
32746
  ...(b.images ?? []).map((image) => encodeBlock(image, cloak)),
32693
32747
  ...documents,
@@ -32696,7 +32750,7 @@ function encodeBlock(b, cloak) {
32696
32750
  return {
32697
32751
  type: "tool_result",
32698
32752
  tool_use_id: b.toolUseId,
32699
- content: parts.length === 0 ? b.content : [...b.content.length > 0 ? [{ type: "text", text: b.content }] : [], ...parts],
32753
+ content: parts.length === 0 ? text : [...text.length > 0 ? [{ type: "text", text }] : [], ...parts],
32700
32754
  is_error: b.isError,
32701
32755
  ...cache
32702
32756
  };
@@ -32872,8 +32926,12 @@ function toWire(req, model, opts) {
32872
32926
  note("anthropic:system-turn-cache-control-dropped");
32873
32927
  for (const m of req.messages) {
32874
32928
  for (const b of m.content) {
32875
- if (b.type === "toolResult" && b.files?.some((f) => f.mediaType !== "application/pdf" && f.mediaType !== "text/plain")) {
32876
- note("anthropic:files-dropped");
32929
+ if (b.type === "toolResult" && b.files !== undefined) {
32930
+ const files = splitFiles(b.files, (t) => t === "application/pdf");
32931
+ if (files.text.length > 0)
32932
+ note("anthropic:tool-result-files-inlined");
32933
+ if (files.dropped)
32934
+ note("anthropic:files-dropped");
32877
32935
  }
32878
32936
  }
32879
32937
  }
@@ -33968,16 +34026,19 @@ function toAntigravityWire(req, model, identity) {
33968
34026
  note("antigravity:tool-result-unmatched");
33969
34027
  if (block.isError === true)
33970
34028
  note("antigravity:tool-result-error-flag-dropped");
34029
+ const files = splitFiles(block.files ?? [], () => true);
34030
+ if (files.text.length > 0)
34031
+ note("antigravity:tool-result-files-inlined");
33971
34032
  parts.push({
33972
34033
  functionResponse: {
33973
34034
  name: cloakName2(cloak, name ?? block.toolUseId),
33974
- response: { output: block.content }
34035
+ response: { output: withFileText(block.content, files.text) }
33975
34036
  }
33976
34037
  });
33977
34038
  for (const image of block.images ?? []) {
33978
34039
  parts.push({ inlineData: { mimeType: image.mediaType, data: image.data } });
33979
34040
  }
33980
- for (const file2 of block.files ?? []) {
34041
+ for (const file2 of files.carried) {
33981
34042
  parts.push({ inlineData: { mimeType: file2.mediaType, data: file2.data } });
33982
34043
  }
33983
34044
  role = "user";
@@ -35720,61 +35781,6 @@ async function* decodeCustomResponses(messages) {
35720
35781
  }
35721
35782
  }
35722
35783
 
35723
- // packages/providers/src/responsesFile.ts
35724
- var ACCEPTED = new Set([
35725
- "application/pdf",
35726
- "text/plain",
35727
- "text/csv",
35728
- "text/markdown",
35729
- "text/html",
35730
- "text/css",
35731
- "text/xml",
35732
- "text/calendar",
35733
- "text/tab-separated-values",
35734
- "text/javascript",
35735
- "text/x-python",
35736
- "text/x-c",
35737
- "text/x-java",
35738
- "text/x-sh",
35739
- "text/x-sql",
35740
- "text/x-typescript",
35741
- "text/x-yaml",
35742
- "application/json",
35743
- "application/javascript",
35744
- "application/typescript",
35745
- "application/toml",
35746
- "application/yaml",
35747
- "application/x-yaml",
35748
- "message/rfc822",
35749
- "application/rtf",
35750
- "application/msword",
35751
- "application/vnd.ms-excel",
35752
- "application/vnd.ms-powerpoint",
35753
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
35754
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
35755
- "application/vnd.openxmlformats-officedocument.presentationml.presentation"
35756
- ]);
35757
- var TEXTUAL = new Set(["application/xml", "application/sql", "application/x-sh"]);
35758
- function responsesFiles(files) {
35759
- const parts = [];
35760
- const text = [];
35761
- let dropped = false;
35762
- for (const file2 of files) {
35763
- if (ACCEPTED.has(file2.mediaType)) {
35764
- parts.push({
35765
- type: "input_file",
35766
- ...file2.filename !== undefined && { filename: file2.filename },
35767
- file_data: `data:${file2.mediaType};base64,${file2.data}`
35768
- });
35769
- } else if (file2.mediaType.startsWith("text/") || TEXTUAL.has(file2.mediaType)) {
35770
- text.push(Buffer.from(file2.data, "base64").toString("utf8"));
35771
- } else {
35772
- dropped = true;
35773
- }
35774
- }
35775
- return { parts, text, dropped };
35776
- }
35777
-
35778
35784
  // packages/providers/src/custom/wire.ts
35779
35785
  function encodeChatToolChoice(c) {
35780
35786
  switch (c.type) {
@@ -35838,19 +35844,23 @@ function toCustomChatWire(req, model) {
35838
35844
  function: { name: block.name, arguments: JSON.stringify(block.input) }
35839
35845
  });
35840
35846
  break;
35841
- case "toolResult":
35847
+ case "toolResult": {
35842
35848
  if (block.native !== undefined)
35843
35849
  note("custom:anthropic-native-block-dropped");
35850
+ const files = splitFiles(block.files ?? [], () => false);
35844
35851
  messages.push({
35845
35852
  role: "tool",
35846
35853
  tool_call_id: block.toolUseId,
35847
- content: block.content
35854
+ content: withFileText(block.content, files.text)
35848
35855
  });
35849
35856
  if (block.images !== undefined)
35850
35857
  note("custom:images-dropped");
35851
- if (block.files !== undefined)
35858
+ if (files.text.length > 0)
35859
+ note("custom:tool-result-files-inlined");
35860
+ if (files.dropped)
35852
35861
  note("custom:files-dropped");
35853
35862
  break;
35863
+ }
35854
35864
  case "providerNative":
35855
35865
  note("custom:anthropic-native-block-dropped");
35856
35866
  break;
@@ -35972,9 +35982,7 @@ function toCustomResponsesWire(req, model) {
35972
35982
  input2.push({
35973
35983
  type: "function_call_output",
35974
35984
  call_id: block.toolUseId,
35975
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
35976
-
35977
- `)
35985
+ output: withFileText(block.content, files.text)
35978
35986
  });
35979
35987
  if (block.images !== undefined) {
35980
35988
  note("custom:tool-result-images-moved");
@@ -36360,9 +36368,7 @@ function toGrokWire(req, model) {
36360
36368
  input2.push({
36361
36369
  type: "function_call_output",
36362
36370
  call_id: block.toolUseId,
36363
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
36364
-
36365
- `)
36371
+ output: withFileText(block.content, files.text)
36366
36372
  });
36367
36373
  if (block.images !== undefined) {
36368
36374
  note("grok:tool-result-images-moved");
@@ -36820,15 +36826,20 @@ function toKiloWire(req, model) {
36820
36826
  function: { name: block.name, arguments: JSON.stringify(block.input) }
36821
36827
  });
36822
36828
  break;
36823
- case "toolResult":
36829
+ case "toolResult": {
36824
36830
  if (block.native !== undefined)
36825
36831
  note("kilo:anthropic-native-block-dropped");
36826
36832
  flush();
36833
+ const files = splitFiles(block.files ?? [], (t) => t === "application/pdf");
36827
36834
  messages.push({
36828
36835
  role: "tool",
36829
36836
  tool_call_id: block.toolUseId,
36830
- content: block.content
36837
+ content: withFileText(block.content, files.text)
36831
36838
  });
36839
+ if (files.text.length > 0)
36840
+ note("kilo:tool-result-files-inlined");
36841
+ if (files.dropped)
36842
+ note("kilo:files-dropped");
36832
36843
  for (const image of block.images ?? []) {
36833
36844
  note("kilo:tool-result-images-moved");
36834
36845
  toolImages.push({
@@ -36836,17 +36847,18 @@ function toKiloWire(req, model) {
36836
36847
  image_url: { url: `data:${image.mediaType};base64,${image.data}` }
36837
36848
  });
36838
36849
  }
36839
- for (const file2 of block.files ?? []) {
36850
+ for (const file2 of files.carried) {
36840
36851
  note("kilo:tool-result-files-moved");
36841
36852
  toolImages.push({
36842
36853
  type: "file",
36843
36854
  file: {
36844
- ...file2.filename !== undefined && { filename: file2.filename },
36855
+ filename: fileName(file2),
36845
36856
  file_data: `data:${file2.mediaType};base64,${file2.data}`
36846
36857
  }
36847
36858
  });
36848
36859
  }
36849
36860
  break;
36861
+ }
36850
36862
  case "providerNative":
36851
36863
  note("kilo:anthropic-native-block-dropped");
36852
36864
  break;
@@ -37100,19 +37112,23 @@ function toChatWire(req, model, vendor = "kimi") {
37100
37112
  function: { name: block.name, arguments: JSON.stringify(block.input) }
37101
37113
  });
37102
37114
  break;
37103
- case "toolResult":
37115
+ case "toolResult": {
37104
37116
  if (block.native !== undefined)
37105
37117
  note("kimi:anthropic-native-block-dropped");
37118
+ const files = splitFiles(block.files ?? [], () => false);
37106
37119
  messages.push({
37107
37120
  role: "tool",
37108
37121
  tool_call_id: block.toolUseId,
37109
- content: block.content
37122
+ content: withFileText(block.content, files.text)
37110
37123
  });
37111
37124
  if (block.images !== undefined)
37112
37125
  note("kimi:images-dropped");
37113
- if (block.files !== undefined)
37126
+ if (files.text.length > 0)
37127
+ note("kimi:tool-result-files-inlined");
37128
+ if (files.dropped)
37114
37129
  note("kimi:files-dropped");
37115
37130
  break;
37131
+ }
37116
37132
  case "providerNative":
37117
37133
  note("kimi:anthropic-native-block-dropped");
37118
37134
  break;
@@ -37519,9 +37535,7 @@ function toMuseWire(req, model) {
37519
37535
  input2.push({
37520
37536
  type: "function_call_output",
37521
37537
  call_id: block.toolUseId,
37522
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
37523
-
37524
- `)
37538
+ output: withFileText(block.content, files.text)
37525
37539
  });
37526
37540
  if (block.images !== undefined) {
37527
37541
  note("muse:tool-result-images-moved");
@@ -37947,9 +37961,7 @@ function toResponsesWire(req, model, opts = { oauth: false }) {
37947
37961
  input2.push({
37948
37962
  type: "function_call_output",
37949
37963
  call_id: block.toolUseId,
37950
- output: [block.content, ...files.text].filter((t) => t.length > 0).join(`
37951
-
37952
- `)
37964
+ output: withFileText(block.content, files.text)
37953
37965
  });
37954
37966
  if (block.images !== undefined) {
37955
37967
  note("openai:tool-result-images-moved");
@@ -61054,6 +61066,7 @@ function readToolResult(content) {
61054
61066
  return { content: "" };
61055
61067
  const text = [];
61056
61068
  const images = [];
61069
+ const files = [];
61057
61070
  const native = [];
61058
61071
  for (const part of content) {
61059
61072
  if (typeof part === "string") {
@@ -61073,6 +61086,16 @@ function readToolResult(content) {
61073
61086
  const p = part !== null && typeof part === "object" ? part : undefined;
61074
61087
  const nativeSchema = p?.type !== undefined && TOOL_RESULT_NATIVE.has(p.type) ? nativeSchemas[p.type] : undefined;
61075
61088
  const parsed2 = nativeSchema?.safeParse(part);
61089
+ if (p?.type === "document" && parsed2?.success === true) {
61090
+ const portable = portableDocument(parsed2.data);
61091
+ if (portable !== undefined) {
61092
+ if (typeof portable === "string")
61093
+ text.push(portable);
61094
+ else
61095
+ files.push(portable);
61096
+ continue;
61097
+ }
61098
+ }
61076
61099
  if (p?.type !== undefined && parsed2?.success === true) {
61077
61100
  const { type: _type, cache_control, ...data } = parsed2.data;
61078
61101
  native.push({
@@ -61090,9 +61113,30 @@ function readToolResult(content) {
61090
61113
  content: text.join(`
61091
61114
  `),
61092
61115
  ...images.length > 0 && { images },
61116
+ ...files.length > 0 && { files },
61093
61117
  ...native.length > 0 && { native }
61094
61118
  };
61095
61119
  }
61120
+ function portableDocument(doc2) {
61121
+ if (doc2.citations !== undefined && doc2.citations !== null || doc2.context !== undefined && doc2.context !== null || doc2.cache_control !== undefined && doc2.cache_control !== null) {
61122
+ return;
61123
+ }
61124
+ const source = doc2.source;
61125
+ const title = typeof doc2.title === "string" ? doc2.title : undefined;
61126
+ if (source.type === "base64" && typeof source.data === "string") {
61127
+ return {
61128
+ type: "file",
61129
+ mediaType: "application/pdf",
61130
+ data: source.data,
61131
+ ...title !== undefined && { filename: title }
61132
+ };
61133
+ }
61134
+ if (source.type === "text" && typeof source.data === "string") {
61135
+ return title === undefined ? source.data : `${title}
61136
+ ${source.data}`;
61137
+ }
61138
+ return;
61139
+ }
61096
61140
  function toIrBlock(b) {
61097
61141
  switch (b.type) {
61098
61142
  case "text":
@@ -63080,7 +63124,7 @@ function createRing(limits = DEFAULT_RING_LIMITS) {
63080
63124
  }
63081
63125
 
63082
63126
  // apps/gateway/src/version.ts
63083
- var VERSION = "0.12.11";
63127
+ var VERSION = "0.12.12";
63084
63128
 
63085
63129
  // apps/gateway/src/app.ts
63086
63130
  var ADMIN_SESSION_TTL_MS = 12 * 60 * 60 * 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnigateway",
3
- "version": "0.12.11",
3
+ "version": "0.12.12",
4
4
  "description": "Self-hosted AI gateway with Anthropic- and OpenAI-compatible APIs, an admin console, and a CLI",
5
5
  "license": "MIT",
6
6
  "author": "Harismawan <mail@harismawan.com>",