@supersolutions/super-chat-router 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +52 -15
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,4 +10,4 @@ URLs or base64 PNG, JPEG, GIF and WebP. Files and audio are dropped with a warni
|
|
|
10
10
|
TypeScript server that supports it; the Go, Python and Rust data planes refuse these requests. For an older server,
|
|
11
11
|
set `toolCalling: false`.
|
|
12
12
|
|
|
13
|
-
See [docs/PACKAGES.md](
|
|
13
|
+
See [docs/PACKAGES.md](../../../docs/PACKAGES.md).
|
package/dist/index.js
CHANGED
|
@@ -45,14 +45,24 @@ function createSuperRouterGateway(config) {
|
|
|
45
45
|
let requestId;
|
|
46
46
|
try {
|
|
47
47
|
const parsed = await response.json();
|
|
48
|
-
|
|
49
|
-
requestId = parsed.error
|
|
48
|
+
if (typeof parsed.error?.code === "string") code = parsed.error.code;
|
|
49
|
+
if (typeof parsed.error?.request_id === "string") requestId = parsed.error.request_id;
|
|
50
50
|
} catch {
|
|
51
51
|
}
|
|
52
52
|
throw new GatewayError(code, response.status, requestId);
|
|
53
53
|
}
|
|
54
54
|
return response;
|
|
55
55
|
}
|
|
56
|
+
const jsonOf = async (response) => {
|
|
57
|
+
let parsed;
|
|
58
|
+
try {
|
|
59
|
+
parsed = await response.json();
|
|
60
|
+
} catch {
|
|
61
|
+
throw new GatewayError("bad_response", response.status);
|
|
62
|
+
}
|
|
63
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new GatewayError("bad_response", response.status);
|
|
64
|
+
return parsed;
|
|
65
|
+
};
|
|
56
66
|
const requestIdFrom = (response) => (response.headers.get("location") ?? "").split("/").pop() ?? "";
|
|
57
67
|
return {
|
|
58
68
|
async infer(request, idempotencyKey) {
|
|
@@ -60,9 +70,9 @@ function createSuperRouterGateway(config) {
|
|
|
60
70
|
if (response.status >= 300 && response.status < 400) {
|
|
61
71
|
const id = requestIdFrom(response);
|
|
62
72
|
if (!id) throw new GatewayError("bad_redirect", response.status);
|
|
63
|
-
return
|
|
73
|
+
return jsonOf(await send("/v1/requests/" + encodeURIComponent(id), { method: "GET" }));
|
|
64
74
|
}
|
|
65
|
-
return
|
|
75
|
+
return jsonOf(response);
|
|
66
76
|
},
|
|
67
77
|
async *stream(request, idempotencyKey, signal) {
|
|
68
78
|
const response = await send("/v1/inferences", { method: "POST", body: body(request, true), ...signal ? { signal } : {} }, idempotencyKey);
|
|
@@ -72,7 +82,14 @@ function createSuperRouterGateway(config) {
|
|
|
72
82
|
}
|
|
73
83
|
if (!response.body) throw new GatewayError("empty_stream");
|
|
74
84
|
for await (const frame of parseSSE(response.body)) {
|
|
75
|
-
|
|
85
|
+
let data;
|
|
86
|
+
try {
|
|
87
|
+
data = JSON.parse(frame.data);
|
|
88
|
+
} catch {
|
|
89
|
+
throw new GatewayError("bad_response", response.status);
|
|
90
|
+
}
|
|
91
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) throw new GatewayError("bad_response", response.status);
|
|
92
|
+
yield { type: frame.event, ...data };
|
|
76
93
|
}
|
|
77
94
|
}
|
|
78
95
|
};
|
|
@@ -167,10 +184,17 @@ function toTools(req) {
|
|
|
167
184
|
return tools.some((t) => t.name === choice.name) ? { tools, tool_choice: { name: choice.name } } : { tools };
|
|
168
185
|
}
|
|
169
186
|
var finishOf = (reason, hasCalls) => reason === "length" ? "length" : reason === "tool_calls" || hasCalls ? "tool-calls" : "stop";
|
|
187
|
+
function outputTokens(wanted) {
|
|
188
|
+
const n = typeof wanted === "number" && Number.isFinite(wanted) ? Math.floor(wanted) : 1024;
|
|
189
|
+
return Math.min(8192, Math.max(1, n));
|
|
190
|
+
}
|
|
191
|
+
var count = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : 0;
|
|
170
192
|
function toUsage(u) {
|
|
171
|
-
if (
|
|
172
|
-
const
|
|
173
|
-
|
|
193
|
+
if (typeof u !== "object" || u === null) return {};
|
|
194
|
+
const cached = count(u.cached);
|
|
195
|
+
const inputTokens = count(u.input) + cached + count(u.cache_write);
|
|
196
|
+
const outputTokens2 = count(u.output);
|
|
197
|
+
return { inputTokens, outputTokens: outputTokens2, totalTokens: inputTokens + outputTokens2, ...cached ? { cachedInputTokens: cached } : {} };
|
|
174
198
|
}
|
|
175
199
|
function toError(error, provider) {
|
|
176
200
|
if (error instanceof AgentError) return error;
|
|
@@ -193,7 +217,7 @@ function createSuperRouterProvider(config) {
|
|
|
193
217
|
customer_id: config.customerId,
|
|
194
218
|
messages,
|
|
195
219
|
...toolCalling ? toTools(req) : {},
|
|
196
|
-
max_output_tokens:
|
|
220
|
+
max_output_tokens: outputTokens(req.maxOutputTokens ?? config.defaultMaxOutputTokens)
|
|
197
221
|
};
|
|
198
222
|
return { request, warnings };
|
|
199
223
|
};
|
|
@@ -220,13 +244,20 @@ function createSuperRouterProvider(config) {
|
|
|
220
244
|
try {
|
|
221
245
|
const result = await config.gateway.infer(request, newKey());
|
|
222
246
|
const failed = result.execution_status !== "succeeded";
|
|
247
|
+
if (typeof result.output === "string" || typeof result.output === "number" || typeof result.output === "boolean") {
|
|
248
|
+
throw new AgentError("unknown", "Super Router sent a reply whose output is not an object.", { provider: id });
|
|
249
|
+
}
|
|
223
250
|
if (!result.output) {
|
|
224
251
|
throw new AgentError("invalid-request", `This idempotency key was already used (request ${result.id}); the router does not store output, so it cannot be replayed.`, { provider: id });
|
|
225
252
|
}
|
|
226
|
-
const
|
|
253
|
+
const content = typeof result.output.content === "string" ? result.output.content : "";
|
|
254
|
+
const calls = Array.isArray(result.output.tool_calls) ? result.output.tool_calls : [];
|
|
227
255
|
const parts = [
|
|
228
|
-
...
|
|
256
|
+
...content || !calls.length ? [{ type: "text", text: content }] : [],
|
|
229
257
|
...calls.map((call) => {
|
|
258
|
+
if (typeof call?.id !== "string" || !call.id || typeof call.name !== "string" || !call.name) {
|
|
259
|
+
throw new AgentError("unknown", "Super Router sent a tool call without an id or name.", { provider: id });
|
|
260
|
+
}
|
|
230
261
|
const { value, repaired } = repairToolArguments(call.arguments);
|
|
231
262
|
return { type: "tool-call", callId: call.id, name: call.name, input: value, status: "pending", ...repaired ? { repaired } : {} };
|
|
232
263
|
})
|
|
@@ -234,7 +265,7 @@ function createSuperRouterProvider(config) {
|
|
|
234
265
|
return {
|
|
235
266
|
parts,
|
|
236
267
|
finishReason: failed ? "error" : finishOf(result.finish_reason, calls.length > 0),
|
|
237
|
-
usage: toUsage(result.usage
|
|
268
|
+
usage: toUsage(result.usage?.meters),
|
|
238
269
|
responseId: result.id,
|
|
239
270
|
modelId: req.model,
|
|
240
271
|
...warnings.length ? { warnings } : {}
|
|
@@ -248,15 +279,18 @@ function createSuperRouterProvider(config) {
|
|
|
248
279
|
let started = false;
|
|
249
280
|
const open = /* @__PURE__ */ new Map();
|
|
250
281
|
let completed = 0;
|
|
282
|
+
let finished = false;
|
|
251
283
|
try {
|
|
252
284
|
for await (const raw of config.gateway.stream(request, newKey(), opts?.signal)) {
|
|
285
|
+
if (raw === null || typeof raw !== "object") continue;
|
|
253
286
|
const event = raw;
|
|
254
287
|
if (!started) {
|
|
255
288
|
started = true;
|
|
256
289
|
yield { type: "start", responseId: event.request_id, modelId: req.model };
|
|
257
290
|
}
|
|
258
|
-
if (event.type === "output.delta")
|
|
259
|
-
|
|
291
|
+
if (event.type === "output.delta") {
|
|
292
|
+
if (typeof event.text === "string" && event.text) yield { type: "text-delta", delta: event.text };
|
|
293
|
+
} else if (event.type === "output.tool_call.delta") {
|
|
260
294
|
let call = open.get(event.index);
|
|
261
295
|
if (!call) {
|
|
262
296
|
if (!event.id || !event.name) throw new AgentError("unknown", "Super Router sent a tool call without an id or name.", { provider: id });
|
|
@@ -264,8 +298,9 @@ function createSuperRouterProvider(config) {
|
|
|
264
298
|
open.set(event.index, call);
|
|
265
299
|
yield { type: "tool-call-start", callId: call.id, name: call.name };
|
|
266
300
|
}
|
|
267
|
-
if (event.arguments_delta) yield { type: "tool-call-delta", callId: call.id, argsDelta: event.arguments_delta };
|
|
301
|
+
if (typeof event.arguments_delta === "string" && event.arguments_delta) yield { type: "tool-call-delta", callId: call.id, argsDelta: event.arguments_delta };
|
|
268
302
|
} else if (event.type === "output.tool_call.completed") {
|
|
303
|
+
if (!event.id || !event.name) throw new AgentError("unknown", "Super Router sent a tool call without an id or name.", { provider: id });
|
|
269
304
|
if (!open.has(event.index)) yield { type: "tool-call-start", callId: event.id, name: event.name };
|
|
270
305
|
const { value, repaired } = repairToolArguments(event.arguments);
|
|
271
306
|
completed += 1;
|
|
@@ -276,10 +311,12 @@ function createSuperRouterProvider(config) {
|
|
|
276
311
|
const ok = event.type === "request.completed" && event.execution_status === "succeeded";
|
|
277
312
|
const finishReason = ok ? finishOf(event.finish_reason, completed > 0) : event.finish_reason === "length" ? "length" : event.execution_status === "cancelled" ? "cancelled" : "error";
|
|
278
313
|
yield { type: "finish", finishReason, responseId: event.request_id, ...usage ? { usage } : {} };
|
|
314
|
+
finished = true;
|
|
279
315
|
} else if (event.type === "request.replayed") {
|
|
280
316
|
throw new AgentError("invalid-request", `This idempotency key was already used (request ${event.request_id}).`, { provider: id });
|
|
281
317
|
}
|
|
282
318
|
}
|
|
319
|
+
if (!finished) throw new AgentError("network", "The model's stream ended before it finished.", { provider: id });
|
|
283
320
|
} catch (error) {
|
|
284
321
|
yield { type: "error", error: (() => {
|
|
285
322
|
try {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/gateway.ts","../src/provider.ts"],"sourcesContent":["import {\n GatewayError,\n parseSSE,\n type InferenceGateway,\n type InferenceRequest,\n type InferenceResult,\n type StreamEvent,\n} from \"@supersolutions/super-protocol\";\n\nexport type SuperRouterGatewayConfig = {\n /** Origin of the Super Router server, e.g. \"https://router.example.com\". */\n baseUrl: string;\n /** A Super Router API key. Keep it server-side; the browser should use a proxy. */\n apiKey: string;\n fetch?: typeof fetch;\n};\n\nconst body = (request: InferenceRequest, stream: boolean) => {\n return JSON.stringify({\n service: request.service,\n ...(request.service_version ? { service_version: request.service_version } : {}),\n customer_id: request.customer_id,\n input: {\n messages: request.messages,\n ...(request.tools?.length ? { tools: request.tools } : {}),\n ...(request.tools?.length && request.tool_choice !== undefined ? { tool_choice: request.tool_choice } : {}),\n },\n limits: {\n max_output_tokens: request.max_output_tokens ?? 1024,\n ...(request.timeout_ms ? { timeout_ms: request.timeout_ms } : {}),\n },\n stream,\n });\n};\n\n/** An `InferenceGateway` over the Super Router HTTP API (`POST /v1/inferences`). */\nexport function createSuperRouterGateway(config: SuperRouterGatewayConfig): InferenceGateway {\n const base = config.baseUrl.replace(/\\/+$/, \"\");\n const doFetch = config.fetch ?? fetch;\n\n async function send(path: string, init: RequestInit, idempotencyKey?: string): Promise<Response> {\n let response: Response;\n try {\n response = await doFetch(base + path, {\n ...init,\n redirect: \"manual\",\n headers: {\n Authorization: `Bearer ${config.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...(idempotencyKey ? { \"Idempotency-Key\": idempotencyKey } : {}),\n },\n });\n } catch (error) {\n if ((error as { name?: string })?.name === \"AbortError\") throw error;\n throw new GatewayError(\"network_error\");\n }\n // A repeated idempotency key answers 303 with the original request's location.\n if (response.status === 303 || (response.status >= 300 && response.status < 400)) return response;\n if (!response.ok) {\n let code = \"http_error\";\n let requestId: string | undefined;\n try {\n const parsed = (await response.json()) as { error?: { code?: string; request_id?: string } };\n code = parsed.error?.code ?? code;\n requestId = parsed.error?.request_id;\n } catch {\n /* non-JSON error body */\n }\n throw new GatewayError(code, response.status, requestId);\n }\n return response;\n }\n\n const requestIdFrom = (response: Response) => (response.headers.get(\"location\") ?? \"\").split(\"/\").pop() ?? \"\";\n\n return {\n async infer(request, idempotencyKey) {\n const response = await send(\"/v1/inferences\", { method: \"POST\", body: body(request, false) }, idempotencyKey);\n if (response.status >= 300 && response.status < 400) {\n const id = requestIdFrom(response);\n if (!id) throw new GatewayError(\"bad_redirect\", response.status);\n return (await (await send(\"/v1/requests/\" + encodeURIComponent(id), { method: \"GET\" })).json()) as InferenceResult;\n }\n return (await response.json()) as InferenceResult;\n },\n\n async *stream(request, idempotencyKey, signal) {\n const response = await send(\"/v1/inferences\", { method: \"POST\", body: body(request, true), ...(signal ? { signal } : {}) }, idempotencyKey);\n if (response.status >= 300 && response.status < 400) {\n yield { type: \"request.replayed\", request_id: requestIdFrom(response), sequence: 0 } satisfies StreamEvent;\n return;\n }\n if (!response.body) throw new GatewayError(\"empty_stream\");\n for await (const frame of parseSSE(response.body)) {\n yield { type: frame.event, ...(JSON.parse(frame.data) as object) } as StreamEvent;\n }\n },\n };\n}\n","import {\n AgentError,\n type CallOptions,\n type ContentPart,\n type FinishReason,\n type GenerateResult,\n type Message,\n type NormalizedRequest,\n type Provider,\n repairToolArguments,\n type StreamEvent,\n type Transport,\n type Usage,\n} from \"@supersolutions/super-chat-core\";\nimport {\n GatewayError,\n type InferenceContentPart,\n type InferenceFinishReason,\n type InferenceGateway,\n type InferenceMessage,\n type InferenceRequest,\n type InferenceTool,\n type InferenceToolCall,\n type InferenceToolChoice,\n type StreamEvent as RouterStreamEvent,\n type Usage as RouterUsage,\n} from \"@supersolutions/super-protocol\";\n\nexport type SuperRouterProviderConfig = {\n gateway: InferenceGateway;\n /** The customer the usage is billed to. */\n customerId: string;\n id?: string;\n label?: string;\n /** Used when the request sets no `maxOutputTokens`. Super Router allows 1..8192. */\n defaultMaxOutputTokens?: number;\n /** One key per logical call; reuse it when retrying so the call never bills twice. */\n idempotencyKey?: () => string;\n /**\n * Send tools and images to the router. Default true. Turn it off for a server\n * that predates tool calling: tools are then left out with a warning.\n */\n toolCalling?: boolean;\n};\n\n// A gateway provider has no HTTP of its own: the gateway holds the credential and the wire.\nconst noTransport: Transport = {\n kind: \"custom\",\n credentialSafe: true,\n async fetch() {\n throw new AgentError(\"not-supported\", \"The Super Router provider does not use a Transport.\");\n },\n} as Transport;\n\nconst MAX_TOOL_RESULT_CHARS = 256_000;\nconst MAX_TOOL_DESCRIPTION_CHARS = 4096;\nconst IMAGE_MEDIA = /^image\\/(png|jpeg|gif|webp)$/;\n\n// Super Router accepts these characters in a call id; a thread may hold ids minted by another provider.\nconst wireCallId = (id: string) => id.replace(/[^a-zA-Z0-9_-]/g, \"_\").slice(0, 128) || \"call\";\n\nconst asText = (output: unknown) => (typeof output === \"string\" ? output : (JSON.stringify(output) ?? \"null\"));\n\nfunction resultText(output: unknown): string {\n const text = asText(output);\n const marker = \"…[truncated]\";\n return text.length > MAX_TOOL_RESULT_CHARS ? text.slice(0, MAX_TOOL_RESULT_CHARS - marker.length) + marker : text;\n}\n\n// The wire requires a JSON object; a repaired call can hold any JSON value.\nfunction argumentsText(input: unknown): string {\n const object = typeof input === \"object\" && input !== null && !Array.isArray(input);\n return JSON.stringify(object ? input : input === undefined || input === null ? {} : { input });\n}\n\nfunction imageUrl(part: Extract<ContentPart, { type: \"image\" }>): string | undefined {\n const { source, mediaType } = part;\n if (source.kind === \"url\") return source.url.startsWith(\"https://\") || /^data:image\\/(png|jpeg|gif|webp);base64,/.test(source.url) ? source.url : undefined;\n if (source.kind === \"base64\" && mediaType && IMAGE_MEDIA.test(mediaType)) return `data:${mediaType};base64,${source.data}`;\n return undefined;\n}\n\nfunction toMessages(req: NormalizedRequest, toolCalling: boolean): { messages: InferenceMessage[]; warnings: string[] } {\n const warnings: string[] = [];\n const messages: InferenceMessage[] = [];\n if (req.system) messages.push({ role: \"system\", content: req.system });\n const history = req.messages as Message[];\n // A call without a result, or a result without a call, is refused by the router: both happen in interrupted threads.\n const called = new Set(history.flatMap((m) => m.parts.flatMap((p) => (p.type === \"tool-call\" ? [p.callId] : []))));\n const answered = new Set(history.flatMap((m) => m.parts.flatMap((p) => (p.type === \"tool-result\" ? [p.callId] : []))));\n let dropped = 0;\n for (const m of history) {\n const texts: string[] = [];\n const images: InferenceContentPart[] = [];\n const calls: InferenceToolCall[] = [];\n const results: InferenceMessage[] = [];\n for (const p of m.parts) {\n if (p.type === \"text\") {\n if (p.text) texts.push(p.text);\n } else if (p.type === \"image\" && toolCalling) {\n const url = imageUrl(p);\n if (url) images.push({ type: \"image\", url, ...(p.detail ? { detail: p.detail } : {}) });\n else dropped += 1;\n } else if (p.type === \"tool-call\" && toolCalling) {\n if (answered.has(p.callId)) calls.push({ id: wireCallId(p.callId), name: p.name, arguments: argumentsText(p.input) });\n } else if (p.type === \"tool-result\" && toolCalling) {\n if (called.has(p.callId)) results.push({ role: \"tool\", tool_call_id: wireCallId(p.callId), content: resultText(p.output), ...(p.failure ? { is_error: true } : {}) });\n } else if (p.type !== \"reasoning\" && p.type !== \"artifact\") {\n dropped += 1;\n }\n }\n const text = texts.join(\"\\n\");\n if (m.role === \"tool\") messages.push(...results);\n else if (m.role === \"assistant\" && calls.length) messages.push({ role: \"assistant\", ...(text ? { content: text } : {}), tool_calls: calls });\n else if (m.role === \"user\" && images.length) messages.push({ role: \"user\", content: [...(text ? [{ type: \"text\" as const, text }] : []), ...images] });\n else if (text) messages.push({ role: m.role, content: text });\n if (m.role !== \"tool\") messages.push(...results);\n }\n if (dropped) warnings.push(`${dropped} part(s) were dropped: Super Router takes text, tool calls and https or base64 PNG, JPEG, GIF and WebP images.`);\n if (!toolCalling && req.tools?.length) warnings.push(\"Tools were ignored: tool calling is turned off for this provider.\");\n if (!messages.some((m) => m.role !== \"system\")) throw new AgentError(\"invalid-request\", \"Super Router needs at least one user or assistant message.\");\n return { messages, warnings };\n}\n\nfunction toTools(req: NormalizedRequest): { tools?: InferenceTool[]; tool_choice?: InferenceToolChoice } {\n const active = req.activeTools ? new Set(req.activeTools) : undefined;\n const tools = (req.tools ?? [])\n .filter((t) => !active || active.has(t.name))\n .map((t): InferenceTool => ({\n name: t.name,\n ...(t.description ? { description: t.description.slice(0, MAX_TOOL_DESCRIPTION_CHARS) } : {}),\n input_schema: { ...t.parameters, type: \"object\" },\n }));\n if (!tools.length) return {};\n const choice = req.toolChoice;\n if (!choice) return { tools };\n if (choice.type !== \"tool\") return { tools, tool_choice: choice.type };\n // Naming a tool that is not on offer this step would be refused; let the model choose instead.\n return tools.some((t) => t.name === choice.name) ? { tools, tool_choice: { name: choice.name } } : { tools };\n}\n\nconst finishOf = (reason: InferenceFinishReason | undefined, hasCalls: boolean): FinishReason =>\n reason === \"length\" ? \"length\" : reason === \"tool_calls\" || hasCalls ? \"tool-calls\" : \"stop\";\n\nfunction toUsage(u?: RouterUsage): Usage {\n if (!u) return {};\n const inputTokens = u.input + u.cached + u.cache_write;\n return { inputTokens, outputTokens: u.output, totalTokens: inputTokens + u.output, ...(u.cached ? { cachedInputTokens: u.cached } : {}) };\n}\n\nfunction toError(error: unknown, provider: string): AgentError {\n if (error instanceof AgentError) return error;\n if ((error as { name?: string })?.name === \"AbortError\") return new AgentError(\"cancelled\", \"Cancelled.\", { provider, cause: error });\n if (error instanceof GatewayError) {\n const status = error.status;\n const kind = error.code === \"network_error\" ? \"network\"\n : status === 401 || status === 403 ? \"auth\"\n : status === 402 ? \"invalid-request\"\n : status === 429 ? \"rate-limit\"\n : status !== undefined && status >= 500 ? \"overloaded\"\n : status !== undefined && status >= 400 ? \"invalid-request\"\n : \"unknown\";\n return new AgentError(kind, error.requestId ? `${error.code} (request ${error.requestId})` : error.code, { ...(status ? { status } : {}), provider, cause: error });\n }\n return new AgentError(\"unknown\", error instanceof Error ? error.message : String(error), { provider, cause: error });\n}\n\n/**\n * A `Provider` that sends every call through an `InferenceGateway`, with tool calling and images.\n * `NormalizedRequest.model` is the Super Router **service** id, not a raw model name.\n */\nexport function createSuperRouterProvider(config: SuperRouterProviderConfig): Provider {\n const id = config.id ?? \"super-router\";\n const newKey = config.idempotencyKey ?? (() => globalThis.crypto.randomUUID());\n const toolCalling = config.toolCalling !== false;\n const build = (req: NormalizedRequest) => {\n const { messages, warnings } = toMessages(req, toolCalling);\n const request: InferenceRequest = {\n service: req.model,\n customer_id: config.customerId,\n messages,\n ...(toolCalling ? toTools(req) : {}),\n max_output_tokens: Math.min(8192, Math.max(1, req.maxOutputTokens ?? config.defaultMaxOutputTokens ?? 1024)),\n };\n return { request, warnings };\n };\n\n return {\n id,\n label: config.label ?? \"Super Router\",\n capabilities: {\n streaming: true, backgroundJobs: false, resumableStreams: false, tools: toolCalling, parallelToolCalls: toolCalling,\n images: toolCalling, files: false, audio: false, reasoning: false, strictJsonSchema: false, serverSideHistory: false, fileUpload: false,\n },\n transport: noTransport,\n\n async generate(req: NormalizedRequest, _opts?: CallOptions): Promise<GenerateResult> {\n const { request, warnings } = build(req);\n try {\n const result = await config.gateway.infer(request, newKey());\n const failed = result.execution_status !== \"succeeded\";\n if (!result.output) {\n // A repeated idempotency key reads the stored request back, and completions are never stored.\n throw new AgentError(\"invalid-request\", `This idempotency key was already used (request ${result.id}); the router does not store output, so it cannot be replayed.`, { provider: id });\n }\n const calls = result.output.tool_calls ?? [];\n const parts: ContentPart[] = [\n ...(result.output.content || !calls.length ? [{ type: \"text\" as const, text: result.output.content }] : []),\n ...calls.map((call): ContentPart => {\n const { value, repaired } = repairToolArguments(call.arguments);\n return { type: \"tool-call\", callId: call.id, name: call.name, input: value, status: \"pending\", ...(repaired ? { repaired } : {}) };\n }),\n ];\n return {\n parts,\n finishReason: failed ? \"error\" : finishOf(result.finish_reason, calls.length > 0),\n usage: toUsage(result.usage.meters),\n responseId: result.id,\n modelId: req.model,\n ...(warnings.length ? { warnings } : {}),\n };\n } catch (error) {\n throw toError(error, id);\n }\n },\n\n async *stream(req: NormalizedRequest, opts?: CallOptions): AsyncIterable<StreamEvent> {\n const { request } = build(req);\n let started = false;\n // Calls that have begun, by the router's index. Only `completed` makes one callable.\n const open = new Map<number, { id: string; name: string }>();\n let completed = 0;\n try {\n for await (const raw of config.gateway.stream(request, newKey(), opts?.signal)) {\n // A failed request can also say why the model stopped, which the protocol does not name yet.\n const event = raw as RouterStreamEvent & { finish_reason?: InferenceFinishReason };\n if (!started) {\n started = true;\n yield { type: \"start\", responseId: event.request_id, modelId: req.model };\n }\n if (event.type === \"output.delta\") yield { type: \"text-delta\", delta: event.text };\n else if (event.type === \"output.tool_call.delta\") {\n let call = open.get(event.index);\n if (!call) {\n if (!event.id || !event.name) throw new AgentError(\"unknown\", \"Super Router sent a tool call without an id or name.\", { provider: id });\n call = { id: event.id, name: event.name };\n open.set(event.index, call);\n yield { type: \"tool-call-start\", callId: call.id, name: call.name };\n }\n if (event.arguments_delta) yield { type: \"tool-call-delta\", callId: call.id, argsDelta: event.arguments_delta };\n } else if (event.type === \"output.tool_call.completed\") {\n if (!open.has(event.index)) yield { type: \"tool-call-start\", callId: event.id, name: event.name };\n const { value, repaired } = repairToolArguments(event.arguments);\n completed += 1;\n yield { type: \"tool-call-end\", callId: event.id, name: event.name, input: value, repaired };\n } else if (event.type === \"request.completed\" || event.type === \"request.failed\") {\n const usage = event.usage?.meters ? toUsage(event.usage.meters) : undefined;\n if (usage) yield { type: \"usage\", usage };\n const ok = event.type === \"request.completed\" && event.execution_status === \"succeeded\";\n const finishReason: FinishReason = ok\n ? finishOf(event.finish_reason, completed > 0)\n : event.finish_reason === \"length\"\n ? \"length\"\n : event.execution_status === \"cancelled\"\n ? \"cancelled\"\n : \"error\";\n yield { type: \"finish\", finishReason, responseId: event.request_id, ...(usage ? { usage } : {}) };\n } else if (event.type === \"request.replayed\") {\n // The original call already ran; its result is read with the request id, never re-billed.\n throw new AgentError(\"invalid-request\", `This idempotency key was already used (request ${event.request_id}).`, { provider: id });\n }\n }\n } catch (error) {\n yield { type: \"error\", error: (() => { try { throw toError(error, id); } catch (e) { return e; } })() };\n }\n },\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AAUP,IAAM,OAAO,CAAC,SAA2B,WAAoB;AAC3D,SAAO,KAAK,UAAU;AAAA,IACpB,SAAS,QAAQ;AAAA,IACjB,GAAI,QAAQ,kBAAkB,EAAE,iBAAiB,QAAQ,gBAAgB,IAAI,CA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GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAG;AAAA,UAClG,WAAW,MAAM,SAAS,oBAAoB;AAE5C,kBAAM,IAAI,WAAW,mBAAmB,kDAAkD,MAAM,UAAU,MAAM,EAAE,UAAU,GAAG,CAAC;AAAA,UAClI;AAAA,QACF;AAAA,MACF,SAAS,OAAO;AACd,cAAM,EAAE,MAAM,SAAS,QAAQ,MAAM;AAAE,cAAI;AAAE,kBAAM,QAAQ,OAAO,EAAE;AAAA,UAAG,SAAS,GAAG;AAAE,mBAAO;AAAA,UAAG;AAAA,QAAE,GAAG,EAAE;AAAA,MACxG;AAAA,IACF;AAAA,EACF;AACF;","names":["GatewayError"]}
|
|
1
|
+
{"version":3,"sources":["../src/gateway.ts","../src/provider.ts"],"sourcesContent":["import {\n GatewayError,\n parseSSE,\n type InferenceGateway,\n type InferenceRequest,\n type InferenceResult,\n type StreamEvent,\n} from \"@supersolutions/super-protocol\";\n\nexport type SuperRouterGatewayConfig = {\n /** Origin of the Super Router server, e.g. \"https://router.example.com\". */\n baseUrl: string;\n /** A Super Router API key. Keep it server-side; the browser should use a proxy. */\n apiKey: string;\n fetch?: typeof fetch;\n};\n\nconst body = (request: InferenceRequest, stream: boolean) => {\n return JSON.stringify({\n service: request.service,\n ...(request.service_version ? { service_version: request.service_version } : {}),\n customer_id: request.customer_id,\n input: {\n messages: request.messages,\n ...(request.tools?.length ? { tools: request.tools } : {}),\n ...(request.tools?.length && request.tool_choice !== undefined ? { tool_choice: request.tool_choice } : {}),\n },\n limits: {\n max_output_tokens: request.max_output_tokens ?? 1024,\n ...(request.timeout_ms ? { timeout_ms: request.timeout_ms } : {}),\n },\n stream,\n });\n};\n\n/** An `InferenceGateway` over the Super Router HTTP API (`POST /v1/inferences`). */\nexport function createSuperRouterGateway(config: SuperRouterGatewayConfig): InferenceGateway {\n const base = config.baseUrl.replace(/\\/+$/, \"\");\n const doFetch = config.fetch ?? fetch;\n\n async function send(path: string, init: RequestInit, idempotencyKey?: string): Promise<Response> {\n let response: Response;\n try {\n response = await doFetch(base + path, {\n ...init,\n redirect: \"manual\",\n headers: {\n Authorization: `Bearer ${config.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...(idempotencyKey ? { \"Idempotency-Key\": idempotencyKey } : {}),\n },\n });\n } catch (error) {\n if ((error as { name?: string })?.name === \"AbortError\") throw error;\n throw new GatewayError(\"network_error\");\n }\n // A repeated idempotency key answers 303 with the original request's location.\n if (response.status === 303 || (response.status >= 300 && response.status < 400)) return response;\n if (!response.ok) {\n let code = \"http_error\";\n let requestId: string | undefined;\n try {\n const parsed = (await response.json()) as { error?: { code?: string; request_id?: string } };\n if (typeof parsed.error?.code === \"string\") code = parsed.error.code;\n if (typeof parsed.error?.request_id === \"string\") requestId = parsed.error.request_id;\n } catch {\n /* non-JSON error body */\n }\n throw new GatewayError(code, response.status, requestId);\n }\n return response;\n }\n\n /**\n * A success body that is not JSON (a proxy's HTML page, a cut-off reply) or not an object (`null`, a string, a list)\n * is a gateway error, not a bare SyntaxError or a TypeError on the first field read.\n */\n const jsonOf = async (response: Response): Promise<InferenceResult> => {\n let parsed: unknown;\n try {\n parsed = await response.json();\n } catch {\n throw new GatewayError(\"bad_response\", response.status);\n }\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) throw new GatewayError(\"bad_response\", response.status);\n return parsed as InferenceResult;\n };\n\n const requestIdFrom = (response: Response) => (response.headers.get(\"location\") ?? \"\").split(\"/\").pop() ?? \"\";\n\n return {\n async infer(request, idempotencyKey) {\n const response = await send(\"/v1/inferences\", { method: \"POST\", body: body(request, false) }, idempotencyKey);\n if (response.status >= 300 && response.status < 400) {\n const id = requestIdFrom(response);\n if (!id) throw new GatewayError(\"bad_redirect\", response.status);\n return jsonOf(await send(\"/v1/requests/\" + encodeURIComponent(id), { method: \"GET\" }));\n }\n return jsonOf(response);\n },\n\n async *stream(request, idempotencyKey, signal) {\n const response = await send(\"/v1/inferences\", { method: \"POST\", body: body(request, true), ...(signal ? { signal } : {}) }, idempotencyKey);\n if (response.status >= 300 && response.status < 400) {\n yield { type: \"request.replayed\", request_id: requestIdFrom(response), sequence: 0 } satisfies StreamEvent;\n return;\n }\n if (!response.body) throw new GatewayError(\"empty_stream\");\n for await (const frame of parseSSE(response.body)) {\n let data: unknown;\n try {\n data = JSON.parse(frame.data);\n } catch {\n throw new GatewayError(\"bad_response\", response.status);\n }\n // A frame that is not an object (`null`, a string: spread would turn it into indexed characters) is not an event.\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) throw new GatewayError(\"bad_response\", response.status);\n yield { type: frame.event, ...data } as StreamEvent;\n }\n },\n };\n}\n","import {\n AgentError,\n type CallOptions,\n type ContentPart,\n type FinishReason,\n type GenerateResult,\n type Message,\n type NormalizedRequest,\n type Provider,\n repairToolArguments,\n type StreamEvent,\n type Transport,\n type Usage,\n} from \"@supersolutions/super-chat-core\";\nimport {\n GatewayError,\n type InferenceContentPart,\n type InferenceFinishReason,\n type InferenceGateway,\n type InferenceMessage,\n type InferenceRequest,\n type InferenceTool,\n type InferenceToolCall,\n type InferenceToolChoice,\n type StreamEvent as RouterStreamEvent,\n type Usage as RouterUsage,\n} from \"@supersolutions/super-protocol\";\n\nexport type SuperRouterProviderConfig = {\n gateway: InferenceGateway;\n /** The customer the usage is billed to. */\n customerId: string;\n id?: string;\n label?: string;\n /** Used when the request sets no `maxOutputTokens`. Super Router allows 1..8192. */\n defaultMaxOutputTokens?: number;\n /** One key per logical call; reuse it when retrying so the call never bills twice. */\n idempotencyKey?: () => string;\n /**\n * Send tools and images to the router. Default true. Turn it off for a server\n * that predates tool calling: tools are then left out with a warning.\n */\n toolCalling?: boolean;\n};\n\n// A gateway provider has no HTTP of its own: the gateway holds the credential and the wire.\nconst noTransport: Transport = {\n kind: \"custom\",\n credentialSafe: true,\n async fetch() {\n throw new AgentError(\"not-supported\", \"The Super Router provider does not use a Transport.\");\n },\n} as Transport;\n\nconst MAX_TOOL_RESULT_CHARS = 256_000;\nconst MAX_TOOL_DESCRIPTION_CHARS = 4096;\nconst IMAGE_MEDIA = /^image\\/(png|jpeg|gif|webp)$/;\n\n// Super Router accepts these characters in a call id; a thread may hold ids minted by another provider.\nconst wireCallId = (id: string) => id.replace(/[^a-zA-Z0-9_-]/g, \"_\").slice(0, 128) || \"call\";\n\nconst asText = (output: unknown) => (typeof output === \"string\" ? output : (JSON.stringify(output) ?? \"null\"));\n\nfunction resultText(output: unknown): string {\n const text = asText(output);\n const marker = \"…[truncated]\";\n return text.length > MAX_TOOL_RESULT_CHARS ? text.slice(0, MAX_TOOL_RESULT_CHARS - marker.length) + marker : text;\n}\n\n// The wire requires a JSON object; a repaired call can hold any JSON value.\nfunction argumentsText(input: unknown): string {\n const object = typeof input === \"object\" && input !== null && !Array.isArray(input);\n return JSON.stringify(object ? input : input === undefined || input === null ? {} : { input });\n}\n\nfunction imageUrl(part: Extract<ContentPart, { type: \"image\" }>): string | undefined {\n const { source, mediaType } = part;\n if (source.kind === \"url\") return source.url.startsWith(\"https://\") || /^data:image\\/(png|jpeg|gif|webp);base64,/.test(source.url) ? source.url : undefined;\n if (source.kind === \"base64\" && mediaType && IMAGE_MEDIA.test(mediaType)) return `data:${mediaType};base64,${source.data}`;\n return undefined;\n}\n\nfunction toMessages(req: NormalizedRequest, toolCalling: boolean): { messages: InferenceMessage[]; warnings: string[] } {\n const warnings: string[] = [];\n const messages: InferenceMessage[] = [];\n if (req.system) messages.push({ role: \"system\", content: req.system });\n const history = req.messages as Message[];\n // A call without a result, or a result without a call, is refused by the router: both happen in interrupted threads.\n const called = new Set(history.flatMap((m) => m.parts.flatMap((p) => (p.type === \"tool-call\" ? [p.callId] : []))));\n const answered = new Set(history.flatMap((m) => m.parts.flatMap((p) => (p.type === \"tool-result\" ? [p.callId] : []))));\n let dropped = 0;\n for (const m of history) {\n const texts: string[] = [];\n const images: InferenceContentPart[] = [];\n const calls: InferenceToolCall[] = [];\n const results: InferenceMessage[] = [];\n for (const p of m.parts) {\n if (p.type === \"text\") {\n if (p.text) texts.push(p.text);\n } else if (p.type === \"image\" && toolCalling) {\n const url = imageUrl(p);\n if (url) images.push({ type: \"image\", url, ...(p.detail ? { detail: p.detail } : {}) });\n else dropped += 1;\n } else if (p.type === \"tool-call\" && toolCalling) {\n if (answered.has(p.callId)) calls.push({ id: wireCallId(p.callId), name: p.name, arguments: argumentsText(p.input) });\n } else if (p.type === \"tool-result\" && toolCalling) {\n if (called.has(p.callId)) results.push({ role: \"tool\", tool_call_id: wireCallId(p.callId), content: resultText(p.output), ...(p.failure ? { is_error: true } : {}) });\n } else if (p.type !== \"reasoning\" && p.type !== \"artifact\") {\n dropped += 1;\n }\n }\n const text = texts.join(\"\\n\");\n if (m.role === \"tool\") messages.push(...results);\n else if (m.role === \"assistant\" && calls.length) messages.push({ role: \"assistant\", ...(text ? { content: text } : {}), tool_calls: calls });\n else if (m.role === \"user\" && images.length) messages.push({ role: \"user\", content: [...(text ? [{ type: \"text\" as const, text }] : []), ...images] });\n else if (text) messages.push({ role: m.role, content: text });\n if (m.role !== \"tool\") messages.push(...results);\n }\n if (dropped) warnings.push(`${dropped} part(s) were dropped: Super Router takes text, tool calls and https or base64 PNG, JPEG, GIF and WebP images.`);\n if (!toolCalling && req.tools?.length) warnings.push(\"Tools were ignored: tool calling is turned off for this provider.\");\n if (!messages.some((m) => m.role !== \"system\")) throw new AgentError(\"invalid-request\", \"Super Router needs at least one user or assistant message.\");\n return { messages, warnings };\n}\n\nfunction toTools(req: NormalizedRequest): { tools?: InferenceTool[]; tool_choice?: InferenceToolChoice } {\n const active = req.activeTools ? new Set(req.activeTools) : undefined;\n const tools = (req.tools ?? [])\n .filter((t) => !active || active.has(t.name))\n .map((t): InferenceTool => ({\n name: t.name,\n ...(t.description ? { description: t.description.slice(0, MAX_TOOL_DESCRIPTION_CHARS) } : {}),\n input_schema: { ...t.parameters, type: \"object\" },\n }));\n if (!tools.length) return {};\n const choice = req.toolChoice;\n if (!choice) return { tools };\n if (choice.type !== \"tool\") return { tools, tool_choice: choice.type };\n // Naming a tool that is not on offer this step would be refused; let the model choose instead.\n return tools.some((t) => t.name === choice.name) ? { tools, tool_choice: { name: choice.name } } : { tools };\n}\n\nconst finishOf = (reason: InferenceFinishReason | undefined, hasCalls: boolean): FinishReason =>\n reason === \"length\" ? \"length\" : reason === \"tool_calls\" || hasCalls ? \"tool-calls\" : \"stop\";\n\n// The router takes whole numbers from 1 to 8192; NaN or a fraction from a careless caller would be refused.\nfunction outputTokens(wanted: number | undefined): number {\n const n = typeof wanted === \"number\" && Number.isFinite(wanted) ? Math.floor(wanted) : 1024;\n return Math.min(8192, Math.max(1, n));\n}\n\nconst count = (v: unknown) => (typeof v === \"number\" && Number.isFinite(v) && v >= 0 ? v : 0);\n\nfunction toUsage(u?: RouterUsage): Usage {\n if (typeof u !== \"object\" || u === null) return {};\n const cached = count(u.cached);\n const inputTokens = count(u.input) + cached + count(u.cache_write);\n const outputTokens = count(u.output);\n return { inputTokens, outputTokens, totalTokens: inputTokens + outputTokens, ...(cached ? { cachedInputTokens: cached } : {}) };\n}\n\nfunction toError(error: unknown, provider: string): AgentError {\n if (error instanceof AgentError) return error;\n if ((error as { name?: string })?.name === \"AbortError\") return new AgentError(\"cancelled\", \"Cancelled.\", { provider, cause: error });\n if (error instanceof GatewayError) {\n const status = error.status;\n const kind = error.code === \"network_error\" ? \"network\"\n : status === 401 || status === 403 ? \"auth\"\n : status === 402 ? \"invalid-request\"\n : status === 429 ? \"rate-limit\"\n : status !== undefined && status >= 500 ? \"overloaded\"\n : status !== undefined && status >= 400 ? \"invalid-request\"\n : \"unknown\";\n return new AgentError(kind, error.requestId ? `${error.code} (request ${error.requestId})` : error.code, { ...(status ? { status } : {}), provider, cause: error });\n }\n return new AgentError(\"unknown\", error instanceof Error ? error.message : String(error), { provider, cause: error });\n}\n\n/**\n * A `Provider` that sends every call through an `InferenceGateway`, with tool calling and images.\n * `NormalizedRequest.model` is the Super Router **service** id, not a raw model name.\n */\nexport function createSuperRouterProvider(config: SuperRouterProviderConfig): Provider {\n const id = config.id ?? \"super-router\";\n const newKey = config.idempotencyKey ?? (() => globalThis.crypto.randomUUID());\n const toolCalling = config.toolCalling !== false;\n const build = (req: NormalizedRequest) => {\n const { messages, warnings } = toMessages(req, toolCalling);\n const request: InferenceRequest = {\n service: req.model,\n customer_id: config.customerId,\n messages,\n ...(toolCalling ? toTools(req) : {}),\n max_output_tokens: outputTokens(req.maxOutputTokens ?? config.defaultMaxOutputTokens),\n };\n return { request, warnings };\n };\n\n return {\n id,\n label: config.label ?? \"Super Router\",\n capabilities: {\n streaming: true, backgroundJobs: false, resumableStreams: false, tools: toolCalling, parallelToolCalls: toolCalling,\n images: toolCalling, files: false, audio: false, reasoning: false, strictJsonSchema: false, serverSideHistory: false, fileUpload: false,\n },\n transport: noTransport,\n\n async generate(req: NormalizedRequest, _opts?: CallOptions): Promise<GenerateResult> {\n const { request, warnings } = build(req);\n try {\n const result = await config.gateway.infer(request, newKey());\n const failed = result.execution_status !== \"succeeded\";\n if (typeof result.output === \"string\" || typeof result.output === \"number\" || typeof result.output === \"boolean\") {\n throw new AgentError(\"unknown\", \"Super Router sent a reply whose output is not an object.\", { provider: id });\n }\n if (!result.output) {\n // A repeated idempotency key reads the stored request back, and completions are never stored.\n throw new AgentError(\"invalid-request\", `This idempotency key was already used (request ${result.id}); the router does not store output, so it cannot be replayed.`, { provider: id });\n }\n // The reply is read as data: a gateway other than the reference one may leave out or mistype a field.\n const content = typeof result.output.content === \"string\" ? result.output.content : \"\";\n const calls = Array.isArray(result.output.tool_calls) ? result.output.tool_calls : [];\n const parts: ContentPart[] = [\n ...(content || !calls.length ? [{ type: \"text\" as const, text: content }] : []),\n ...calls.map((call): ContentPart => {\n if (typeof call?.id !== \"string\" || !call.id || typeof call.name !== \"string\" || !call.name) {\n throw new AgentError(\"unknown\", \"Super Router sent a tool call without an id or name.\", { provider: id });\n }\n const { value, repaired } = repairToolArguments(call.arguments);\n return { type: \"tool-call\", callId: call.id, name: call.name, input: value, status: \"pending\", ...(repaired ? { repaired } : {}) };\n }),\n ];\n return {\n parts,\n finishReason: failed ? \"error\" : finishOf(result.finish_reason, calls.length > 0),\n usage: toUsage(result.usage?.meters),\n responseId: result.id,\n modelId: req.model,\n ...(warnings.length ? { warnings } : {}),\n };\n } catch (error) {\n throw toError(error, id);\n }\n },\n\n async *stream(req: NormalizedRequest, opts?: CallOptions): AsyncIterable<StreamEvent> {\n const { request } = build(req);\n let started = false;\n // Calls that have begun, by the router's index. Only `completed` makes one callable.\n const open = new Map<number, { id: string; name: string }>();\n let completed = 0;\n let finished = false;\n try {\n for await (const raw of config.gateway.stream(request, newKey(), opts?.signal)) {\n // A failed request can also say why the model stopped, which the protocol does not name yet.\n if (raw === null || typeof raw !== \"object\") continue; // not an event\n const event = raw as RouterStreamEvent & { finish_reason?: InferenceFinishReason };\n if (!started) {\n started = true;\n yield { type: \"start\", responseId: event.request_id, modelId: req.model };\n }\n if (event.type === \"output.delta\") {\n if (typeof event.text === \"string\" && event.text) yield { type: \"text-delta\", delta: event.text };\n } else if (event.type === \"output.tool_call.delta\") {\n let call = open.get(event.index);\n if (!call) {\n if (!event.id || !event.name) throw new AgentError(\"unknown\", \"Super Router sent a tool call without an id or name.\", { provider: id });\n call = { id: event.id, name: event.name };\n open.set(event.index, call);\n yield { type: \"tool-call-start\", callId: call.id, name: call.name };\n }\n if (typeof event.arguments_delta === \"string\" && event.arguments_delta) yield { type: \"tool-call-delta\", callId: call.id, argsDelta: event.arguments_delta };\n } else if (event.type === \"output.tool_call.completed\") {\n if (!event.id || !event.name) throw new AgentError(\"unknown\", \"Super Router sent a tool call without an id or name.\", { provider: id });\n if (!open.has(event.index)) yield { type: \"tool-call-start\", callId: event.id, name: event.name };\n const { value, repaired } = repairToolArguments(event.arguments);\n completed += 1;\n yield { type: \"tool-call-end\", callId: event.id, name: event.name, input: value, repaired };\n } else if (event.type === \"request.completed\" || event.type === \"request.failed\") {\n const usage = event.usage?.meters ? toUsage(event.usage.meters) : undefined;\n if (usage) yield { type: \"usage\", usage };\n const ok = event.type === \"request.completed\" && event.execution_status === \"succeeded\";\n const finishReason: FinishReason = ok\n ? finishOf(event.finish_reason, completed > 0)\n : event.finish_reason === \"length\"\n ? \"length\"\n : event.execution_status === \"cancelled\"\n ? \"cancelled\"\n : \"error\";\n yield { type: \"finish\", finishReason, responseId: event.request_id, ...(usage ? { usage } : {}) };\n finished = true;\n } else if (event.type === \"request.replayed\") {\n // The original call already ran; its result is read with the request id, never re-billed.\n throw new AgentError(\"invalid-request\", `This idempotency key was already used (request ${event.request_id}).`, { provider: id });\n }\n }\n // A stream that closes without request.completed or request.failed was cut off (a proxy timeout, a dropped\n // connection). Ending quietly would show half an answer as a finished one.\n if (!finished) throw new AgentError(\"network\", \"The model's stream ended before it finished.\", { provider: id });\n } catch (error) {\n yield { type: \"error\", error: (() => { try { throw toError(error, id); } catch (e) { return e; } })() };\n }\n },\n };\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAKK;AAUP,IAAM,OAAO,CAAC,SAA2B,WAAoB;AAC3D,SAAO,KAAK,UAAU;AAAA,IACpB,SAAS,QAAQ;AAAA,IACjB,GAAI,QAAQ,kBAAkB,EAAE,iBAAiB,QAAQ,gBAAgB,IAAI,CAAC;AAAA,IAC9E,aAAa,QAAQ;AAAA,IACrB,OAAO;AAAA,MACL,UAAU,QAAQ;AAAA,MAClB,GAAI,QAAQ,OAAO,SAAS,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC;AAAA,MACxD,GAAI,QAAQ,OAAO,UAAU,QAAQ,gBAAgB,SAAY,EAAE,aAAa,QAAQ,YAAY,IAAI,CAAC;AAAA,IAC3G;AAAA,IACA,QAAQ;AAAA,MACN,mBAAmB,QAAQ,qBAAqB;AAAA,MAChD,GAAI,QAAQ,aAAa,EAAE,YAAY,QAAQ,WAAW,IAAI,CAAC;AAAA,IACjE;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAGO,SAAS,yBAA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kD,MAAM,UAAU,MAAM,EAAE,UAAU,GAAG,CAAC;AAAA,UAClI;AAAA,QACF;AAGA,YAAI,CAAC,SAAU,OAAM,IAAI,WAAW,WAAW,gDAAgD,EAAE,UAAU,GAAG,CAAC;AAAA,MACjH,SAAS,OAAO;AACd,cAAM,EAAE,MAAM,SAAS,QAAQ,MAAM;AAAE,cAAI;AAAE,kBAAM,QAAQ,OAAO,EAAE;AAAA,UAAG,SAAS,GAAG;AAAE,mBAAO;AAAA,UAAG;AAAA,QAAE,GAAG,EAAE;AAAA,MACxG;AAAA,IACF;AAAA,EACF;AACF;","names":["GatewayError","outputTokens"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supersolutions/super-chat-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Super Router binding for super-chat: an HTTP InferenceGateway and a text Provider that routes through any InferenceGateway.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SUPER SOLUTION LABS INC",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@supersolutions/super-protocol": "0.4.
|
|
45
|
-
"@supersolutions/super-chat-core": "0.
|
|
44
|
+
"@supersolutions/super-protocol": "0.4.2",
|
|
45
|
+
"@supersolutions/super-chat-core": "0.6.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"tsup": "^8.3.5",
|