@supersolutions/super-chat-router 0.0.0 → 0.2.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/LICENSE +201 -0
- package/NOTICE +14 -0
- package/README.md +11 -1
- package/dist/index.d.ts +36 -0
- package/dist/index.js +299 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 SUPER SOLUTION LABS INC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
superchat
|
|
2
|
+
Copyright 2026 SUPER SOLUTION LABS INC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
# @supersolutions/super-chat-router
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`createSuperRouterGateway` is an `InferenceGateway` over the Super Router HTTP API.
|
|
4
|
+
`createSuperRouterProvider` wraps any gateway as a super-chat `Provider`; the request's `model` is the Super Router
|
|
5
|
+
service id. Errors are mapped to `AgentError` kinds; a replayed idempotency key is reported, never passed off as a
|
|
6
|
+
fresh answer.
|
|
7
|
+
|
|
8
|
+
The provider carries text, tool declarations, streaming tool calls, tool results, usage, and images as `https:`
|
|
9
|
+
URLs or base64 PNG, JPEG, GIF and WebP. Files and audio are dropped with a warning. Tool calling needs a Super Router
|
|
10
|
+
TypeScript server that supports it; the Go, Python and Rust data planes refuse these requests. For an older server,
|
|
11
|
+
set `toolCalling: false`.
|
|
12
|
+
|
|
13
|
+
See [docs/PACKAGES.md](../../docs/PACKAGES.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { InferenceGateway } from '@supersolutions/super-protocol';
|
|
2
|
+
import { Provider } from '@supersolutions/super-chat-core';
|
|
3
|
+
|
|
4
|
+
type SuperRouterGatewayConfig = {
|
|
5
|
+
/** Origin of the Super Router server, e.g. "https://router.example.com". */
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
/** A Super Router API key. Keep it server-side; the browser should use a proxy. */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
};
|
|
11
|
+
/** An `InferenceGateway` over the Super Router HTTP API (`POST /v1/inferences`). */
|
|
12
|
+
declare function createSuperRouterGateway(config: SuperRouterGatewayConfig): InferenceGateway;
|
|
13
|
+
|
|
14
|
+
type SuperRouterProviderConfig = {
|
|
15
|
+
gateway: InferenceGateway;
|
|
16
|
+
/** The customer the usage is billed to. */
|
|
17
|
+
customerId: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Used when the request sets no `maxOutputTokens`. Super Router allows 1..8192. */
|
|
21
|
+
defaultMaxOutputTokens?: number;
|
|
22
|
+
/** One key per logical call; reuse it when retrying so the call never bills twice. */
|
|
23
|
+
idempotencyKey?: () => string;
|
|
24
|
+
/**
|
|
25
|
+
* Send tools and images to the router. Default true. Turn it off for a server
|
|
26
|
+
* that predates tool calling: tools are then left out with a warning.
|
|
27
|
+
*/
|
|
28
|
+
toolCalling?: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A `Provider` that sends every call through an `InferenceGateway`, with tool calling and images.
|
|
32
|
+
* `NormalizedRequest.model` is the Super Router **service** id, not a raw model name.
|
|
33
|
+
*/
|
|
34
|
+
declare function createSuperRouterProvider(config: SuperRouterProviderConfig): Provider;
|
|
35
|
+
|
|
36
|
+
export { type SuperRouterGatewayConfig, type SuperRouterProviderConfig, createSuperRouterGateway, createSuperRouterProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// src/gateway.ts
|
|
2
|
+
import {
|
|
3
|
+
GatewayError,
|
|
4
|
+
parseSSE
|
|
5
|
+
} from "@supersolutions/super-protocol";
|
|
6
|
+
var body = (request, stream) => {
|
|
7
|
+
return JSON.stringify({
|
|
8
|
+
service: request.service,
|
|
9
|
+
...request.service_version ? { service_version: request.service_version } : {},
|
|
10
|
+
customer_id: request.customer_id,
|
|
11
|
+
input: {
|
|
12
|
+
messages: request.messages,
|
|
13
|
+
...request.tools?.length ? { tools: request.tools } : {},
|
|
14
|
+
...request.tools?.length && request.tool_choice !== void 0 ? { tool_choice: request.tool_choice } : {}
|
|
15
|
+
},
|
|
16
|
+
limits: {
|
|
17
|
+
max_output_tokens: request.max_output_tokens ?? 1024,
|
|
18
|
+
...request.timeout_ms ? { timeout_ms: request.timeout_ms } : {}
|
|
19
|
+
},
|
|
20
|
+
stream
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
function createSuperRouterGateway(config) {
|
|
24
|
+
const base = config.baseUrl.replace(/\/+$/, "");
|
|
25
|
+
const doFetch = config.fetch ?? fetch;
|
|
26
|
+
async function send(path, init, idempotencyKey) {
|
|
27
|
+
let response;
|
|
28
|
+
try {
|
|
29
|
+
response = await doFetch(base + path, {
|
|
30
|
+
...init,
|
|
31
|
+
redirect: "manual",
|
|
32
|
+
headers: {
|
|
33
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error?.name === "AbortError") throw error;
|
|
40
|
+
throw new GatewayError("network_error");
|
|
41
|
+
}
|
|
42
|
+
if (response.status === 303 || response.status >= 300 && response.status < 400) return response;
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
let code = "http_error";
|
|
45
|
+
let requestId;
|
|
46
|
+
try {
|
|
47
|
+
const parsed = await response.json();
|
|
48
|
+
code = parsed.error?.code ?? code;
|
|
49
|
+
requestId = parsed.error?.request_id;
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
throw new GatewayError(code, response.status, requestId);
|
|
53
|
+
}
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
const requestIdFrom = (response) => (response.headers.get("location") ?? "").split("/").pop() ?? "";
|
|
57
|
+
return {
|
|
58
|
+
async infer(request, idempotencyKey) {
|
|
59
|
+
const response = await send("/v1/inferences", { method: "POST", body: body(request, false) }, idempotencyKey);
|
|
60
|
+
if (response.status >= 300 && response.status < 400) {
|
|
61
|
+
const id = requestIdFrom(response);
|
|
62
|
+
if (!id) throw new GatewayError("bad_redirect", response.status);
|
|
63
|
+
return await (await send("/v1/requests/" + encodeURIComponent(id), { method: "GET" })).json();
|
|
64
|
+
}
|
|
65
|
+
return await response.json();
|
|
66
|
+
},
|
|
67
|
+
async *stream(request, idempotencyKey, signal) {
|
|
68
|
+
const response = await send("/v1/inferences", { method: "POST", body: body(request, true), ...signal ? { signal } : {} }, idempotencyKey);
|
|
69
|
+
if (response.status >= 300 && response.status < 400) {
|
|
70
|
+
yield { type: "request.replayed", request_id: requestIdFrom(response), sequence: 0 };
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!response.body) throw new GatewayError("empty_stream");
|
|
74
|
+
for await (const frame of parseSSE(response.body)) {
|
|
75
|
+
yield { type: frame.event, ...JSON.parse(frame.data) };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/provider.ts
|
|
82
|
+
import {
|
|
83
|
+
AgentError,
|
|
84
|
+
repairToolArguments
|
|
85
|
+
} from "@supersolutions/super-chat-core";
|
|
86
|
+
import {
|
|
87
|
+
GatewayError as GatewayError2
|
|
88
|
+
} from "@supersolutions/super-protocol";
|
|
89
|
+
var noTransport = {
|
|
90
|
+
kind: "custom",
|
|
91
|
+
credentialSafe: true,
|
|
92
|
+
async fetch() {
|
|
93
|
+
throw new AgentError("not-supported", "The Super Router provider does not use a Transport.");
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var MAX_TOOL_RESULT_CHARS = 256e3;
|
|
97
|
+
var MAX_TOOL_DESCRIPTION_CHARS = 4096;
|
|
98
|
+
var IMAGE_MEDIA = /^image\/(png|jpeg|gif|webp)$/;
|
|
99
|
+
var wireCallId = (id) => id.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 128) || "call";
|
|
100
|
+
var asText = (output) => typeof output === "string" ? output : JSON.stringify(output) ?? "null";
|
|
101
|
+
function resultText(output) {
|
|
102
|
+
const text = asText(output);
|
|
103
|
+
const marker = "\u2026[truncated]";
|
|
104
|
+
return text.length > MAX_TOOL_RESULT_CHARS ? text.slice(0, MAX_TOOL_RESULT_CHARS - marker.length) + marker : text;
|
|
105
|
+
}
|
|
106
|
+
function argumentsText(input) {
|
|
107
|
+
const object = typeof input === "object" && input !== null && !Array.isArray(input);
|
|
108
|
+
return JSON.stringify(object ? input : input === void 0 || input === null ? {} : { input });
|
|
109
|
+
}
|
|
110
|
+
function imageUrl(part) {
|
|
111
|
+
const { source, mediaType } = part;
|
|
112
|
+
if (source.kind === "url") return source.url.startsWith("https://") || /^data:image\/(png|jpeg|gif|webp);base64,/.test(source.url) ? source.url : void 0;
|
|
113
|
+
if (source.kind === "base64" && mediaType && IMAGE_MEDIA.test(mediaType)) return `data:${mediaType};base64,${source.data}`;
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
function toMessages(req, toolCalling) {
|
|
117
|
+
const warnings = [];
|
|
118
|
+
const messages = [];
|
|
119
|
+
if (req.system) messages.push({ role: "system", content: req.system });
|
|
120
|
+
const history = req.messages;
|
|
121
|
+
const called = new Set(history.flatMap((m) => m.parts.flatMap((p) => p.type === "tool-call" ? [p.callId] : [])));
|
|
122
|
+
const answered = new Set(history.flatMap((m) => m.parts.flatMap((p) => p.type === "tool-result" ? [p.callId] : [])));
|
|
123
|
+
let dropped = 0;
|
|
124
|
+
for (const m of history) {
|
|
125
|
+
const texts = [];
|
|
126
|
+
const images = [];
|
|
127
|
+
const calls = [];
|
|
128
|
+
const results = [];
|
|
129
|
+
for (const p of m.parts) {
|
|
130
|
+
if (p.type === "text") {
|
|
131
|
+
if (p.text) texts.push(p.text);
|
|
132
|
+
} else if (p.type === "image" && toolCalling) {
|
|
133
|
+
const url = imageUrl(p);
|
|
134
|
+
if (url) images.push({ type: "image", url, ...p.detail ? { detail: p.detail } : {} });
|
|
135
|
+
else dropped += 1;
|
|
136
|
+
} else if (p.type === "tool-call" && toolCalling) {
|
|
137
|
+
if (answered.has(p.callId)) calls.push({ id: wireCallId(p.callId), name: p.name, arguments: argumentsText(p.input) });
|
|
138
|
+
} else if (p.type === "tool-result" && toolCalling) {
|
|
139
|
+
if (called.has(p.callId)) results.push({ role: "tool", tool_call_id: wireCallId(p.callId), content: resultText(p.output), ...p.failure ? { is_error: true } : {} });
|
|
140
|
+
} else if (p.type !== "reasoning" && p.type !== "artifact") {
|
|
141
|
+
dropped += 1;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const text = texts.join("\n");
|
|
145
|
+
if (m.role === "tool") messages.push(...results);
|
|
146
|
+
else if (m.role === "assistant" && calls.length) messages.push({ role: "assistant", ...text ? { content: text } : {}, tool_calls: calls });
|
|
147
|
+
else if (m.role === "user" && images.length) messages.push({ role: "user", content: [...text ? [{ type: "text", text }] : [], ...images] });
|
|
148
|
+
else if (text) messages.push({ role: m.role, content: text });
|
|
149
|
+
if (m.role !== "tool") messages.push(...results);
|
|
150
|
+
}
|
|
151
|
+
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.`);
|
|
152
|
+
if (!toolCalling && req.tools?.length) warnings.push("Tools were ignored: tool calling is turned off for this provider.");
|
|
153
|
+
if (!messages.some((m) => m.role !== "system")) throw new AgentError("invalid-request", "Super Router needs at least one user or assistant message.");
|
|
154
|
+
return { messages, warnings };
|
|
155
|
+
}
|
|
156
|
+
function toTools(req) {
|
|
157
|
+
const active = req.activeTools ? new Set(req.activeTools) : void 0;
|
|
158
|
+
const tools = (req.tools ?? []).filter((t) => !active || active.has(t.name)).map((t) => ({
|
|
159
|
+
name: t.name,
|
|
160
|
+
...t.description ? { description: t.description.slice(0, MAX_TOOL_DESCRIPTION_CHARS) } : {},
|
|
161
|
+
input_schema: { ...t.parameters, type: "object" }
|
|
162
|
+
}));
|
|
163
|
+
if (!tools.length) return {};
|
|
164
|
+
const choice = req.toolChoice;
|
|
165
|
+
if (!choice) return { tools };
|
|
166
|
+
if (choice.type !== "tool") return { tools, tool_choice: choice.type };
|
|
167
|
+
return tools.some((t) => t.name === choice.name) ? { tools, tool_choice: { name: choice.name } } : { tools };
|
|
168
|
+
}
|
|
169
|
+
var finishOf = (reason, hasCalls) => reason === "length" ? "length" : reason === "tool_calls" || hasCalls ? "tool-calls" : "stop";
|
|
170
|
+
function toUsage(u) {
|
|
171
|
+
if (!u) return {};
|
|
172
|
+
const inputTokens = u.input + u.cached + u.cache_write;
|
|
173
|
+
return { inputTokens, outputTokens: u.output, totalTokens: inputTokens + u.output, ...u.cached ? { cachedInputTokens: u.cached } : {} };
|
|
174
|
+
}
|
|
175
|
+
function toError(error, provider) {
|
|
176
|
+
if (error instanceof AgentError) return error;
|
|
177
|
+
if (error?.name === "AbortError") return new AgentError("cancelled", "Cancelled.", { provider, cause: error });
|
|
178
|
+
if (error instanceof GatewayError2) {
|
|
179
|
+
const status = error.status;
|
|
180
|
+
const kind = error.code === "network_error" ? "network" : status === 401 || status === 403 ? "auth" : status === 402 ? "invalid-request" : status === 429 ? "rate-limit" : status !== void 0 && status >= 500 ? "overloaded" : status !== void 0 && status >= 400 ? "invalid-request" : "unknown";
|
|
181
|
+
return new AgentError(kind, error.requestId ? `${error.code} (request ${error.requestId})` : error.code, { ...status ? { status } : {}, provider, cause: error });
|
|
182
|
+
}
|
|
183
|
+
return new AgentError("unknown", error instanceof Error ? error.message : String(error), { provider, cause: error });
|
|
184
|
+
}
|
|
185
|
+
function createSuperRouterProvider(config) {
|
|
186
|
+
const id = config.id ?? "super-router";
|
|
187
|
+
const newKey = config.idempotencyKey ?? (() => globalThis.crypto.randomUUID());
|
|
188
|
+
const toolCalling = config.toolCalling !== false;
|
|
189
|
+
const build = (req) => {
|
|
190
|
+
const { messages, warnings } = toMessages(req, toolCalling);
|
|
191
|
+
const request = {
|
|
192
|
+
service: req.model,
|
|
193
|
+
customer_id: config.customerId,
|
|
194
|
+
messages,
|
|
195
|
+
...toolCalling ? toTools(req) : {},
|
|
196
|
+
max_output_tokens: Math.min(8192, Math.max(1, req.maxOutputTokens ?? config.defaultMaxOutputTokens ?? 1024))
|
|
197
|
+
};
|
|
198
|
+
return { request, warnings };
|
|
199
|
+
};
|
|
200
|
+
return {
|
|
201
|
+
id,
|
|
202
|
+
label: config.label ?? "Super Router",
|
|
203
|
+
capabilities: {
|
|
204
|
+
streaming: true,
|
|
205
|
+
backgroundJobs: false,
|
|
206
|
+
resumableStreams: false,
|
|
207
|
+
tools: toolCalling,
|
|
208
|
+
parallelToolCalls: toolCalling,
|
|
209
|
+
images: toolCalling,
|
|
210
|
+
files: false,
|
|
211
|
+
audio: false,
|
|
212
|
+
reasoning: false,
|
|
213
|
+
strictJsonSchema: false,
|
|
214
|
+
serverSideHistory: false,
|
|
215
|
+
fileUpload: false
|
|
216
|
+
},
|
|
217
|
+
transport: noTransport,
|
|
218
|
+
async generate(req, _opts) {
|
|
219
|
+
const { request, warnings } = build(req);
|
|
220
|
+
try {
|
|
221
|
+
const result = await config.gateway.infer(request, newKey());
|
|
222
|
+
const failed = result.execution_status !== "succeeded";
|
|
223
|
+
if (!result.output) {
|
|
224
|
+
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
|
+
}
|
|
226
|
+
const calls = result.output.tool_calls ?? [];
|
|
227
|
+
const parts = [
|
|
228
|
+
...result.output.content || !calls.length ? [{ type: "text", text: result.output.content }] : [],
|
|
229
|
+
...calls.map((call) => {
|
|
230
|
+
const { value, repaired } = repairToolArguments(call.arguments);
|
|
231
|
+
return { type: "tool-call", callId: call.id, name: call.name, input: value, status: "pending", ...repaired ? { repaired } : {} };
|
|
232
|
+
})
|
|
233
|
+
];
|
|
234
|
+
return {
|
|
235
|
+
parts,
|
|
236
|
+
finishReason: failed ? "error" : finishOf(result.finish_reason, calls.length > 0),
|
|
237
|
+
usage: toUsage(result.usage.meters),
|
|
238
|
+
responseId: result.id,
|
|
239
|
+
modelId: req.model,
|
|
240
|
+
...warnings.length ? { warnings } : {}
|
|
241
|
+
};
|
|
242
|
+
} catch (error) {
|
|
243
|
+
throw toError(error, id);
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
async *stream(req, opts) {
|
|
247
|
+
const { request } = build(req);
|
|
248
|
+
let started = false;
|
|
249
|
+
const open = /* @__PURE__ */ new Map();
|
|
250
|
+
let completed = 0;
|
|
251
|
+
try {
|
|
252
|
+
for await (const raw of config.gateway.stream(request, newKey(), opts?.signal)) {
|
|
253
|
+
const event = raw;
|
|
254
|
+
if (!started) {
|
|
255
|
+
started = true;
|
|
256
|
+
yield { type: "start", responseId: event.request_id, modelId: req.model };
|
|
257
|
+
}
|
|
258
|
+
if (event.type === "output.delta") yield { type: "text-delta", delta: event.text };
|
|
259
|
+
else if (event.type === "output.tool_call.delta") {
|
|
260
|
+
let call = open.get(event.index);
|
|
261
|
+
if (!call) {
|
|
262
|
+
if (!event.id || !event.name) throw new AgentError("unknown", "Super Router sent a tool call without an id or name.", { provider: id });
|
|
263
|
+
call = { id: event.id, name: event.name };
|
|
264
|
+
open.set(event.index, call);
|
|
265
|
+
yield { type: "tool-call-start", callId: call.id, name: call.name };
|
|
266
|
+
}
|
|
267
|
+
if (event.arguments_delta) yield { type: "tool-call-delta", callId: call.id, argsDelta: event.arguments_delta };
|
|
268
|
+
} else if (event.type === "output.tool_call.completed") {
|
|
269
|
+
if (!open.has(event.index)) yield { type: "tool-call-start", callId: event.id, name: event.name };
|
|
270
|
+
const { value, repaired } = repairToolArguments(event.arguments);
|
|
271
|
+
completed += 1;
|
|
272
|
+
yield { type: "tool-call-end", callId: event.id, name: event.name, input: value, repaired };
|
|
273
|
+
} else if (event.type === "request.completed" || event.type === "request.failed") {
|
|
274
|
+
const usage = event.usage?.meters ? toUsage(event.usage.meters) : void 0;
|
|
275
|
+
if (usage) yield { type: "usage", usage };
|
|
276
|
+
const ok = event.type === "request.completed" && event.execution_status === "succeeded";
|
|
277
|
+
const finishReason = ok ? finishOf(event.finish_reason, completed > 0) : event.finish_reason === "length" ? "length" : event.execution_status === "cancelled" ? "cancelled" : "error";
|
|
278
|
+
yield { type: "finish", finishReason, responseId: event.request_id, ...usage ? { usage } : {} };
|
|
279
|
+
} else if (event.type === "request.replayed") {
|
|
280
|
+
throw new AgentError("invalid-request", `This idempotency key was already used (request ${event.request_id}).`, { provider: id });
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
} catch (error) {
|
|
284
|
+
yield { type: "error", error: (() => {
|
|
285
|
+
try {
|
|
286
|
+
throw toError(error, id);
|
|
287
|
+
} catch (e) {
|
|
288
|
+
return e;
|
|
289
|
+
}
|
|
290
|
+
})() };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
export {
|
|
296
|
+
createSuperRouterGateway,
|
|
297
|
+
createSuperRouterProvider
|
|
298
|
+
};
|
|
299
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,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,yBAAyB,QAAoD;AAC3F,QAAM,OAAO,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AAC9C,QAAM,UAAU,OAAO,SAAS;AAEhC,iBAAe,KAAK,MAAc,MAAmB,gBAA4C;AAC/F,QAAI;AACJ,QAAI;AACF,iBAAW,MAAM,QAAQ,OAAO,MAAM;AAAA,QACpC,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,eAAe,UAAU,OAAO,MAAM;AAAA,UACtC,gBAAgB;AAAA,UAChB,GA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AM,iBAAiB,QAAQ,MAAM,IAAI,MAAM,MAAM,MAAM,OAAO,OAAO,SAAS;AAAA,UAC5F,WAAW,MAAM,SAAS,uBAAuB,MAAM,SAAS,kBAAkB;AAChF,kBAAM,QAAQ,MAAM,OAAO,SAAS,QAAQ,MAAM,MAAM,MAAM,IAAI;AAClE,gBAAI,MAAO,OAAM,EAAE,MAAM,SAAS,MAAM;AACxC,kBAAM,KAAK,MAAM,SAAS,uBAAuB,MAAM,qBAAqB;AAC5E,kBAAM,eAA6B,KAC/B,SAAS,MAAM,eAAe,YAAY,CAAC,IAC3C,MAAM,kBAAkB,WACtB,WACA,MAAM,qBAAqB,cACzB,cACA;AACR,kBAAM,EAAE,MAAM,UAAU,cAAc,YAAY,MAAM,YAAY,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"]}
|
package/package.json
CHANGED
|
@@ -1,16 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supersolutions/super-chat-router",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"author": "SUPER SOLUTION LABS INC",
|
|
7
|
+
"homepage": "https://github.com/Super-Solution/super-chat/tree/main/packages/integrations/router#readme",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/Super-Solution/super-chat/issues"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"agent",
|
|
13
|
+
"chat",
|
|
14
|
+
"router",
|
|
15
|
+
"gateway",
|
|
16
|
+
"billing"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"main": "./dist/index.js",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
}
|
|
9
29
|
},
|
|
10
30
|
"files": [
|
|
11
|
-
"
|
|
31
|
+
"dist",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"NOTICE"
|
|
12
34
|
],
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/Super-Solution/super-chat.git",
|
|
38
|
+
"directory": "packages/integrations/router"
|
|
39
|
+
},
|
|
13
40
|
"publishConfig": {
|
|
14
41
|
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@supersolutions/super-protocol": "0.2.0",
|
|
45
|
+
"@supersolutions/super-chat-core": "0.2.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"tsup": "^8.3.5",
|
|
49
|
+
"typescript": "^5.7.2"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup",
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
15
54
|
}
|
|
16
55
|
}
|