@omnicross/core 0.2.0 → 0.2.1

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 (122) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +57 -57
  3. package/README.md +22 -22
  4. package/dist/{BuiltinToolExecutor-CS2WpXhM.d.cts → BuiltinToolExecutor-BHgH-EaZ.d.cts} +25 -2
  5. package/dist/{BuiltinToolExecutor-BluWyeob.d.ts → BuiltinToolExecutor-Bi1LmiTP.d.ts} +25 -2
  6. package/dist/{CompletionService-BiJqftc-.d.cts → CompletionService-BniP7j88.d.cts} +2 -2
  7. package/dist/{CompletionService-NXN_Av5W.d.ts → CompletionService-BqrKPwfA.d.ts} +2 -2
  8. package/dist/{ProviderProxy-CgIcCVwk.d.cts → ProviderProxy-Bz_nkOwq.d.cts} +1 -1
  9. package/dist/{ProviderProxy-DYoY5XoT.d.ts → ProviderProxy-Ckr6oTrE.d.ts} +1 -1
  10. package/dist/auth/GeminiCodeAssistProjectResolver.cjs +2 -2
  11. package/dist/auth/GeminiCodeAssistProjectResolver.js +1 -1
  12. package/dist/{chunk-FJNKXOWE.js → chunk-2C3TTBS7.js} +4 -4
  13. package/dist/{chunk-OST5RJOJ.cjs → chunk-4Z3ZLLC2.cjs} +13 -7
  14. package/dist/chunk-7RJI3NDI.cjs +236 -0
  15. package/dist/chunk-D4WNI6BR.cjs +386 -0
  16. package/dist/chunk-DBBR6RHF.js +236 -0
  17. package/dist/chunk-E4QHVXV5.cjs +118 -0
  18. package/dist/chunk-HL2YSPL7.cjs +673 -0
  19. package/dist/chunk-LFPQ2OVH.js +386 -0
  20. package/dist/{chunk-WSJE42SG.js → chunk-LKDAN4D7.js} +3684 -2462
  21. package/dist/{chunk-DEIUR2TH.js → chunk-LQYS2N47.js} +12 -8
  22. package/dist/{chunk-NZYN7C3P.cjs → chunk-MPXOKQJP.cjs} +53 -53
  23. package/dist/chunk-MZEGQSKQ.js +118 -0
  24. package/dist/chunk-NLUOTJWB.js +673 -0
  25. package/dist/{chunk-CTKM773J.cjs → chunk-UPQIWJIE.cjs} +12 -8
  26. package/dist/{chunk-CFSGYFOZ.js → chunk-VL5TUDTM.js} +7 -1
  27. package/dist/{chunk-7B56AJBB.cjs → chunk-VSYQ6XYN.cjs} +2233 -1011
  28. package/dist/{chunk-CDHS2QDC.js → chunk-Y4CRNHJO.js} +53 -53
  29. package/dist/{chunk-TVYA5JSQ.cjs → chunk-ZAPN7XA6.cjs} +5 -5
  30. package/dist/completion/BuiltinToolExecutor.cjs +2 -2
  31. package/dist/completion/BuiltinToolExecutor.d.cts +3 -1
  32. package/dist/completion/BuiltinToolExecutor.d.ts +3 -1
  33. package/dist/completion/BuiltinToolExecutor.js +1 -1
  34. package/dist/completion/CompletionService.cjs +11 -10
  35. package/dist/completion/CompletionService.d.cts +6 -3
  36. package/dist/completion/CompletionService.d.ts +6 -3
  37. package/dist/completion/CompletionService.js +10 -9
  38. package/dist/completion.cjs +11 -10
  39. package/dist/completion.d.cts +6 -3
  40. package/dist/completion.d.ts +6 -3
  41. package/dist/completion.js +10 -9
  42. package/dist/egress-I46O_p5L.d.cts +126 -0
  43. package/dist/egress-I46O_p5L.d.ts +126 -0
  44. package/dist/frontends-Doz0RaWu.d.cts +97 -0
  45. package/dist/frontends-Doz0RaWu.d.ts +97 -0
  46. package/dist/image-generation.cjs +2 -2
  47. package/dist/image-generation.d.cts +7 -4
  48. package/dist/image-generation.d.ts +7 -4
  49. package/dist/image-generation.js +1 -1
  50. package/dist/index.cjs +25 -10
  51. package/dist/index.d.cts +12 -8
  52. package/dist/index.d.ts +12 -8
  53. package/dist/index.js +24 -9
  54. package/dist/openai-operation.d.cts +4 -1
  55. package/dist/openai-operation.d.ts +4 -1
  56. package/dist/outbound-api/routeResolver.d.cts +9 -5
  57. package/dist/outbound-api/routeResolver.d.ts +9 -5
  58. package/dist/outbound-api/subscriptionRegistryPort.d.cts +4 -1
  59. package/dist/outbound-api/subscriptionRegistryPort.d.ts +4 -1
  60. package/dist/outbound-api/types.d.cts +8 -4
  61. package/dist/outbound-api/types.d.ts +8 -4
  62. package/dist/outbound-api.cjs +25 -10
  63. package/dist/outbound-api.d.cts +117 -8
  64. package/dist/outbound-api.d.ts +117 -8
  65. package/dist/outbound-api.js +24 -9
  66. package/dist/pipeline/AccountAllowanceScheduling.d.cts +8 -4
  67. package/dist/pipeline/AccountAllowanceScheduling.d.ts +8 -4
  68. package/dist/pipeline/upstreamFetch.cjs +2 -2
  69. package/dist/pipeline/upstreamFetch.js +1 -1
  70. package/dist/ports.d.cts +8 -4
  71. package/dist/ports.d.ts +8 -4
  72. package/dist/provider-proxy/ProviderProxy.cjs +11 -10
  73. package/dist/provider-proxy/ProviderProxy.d.cts +5 -2
  74. package/dist/provider-proxy/ProviderProxy.d.ts +5 -2
  75. package/dist/provider-proxy/ProviderProxy.js +10 -9
  76. package/dist/provider-proxy/ingress/providerProxyShared.cjs +13 -10
  77. package/dist/provider-proxy/ingress/providerProxyShared.d.cts +22 -3
  78. package/dist/provider-proxy/ingress/providerProxyShared.d.ts +22 -3
  79. package/dist/provider-proxy/ingress/providerProxyShared.js +12 -9
  80. package/dist/provider-proxy/types.d.cts +4 -1
  81. package/dist/provider-proxy/types.d.ts +4 -1
  82. package/dist/provider-proxy.cjs +11 -10
  83. package/dist/provider-proxy.d.cts +10 -6
  84. package/dist/provider-proxy.d.ts +10 -6
  85. package/dist/provider-proxy.js +10 -9
  86. package/dist/proxy-UZTtjPZx.d.cts +18 -0
  87. package/dist/proxy-UZTtjPZx.d.ts +18 -0
  88. package/dist/{routeResolver-rpKQLyDO.d.cts → routeResolver-Da0yvkL1.d.cts} +2 -2
  89. package/dist/{routeResolver-CTCcSHWu.d.ts → routeResolver-STwMz_G4.d.ts} +2 -2
  90. package/dist/runtime-6QXNU526.cjs +8 -0
  91. package/dist/runtime-M5WXLD2R.js +8 -0
  92. package/dist/runtime-t8AZacFF.d.cts +233 -0
  93. package/dist/runtime-t8AZacFF.d.ts +233 -0
  94. package/dist/search/api.cjs +761 -0
  95. package/dist/search/api.d.cts +370 -0
  96. package/dist/search/api.d.ts +370 -0
  97. package/dist/search/api.js +761 -0
  98. package/dist/search/http.cjs +37 -0
  99. package/dist/search/http.d.cts +269 -0
  100. package/dist/search/http.d.ts +269 -0
  101. package/dist/search/http.js +37 -0
  102. package/dist/search.cjs +57 -0
  103. package/dist/search.d.cts +113 -0
  104. package/dist/search.d.ts +113 -0
  105. package/dist/search.js +57 -0
  106. package/dist/transformer/transformers/AnthropicTransformer.cjs +3 -3
  107. package/dist/transformer/transformers/AnthropicTransformer.js +2 -2
  108. package/dist/transformer/transformers.cjs +7 -7
  109. package/dist/transformer/transformers.js +6 -6
  110. package/dist/transformer.cjs +6 -6
  111. package/dist/transformer.js +5 -5
  112. package/dist/{types-DsHBBk3h.d.cts → types-BSIJdsyl.d.cts} +15 -0
  113. package/dist/{types-CbglB73l.d.cts → types-Be-yt_6T.d.cts} +1 -1
  114. package/dist/{types-CVRge76p.d.ts → types-By9Tg6-I.d.ts} +15 -0
  115. package/dist/types-CbCZqLGg.d.cts +127 -0
  116. package/dist/types-CbCZqLGg.d.ts +127 -0
  117. package/dist/{types-jjU24eYG.d.cts → types-D-oHYusb.d.cts} +73 -4
  118. package/dist/{types-Bd72H4SB.d.ts → types-Dm4_36V4.d.ts} +1 -1
  119. package/dist/{types-5T223WYQ.d.ts → types-Dvlpjn0d.d.ts} +73 -4
  120. package/package.json +5 -3
  121. package/dist/{chunk-6OC3ORW6.js → chunk-EUZRH544.js} +3 -3
  122. package/dist/{chunk-SQMAEDNE.cjs → chunk-POUTD5AM.cjs} +2 -2
