@decocms/runtime 0.25.1 → 0.26.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.
Files changed (46) hide show
  1. package/dist/bindings/deconfig/index.d.ts +6 -5
  2. package/dist/bindings/deconfig/index.js +4 -4
  3. package/dist/bindings/index.d.ts +1544 -46
  4. package/dist/bindings/index.js +9 -7
  5. package/dist/bindings/index.js.map +1 -1
  6. package/dist/{chunk-F6XZPFWM.js → chunk-3AWMDSOH.js} +20 -51
  7. package/dist/chunk-3AWMDSOH.js.map +1 -0
  8. package/dist/{chunk-QELHWEZH.js → chunk-5EYZ2LVM.js} +8 -5
  9. package/dist/chunk-5EYZ2LVM.js.map +1 -0
  10. package/dist/{chunk-O6IURJAY.js → chunk-GPIGZ6DL.js} +38 -33
  11. package/dist/chunk-GPIGZ6DL.js.map +1 -0
  12. package/dist/{chunk-I2KGAHFY.js → chunk-LCU3FBI3.js} +6 -2
  13. package/dist/chunk-LCU3FBI3.js.map +1 -0
  14. package/dist/drizzle.d.ts +4 -3
  15. package/dist/{index-D8GtUDPS.d.ts → index-COMJ3oN7.d.ts} +4 -3
  16. package/dist/{index-SnnmAI05.d.ts → index-DqyElLzZ.d.ts} +10 -10
  17. package/dist/index.d.ts +4 -3
  18. package/dist/index.js +5 -5
  19. package/dist/mastra.d.ts +4 -3
  20. package/dist/mastra.js +1 -1
  21. package/dist/{mcp-Bv7IAgWX.d.ts → mcp-Dbqp-p04.d.ts} +9 -13
  22. package/dist/mcp-client.d.ts +10 -14
  23. package/dist/mcp-client.js +1 -1
  24. package/dist/proxy.d.ts +3 -2
  25. package/dist/proxy.js +2 -2
  26. package/dist/resources.d.ts +42 -42
  27. package/dist/views.d.ts +12 -12
  28. package/package.json +4 -2
  29. package/src/bindings/binder.ts +37 -34
  30. package/src/bindings/channels.ts +1 -1
  31. package/src/bindings/index.ts +8 -6
  32. package/src/bindings/language-model/ai-sdk.ts +87 -0
  33. package/src/bindings/language-model/index.ts +4 -0
  34. package/src/bindings/language-model/utils.ts +118 -0
  35. package/src/bindings/views.ts +1 -1
  36. package/src/connection.ts +8 -53
  37. package/src/http-client-transport.ts +1 -66
  38. package/src/mastra.ts +4 -0
  39. package/src/mcp-client.ts +22 -2
  40. package/src/mcp.ts +16 -17
  41. package/src/proxy.ts +6 -2
  42. package/dist/chunk-F6XZPFWM.js.map +0 -1
  43. package/dist/chunk-I2KGAHFY.js.map +0 -1
  44. package/dist/chunk-O6IURJAY.js.map +0 -1
  45. package/dist/chunk-QELHWEZH.js.map +0 -1
  46. package/dist/connection-DDtQYrea.d.ts +0 -30
