@decocms/bindings 1.0.1-alpha.4 → 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 +8 -11
- package/src/core/binder.ts +15 -76
- 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 +84 -99
- 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 +2 -1
- 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 +1 -1
- 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,
|
|
@@ -265,16 +274,12 @@ export function createCollectionBindings<
|
|
|
265
274
|
{
|
|
266
275
|
name: `COLLECTION_${upperName}_LIST` as const,
|
|
267
276
|
inputSchema: CollectionListInputSchema,
|
|
268
|
-
outputSchema: createCollectionListOutputSchema(entitySchema)
|
|
269
|
-
CollectionListOutput<z.infer<TEntitySchema>>
|
|
270
|
-
>,
|
|
277
|
+
outputSchema: createCollectionListOutputSchema(entitySchema),
|
|
271
278
|
},
|
|
272
279
|
{
|
|
273
280
|
name: `COLLECTION_${upperName}_GET` as const,
|
|
274
281
|
inputSchema: CollectionGetInputSchema,
|
|
275
|
-
outputSchema: createCollectionGetOutputSchema(entitySchema)
|
|
276
|
-
CollectionGetOutput<z.infer<TEntitySchema>>
|
|
277
|
-
>,
|
|
282
|
+
outputSchema: createCollectionGetOutputSchema(entitySchema),
|
|
278
283
|
},
|
|
279
284
|
];
|
|
280
285
|
|
|
@@ -283,108 +288,88 @@ export function createCollectionBindings<
|
|
|
283
288
|
bindings.push(
|
|
284
289
|
{
|
|
285
290
|
name: `COLLECTION_${upperName}_CREATE` as const,
|
|
286
|
-
inputSchema: createCollectionInsertInputSchema(
|
|
287
|
-
|
|
288
|
-
) as unknown as z.ZodType<
|
|
289
|
-
CollectionInsertInput<z.infer<TEntitySchema>>
|
|
290
|
-
>,
|
|
291
|
-
outputSchema: createCollectionInsertOutputSchema(
|
|
292
|
-
entitySchema,
|
|
293
|
-
) as unknown as z.ZodType<
|
|
294
|
-
CollectionInsertOutput<z.infer<TEntitySchema>>
|
|
295
|
-
>,
|
|
291
|
+
inputSchema: createCollectionInsertInputSchema(entitySchema),
|
|
292
|
+
outputSchema: createCollectionInsertOutputSchema(entitySchema),
|
|
296
293
|
opt: true,
|
|
297
294
|
},
|
|
298
295
|
{
|
|
299
296
|
name: `COLLECTION_${upperName}_UPDATE` as const,
|
|
300
|
-
inputSchema: createCollectionUpdateInputSchema(
|
|
301
|
-
|
|
302
|
-
) as unknown as z.ZodType<
|
|
303
|
-
CollectionUpdateInput<z.infer<TEntitySchema>>
|
|
304
|
-
>,
|
|
305
|
-
outputSchema: createCollectionUpdateOutputSchema(
|
|
306
|
-
entitySchema,
|
|
307
|
-
) as unknown as z.ZodType<
|
|
308
|
-
CollectionUpdateOutput<z.infer<TEntitySchema>>
|
|
309
|
-
>,
|
|
297
|
+
inputSchema: createCollectionUpdateInputSchema(entitySchema),
|
|
298
|
+
outputSchema: createCollectionUpdateOutputSchema(entitySchema),
|
|
310
299
|
opt: true,
|
|
311
300
|
},
|
|
312
301
|
{
|
|
313
302
|
name: `COLLECTION_${upperName}_DELETE` as const,
|
|
314
303
|
inputSchema: CollectionDeleteInputSchema,
|
|
315
|
-
outputSchema: createCollectionDeleteOutputSchema(
|
|
316
|
-
entitySchema,
|
|
317
|
-
) as unknown as z.ZodType<
|
|
318
|
-
CollectionDeleteOutput<z.infer<TEntitySchema>>
|
|
319
|
-
>,
|
|
304
|
+
outputSchema: createCollectionDeleteOutputSchema(entitySchema),
|
|
320
305
|
opt: true,
|
|
321
306
|
},
|
|
322
307
|
);
|
|
323
308
|
}
|
|
324
309
|
|
|
325
|
-
return bindings as unknown as
|
|
310
|
+
return bindings as unknown as CollectionBinding<
|
|
326
311
|
TEntitySchema,
|
|
327
312
|
Uppercase<TName>
|
|
328
|
-
|
|
313
|
+
>;
|
|
329
314
|
}
|
|
330
315
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
outputSchema: z.ZodType<CollectionGetOutput<z.infer<TEntitySchema>>>;
|
|
344
|
-
},
|
|
345
|
-
];
|
|
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
|
+
|
|
346
328
|
/**
|
|
347
329
|
* Type helper to extract the collection binding type
|
|
348
330
|
*/
|
|
349
331
|
export type CollectionBinding<
|
|
350
|
-
TEntitySchema
|
|
332
|
+
TEntitySchema,
|
|
351
333
|
TUpperName extends Uppercase<string> = Uppercase<string>,
|
|
334
|
+
TEntity = TEntitySchema extends z.AnyZodObject
|
|
335
|
+
? z.infer<TEntitySchema>
|
|
336
|
+
: TEntitySchema,
|
|
352
337
|
> = [
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
+
>,
|
|
381
366
|
];
|
|
382
367
|
|
|
383
368
|
/**
|
|
384
369
|
* Type helper to extract tool names from a collection binding
|
|
385
370
|
*/
|
|
386
371
|
export type CollectionTools<
|
|
387
|
-
TEntitySchema extends
|
|
372
|
+
TEntitySchema extends z.AnyZodObject,
|
|
388
373
|
TUpperName extends Uppercase<string> = Uppercase<string>,
|
|
389
374
|
> = CollectionBinding<TEntitySchema, TUpperName>[number]["name"];
|
|
390
375
|
|
|
@@ -398,7 +383,7 @@ export type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;
|
|
|
398
383
|
* Type helper for insert input with generic item type
|
|
399
384
|
*/
|
|
400
385
|
export type CollectionInsertInput<T> = {
|
|
401
|
-
data: T
|
|
386
|
+
data: Partial<T>;
|
|
402
387
|
};
|
|
403
388
|
|
|
404
389
|
/**
|