@decocms/bindings 0.1.2 → 0.1.4

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.
@@ -9,30 +9,27 @@ var BaseCollectionEntitySchema = z.object({
9
9
  created_by: z.string().optional(),
10
10
  updated_by: z.string().optional()
11
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
- );
12
+ var ComparisonExpressionSchema = z.object({
13
+ field: z.array(z.string()),
14
+ operator: z.enum([
15
+ "eq",
16
+ "gt",
17
+ "gte",
18
+ "lt",
19
+ "lte",
20
+ "in",
21
+ "like",
22
+ "contains"
23
+ ]),
24
+ value: z.unknown()
25
+ });
26
+ var WhereExpressionSchema = z.union([
27
+ ComparisonExpressionSchema,
28
+ z.object({
29
+ operator: z.enum(["and", "or", "not"]),
30
+ conditions: z.array(ComparisonExpressionSchema)
31
+ })
32
+ ]);
36
33
  var OrderByExpressionSchema = z.object({
37
34
  field: z.array(z.string()),
38
35
  direction: z.enum(["asc", "desc"]),
@@ -128,5 +125,5 @@ function createCollectionBindings(collectionName, entitySchema, options) {
128
125
  }
129
126
 
130
127
  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
128
+ //# sourceMappingURL=chunk-L7E6ONLJ.js.map
129
+ //# sourceMappingURL=chunk-L7E6ONLJ.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,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACzB,CAAC;AAUD,IAAM,0BAAA,GAA6B,EAAE,MAAA,CAAO;AAAA,EAC1C,KAAA,EAAO,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAQ,CAAA;AAAA,EACzB,QAAA,EAAU,EAAE,IAAA,CAAK;AAAA,IACf,IAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAA;AAAA,IACA;AAAA,GACD,CAAA;AAAA,EACD,KAAA,EAAO,EAAE,OAAA;AACX,CAAC,CAAA;AAMM,IAAM,qBAAA,GAAwB,EAAE,KAAA,CAAM;AAAA,EAC3C,0BAAA;AAAA,EACA,EAAE,MAAA,CAAO;AAAA,IACP,UAAU,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAO,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IACrC,UAAA,EAAY,CAAA,CAAE,KAAA,CAAM,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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 * Comparison expression schema for filtering\n */\nconst ComparisonExpressionSchema = 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\n/**\n * Where expression schema for filtering\n * Supports TanStack DB predicate push-down patterns\n */\nexport const WhereExpressionSchema = z.union([\n ComparisonExpressionSchema,\n z.object({\n operator: z.enum([\"and\", \"or\", \"not\"]),\n conditions: z.array(ComparisonExpressionSchema),\n }),\n]);\n\n/**\n * Where expression type for filtering\n * Derived from WhereExpressionSchema\n */\nexport type WhereExpression = z.infer<typeof WhereExpressionSchema>;\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"]}
package/dist/index.js CHANGED
@@ -46,6 +46,7 @@ function createBindingChecker(binderTools) {
46
46
  return false;
47
47
  }
48
48
  } catch (error) {
49
+ console.error("Schema diff failed", error);
49
50
  return false;
50
51
  }
51
52
  } else if (binderInputSchema && !toolInputSchema) {
@@ -63,6 +64,7 @@ function createBindingChecker(binderTools) {
63
64
  return false;
64
65
  }
65
66
  } catch (error) {
67
+ console.error("Schema diff failed", error);
66
68
  return false;
67
69
  }
68
70
  } else if (binderOutputSchema && !toolOutputSchema) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/core/binder.ts"],"names":["jsonSchema"],"mappings":";;;;AAwEA,SAAS,gBAAgB,MAAA,EAAkD;AACzE,EAAA,IAAI,CAAC,QAAQ,OAAO,MAAA;AAGpB,EAAA,IAAI,OAAO,IAAA,EAAM;AACf,IAAA,MAAMA,WAAAA,GAAa,gBAAgB,MAAA,EAAQ;AAAA;AAAA,MAEzC,YAAA,EAAc;AAAA,KACf,CAAA;AAGD,IAAA,IAAIA,WAAAA,CAAW,SAAS,QAAA,EAAU;AAChC,MAAA,OAAOA,WAAAA,CAAW,oBAAA;AAAA,IACpB;AAEA,IAAA,OAAOA,WAAAA;AAAA,EACT;AAGA,EAAA,MAAM,UAAA,GAAa,MAAA;AAGnB,EAAA,IAAI,UAAA,CAAW,IAAA,KAAS,QAAA,IAAY,sBAAA,IAA0B,UAAA,EAAY;AACxE,IAAA,MAAM,IAAA,GAAO,EAAE,GAAG,UAAA,EAAW;AAC7B,IAAA,OAAO,IAAA,CAAK,oBAAA;AACZ,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,UAAA;AACT;AAoCO,SAAS,qBACd,WAAA,EACgB;AAChB,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAO,KAAA,KAA6B;AACnD,MAAA,KAAA,MAAW,cAAc,WAAA,EAAa;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AAM,WAAA,CAAY;AAAA,cACnC,YAAA,EAAc,kBAAA;AAAA,cACd,iBAAA,EAAmB;AAAA,aACpB,CAAA;AAGD,YAAA,IAAI,WAAW,aAAA,EAAe;AAC5B,cAAA,OAAO,KAAA;AAAA,YACT;AAAA,UACF,SAAS,KAAA,EAAO;AAEd,YAAA,OAAO,KAAA;AAAA,UACT;AAAA,QACF,CAAA,MAAA,IAAW,kBAAA,IAAsB,CAAC,gBAAA,EAAkB;AAElD,UAAA,OAAO,KAAA;AAAA,QACT;AAAA,MACF;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Core Binder Types and Utilities\n *\n * This module provides the core types and utilities for the bindings system.\n * Bindings define standardized interfaces that integrations (MCPs) can implement.\n */\n\nimport type { ZodType } from \"zod\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { diffSchemas } from \"json-schema-diff\";\n\n/**\n * ToolBinder defines a single tool within a binding.\n * It specifies the tool name, input/output schemas, and whether it's optional.\n *\n * @template TName - The tool name (can be a string or RegExp for pattern matching)\n * @template TInput - The input type (inferred from inputSchema)\n * @template TReturn - The return type (inferred from outputSchema)\n */\nexport interface ToolBinder<\n TName extends string | RegExp = string,\n // biome-ignore lint/suspicious/noExplicitAny: Generic type parameter\n TInput = any,\n TReturn extends object | null | boolean = object,\n> {\n /** The name of the tool (e.g., \"DECO_CHAT_CHANNELS_JOIN\") */\n name: TName;\n\n /** Zod schema for validating tool input */\n inputSchema: ZodType<TInput>;\n\n /** Optional Zod schema for validating tool output */\n outputSchema?: ZodType<TReturn>;\n\n /**\n * Whether this tool is optional in the binding.\n * If true, an implementation doesn't need to provide this tool.\n */\n opt?: true;\n}\n\n/**\n * Binder represents a collection of tool definitions that form a binding.\n * A binding is like a TypeScript interface - it defines what tools must be implemented.\n *\n * @template TDefinition - Array of ToolBinder definitions\n *\n * @example\n * ```ts\n * const MY_BINDING = [{\n * name: \"MY_TOOL\" as const,\n * inputSchema: z.object({ id: z.string() }),\n * outputSchema: z.object({ success: z.boolean() }),\n * }] as const satisfies Binder;\n * ```\n */\nexport type Binder<\n TDefinition extends readonly ToolBinder[] = readonly ToolBinder[],\n> = TDefinition;\n\n/**\n * Tool with schemas for validation\n */\nexport interface ToolWithSchemas {\n name: string;\n inputSchema?: ZodType<any> | Record<string, unknown>;\n outputSchema?: ZodType<any> | Record<string, unknown>;\n}\n\n/**\n * Converts a schema to JSON Schema format if it's a Zod schema\n */\nfunction normalizeSchema(schema: any): Record<string, unknown> | undefined {\n if (!schema) return undefined;\n\n // If it's a Zod schema (has _def property), convert it\n if (schema._def) {\n const jsonSchema = zodToJsonSchema(schema, {\n // Don't add additionalProperties: false to allow structural compatibility\n $refStrategy: \"none\",\n }) as Record<string, unknown>;\n\n // Remove additionalProperties constraint to allow subtyping\n if (jsonSchema.type === \"object\") {\n delete jsonSchema.additionalProperties;\n }\n\n return jsonSchema;\n }\n\n // Otherwise assume it's already a JSON Schema\n const jsonSchema = schema as Record<string, unknown>;\n\n // Remove additionalProperties constraint if present\n if (jsonSchema.type === \"object\" && \"additionalProperties\" in jsonSchema) {\n const copy = { ...jsonSchema };\n delete copy.additionalProperties;\n return copy;\n }\n\n return jsonSchema;\n}\n\n/**\n * Binding checker interface\n */\nexport interface BindingChecker {\n /**\n * Check if a set of tools implements the binding with full schema validation.\n *\n * Validates:\n * - Tool name matches (exact or regex)\n * - Input schema: Tool accepts what binder requires (no removals from binder to tool)\n * - Output schema: Tool provides what binder expects (no removals from tool to binder)\n *\n * @param tools - Array of tools with names and schemas\n * @returns Promise<boolean> - true if all tools implement the binding correctly\n */\n isImplementedBy: (tools: ToolWithSchemas[]) => Promise<boolean>;\n}\n\n/**\n * Creates a binding checker with full schema validation using json-schema-diff.\n *\n * This performs strict compatibility checking:\n * - For input schemas: Validates that the tool can accept what the binder requires\n * - For output schemas: Validates that the tool provides what the binder expects\n *\n * @param binderTools - The binding definition to check against\n * @returns A binding checker with an async isImplementedBy method\n *\n * @example\n * ```ts\n * const checker = createBindingChecker(MY_BINDING);\n * const isCompatible = await checker.isImplementedBy(availableTools);\n * ```\n */\nexport function createBindingChecker<TDefinition extends readonly ToolBinder[]>(\n binderTools: TDefinition,\n): BindingChecker {\n return {\n isImplementedBy: async (tools: ToolWithSchemas[]) => {\n for (const binderTool of binderTools) {\n // Find matching tool by name (exact or regex)\n const pattern =\n typeof binderTool.name === \"string\"\n ? new RegExp(`^${binderTool.name}$`)\n : binderTool.name;\n\n const matchedTool = tools.find((t) => pattern.test(t.name));\n\n // Skip optional tools that aren't present\n if (!matchedTool && binderTool.opt) {\n continue;\n }\n\n // Required tool not found\n if (!matchedTool) {\n return false;\n }\n\n // === INPUT SCHEMA VALIDATION ===\n // Tool must accept what binder requires\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't accept something binder requires\n const binderInputSchema = normalizeSchema(binderTool.inputSchema);\n const toolInputSchema = normalizeSchema(matchedTool.inputSchema);\n\n if (binderInputSchema && toolInputSchema) {\n try {\n const inputDiff = await diffSchemas({\n sourceSchema: binderInputSchema,\n destinationSchema: toolInputSchema,\n });\n\n // If something was removed from binder to tool, tool can't accept it\n if (inputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderInputSchema && !toolInputSchema) {\n // Binder requires input schema but tool doesn't have one\n return false;\n }\n\n // === OUTPUT SCHEMA VALIDATION ===\n // Tool must provide what binder expects (but can provide more)\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't provide something binder expects\n const binderOutputSchema = normalizeSchema(binderTool.outputSchema);\n const toolOutputSchema = normalizeSchema(matchedTool.outputSchema);\n\n if (binderOutputSchema && toolOutputSchema) {\n try {\n const outputDiff = await diffSchemas({\n sourceSchema: binderOutputSchema,\n destinationSchema: toolOutputSchema,\n });\n\n // If something was removed from binder to tool, tool doesn't provide it\n if (outputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderOutputSchema && !toolOutputSchema) {\n // Binder expects output schema but tool doesn't have one\n return false;\n }\n }\n\n return true;\n },\n };\n}\n\n"]}
