@decocms/bindings 1.0.1-alpha.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +9 -11
- package/src/core/binder.ts +15 -77
- package/src/core/client/index.ts +10 -0
- package/src/core/client/mcp-client.ts +18 -5
- package/src/core/client/mcp.ts +48 -11
- package/src/core/client/proxy.ts +64 -48
- package/src/index.ts +57 -0
- package/src/well-known/assistant.ts +87 -0
- package/src/well-known/collections.ts +105 -84
- package/src/well-known/event-bus.ts +454 -0
- package/src/well-known/event-subscriber.ts +259 -0
- package/src/well-known/language-model.ts +217 -5
- package/src/well-known/mcp.ts +36 -0
- package/src/well-known/prompt.ts +110 -0
- package/src/well-known/registry.ts +128 -0
- package/src/well-known/workflow.ts +297 -0
- package/test/index.test.ts +3 -2
- package/test/mcp.test.ts +40 -0
- package/src/core/subset.ts +0 -514
- package/src/well-known/agent.ts +0 -60
- package/vitest.config.ts +0 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { z, type ZodType } from "zod";
|
|
2
2
|
import type { ToolBinder } from "../core/binder";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -23,6 +23,7 @@ import type { ToolBinder } from "../core/binder";
|
|
|
23
23
|
export const BaseCollectionEntitySchema = z.object({
|
|
24
24
|
id: z.string().describe("Unique identifier for the entity"),
|
|
25
25
|
title: z.string().describe("Human-readable title for the entity"),
|
|
26
|
+
description: z.string().nullish().describe("Description of the entity"),
|
|
26
27
|
created_at: z.string().datetime(),
|
|
27
28
|
updated_at: z.string().datetime(),
|
|
28
29
|
created_by: z.string().optional(),
|
|
@@ -44,22 +45,30 @@ const ComparisonExpressionSchema = z.object({
|
|
|
44
45
|
});
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
|
-
* Where expression
|
|
48
|
-
*
|
|
48
|
+
* Where expression type for filtering
|
|
49
|
+
* Recursive to allow nested logical operators
|
|
49
50
|
*/
|
|
50
|
-
export
|
|
51
|
-
ComparisonExpressionSchema
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
]);
|
|
51
|
+
export type WhereExpression =
|
|
52
|
+
| z.infer<typeof ComparisonExpressionSchema>
|
|
53
|
+
| {
|
|
54
|
+
operator: "and" | "or" | "not";
|
|
55
|
+
conditions: WhereExpression[];
|
|
56
|
+
};
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Where expression
|
|
60
|
-
*
|
|
59
|
+
* Where expression schema for filtering
|
|
60
|
+
* Supports TanStack DB predicate push-down patterns
|
|
61
|
+
* Recursive to allow nested logical operators
|
|
61
62
|
*/
|
|
62
|
-
export
|
|
63
|
+
export const WhereExpressionSchema: z.ZodType<WhereExpression> = z.lazy(() =>
|
|
64
|
+
z.union([
|
|
65
|
+
ComparisonExpressionSchema,
|
|
66
|
+
z.object({
|
|
67
|
+
operator: z.enum(["and", "or", "not"]),
|
|
68
|
+
conditions: z.array(WhereExpressionSchema),
|
|
69
|
+
}),
|
|
70
|
+
]),
|
|
71
|
+
);
|
|
63
72
|
|
|
64
73
|
/**
|
|
65
74
|
* Order by expression for sorting
|
|
@@ -139,14 +148,14 @@ export function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(
|
|
|
139
148
|
/**
|
|
140
149
|
* Factory function to create insert input schema
|
|
141
150
|
*/
|
|
142
|
-
export function createCollectionInsertInputSchema<
|
|
143
|
-
|
|
144
|
-
) {
|
|
151
|
+
export function createCollectionInsertInputSchema<
|
|
152
|
+
T extends z.ZodObject<z.ZodRawShape>,
|
|
153
|
+
>(entitySchema: T) {
|
|
145
154
|
// Remove id field since it may be auto-generated by the server
|
|
146
155
|
return z.object({
|
|
147
|
-
data: entitySchema
|
|
148
|
-
|
|
149
|
-
|
|
156
|
+
data: entitySchema
|
|
157
|
+
.partial()
|
|
158
|
+
.describe("Data for the new entity (id may be auto-generated)"),
|
|
150
159
|
});
|
|
151
160
|
}
|
|
152
161
|
|
|
@@ -251,7 +260,7 @@ export interface CollectionBindingOptions {
|
|
|
251
260
|
* ```
|
|
252
261
|
*/
|
|
253
262
|
export function createCollectionBindings<
|
|
254
|
-
TEntitySchema extends
|
|
263
|
+
TEntitySchema extends z.ZodObject<z.ZodRawShape>,
|
|
255
264
|
TName extends string,
|
|
256
265
|
>(
|
|
257
266
|
collectionName: TName,
|
|
@@ -261,19 +270,18 @@ export function createCollectionBindings<
|
|
|
261
270
|
const upperName = collectionName.toUpperCase() as Uppercase<TName>;
|
|
262
271
|
const readOnly = options?.readOnly ?? false;
|
|
263
272
|
|
|
264
|
-
const bindings:
|
|
265
|
-
|
|
266
|
-
{
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
{
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
];
|
|
273
|
+
const bindings: ToolBinder[] = [
|
|
274
|
+
{
|
|
275
|
+
name: `COLLECTION_${upperName}_LIST` as const,
|
|
276
|
+
inputSchema: CollectionListInputSchema,
|
|
277
|
+
outputSchema: createCollectionListOutputSchema(entitySchema),
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: `COLLECTION_${upperName}_GET` as const,
|
|
281
|
+
inputSchema: CollectionGetInputSchema,
|
|
282
|
+
outputSchema: createCollectionGetOutputSchema(entitySchema),
|
|
283
|
+
},
|
|
284
|
+
];
|
|
277
285
|
|
|
278
286
|
// Only include mutation operations if not read-only
|
|
279
287
|
if (!readOnly) {
|
|
@@ -299,71 +307,69 @@ export function createCollectionBindings<
|
|
|
299
307
|
);
|
|
300
308
|
}
|
|
301
309
|
|
|
302
|
-
return bindings
|
|
310
|
+
return bindings as unknown as CollectionBinding<
|
|
311
|
+
TEntitySchema,
|
|
312
|
+
Uppercase<TName>
|
|
313
|
+
>;
|
|
303
314
|
}
|
|
304
315
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
name: `COLLECTION_${TUpperName}_GET`;
|
|
318
|
-
inputSchema: typeof CollectionGetInputSchema;
|
|
319
|
-
outputSchema: ReturnType<
|
|
320
|
-
typeof createCollectionGetOutputSchema<TEntitySchema>
|
|
321
|
-
>;
|
|
322
|
-
},
|
|
323
|
-
];
|
|
316
|
+
// Helper type for tool definition
|
|
317
|
+
type ToolBinding<
|
|
318
|
+
Name extends string,
|
|
319
|
+
Input,
|
|
320
|
+
Output,
|
|
321
|
+
Opt extends boolean = false,
|
|
322
|
+
> = {
|
|
323
|
+
name: Name;
|
|
324
|
+
inputSchema: ZodType<Input>;
|
|
325
|
+
outputSchema: ZodType<Output>;
|
|
326
|
+
} & (Opt extends true ? { opt: true } : unknown);
|
|
327
|
+
|
|
324
328
|
/**
|
|
325
329
|
* Type helper to extract the collection binding type
|
|
326
330
|
*/
|
|
327
331
|
export type CollectionBinding<
|
|
328
|
-
TEntitySchema
|
|
332
|
+
TEntitySchema,
|
|
329
333
|
TUpperName extends Uppercase<string> = Uppercase<string>,
|
|
334
|
+
TEntity = TEntitySchema extends z.AnyZodObject
|
|
335
|
+
? z.infer<TEntitySchema>
|
|
336
|
+
: TEntitySchema,
|
|
330
337
|
> = [
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
},
|
|
338
|
+
ToolBinding<
|
|
339
|
+
`COLLECTION_${TUpperName}_LIST`,
|
|
340
|
+
CollectionListInput,
|
|
341
|
+
CollectionListOutput<TEntity>
|
|
342
|
+
>,
|
|
343
|
+
ToolBinding<
|
|
344
|
+
`COLLECTION_${TUpperName}_GET`,
|
|
345
|
+
CollectionGetInput,
|
|
346
|
+
CollectionGetOutput<TEntity>
|
|
347
|
+
>,
|
|
348
|
+
ToolBinding<
|
|
349
|
+
`COLLECTION_${TUpperName}_CREATE`,
|
|
350
|
+
CollectionInsertInput<TEntity>,
|
|
351
|
+
CollectionInsertOutput<TEntity>,
|
|
352
|
+
true
|
|
353
|
+
>,
|
|
354
|
+
ToolBinding<
|
|
355
|
+
`COLLECTION_${TUpperName}_UPDATE`,
|
|
356
|
+
CollectionUpdateInput<TEntity>,
|
|
357
|
+
CollectionUpdateOutput<TEntity>,
|
|
358
|
+
true
|
|
359
|
+
>,
|
|
360
|
+
ToolBinding<
|
|
361
|
+
`COLLECTION_${TUpperName}_DELETE`,
|
|
362
|
+
CollectionDeleteInput,
|
|
363
|
+
CollectionDeleteOutput<TEntity>,
|
|
364
|
+
true
|
|
365
|
+
>,
|
|
360
366
|
];
|
|
361
367
|
|
|
362
368
|
/**
|
|
363
369
|
* Type helper to extract tool names from a collection binding
|
|
364
370
|
*/
|
|
365
371
|
export type CollectionTools<
|
|
366
|
-
TEntitySchema extends
|
|
372
|
+
TEntitySchema extends z.AnyZodObject,
|
|
367
373
|
TUpperName extends Uppercase<string> = Uppercase<string>,
|
|
368
374
|
> = CollectionBinding<TEntitySchema, TUpperName>[number]["name"];
|
|
369
375
|
|
|
@@ -373,6 +379,21 @@ export type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;
|
|
|
373
379
|
export type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;
|
|
374
380
|
export type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;
|
|
375
381
|
|
|
382
|
+
/**
|
|
383
|
+
* Type helper for insert input with generic item type
|
|
384
|
+
*/
|
|
385
|
+
export type CollectionInsertInput<T> = {
|
|
386
|
+
data: Partial<T>;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Type helper for update input with generic item type
|
|
391
|
+
*/
|
|
392
|
+
export type CollectionUpdateInput<T> = {
|
|
393
|
+
id: string;
|
|
394
|
+
data: Partial<T>;
|
|
395
|
+
};
|
|
396
|
+
|
|
376
397
|
/**
|
|
377
398
|
* Type helper for list output with generic item type
|
|
378
399
|
*/
|