@@ -1765,7 +1765,10 @@ async function readJsonBody(request2, options) {
1765
1765
 
1766
1766
  // src/image-generation/openai-images/types.ts
1767
1767
  var DEFAULT_IMAGE_API_LIMITS = Object.freeze({
1768
- maxJsonBytes: 1024 * 1024,
1768
+ // Codex's built-in image tool sends edits as JSON data URLs rather than
1769
+ // multipart files. Leave room for the Base64 expansion of the bounded
1770
+ // aggregate input budget plus the small JSON/options envelope.
1771
+ maxJsonBytes: 96 * 1024 * 1024,
1769
1772
  maxMultipartBytes: 64 * 1024 * 1024,
1770
1773
  maxFileBytes: 50 * 1024 * 1024,
1771
1774
  maxTotalInputBytes: 64 * 1024 * 1024,
@@ -2326,7 +2329,7 @@ async function readMultipartEdit(request2, scope, limits, signal) {
2326
2329
  function invalid4(param = "image") {
2327
2330
  throw new ImageGenerationError("invalid_image_request", { param });
2328
2331
  }
2329
- function closedInput(value, maxRemoteUrlBytes) {
2332
+ function closedInput(value, limits) {
2330
2333
  if (!value || typeof value !== "object" || Array.isArray(value)) invalid4();
2331
2334
  const record2 = value;
2332
2335
  const keys = Object.keys(record2);
@@ -2334,8 +2337,9 @@ function closedInput(value, maxRemoteUrlBytes) {
2334
2337
  const key = keys[0];
2335
2338
  if (key !== "file_id" && key !== "image_url") invalid4();
2336
2339
  const item = record2[key];
2337
- const maxBytes = key === "file_id" ? 256 : maxRemoteUrlBytes;
2338
- if (typeof item !== "string" || !item || Buffer.byteLength(item, "utf8") > maxBytes) invalid4();
2340
+ if (typeof item !== "string" || !item) invalid4();
2341
+ const maxBytes = key === "file_id" ? 256 : item.toLowerCase().startsWith("data:") ? Math.ceil(limits.maxFileBytes / 3) * 4 + 64 : limits.maxRemoteUrlBytes;
2342
+ if (Buffer.byteLength(item, "utf8") > maxBytes) invalid4();
2339
2343
  return { [key]: item };
2340
2344
  }
2341
2345
  function decodedBase64Length(value) {
@@ -2407,7 +2411,7 @@ async function resolveReference(referenceId, runtime, scope) {
2407
2411
  return asset;
2408
2412
  }
2409
2413
  async function resolveImageInput(value, runtime, scope, signal) {
2410
- const input = closedInput(value, runtime.limits.maxRemoteUrlBytes);
2414
+ const input = closedInput(value, runtime.limits);
2411
2415
  if ("file_id" in input) return resolveReference(input.file_id, runtime, scope);
2412
2416
  if (input.image_url.toLowerCase().startsWith("data:")) {
2413
2417
  return resolveDataUrl(input.image_url, runtime, scope, signal);
@@ -2432,10 +2436,10 @@ async function resolveImageInput(value, runtime, scope, signal) {
2432
2436
  materializer
2433
2437
  });
2434
2438
  }
2435
- function parseImageInputList(value, maxRemoteUrlBytes) {
2439
+ function parseImageInputList(value, limits) {
2436
2440
  const list = Array.isArray(value) ? value : [value];
2437
2441
  if (list.length < 1 || list.length > 16) invalid4();
2438
- for (const item of list) closedInput(item, maxRemoteUrlBytes);
2442
+ for (const item of list) closedInput(item, limits);
2439
2443
  return list;
2440
2444
  }
2441
2445
 
@@ -2481,7 +2485,7 @@ function createImageEditHandler(deps) {
2481
2485
  });
2482
2486
  const inputs = parseImageInputList(
2483
2487
  record2.images ?? record2.image,
2484
- runtime.limits.maxRemoteUrlBytes
2488
+ runtime.limits
2485
2489
  );
2486
2490
  const resolveObservedInput = async (input) => {
2487
2491
  const reference = isReferenceInput(input);
@@ -1,20 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/completion/BuiltinToolExecutor.ts
2
+ var _searchtypes = require('@omnicross/contracts/search-types');
2
3
  var DEFAULT_SEARCH_COUNT = 5;
3
4
  var DEFAULT_FETCH_MAX_CHARS = 2e4;
4
- var FALLBACK_ORDER = [
5
- "tavily",
6
- "jina",
7
- "searxng",
8
- "zhipu",
9
- "z.ai",
10
- "bocha",
11
- "grok",
12
- "local-google",
13
- "local-bing",
14
- "local-baidu",
15
- "local-duckduckgo"
16
- ];
17
- var IMPLICIT_LOCAL_FALLBACK = "local-google";
18
5
  var WEB_SEARCH_TOOL = {
19
6
  id: "builtin__web_search",
20
7
  serverId: "builtin",
@@ -50,10 +37,19 @@ var WEB_FETCH_TOOL = {
50
37
  isBuiltIn: true
51
38
  };
52
39
  var BuiltinToolExecutor = class {
53
- constructor(webSearch) {
40
+ /**
41
+ * @param webSearch - the legacy port, still the `web_fetch` URL reader.
42
+ * @param runtime - the search runtime `web_search` delegates to. Optional so
43
+ * the single-argument construction hosts already use keeps compiling; when
44
+ * omitted, a default runtime over the builtin HTTP providers is built on
45
+ * first use.
46
+ */
47
+ constructor(webSearch, runtime) {
54
48
  this.webSearch = webSearch;
49
+ this.runtime = runtime;
55
50
  }
56
51
 
52
+
57
53
  async execute(toolName, args) {
58
54
  switch (toolName) {
59
55
  case "web_search":
@@ -73,47 +69,51 @@ var BuiltinToolExecutor = class {
73
69
  return { isError: true, content: [{ type: "text", text: "Error: query parameter is required." }] };
74
70
  }
75
71
  const count = Math.min(Math.max(Number(_nullishCoalesce(args.count, () => ( DEFAULT_SEARCH_COUNT))), 1), 10);
76
- const chain = this.resolveProviderChain();
77
- let lastError = "";
78
- for (const providerId of chain) {
79
- try {
80
- const result = await this.webSearch.search(query, providerId, { maxResults: count });
81
- if (!result.success) {
82
- lastError = result.error || "Unknown error";
83
- console.log(`[BuiltinToolExecutor] Search provider ${providerId} failed: ${lastError}, trying next...`);
84
- continue;
85
- }
86
- const items = result.results.slice(0, count);
87
- if (items.length === 0) {
88
- console.log(`[BuiltinToolExecutor] Search provider ${providerId} returned 0 results, trying next...`);
89
- continue;
90
- }
91
- const text = items.map((r, i) => `${i + 1}. ${r.title}
72
+ let response;
73
+ try {
74
+ response = await (await this.getRuntime()).search({
75
+ query,
76
+ options: { maxResults: count }
77
+ });
78
+ } catch (err) {
79
+ const shape = _searchtypes.toSearchErrorShape.call(void 0, err);
80
+ return {
81
+ isError: false,
82
+ content: [{ type: "text", text: `Search failed (${shape.code}): ${shape.message}` }]
83
+ };
84
+ }
85
+ if (response.results.length === 0) {
86
+ return {
87
+ isError: false,
88
+ content: [{ type: "text", text: `No results found for "${query}" after trying ${response.attempts.length} provider(s). Try rephrasing your search.` }]
89
+ };
90
+ }
91
+ const text = response.results.map((r, i) => `${i + 1}. ${r.title}
92
92
  URL: ${r.url}
93
93
  ${r.content || ""}`).join("\n\n");
94
- return { isError: false, content: [{ type: "text", text }] };
95
- } catch (err) {
96
- lastError = err instanceof Error ? err.message : String(err);
97
- console.log(`[BuiltinToolExecutor] Search provider ${providerId} threw: ${lastError}, trying next...`);
98
- continue;
99
- }
100
- }
101
- return {
102
- isError: false,
103
- content: [{ type: "text", text: lastError ? `Search failed after trying ${chain.length} provider(s). Last error: ${lastError}` : `No results found for "${query}" after trying ${chain.length} provider(s). Try rephrasing your search.` }]
104
- };
94
+ return { isError: false, content: [{ type: "text", text }] };
105
95
  }
106
- resolveProviderChain() {
107
- const chain = [];
108
- for (const id of FALLBACK_ORDER) {
109
- if (this.webSearch.isProviderEnabled(id)) {
110
- chain.push(id);
111
- }
112
- }
113
- if (!chain.includes(IMPLICIT_LOCAL_FALLBACK)) {
114
- chain.push(IMPLICIT_LOCAL_FALLBACK);
115
- }
116
- return chain;
96
+ /** Memoized lazy construction, so concurrent first calls share one runtime. */
97
+
98
+ /**
99
+ * The runtime `web_search` delegates to.
100
+ *
101
+ * Imported lazily so the search stack's transport and HTML parsing stay out
102
+ * of the module graph of every consumer that only wants the tool definitions
103
+ * — the same reason `builtin-web-fetch` is loaded on demand below.
104
+ *
105
+ * The PROMISE is memoized, not just its result: two concurrent first searches
106
+ * would otherwise each build a runtime and the later one would win. Harmless
107
+ * while the default runtime is stateless, but it stops being harmless the
108
+ * moment one holds a connection pool or a cache.
109
+ */
110
+ getRuntime() {
111
+ if (this.runtime !== void 0) return Promise.resolve(this.runtime);
112
+ this.runtimeInit ??= Promise.resolve().then(() => _interopRequireWildcard(require("./runtime-6QXNU526.cjs"))).then(({ createSearchRuntime }) => {
113
+ this.runtime = createSearchRuntime();
114
+ return this.runtime;
115
+ });
116
+ return this.runtimeInit;
117
117
  }
118
118
  // -----------------------------------------------------------------------
119
119
  // web_fetch
@@ -0,0 +1,118 @@
1
+ // src/search/frontends.ts
2
+ var SEARCH_FRONTEND_NAMES = Object.freeze([
3
+ "codex",
4
+ "responses",
5
+ "anthropic"
6
+ ]);
7
+ var SEARCH_FRONTEND_MODES = Object.freeze([
8
+ "native",
9
+ "managed",
10
+ "off"
11
+ ]);
12
+ var DEFAULT_SEARCH_FRONTEND_MODES = Object.freeze({
13
+ codex: "off",
14
+ responses: "native",
15
+ anthropic: "native"
16
+ });
17
+ var SEARCH_UNSUPPORTED_CAPABILITY_CODE = "unsupported_capability";
18
+ function searchErrorHttpStatus(code) {
19
+ switch (code) {
20
+ case "rate_limited":
21
+ return 429;
22
+ case "timeout":
23
+ return 504;
24
+ case "cancelled":
25
+ return 499;
26
+ case "config_missing":
27
+ return 503;
28
+ case "auth_failed":
29
+ case "upstream_unavailable":
30
+ case "parse_failed":
31
+ case "policy_denied":
32
+ return 502;
33
+ default:
34
+ return 502;
35
+ }
36
+ }
37
+ function isSearchFrontendMode(value) {
38
+ return typeof value === "string" && SEARCH_FRONTEND_MODES.includes(value);
39
+ }
40
+ function record(value) {
41
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
42
+ }
43
+ function normalizeSearchFrontendModes(value) {
44
+ const raw = record(value) ?? {};
45
+ const modes = {
46
+ ...DEFAULT_SEARCH_FRONTEND_MODES
47
+ };
48
+ for (const name of SEARCH_FRONTEND_NAMES) {
49
+ const candidate = raw[name];
50
+ if (isSearchFrontendMode(candidate)) modes[name] = candidate;
51
+ }
52
+ return Object.freeze(modes);
53
+ }
54
+ function validateSearchFrontendModes(value, path = "$.search.modes") {
55
+ if (value === void 0) return [];
56
+ const raw = record(value);
57
+ if (!raw) return [`${path}: expected an object`];
58
+ const errors = [];
59
+ for (const [key, candidate] of Object.entries(raw)) {
60
+ if (!SEARCH_FRONTEND_NAMES.includes(key)) {
61
+ errors.push(`${path}.${key}: unknown frontend (expected ${SEARCH_FRONTEND_NAMES.join(", ")})`);
62
+ continue;
63
+ }
64
+ if (isSearchFrontendMode(candidate)) continue;
65
+ errors.push(
66
+ `${path}.${key}: not a mode (got ${typeof candidate}; expected ${SEARCH_FRONTEND_MODES.join(", ")})`
67
+ );
68
+ }
69
+ return errors;
70
+ }
71
+
72
+ // src/search/webSearchBackendCompat.ts
73
+ import {
74
+ searchErrorToLegacyWebSearchResponse,
75
+ toLegacyWebSearchResponse
76
+ } from "@omnicross/contracts/search-compat";
77
+ import { toSearchErrorShape } from "@omnicross/contracts/search-types";
78
+ function searchRuntimeAsWebSearchBackend(runtime, options = {}) {
79
+ return {
80
+ async search(query, providerId, searchOptions) {
81
+ try {
82
+ const response = await runtime.search({
83
+ query,
84
+ provider: providerId,
85
+ // `WebSearchOptions` is a strict subset of `SearchOptions` with
86
+ // identical field names — asserted in the contracts tests.
87
+ ...searchOptions === void 0 ? {} : { options: searchOptions }
88
+ });
89
+ return toLegacyWebSearchResponse(response);
90
+ } catch (error) {
91
+ return searchErrorToLegacyWebSearchResponse(query, toSearchErrorShape(error));
92
+ }
93
+ },
94
+ isProviderEnabled(id) {
95
+ return runtime.listProviders().some((descriptor) => descriptor.id === id);
96
+ },
97
+ async readUrl(url, readOptions) {
98
+ if (options.readUrl !== void 0) return options.readUrl(url, readOptions);
99
+ return {
100
+ success: false,
101
+ url,
102
+ error: "URL reading is not available through the search runtime adapter"
103
+ };
104
+ }
105
+ };
106
+ }
107
+
108
+ export {
109
+ SEARCH_FRONTEND_NAMES,
110
+ SEARCH_FRONTEND_MODES,
111
+ DEFAULT_SEARCH_FRONTEND_MODES,
112
+ SEARCH_UNSUPPORTED_CAPABILITY_CODE,
113
+ searchErrorHttpStatus,
114
+ isSearchFrontendMode,
115
+ normalizeSearchFrontendModes,
116
+ validateSearchFrontendModes,
117
+ searchRuntimeAsWebSearchBackend
118
+ };