@decocms/runtime 0.25.1 → 0.27.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bindings/deconfig/index.d.ts +6 -5
- package/dist/bindings/deconfig/index.js +4 -4
- package/dist/bindings/index.d.ts +1286 -28
- package/dist/bindings/index.js +9 -7
- package/dist/bindings/index.js.map +1 -1
- package/dist/{chunk-F6XZPFWM.js → chunk-3AWMDSOH.js} +20 -51
- package/dist/chunk-3AWMDSOH.js.map +1 -0
- package/dist/{chunk-QELHWEZH.js → chunk-5EYZ2LVM.js} +8 -5
- package/dist/chunk-5EYZ2LVM.js.map +1 -0
- package/dist/{chunk-O6IURJAY.js → chunk-GPIGZ6DL.js} +38 -33
- package/dist/chunk-GPIGZ6DL.js.map +1 -0
- package/dist/{chunk-I2KGAHFY.js → chunk-LCU3FBI3.js} +6 -2
- package/dist/chunk-LCU3FBI3.js.map +1 -0
- package/dist/drizzle.d.ts +4 -3
- package/dist/{index-SnnmAI05.d.ts → index-6dtc1EK6.d.ts} +14 -14
- package/dist/{index-D8GtUDPS.d.ts → index-COMJ3oN7.d.ts} +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -5
- package/dist/mastra.d.ts +4 -3
- package/dist/mastra.js +1 -1
- package/dist/{mcp-Bv7IAgWX.d.ts → mcp-Dbqp-p04.d.ts} +9 -13
- package/dist/mcp-client.d.ts +10 -14
- package/dist/mcp-client.js +1 -1
- package/dist/proxy.d.ts +3 -2
- package/dist/proxy.js +2 -2
- package/dist/resources.d.ts +38 -38
- package/dist/views.d.ts +6 -6
- package/package.json +3 -1
- package/src/bindings/binder.ts +37 -34
- package/src/bindings/channels.ts +1 -1
- package/src/bindings/index.ts +8 -6
- package/src/bindings/language-model/ai-sdk.ts +87 -0
- package/src/bindings/language-model/index.ts +4 -0
- package/src/bindings/language-model/utils.ts +118 -0
- package/src/bindings/views.ts +1 -1
- package/src/connection.ts +8 -53
- package/src/http-client-transport.ts +1 -66
- package/src/mastra.ts +4 -0
- package/src/mcp-client.ts +22 -2
- package/src/mcp.ts +16 -17
- package/src/proxy.ts +6 -2
- package/dist/chunk-F6XZPFWM.js.map +0 -1
- package/dist/chunk-I2KGAHFY.js.map +0 -1
- package/dist/chunk-O6IURJAY.js.map +0 -1
- package/dist/chunk-QELHWEZH.js.map +0 -1
- package/dist/connection-DDtQYrea.d.ts +0 -30
package/dist/resources.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ declare const ResourcesReadInputSchema: z.ZodObject<{
|
|
|
4
4
|
name: z.ZodString;
|
|
5
5
|
uri: z.ZodString;
|
|
6
6
|
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
name: string;
|
|
8
7
|
uri: string;
|
|
9
|
-
}, {
|
|
10
8
|
name: string;
|
|
9
|
+
}, {
|
|
11
10
|
uri: string;
|
|
11
|
+
name: string;
|
|
12
12
|
}>;
|
|
13
13
|
declare const ResourcesReadOutputSchema: z.ZodObject<{
|
|
14
14
|
name: z.ZodString;
|
|
@@ -24,25 +24,25 @@ declare const ResourcesReadOutputSchema: z.ZodObject<{
|
|
|
24
24
|
data: z.ZodString;
|
|
25
25
|
type: z.ZodEnum<["text", "blob"]>;
|
|
26
26
|
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
uri: string;
|
|
27
28
|
type: "text" | "blob";
|
|
28
29
|
name: string;
|
|
29
30
|
data: string;
|
|
30
|
-
uri: string;
|
|
31
|
-
description?: string | undefined;
|
|
32
31
|
mimeType?: string | undefined;
|
|
33
32
|
title?: string | undefined;
|
|
33
|
+
description?: string | undefined;
|
|
34
34
|
annotations?: Record<string, string> | undefined;
|
|
35
35
|
thumbnail?: string | undefined;
|
|
36
36
|
timestamp?: string | undefined;
|
|
37
37
|
size?: number | undefined;
|
|
38
38
|
}, {
|
|
39
|
+
uri: string;
|
|
39
40
|
type: "text" | "blob";
|
|
40
41
|
name: string;
|
|
41
42
|
data: string;
|
|
42
|
-
uri: string;
|
|
43
|
-
description?: string | undefined;
|
|
44
43
|
mimeType?: string | undefined;
|
|
45
44
|
title?: string | undefined;
|
|
45
|
+
description?: string | undefined;
|
|
46
46
|
annotations?: Record<string, string> | undefined;
|
|
47
47
|
thumbnail?: string | undefined;
|
|
48
48
|
timestamp?: string | undefined;
|
|
@@ -76,21 +76,21 @@ declare const ResourceSearchOutputSchema: z.ZodObject<{
|
|
|
76
76
|
size: z.ZodOptional<z.ZodNumber>;
|
|
77
77
|
annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
78
78
|
}, "strip", z.ZodTypeAny, {
|
|
79
|
-
name: string;
|
|
80
79
|
uri: string;
|
|
81
|
-
|
|
80
|
+
name: string;
|
|
82
81
|
mimeType?: string | undefined;
|
|
83
82
|
title?: string | undefined;
|
|
83
|
+
description?: string | undefined;
|
|
84
84
|
annotations?: Record<string, string> | undefined;
|
|
85
85
|
thumbnail?: string | undefined;
|
|
86
86
|
timestamp?: string | undefined;
|
|
87
87
|
size?: number | undefined;
|
|
88
88
|
}, {
|
|
89
|
-
name: string;
|
|
90
89
|
uri: string;
|
|
91
|
-
|
|
90
|
+
name: string;
|
|
92
91
|
mimeType?: string | undefined;
|
|
93
92
|
title?: string | undefined;
|
|
93
|
+
description?: string | undefined;
|
|
94
94
|
annotations?: Record<string, string> | undefined;
|
|
95
95
|
thumbnail?: string | undefined;
|
|
96
96
|
timestamp?: string | undefined;
|
|
@@ -100,11 +100,11 @@ declare const ResourceSearchOutputSchema: z.ZodObject<{
|
|
|
100
100
|
nextCursor: z.ZodOptional<z.ZodString>;
|
|
101
101
|
}, "strip", z.ZodTypeAny, {
|
|
102
102
|
items: {
|
|
103
|
-
name: string;
|
|
104
103
|
uri: string;
|
|
105
|
-
|
|
104
|
+
name: string;
|
|
106
105
|
mimeType?: string | undefined;
|
|
107
106
|
title?: string | undefined;
|
|
107
|
+
description?: string | undefined;
|
|
108
108
|
annotations?: Record<string, string> | undefined;
|
|
109
109
|
thumbnail?: string | undefined;
|
|
110
110
|
timestamp?: string | undefined;
|
|
@@ -114,11 +114,11 @@ declare const ResourceSearchOutputSchema: z.ZodObject<{
|
|
|
114
114
|
nextCursor?: string | undefined;
|
|
115
115
|
}, {
|
|
116
116
|
items: {
|
|
117
|
-
name: string;
|
|
118
117
|
uri: string;
|
|
119
|
-
|
|
118
|
+
name: string;
|
|
120
119
|
mimeType?: string | undefined;
|
|
121
120
|
title?: string | undefined;
|
|
121
|
+
description?: string | undefined;
|
|
122
122
|
annotations?: Record<string, string> | undefined;
|
|
123
123
|
thumbnail?: string | undefined;
|
|
124
124
|
timestamp?: string | undefined;
|
|
@@ -148,26 +148,26 @@ declare const ResourceCreateInputSchema: z.ZodObject<{
|
|
|
148
148
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
149
149
|
}, "strip", z.ZodTypeAny, {
|
|
150
150
|
name: string;
|
|
151
|
-
resourceName: string;
|
|
152
151
|
content: {
|
|
153
152
|
type: "text" | "blob";
|
|
154
153
|
data: string;
|
|
155
154
|
mimeType?: string | undefined;
|
|
156
155
|
};
|
|
157
|
-
|
|
156
|
+
resourceName: string;
|
|
158
157
|
metadata?: Record<string, any> | undefined;
|
|
159
158
|
title?: string | undefined;
|
|
159
|
+
description?: string | undefined;
|
|
160
160
|
}, {
|
|
161
161
|
name: string;
|
|
162
|
-
resourceName: string;
|
|
163
162
|
content: {
|
|
164
163
|
type: "text" | "blob";
|
|
165
164
|
data: string;
|
|
166
165
|
mimeType?: string | undefined;
|
|
167
166
|
};
|
|
168
|
-
|
|
167
|
+
resourceName: string;
|
|
169
168
|
metadata?: Record<string, any> | undefined;
|
|
170
169
|
title?: string | undefined;
|
|
170
|
+
description?: string | undefined;
|
|
171
171
|
}>;
|
|
172
172
|
declare const ResourceCreateOutputSchema: z.ZodObject<{
|
|
173
173
|
name: z.ZodString;
|
|
@@ -180,21 +180,21 @@ declare const ResourceCreateOutputSchema: z.ZodObject<{
|
|
|
180
180
|
size: z.ZodOptional<z.ZodNumber>;
|
|
181
181
|
annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
182
182
|
}, "strip", z.ZodTypeAny, {
|
|
183
|
-
name: string;
|
|
184
183
|
uri: string;
|
|
185
|
-
|
|
184
|
+
name: string;
|
|
186
185
|
mimeType?: string | undefined;
|
|
187
186
|
title?: string | undefined;
|
|
187
|
+
description?: string | undefined;
|
|
188
188
|
annotations?: Record<string, string> | undefined;
|
|
189
189
|
thumbnail?: string | undefined;
|
|
190
190
|
timestamp?: string | undefined;
|
|
191
191
|
size?: number | undefined;
|
|
192
192
|
}, {
|
|
193
|
-
name: string;
|
|
194
193
|
uri: string;
|
|
195
|
-
|
|
194
|
+
name: string;
|
|
196
195
|
mimeType?: string | undefined;
|
|
197
196
|
title?: string | undefined;
|
|
197
|
+
description?: string | undefined;
|
|
198
198
|
annotations?: Record<string, string> | undefined;
|
|
199
199
|
thumbnail?: string | undefined;
|
|
200
200
|
timestamp?: string | undefined;
|
|
@@ -221,10 +221,8 @@ declare const ResourceUpdateInputSchema: z.ZodObject<{
|
|
|
221
221
|
}>>;
|
|
222
222
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
223
223
|
}, "strip", z.ZodTypeAny, {
|
|
224
|
-
name: string;
|
|
225
224
|
uri: string;
|
|
226
|
-
|
|
227
|
-
resourceName?: string | undefined;
|
|
225
|
+
name: string;
|
|
228
226
|
metadata?: Record<string, any> | undefined;
|
|
229
227
|
content?: {
|
|
230
228
|
type: "text" | "blob";
|
|
@@ -232,11 +230,11 @@ declare const ResourceUpdateInputSchema: z.ZodObject<{
|
|
|
232
230
|
mimeType?: string | undefined;
|
|
233
231
|
} | undefined;
|
|
234
232
|
title?: string | undefined;
|
|
235
|
-
}, {
|
|
236
|
-
name: string;
|
|
237
|
-
uri: string;
|
|
238
233
|
description?: string | undefined;
|
|
239
234
|
resourceName?: string | undefined;
|
|
235
|
+
}, {
|
|
236
|
+
uri: string;
|
|
237
|
+
name: string;
|
|
240
238
|
metadata?: Record<string, any> | undefined;
|
|
241
239
|
content?: {
|
|
242
240
|
type: "text" | "blob";
|
|
@@ -244,6 +242,8 @@ declare const ResourceUpdateInputSchema: z.ZodObject<{
|
|
|
244
242
|
mimeType?: string | undefined;
|
|
245
243
|
} | undefined;
|
|
246
244
|
title?: string | undefined;
|
|
245
|
+
description?: string | undefined;
|
|
246
|
+
resourceName?: string | undefined;
|
|
247
247
|
}>;
|
|
248
248
|
declare const ResourceUpdateOutputSchema: z.ZodObject<{
|
|
249
249
|
name: z.ZodString;
|
|
@@ -256,21 +256,21 @@ declare const ResourceUpdateOutputSchema: z.ZodObject<{
|
|
|
256
256
|
size: z.ZodOptional<z.ZodNumber>;
|
|
257
257
|
annotations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
258
258
|
}, "strip", z.ZodTypeAny, {
|
|
259
|
-
name: string;
|
|
260
259
|
uri: string;
|
|
261
|
-
|
|
260
|
+
name: string;
|
|
262
261
|
mimeType?: string | undefined;
|
|
263
262
|
title?: string | undefined;
|
|
263
|
+
description?: string | undefined;
|
|
264
264
|
annotations?: Record<string, string> | undefined;
|
|
265
265
|
thumbnail?: string | undefined;
|
|
266
266
|
timestamp?: string | undefined;
|
|
267
267
|
size?: number | undefined;
|
|
268
268
|
}, {
|
|
269
|
-
name: string;
|
|
270
269
|
uri: string;
|
|
271
|
-
|
|
270
|
+
name: string;
|
|
272
271
|
mimeType?: string | undefined;
|
|
273
272
|
title?: string | undefined;
|
|
273
|
+
description?: string | undefined;
|
|
274
274
|
annotations?: Record<string, string> | undefined;
|
|
275
275
|
thumbnail?: string | undefined;
|
|
276
276
|
timestamp?: string | undefined;
|
|
@@ -281,12 +281,12 @@ declare const ResourceDeleteInputSchema: z.ZodObject<{
|
|
|
281
281
|
uri: z.ZodString;
|
|
282
282
|
force: z.ZodOptional<z.ZodBoolean>;
|
|
283
283
|
}, "strip", z.ZodTypeAny, {
|
|
284
|
-
name: string;
|
|
285
284
|
uri: string;
|
|
285
|
+
name: string;
|
|
286
286
|
force?: boolean | undefined;
|
|
287
287
|
}, {
|
|
288
|
-
name: string;
|
|
289
288
|
uri: string;
|
|
289
|
+
name: string;
|
|
290
290
|
force?: boolean | undefined;
|
|
291
291
|
}>;
|
|
292
292
|
declare const ResourceDeleteOutputSchema: z.ZodObject<{
|
|
@@ -308,16 +308,16 @@ declare const ResourcesListOutputSchema: z.ZodObject<{
|
|
|
308
308
|
hasDelete: z.ZodOptional<z.ZodBoolean>;
|
|
309
309
|
}, "strip", z.ZodTypeAny, {
|
|
310
310
|
name: string;
|
|
311
|
-
description: string;
|
|
312
311
|
title: string;
|
|
312
|
+
description: string;
|
|
313
313
|
icon: string;
|
|
314
314
|
hasCreate?: boolean | undefined;
|
|
315
315
|
hasUpdate?: boolean | undefined;
|
|
316
316
|
hasDelete?: boolean | undefined;
|
|
317
317
|
}, {
|
|
318
318
|
name: string;
|
|
319
|
-
description: string;
|
|
320
319
|
title: string;
|
|
320
|
+
description: string;
|
|
321
321
|
icon: string;
|
|
322
322
|
hasCreate?: boolean | undefined;
|
|
323
323
|
hasUpdate?: boolean | undefined;
|
|
@@ -326,8 +326,8 @@ declare const ResourcesListOutputSchema: z.ZodObject<{
|
|
|
326
326
|
}, "strip", z.ZodTypeAny, {
|
|
327
327
|
resources: {
|
|
328
328
|
name: string;
|
|
329
|
-
description: string;
|
|
330
329
|
title: string;
|
|
330
|
+
description: string;
|
|
331
331
|
icon: string;
|
|
332
332
|
hasCreate?: boolean | undefined;
|
|
333
333
|
hasUpdate?: boolean | undefined;
|
|
@@ -336,8 +336,8 @@ declare const ResourcesListOutputSchema: z.ZodObject<{
|
|
|
336
336
|
}, {
|
|
337
337
|
resources: {
|
|
338
338
|
name: string;
|
|
339
|
-
description: string;
|
|
340
339
|
title: string;
|
|
340
|
+
description: string;
|
|
341
341
|
icon: string;
|
|
342
342
|
hasCreate?: boolean | undefined;
|
|
343
343
|
hasUpdate?: boolean | undefined;
|
package/dist/views.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ declare const ViewsListOutputSchema: z.ZodObject<{
|
|
|
18
18
|
title: string;
|
|
19
19
|
icon: string;
|
|
20
20
|
id?: string | undefined;
|
|
21
|
-
name?: string | undefined;
|
|
22
21
|
url?: string | undefined;
|
|
22
|
+
name?: string | undefined;
|
|
23
23
|
description?: string | undefined;
|
|
24
24
|
resourceName?: string | undefined;
|
|
25
25
|
mimeTypePattern?: string | undefined;
|
|
@@ -29,11 +29,11 @@ declare const ViewsListOutputSchema: z.ZodObject<{
|
|
|
29
29
|
title: string;
|
|
30
30
|
icon: string;
|
|
31
31
|
id?: string | undefined;
|
|
32
|
-
name?: string | undefined;
|
|
33
32
|
url?: string | undefined;
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
tools?: string[] | undefined;
|
|
34
35
|
description?: string | undefined;
|
|
35
36
|
resourceName?: string | undefined;
|
|
36
|
-
tools?: string[] | undefined;
|
|
37
37
|
mimeTypePattern?: string | undefined;
|
|
38
38
|
prompt?: string | undefined;
|
|
39
39
|
installBehavior?: "open" | "none" | "autoPin" | undefined;
|
|
@@ -44,8 +44,8 @@ declare const ViewsListOutputSchema: z.ZodObject<{
|
|
|
44
44
|
title: string;
|
|
45
45
|
icon: string;
|
|
46
46
|
id?: string | undefined;
|
|
47
|
-
name?: string | undefined;
|
|
48
47
|
url?: string | undefined;
|
|
48
|
+
name?: string | undefined;
|
|
49
49
|
description?: string | undefined;
|
|
50
50
|
resourceName?: string | undefined;
|
|
51
51
|
mimeTypePattern?: string | undefined;
|
|
@@ -57,11 +57,11 @@ declare const ViewsListOutputSchema: z.ZodObject<{
|
|
|
57
57
|
title: string;
|
|
58
58
|
icon: string;
|
|
59
59
|
id?: string | undefined;
|
|
60
|
-
name?: string | undefined;
|
|
61
60
|
url?: string | undefined;
|
|
61
|
+
name?: string | undefined;
|
|
62
|
+
tools?: string[] | undefined;
|
|
62
63
|
description?: string | undefined;
|
|
63
64
|
resourceName?: string | undefined;
|
|
64
|
-
tools?: string[] | undefined;
|
|
65
65
|
mimeTypePattern?: string | undefined;
|
|
66
66
|
prompt?: string | undefined;
|
|
67
67
|
installBehavior?: "open" | "none" | "autoPin" | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@cloudflare/workers-types": "^4.20250617.0",
|
|
11
11
|
"@deco/mcp": "npm:@jsr/deco__mcp@0.5.5",
|
|
12
|
+
"@decocms/bindings": "workspace:*",
|
|
12
13
|
"@mastra/cloudflare-d1": "^0.13.4",
|
|
13
14
|
"@mastra/core": "^0.20.2",
|
|
14
15
|
"@modelcontextprotocol/sdk": "^1.19.1",
|
|
16
|
+
"@ai-sdk/provider": "^2.0.0",
|
|
15
17
|
"bidc": "0.0.3",
|
|
16
18
|
"drizzle-orm": "^0.44.5",
|
|
17
19
|
"jose": "^6.0.11",
|
package/src/bindings/binder.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/* oxlint-disable no-explicit-any */
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import type { MCPConnection } from "../connection.ts";
|
|
4
|
-
import { createPrivateTool } from "../mastra.ts";
|
|
4
|
+
import { createPrivateTool, createStreamableTool } from "../mastra.ts";
|
|
5
5
|
import {
|
|
6
6
|
createMCPFetchStub,
|
|
7
7
|
type MCPClientFetchStub,
|
|
8
8
|
type ToolBinder,
|
|
9
9
|
} from "../mcp.ts";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { CHANNEL_BINDING } from "./channels.ts";
|
|
11
|
+
import { VIEW_BINDING } from "./views.ts";
|
|
12
12
|
|
|
13
13
|
// ToolLike is a simplified version of the Tool interface that matches what we need for bindings
|
|
14
14
|
export interface ToolLike<
|
|
@@ -75,27 +75,16 @@ export const bindingClient = <TDefinition extends readonly ToolBinder[]>(
|
|
|
75
75
|
forConnection: (
|
|
76
76
|
mcpConnection: MCPConnection,
|
|
77
77
|
): MCPClientFetchStub<TDefinition> => {
|
|
78
|
-
|
|
78
|
+
return createMCPFetchStub<TDefinition>({
|
|
79
79
|
connection: mcpConnection,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
get(_, name) {
|
|
85
|
-
if (typeof name !== "string") {
|
|
86
|
-
throw new Error("Name must be a string");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return (args: Record<string, unknown>) => {
|
|
90
|
-
return (
|
|
91
|
-
stub[name as keyof MCPClientFetchStub<TDefinition>] as (
|
|
92
|
-
args: Record<string, unknown>,
|
|
93
|
-
) => Promise<unknown>
|
|
94
|
-
)(args);
|
|
95
|
-
};
|
|
80
|
+
streamable: binder.reduce(
|
|
81
|
+
(acc, tool) => {
|
|
82
|
+
acc[tool.name] = tool.streamable === true;
|
|
83
|
+
return acc;
|
|
96
84
|
},
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
{} as Record<string, boolean>,
|
|
86
|
+
),
|
|
87
|
+
});
|
|
99
88
|
},
|
|
100
89
|
};
|
|
101
90
|
};
|
|
@@ -103,9 +92,8 @@ export const bindingClient = <TDefinition extends readonly ToolBinder[]>(
|
|
|
103
92
|
export type MCPBindingClient<T extends ReturnType<typeof bindingClient>> =
|
|
104
93
|
ReturnType<T["forConnection"]>;
|
|
105
94
|
|
|
106
|
-
export const ChannelBinding = bindingClient(
|
|
107
|
-
|
|
108
|
-
export const ViewBinding = bindingClient(VIEW_BINDING_SCHEMA);
|
|
95
|
+
export const ChannelBinding = bindingClient(CHANNEL_BINDING);
|
|
96
|
+
export const ViewBinding = bindingClient(VIEW_BINDING);
|
|
109
97
|
|
|
110
98
|
export type { Callbacks } from "./channels.ts";
|
|
111
99
|
|
|
@@ -113,8 +101,12 @@ export const impl = <TBinder extends Binder>(
|
|
|
113
101
|
schema: TBinder,
|
|
114
102
|
implementation: BinderImplementation<TBinder>,
|
|
115
103
|
createToolFn = createPrivateTool,
|
|
104
|
+
createStreamableToolFn = createStreamableTool,
|
|
116
105
|
) => {
|
|
117
|
-
const impl:
|
|
106
|
+
const impl: (
|
|
107
|
+
| ReturnType<typeof createToolFn>
|
|
108
|
+
| ReturnType<typeof createStreamableToolFn>
|
|
109
|
+
)[] = [];
|
|
118
110
|
for (const key in schema) {
|
|
119
111
|
const toolSchema = schema[key];
|
|
120
112
|
const toolImplementation = implementation[key];
|
|
@@ -127,17 +119,28 @@ export const impl = <TBinder extends Binder>(
|
|
|
127
119
|
throw new Error(`Implementation for ${key} is required`);
|
|
128
120
|
}
|
|
129
121
|
|
|
130
|
-
const { name, handler, ...toolLike }
|
|
122
|
+
const { name, handler, streamable, ...toolLike } = {
|
|
131
123
|
...toolSchema,
|
|
132
124
|
...toolImplementation,
|
|
133
125
|
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
if (streamable) {
|
|
127
|
+
impl.push(
|
|
128
|
+
createStreamableToolFn({
|
|
129
|
+
...toolLike,
|
|
130
|
+
streamable,
|
|
131
|
+
id: name,
|
|
132
|
+
execute: ({ context }) => Promise.resolve(handler(context)),
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
} else {
|
|
136
|
+
impl.push(
|
|
137
|
+
createToolFn({
|
|
138
|
+
...toolLike,
|
|
139
|
+
id: name,
|
|
140
|
+
execute: ({ context }) => Promise.resolve(handler(context)),
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
141
144
|
}
|
|
142
145
|
return impl;
|
|
143
146
|
};
|
package/src/bindings/channels.ts
CHANGED
|
@@ -34,7 +34,7 @@ const listChannelsSchema = z.object({
|
|
|
34
34
|
export type Callbacks = z.infer<typeof callbacksSchema>;
|
|
35
35
|
export type JoinedChannelPayload = z.infer<typeof joinChannelSchema>;
|
|
36
36
|
export type ListChannelsSchema = z.infer<typeof listChannelsSchema>;
|
|
37
|
-
export const
|
|
37
|
+
export const CHANNEL_BINDING = [
|
|
38
38
|
{
|
|
39
39
|
name: "DECO_CHAT_CHANNELS_JOIN" as const,
|
|
40
40
|
inputSchema: joinChannelSchema,
|
package/src/bindings/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CHANNEL_BINDING } from "./channels.ts";
|
|
2
|
+
import { VIEW_BINDING as VIEWS_BINDING } from "./views.ts";
|
|
3
3
|
|
|
4
4
|
// Import new Resources 2.0 bindings function
|
|
5
|
+
import { LANGUAGE_MODEL_BINDING } from "@decocms/bindings/llm";
|
|
5
6
|
import { createResourceBindings } from "./resources/bindings.ts";
|
|
6
7
|
|
|
7
8
|
// Export types and utilities from binder
|
|
@@ -35,11 +36,11 @@ export * from "./resources/schemas.ts";
|
|
|
35
36
|
|
|
36
37
|
// Export deconfig helpers and types
|
|
37
38
|
export {
|
|
38
|
-
ResourcePath,
|
|
39
|
-
ResourceUri,
|
|
40
39
|
getMetadataString as deconfigGetMetadataString,
|
|
41
40
|
getMetadataValue as deconfigGetMetadataValue,
|
|
42
41
|
normalizeDirectory as deconfigNormalizeDirectory,
|
|
42
|
+
ResourcePath,
|
|
43
|
+
ResourceUri,
|
|
43
44
|
} from "./deconfig/helpers.ts";
|
|
44
45
|
export { createDeconfigResource } from "./deconfig/index.ts";
|
|
45
46
|
export type {
|
|
@@ -52,8 +53,9 @@ export type {
|
|
|
52
53
|
export { deconfigTools } from "./deconfig/types.ts";
|
|
53
54
|
|
|
54
55
|
export const WellKnownBindings = {
|
|
55
|
-
Channel:
|
|
56
|
-
View:
|
|
56
|
+
Channel: CHANNEL_BINDING,
|
|
57
|
+
View: VIEWS_BINDING,
|
|
58
|
+
LanguageModel: LANGUAGE_MODEL_BINDING,
|
|
57
59
|
// Note: Resources is not included here since it's a generic function
|
|
58
60
|
// Use createResourceBindings(dataSchema) directly for Resources 2.0
|
|
59
61
|
} as const;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LanguageModelV2,
|
|
3
|
+
LanguageModelV2CallOptions,
|
|
4
|
+
ProviderV2,
|
|
5
|
+
} from "@ai-sdk/provider";
|
|
6
|
+
import type { LanguageModelBinding } from "@decocms/bindings/llm";
|
|
7
|
+
import { lazy, responseToStream } from "./utils.ts";
|
|
8
|
+
|
|
9
|
+
const toRegExp = (supportedUrls: Record<string, string[]>) => {
|
|
10
|
+
return Object.fromEntries(
|
|
11
|
+
Object.entries(supportedUrls).map(([key, values]) => [
|
|
12
|
+
key,
|
|
13
|
+
values.map((v) => new RegExp(v)),
|
|
14
|
+
]),
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type LLMBindingClient = ReturnType<
|
|
19
|
+
(typeof LanguageModelBinding)["forConnection"]
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
export interface Provider extends ProviderV2 {
|
|
23
|
+
listModels: LLMBindingClient["COLLECTION_LLM_LIST"];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates a ai-sdk compatible provider for the given binding
|
|
28
|
+
* @param binding - The binding to create the provider from
|
|
29
|
+
* @returns The provider
|
|
30
|
+
*/
|
|
31
|
+
export const createProvider = (binding: LLMBindingClient): Provider => {
|
|
32
|
+
return {
|
|
33
|
+
imageModel: () => {
|
|
34
|
+
throw new Error("Image models are not supported by this provider");
|
|
35
|
+
},
|
|
36
|
+
textEmbeddingModel: () => {
|
|
37
|
+
throw new Error(
|
|
38
|
+
"Text embedding models are not supported by this provider",
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
listModels: async () => {
|
|
42
|
+
return await binding.COLLECTION_LLM_LIST({});
|
|
43
|
+
},
|
|
44
|
+
languageModel: (modelId: string): LanguageModelV2 => {
|
|
45
|
+
const supportedUrls = lazy(() =>
|
|
46
|
+
binding
|
|
47
|
+
.LLM_METADATA({ modelId })
|
|
48
|
+
.then((metadata) => toRegExp(metadata.supportedUrls))
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
specificationVersion: "v2" as const,
|
|
53
|
+
provider: "llm-binding",
|
|
54
|
+
modelId,
|
|
55
|
+
supportedUrls,
|
|
56
|
+
doGenerate: async (options: LanguageModelV2CallOptions) => {
|
|
57
|
+
const response = await binding.LLM_DO_GENERATE({
|
|
58
|
+
callOptions: options,
|
|
59
|
+
modelId,
|
|
60
|
+
});
|
|
61
|
+
// Ensure usage fields are always present as required by LanguageModelV2
|
|
62
|
+
return {
|
|
63
|
+
...response,
|
|
64
|
+
usage: {
|
|
65
|
+
inputTokens: response.usage.inputTokens ?? undefined,
|
|
66
|
+
outputTokens: response.usage.outputTokens ?? undefined,
|
|
67
|
+
totalTokens: response.usage.totalTokens ?? undefined,
|
|
68
|
+
reasoningTokens: response.usage.reasoningTokens ?? undefined,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
doStream: async (options: LanguageModelV2CallOptions) => {
|
|
73
|
+
const response = await binding.LLM_DO_STREAM({
|
|
74
|
+
callOptions: options,
|
|
75
|
+
modelId,
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
stream: responseToStream(response),
|
|
79
|
+
response: {
|
|
80
|
+
headers: Object.fromEntries(response.headers?.entries() ?? []),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
};
|