omnicell-router 0.7.0 → 0.8.2
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/backend/dist/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/base.d.ts +13 -2
- package/backend/dist/cli/clients/claude.d.ts +2 -2
- package/backend/dist/cli/clients/codex.d.ts +2 -2
- package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
- package/backend/dist/cli/clients/core-adapters.js +3 -4
- package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
- package/backend/dist/cli/clients/cursor-proxy.js +421 -0
- package/backend/dist/cli/clients/dsh.d.ts +2 -2
- package/backend/dist/cli/clients/grok.d.ts +2 -2
- package/backend/dist/cli/clients/index.d.ts +8 -1
- package/backend/dist/cli/clients/index.js +55 -21
- package/backend/dist/cli/clients/kimi.d.ts +2 -2
- package/backend/dist/cli/clients/launcher.d.ts +8 -0
- package/backend/dist/cli/clients/model-meta.js +1 -1
- package/backend/dist/cli/clients/omp.d.ts +2 -2
- package/backend/dist/cli/clients/openclaw.d.ts +2 -2
- package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
- package/backend/dist/cli/clients/opencode-proxy.js +351 -0
- package/backend/dist/cli/clients/opencode.d.ts +2 -2
- package/backend/dist/cli/clients/pi.d.ts +2 -2
- package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
- package/backend/dist/cli/clients/plugin-adapters.js +6 -29
- package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
- package/backend/dist/cli/clients/qoder-proxy.js +497 -0
- package/backend/dist/cli/clients/reserved.d.ts +2 -6
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
- package/backend/dist/cli/index.js +60 -9
- package/backend/dist/cli/types.d.ts +29 -8
- package/backend/dist/compression/caveman-prompts.d.ts +1 -1
- package/backend/dist/config/comments-en.js +6 -12
- package/backend/dist/config/comments-zh.js +6 -12
- package/backend/dist/config/defaults.d.ts +56 -1
- package/backend/dist/config/defaults.js +68 -0
- package/backend/dist/config/index.d.ts +9 -2
- package/backend/dist/config/index.js +26 -3
- package/backend/dist/config/types.d.ts +55 -43
- package/backend/dist/forward-proxy/egress.d.ts +10 -2
- package/backend/dist/forward-proxy/egress.js +42 -4
- package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/forward-proxy/ordered-relay.js +46 -0
- package/backend/dist/forward-proxy/rules.d.ts +66 -19
- package/backend/dist/forward-proxy/rules.js +61 -14
- package/backend/dist/forward-proxy/server.js +226 -77
- package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
- package/backend/dist/forward-proxy/system-proxy.js +199 -22
- package/backend/dist/harness/common/market.d.ts +3 -3
- package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
- package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
- package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
- package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
- package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
- package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
- package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
- package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
- package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
- package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
- package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
- package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
- package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
- package/backend/dist/harness/translation.js +64 -21
- package/backend/dist/harness/types.d.ts +1 -1
- package/backend/dist/harness/types.js +1 -1
- package/backend/dist/index.js +31 -18
- package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
- package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
- package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
- package/backend/dist/ir/adapters/anthropic.js +788 -0
- package/backend/dist/ir/adapters/chat.d.ts +15 -0
- package/backend/dist/ir/adapters/chat.js +602 -0
- package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
- package/backend/dist/ir/adapters/google-stream.js +242 -0
- package/backend/dist/ir/adapters/google.d.ts +9 -0
- package/backend/dist/ir/adapters/google.js +317 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
- package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
- package/backend/dist/ir/adapters/openai-responses.js +26 -1
- package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
- package/backend/dist/ir/adapters/responses-output.js +348 -0
- package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
- package/backend/dist/ir/adapters/responses-stream.js +178 -0
- package/backend/dist/ir/adapters/responses.d.ts +14 -0
- package/backend/dist/ir/adapters/responses.js +646 -0
- package/backend/dist/ir/errors.d.ts +2 -2
- package/backend/dist/ir/types.d.ts +2 -1
- package/backend/dist/metrics/request-cost.d.ts +11 -2
- package/backend/dist/metrics/request-cost.js +12 -3
- package/backend/dist/observability/request-identity.d.ts +1 -1
- package/backend/dist/observability/trace-id.d.ts +40 -0
- package/backend/dist/observability/trace-id.js +134 -0
- package/backend/dist/observability/upstream-events.d.ts +82 -60
- package/backend/dist/observability/upstream-events.js +142 -67
- package/backend/dist/opencode/catalog/types.d.ts +9 -0
- package/backend/dist/opencode/credentials/types.d.ts +2 -2
- package/backend/dist/opencode/probe.d.ts +24 -1
- package/backend/dist/opencode/probe.js +28 -4
- package/backend/dist/opencode/user-config.d.ts +5 -0
- package/backend/dist/pipeline/directives.d.ts +6 -2
- package/backend/dist/pipeline/directives.js +7 -3
- package/backend/dist/pipeline/orchestrator.d.ts +28 -27
- package/backend/dist/pipeline/orchestrator.js +220 -194
- package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
- package/backend/dist/pipeline/unresolved-model.js +43 -0
- package/backend/dist/plugins/catalog-def.d.ts +143 -0
- package/backend/dist/plugins/catalog-def.js +177 -0
- package/backend/dist/plugins/gateways.d.ts +62 -3
- package/backend/dist/plugins/gateways.js +139 -2
- package/backend/dist/plugins/host.d.ts +42 -5
- package/backend/dist/plugins/host.js +454 -38
- package/backend/dist/plugins/manifest.d.ts +119 -10
- package/backend/dist/plugins/manifest.js +265 -14
- package/backend/dist/plugins/pack.js +26 -0
- package/backend/dist/plugins/types.d.ts +187 -21
- package/backend/dist/protocols/systemone/convert.d.ts +1 -0
- package/backend/dist/protocols/systemone/convert.js +6 -1
- package/backend/dist/protocols/systemone/decide.js +18 -8
- package/backend/dist/providers/anthropic-messages.d.ts +12 -0
- package/backend/dist/providers/anthropic-messages.js +53 -0
- package/backend/dist/providers/anthropic.d.ts +7 -8
- package/backend/dist/providers/anthropic.js +36 -324
- package/backend/dist/providers/base.d.ts +14 -2
- package/backend/dist/providers/boot-direct.js +68 -38
- package/backend/dist/providers/dispatch.d.ts +5 -19
- package/backend/dist/providers/dispatch.js +46 -58
- package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
- package/backend/dist/providers/executors/anthropic-messages.js +3 -0
- package/backend/dist/providers/executors/dispatch.d.ts +16 -2
- package/backend/dist/providers/executors/dispatch.js +39 -9
- package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
- package/backend/dist/providers/executors/google-gemini.js +3 -0
- package/backend/dist/providers/executors/http-stream.js +16 -3
- package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
- package/backend/dist/providers/executors/openai-chat.js +3 -0
- package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
- package/backend/dist/providers/executors/openai-responses.js +3 -0
- package/backend/dist/providers/executors/plugin-adapter.js +4 -4
- package/backend/dist/providers/google-gemini.d.ts +12 -0
- package/backend/dist/providers/google-gemini.js +50 -0
- package/backend/dist/providers/google.d.ts +7 -8
- package/backend/dist/providers/google.js +35 -308
- package/backend/dist/providers/http-json.d.ts +19 -0
- package/backend/dist/providers/http-json.js +104 -0
- package/backend/dist/providers/http-stream.d.ts +52 -0
- package/backend/dist/providers/http-stream.js +423 -0
- package/backend/dist/providers/member-match.d.ts +4 -5
- package/backend/dist/providers/member-match.js +4 -5
- package/backend/dist/providers/openai-chat.d.ts +13 -0
- package/backend/dist/providers/openai-chat.js +99 -0
- package/backend/dist/providers/openai-compatible.d.ts +7 -4
- package/backend/dist/providers/openai-compatible.js +71 -368
- package/backend/dist/providers/openai-responses.d.ts +12 -0
- package/backend/dist/providers/openai-responses.js +68 -0
- package/backend/dist/providers/opencode-proxy.d.ts +5 -5
- package/backend/dist/providers/opencode-proxy.js +49 -125
- package/backend/dist/providers/plugin-adapter.d.ts +9 -0
- package/backend/dist/providers/plugin-adapter.js +31 -0
- package/backend/dist/providers/registry.d.ts +49 -24
- package/backend/dist/providers/registry.js +97 -55
- package/backend/dist/providers/responses.d.ts +7 -28
- package/backend/dist/providers/responses.js +45 -253
- package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
- package/backend/dist/providers/tool-markup-leak.js +57 -0
- package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
- package/backend/dist/providers/tool-markup-recovery.js +786 -0
- package/backend/dist/providers/virtual-meta.d.ts +21 -2
- package/backend/dist/providers/virtual-meta.js +49 -9
- package/backend/dist/proxy/asset-download.d.ts +54 -0
- package/backend/dist/proxy/asset-download.js +420 -0
- package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
- package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
- package/backend/dist/proxy/mihomo-binary.js +62 -51
- package/backend/dist/proxy/mihomo-client.js +15 -1
- package/backend/dist/proxy/mihomo-config.js +11 -2
- package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/proxy/mihomo-geo.js +213 -0
- package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
- package/backend/dist/proxy/mihomo-logs.js +70 -0
- package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
- package/backend/dist/proxy/mihomo-pac.js +15 -0
- package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
- package/backend/dist/proxy/mihomo-rules-import.js +7 -7
- package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
- package/backend/dist/proxy/mihomo-sidecar.js +148 -26
- package/backend/dist/quota/adapters/minimax.js +36 -13
- package/backend/dist/quota/cli-login.d.ts +8 -0
- package/backend/dist/quota/cli-login.js +18 -0
- package/backend/dist/quota/declarations.js +10 -0
- package/backend/dist/quota/dsl.js +18 -5
- package/backend/dist/quota/engine.d.ts +22 -1
- package/backend/dist/quota/engine.js +170 -29
- package/backend/dist/quota/prober.d.ts +5 -0
- package/backend/dist/quota/prober.js +11 -2
- package/backend/dist/quota/types.d.ts +87 -8
- package/backend/dist/quota/verdict.d.ts +35 -0
- package/backend/dist/quota/verdict.js +135 -0
- package/backend/dist/ratelimit/admission.d.ts +131 -0
- package/backend/dist/ratelimit/admission.js +233 -0
- package/backend/dist/ratelimit/rate-limiter.js +6 -0
- package/backend/dist/resilience/types.d.ts +2 -2
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +5 -8
- package/backend/dist/routes/console.js +248 -52
- package/backend/dist/routes/mihomo.d.ts +2 -0
- package/backend/dist/routes/mihomo.js +334 -29
- package/backend/dist/routes/responses.d.ts +87 -8
- package/backend/dist/routes/responses.js +314 -33
- package/backend/dist/server.js +34 -6
- package/backend/dist/session/session-manager.d.ts +6 -0
- package/backend/dist/session/session-manager.js +20 -9
- package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
- package/backend/dist/surfaces/chat-pipeline.js +17 -7
- package/backend/dist/surfaces/chat.js +15 -0
- package/backend/dist/surfaces/decision-pipeline.js +7 -10
- package/backend/dist/surfaces/direct-forward.d.ts +3 -0
- package/backend/dist/surfaces/direct-forward.js +206 -0
- package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
- package/backend/dist/surfaces/rate-limit-response.js +57 -0
- package/backend/dist/surfaces/types.d.ts +11 -0
- package/backend/dist/trace/tracker.d.ts +32 -1
- package/backend/dist/trace/tracker.js +29 -4
- package/backend/dist/types/router.d.ts +34 -12
- package/backend/dist/types/router.js +35 -6
- package/backend/dist/utils/chat-stream.d.ts +21 -8
- package/backend/dist/utils/chat-stream.js +46 -9
- package/backend/dist/utils/event-ring.d.ts +4 -0
- package/backend/dist/utils/event-ring.js +4 -0
- package/backend/dist/utils/popularity.js +29 -4
- package/backend/dist/utils/proxy.d.ts +7 -0
- package/backend/dist/utils/proxy.js +35 -10
- package/backend/dist/utils/retry-after.d.ts +21 -0
- package/backend/dist/utils/retry-after.js +36 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
- package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
|
@@ -1,83 +1,71 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OpenAIChatProvider } from './openai-chat.js';
|
|
2
2
|
import { getModelServicePlugin } from '../plugins/host.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Anthropic Messages for claude-*) — and even different MOUNTS per wire
|
|
10
|
-
* (Zen: /zen/v1 vs /inference/anthropic/v1). Dispatch is driven purely by
|
|
11
|
-
* `ModelRegistration.wire`, resolved at boot through the shared wireFor()/
|
|
12
|
-
* baseForWire() that the console probe also uses — test ≡ inference by structure.
|
|
13
|
-
*/
|
|
3
|
+
import { OpenAIResponsesProvider } from './openai-responses.js';
|
|
4
|
+
import { AnthropicMessagesProvider } from './anthropic-messages.js';
|
|
5
|
+
import { GoogleGeminiProvider } from './google-gemini.js';
|
|
6
|
+
import { createPluginProvider } from './plugin-adapter.js';
|
|
7
|
+
import { isPluginWire } from './plugin-wires.js';
|
|
8
|
+
/** Resolve each model's physical wire to one canonical executor. */
|
|
14
9
|
export class DispatchingProvider {
|
|
15
10
|
name;
|
|
16
11
|
execs = new Map();
|
|
17
12
|
constructor(config, wireBases) {
|
|
18
13
|
this.name = config.name;
|
|
19
|
-
for (const [
|
|
20
|
-
if (
|
|
14
|
+
for (const [wire, baseUrl] of Object.entries(wireBases)) {
|
|
15
|
+
if (wire === 'unroutable' || wire === 'systemone')
|
|
21
16
|
continue;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
//
|
|
37
|
-
|
|
17
|
+
const wireConfig = {
|
|
18
|
+
...config,
|
|
19
|
+
type: wire,
|
|
20
|
+
baseUrl,
|
|
21
|
+
};
|
|
22
|
+
if (wire === 'anthropic-messages')
|
|
23
|
+
this.execs.set(wire, new AnthropicMessagesProvider(wireConfig));
|
|
24
|
+
else if (wire === 'google-gemini')
|
|
25
|
+
this.execs.set(wire, new GoogleGeminiProvider(wireConfig));
|
|
26
|
+
else if (wire === 'openai-responses')
|
|
27
|
+
this.execs.set(wire, new OpenAIResponsesProvider(wireConfig));
|
|
28
|
+
else if (wire === 'openai-chat')
|
|
29
|
+
this.execs.set(wire, new OpenAIChatProvider(wireConfig));
|
|
30
|
+
else {
|
|
31
|
+
// Plugin-owned wires are resolved through the host registry, never
|
|
32
|
+
// through a name list here (a new plugin protocol needs no core edit).
|
|
33
|
+
const plugin = getModelServicePlugin(wire);
|
|
38
34
|
if (plugin)
|
|
39
|
-
this.execs.set(
|
|
35
|
+
this.execs.set(wire, createPluginProvider(plugin, wireConfig));
|
|
36
|
+
else if (!isPluginWire(wire))
|
|
37
|
+
this.execs.set(wire, new OpenAIChatProvider(wireConfig));
|
|
38
|
+
// A plugin wire with no installed executor stays UNSET on purpose:
|
|
39
|
+
// exec() then fails by wire id instead of routing the request to a
|
|
40
|
+
// chat executor that would only produce an upstream 400.
|
|
40
41
|
}
|
|
41
|
-
else
|
|
42
|
-
this.execs.set(w, new OpenAICompatibleProvider(wireCfg));
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
exec(model) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
49
|
-
throw new Error(
|
|
50
|
-
|
|
51
|
-
return exec;
|
|
45
|
+
const wire = model.wire ?? 'openai-chat';
|
|
46
|
+
const executor = this.execs.get(wire);
|
|
47
|
+
if (!executor)
|
|
48
|
+
throw new Error(`Model '${model.id}' wire '${wire}' is not registered in the direct pool`);
|
|
49
|
+
return executor;
|
|
52
50
|
}
|
|
53
|
-
|
|
51
|
+
createCompletion(request, model, upstreamEventContext, credential) {
|
|
54
52
|
return this.exec(model).createCompletion(request, model, upstreamEventContext, credential);
|
|
55
53
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Streaming capability: only executors with a native streaming reader are
|
|
58
|
-
* admitted to the streamed relay path — the OpenAI `chat/completions` SSE
|
|
59
|
-
* reader and the Qoder gRPC server-streaming bridge. Anthropic /
|
|
60
|
-
* Google / Responses executors still return a buffered JSON document, so
|
|
61
|
-
* their models keep the buffered path and the fake-stream re-chunker.
|
|
62
|
-
*/
|
|
63
54
|
supportsStreaming(model) {
|
|
64
|
-
const w = model.wire ?? 'openai';
|
|
65
|
-
if (w !== 'openai' && w !== 'qoder' && w !== 'workbuddy')
|
|
66
|
-
return false;
|
|
67
55
|
try {
|
|
68
|
-
|
|
56
|
+
const executor = this.exec(model);
|
|
57
|
+
return executor.supportsStreaming
|
|
58
|
+
? executor.supportsStreaming(model)
|
|
59
|
+
: typeof executor.createStream === 'function';
|
|
69
60
|
}
|
|
70
61
|
catch {
|
|
71
|
-
// Unroutable wire (exec throws): report "cannot stream" and let the pool
|
|
72
|
-
// surface the real routing error — a capability probe must not mask it.
|
|
73
62
|
return false;
|
|
74
63
|
}
|
|
75
64
|
}
|
|
76
65
|
async createStream(request, model, upstreamEventContext, credential) {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
throw new Error(`Wire '${model.wire ?? 'openai'}' has no native streaming executor`);
|
|
80
|
-
|
|
81
|
-
return exec.createStream(request, model, upstreamEventContext, credential);
|
|
66
|
+
const executor = this.exec(model);
|
|
67
|
+
if (!executor.createStream)
|
|
68
|
+
throw new Error(`Wire '${model.wire ?? 'openai-chat'}' has no native streaming executor`);
|
|
69
|
+
return executor.createStream(request, model, upstreamEventContext, credential);
|
|
82
70
|
}
|
|
83
71
|
}
|
|
@@ -6,6 +6,7 @@ export declare class AnthropicMessagesProvider implements LLMProvider {
|
|
|
6
6
|
name: string;
|
|
7
7
|
private config;
|
|
8
8
|
constructor(config: ProviderConfig);
|
|
9
|
+
dialBaseFor(): string;
|
|
9
10
|
private headers;
|
|
10
11
|
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
11
12
|
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
@@ -6,9 +6,23 @@ import { WireKind } from '../wire.js';
|
|
|
6
6
|
export declare class DispatchingProvider implements LLMProvider {
|
|
7
7
|
name: string;
|
|
8
8
|
private execs;
|
|
9
|
+
/**
|
|
10
|
+
* Wires whose executor is CORE (the four built-in transports + the
|
|
11
|
+
* openai-chat fallback for unknown non-plugin types) and therefore honors
|
|
12
|
+
* `config.proxy` through `proxiedFetch`. Plugin wires own their egress and
|
|
13
|
+
* stay OUT of this set — `dialBaseFor` answers only for the core ones, so
|
|
14
|
+
* the trace never claims an egress the plugin may not have taken.
|
|
15
|
+
*/
|
|
16
|
+
private coreWires;
|
|
17
|
+
private wireBases;
|
|
9
18
|
constructor(config: ProviderConfig, wireBases: Partial<Record<WireKind, string>>);
|
|
19
|
+
/**
|
|
20
|
+
* The per-wire base this dispatch dials for `model` — only for core wires.
|
|
21
|
+
* `undefined` = plugin-owned (or unset) transport: egress unknown.
|
|
22
|
+
*/
|
|
23
|
+
dialBaseFor(model: ModelRegistration): string | undefined;
|
|
10
24
|
private exec;
|
|
11
|
-
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
25
|
+
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential, sessionId?: string): Promise<CanonicalResponse>;
|
|
12
26
|
supportsStreaming(model: ModelRegistration): boolean;
|
|
13
|
-
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
27
|
+
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential, sessionId?: string): Promise<AsyncIterable<StreamEvent>>;
|
|
14
28
|
}
|
|
@@ -9,8 +9,18 @@ import { isPluginWire } from '../plugin-wires.js';
|
|
|
9
9
|
export class DispatchingProvider {
|
|
10
10
|
name;
|
|
11
11
|
execs = new Map();
|
|
12
|
+
/**
|
|
13
|
+
* Wires whose executor is CORE (the four built-in transports + the
|
|
14
|
+
* openai-chat fallback for unknown non-plugin types) and therefore honors
|
|
15
|
+
* `config.proxy` through `proxiedFetch`. Plugin wires own their egress and
|
|
16
|
+
* stay OUT of this set — `dialBaseFor` answers only for the core ones, so
|
|
17
|
+
* the trace never claims an egress the plugin may not have taken.
|
|
18
|
+
*/
|
|
19
|
+
coreWires = new Set();
|
|
20
|
+
wireBases;
|
|
12
21
|
constructor(config, wireBases) {
|
|
13
22
|
this.name = config.name;
|
|
23
|
+
this.wireBases = wireBases;
|
|
14
24
|
for (const [wire, baseUrl] of Object.entries(wireBases)) {
|
|
15
25
|
if (wire === 'unroutable' || wire === 'systemone')
|
|
16
26
|
continue;
|
|
@@ -19,28 +29,48 @@ export class DispatchingProvider {
|
|
|
19
29
|
type: wire,
|
|
20
30
|
baseUrl,
|
|
21
31
|
};
|
|
22
|
-
if (wire === 'anthropic-messages')
|
|
32
|
+
if (wire === 'anthropic-messages') {
|
|
23
33
|
this.execs.set(wire, new AnthropicMessagesProvider(wireConfig));
|
|
24
|
-
|
|
34
|
+
this.coreWires.add(wire);
|
|
35
|
+
}
|
|
36
|
+
else if (wire === 'google-gemini') {
|
|
25
37
|
this.execs.set(wire, new GoogleGeminiProvider(wireConfig));
|
|
26
|
-
|
|
38
|
+
this.coreWires.add(wire);
|
|
39
|
+
}
|
|
40
|
+
else if (wire === 'openai-responses') {
|
|
27
41
|
this.execs.set(wire, new OpenAIResponsesProvider(wireConfig));
|
|
28
|
-
|
|
42
|
+
this.coreWires.add(wire);
|
|
43
|
+
}
|
|
44
|
+
else if (wire === 'openai-chat') {
|
|
29
45
|
this.execs.set(wire, new OpenAIChatProvider(wireConfig));
|
|
46
|
+
this.coreWires.add(wire);
|
|
47
|
+
}
|
|
30
48
|
else {
|
|
31
49
|
// Plugin-owned wires are resolved through the host registry, never
|
|
32
50
|
// through a name list here (a new plugin protocol needs no core edit).
|
|
33
51
|
const plugin = getModelServicePlugin(wire);
|
|
34
52
|
if (plugin)
|
|
35
53
|
this.execs.set(wire, createPluginProvider(plugin, wireConfig));
|
|
36
|
-
else if (!isPluginWire(wire))
|
|
54
|
+
else if (!isPluginWire(wire)) {
|
|
37
55
|
this.execs.set(wire, new OpenAIChatProvider(wireConfig));
|
|
56
|
+
this.coreWires.add(wire);
|
|
57
|
+
}
|
|
38
58
|
// A plugin wire with no installed executor stays UNSET on purpose:
|
|
39
59
|
// exec() then fails by wire id instead of routing the request to a
|
|
40
60
|
// chat executor that would only produce an upstream 400.
|
|
41
61
|
}
|
|
42
62
|
}
|
|
43
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* The per-wire base this dispatch dials for `model` — only for core wires.
|
|
66
|
+
* `undefined` = plugin-owned (or unset) transport: egress unknown.
|
|
67
|
+
*/
|
|
68
|
+
dialBaseFor(model) {
|
|
69
|
+
const wire = model.wire ?? 'openai-chat';
|
|
70
|
+
if (!this.coreWires.has(wire))
|
|
71
|
+
return undefined;
|
|
72
|
+
return this.wireBases[wire];
|
|
73
|
+
}
|
|
44
74
|
exec(model) {
|
|
45
75
|
const wire = model.wire ?? 'openai-chat';
|
|
46
76
|
const executor = this.execs.get(wire);
|
|
@@ -48,8 +78,8 @@ export class DispatchingProvider {
|
|
|
48
78
|
throw new Error(`Model '${model.id}' wire '${wire}' is not registered in the direct pool`);
|
|
49
79
|
return executor;
|
|
50
80
|
}
|
|
51
|
-
createCompletion(request, model, upstreamEventContext, credential) {
|
|
52
|
-
return this.exec(model).createCompletion(request, model, upstreamEventContext, credential);
|
|
81
|
+
createCompletion(request, model, upstreamEventContext, credential, sessionId) {
|
|
82
|
+
return this.exec(model).createCompletion(request, model, upstreamEventContext, credential, sessionId);
|
|
53
83
|
}
|
|
54
84
|
supportsStreaming(model) {
|
|
55
85
|
try {
|
|
@@ -62,10 +92,10 @@ export class DispatchingProvider {
|
|
|
62
92
|
return false;
|
|
63
93
|
}
|
|
64
94
|
}
|
|
65
|
-
async createStream(request, model, upstreamEventContext, credential) {
|
|
95
|
+
async createStream(request, model, upstreamEventContext, credential, sessionId) {
|
|
66
96
|
const executor = this.exec(model);
|
|
67
97
|
if (!executor.createStream)
|
|
68
98
|
throw new Error(`Wire '${model.wire ?? 'openai-chat'}' has no native streaming executor`);
|
|
69
|
-
return executor.createStream(request, model, upstreamEventContext, credential);
|
|
99
|
+
return executor.createStream(request, model, upstreamEventContext, credential, sessionId);
|
|
70
100
|
}
|
|
71
101
|
}
|
|
@@ -6,6 +6,7 @@ export declare class GoogleGeminiProvider implements LLMProvider {
|
|
|
6
6
|
name: string;
|
|
7
7
|
private config;
|
|
8
8
|
constructor(config: ProviderConfig);
|
|
9
|
+
dialBaseFor(): string;
|
|
9
10
|
private headers;
|
|
10
11
|
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
11
12
|
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
@@ -224,6 +224,18 @@ export async function postProviderStream(options) {
|
|
|
224
224
|
try {
|
|
225
225
|
return await Promise.race([pending, deadline]);
|
|
226
226
|
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
// `controller.abort()` above settles the pending read SYNCHRONOUSLY, so the
|
|
229
|
+
// abort rejection can win this race against `deadline`'s own reject — the
|
|
230
|
+
// caller then sees "The operation was aborted." instead of the idle
|
|
231
|
+
// diagnostic. Re-label here, at the one place that knows an idle deadline
|
|
232
|
+
// fired, so EVERY caller (head wait, SSE loop, non-2xx error body) reports
|
|
233
|
+
// the real cause. `cause` keeps the transport error. Non-idle failures
|
|
234
|
+
// (a genuine upstream abort) propagate untouched.
|
|
235
|
+
if (idleTripped)
|
|
236
|
+
throw new Error(idleMessage(), { cause: err });
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
227
239
|
finally {
|
|
228
240
|
clearTimeout(timer);
|
|
229
241
|
}
|
|
@@ -435,9 +447,10 @@ export async function postProviderStream(options) {
|
|
|
435
447
|
throw new Error(message, { cause: err });
|
|
436
448
|
}
|
|
437
449
|
if (idleTripped) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
450
|
+
// `raceIdle` already re-labelled this as the idle message (it is the
|
|
451
|
+
// only place that knows an idle deadline fired); just record it.
|
|
452
|
+
capture(idleMessage());
|
|
453
|
+
throw err;
|
|
441
454
|
}
|
|
442
455
|
if (totalTripped) {
|
|
443
456
|
const message = `Upstream ${provider} stream exceeded the total timeout of ${options.timeoutMs}ms — aborted`;
|
|
@@ -5,6 +5,7 @@ export declare class OpenAIChatProvider implements LLMProvider {
|
|
|
5
5
|
name: string;
|
|
6
6
|
private config;
|
|
7
7
|
constructor(config: ProviderConfig);
|
|
8
|
+
dialBaseFor(): string;
|
|
8
9
|
private headers;
|
|
9
10
|
/** One explicit, adapter-owned whitelist feeds both buffered and streaming calls. */
|
|
10
11
|
private payload;
|
|
@@ -6,6 +6,7 @@ export declare class OpenAIResponsesProvider implements LLMProvider {
|
|
|
6
6
|
name: string;
|
|
7
7
|
private config;
|
|
8
8
|
constructor(config: ProviderConfig);
|
|
9
|
+
dialBaseFor(): string;
|
|
9
10
|
private headers;
|
|
10
11
|
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
11
12
|
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
@@ -10,14 +10,14 @@ export function createPluginProvider(plugin, config) {
|
|
|
10
10
|
return {
|
|
11
11
|
name: provider.name,
|
|
12
12
|
supportsStreaming: () => typeof provider.createStream === 'function',
|
|
13
|
-
async createCompletion(request, model, upstreamEventContext, credential) {
|
|
14
|
-
const response = await provider.createCompletion(irToChatRequest(request, model.upstreamModel, { carrierExtensions: false }), model, upstreamEventContext, credential);
|
|
13
|
+
async createCompletion(request, model, upstreamEventContext, credential, sessionId) {
|
|
14
|
+
const response = await provider.createCompletion(irToChatRequest(request, model.upstreamModel, { carrierExtensions: false }), model, upstreamEventContext, credential, sessionId);
|
|
15
15
|
return chatResponseToIR(response);
|
|
16
16
|
},
|
|
17
|
-
async createStream(request, model, upstreamEventContext, credential) {
|
|
17
|
+
async createStream(request, model, upstreamEventContext, credential, sessionId) {
|
|
18
18
|
if (!provider.createStream)
|
|
19
19
|
throw new Error(`Plugin provider '${provider.name}' has no stream executor`);
|
|
20
|
-
const stream = await provider.createStream(irToChatRequest(request, model.upstreamModel, { carrierExtensions: false }), model, upstreamEventContext, credential);
|
|
20
|
+
const stream = await provider.createStream(irToChatRequest(request, model.upstreamModel, { carrierExtensions: false }), model, upstreamEventContext, credential, sessionId);
|
|
21
21
|
return {
|
|
22
22
|
async *[Symbol.asyncIterator]() {
|
|
23
23
|
const decoder = new ChatStreamDecoder();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LLMProvider, UpstreamEventContext, CallCredential } from './base.js';
|
|
2
|
+
import type { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
+
import type { CanonicalRequest, CanonicalResponse, StreamEvent } from '../ir/types.js';
|
|
4
|
+
/** Google Generative Language upstream. The provider speaks Canonical IR only. */
|
|
5
|
+
export declare class GoogleGeminiProvider implements LLMProvider {
|
|
6
|
+
name: string;
|
|
7
|
+
private config;
|
|
8
|
+
constructor(config: ProviderConfig);
|
|
9
|
+
private headers;
|
|
10
|
+
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
11
|
+
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { canonicalToGooglePayload, googleResponseToIR } from '../ir/adapters/google-gemini.js';
|
|
2
|
+
import { GoogleGeminiStreamDecoder } from '../ir/adapters/google-gemini-stream.js';
|
|
3
|
+
import { DEFAULT_PROVIDER_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_STREAM_TIMEOUT_MS, } from '../config/defaults.js';
|
|
4
|
+
import { postProviderJson, setDefaultHeaderCaseInsensitive, setHeaderCaseInsensitive } from './http-json.js';
|
|
5
|
+
import { postProviderStream } from './http-stream.js';
|
|
6
|
+
/** Google Generative Language upstream. The provider speaks Canonical IR only. */
|
|
7
|
+
export class GoogleGeminiProvider {
|
|
8
|
+
name;
|
|
9
|
+
config;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.name = config.name;
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
headers(credential) {
|
|
15
|
+
const headers = {
|
|
16
|
+
...this.config.headers,
|
|
17
|
+
};
|
|
18
|
+
setDefaultHeaderCaseInsensitive(headers, 'Content-Type', 'application/json');
|
|
19
|
+
setHeaderCaseInsensitive(headers, 'x-goog-api-key', credential?.key ?? this.config.apiKey);
|
|
20
|
+
return headers;
|
|
21
|
+
}
|
|
22
|
+
async createCompletion(request, model, upstreamEventContext, credential) {
|
|
23
|
+
const data = await postProviderJson({
|
|
24
|
+
url: `${this.config.baseUrl.replace(/\/+$/, '')}/models/${encodeURIComponent(model.upstreamModel)}:generateContent`,
|
|
25
|
+
headers: this.headers(credential),
|
|
26
|
+
payload: canonicalToGooglePayload(request, model),
|
|
27
|
+
model,
|
|
28
|
+
provider: this.name,
|
|
29
|
+
label: 'google',
|
|
30
|
+
timeoutMs: this.config.timeoutMs || DEFAULT_PROVIDER_TIMEOUT_MS,
|
|
31
|
+
upstreamEventContext,
|
|
32
|
+
});
|
|
33
|
+
return googleResponseToIR(data);
|
|
34
|
+
}
|
|
35
|
+
async createStream(request, model, upstreamEventContext, credential) {
|
|
36
|
+
return postProviderStream({
|
|
37
|
+
url: `${this.config.baseUrl.replace(/\/+$/, '')}/models/${encodeURIComponent(model.upstreamModel)}:streamGenerateContent?alt=sse`,
|
|
38
|
+
headers: this.headers(credential),
|
|
39
|
+
payload: canonicalToGooglePayload(request, model),
|
|
40
|
+
model,
|
|
41
|
+
provider: this.name,
|
|
42
|
+
label: 'google',
|
|
43
|
+
timeoutMs: this.config.streamTimeoutMs || DEFAULT_STREAM_TIMEOUT_MS,
|
|
44
|
+
idleTimeoutMs: this.config.streamIdleTimeoutMs || DEFAULT_STREAM_IDLE_TIMEOUT_MS,
|
|
45
|
+
upstreamEventContext,
|
|
46
|
+
createDecoder: () => new GoogleGeminiStreamDecoder(),
|
|
47
|
+
parseBuffered: (body) => googleResponseToIR(body),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { LLMProvider,
|
|
2
|
-
import { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
export declare function buildGooglePayload(request: ChatCompletionRequest, model: ModelRegistration): Record<string, any>;
|
|
6
|
-
/** Pure response mapper: Gemini generateContent payload → chat-completions response. */
|
|
7
|
-
export declare function googleToChatCompletion(data: any, model: ModelRegistration): ChatCompletionResponse;
|
|
1
|
+
import type { LLMProvider, UpstreamEventContext, CallCredential } from './base.js';
|
|
2
|
+
import type { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
+
import type { CanonicalRequest, CanonicalResponse, StreamEvent } from '../ir/types.js';
|
|
4
|
+
/** Google Generative Language upstream. The provider speaks Canonical IR only. */
|
|
8
5
|
export declare class GoogleProvider implements LLMProvider {
|
|
9
6
|
name: string;
|
|
10
7
|
private config;
|
|
11
8
|
constructor(config: ProviderConfig);
|
|
12
|
-
|
|
9
|
+
private headers;
|
|
10
|
+
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
11
|
+
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
13
12
|
}
|