@decocms/bindings 0.1.6 → 0.2.1-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.
Files changed (75) hide show
  1. package/README.md +16 -16
  2. package/dist/browser/agents.js +29 -0
  3. package/dist/browser/agents.js.map +1 -0
  4. package/dist/browser/chunk-6QEXJ7XW.js +48564 -0
  5. package/dist/browser/chunk-6QEXJ7XW.js.map +1 -0
  6. package/dist/browser/chunk-WKNVAFKE.js +2176 -0
  7. package/dist/browser/chunk-WKNVAFKE.js.map +1 -0
  8. package/dist/browser/chunk-XWLBKKHZ.js +127 -0
  9. package/dist/browser/chunk-XWLBKKHZ.js.map +1 -0
  10. package/dist/browser/chunk-ZX4ZDU2T.js +58 -0
  11. package/dist/browser/chunk-ZX4ZDU2T.js.map +1 -0
  12. package/dist/browser/client.js +9 -0
  13. package/dist/browser/client.js.map +1 -0
  14. package/dist/browser/collections.js +4 -0
  15. package/dist/browser/connection.js +8 -0
  16. package/dist/browser/connection.js.map +1 -0
  17. package/dist/browser/index.js +10 -0
  18. package/dist/browser/index.js.map +1 -0
  19. package/dist/browser/language-model.js +205 -0
  20. package/dist/browser/language-model.js.map +1 -0
  21. package/dist/client.d.ts +12 -0
  22. package/dist/client.js +54 -0
  23. package/dist/client.js.map +1 -0
  24. package/dist/{well-known/collections.d.ts → collections.d.ts} +170 -23
  25. package/dist/{chunk-L7E6ONLJ.js → collections.js} +18 -24
  26. package/dist/collections.js.map +1 -0
  27. package/dist/connection.d.ts +30 -0
  28. package/dist/connection.js +3 -0
  29. package/dist/connection.js.map +1 -0
  30. package/dist/index.d.ts +6 -2
  31. package/dist/index.js +262 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/language-model.d.ts +3228 -0
  34. package/dist/language-model.js +628 -0
  35. package/dist/language-model.js.map +1 -0
  36. package/dist/models.d.ts +2071 -0
  37. package/dist/models.js +111 -0
  38. package/dist/models.js.map +1 -0
  39. package/dist/node/agents.d.ts +903 -0
  40. package/dist/node/agents.js +27 -0
  41. package/dist/node/agents.js.map +1 -0
  42. package/dist/node/chunk-BLCFITZG.js +56 -0
  43. package/dist/node/chunk-BLCFITZG.js.map +1 -0
  44. package/dist/node/chunk-QMQMPK7Q.js +50 -0
  45. package/dist/node/chunk-QMQMPK7Q.js.map +1 -0
  46. package/dist/node/chunk-QP7AQCEP.js +23478 -0
  47. package/dist/node/chunk-QP7AQCEP.js.map +1 -0
  48. package/dist/node/chunk-T2DG7334.js +125 -0
  49. package/dist/node/chunk-T2DG7334.js.map +1 -0
  50. package/dist/node/client.d.ts +12 -0
  51. package/dist/node/client.js +7 -0
  52. package/dist/node/client.js.map +1 -0
  53. package/dist/node/collections.d.ts +537 -0
  54. package/dist/node/collections.js +4 -0
  55. package/dist/node/collections.js.map +1 -0
  56. package/dist/node/connection.d.ts +30 -0
  57. package/dist/node/connection.js +6 -0
  58. package/dist/node/connection.js.map +1 -0
  59. package/dist/node/index.d.ts +94 -0
  60. package/dist/node/index.js +8 -0
  61. package/dist/node/index.js.map +1 -0
  62. package/dist/node/language-model.d.ts +2840 -0
  63. package/dist/node/language-model.js +203 -0
  64. package/dist/node/language-model.js.map +1 -0
  65. package/package.json +45 -17
  66. package/dist/chunk-L7E6ONLJ.js.map +0 -1
  67. package/dist/well-known/collections.js +0 -3
  68. package/dist/well-known/models.d.ts +0 -127
  69. package/dist/well-known/models.js +0 -46
  70. package/dist/well-known/models.js.map +0 -1
  71. package/src/core/binder.ts +0 -221
  72. package/src/index.ts +0 -16
  73. package/src/well-known/collections.ts +0 -328
  74. package/src/well-known/models.ts +0 -79
  75. /package/dist/{well-known → browser}/collections.js.map +0 -0