1
+ {"version":3,"sources":["../src/core/binder.ts"],"names":["jsonSchema"],"mappings":";;;;AAwEA,SAAS,gBAAgB,MAAA,EAAkD;AACzE,EAAA,IAAI,CAAC,QAAQ,OAAO,MAAA;AAGpB,EAAA,IAAI,OAAO,IAAA,EAAM;AACf,IAAA,MAAMA,WAAAA,GAAa,gBAAgB,MAAA,EAAQ;AAAA;AAAA,MAEzC,YAAA,EAAc;AAAA,KACf,CAAA;AAGD,IAAA,IAAIA,WAAAA,CAAW,SAAS,QAAA,EAAU;AAChC,MAAA,OAAOA,WAAAA,CAAW,oBAAA;AAAA,IACpB;AAEA,IAAA,OAAOA,WAAAA;AAAA,EACT;AAGA,EAAA,MAAM,UAAA,GAAa,MAAA;AAGnB,EAAA,IAAI,UAAA,CAAW,IAAA,KAAS,QAAA,IAAY,sBAAA,IAA0B,UAAA,EAAY;AACxE,IAAA,MAAM,IAAA,GAAO,EAAE,GAAG,UAAA,EAAW;AAC7B,IAAA,OAAO,IAAA,CAAK,oBAAA;AACZ,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,OAAO,UAAA;AACT;AAoCO,SAAS,qBACd,WAAA,EACgB;AAChB,EAAA,OAAO;AAAA,IACL,eAAA,EAAiB,OAAO,KAAA,KAA6B;AACnD,MAAA,KAAA,MAAW,cAAc,WAAA,EAAa;AAEpC,QAAA,MAAM,OAAA,GAAU,OAAO,UAAA,CAAW,IAAA,KAAS,QAAA,GACvC,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,UAAA,CAAW,IAAI,CAAA,CAAA,CAAG,CAAA,GACjC,UAAA,CAAW,IAAA;AAEf,QAAA,MAAM,WAAA,GAAc,MAAM,IAAA,CAAK,CAAC,MAAM,OAAA,CAAQ,IAAA,CAAK,CAAA,CAAE,IAAI,CAAC,CAAA;AAG1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AK,CAAA;AAEzC,YAAA,OAAO,KAAA;AAAA,UACT;AAAA,QACF,CAAA,MAAA,IAAW,kBAAA,IAAsB,CAAC,gBAAA,EAAkB;AAElD,UAAA,OAAO,KAAA;AAAA,QACT;AAAA,MACF;AAEA,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Core Binder Types and Utilities\n *\n * This module provides the core types and utilities for the bindings system.\n * Bindings define standardized interfaces that integrations (MCPs) can implement.\n */\n\nimport type { ZodType } from \"zod\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { diffSchemas } from \"json-schema-diff\";\n\n/**\n * ToolBinder defines a single tool within a binding.\n * It specifies the tool name, input/output schemas, and whether it's optional.\n *\n * @template TName - The tool name (can be a string or RegExp for pattern matching)\n * @template TInput - The input type (inferred from inputSchema)\n * @template TReturn - The return type (inferred from outputSchema)\n */\nexport interface ToolBinder<\n TName extends string | RegExp = string,\n // biome-ignore lint/suspicious/noExplicitAny: Generic type parameter\n TInput = any,\n TReturn extends object | null | boolean = object,\n> {\n /** The name of the tool (e.g., \"DECO_CHAT_CHANNELS_JOIN\") */\n name: TName;\n\n /** Zod schema for validating tool input */\n inputSchema: ZodType<TInput>;\n\n /** Optional Zod schema for validating tool output */\n outputSchema?: ZodType<TReturn>;\n\n /**\n * Whether this tool is optional in the binding.\n * If true, an implementation doesn't need to provide this tool.\n */\n opt?: true;\n}\n\n/**\n * Binder represents a collection of tool definitions that form a binding.\n * A binding is like a TypeScript interface - it defines what tools must be implemented.\n *\n * @template TDefinition - Array of ToolBinder definitions\n *\n * @example\n * ```ts\n * const MY_BINDING = [{\n * name: \"MY_TOOL\" as const,\n * inputSchema: z.object({ id: z.string() }),\n * outputSchema: z.object({ success: z.boolean() }),\n * }] as const satisfies Binder;\n * ```\n */\nexport type Binder<\n TDefinition extends readonly ToolBinder[] = readonly ToolBinder[],\n> = TDefinition;\n\n/**\n * Tool with schemas for validation\n */\nexport interface ToolWithSchemas {\n name: string;\n inputSchema?: ZodType<any> | Record<string, unknown>;\n outputSchema?: ZodType<any> | Record<string, unknown>;\n}\n\n/**\n * Converts a schema to JSON Schema format if it's a Zod schema\n */\nfunction normalizeSchema(schema: any): Record<string, unknown> | undefined {\n if (!schema) return undefined;\n\n // If it's a Zod schema (has _def property), convert it\n if (schema._def) {\n const jsonSchema = zodToJsonSchema(schema, {\n // Don't add additionalProperties: false to allow structural compatibility\n $refStrategy: \"none\",\n }) as Record<string, unknown>;\n\n // Remove additionalProperties constraint to allow subtyping\n if (jsonSchema.type === \"object\") {\n delete jsonSchema.additionalProperties;\n }\n\n return jsonSchema;\n }\n\n // Otherwise assume it's already a JSON Schema\n const jsonSchema = schema as Record<string, unknown>;\n\n // Remove additionalProperties constraint if present\n if (jsonSchema.type === \"object\" && \"additionalProperties\" in jsonSchema) {\n const copy = { ...jsonSchema };\n delete copy.additionalProperties;\n return copy;\n }\n\n return jsonSchema;\n}\n\n/**\n * Binding checker interface\n */\nexport interface BindingChecker {\n /**\n * Check if a set of tools implements the binding with full schema validation.\n *\n * Validates:\n * - Tool name matches (exact or regex)\n * - Input schema: Tool accepts what binder requires (no removals from binder to tool)\n * - Output schema: Tool provides what binder expects (no removals from tool to binder)\n *\n * @param tools - Array of tools with names and schemas\n * @returns Promise<boolean> - true if all tools implement the binding correctly\n */\n isImplementedBy: (tools: ToolWithSchemas[]) => Promise<boolean>;\n}\n\n/**\n * Creates a binding checker with full schema validation using json-schema-diff.\n *\n * This performs strict compatibility checking:\n * - For input schemas: Validates that the tool can accept what the binder requires\n * - For output schemas: Validates that the tool provides what the binder expects\n *\n * @param binderTools - The binding definition to check against\n * @returns A binding checker with an async isImplementedBy method\n *\n * @example\n * ```ts\n * const checker = createBindingChecker(MY_BINDING);\n * const isCompatible = await checker.isImplementedBy(availableTools);\n * ```\n */\nexport function createBindingChecker<TDefinition extends readonly ToolBinder[]>(\n binderTools: TDefinition,\n): BindingChecker {\n return {\n isImplementedBy: async (tools: ToolWithSchemas[]) => {\n for (const binderTool of binderTools) {\n // Find matching tool by name (exact or regex)\n const pattern = typeof binderTool.name === \"string\"\n ? new RegExp(`^${binderTool.name}$`)\n : binderTool.name;\n\n const matchedTool = tools.find((t) => pattern.test(t.name));\n\n // Skip optional tools that aren't present\n if (!matchedTool && binderTool.opt) {\n continue;\n }\n\n // Required tool not found\n if (!matchedTool) {\n return false;\n }\n\n // === INPUT SCHEMA VALIDATION ===\n // Tool must accept what binder requires\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't accept something binder requires\n const binderInputSchema = normalizeSchema(binderTool.inputSchema);\n const toolInputSchema = normalizeSchema(matchedTool.inputSchema);\n\n if (binderInputSchema && toolInputSchema) {\n try {\n const inputDiff = await diffSchemas({\n sourceSchema: binderInputSchema,\n destinationSchema: toolInputSchema,\n });\n\n // If something was removed from binder to tool, tool can't accept it\n if (inputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n console.error(\"Schema diff failed\", error);\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderInputSchema && !toolInputSchema) {\n // Binder requires input schema but tool doesn't have one\n return false;\n }\n\n // === OUTPUT SCHEMA VALIDATION ===\n // Tool must provide what binder expects (but can provide more)\n // Check: binder (source) -> tool (destination)\n // If removals found, tool doesn't provide something binder expects\n const binderOutputSchema = normalizeSchema(binderTool.outputSchema);\n const toolOutputSchema = normalizeSchema(matchedTool.outputSchema);\n\n if (binderOutputSchema && toolOutputSchema) {\n try {\n const outputDiff = await diffSchemas({\n sourceSchema: binderOutputSchema,\n destinationSchema: toolOutputSchema,\n });\n\n // If something was removed from binder to tool, tool doesn't provide it\n if (outputDiff.removalsFound) {\n return false;\n }\n } catch (error) {\n console.error(\"Schema diff failed\", error);\n // Schema diff failed - consider incompatible\n return false;\n }\n } else if (binderOutputSchema && !toolOutputSchema) {\n // Binder expects output schema but tool doesn't have one\n return false;\n }\n }\n\n return true;\n },\n };\n}\n"]}
@@ -46,22 +46,56 @@ declare const BaseCollectionEntitySchema: z.ZodObject<{
46
46
  */
47
47
  type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
48
48
  /**
49
- * Where expression type for filtering
49
+ * Where expression schema for filtering
50
50
  * Supports TanStack DB predicate push-down patterns
51
51
  */
52
- type WhereExpression = {
52
+ declare const WhereExpressionSchema: z.ZodUnion<[z.ZodObject<{
53
+ field: z.ZodArray<z.ZodString, "many">;
54
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
55
+ value: z.ZodUnknown;
56
+ }, "strip", z.ZodTypeAny, {
53
57
  field: string[];
54
58
  operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
55
- value: unknown;
56
- } | {
59
+ value?: unknown;
60
+ }, {
61
+ field: string[];
62
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
63
+ value?: unknown;
64
+ }>, z.ZodObject<{
65
+ operator: z.ZodEnum<["and", "or", "not"]>;
66
+ conditions: z.ZodArray<z.ZodObject<{
67
+ field: z.ZodArray<z.ZodString, "many">;
68
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
69
+ value: z.ZodUnknown;
70
+ }, "strip", z.ZodTypeAny, {
71
+ field: string[];
72
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
73
+ value?: unknown;
74
+ }, {
75
+ field: string[];
76
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
77
+ value?: unknown;
78
+ }>, "many">;
79
+ }, "strip", z.ZodTypeAny, {
57
80
  operator: "and" | "or" | "not";
58
- conditions: WhereExpression[];
59
- };
81
+ conditions: {
82
+ field: string[];
83
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
84
+ value?: unknown;
85
+ }[];
86
+ }, {
87
+ operator: "and" | "or" | "not";
88
+ conditions: {
89
+ field: string[];
90
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
91
+ value?: unknown;
92
+ }[];
93
+ }>]>;
60
94
  /**
61
- * Where expression schema for filtering
62
- * Supports TanStack DB predicate push-down patterns
95
+ * Where expression type for filtering
96
+ * Derived from WhereExpressionSchema
63
97
  */
64
- declare const WhereExpressionSchema: z.ZodType<WhereExpression>;
98
+ type WhereExpression = z.infer<typeof WhereExpressionSchema>;
65
99
  /**
66
100
  * Order by expression for sorting
67
101
  */
@@ -83,7 +117,48 @@ declare const OrderByExpressionSchema: z.ZodObject<{
83
117
  * Compatible with TanStack DB LoadSubsetOptions
84
118
  */
85
119
  declare const CollectionListInputSchema: z.ZodObject<{
86
- where: z.ZodOptional<z.ZodType<WhereExpression, z.ZodTypeDef, WhereExpression>>;
120
+ where: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
121
+ field: z.ZodArray<z.ZodString, "many">;
122
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
123
+ value: z.ZodUnknown;
124
+ }, "strip", z.ZodTypeAny, {
125
+ field: string[];
126
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
127
+ value?: unknown;
128
+ }, {
129
+ field: string[];
130
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
131
+ value?: unknown;
132
+ }>, z.ZodObject<{
133
+ operator: z.ZodEnum<["and", "or", "not"]>;
134
+ conditions: z.ZodArray<z.ZodObject<{
135
+ field: z.ZodArray<z.ZodString, "many">;
136
+ operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
137
+ value: z.ZodUnknown;
138
+ }, "strip", z.ZodTypeAny, {
139
+ field: string[];
140
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
141
+ value?: unknown;
142
+ }, {
143
+ field: string[];
144
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
145
+ value?: unknown;
146
+ }>, "many">;
147
+ }, "strip", z.ZodTypeAny, {
148
+ operator: "and" | "or" | "not";
149
+ conditions: {
150
+ field: string[];
151
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
152
+ value?: unknown;
153
+ }[];
154
+ }, {
155
+ operator: "and" | "or" | "not";
156
+ conditions: {
157
+ field: string[];
158
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
159
+ value?: unknown;
160
+ }[];
161
+ }>]>>;
87
162
  orderBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
88
163
  field: z.ZodArray<z.ZodString, "many">;
89
164
  direction: z.ZodEnum<["asc", "desc"]>;
@@ -100,7 +175,18 @@ declare const CollectionListInputSchema: z.ZodObject<{
100
175
  limit: z.ZodOptional<z.ZodNumber>;
101
176
  offset: z.ZodOptional<z.ZodNumber>;
102
177
  }, "strip", z.ZodTypeAny, {
103
- where?: WhereExpression | undefined;
178
+ where?: {
179
+ field: string[];
180
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
181
+ value?: unknown;
182
+ } | {
183
+ operator: "and" | "or" | "not";
184
+ conditions: {
185
+ field: string[];
186
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
187
+ value?: unknown;
188
+ }[];
189
+ } | undefined;
104
190
  orderBy?: {
105
191
  field: string[];
106
192
  direction: "asc" | "desc";
@@ -109,7 +195,18 @@ declare const CollectionListInputSchema: z.ZodObject<{
109
195
  limit?: number | undefined;
110
196
  offset?: number | undefined;
111
197
  }, {
112
- where?: WhereExpression | undefined;
198
+ where?: {
199
+ field: string[];
200
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
201
+ value?: unknown;
202
+ } | {
203
+ operator: "and" | "or" | "not";
204
+ conditions: {
205
+ field: string[];
206
+ operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
207
+ value?: unknown;
208
+ }[];
209
+ } | undefined;
113
210
  orderBy?: {
114
211
  field: string[];
115
212
  direction: "asc" | "desc";
@@ -1,3 +1,3 @@
1
- export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema } from '../chunk-IBOJHI67.js';
1
+ export { BaseCollectionEntitySchema, CollectionDeleteInputSchema, CollectionDeleteOutputSchema, CollectionGetInputSchema, CollectionListInputSchema, OrderByExpressionSchema, WhereExpressionSchema, createCollectionBindings, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema } from '../chunk-L7E6ONLJ.js';
2
2
  //# sourceMappingURL=collections.js.map
3
3
  //# sourceMappingURL=collections.js.map
@@ -1,15 +1,107 @@
1
1
  import { ToolBinder } from '../index.js';
2
- import 'zod';
2
+ import { z } from 'zod';
3
3
 
4
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.
5
+ * Model entity schema for AI models
6
+ * Extends BaseCollectionEntitySchema with model-specific fields
7
+ * Base schema already includes: id, title, created_at, updated_at, created_by, updated_by
12
8
  */
9
+ declare const ModelSchema: z.ZodObject<{
10
+ id: z.ZodString;
11
+ title: z.ZodString;
12
+ created_at: z.ZodString;
13
+ updated_at: z.ZodString;
14
+ created_by: z.ZodOptional<z.ZodString>;
15
+ updated_by: z.ZodOptional<z.ZodString>;
16
+ } & {
17
+ logo: z.ZodNullable<z.ZodString>;
18
+ description: z.ZodNullable<z.ZodString>;
19
+ capabilities: z.ZodArray<z.ZodString, "many">;
20
+ limits: z.ZodNullable<z.ZodObject<{
21
+ contextWindow: z.ZodNumber;
22
+ maxOutputTokens: z.ZodNumber;
23
+ }, "strip", z.ZodTypeAny, {
24
+ contextWindow: number;
25
+ maxOutputTokens: number;
26
+ }, {
27
+ contextWindow: number;
28
+ maxOutputTokens: number;
29
+ }>>;
30
+ costs: z.ZodNullable<z.ZodObject<{
31
+ input: z.ZodNumber;
32
+ output: z.ZodNumber;
33
+ }, "strip", z.ZodTypeAny, {
34
+ input: number;
35
+ output: number;
36
+ }, {
37
+ input: number;
38
+ output: number;
39
+ }>>;
40
+ endpoint: z.ZodNullable<z.ZodObject<{
41
+ url: z.ZodString;
42
+ method: z.ZodDefault<z.ZodString>;
43
+ contentType: z.ZodDefault<z.ZodString>;
44
+ stream: z.ZodDefault<z.ZodBoolean>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ url: string;
47
+ method: string;
48
+ contentType: string;
49
+ stream: boolean;
50
+ }, {
51
+ url: string;
52
+ method?: string | undefined;
53
+ contentType?: string | undefined;
54
+ stream?: boolean | undefined;
55
+ }>>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ id: string;
58
+ title: string;
59
+ created_at: string;
60
+ updated_at: string;
61
+ logo: string | null;
62
+ description: string | null;
63
+ capabilities: string[];
64
+ limits: {
65
+ contextWindow: number;
66
+ maxOutputTokens: number;
67
+ } | null;
68
+ costs: {
69
+ input: number;
70
+ output: number;
71
+ } | null;
72
+ endpoint: {
73
+ url: string;
74
+ method: string;
75
+ contentType: string;
76
+ stream: boolean;
77
+ } | null;
78
+ created_by?: string | undefined;
79
+ updated_by?: string | undefined;
80
+ }, {
81
+ id: string;
82
+ title: string;
83
+ created_at: string;
84
+ updated_at: string;
85
+ logo: string | null;
86
+ description: string | null;
87
+ capabilities: string[];
88
+ limits: {
89
+ contextWindow: number;
90
+ maxOutputTokens: number;
91
+ } | null;
92
+ costs: {
93
+ input: number;
94
+ output: number;
95
+ } | null;
96
+ endpoint: {
97
+ url: string;
98
+ method?: string | undefined;
99
+ contentType?: string | undefined;
100
+ stream?: boolean | undefined;
101
+ } | null;
102
+ created_by?: string | undefined;
103
+ updated_by?: string | undefined;
104
+ }>;
13
105
  /**
14
106
  * MODELS Collection Binding
15
107
  *
@@ -29,4 +121,4 @@ declare const MODELS_COLLECTION_BINDING: ToolBinder<string, any, object>[];
29
121
  */
30
122
  declare const MODELS_BINDING: readonly ToolBinder<string, any, object>[];
31
123
 
32
- export { MODELS_BINDING, MODELS_COLLECTION_BINDING };
124
+ export { MODELS_BINDING, MODELS_COLLECTION_BINDING, ModelSchema };
@@ -1,4 +1,4 @@
1
- import { BaseCollectionEntitySchema, createCollectionBindings } from '../chunk-IBOJHI67.js';
1
+ import { BaseCollectionEntitySchema, createCollectionBindings } from '../chunk-L7E6ONLJ.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  var ModelSchema = BaseCollectionEntitySchema.extend({
@@ -31,6 +31,6 @@ var MODELS_BINDING = [
31
31
  ...MODELS_COLLECTION_BINDING
32
32
  ];
33
33
 
34
- export { MODELS_BINDING, MODELS_COLLECTION_BINDING };
34
+ export { MODELS_BINDING, MODELS_COLLECTION_BINDING, ModelSchema };
35
35
  //# sourceMappingURL=models.js.map
36
36
  //# sourceMappingURL=models.js.map
@@ -1 +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"]}
1
+ {"version":3,"sources":["../../src/well-known/models.ts"],"names":[],"mappings":";;;AAsBO,IAAM,WAAA,GAAc,2BAA2B,MAAA,CAAO;AAAA;AAAA,EAE3D,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;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 */\nexport const 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.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -142,10 +142,9 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
142
142
  isImplementedBy: async (tools: ToolWithSchemas[]) => {
143
143
  for (const binderTool of binderTools) {
144
144
  // Find matching tool by name (exact or regex)
145
- const pattern =
146
- typeof binderTool.name === "string"
147
- ? new RegExp(`^${binderTool.name}$`)
148
- : binderTool.name;
145
+ const pattern = typeof binderTool.name === "string"
146
+ ? new RegExp(`^${binderTool.name}$`)
147
+ : binderTool.name;
149
148
 
150
149
  const matchedTool = tools.find((t) => pattern.test(t.name));
151
150
 
@@ -178,6 +177,7 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
178
177
  return false;
179
178
  }
180
179
  } catch (error) {
180
+ console.error("Schema diff failed", error);
181
181
  // Schema diff failed - consider incompatible
182
182
  return false;
183
183
  }
@@ -205,6 +205,7 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
205
205
  return false;
206
206
  }
207
207
  } catch (error) {
208
+ console.error("Schema diff failed", error);
208
209
  // Schema diff failed - consider incompatible
209
210
  return false;
210
211
  }
@@ -218,4 +219,3 @@ export function createBindingChecker<TDefinition extends readonly ToolBinder[]>(
218
219
  },
219
220
  };
220
221
  }
221
-
@@ -35,48 +35,40 @@ export const BaseCollectionEntitySchema = z.object({
35
35
  export type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
36
36
 
37
37
  /**
38
- * Where expression type for filtering
39
- * Supports TanStack DB predicate push-down patterns
38
+ * Comparison expression schema for filtering
40
39
  */
41
- export type WhereExpression =
42
- | {
43
- field: string[];
44
- operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
45
- value: unknown;
46
- }
47
- | {
48
- operator: "and" | "or" | "not";
49
- conditions: WhereExpression[];
50
- };
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
+ });
51
54
 
52
55
  /**
53
56
  * Where expression schema for filtering
54
57
  * Supports TanStack DB predicate push-down patterns
55
58
  */
56
- export const WhereExpressionSchema = z.lazy(() =>
57
- z.union([
58
- // Simple comparison
59
- z.object({
60
- field: z.array(z.string()),
61
- operator: z.enum([
62
- "eq",
63
- "gt",
64
- "gte",
65
- "lt",
66
- "lte",
67
- "in",
68
- "like",
69
- "contains",
70
- ]),
71
- value: z.unknown(),
72
- }),
73
- // Logical operators
74
- z.object({
75
- operator: z.enum(["and", "or", "not"]),
76
- conditions: z.array(WhereExpressionSchema),
77
- }),
78
- ])
79
- ) as z.ZodType<WhereExpression>;
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>;
80
72
 
81
73
  /**
82
74
  * Order by expression for sorting
@@ -20,7 +20,7 @@ import {
20
20
  * Extends BaseCollectionEntitySchema with model-specific fields
21
21
  * Base schema already includes: id, title, created_at, updated_at, created_by, updated_by
22
22
  */
23
- const ModelSchema = BaseCollectionEntitySchema.extend({
23
+ export const ModelSchema = BaseCollectionEntitySchema.extend({
24
24
  // Model-specific fields
25
25
  logo: z.string().nullable(),
26
26
  description: z.string().nullable(),
@@ -1 +0,0 @@
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,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA,EAAS;AAAA,EAChC,UAAA,EAAY,CAAA,CAAE,MAAA,EAAO,CAAE,QAAA;AACzB,CAAC;AA0BM,IAAM,wBAAwB,CAAA,CAAE,IAAA;AAAA,EAAK,MAC1C,EAAE,KAAA,CAAM;AAAA;AAAA,IAEN,EAAE,MAAA,CAAO;AAAA,MACP,KAAA,EAAO,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAQ,CAAA;AAAA,MACzB,QAAA,EAAU,EAAE,IAAA,CAAK;AAAA,QACf,IAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,IAAA;AAAA,QACA,KAAA;AAAA,QACA,IAAA;AAAA,QACA,MAAA;AAAA,QACA;AAAA,OACD,CAAA;AAAA,MACD,KAAA,EAAO,EAAE,OAAA;AAAQ,KAClB,CAAA;AAAA;AAAA,IAED,EAAE,MAAA,CAAO;AAAA,MACP,UAAU,CAAA,CAAE,IAAA,CAAK,CAAC,KAAA,EAAO,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AAA,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"]}