@decocms/bindings 0.2.4-beta.1 → 0.2.4-beta.3
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 +5 -5
- package/dist/core/binder.d.ts +3 -0
- package/dist/core/binder.js +81 -0
- package/dist/core/binder.js.map +1 -0
- package/dist/{client.js → core/client/http-client-transport.js} +9 -9
- package/dist/core/client/http-client-transport.js.map +1 -0
- package/dist/core/client/index.d.ts +3 -0
- package/dist/core/client/index.js +5 -0
- package/dist/core/client/index.js.map +1 -0
- package/dist/core/client/mcp-client.d.ts +233 -0
- package/dist/core/client/mcp-client.js +99 -0
- package/dist/core/client/mcp-client.js.map +1 -0
- package/dist/core/client/mcp.d.ts +3 -0
- package/dist/core/client/mcp.js +29 -0
- package/dist/core/client/mcp.js.map +1 -0
- package/dist/core/client/proxy.d.ts +10 -0
- package/dist/core/client/proxy.js +104 -0
- package/dist/core/client/proxy.js.map +1 -0
- package/dist/core/connection.js +1 -0
- package/dist/core/connection.js.map +1 -0
- package/dist/core/subset.d.ts +17 -0
- package/dist/core/subset.js +321 -0
- package/dist/core/subset.js.map +1 -0
- package/dist/index-D0aUdNls.d.ts +153 -0
- package/dist/index.d.ts +3 -94
- package/dist/index.js +5 -340
- package/dist/index.js.map +1 -1
- package/dist/{node → well-known}/agents.d.ts +64 -64
- package/dist/well-known/agents.js +28 -0
- package/dist/well-known/agents.js.map +1 -0
- package/dist/{node → well-known}/collections.d.ts +1 -1
- package/dist/{collections.js → well-known/collections.js} +24 -13
- package/dist/well-known/collections.js.map +1 -0
- package/dist/{node → well-known}/language-model.d.ts +387 -391
- package/dist/{node → well-known}/language-model.js +27 -21
- package/dist/well-known/language-model.js.map +1 -0
- package/package.json +17 -37
- package/dist/browser/agents.js +0 -29
- package/dist/browser/agents.js.map +0 -1
- package/dist/browser/chunk-6QEXJ7XW.js +0 -48564
- package/dist/browser/chunk-6QEXJ7XW.js.map +0 -1
- package/dist/browser/chunk-WKNVAFKE.js +0 -2176
- package/dist/browser/chunk-WKNVAFKE.js.map +0 -1
- package/dist/browser/chunk-XWLBKKHZ.js +0 -127
- package/dist/browser/chunk-XWLBKKHZ.js.map +0 -1
- package/dist/browser/chunk-ZX4ZDU2T.js +0 -58
- package/dist/browser/chunk-ZX4ZDU2T.js.map +0 -1
- package/dist/browser/client.js +0 -9
- package/dist/browser/client.js.map +0 -1
- package/dist/browser/collections.js +0 -4
- package/dist/browser/collections.js.map +0 -1
- package/dist/browser/connection.js +0 -8
- package/dist/browser/connection.js.map +0 -1
- package/dist/browser/index.js +0 -10
- package/dist/browser/index.js.map +0 -1
- package/dist/browser/language-model.js +0 -205
- package/dist/browser/language-model.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/collections.d.ts +0 -537
- package/dist/collections.js.map +0 -1
- package/dist/connection.js +0 -3
- package/dist/connection.js.map +0 -1
- package/dist/language-model.d.ts +0 -3228
- package/dist/language-model.js +0 -628
- package/dist/language-model.js.map +0 -1
- package/dist/models.d.ts +0 -2071
- package/dist/models.js +0 -111
- package/dist/models.js.map +0 -1
- package/dist/node/agents.js +0 -27
- package/dist/node/agents.js.map +0 -1
- package/dist/node/chunk-BLCFITZG.js +0 -56
- package/dist/node/chunk-BLCFITZG.js.map +0 -1
- package/dist/node/chunk-QMQMPK7Q.js +0 -50
- package/dist/node/chunk-QMQMPK7Q.js.map +0 -1
- package/dist/node/chunk-QP7AQCEP.js +0 -23478
- package/dist/node/chunk-QP7AQCEP.js.map +0 -1
- package/dist/node/chunk-T2DG7334.js +0 -125
- package/dist/node/chunk-T2DG7334.js.map +0 -1
- package/dist/node/client.d.ts +0 -12
- package/dist/node/client.js +0 -7
- package/dist/node/client.js.map +0 -1
- package/dist/node/collections.js +0 -4
- package/dist/node/collections.js.map +0 -1
- package/dist/node/connection.d.ts +0 -30
- package/dist/node/connection.js +0 -6
- package/dist/node/connection.js.map +0 -1
- package/dist/node/index.d.ts +0 -94
- package/dist/node/index.js +0 -8
- package/dist/node/index.js.map +0 -1
- package/dist/node/language-model.js.map +0 -1
- /package/dist/{client.d.ts → core/client/http-client-transport.d.ts} +0 -0
- /package/dist/{connection.d.ts → core/connection.d.ts} +0 -0
package/dist/language-model.js
DELETED
|
@@ -1,628 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { diffSchemas } from 'json-schema-diff';
|
|
3
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
4
|
-
import { convertJsonSchemaToZod } from 'zod-from-json-schema';
|
|
5
|
-
import { Client as Client$1 } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
7
|
-
import { WebSocketClientTransport } from '@modelcontextprotocol/sdk/client/websocket.js';
|
|
8
|
-
import { ListToolsResultSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
10
|
-
|
|
11
|
-
// src/well-known/language-model.ts
|
|
12
|
-
var HTTPClientTransport = class extends StreamableHTTPClientTransport {
|
|
13
|
-
constructor(url, opts) {
|
|
14
|
-
super(url, opts);
|
|
15
|
-
}
|
|
16
|
-
send(message, options) {
|
|
17
|
-
const mockAction = getMockActionFor(message);
|
|
18
|
-
if (mockAction?.type === "emit") {
|
|
19
|
-
this.onmessage?.(mockAction.message);
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
if (mockAction?.type === "suppress") {
|
|
23
|
-
return Promise.resolve();
|
|
24
|
-
}
|
|
25
|
-
return super.send(message, options);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
function getMockActionFor(message) {
|
|
29
|
-
const m = message;
|
|
30
|
-
if (!m || typeof m !== "object" || !("method" in m)) return null;
|
|
31
|
-
switch (m.method) {
|
|
32
|
-
case "initialize": {
|
|
33
|
-
const protocolVersion = m?.params?.protocolVersion;
|
|
34
|
-
if (!protocolVersion) return null;
|
|
35
|
-
return {
|
|
36
|
-
type: "emit",
|
|
37
|
-
message: {
|
|
38
|
-
result: {
|
|
39
|
-
protocolVersion,
|
|
40
|
-
capabilities: { tools: {} },
|
|
41
|
-
serverInfo: { name: "deco-chat-server", version: "1.0.0" }
|
|
42
|
-
},
|
|
43
|
-
jsonrpc: m.jsonrpc ?? "2.0",
|
|
44
|
-
// @ts-expect-error - id is not typed
|
|
45
|
-
id: m.id
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
case "notifications/roots/list_changed":
|
|
50
|
-
case "notifications/initialized":
|
|
51
|
-
case "notifications/cancelled":
|
|
52
|
-
case "notifications/progress": {
|
|
53
|
-
return { type: "suppress" };
|
|
54
|
-
}
|
|
55
|
-
default:
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// src/core/client/mcp-client.ts
|
|
61
|
-
var Client = class extends Client$1 {
|
|
62
|
-
constructor(_clientInfo, options) {
|
|
63
|
-
super(_clientInfo, options);
|
|
64
|
-
}
|
|
65
|
-
async listTools(params, options) {
|
|
66
|
-
const result = await this.request(
|
|
67
|
-
{ method: "tools/list", params },
|
|
68
|
-
ListToolsResultSchema,
|
|
69
|
-
options
|
|
70
|
-
);
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var createServerClient = async (mcpServer, signal, extraHeaders) => {
|
|
75
|
-
const transport = createTransport(mcpServer.connection, signal, extraHeaders);
|
|
76
|
-
if (!transport) {
|
|
77
|
-
throw new Error("Unknown MCP connection type");
|
|
78
|
-
}
|
|
79
|
-
const client = new Client({
|
|
80
|
-
name: mcpServer?.name ?? "MCP Client",
|
|
81
|
-
version: "1.0.0"
|
|
82
|
-
});
|
|
83
|
-
await client.connect(transport);
|
|
84
|
-
return {
|
|
85
|
-
client,
|
|
86
|
-
callStreamableTool: (tool, args) => {
|
|
87
|
-
if (mcpServer.connection.type !== "HTTP") {
|
|
88
|
-
throw new Error("HTTP connection required");
|
|
89
|
-
}
|
|
90
|
-
return fetch(mcpServer.connection.url + `/call-tool/${tool}`, {
|
|
91
|
-
method: "POST",
|
|
92
|
-
redirect: "manual",
|
|
93
|
-
body: JSON.stringify(args),
|
|
94
|
-
headers: {
|
|
95
|
-
...extraHeaders,
|
|
96
|
-
Authorization: `Bearer ${mcpServer.connection.token}`
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
var createTransport = (connection, signal, extraHeaders) => {
|
|
103
|
-
if (connection.type === "Websocket") {
|
|
104
|
-
return new WebSocketClientTransport(new URL(connection.url));
|
|
105
|
-
}
|
|
106
|
-
if (connection.type !== "SSE" && connection.type !== "HTTP") {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
const authHeaders = connection.token ? { authorization: `Bearer ${connection.token}` } : {};
|
|
110
|
-
const headers = {
|
|
111
|
-
...authHeaders,
|
|
112
|
-
...extraHeaders ?? {},
|
|
113
|
-
..."headers" in connection ? connection.headers || {} : {}
|
|
114
|
-
};
|
|
115
|
-
if (connection.type === "SSE") {
|
|
116
|
-
const config = {
|
|
117
|
-
requestInit: { headers, signal }
|
|
118
|
-
};
|
|
119
|
-
if (connection.token) {
|
|
120
|
-
config.eventSourceInit = {
|
|
121
|
-
fetch: (req, init) => {
|
|
122
|
-
return fetch(req, {
|
|
123
|
-
...init,
|
|
124
|
-
headers: {
|
|
125
|
-
...headers,
|
|
126
|
-
Accept: "text/event-stream"
|
|
127
|
-
},
|
|
128
|
-
signal
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return new SSEClientTransport(new URL(connection.url), config);
|
|
134
|
-
}
|
|
135
|
-
return new HTTPClientTransport(new URL(connection.url), {
|
|
136
|
-
requestInit: {
|
|
137
|
-
headers,
|
|
138
|
-
signal,
|
|
139
|
-
// @ts-ignore - this is a valid option for fetch
|
|
140
|
-
credentials: "include"
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/core/client/proxy.ts
|
|
146
|
-
var safeParse = (content) => {
|
|
147
|
-
try {
|
|
148
|
-
return JSON.parse(content);
|
|
149
|
-
} catch {
|
|
150
|
-
return content;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
var toolsMap = /* @__PURE__ */ new Map();
|
|
154
|
-
function createMCPClientProxy(options) {
|
|
155
|
-
return new Proxy({}, {
|
|
156
|
-
get(_, name) {
|
|
157
|
-
if (name === "toJSON") {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
if (typeof name !== "string") {
|
|
161
|
-
throw new Error("Name must be a string");
|
|
162
|
-
}
|
|
163
|
-
async function callToolFn(args) {
|
|
164
|
-
const debugId = options?.debugId?.();
|
|
165
|
-
const extraHeaders = debugId ? { "x-trace-debug-id": debugId } : void 0;
|
|
166
|
-
const { client, callStreamableTool } = await createServerClient(
|
|
167
|
-
{ connection: options.connection },
|
|
168
|
-
void 0,
|
|
169
|
-
extraHeaders
|
|
170
|
-
);
|
|
171
|
-
if (options?.streamable?.[String(name)]) {
|
|
172
|
-
return callStreamableTool(String(name), args);
|
|
173
|
-
}
|
|
174
|
-
const { structuredContent, isError, content } = await client.callTool(
|
|
175
|
-
{
|
|
176
|
-
name: String(name),
|
|
177
|
-
arguments: args
|
|
178
|
-
},
|
|
179
|
-
void 0,
|
|
180
|
-
{
|
|
181
|
-
timeout: 3e6
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
if (isError) {
|
|
185
|
-
const maybeErrorMessage = content?.[0]?.text;
|
|
186
|
-
const error = typeof maybeErrorMessage === "string" ? safeParse(maybeErrorMessage) : null;
|
|
187
|
-
const throwableError = error?.code && typeof options?.getErrorByStatusCode === "function" ? options.getErrorByStatusCode(
|
|
188
|
-
error.code,
|
|
189
|
-
error.message,
|
|
190
|
-
error.traceId
|
|
191
|
-
) : null;
|
|
192
|
-
if (throwableError) {
|
|
193
|
-
throw throwableError;
|
|
194
|
-
}
|
|
195
|
-
throw new Error(
|
|
196
|
-
`Tool ${String(name)} returned an error: ${JSON.stringify(
|
|
197
|
-
structuredContent ?? content
|
|
198
|
-
)}`
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
return structuredContent;
|
|
202
|
-
}
|
|
203
|
-
const listToolsFn = async () => {
|
|
204
|
-
const { client } = await createServerClient({
|
|
205
|
-
connection: options.connection
|
|
206
|
-
});
|
|
207
|
-
const { tools } = await client.listTools();
|
|
208
|
-
return tools;
|
|
209
|
-
};
|
|
210
|
-
async function listToolsOnce() {
|
|
211
|
-
const conn = options.connection;
|
|
212
|
-
const key = JSON.stringify(conn);
|
|
213
|
-
try {
|
|
214
|
-
if (!toolsMap.has(key)) {
|
|
215
|
-
toolsMap.set(key, listToolsFn());
|
|
216
|
-
}
|
|
217
|
-
return await toolsMap.get(key);
|
|
218
|
-
} catch (error) {
|
|
219
|
-
console.error("Failed to list tools", error);
|
|
220
|
-
toolsMap.delete(key);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
callToolFn.asTool = async () => {
|
|
225
|
-
const tools = await listToolsOnce() ?? [];
|
|
226
|
-
const tool = tools.find((t) => t.name === name);
|
|
227
|
-
if (!tool) {
|
|
228
|
-
throw new Error(`Tool ${name} not found`);
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
...tool,
|
|
232
|
-
id: tool.name,
|
|
233
|
-
inputSchema: tool.inputSchema ? convertJsonSchemaToZod(tool.inputSchema) : void 0,
|
|
234
|
-
outputSchema: tool.outputSchema ? convertJsonSchemaToZod(tool.outputSchema) : void 0,
|
|
235
|
-
execute: (input) => {
|
|
236
|
-
return callToolFn(input.context);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
return callToolFn;
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// src/core/client/mcp.ts
|
|
246
|
-
new Proxy(
|
|
247
|
-
{},
|
|
248
|
-
{
|
|
249
|
-
get(_, name) {
|
|
250
|
-
if (name === "toJSON") {
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
if (name === "forConnection") {
|
|
254
|
-
return (connection) => createMCPFetchStub({
|
|
255
|
-
connection
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
return global[name];
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
);
|
|
262
|
-
function createMCPFetchStub(options) {
|
|
263
|
-
return createMCPClientProxy(options);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// src/core/binder.ts
|
|
267
|
-
function normalizeSchema(schema) {
|
|
268
|
-
if (!schema) return void 0;
|
|
269
|
-
if (schema._def) {
|
|
270
|
-
const jsonSchema2 = zodToJsonSchema(schema, {
|
|
271
|
-
// Don't add additionalProperties: false to allow structural compatibility
|
|
272
|
-
$refStrategy: "none"
|
|
273
|
-
});
|
|
274
|
-
if (jsonSchema2.type === "object") {
|
|
275
|
-
delete jsonSchema2.additionalProperties;
|
|
276
|
-
}
|
|
277
|
-
return jsonSchema2;
|
|
278
|
-
}
|
|
279
|
-
const jsonSchema = schema;
|
|
280
|
-
if (jsonSchema.type === "object" && "additionalProperties" in jsonSchema) {
|
|
281
|
-
const copy = { ...jsonSchema };
|
|
282
|
-
delete copy.additionalProperties;
|
|
283
|
-
return copy;
|
|
284
|
-
}
|
|
285
|
-
return jsonSchema;
|
|
286
|
-
}
|
|
287
|
-
var bindingClient = (binder) => {
|
|
288
|
-
return {
|
|
289
|
-
...createBindingChecker(binder),
|
|
290
|
-
forConnection: (mcpConnection) => {
|
|
291
|
-
return createMCPFetchStub({
|
|
292
|
-
connection: mcpConnection,
|
|
293
|
-
streamable: binder.reduce(
|
|
294
|
-
(acc, tool) => {
|
|
295
|
-
acc[tool.name] = tool.streamable === true;
|
|
296
|
-
return acc;
|
|
297
|
-
},
|
|
298
|
-
{}
|
|
299
|
-
)
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
function createBindingChecker(binderTools) {
|
|
305
|
-
return {
|
|
306
|
-
isImplementedBy: async (tools) => {
|
|
307
|
-
for (const binderTool of binderTools) {
|
|
308
|
-
const pattern = typeof binderTool.name === "string" ? new RegExp(`^${binderTool.name}$`) : binderTool.name;
|
|
309
|
-
const matchedTool = tools.find((t) => pattern.test(t.name));
|
|
310
|
-
if (!matchedTool && binderTool.opt) {
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
if (!matchedTool) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
const binderInputSchema = normalizeSchema(binderTool.inputSchema);
|
|
317
|
-
const toolInputSchema = normalizeSchema(matchedTool.inputSchema);
|
|
318
|
-
if (binderInputSchema && toolInputSchema) {
|
|
319
|
-
try {
|
|
320
|
-
const inputDiff = await diffSchemas({
|
|
321
|
-
sourceSchema: binderInputSchema,
|
|
322
|
-
destinationSchema: toolInputSchema
|
|
323
|
-
});
|
|
324
|
-
if (inputDiff.removalsFound) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
} catch (error) {
|
|
328
|
-
console.error("Schema diff failed", error);
|
|
329
|
-
return false;
|
|
330
|
-
}
|
|
331
|
-
} else if (binderInputSchema && !toolInputSchema) {
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
const binderOutputSchema = normalizeSchema(binderTool.outputSchema);
|
|
335
|
-
const toolOutputSchema = normalizeSchema(matchedTool.outputSchema);
|
|
336
|
-
if (binderOutputSchema && toolOutputSchema) {
|
|
337
|
-
try {
|
|
338
|
-
const outputDiff = await diffSchemas({
|
|
339
|
-
sourceSchema: binderOutputSchema,
|
|
340
|
-
destinationSchema: toolOutputSchema
|
|
341
|
-
});
|
|
342
|
-
if (outputDiff.removalsFound) {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
} catch (error) {
|
|
346
|
-
console.error("Schema diff failed", error);
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
} else if (binderOutputSchema && !toolOutputSchema) {
|
|
350
|
-
return false;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return true;
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
var BaseCollectionEntitySchema = z.object({
|
|
358
|
-
id: z.string().describe("Unique identifier for the entity"),
|
|
359
|
-
title: z.string().describe("Human-readable title for the entity"),
|
|
360
|
-
created_at: z.string().datetime(),
|
|
361
|
-
updated_at: z.string().datetime(),
|
|
362
|
-
created_by: z.string().optional(),
|
|
363
|
-
updated_by: z.string().optional()
|
|
364
|
-
});
|
|
365
|
-
var ComparisonExpressionSchema = z.object({
|
|
366
|
-
field: z.array(z.string()),
|
|
367
|
-
operator: z.enum(["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]),
|
|
368
|
-
value: z.unknown()
|
|
369
|
-
});
|
|
370
|
-
var WhereExpressionSchema = z.union([
|
|
371
|
-
ComparisonExpressionSchema,
|
|
372
|
-
z.object({
|
|
373
|
-
operator: z.enum(["and", "or", "not"]),
|
|
374
|
-
conditions: z.array(ComparisonExpressionSchema)
|
|
375
|
-
})
|
|
376
|
-
]);
|
|
377
|
-
var OrderByExpressionSchema = z.object({
|
|
378
|
-
field: z.array(z.string()),
|
|
379
|
-
direction: z.enum(["asc", "desc"]),
|
|
380
|
-
nulls: z.enum(["first", "last"]).optional()
|
|
381
|
-
});
|
|
382
|
-
var CollectionListInputSchema = z.object({
|
|
383
|
-
where: WhereExpressionSchema.optional().describe("Filter expression"),
|
|
384
|
-
orderBy: z.array(OrderByExpressionSchema).optional().describe("Sort expressions"),
|
|
385
|
-
limit: z.number().int().min(1).max(1e3).optional().describe("Maximum number of items to return"),
|
|
386
|
-
offset: z.number().int().min(0).optional().describe("Number of items to skip")
|
|
387
|
-
});
|
|
388
|
-
function createCollectionListOutputSchema(entitySchema) {
|
|
389
|
-
return z.object({
|
|
390
|
-
items: z.array(entitySchema).describe("Array of collection items"),
|
|
391
|
-
totalCount: z.number().int().min(0).optional().describe("Total number of matching items (if available)"),
|
|
392
|
-
hasMore: z.boolean().optional().describe("Whether there are more items available")
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
var CollectionGetInputSchema = z.object({
|
|
396
|
-
id: z.string().describe("ID of the entity to retrieve")
|
|
397
|
-
});
|
|
398
|
-
function createCollectionGetOutputSchema(entitySchema) {
|
|
399
|
-
return z.object({
|
|
400
|
-
item: entitySchema.nullable().describe("The retrieved item, or null if not found")
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
z.object({
|
|
404
|
-
id: z.string().describe("ID of the entity to delete")
|
|
405
|
-
});
|
|
406
|
-
function createCollectionBindings(collectionName, entitySchema, options) {
|
|
407
|
-
const upperName = collectionName.toUpperCase();
|
|
408
|
-
const bindings = [
|
|
409
|
-
{
|
|
410
|
-
name: `COLLECTION_${upperName}_LIST`,
|
|
411
|
-
inputSchema: CollectionListInputSchema,
|
|
412
|
-
outputSchema: createCollectionListOutputSchema(entitySchema)
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
name: `COLLECTION_${upperName}_GET`,
|
|
416
|
-
inputSchema: CollectionGetInputSchema,
|
|
417
|
-
outputSchema: createCollectionGetOutputSchema(entitySchema)
|
|
418
|
-
}
|
|
419
|
-
];
|
|
420
|
-
return bindings;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// src/well-known/models.ts
|
|
424
|
-
var ModelSchema = BaseCollectionEntitySchema.extend({
|
|
425
|
-
// Model-specific fields
|
|
426
|
-
logo: z.string().nullable(),
|
|
427
|
-
description: z.string().nullable(),
|
|
428
|
-
capabilities: z.array(z.string()),
|
|
429
|
-
limits: z.object({
|
|
430
|
-
contextWindow: z.number(),
|
|
431
|
-
maxOutputTokens: z.number()
|
|
432
|
-
}).nullable(),
|
|
433
|
-
costs: z.object({
|
|
434
|
-
input: z.number(),
|
|
435
|
-
output: z.number()
|
|
436
|
-
}).nullable(),
|
|
437
|
-
// Provider information
|
|
438
|
-
provider: z.enum([
|
|
439
|
-
"openai",
|
|
440
|
-
"anthropic",
|
|
441
|
-
"google",
|
|
442
|
-
"xai",
|
|
443
|
-
"deepseek",
|
|
444
|
-
"openai-compatible",
|
|
445
|
-
"openrouter"
|
|
446
|
-
]).nullable(),
|
|
447
|
-
// Streaming endpoint information
|
|
448
|
-
endpoint: z.object({
|
|
449
|
-
url: z.string().url(),
|
|
450
|
-
method: z.string().default("POST"),
|
|
451
|
-
contentType: z.string().default("application/json"),
|
|
452
|
-
stream: z.boolean().default(true)
|
|
453
|
-
}).nullable()
|
|
454
|
-
});
|
|
455
|
-
var MODELS_COLLECTION_BINDING = createCollectionBindings(
|
|
456
|
-
"models",
|
|
457
|
-
ModelSchema);
|
|
458
|
-
var MODELS_BINDING = [
|
|
459
|
-
...MODELS_COLLECTION_BINDING
|
|
460
|
-
];
|
|
461
|
-
|
|
462
|
-
// src/well-known/language-model.ts
|
|
463
|
-
var LanguageModelCallOptionsSchema = z.object({
|
|
464
|
-
// Core parameters
|
|
465
|
-
prompt: z.any().describe(
|
|
466
|
-
"A language mode prompt is a standardized prompt type (messages, system, etc.)"
|
|
467
|
-
),
|
|
468
|
-
// Generation parameters
|
|
469
|
-
maxOutputTokens: z.number().optional().describe("Maximum number of tokens to generate"),
|
|
470
|
-
temperature: z.number().optional().describe(
|
|
471
|
-
"Temperature setting. The range depends on the provider and model"
|
|
472
|
-
),
|
|
473
|
-
topP: z.number().optional().describe("Nucleus sampling parameter"),
|
|
474
|
-
topK: z.number().optional().describe(
|
|
475
|
-
"Only sample from the top K options for each subsequent token. Used to remove long tail low probability responses"
|
|
476
|
-
),
|
|
477
|
-
presencePenalty: z.number().optional().describe(
|
|
478
|
-
"Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt"
|
|
479
|
-
),
|
|
480
|
-
frequencyPenalty: z.number().optional().describe(
|
|
481
|
-
"Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases"
|
|
482
|
-
),
|
|
483
|
-
seed: z.number().optional().describe(
|
|
484
|
-
"The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results"
|
|
485
|
-
),
|
|
486
|
-
// Stop sequences
|
|
487
|
-
stopSequences: z.array(z.string()).optional().describe(
|
|
488
|
-
"Stop sequences. If set, the model will stop generating text when one of the stop sequences is generated"
|
|
489
|
-
),
|
|
490
|
-
// Response format
|
|
491
|
-
responseFormat: z.union([
|
|
492
|
-
z.object({ type: z.literal("text") }),
|
|
493
|
-
z.object({
|
|
494
|
-
type: z.literal("json"),
|
|
495
|
-
schema: z.any().optional().describe("JSON schema that the generated output should conform to"),
|
|
496
|
-
name: z.string().optional().describe("Name of output that should be generated"),
|
|
497
|
-
description: z.string().optional().describe("Description of the output that should be generated")
|
|
498
|
-
})
|
|
499
|
-
]).optional().describe(
|
|
500
|
-
"Response format. The output can either be text or JSON. Default is text"
|
|
501
|
-
),
|
|
502
|
-
// Tools
|
|
503
|
-
tools: z.array(z.any()).optional().describe("The tools that are available for the model"),
|
|
504
|
-
toolChoice: z.any().optional().describe("Specifies how the tool should be selected. Defaults to 'auto'"),
|
|
505
|
-
// Stream options
|
|
506
|
-
includeRawChunks: z.boolean().optional().describe(
|
|
507
|
-
"Include raw chunks in the stream. Only applicable for streaming calls"
|
|
508
|
-
),
|
|
509
|
-
// Abort signal
|
|
510
|
-
abortSignal: z.any().optional().describe("Abort signal for cancelling the operation"),
|
|
511
|
-
// Additional options
|
|
512
|
-
headers: z.record(z.string(), z.union([z.string(), z.undefined()])).optional().describe("Additional HTTP headers to be sent with the request"),
|
|
513
|
-
providerOptions: z.any().optional().describe("Additional provider-specific options")
|
|
514
|
-
});
|
|
515
|
-
var LanguageModelGenerateOutputSchema = z.object({
|
|
516
|
-
// Ordered content that the model has generated
|
|
517
|
-
content: z.array(z.any()).describe(
|
|
518
|
-
"Ordered content that the model has generated (text, tool-calls, reasoning, files, sources)"
|
|
519
|
-
),
|
|
520
|
-
// Finish reason (required)
|
|
521
|
-
finishReason: z.enum([
|
|
522
|
-
"stop",
|
|
523
|
-
"length",
|
|
524
|
-
"content-filter",
|
|
525
|
-
"tool-calls",
|
|
526
|
-
"error",
|
|
527
|
-
"other",
|
|
528
|
-
"unknown"
|
|
529
|
-
]).describe("Reason why generation stopped"),
|
|
530
|
-
// Usage information (required)
|
|
531
|
-
usage: z.object({
|
|
532
|
-
inputTokens: z.number().optional(),
|
|
533
|
-
outputTokens: z.number().optional(),
|
|
534
|
-
totalTokens: z.number().optional(),
|
|
535
|
-
reasoningTokens: z.number().optional()
|
|
536
|
-
}).passthrough().transform((val) => ({
|
|
537
|
-
inputTokens: val.inputTokens,
|
|
538
|
-
outputTokens: val.outputTokens,
|
|
539
|
-
totalTokens: val.totalTokens,
|
|
540
|
-
reasoningTokens: val.reasoningTokens,
|
|
541
|
-
...val
|
|
542
|
-
})).describe("Usage information for the language model call"),
|
|
543
|
-
// Provider metadata
|
|
544
|
-
providerMetadata: z.any().optional().describe("Additional provider-specific metadata"),
|
|
545
|
-
// Request information for telemetry and debugging
|
|
546
|
-
request: z.object({
|
|
547
|
-
body: z.any().optional().describe("Request HTTP body sent to the provider API")
|
|
548
|
-
}).optional().describe("Optional request information for telemetry and debugging"),
|
|
549
|
-
// Response information for telemetry and debugging
|
|
550
|
-
response: z.object({
|
|
551
|
-
id: z.string().optional().describe("ID for the generated response"),
|
|
552
|
-
timestamp: z.date().optional().describe("Timestamp for the start of the generated response"),
|
|
553
|
-
modelId: z.string().optional().describe("The ID of the response model that was used"),
|
|
554
|
-
headers: z.record(z.string(), z.string()).optional().describe("Response headers"),
|
|
555
|
-
body: z.any().optional().describe("Response HTTP body")
|
|
556
|
-
}).optional().describe("Optional response information for telemetry and debugging"),
|
|
557
|
-
// Warnings for the call (required)
|
|
558
|
-
warnings: z.array(z.any()).describe("Warnings for the call, e.g. unsupported settings")
|
|
559
|
-
});
|
|
560
|
-
var LanguageModelStreamOutputSchema = z.object({
|
|
561
|
-
// Stream of language model output parts
|
|
562
|
-
stream: z.any().describe("ReadableStream of LanguageModelV2StreamPart"),
|
|
563
|
-
// Request information for telemetry and debugging
|
|
564
|
-
request: z.object({
|
|
565
|
-
body: z.any().optional().describe("Request HTTP body sent to the provider API")
|
|
566
|
-
}).optional().describe("Optional request information for telemetry and debugging"),
|
|
567
|
-
// Response information
|
|
568
|
-
response: z.object({
|
|
569
|
-
headers: z.record(z.string(), z.string()).optional().describe("Response headers")
|
|
570
|
-
}).optional().describe("Optional response data")
|
|
571
|
-
});
|
|
572
|
-
var LanguageModelMetadataSchema = z.object({
|
|
573
|
-
supportedUrls: z.record(z.string(), z.array(z.string())).describe("Supported URL patterns by media type for the provider")
|
|
574
|
-
});
|
|
575
|
-
var ModelSchema2 = z.object({
|
|
576
|
-
modelId: z.string().describe("The ID of the model"),
|
|
577
|
-
// Model-specific fields
|
|
578
|
-
logo: z.string().nullable(),
|
|
579
|
-
description: z.string().nullable(),
|
|
580
|
-
capabilities: z.array(z.string()),
|
|
581
|
-
limits: z.object({
|
|
582
|
-
contextWindow: z.number(),
|
|
583
|
-
maxOutputTokens: z.number()
|
|
584
|
-
}).nullable(),
|
|
585
|
-
costs: z.object({
|
|
586
|
-
input: z.number(),
|
|
587
|
-
output: z.number()
|
|
588
|
-
}).nullable(),
|
|
589
|
-
// Provider information
|
|
590
|
-
provider: z.enum([
|
|
591
|
-
"openai",
|
|
592
|
-
"anthropic",
|
|
593
|
-
"google",
|
|
594
|
-
"xai",
|
|
595
|
-
"deepseek",
|
|
596
|
-
"openai-compatible",
|
|
597
|
-
"openrouter"
|
|
598
|
-
]).nullable()
|
|
599
|
-
});
|
|
600
|
-
var LanguageModelInputSchema = z.object({
|
|
601
|
-
modelId: z.string().describe("The ID of the model"),
|
|
602
|
-
callOptions: LanguageModelCallOptionsSchema
|
|
603
|
-
});
|
|
604
|
-
var LANGUAGE_MODEL_BINDING = [
|
|
605
|
-
{
|
|
606
|
-
name: "LLM_METADATA",
|
|
607
|
-
inputSchema: z.object({
|
|
608
|
-
modelId: z.string().describe("The ID of the model")
|
|
609
|
-
}),
|
|
610
|
-
outputSchema: LanguageModelMetadataSchema
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
name: "LLM_DO_STREAM",
|
|
614
|
-
inputSchema: LanguageModelInputSchema,
|
|
615
|
-
streamable: true
|
|
616
|
-
},
|
|
617
|
-
{
|
|
618
|
-
name: "LLM_DO_GENERATE",
|
|
619
|
-
inputSchema: LanguageModelInputSchema,
|
|
620
|
-
outputSchema: LanguageModelGenerateOutputSchema
|
|
621
|
-
},
|
|
622
|
-
...MODELS_BINDING
|
|
623
|
-
];
|
|
624
|
-
var LanguageModelBinding = bindingClient(LANGUAGE_MODEL_BINDING);
|
|
625
|
-
|
|
626
|
-
export { LANGUAGE_MODEL_BINDING, LanguageModelBinding, LanguageModelCallOptionsSchema, LanguageModelGenerateOutputSchema, LanguageModelInputSchema, LanguageModelMetadataSchema, LanguageModelStreamOutputSchema, ModelSchema2 as ModelSchema };
|
|
627
|
-
//# sourceMappingURL=language-model.js.map
|
|
628
|
-
//# sourceMappingURL=language-model.js.map
|