@@ -1,221 +0,0 @@
1
- /**
2
- * Core Binder Types and Utilities
3
- *
4
- * This module provides the core types and utilities for the bindings system.
5
- * Bindings define standardized interfaces that integrations (MCPs) can implement.
6
- */
7
-
8
- import type { ZodType } from "zod";
9
- import { zodToJsonSchema } from "zod-to-json-schema";
10
- import { diffSchemas } from "json-schema-diff";
11
-
12
- /**
13
- * ToolBinder defines a single tool within a binding.
14
- * It specifies the tool name, input/output schemas, and whether it's optional.
15
- *
16
- * @template TName - The tool name (can be a string or RegExp for pattern matching)
17
- * @template TInput - The input type (inferred from inputSchema)
18
- * @template TReturn - The return type (inferred from outputSchema)
19
- */
20
- export interface ToolBinder<
21
- TName extends string | RegExp = string,
22
- // biome-ignore lint/suspicious/noExplicitAny: Generic type parameter
23
- TInput = any,
24
- TReturn extends object | null | boolean = object,
25
- > {
26
- /** The name of the tool (e.g., "DECO_CHAT_CHANNELS_JOIN") */
27
- name: TName;
28
-
29
- /** Zod schema for validating tool input */
30
- inputSchema: ZodType<TInput>;
31
-
32
- /** Optional Zod schema for validating tool output */
33
- outputSchema?: ZodType<TReturn>;
34
-
35
- /**
36
- * Whether this tool is optional in the binding.
37
- * If true, an implementation doesn't need to provide this tool.
38
- */
39
- opt?: true;
40
- }
41
-
42
- /**
43
- * Binder represents a collection of tool definitions that form a binding.
44
- * A binding is like a TypeScript interface - it defines what tools must be implemented.
45
- *
46
- * @template TDefinition - Array of ToolBinder definitions
47
- *
48
- * @example
49
- * ```ts
50
- * const MY_BINDING = [{
51
- * name: "MY_TOOL" as const,
52
- * inputSchema: z.object({ id: z.string() }),
53
- * outputSchema: z.object({ success: z.boolean() }),
54
- * }] as const satisfies Binder;
55
- * ```
56
- */
57
- export type Binder<
58
- TDefinition extends readonly ToolBinder[] = readonly ToolBinder[],
59
- > = TDefinition;
60
-
61
- /**
62
- * Tool with schemas for validation
63
- */
64
- export interface ToolWithSchemas {
65
- name: string;
66
- inputSchema?: ZodType<any> | Record<string, unknown>;
67
- outputSchema?: ZodType<any> | Record<string, unknown>;
68
- }
69
-
70
- /**
71
- * Converts a schema to JSON Schema format if it's a Zod schema
72
- */
73
- function normalizeSchema(schema: any): Record<string, unknown> | undefined {
74
- if (!schema) return undefined;
75
-
76
- // If it's a Zod schema (has _def property), convert it
77
- if (schema._def) {
78
- const jsonSchema = zodToJsonSchema(schema, {
79
- // Don't add additionalProperties: false to allow structural compatibility
80
- $refStrategy: "none",
81
- }) as Record<string, unknown>;
82
-
83
- // Remove additionalProperties constraint to allow subtyping
84
- if (jsonSchema.type === "object") {
85
- delete jsonSchema.additionalProperties;
86
- }
87
-
88
- return jsonSchema;
89
- }
90
-
91
- // Otherwise assume it's already a JSON Schema
92
- const jsonSchema = schema as Record<string, unknown>;
93
-
94
- // Remove additionalProperties constraint if present
95
- if (jsonSchema.type === "object" && "additionalProperties" in jsonSchema) {
96
- const copy = { ...jsonSchema };
97
- delete copy.additionalProperties;
98
- return copy;
99
- }
100
-
101
- return jsonSchema;
102
- }
103
-
104
- /**
105
- * Binding checker interface
106
- */
107
- export interface BindingChecker {
108
- /**
109
- * Check if a set of tools implements the binding with full schema validation.
110
- *
111
- * Validates:
112
- * - Tool name matches (exact or regex)
113
- * - Input schema: Tool accepts what binder requires (no removals from binder to tool)
114
- * - Output schema: Tool provides what binder expects (no removals from tool to binder)
115
- *
116
- * @param tools - Array of tools with names and schemas
117
- * @returns Promise<boolean> - true if all tools implement the binding correctly
118
- */
119
- isImplementedBy: (tools: ToolWithSchemas[]) => Promise<boolean>;
120
- }
121
-
122
- /**
123
- * Creates a binding checker with full schema validation using json-schema-diff.
124
- *
125
- * This performs strict compatibility checking:
126
- * - For input schemas: Validates that the tool can accept what the binder requires
127
- * - For output schemas: Validates that the tool provides what the binder expects
128
- *
129
- * @param binderTools - The binding definition to check against
130
- * @returns A binding checker with an async isImplementedBy method
131
- *
132
- * @example
133
- * ```ts
134
- * const checker = createBindingChecker(MY_BINDING);
135
- * const isCompatible = await checker.isImplementedBy(availableTools);
136
- * ```
137
- */
138
- export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
139
- binderTools: TDefinition,
140
- ): BindingChecker {
141
- return {
142
- isImplementedBy: async (tools: ToolWithSchemas[]) => {
143
- for (const binderTool of binderTools) {
144
- // Find matching tool by name (exact or regex)
145
- const pattern = typeof binderTool.name === "string"
146
- ? new RegExp(`^${binderTool.name}$`)
147
- : binderTool.name;
148
-
149
- const matchedTool = tools.find((t) => pattern.test(t.name));
150
-
151
- // Skip optional tools that aren't present
152
- if (!matchedTool && binderTool.opt) {
153
- continue;
154
- }
155
-
156
- // Required tool not found
157
- if (!matchedTool) {
158
- return false;
159
- }
160
-
161
- // === INPUT SCHEMA VALIDATION ===
162
- // Tool must accept what binder requires
163
- // Check: binder (source) -> tool (destination)
164
- // If removals found, tool doesn't accept something binder requires
165
- const binderInputSchema = normalizeSchema(binderTool.inputSchema);
166
- const toolInputSchema = normalizeSchema(matchedTool.inputSchema);
167
-
168
- if (binderInputSchema && toolInputSchema) {
169
- try {
170
- const inputDiff = await diffSchemas({
171
- sourceSchema: binderInputSchema,
172
- destinationSchema: toolInputSchema,
173
- });
174
-
175
- // If something was removed from binder to tool, tool can't accept it
176
- if (inputDiff.removalsFound) {
177
- return false;
178
- }
179
- } catch (error) {
180
- console.error("Schema diff failed", error);
181
- // Schema diff failed - consider incompatible
182
- return false;
183
- }
184
- } else if (binderInputSchema && !toolInputSchema) {
185
- // Binder requires input schema but tool doesn't have one
186
- return false;
187
- }
188
-
189
- // === OUTPUT SCHEMA VALIDATION ===
190
- // Tool must provide what binder expects (but can provide more)
191
- // Check: binder (source) -> tool (destination)
192
- // If removals found, tool doesn't provide something binder expects
193
- const binderOutputSchema = normalizeSchema(binderTool.outputSchema);
194
- const toolOutputSchema = normalizeSchema(matchedTool.outputSchema);
195
-
196
- if (binderOutputSchema && toolOutputSchema) {
197
- try {
198
- const outputDiff = await diffSchemas({
199
- sourceSchema: binderOutputSchema,
200
- destinationSchema: toolOutputSchema,
201
- });
202
-
203
- // If something was removed from binder to tool, tool doesn't provide it
204
- if (outputDiff.removalsFound) {
205
- return false;
206
- }
207
- } catch (error) {
208
- console.error("Schema diff failed", error);
209
- // Schema diff failed - consider incompatible
210
- return false;
211
- }
212
- } else if (binderOutputSchema && !toolOutputSchema) {
213
- // Binder expects output schema but tool doesn't have one
214
- return false;
215
- }
216
- }
217
-
218
- return true;
219
- },
220
- };
221
- }
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * @decocms/bindings
3
- *
4
- * Core type definitions for the bindings system.
5
- * Bindings define standardized interfaces that integrations (MCPs) can implement.
6
- */
7
-
8
- // Re-export core binder types and utilities
9
- export {
10
- type ToolBinder,
11
- type Binder,
12
- type ToolWithSchemas,
13
- type BindingChecker,
14
- createBindingChecker,
15
- } from "./core/binder";
16
-
@@ -1,328 +0,0 @@
1
- import { z } from "zod";
2
- import type { ToolBinder } from "../core/binder";
3
-
4
- /**
5
- * Collection Bindings
6
- *
7
- * This module provides standardized tool bindings for Collections, representing
8
- * SQL table-like structures with CRUD + Search operations compatible with TanStack DB.
9
- *
10
- * Key Features:
11
- * - Generic collection bindings that work with any entity type
12
- * - Standardized tool naming: `DECO_COLLECTION_{COLLECTION}_*`
13
- * - Compatible with TanStack DB query-collection
14
- * - Full TypeScript support with proper type constraints
15
- * - Support for filtering, sorting, and pagination
16
- * - Simple id and title fields for human-readable identification
17
- */
18
-
19
- /**
20
- * Base schema for collection entities
21
- * All collection entities must have an id, title, and audit trail fields
22
- */
23
- export const BaseCollectionEntitySchema = z.object({
24
- id: z.string().describe("Unique identifier for the entity"),
25
- title: z.string().describe("Human-readable title for the entity"),
26
- created_at: z.string().datetime(),
27
- updated_at: z.string().datetime(),
28
- created_by: z.string().optional(),
29
- updated_by: z.string().optional(),
30
- });
31
-
32
- /**
33
- * Type helper for BaseCollectionEntitySchema
34
- */
35
- export type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
36
-
37
- /**
38
- * Comparison expression schema for filtering
39
- */
40
- const ComparisonExpressionSchema = z.object({
41
- field: z.array(z.string()),
42
- operator: z.enum([
43
- "eq",
44
- "gt",
45
- "gte",
46
- "lt",
47
- "lte",
48
- "in",
49
- "like",
50
- "contains",
51
- ]),
52
- value: z.unknown(),
53
- });
54
-
55
- /**
56
- * Where expression schema for filtering
57
- * Supports TanStack DB predicate push-down patterns
58
- */
59
- export const WhereExpressionSchema = z.union([
60
- ComparisonExpressionSchema,
61
- z.object({
62
- operator: z.enum(["and", "or", "not"]),
63
- conditions: z.array(ComparisonExpressionSchema),
64
- }),
65
- ]);
66
-
67
- /**
68
- * Where expression type for filtering
69
- * Derived from WhereExpressionSchema
70
- */
71
- export type WhereExpression = z.infer<typeof WhereExpressionSchema>;
72
-
73
- /**
74
- * Order by expression for sorting
75
- */
76
- export const OrderByExpressionSchema = z.object({
77
- field: z.array(z.string()),
78
- direction: z.enum(["asc", "desc"]),
79
- nulls: z.enum(["first", "last"]).optional(),
80
- });
81
-
82
- /**
83
- * List/Query input schema for collections
84
- * Compatible with TanStack DB LoadSubsetOptions
85
- */
86
- export const CollectionListInputSchema = z.object({
87
- where: WhereExpressionSchema.optional().describe("Filter expression"),
88
- orderBy: z
89
- .array(OrderByExpressionSchema)
90
- .optional()
91
- .describe("Sort expressions"),
92
- limit: z
93
- .number()
94
- .int()
95
- .min(1)
96
- .max(1000)
97
- .optional()
98
- .describe("Maximum number of items to return"),
99
- offset: z
100
- .number()
101
- .int()
102
- .min(0)
103
- .optional()
104
- .describe("Number of items to skip"),
105
- });
106
-
107
- /**
108
- * Factory function to create list output schema for a specific collection type
109
- */
110
- export function createCollectionListOutputSchema<T extends z.ZodTypeAny>(
111
- entitySchema: T,
112
- ) {
113
- return z.object({
114
- items: z.array(entitySchema).describe("Array of collection items"),
115
- totalCount: z
116
- .number()
117
- .int()
118
- .min(0)
119
- .optional()
120
- .describe("Total number of matching items (if available)"),
121
- hasMore: z
122
- .boolean()
123
- .optional()
124
- .describe("Whether there are more items available"),
125
- });
126
- }
127
-
128
- /**
129
- * Get by ID input schema
130
- */
131
- export const CollectionGetInputSchema = z.object({
132
- id: z.string().describe("ID of the entity to retrieve"),
133
- });
134
-
135
- /**
136
- * Factory function to create get output schema
137
- */
138
- export function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(
139
- entitySchema: T,
140
- ) {
141
- return z.object({
142
- item: entitySchema
143
- .nullable()
144
- .describe("The retrieved item, or null if not found"),
145
- });
146
- }
147
-
148
- /**
149
- * Factory function to create insert input schema
150
- */
151
- export function createCollectionInsertInputSchema<T extends z.ZodTypeAny>(
152
- entitySchema: T,
153
- ) {
154
- // Remove id field since it may be auto-generated by the server
155
- return z.object({
156
- data: entitySchema.describe("Data for the new entity (id may be auto-generated)"),
157
- });
158
- }
159
-
160
- /**
161
- * Factory function to create insert output schema
162
- */
163
- export function createCollectionInsertOutputSchema<T extends z.ZodTypeAny>(
164
- entitySchema: T,
165
- ) {
166
- return z.object({
167
- item: entitySchema.describe("The created entity with generated id"),
168
- });
169
- }
170
-
171
- /**
172
- * Factory function to create update input schema
173
- */
174
- export function createCollectionUpdateInputSchema<T extends z.ZodTypeAny>(
175
- entitySchema: T,
176
- ) {
177
- return z.object({
178
- id: z.string().describe("ID of the entity to update"),
179
- data: (entitySchema as unknown as z.AnyZodObject)
180
- .partial()
181
- .describe("Partial entity data to update"),
182
- });
183
- }
184
-
185
- /**
186
- * Factory function to create update output schema
187
- */
188
- export function createCollectionUpdateOutputSchema<T extends z.ZodTypeAny>(
189
- entitySchema: T,
190
- ) {
191
- return z.object({
192
- item: entitySchema.describe("The updated entity"),
193
- });
194
- }
195
-
196
- /**
197
- * Delete input schema
198
- */
199
- export const CollectionDeleteInputSchema = z.object({
200
- id: z.string().describe("ID of the entity to delete"),
201
- });
202
-
203
- /**
204
- * Delete output schema
205
- */
206
- export const CollectionDeleteOutputSchema = z.object({
207
- success: z.boolean().describe("Whether the deletion was successful"),
208
- id: z.string().describe("ID of the deleted entity"),
209
- });
210
-
211
- /**
212
- * Options for creating collection bindings
213
- */
214
- export interface CollectionBindingOptions {
215
- /**
216
- * If true, only LIST and GET operations will be included (read-only collection)
217
- * @default false
218
- */
219
- readOnly?: boolean;
220
- }
221
-
222
- /**
223
- * Creates generic collection bindings for a specific entity type
224
- *
225
- * This function generates standardized tool bindings that work with any collection/table
226
- * by accepting a custom entity schema and collection name. The bindings provide:
227
- * - DECO_COLLECTION_{NAME}_LIST - Query/search entities with filtering and sorting (required)
228
- * - DECO_COLLECTION_{NAME}_GET - Get a single entity by ID (required)
229
- * - DECO_COLLECTION_{NAME}_INSERT - Create a new entity (optional, excluded if readOnly=true)
230
- * - DECO_COLLECTION_{NAME}_UPDATE - Update an existing entity (optional, excluded if readOnly=true)
231
- * - DECO_COLLECTION_{NAME}_DELETE - Delete an entity (optional, excluded if readOnly=true)
232
- *
233
- * @param collectionName - The name of the collection/table (e.g., "users", "products", "orders")
234
- * @param entitySchema - The Zod schema for the entity type (must extend BaseCollectionEntitySchema)
235
- * @param options - Optional configuration for the collection bindings
236
- * @returns Array of tool bindings for Collection CRUD + Query operations
237
- *
238
- * @example
239
- * ```typescript
240
- * const UserSchema = z.object({
241
- * id: z.string(),
242
- * title: z.string(),
243
- * created_at: z.string().datetime(),
244
- * updated_at: z.string().datetime(),
245
- * created_by: z.string().optional(),
246
- * updated_by: z.string().optional(),
247
- * email: z.string().email(),
248
- * });
249
- *
250
- * // Full CRUD collection
251
- * const USER_COLLECTION_BINDING = createCollectionBindings("users", UserSchema);
252
- *
253
- * // Read-only collection (only LIST and GET)
254
- * const READONLY_COLLECTION_BINDING = createCollectionBindings("products", ProductSchema, { readOnly: true });
255
- * ```
256
- */
257
- export function createCollectionBindings<
258
- TEntitySchema extends BaseCollectionEntitySchemaType,
259
- >(
260
- collectionName: string,
261
- entitySchema: TEntitySchema,
262
- options?: CollectionBindingOptions,
263
- ) {
264
- const upperName = collectionName.toUpperCase();
265
- const readOnly = options?.readOnly ?? false;
266
-
267
- const bindings: ToolBinder[] = [
268
- {
269
- name: `DECO_COLLECTION_${upperName}_LIST` as const,
270
- inputSchema: CollectionListInputSchema,
271
- outputSchema: createCollectionListOutputSchema(entitySchema),
272
- },
273
- {
274
- name: `DECO_COLLECTION_${upperName}_GET` as const,
275
- inputSchema: CollectionGetInputSchema,
276
- outputSchema: createCollectionGetOutputSchema(entitySchema),
277
- },
278
- ];
279
-
280
- // Only include mutation operations if not read-only
281
- if (!readOnly) {
282
- bindings.push(
283
- {
284
- name: `DECO_COLLECTION_${upperName}_INSERT` as const,
285
- inputSchema: createCollectionInsertInputSchema(entitySchema),
286
- outputSchema: createCollectionInsertOutputSchema(entitySchema),
287
- opt: true,
288
- },
289
- {
290
- name: `DECO_COLLECTION_${upperName}_UPDATE` as const,
291
- inputSchema: createCollectionUpdateInputSchema(entitySchema),
292
- outputSchema: createCollectionUpdateOutputSchema(entitySchema),
293
- opt: true,
294
- },
295
- {
296
- name: `DECO_COLLECTION_${upperName}_DELETE` as const,
297
- inputSchema: CollectionDeleteInputSchema,
298
- outputSchema: CollectionDeleteOutputSchema,
299
- opt: true,
300
- },
301
- );
302
- }
303
-
304
- return bindings satisfies readonly ToolBinder[];
305
- }
306
-
307
- /**
308
- * Type helper to extract the collection binding type
309
- */
310
- export type CollectionBinding<
311
- TEntitySchema extends BaseCollectionEntitySchemaType,
312
- > = ReturnType<typeof createCollectionBindings<TEntitySchema>>;
313
-
314
- /**
315
- * Type helper to extract tool names from a collection binding
316
- */
317
- export type CollectionTools<
318
- TEntitySchema extends BaseCollectionEntitySchemaType,
319
- > = CollectionBinding<TEntitySchema>[number]["name"];
320
-
321
- // Export types for TypeScript usage
322
- export type CollectionListInput = z.infer<typeof CollectionListInputSchema>;
323
- export type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;
324
- export type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;
325
- export type CollectionDeleteOutput = z.infer<
326
- typeof CollectionDeleteOutputSchema
327
- >;
328
- export type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;
@@ -1,79 +0,0 @@
1
- /**
2
- * Models Well-Known Binding
3
- *
4
- * Defines the interface for AI model providers.
5
- * Any MCP that implements this binding can provide AI models and streaming endpoints.
6
- *
7
- * This binding uses collection bindings for LIST and GET operations (read-only).
8
- * Streaming endpoint information is included directly in the model entity schema.
9
- */
10
-
11
- import { z } from "zod";
12
- import type { Binder } from "../core/binder";
13
- import {
14
- BaseCollectionEntitySchema,
15
- createCollectionBindings,
16
- } from "./collections";
17
-
18
- /**
19
- * Model entity schema for AI models
20
- * Extends BaseCollectionEntitySchema with model-specific fields
21
- * Base schema already includes: id, title, created_at, updated_at, created_by, updated_by
22
- */
23
- export const ModelSchema = BaseCollectionEntitySchema.extend({
24
- // Model-specific fields
25
- logo: z.string().nullable(),
26
- description: z.string().nullable(),
27
- capabilities: z.array(z.string()),
28
- limits: z.object({
29
- contextWindow: z.number(),
30
- maxOutputTokens: z.number(),
31
- }).nullable(),
32
- costs: z.object({
33
- input: z.number(),
34
- output: z.number(),
35
- }).nullable(),
36
- // Provider information
37
- provider: z.enum([
38
- "openai",
39
- "anthropic",
40
- "google",
41
- "xai",
42
- "deepseek",
43
- "openai-compatible",
44
- "openrouter",
45
- ]).nullable(),
46
- // Streaming endpoint information
47
- endpoint: z.object({
48
- url: z.string().url(),
49
- method: z.string().default("POST"),
50
- contentType: z.string().default("application/json"),
51
- stream: z.boolean().default(true),
52
- }).nullable(),
53
- });
54
-
55
- /**
56
- * MODELS Collection Binding
57
- *
58
- * Collection bindings for models (read-only).
59
- * Provides LIST and GET operations for AI models.
60
- */
61
- export const MODELS_COLLECTION_BINDING = createCollectionBindings(
62
- "models",
63
- ModelSchema,
64
- { readOnly: true },
65
- );
66
-
67
- /**
68
- * MODELS Binding
69
- *
70
- * Defines the interface for AI model providers.
71
- * Any MCP that implements this binding can provide AI models and streaming endpoints.
72
- *
73
- * Required tools:
74
- * - DECO_COLLECTION_MODELS_LIST: List available AI models with their capabilities
75
- * - DECO_COLLECTION_MODELS_GET: Get a single model by ID (includes streaming endpoint info)
76
- */
77
- export const MODELS_BINDING = [
78
- ...MODELS_COLLECTION_BINDING,
79
- ] as const satisfies Binder;
File without changes