@decocms/bindings 0.1.1 → 0.1.2
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 +6 -6
- package/dist/chunk-IBOJHI67.js +132 -0
- package/dist/chunk-IBOJHI67.js.map +1 -0
- package/dist/well-known/collections.d.ts +293 -0
- package/dist/well-known/collections.js +3 -0
- package/dist/well-known/collections.js.map +1 -0
- package/dist/well-known/models.d.ts +32 -0
- package/dist/well-known/models.js +36 -0
- package/dist/well-known/models.js.map +1 -0
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -186,8 +186,8 @@ const isValid = checker.isImplementedBy(availableTools);
|
|
|
186
186
|
|
|
187
187
|
The package includes pre-defined bindings for common use cases. Well-known bindings are organized in the `well-known` folder and must be imported directly:
|
|
188
188
|
|
|
189
|
-
- **Collections**: `@decocms/bindings/
|
|
190
|
-
- **Models**: `@decocms/bindings/
|
|
189
|
+
- **Collections**: `@decocms/bindings/collections` - Collection bindings for SQL table-like structures
|
|
190
|
+
- **Models**: `@decocms/bindings/models` - AI model providers interface
|
|
191
191
|
|
|
192
192
|
See the [Collection Bindings](#collection-bindings) and [Models Bindings](#models-bindings) sections below for detailed usage examples.
|
|
193
193
|
|
|
@@ -243,7 +243,7 @@ Collection bindings are a well-known binding pattern for SQL table-like structur
|
|
|
243
243
|
|
|
244
244
|
```typescript
|
|
245
245
|
import { z } from "zod";
|
|
246
|
-
import { createCollectionBindings } from "@decocms/bindings/
|
|
246
|
+
import { createCollectionBindings } from "@decocms/bindings/collections";
|
|
247
247
|
import { createBindingChecker } from "@decocms/bindings";
|
|
248
248
|
|
|
249
249
|
// Define your entity schema extending the base schema
|
|
@@ -338,7 +338,7 @@ Models bindings provide a well-known interface for AI model providers. They use
|
|
|
338
338
|
### Using Models Bindings
|
|
339
339
|
|
|
340
340
|
```typescript
|
|
341
|
-
import { MODELS_BINDING, MODELS_COLLECTION_BINDING } from "@decocms/bindings/
|
|
341
|
+
import { MODELS_BINDING, MODELS_COLLECTION_BINDING } from "@decocms/bindings/models";
|
|
342
342
|
import { createBindingChecker } from "@decocms/bindings";
|
|
343
343
|
|
|
344
344
|
// Use the pre-defined MODELS_BINDING
|
|
@@ -407,7 +407,7 @@ Models follow the collection entity schema with additional model-specific fields
|
|
|
407
407
|
Here's how you would implement the models binding in an MCP server:
|
|
408
408
|
|
|
409
409
|
```typescript
|
|
410
|
-
import { MODELS_BINDING } from "@decocms/bindings/
|
|
410
|
+
import { MODELS_BINDING } from "@decocms/bindings/models";
|
|
411
411
|
import { impl } from "@decocms/sdk/mcp/bindings/binder";
|
|
412
412
|
|
|
413
413
|
const modelTools = impl(MODELS_BINDING, [
|
|
@@ -492,7 +492,7 @@ Here's how you would implement a collection binding in an MCP server:
|
|
|
492
492
|
|
|
493
493
|
```typescript
|
|
494
494
|
import { z } from "zod";
|
|
495
|
-
import { createCollectionBindings } from "@decocms/bindings/
|
|
495
|
+
import { createCollectionBindings } from "@decocms/bindings/collections";
|
|
496
496
|
import { impl } from "@decocms/sdk/mcp/bindings/binder";
|
|
497
497
|
|
|
498
498
|
const TodoSchema = z.object({
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/well-known/collections.ts
|
|
4
|
+
var BaseCollectionEntitySchema = z.object({
|
|
5
|
+
id: z.string().describe("Unique identifier for the entity"),
|
|
6
|
+
title: z.string().describe("Human-readable title for the entity"),
|
|
7
|
+
created_at: z.string().datetime(),
|
|
8
|
+
updated_at: z.string().datetime(),
|
|
9
|
+
created_by: z.string().optional(),
|
|
10
|
+
updated_by: z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
var WhereExpressionSchema = z.lazy(
|
|
13
|
+
() => z.union([
|
|
14
|
+
// Simple comparison
|
|
15
|
+
z.object({
|
|
16
|
+
field: z.array(z.string()),
|
|
17
|
+
operator: z.enum([
|
|
18
|
+
"eq",
|
|
19
|
+
"gt",
|
|
20
|
+
"gte",
|
|
21
|
+
"lt",
|
|
22
|
+
"lte",
|
|
23
|
+
"in",
|
|
24
|
+
"like",
|
|
25
|
+
"contains"
|
|
26
|
+
]),
|
|
27
|
+
value: z.unknown()
|
|
28
|
+
}),
|
|
29
|
+
// Logical operators
|
|
30
|
+
z.object({
|
|
31
|
+
operator: z.enum(["and", "or", "not"]),
|
|
32
|
+
conditions: z.array(WhereExpressionSchema)
|
|
33
|
+
})
|
|
34
|
+
])
|
|
35
|
+
);
|
|
36
|
+
var OrderByExpressionSchema = z.object({
|
|
37
|
+
field: z.array(z.string()),
|
|
38
|
+
direction: z.enum(["asc", "desc"]),
|
|
39
|
+
nulls: z.enum(["first", "last"]).optional()
|
|
40
|
+
});
|
|
41
|
+
var CollectionListInputSchema = z.object({
|
|
42
|
+
where: WhereExpressionSchema.optional().describe("Filter expression"),
|
|
43
|
+
orderBy: z.array(OrderByExpressionSchema).optional().describe("Sort expressions"),
|
|
44
|
+
limit: z.number().int().min(1).max(1e3).optional().describe("Maximum number of items to return"),
|
|
45
|
+
offset: z.number().int().min(0).optional().describe("Number of items to skip")
|
|
46
|
+
});
|
|
47
|
+
function createCollectionListOutputSchema(entitySchema) {
|
|
48
|
+
return z.object({
|
|
49
|
+
items: z.array(entitySchema).describe("Array of collection items"),
|
|
50
|
+
totalCount: z.number().int().min(0).optional().describe("Total number of matching items (if available)"),
|
|
51
|
+
hasMore: z.boolean().optional().describe("Whether there are more items available")
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
var CollectionGetInputSchema = z.object({
|
|
55
|
+
id: z.string().describe("ID of the entity to retrieve")
|
|
56
|
+
});
|
|
57
|
+
function createCollectionGetOutputSchema(entitySchema) {
|
|
58
|
+
return z.object({
|
|
59
|
+
item: entitySchema.nullable().describe("The retrieved item, or null if not found")
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function createCollectionInsertInputSchema(entitySchema) {
|
|
63
|
+
return z.object({
|
|
64
|
+
data: entitySchema.describe("Data for the new entity (id may be auto-generated)")
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function createCollectionInsertOutputSchema(entitySchema) {
|
|
68
|
+
return z.object({
|
|
69
|
+
item: entitySchema.describe("The created entity with generated id")
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function createCollectionUpdateInputSchema(entitySchema) {
|
|
73
|
+
return z.object({
|
|
74
|
+
id: z.string().describe("ID of the entity to update"),
|
|
75
|
+
data: entitySchema.partial().describe("Partial entity data to update")
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function createCollectionUpdateOutputSchema(entitySchema) {
|
|
79
|
+
return z.object({
|
|
80
|
+
item: entitySchema.describe("The updated entity")
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
var CollectionDeleteInputSchema = z.object({
|
|
84
|
+
id: z.string().describe("ID of the entity to delete")
|
|
85
|
+
});
|
|
86
|
+
var CollectionDeleteOutputSchema = z.object({
|
|
87
|
+
success: z.boolean().describe("Whether the deletion was successful"),
|
|
88
|
+
id: z.string().describe("ID of the deleted entity")
|
|
89
|
+
});
|
|
90
|
+
function createCollectionBindings(collectionName, entitySchema, options) {
|
|
91
|
+
const upperName = collectionName.toUpperCase();
|
|
92
|
+
const readOnly = options?.readOnly ?? false;
|
|
93
|
+
const bindings = [
|
|
94
|
+
{
|
|
95
|
+
name: `DECO_COLLECTION_${upperName}_LIST`,
|
|
96
|
+
inputSchema: CollectionListInputSchema,
|
|
97
|
+
outputSchema: createCollectionListOutputSchema(entitySchema)
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: `DECO_COLLECTION_${upperName}_GET`,
|
|
101
|
+
inputSchema: CollectionGetInputSchema,
|
|
102
|
+
outputSchema: createCollectionGetOutputSchema(entitySchema)
|
|
103
|
+
}
|
|
104
|
+
];
|
|
105
|
+
if (!readOnly) {
|
|
106
|
+
bindings.push(
|
|
107
|
+
{
|
|
108
|
+
name: `DECO_COLLECTION_${upperName}_INSERT`,
|
|
109
|
+
inputSchema: createCollectionInsertInputSchema(entitySchema),
|
|
110
|
+
outputSchema: createCollectionInsertOutputSchema(entitySchema),
|
|
111
|
+
opt: true
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: `DECO_COLLECTION_${upperName}_UPDATE`,
|
|
115
|
+
inputSchema: createCollectionUpdateInputSchema(entitySchema),
|
|
116
|
+
outputSchema: createCollectionUpdateOutputSchema(entitySchema),
|
|
117
|
+
opt: true
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: `DECO_COLLECTION_${upperName}_DELETE`,
|
|
121
|
+
inputSchema: CollectionDeleteInputSchema,
|
|
122
|
+
outputSchema: CollectionDeleteOutputSchema,
|
|
123
|
+
opt: true
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return bindings;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema };
|
|
131
|
+
//# sourceMappingURL=chunk-IBOJHI67.js.map
|
|
132
|
+
//# sourceMappingURL=chunk-IBOJHI67.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/well-known/collections.ts"],"names":[],"mappings":";;;AAsBO,IAAM,0BAAA,GAA6B,EAAE,MAAA,CAAO;AAAA,EACjD,EAAA,EAAI,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,kCAAkC,CAAA;AAAA,EAC1D,KAAA,EAAO,CAAA,CAAE,MAAA,EAAO,CAAE,SAAS,qCAAqC,CAAA;AAAA,EAChE,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,U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ClC,WAAA,EAAa,wBAAA;AAAA,MACb,YAAA,EAAc,gCAAgC,YAAY;AAAA;AAC5D,GACF;AAGA,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,QAAA,CAAS,IAAA;AAAA,MACP;AAAA,QACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,OAAA,CAAA;AAAA,QAClC,WAAA,EAAa,kCAAkC,YAAY,CAAA;AAAA,QAC3D,YAAA,EAAc,mCAAmC,YAAY,CAAA;AAAA,QAC7D,GAAA,EAAK;AAAA,OACP;AAAA,MACA;AAAA,QACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,OAAA,CAAA;AAAA,QAClC,WAAA,EAAa,kCAAkC,YAAY,CAAA;AAAA,QAC3D,YAAA,EAAc,mCAAmC,YAAY,CAAA;AAAA,QAC7D,GAAA,EAAK;AAAA,OACP;AAAA,MACA;AAAA,QACE,IAAA,EAAM,mBAAmB,SAAS,CAAA,OAAA,CAAA;AAAA,QAClC,WAAA,EAAa,2BAAA;AAAA,QACb,YAAA,EAAc,4BAAA;AAAA,QACd,GAAA,EAAK;AAAA;AACP,KACF;AAAA,EACF;AAEA,EAAA,OAAO,QAAA;AACT","file":"chunk-IBOJHI67.js","sourcesContent":["import { z } from \"zod\";\nimport type { ToolBinder } from \"../core/binder\";\n\n/**\n * Collection Bindings\n *\n * This module provides standardized tool bindings for Collections, representing\n * SQL table-like structures with CRUD + Search operations compatible with TanStack DB.\n *\n * Key Features:\n * - Generic collection bindings that work with any entity type\n * - Standardized tool naming: `DECO_COLLECTION_{COLLECTION}_*`\n * - Compatible with TanStack DB query-collection\n * - Full TypeScript support with proper type constraints\n * - Support for filtering, sorting, and pagination\n * - Simple id and title fields for human-readable identification\n */\n\n/**\n * Base schema for collection entities\n * All collection entities must have an id, title, and audit trail fields\n */\nexport const BaseCollectionEntitySchema = z.object({\n id: z.string().describe(\"Unique identifier for the entity\"),\n title: z.string().describe(\"Human-readable title for the entity\"),\n created_at: z.string().datetime(),\n updated_at: z.string().datetime(),\n created_by: z.string().optional(),\n updated_by: z.string().optional(),\n});\n\n/**\n * Type helper for BaseCollectionEntitySchema\n */\nexport type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;\n\n/**\n * Where expression type for filtering\n * Supports TanStack DB predicate push-down patterns\n */\nexport type WhereExpression =\n | {\n field: string[];\n operator: \"eq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"in\" | \"like\" | \"contains\";\n value: unknown;\n }\n | {\n operator: \"and\" | \"or\" | \"not\";\n conditions: WhereExpression[];\n };\n\n/**\n * Where expression schema for filtering\n * Supports TanStack DB predicate push-down patterns\n */\nexport const WhereExpressionSchema = z.lazy(() =>\n z.union([\n // Simple comparison\n z.object({\n field: z.array(z.string()),\n operator: z.enum([\n \"eq\",\n \"gt\",\n \"gte\",\n \"lt\",\n \"lte\",\n \"in\",\n \"like\",\n \"contains\",\n ]),\n value: z.unknown(),\n }),\n // Logical operators\n z.object({\n operator: z.enum([\"and\", \"or\", \"not\"]),\n conditions: z.array(WhereExpressionSchema),\n }),\n ])\n) as z.ZodType<WhereExpression>;\n\n/**\n * Order by expression for sorting\n */\nexport const OrderByExpressionSchema = z.object({\n field: z.array(z.string()),\n direction: z.enum([\"asc\", \"desc\"]),\n nulls: z.enum([\"first\", \"last\"]).optional(),\n});\n\n/**\n * List/Query input schema for collections\n * Compatible with TanStack DB LoadSubsetOptions\n */\nexport const CollectionListInputSchema = z.object({\n where: WhereExpressionSchema.optional().describe(\"Filter expression\"),\n orderBy: z\n .array(OrderByExpressionSchema)\n .optional()\n .describe(\"Sort expressions\"),\n limit: z\n .number()\n .int()\n .min(1)\n .max(1000)\n .optional()\n .describe(\"Maximum number of items to return\"),\n offset: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\"Number of items to skip\"),\n});\n\n/**\n * Factory function to create list output schema for a specific collection type\n */\nexport function createCollectionListOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n items: z.array(entitySchema).describe(\"Array of collection items\"),\n totalCount: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\"Total number of matching items (if available)\"),\n hasMore: z\n .boolean()\n .optional()\n .describe(\"Whether there are more items available\"),\n });\n}\n\n/**\n * Get by ID input schema\n */\nexport const CollectionGetInputSchema = z.object({\n id: z.string().describe(\"ID of the entity to retrieve\"),\n});\n\n/**\n * Factory function to create get output schema\n */\nexport function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema\n .nullable()\n .describe(\"The retrieved item, or null if not found\"),\n });\n}\n\n/**\n * Factory function to create insert input schema\n */\nexport function createCollectionInsertInputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n // Remove id field since it may be auto-generated by the server\n return z.object({\n data: entitySchema.describe(\"Data for the new entity (id may be auto-generated)\"),\n });\n}\n\n/**\n * Factory function to create insert output schema\n */\nexport function createCollectionInsertOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema.describe(\"The created entity with generated id\"),\n });\n}\n\n/**\n * Factory function to create update input schema\n */\nexport function createCollectionUpdateInputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n id: z.string().describe(\"ID of the entity to update\"),\n data: (entitySchema as unknown as z.AnyZodObject)\n .partial()\n .describe(\"Partial entity data to update\"),\n });\n}\n\n/**\n * Factory function to create update output schema\n */\nexport function createCollectionUpdateOutputSchema<T extends z.ZodTypeAny>(\n entitySchema: T,\n) {\n return z.object({\n item: entitySchema.describe(\"The updated entity\"),\n });\n}\n\n/**\n * Delete input schema\n */\nexport const CollectionDeleteInputSchema = z.object({\n id: z.string().describe(\"ID of the entity to delete\"),\n});\n\n/**\n * Delete output schema\n */\nexport const CollectionDeleteOutputSchema = z.object({\n success: z.boolean().describe(\"Whether the deletion was successful\"),\n id: z.string().describe(\"ID of the deleted entity\"),\n});\n\n/**\n * Options for creating collection bindings\n */\nexport interface CollectionBindingOptions {\n /**\n * If true, only LIST and GET operations will be included (read-only collection)\n * @default false\n */\n readOnly?: boolean;\n}\n\n/**\n * Creates generic collection bindings for a specific entity type\n *\n * This function generates standardized tool bindings that work with any collection/table\n * by accepting a custom entity schema and collection name. The bindings provide:\n * - DECO_COLLECTION_{NAME}_LIST - Query/search entities with filtering and sorting (required)\n * - DECO_COLLECTION_{NAME}_GET - Get a single entity by ID (required)\n * - DECO_COLLECTION_{NAME}_INSERT - Create a new entity (optional, excluded if readOnly=true)\n * - DECO_COLLECTION_{NAME}_UPDATE - Update an existing entity (optional, excluded if readOnly=true)\n * - DECO_COLLECTION_{NAME}_DELETE - Delete an entity (optional, excluded if readOnly=true)\n *\n * @param collectionName - The name of the collection/table (e.g., \"users\", \"products\", \"orders\")\n * @param entitySchema - The Zod schema for the entity type (must extend BaseCollectionEntitySchema)\n * @param options - Optional configuration for the collection bindings\n * @returns Array of tool bindings for Collection CRUD + Query operations\n *\n * @example\n * ```typescript\n * const UserSchema = z.object({\n * id: z.string(),\n * title: z.string(),\n * created_at: z.string().datetime(),\n * updated_at: z.string().datetime(),\n * created_by: z.string().optional(),\n * updated_by: z.string().optional(),\n * email: z.string().email(),\n * });\n *\n * // Full CRUD collection\n * const USER_COLLECTION_BINDING = createCollectionBindings(\"users\", UserSchema);\n *\n * // Read-only collection (only LIST and GET)\n * const READONLY_COLLECTION_BINDING = createCollectionBindings(\"products\", ProductSchema, { readOnly: true });\n * ```\n */\nexport function createCollectionBindings<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n>(\n collectionName: string,\n entitySchema: TEntitySchema,\n options?: CollectionBindingOptions,\n) {\n const upperName = collectionName.toUpperCase();\n const readOnly = options?.readOnly ?? false;\n\n const bindings: ToolBinder[] = [\n {\n name: `DECO_COLLECTION_${upperName}_LIST` as const,\n inputSchema: CollectionListInputSchema,\n outputSchema: createCollectionListOutputSchema(entitySchema),\n },\n {\n name: `DECO_COLLECTION_${upperName}_GET` as const,\n inputSchema: CollectionGetInputSchema,\n outputSchema: createCollectionGetOutputSchema(entitySchema),\n },\n ];\n\n // Only include mutation operations if not read-only\n if (!readOnly) {\n bindings.push(\n {\n name: `DECO_COLLECTION_${upperName}_INSERT` as const,\n inputSchema: createCollectionInsertInputSchema(entitySchema),\n outputSchema: createCollectionInsertOutputSchema(entitySchema),\n opt: true,\n },\n {\n name: `DECO_COLLECTION_${upperName}_UPDATE` as const,\n inputSchema: createCollectionUpdateInputSchema(entitySchema),\n outputSchema: createCollectionUpdateOutputSchema(entitySchema),\n opt: true,\n },\n {\n name: `DECO_COLLECTION_${upperName}_DELETE` as const,\n inputSchema: CollectionDeleteInputSchema,\n outputSchema: CollectionDeleteOutputSchema,\n opt: true,\n },\n );\n }\n\n return bindings satisfies readonly ToolBinder[];\n}\n\n/**\n * Type helper to extract the collection binding type\n */\nexport type CollectionBinding<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n> = ReturnType<typeof createCollectionBindings<TEntitySchema>>;\n\n/**\n * Type helper to extract tool names from a collection binding\n */\nexport type CollectionTools<\n TEntitySchema extends BaseCollectionEntitySchemaType,\n> = CollectionBinding<TEntitySchema>[number][\"name\"];\n\n// Export types for TypeScript usage\nexport type CollectionListInput = z.infer<typeof CollectionListInputSchema>;\nexport type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;\nexport type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;\nexport type CollectionDeleteOutput = z.infer<\n typeof CollectionDeleteOutputSchema\n>;\nexport type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;\n"]}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ToolBinder } from '../index.js';
|
|
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
|
+
* Base schema for collection entities
|
|
20
|
+
* All collection entities must have an id, title, and audit trail fields
|
|
21
|
+
*/
|
|
22
|
+
declare const BaseCollectionEntitySchema: z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
title: z.ZodString;
|
|
25
|
+
created_at: z.ZodString;
|
|
26
|
+
updated_at: z.ZodString;
|
|
27
|
+
created_by: z.ZodOptional<z.ZodString>;
|
|
28
|
+
updated_by: z.ZodOptional<z.ZodString>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
id: string;
|
|
31
|
+
title: string;
|
|
32
|
+
created_at: string;
|
|
33
|
+
updated_at: string;
|
|
34
|
+
created_by?: string | undefined;
|
|
35
|
+
updated_by?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
id: string;
|
|
38
|
+
title: string;
|
|
39
|
+
created_at: string;
|
|
40
|
+
updated_at: string;
|
|
41
|
+
created_by?: string | undefined;
|
|
42
|
+
updated_by?: string | undefined;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Type helper for BaseCollectionEntitySchema
|
|
46
|
+
*/
|
|
47
|
+
type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
|
|
48
|
+
/**
|
|
49
|
+
* Where expression type for filtering
|
|
50
|
+
* Supports TanStack DB predicate push-down patterns
|
|
51
|
+
*/
|
|
52
|
+
type WhereExpression = {
|
|
53
|
+
field: string[];
|
|
54
|
+
operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
|
|
55
|
+
value: unknown;
|
|
56
|
+
} | {
|
|
57
|
+
operator: "and" | "or" | "not";
|
|
58
|
+
conditions: WhereExpression[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Where expression schema for filtering
|
|
62
|
+
* Supports TanStack DB predicate push-down patterns
|
|
63
|
+
*/
|
|
64
|
+
declare const WhereExpressionSchema: z.ZodType<WhereExpression>;
|
|
65
|
+
/**
|
|
66
|
+
* Order by expression for sorting
|
|
67
|
+
*/
|
|
68
|
+
declare const OrderByExpressionSchema: z.ZodObject<{
|
|
69
|
+
field: z.ZodArray<z.ZodString, "many">;
|
|
70
|
+
direction: z.ZodEnum<["asc", "desc"]>;
|
|
71
|
+
nulls: z.ZodOptional<z.ZodEnum<["first", "last"]>>;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
field: string[];
|
|
74
|
+
direction: "asc" | "desc";
|
|
75
|
+
nulls?: "first" | "last" | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
field: string[];
|
|
78
|
+
direction: "asc" | "desc";
|
|
79
|
+
nulls?: "first" | "last" | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* List/Query input schema for collections
|
|
83
|
+
* Compatible with TanStack DB LoadSubsetOptions
|
|
84
|
+
*/
|
|
85
|
+
declare const CollectionListInputSchema: z.ZodObject<{
|
|
86
|
+
where: z.ZodOptional<z.ZodType<WhereExpression, z.ZodTypeDef, WhereExpression>>;
|
|
87
|
+
orderBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
88
|
+
field: z.ZodArray<z.ZodString, "many">;
|
|
89
|
+
direction: z.ZodEnum<["asc", "desc"]>;
|
|
90
|
+
nulls: z.ZodOptional<z.ZodEnum<["first", "last"]>>;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
field: string[];
|
|
93
|
+
direction: "asc" | "desc";
|
|
94
|
+
nulls?: "first" | "last" | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
field: string[];
|
|
97
|
+
direction: "asc" | "desc";
|
|
98
|
+
nulls?: "first" | "last" | undefined;
|
|
99
|
+
}>, "many">>;
|
|
100
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
101
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
where?: WhereExpression | undefined;
|
|
104
|
+
orderBy?: {
|
|
105
|
+
field: string[];
|
|
106
|
+
direction: "asc" | "desc";
|
|
107
|
+
nulls?: "first" | "last" | undefined;
|
|
108
|
+
}[] | undefined;
|
|
109
|
+
limit?: number | undefined;
|
|
110
|
+
offset?: number | undefined;
|
|
111
|
+
}, {
|
|
112
|
+
where?: WhereExpression | undefined;
|
|
113
|
+
orderBy?: {
|
|
114
|
+
field: string[];
|
|
115
|
+
direction: "asc" | "desc";
|
|
116
|
+
nulls?: "first" | "last" | undefined;
|
|
117
|
+
}[] | undefined;
|
|
118
|
+
limit?: number | undefined;
|
|
119
|
+
offset?: number | undefined;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Factory function to create list output schema for a specific collection type
|
|
123
|
+
*/
|
|
124
|
+
declare function createCollectionListOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
|
|
125
|
+
items: z.ZodArray<T, "many">;
|
|
126
|
+
totalCount: z.ZodOptional<z.ZodNumber>;
|
|
127
|
+
hasMore: z.ZodOptional<z.ZodBoolean>;
|
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
|
129
|
+
items: T["_output"][];
|
|
130
|
+
totalCount?: number | undefined;
|
|
131
|
+
hasMore?: boolean | undefined;
|
|
132
|
+
}, {
|
|
133
|
+
items: T["_input"][];
|
|
134
|
+
totalCount?: number | undefined;
|
|
135
|
+
hasMore?: boolean | undefined;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Get by ID input schema
|
|
139
|
+
*/
|
|
140
|
+
declare const CollectionGetInputSchema: z.ZodObject<{
|
|
141
|
+
id: z.ZodString;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
id: string;
|
|
144
|
+
}, {
|
|
145
|
+
id: string;
|
|
146
|
+
}>;
|
|
147
|
+
/**
|
|
148
|
+
* Factory function to create get output schema
|
|
149
|
+
*/
|
|
150
|
+
declare function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
|
|
151
|
+
item: z.ZodNullable<T>;
|
|
152
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
153
|
+
item: z.ZodNullable<T>;
|
|
154
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
|
|
155
|
+
item: z.ZodNullable<T>;
|
|
156
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
157
|
+
/**
|
|
158
|
+
* Factory function to create insert input schema
|
|
159
|
+
*/
|
|
160
|
+
declare function createCollectionInsertInputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
|
|
161
|
+
data: T;
|
|
162
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
163
|
+
data: T;
|
|
164
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
|
|
165
|
+
data: T;
|
|
166
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
167
|
+
/**
|
|
168
|
+
* Factory function to create insert output schema
|
|
169
|
+
*/
|
|
170
|
+
declare function createCollectionInsertOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
|
|
171
|
+
item: T;
|
|
172
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
173
|
+
item: T;
|
|
174
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
|
|
175
|
+
item: T;
|
|
176
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
177
|
+
/**
|
|
178
|
+
* Factory function to create update input schema
|
|
179
|
+
*/
|
|
180
|
+
declare function createCollectionUpdateInputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
|
|
181
|
+
id: z.ZodString;
|
|
182
|
+
data: z.ZodObject<{
|
|
183
|
+
[x: string]: z.ZodOptional<any>;
|
|
184
|
+
}, any, any, {
|
|
185
|
+
[x: string]: any;
|
|
186
|
+
}, {
|
|
187
|
+
[x: string]: any;
|
|
188
|
+
}>;
|
|
189
|
+
}, "strip", z.ZodTypeAny, {
|
|
190
|
+
id: string;
|
|
191
|
+
data: {
|
|
192
|
+
[x: string]: any;
|
|
193
|
+
};
|
|
194
|
+
}, {
|
|
195
|
+
id: string;
|
|
196
|
+
data: {
|
|
197
|
+
[x: string]: any;
|
|
198
|
+
};
|
|
199
|
+
}>;
|
|
200
|
+
/**
|
|
201
|
+
* Factory function to create update output schema
|
|
202
|
+
*/
|
|
203
|
+
declare function createCollectionUpdateOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
|
|
204
|
+
item: T;
|
|
205
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
206
|
+
item: T;
|
|
207
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
|
|
208
|
+
item: T;
|
|
209
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
210
|
+
/**
|
|
211
|
+
* Delete input schema
|
|
212
|
+
*/
|
|
213
|
+
declare const CollectionDeleteInputSchema: z.ZodObject<{
|
|
214
|
+
id: z.ZodString;
|
|
215
|
+
}, "strip", z.ZodTypeAny, {
|
|
216
|
+
id: string;
|
|
217
|
+
}, {
|
|
218
|
+
id: string;
|
|
219
|
+
}>;
|
|
220
|
+
/**
|
|
221
|
+
* Delete output schema
|
|
222
|
+
*/
|
|
223
|
+
declare const CollectionDeleteOutputSchema: z.ZodObject<{
|
|
224
|
+
success: z.ZodBoolean;
|
|
225
|
+
id: z.ZodString;
|
|
226
|
+
}, "strip", z.ZodTypeAny, {
|
|
227
|
+
id: string;
|
|
228
|
+
success: boolean;
|
|
229
|
+
}, {
|
|
230
|
+
id: string;
|
|
231
|
+
success: boolean;
|
|
232
|
+
}>;
|
|
233
|
+
/**
|
|
234
|
+
* Options for creating collection bindings
|
|
235
|
+
*/
|
|
236
|
+
interface CollectionBindingOptions {
|
|
237
|
+
/**
|
|
238
|
+
* If true, only LIST and GET operations will be included (read-only collection)
|
|
239
|
+
* @default false
|
|
240
|
+
*/
|
|
241
|
+
readOnly?: boolean;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Creates generic collection bindings for a specific entity type
|
|
245
|
+
*
|
|
246
|
+
* This function generates standardized tool bindings that work with any collection/table
|
|
247
|
+
* by accepting a custom entity schema and collection name. The bindings provide:
|
|
248
|
+
* - DECO_COLLECTION_{NAME}_LIST - Query/search entities with filtering and sorting (required)
|
|
249
|
+
* - DECO_COLLECTION_{NAME}_GET - Get a single entity by ID (required)
|
|
250
|
+
* - DECO_COLLECTION_{NAME}_INSERT - Create a new entity (optional, excluded if readOnly=true)
|
|
251
|
+
* - DECO_COLLECTION_{NAME}_UPDATE - Update an existing entity (optional, excluded if readOnly=true)
|
|
252
|
+
* - DECO_COLLECTION_{NAME}_DELETE - Delete an entity (optional, excluded if readOnly=true)
|
|
253
|
+
*
|
|
254
|
+
* @param collectionName - The name of the collection/table (e.g., "users", "products", "orders")
|
|
255
|
+
* @param entitySchema - The Zod schema for the entity type (must extend BaseCollectionEntitySchema)
|
|
256
|
+
* @param options - Optional configuration for the collection bindings
|
|
257
|
+
* @returns Array of tool bindings for Collection CRUD + Query operations
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* const UserSchema = z.object({
|
|
262
|
+
* id: z.string(),
|
|
263
|
+
* title: z.string(),
|
|
264
|
+
* created_at: z.string().datetime(),
|
|
265
|
+
* updated_at: z.string().datetime(),
|
|
266
|
+
* created_by: z.string().optional(),
|
|
267
|
+
* updated_by: z.string().optional(),
|
|
268
|
+
* email: z.string().email(),
|
|
269
|
+
* });
|
|
270
|
+
*
|
|
271
|
+
* // Full CRUD collection
|
|
272
|
+
* const USER_COLLECTION_BINDING = createCollectionBindings("users", UserSchema);
|
|
273
|
+
*
|
|
274
|
+
* // Read-only collection (only LIST and GET)
|
|
275
|
+
* const READONLY_COLLECTION_BINDING = createCollectionBindings("products", ProductSchema, { readOnly: true });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function createCollectionBindings<TEntitySchema extends BaseCollectionEntitySchemaType>(collectionName: string, entitySchema: TEntitySchema, options?: CollectionBindingOptions): ToolBinder<string, any, object>[];
|
|
279
|
+
/**
|
|
280
|
+
* Type helper to extract the collection binding type
|
|
281
|
+
*/
|
|
282
|
+
type CollectionBinding<TEntitySchema extends BaseCollectionEntitySchemaType> = ReturnType<typeof createCollectionBindings<TEntitySchema>>;
|
|
283
|
+
/**
|
|
284
|
+
* Type helper to extract tool names from a collection binding
|
|
285
|
+
*/
|
|
286
|
+
type CollectionTools<TEntitySchema extends BaseCollectionEntitySchemaType> = CollectionBinding<TEntitySchema>[number]["name"];
|
|
287
|
+
type CollectionListInput = z.infer<typeof CollectionListInputSchema>;
|
|
288
|
+
type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;
|
|
289
|
+
type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;
|
|
290
|
+
type CollectionDeleteOutput = z.infer<typeof CollectionDeleteOutputSchema>;
|
|
291
|
+
type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;
|
|
292
|
+
|
|
293
|
+
export { BaseCollectionEntitySchema, type BaseCollectionEntitySchemaType, type CollectionBinding, type CollectionBindingOptions, type CollectionDeleteInput, CollectionDeleteInputSchema, type CollectionDeleteOutput, CollectionDeleteOutputSchema, type CollectionGetInput, CollectionGetInputSchema, type CollectionListInput, CollectionListInputSchema, type CollectionTools, type OrderByExpression, OrderByExpressionSchema, type WhereExpression, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema } from '../chunk-IBOJHI67.js';
|
|
2
|
+
//# sourceMappingURL=collections.js.map
|
|
3
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"collections.js"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ToolBinder } from '../index.js';
|
|
2
|
+
import 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Models Well-Known Binding
|
|
6
|
+
*
|
|
7
|
+
* Defines the interface for AI model providers.
|
|
8
|
+
* Any MCP that implements this binding can provide AI models and streaming endpoints.
|
|
9
|
+
*
|
|
10
|
+
* This binding uses collection bindings for LIST and GET operations (read-only).
|
|
11
|
+
* Streaming endpoint information is included directly in the model entity schema.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* MODELS Collection Binding
|
|
15
|
+
*
|
|
16
|
+
* Collection bindings for models (read-only).
|
|
17
|
+
* Provides LIST and GET operations for AI models.
|
|
18
|
+
*/
|
|
19
|
+
declare const MODELS_COLLECTION_BINDING: ToolBinder<string, any, object>[];
|
|
20
|
+
/**
|
|
21
|
+
* MODELS Binding
|
|
22
|
+
*
|
|
23
|
+
* Defines the interface for AI model providers.
|
|
24
|
+
* Any MCP that implements this binding can provide AI models and streaming endpoints.
|
|
25
|
+
*
|
|
26
|
+
* Required tools:
|
|
27
|
+
* - DECO_COLLECTION_MODELS_LIST: List available AI models with their capabilities
|
|
28
|
+
* - DECO_COLLECTION_MODELS_GET: Get a single model by ID (includes streaming endpoint info)
|
|
29
|
+
*/
|
|
30
|
+
declare const MODELS_BINDING: readonly ToolBinder<string, any, object>[];
|
|
31
|
+
|
|
32
|
+
export { MODELS_BINDING, MODELS_COLLECTION_BINDING };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseCollectionEntitySchema, createCollectionBindings } from '../chunk-IBOJHI67.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
var ModelSchema = BaseCollectionEntitySchema.extend({
|
|
5
|
+
// Model-specific fields
|
|
6
|
+
logo: z.string().nullable(),
|
|
7
|
+
description: z.string().nullable(),
|
|
8
|
+
capabilities: z.array(z.string()),
|
|
9
|
+
limits: z.object({
|
|
10
|
+
contextWindow: z.number(),
|
|
11
|
+
maxOutputTokens: z.number()
|
|
12
|
+
}).nullable(),
|
|
13
|
+
costs: z.object({
|
|
14
|
+
input: z.number(),
|
|
15
|
+
output: z.number()
|
|
16
|
+
}).nullable(),
|
|
17
|
+
// Streaming endpoint information
|
|
18
|
+
endpoint: z.object({
|
|
19
|
+
url: z.string().url(),
|
|
20
|
+
method: z.string().default("POST"),
|
|
21
|
+
contentType: z.string().default("application/json"),
|
|
22
|
+
stream: z.boolean().default(true)
|
|
23
|
+
}).nullable()
|
|
24
|
+
});
|
|
25
|
+
var MODELS_COLLECTION_BINDING = createCollectionBindings(
|
|
26
|
+
"models",
|
|
27
|
+
ModelSchema,
|
|
28
|
+
{ readOnly: true }
|
|
29
|
+
);
|
|
30
|
+
var MODELS_BINDING = [
|
|
31
|
+
...MODELS_COLLECTION_BINDING
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export { MODELS_BINDING, MODELS_COLLECTION_BINDING };
|
|
35
|
+
//# sourceMappingURL=models.js.map
|
|
36
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/well-known/models.ts"],"names":[],"mappings":";;;AAsBA,IAAM,WAAA,GAAc,2BAA2B,MAAA,CAAO;AAAA;AAAA,EAEpD,IAAA,EAAM,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAC1B,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EACjC,YAAA,EAAc,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAQ,CAAA;AAAA,EAChC,MAAA,EAAQ,EAAE,MAAA,CAAO;AAAA,IACf,aAAA,EAAe,EAAE,MAAA,EAAO;AAAA,IACxB,eAAA,EAAiB,EAAE,MAAA;AAAO,GAC3B,EAAE,QAAA,EAAS;AAAA,EACZ,KAAA,EAAO,EAAE,MAAA,CAAO;AAAA,IACd,KAAA,EAAO,EAAE,MAAA,EAAO;AAAA,IAChB,MAAA,EAAQ,EAAE,MAAA;AAAO,GAClB,EAAE,QAAA,EAAS;AAAA;AAAA,EAEZ,QAAA,EAAU,EAAE,MAAA,CAAO;AAAA,IACjB,GAAA,EAAK,CAAA,CAAE,MAAA,EAAO,CAAE,GAAA,EAAI;AAAA,IACpB,MAAA,EAAQ,CAAA,CAAE,MAAA,EAAO,CAAE,QAAQ,MAAM,CAAA;AAAA,IACjC,WAAA,EAAa,CAAA,CAAE,MAAA,EAAO,CAAE,QAAQ,kBAAkB,CAAA;AAAA,IAClD,MAAA,EAAQ,CAAA,CAAE,OAAA,EAAQ,CAAE,QAAQ,IAAI;AAAA,GACjC,EAAE,QAAA;AACL,CAAC,CAAA;AAQM,IAAM,yBAAA,GAA4B,wBAAA;AAAA,EACvC,QAAA;AAAA,EACA,WAAA;AAAA,EACA,EAAE,UAAU,IAAA;AACd;AAYO,IAAM,cAAA,GAAiB;AAAA,EAC5B,GAAG;AACL","file":"models.js","sourcesContent":["/**\n * Models Well-Known Binding\n *\n * Defines the interface for AI model providers.\n * Any MCP that implements this binding can provide AI models and streaming endpoints.\n *\n * This binding uses collection bindings for LIST and GET operations (read-only).\n * Streaming endpoint information is included directly in the model entity schema.\n */\n\nimport { z } from \"zod\";\nimport type { Binder } from \"../core/binder\";\nimport {\n BaseCollectionEntitySchema,\n createCollectionBindings,\n} from \"./collections\";\n\n/**\n * Model entity schema for AI models\n * Extends BaseCollectionEntitySchema with model-specific fields\n * Base schema already includes: id, title, created_at, updated_at, created_by, updated_by\n */\nconst ModelSchema = BaseCollectionEntitySchema.extend({\n // Model-specific fields\n logo: z.string().nullable(),\n description: z.string().nullable(),\n capabilities: z.array(z.string()),\n limits: z.object({\n contextWindow: z.number(),\n maxOutputTokens: z.number(),\n }).nullable(),\n costs: z.object({\n input: z.number(),\n output: z.number(),\n }).nullable(),\n // Streaming endpoint information\n endpoint: z.object({\n url: z.string().url(),\n method: z.string().default(\"POST\"),\n contentType: z.string().default(\"application/json\"),\n stream: z.boolean().default(true),\n }).nullable(),\n});\n\n/**\n * MODELS Collection Binding\n *\n * Collection bindings for models (read-only).\n * Provides LIST and GET operations for AI models.\n */\nexport const MODELS_COLLECTION_BINDING = createCollectionBindings(\n \"models\",\n ModelSchema,\n { readOnly: true },\n);\n\n/**\n * MODELS Binding\n *\n * Defines the interface for AI model providers.\n * Any MCP that implements this binding can provide AI models and streaming endpoints.\n *\n * Required tools:\n * - DECO_COLLECTION_MODELS_LIST: List available AI models with their capabilities\n * - DECO_COLLECTION_MODELS_GET: Get a single model by ID (includes streaming endpoint info)\n */\nexport const MODELS_BINDING = [\n ...MODELS_COLLECTION_BINDING,\n] as const satisfies Binder;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/bindings",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -24,6 +24,16 @@
|
|
|
24
24
|
"source": "./src/index.ts",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./models": {
|
|
29
|
+
"source": "./src/well-known/models.ts",
|
|
30
|
+
"types": "./dist/well-known/models.d.ts",
|
|
31
|
+
"default": "./dist/well-known/models.js"
|
|
32
|
+
},
|
|
33
|
+
"./collections": {
|
|
34
|
+
"source": "./src/well-known/collections.ts",
|
|
35
|
+
"types": "./dist/well-known/collections.d.ts",
|
|
36
|
+
"default": "./dist/well-known/collections.js"
|
|
27
37
|
}
|
|
28
38
|
},
|
|
29
39
|
"devDependencies": {
|