@omnicross/core 0.1.10 → 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.
- package/README.md +7 -0
- package/dist/{BuiltinToolExecutor-CS2WpXhM.d.cts → BuiltinToolExecutor-BHgH-EaZ.d.cts} +25 -2
- package/dist/{BuiltinToolExecutor-BluWyeob.d.ts → BuiltinToolExecutor-Bi1LmiTP.d.ts} +25 -2
- package/dist/{CompletionService-kNA17cfI.d.cts → CompletionService-BniP7j88.d.cts} +2 -2
- package/dist/{CompletionService-C3BX0Ovy.d.ts → CompletionService-BqrKPwfA.d.ts} +2 -2
- package/dist/{ProviderProxy-QdwNV6l1.d.cts → ProviderProxy-Bz_nkOwq.d.cts} +1 -1
- package/dist/{ProviderProxy--ROec6VI.d.ts → ProviderProxy-Ckr6oTrE.d.ts} +1 -1
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -6
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -4
- package/dist/{chunk-NGYOO5TO.js → chunk-2C3TTBS7.js} +7 -7
- package/dist/{chunk-QUSEZNYS.cjs → chunk-32SRZFFP.cjs} +4 -1
- package/dist/chunk-4JOU54M5.js +200 -0
- package/dist/{chunk-2UTGX6FM.js → chunk-4VVCXVB7.js} +1 -1
- package/dist/{chunk-RJUONLUQ.cjs → chunk-4Z3ZLLC2.cjs} +14 -8
- package/dist/chunk-6DDYNS2B.cjs +384 -0
- package/dist/{chunk-GXEZ2R3E.js → chunk-6OKXH2TW.js} +18 -7
- package/dist/{chunk-YWL7YZWS.cjs → chunk-7LRTPNFL.cjs} +5 -0
- package/dist/{chunk-CCVRRJOX.js → chunk-7PIUVCKK.js} +9 -2
- package/dist/chunk-7RJI3NDI.cjs +236 -0
- package/dist/{chunk-IIRPUVPH.cjs → chunk-7ZHBN75N.cjs} +3 -1
- package/dist/chunk-D4WNI6BR.cjs +386 -0
- package/dist/chunk-DBBR6RHF.js +236 -0
- package/dist/chunk-E4QHVXV5.cjs +118 -0
- package/dist/{chunk-HKB656B4.js → chunk-EUZRH544.js} +55 -287
- package/dist/{chunk-WNKWAEUR.js → chunk-EYGBM2VC.js} +3 -1
- package/dist/{chunk-UWDW6PN3.cjs → chunk-FX325I5Q.cjs} +20 -9
- package/dist/chunk-G4CZIUIB.cjs +200 -0
- package/dist/chunk-HCOQQAZE.cjs +123 -0
- package/dist/chunk-HL2YSPL7.cjs +673 -0
- package/dist/{chunk-55FMGZ3L.js → chunk-HN74IGEO.js} +1 -1
- package/dist/{chunk-ZY6KU6P3.js → chunk-HOMUGKHR.js} +8 -5
- package/dist/{chunk-AOFWNWLT.cjs → chunk-IUL4VWNU.cjs} +22 -1
- package/dist/{chunk-5LNYGCIW.cjs → chunk-KIQ2HA2A.cjs} +5 -5
- package/dist/{chunk-MUHWHQVM.cjs → chunk-KQBLZMP6.cjs} +4 -3
- package/dist/chunk-LFEH7CEO.js +384 -0
- package/dist/chunk-LFPQ2OVH.js +386 -0
- package/dist/{chunk-FEBAQI5A.js → chunk-LKDAN4D7.js} +6363 -1350
- package/dist/chunk-LQYS2N47.js +3923 -0
- package/dist/{chunk-NZYN7C3P.cjs → chunk-MPXOKQJP.cjs} +53 -53
- package/dist/chunk-MZEGQSKQ.js +118 -0
- package/dist/chunk-N76KU6F5.js +123 -0
- package/dist/chunk-NLUOTJWB.js +673 -0
- package/dist/{chunk-CMVXX7ON.cjs → chunk-NOITAVHA.cjs} +114 -58
- package/dist/{chunk-Q27JY5RG.cjs → chunk-OIKREZVQ.cjs} +7 -4
- package/dist/{chunk-ZQQUD66M.cjs → chunk-POUTD5AM.cjs} +63 -295
- package/dist/{chunk-6D4W22P4.js → chunk-QIIAMBTM.js} +4 -1
- package/dist/{chunk-56QD3YW6.cjs → chunk-QWNUOR7F.cjs} +11 -4
- package/dist/{chunk-S3DYFEBE.js → chunk-R4VCO2CB.js} +10 -1
- package/dist/{chunk-4VZX5F4T.cjs → chunk-T6NWPIYZ.cjs} +5 -2
- package/dist/{chunk-EBLFCNPY.js → chunk-U47LQXPB.js} +5 -2
- package/dist/chunk-UPQIWJIE.cjs +3923 -0
- package/dist/{chunk-N7OOJI5V.js → chunk-V2UKUTJ3.js} +5 -0
- package/dist/{chunk-45FHEOKW.js → chunk-V53ZEFXC.js} +92 -36
- package/dist/{chunk-RJ5ZGNI3.js → chunk-VL5TUDTM.js} +8 -2
- package/dist/{chunk-TIT74RIL.cjs → chunk-VSYQ6XYN.cjs} +6837 -1824
- package/dist/{chunk-OC6DOOFX.cjs → chunk-VXRTQZF2.cjs} +5 -5
- package/dist/{chunk-RICPANBY.cjs → chunk-WX2E2G7H.cjs} +13 -4
- package/dist/{chunk-DE2SRBFZ.js → chunk-X335TJNS.js} +4 -3
- package/dist/{chunk-CDHS2QDC.js → chunk-Y4CRNHJO.js} +53 -53
- package/dist/{chunk-P7EM6BND.cjs → chunk-ZAPN7XA6.cjs} +10 -10
- package/dist/{chunk-N2EIM2XJ.js → chunk-ZLNHPUFA.js} +22 -1
- package/dist/completion/BuiltinToolExecutor.cjs +2 -2
- package/dist/completion/BuiltinToolExecutor.d.cts +3 -1
- package/dist/completion/BuiltinToolExecutor.d.ts +3 -1
- package/dist/completion/BuiltinToolExecutor.js +1 -1
- package/dist/completion/CompletionService.cjs +32 -28
- package/dist/completion/CompletionService.d.cts +7 -3
- package/dist/completion/CompletionService.d.ts +7 -3
- package/dist/completion/CompletionService.js +31 -27
- package/dist/completion.cjs +40 -36
- package/dist/completion.d.cts +7 -3
- package/dist/completion.d.ts +7 -3
- package/dist/completion.js +39 -35
- package/dist/egress-I46O_p5L.d.cts +126 -0
- package/dist/egress-I46O_p5L.d.ts +126 -0
- package/dist/frontends-Doz0RaWu.d.cts +97 -0
- package/dist/frontends-Doz0RaWu.d.ts +97 -0
- package/dist/image-generation.cjs +52 -0
- package/dist/image-generation.d.cts +96 -0
- package/dist/image-generation.d.ts +96 -0
- package/dist/image-generation.js +52 -0
- package/dist/index.cjs +142 -32
- package/dist/index.d.cts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +159 -49
- package/dist/openai-operation.cjs +18 -0
- package/dist/openai-operation.d.cts +22 -0
- package/dist/openai-operation.d.ts +22 -0
- package/dist/openai-operation.js +18 -0
- package/dist/outbound-api/auditCapture.cjs +3 -3
- package/dist/outbound-api/auditCapture.d.cts +13 -2
- package/dist/outbound-api/auditCapture.d.ts +13 -2
- package/dist/outbound-api/auditCapture.js +2 -2
- package/dist/outbound-api/auditRedact.cjs +2 -2
- package/dist/outbound-api/auditRedact.js +1 -1
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +11 -4
- package/dist/outbound-api/routeResolver.d.ts +11 -4
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +5 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +5 -1
- package/dist/outbound-api/types.d.cts +10 -3
- package/dist/outbound-api/types.d.ts +10 -3
- package/dist/outbound-api.cjs +65 -33
- package/dist/outbound-api.d.cts +205 -10
- package/dist/outbound-api.d.ts +205 -10
- package/dist/outbound-api.js +64 -32
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +22 -15
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +22 -15
- package/dist/pipeline/LlmConfigProviderAuth.cjs +3 -3
- package/dist/pipeline/LlmConfigProviderAuth.js +2 -2
- package/dist/pipeline/SubscriptionAccountHealth.cjs +2 -2
- package/dist/pipeline/SubscriptionAccountHealth.d.cts +7 -0
- package/dist/pipeline/SubscriptionAccountHealth.d.ts +7 -0
- package/dist/pipeline/SubscriptionAccountHealth.js +1 -1
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.d.cts +11 -6
- package/dist/pipeline/executeProviderCall.d.ts +11 -6
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/upstreamFetch.cjs +2 -2
- package/dist/pipeline/upstreamFetch.d.cts +5 -0
- package/dist/pipeline/upstreamFetch.d.ts +5 -0
- package/dist/pipeline/upstreamFetch.js +1 -1
- package/dist/ports.d.cts +10 -3
- package/dist/ports.d.ts +10 -3
- package/dist/provider-proxy/ProviderProxy.cjs +32 -28
- package/dist/provider-proxy/ProviderProxy.d.cts +6 -2
- package/dist/provider-proxy/ProviderProxy.d.ts +6 -2
- package/dist/provider-proxy/ProviderProxy.js +31 -27
- package/dist/provider-proxy/identity/codexCliHeaders.cjs +4 -2
- package/dist/provider-proxy/identity/codexCliHeaders.d.cts +26 -6
- package/dist/provider-proxy/identity/codexCliHeaders.d.ts +26 -6
- package/dist/provider-proxy/identity/codexCliHeaders.js +5 -3
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +36 -28
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +41 -9
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +41 -9
- package/dist/provider-proxy/ingress/providerProxyShared.js +35 -27
- package/dist/provider-proxy/types.d.cts +17 -483
- package/dist/provider-proxy/types.d.ts +17 -483
- package/dist/provider-proxy.cjs +46 -28
- package/dist/provider-proxy.d.cts +34 -8
- package/dist/provider-proxy.d.ts +34 -8
- package/dist/provider-proxy.js +45 -27
- package/dist/proxy-UZTtjPZx.d.cts +18 -0
- package/dist/proxy-UZTtjPZx.d.ts +18 -0
- package/dist/{routeResolver-CVFE8KKe.d.cts → routeResolver-Da0yvkL1.d.cts} +4 -2
- package/dist/{routeResolver-C0mkkZaM.d.ts → routeResolver-STwMz_G4.d.ts} +4 -2
- package/dist/runtime-6QXNU526.cjs +8 -0
- package/dist/runtime-M5WXLD2R.js +8 -0
- package/dist/runtime-t8AZacFF.d.cts +233 -0
- package/dist/runtime-t8AZacFF.d.ts +233 -0
- package/dist/search/api.cjs +761 -0
- package/dist/search/api.d.cts +370 -0
- package/dist/search/api.d.ts +370 -0
- package/dist/search/api.js +761 -0
- package/dist/search/http.cjs +37 -0
- package/dist/search/http.d.cts +269 -0
- package/dist/search/http.d.ts +269 -0
- package/dist/search/http.js +37 -0
- package/dist/search.cjs +57 -0
- package/dist/search.d.cts +113 -0
- package/dist/search.d.ts +113 -0
- package/dist/search.js +57 -0
- package/dist/transformer/TransformerChainExecutor.cjs +2 -2
- package/dist/transformer/TransformerChainExecutor.d.cts +2 -2
- package/dist/transformer/TransformerChainExecutor.d.ts +2 -2
- package/dist/transformer/TransformerChainExecutor.js +1 -1
- package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.cjs +16 -0
- package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.d.cts +53 -0
- package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.d.ts +53 -0
- package/dist/transformer/transformers/AnthropicOpenAIToAnthropicStream.js +16 -0
- package/dist/transformer/transformers/AnthropicTransformer.cjs +4 -3
- package/dist/transformer/transformers/AnthropicTransformer.js +3 -2
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +4 -4
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +3 -3
- package/dist/transformer/transformers/GeminiTransformer.cjs +4 -4
- package/dist/transformer/transformers/GeminiTransformer.js +3 -3
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +3 -3
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +2 -2
- package/dist/transformer/transformers/OpenAITransformer.cjs +3 -3
- package/dist/transformer/transformers/OpenAITransformer.js +2 -2
- package/dist/transformer/transformers.cjs +11 -10
- package/dist/transformer/transformers.js +12 -11
- package/dist/transformer/types.d.cts +39 -4
- package/dist/transformer/types.d.ts +39 -4
- package/dist/transformer.cjs +14 -13
- package/dist/transformer.js +13 -12
- package/dist/types-BSIJdsyl.d.cts +1130 -0
- package/dist/types-Be-yt_6T.d.cts +196 -0
- package/dist/types-By9Tg6-I.d.ts +1130 -0
- package/dist/types-CbCZqLGg.d.cts +127 -0
- package/dist/types-CbCZqLGg.d.ts +127 -0
- package/dist/{types-C2MwkLah.d.cts → types-D-oHYusb.d.cts} +250 -21
- package/dist/types-Dm4_36V4.d.ts +196 -0
- package/dist/{types-BB8pxk_3.d.ts → types-Dvlpjn0d.d.ts} +250 -21
- package/dist/usage.cjs +2 -2
- package/dist/usage.d.cts +6 -1
- package/dist/usage.d.ts +6 -1
- package/dist/usage.js +1 -1
- package/package.json +71 -64
- package/dist/chunk-FCR77GYM.cjs +0 -33
- package/dist/chunk-K5NM7VAH.js +0 -33
- /package/dist/{chunk-XXFYLL7R.js → chunk-ECZ3ZE2C.js} +0 -0
- /package/dist/{chunk-3SCOLIPT.cjs → chunk-MXI2PWIC.cjs} +0 -0
|
@@ -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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// src/outbound-api/auditRedact.ts
|
|
2
|
+
var AUDIT_REDACTED = "***REDACTED***";
|
|
3
|
+
var RULES = [
|
|
4
|
+
// `sk-…` family (Anthropic sk-ant-, omnicross sk-omnicross-, OpenAI sk-proj-/sk-).
|
|
5
|
+
{ re: /\bsk-[A-Za-z0-9_-]{6,}/g, replace: AUDIT_REDACTED },
|
|
6
|
+
// Google API keys.
|
|
7
|
+
{ re: /\bAIza[A-Za-z0-9_-]{10,}/g, replace: AUDIT_REDACTED },
|
|
8
|
+
// `Bearer <token>` (auth headers echoed into a body / SSE error).
|
|
9
|
+
{ re: /\bBearer\s+[A-Za-z0-9._~+/=-]{6,}/gi, replace: `Bearer ${AUDIT_REDACTED}` },
|
|
10
|
+
// Inline `x-api-key` / `api-key` / `authorization` label followed by a value.
|
|
11
|
+
{
|
|
12
|
+
re: /\b(x-api-key|api[_-]?key|authorization)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
|
|
13
|
+
replace: `$1$2${AUDIT_REDACTED}`
|
|
14
|
+
},
|
|
15
|
+
// `x-goog-api-key` header echoed inline.
|
|
16
|
+
{
|
|
17
|
+
re: /\b(x-goog-api-key)(["']?\s*[:=]\s*["']?)[A-Za-z0-9._~+/=-]{6,}/gi,
|
|
18
|
+
replace: `$1$2${AUDIT_REDACTED}`
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
function redactEncryptedContentValue(value) {
|
|
22
|
+
if (!value || typeof value !== "object") return false;
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
let changed2 = false;
|
|
25
|
+
for (const item of value) changed2 = redactEncryptedContentValue(item) || changed2;
|
|
26
|
+
return changed2;
|
|
27
|
+
}
|
|
28
|
+
let changed = false;
|
|
29
|
+
const record = value;
|
|
30
|
+
for (const [key, nested] of Object.entries(record)) {
|
|
31
|
+
if (key === "encrypted_content") {
|
|
32
|
+
record[key] = AUDIT_REDACTED;
|
|
33
|
+
changed = true;
|
|
34
|
+
} else {
|
|
35
|
+
changed = redactEncryptedContentValue(nested) || changed;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return changed;
|
|
39
|
+
}
|
|
40
|
+
function redactJsonValue(text) {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(text);
|
|
43
|
+
return redactEncryptedContentValue(parsed) ? JSON.stringify(parsed) : null;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function redactEncryptedContentSse(text) {
|
|
49
|
+
return text.replace(/^(\s*data:\s*)([^\r\n]*)(\r?)$/gm, (line, prefix, payload, cr) => {
|
|
50
|
+
if (!payload || payload.trim() === "[DONE]") return line;
|
|
51
|
+
const redacted = redactJsonValue(payload.trim());
|
|
52
|
+
return redacted === null ? line : `${prefix}${redacted}${cr}`;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function findJsonLikeValueEnd(text, start) {
|
|
56
|
+
const first = text[start];
|
|
57
|
+
if (first === '"' || first === "'") {
|
|
58
|
+
let escaped = false;
|
|
59
|
+
for (let index = start + 1; index < text.length; index += 1) {
|
|
60
|
+
const char = text[index];
|
|
61
|
+
if (escaped) escaped = false;
|
|
62
|
+
else if (char === "\\") escaped = true;
|
|
63
|
+
else if (char === first) return index + 1;
|
|
64
|
+
}
|
|
65
|
+
return text.length;
|
|
66
|
+
}
|
|
67
|
+
if (first === "{" || first === "[") {
|
|
68
|
+
const opening = first;
|
|
69
|
+
const closing = first === "{" ? "}" : "]";
|
|
70
|
+
let depth = 0;
|
|
71
|
+
let quote = "";
|
|
72
|
+
let escaped = false;
|
|
73
|
+
for (let index = start; index < text.length; index += 1) {
|
|
74
|
+
const char = text[index];
|
|
75
|
+
if (quote) {
|
|
76
|
+
if (escaped) escaped = false;
|
|
77
|
+
else if (char === "\\") escaped = true;
|
|
78
|
+
else if (char === quote) quote = "";
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (char === '"' || char === "'") quote = char;
|
|
82
|
+
else if (char === opening) depth += 1;
|
|
83
|
+
else if (char === closing && --depth === 0) return index + 1;
|
|
84
|
+
}
|
|
85
|
+
return text.length;
|
|
86
|
+
}
|
|
87
|
+
let end = start;
|
|
88
|
+
while (end < text.length && !/[\r\n,}\]]/.test(text[end])) end += 1;
|
|
89
|
+
return end;
|
|
90
|
+
}
|
|
91
|
+
function redactEncryptedContentText(text) {
|
|
92
|
+
const key = /["']encrypted_content["']\s*:\s*/g;
|
|
93
|
+
let output = "";
|
|
94
|
+
let cursor = 0;
|
|
95
|
+
for (; ; ) {
|
|
96
|
+
const match = key.exec(text);
|
|
97
|
+
if (!match) break;
|
|
98
|
+
const valueStart = match.index + match[0].length;
|
|
99
|
+
const valueEnd = findJsonLikeValueEnd(text, valueStart);
|
|
100
|
+
output += text.slice(cursor, valueStart) + JSON.stringify(AUDIT_REDACTED);
|
|
101
|
+
cursor = valueEnd;
|
|
102
|
+
key.lastIndex = valueEnd;
|
|
103
|
+
}
|
|
104
|
+
return cursor === 0 ? text : output + text.slice(cursor);
|
|
105
|
+
}
|
|
106
|
+
function redactEncryptedContent(text) {
|
|
107
|
+
const completeJson = redactJsonValue(text);
|
|
108
|
+
if (completeJson !== null) return completeJson;
|
|
109
|
+
return redactEncryptedContentText(redactEncryptedContentSse(text));
|
|
110
|
+
}
|
|
111
|
+
function redactAuditText(text) {
|
|
112
|
+
if (typeof text !== "string" || text.length === 0) return text ?? "";
|
|
113
|
+
let out = redactEncryptedContent(text);
|
|
114
|
+
for (const { re, replace } of RULES) {
|
|
115
|
+
out = out.replace(re, replace);
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export {
|
|
121
|
+
AUDIT_REDACTED,
|
|
122
|
+
redactAuditText
|
|
123
|
+
};
|