@@ -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;
@@ -25,24 +25,24 @@ declare const ResourcesReadOutputSchema: z.ZodObject<{
25
25
  type: z.ZodEnum<["text", "blob"]>;
26
26
  }, "strip", z.ZodTypeAny, {
27
27
  type: "text" | "blob";
28
- name: string;
29
28
  data: string;
30
29
  uri: string;
31
- description?: string | undefined;
30
+ name: string;
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
39
  type: "text" | "blob";
40
- name: string;
41
40
  data: string;
42
41
  uri: string;
43
- description?: string | undefined;
42
+ name: string;
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
- description?: string | undefined;
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
- description?: string | undefined;
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
- description?: string | undefined;
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
- description?: string | undefined;
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;
@@ -147,27 +147,27 @@ declare const ResourceCreateInputSchema: z.ZodObject<{
147
147
  }>;
148
148
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
149
149
  }, "strip", z.ZodTypeAny, {
150
- name: string;
151
- resourceName: string;
152
150
  content: {
153
151
  type: "text" | "blob";
154
152
  data: string;
155
153
  mimeType?: string | undefined;
156
154
  };
155
+ name: string;
156
+ resourceName: string;
157
+ title?: string | undefined;
157
158
  description?: string | undefined;
158
159
  metadata?: Record<string, any> | undefined;
159
- title?: string | undefined;
160
160
  }, {
161
- name: string;
162
- resourceName: string;
163
161
  content: {
164
162
  type: "text" | "blob";
165
163
  data: string;
166
164
  mimeType?: string | undefined;
167
165
  };
166
+ name: string;
167
+ resourceName: string;
168
+ title?: string | undefined;
168
169
  description?: string | undefined;
169
170
  metadata?: Record<string, any> | undefined;
170
- title?: 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
- description?: string | undefined;
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
- description?: string | undefined;
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,29 +221,29 @@ 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
- description?: string | undefined;
227
- resourceName?: string | undefined;
228
- metadata?: Record<string, any> | undefined;
225
+ name: string;
229
226
  content?: {
230
227
  type: "text" | "blob";
231
228
  data: string;
232
229
  mimeType?: string | undefined;
233
230
  } | undefined;
234
231
  title?: string | undefined;
235
- }, {
236
- name: string;
237
- uri: string;
238
232
  description?: string | undefined;
239
- resourceName?: string | undefined;
240
233
  metadata?: Record<string, any> | undefined;
234
+ resourceName?: string | undefined;
235
+ }, {
236
+ uri: string;
237
+ name: string;
241
238
  content?: {
242
239
  type: "text" | "blob";
243
240
  data: string;
244
241
  mimeType?: string | undefined;
245
242
  } | undefined;
246
243
  title?: string | undefined;
244
+ description?: string | undefined;
245
+ metadata?: Record<string, any> | 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
- description?: string | undefined;
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
- description?: string | undefined;
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
@@ -14,13 +14,13 @@ declare const ViewsListOutputSchema: z.ZodObject<{
14
14
  prompt: z.ZodOptional<z.ZodString>;
15
15
  installBehavior: z.ZodOptional<z.ZodEnum<["none", "open", "autoPin"]>>;
16
16
  }, "strip", z.ZodTypeAny, {
17
- tools: string[];
18
17
  title: string;
18
+ tools: string[];
19
19
  icon: string;
20
- id?: string | undefined;
21
- name?: string | undefined;
22
20
  url?: string | undefined;
21
+ name?: string | undefined;
23
22
  description?: string | undefined;
23
+ id?: string | undefined;
24
24
  resourceName?: string | undefined;
25
25
  mimeTypePattern?: string | undefined;
26
26
  prompt?: string | undefined;
@@ -28,25 +28,25 @@ declare const ViewsListOutputSchema: z.ZodObject<{
28
28
  }, {
29
29
  title: string;
30
30
  icon: string;
31
- id?: string | undefined;
32
- name?: string | undefined;
33
31
  url?: string | undefined;
32
+ name?: string | undefined;
34
33
  description?: string | undefined;
35
- resourceName?: string | undefined;
36
34
  tools?: string[] | undefined;
35
+ id?: string | undefined;
36
+ resourceName?: string | undefined;
37
37
  mimeTypePattern?: string | undefined;
38
38
  prompt?: string | undefined;
39
39
  installBehavior?: "open" | "none" | "autoPin" | undefined;
40
40
  }>, "many">;
41
41
  }, "strip", z.ZodTypeAny, {
42
42
  views: {
43
- tools: string[];
44
43
  title: string;
44
+ tools: string[];
45
45
  icon: string;
46
- id?: string | undefined;
47
- name?: string | undefined;
48
46
  url?: string | undefined;
47
+ name?: string | undefined;
49
48
  description?: string | undefined;
49
+ id?: string | undefined;
50
50
  resourceName?: string | undefined;
51
51
  mimeTypePattern?: string | undefined;
52
52
  prompt?: string | undefined;
@@ -56,12 +56,12 @@ declare const ViewsListOutputSchema: z.ZodObject<{
56
56
  views: {
57
57
  title: string;
58
58
  icon: string;
59
- id?: string | undefined;
60
- name?: string | undefined;
61
59
  url?: string | undefined;
60
+ name?: string | undefined;
62
61
  description?: string | undefined;
63
- resourceName?: string | undefined;
64
62
  tools?: string[] | undefined;
63
+ id?: string | undefined;
64
+ resourceName?: 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.25.1",
3
+ "version": "0.26.0",
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",
@@ -101,4 +103,4 @@
101
103
  "publishConfig": {
102
104
  "access": "public"
103
105
  }
104
- }
106
+ }
@@ -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 { CHANNEL_BINDING_SCHEMA } from "./channels.ts";
11
- import { VIEW_BINDING_SCHEMA } from "./views.ts";
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
- const stub = createMCPFetchStub<TDefinition>({
78
+ return createMCPFetchStub<TDefinition>({
79
79
  connection: mcpConnection,
80
- });
81
- return new Proxy<MCPClientFetchStub<TDefinition>>(
82
- {} as MCPClientFetchStub<TDefinition>,
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(CHANNEL_BINDING_SCHEMA);
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: ReturnType<typeof createToolFn>[] = [];
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 }: ToolLike = {
122
+ const { name, handler, streamable, ...toolLike } = {
131
123
  ...toolSchema,
132
124
  ...toolImplementation,
133
125
  };
134
- impl.push(
135
- createToolFn({
136
- ...toolLike,
137
- id: name,
138
- execute: ({ context }) => Promise.resolve(handler(context)),
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
  };
@@ -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 CHANNEL_BINDING_SCHEMA = [
37
+ export const CHANNEL_BINDING = [
38
38
  {
39
39
  name: "DECO_CHAT_CHANNELS_JOIN" as const,
40
40
  inputSchema: joinChannelSchema,
@@ -1,7 +1,8 @@
1
- import { CHANNEL_BINDING_SCHEMA } from "./channels.ts";
2
- import { VIEW_BINDING_SCHEMA } from "./views.ts";
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: CHANNEL_BINDING_SCHEMA,
56
- View: VIEW_BINDING_SCHEMA,
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 { LanguageModelBinding } from "@decocms/bindings/llm";
7
+ import { lazy, responseToStream } from "./utils";
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_MODELS_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_MODELS_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
+ };
@@ -0,0 +1,4 @@
1
+ export * from "@decocms/bindings";
2
+ export { LanguageModelBinding } from "@decocms/bindings/llm";
3
+ export * from "./ai-sdk.ts";
4
+ export * from "./utils.ts";