@decocms/runtime 1.0.0-alpha.34 → 1.0.0-alpha.36
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/package.json +2 -2
- package/src/events.ts +15 -10
- package/src/tools.ts +3 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"check": "tsc --noEmit"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@cloudflare/workers-types": "^4.20250617.0",
|
|
10
10
|
"@deco/mcp": "npm:@jsr/deco__mcp@0.7.8",
|
|
11
|
-
"@decocms/bindings": "1.0.1-alpha.
|
|
11
|
+
"@decocms/bindings": "1.0.1-alpha.21",
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.20.2",
|
|
13
13
|
"@ai-sdk/provider": "^2.0.0",
|
|
14
14
|
"hono": "^4.10.7",
|
package/src/events.ts
CHANGED
|
@@ -10,8 +10,8 @@ import z from "zod";
|
|
|
10
10
|
// ============================================================================
|
|
11
11
|
|
|
12
12
|
export interface EventSubscription {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
eventType: string;
|
|
14
|
+
publisher: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface Binding {
|
|
@@ -214,6 +214,7 @@ const scopesFromEvents = <TSchema extends z.ZodTypeAny = never>(
|
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
216
|
* Get subscriptions from event handlers and state
|
|
217
|
+
* Returns flat array of { eventType, publisher } for EVENT_SYNC_SUBSCRIPTIONS
|
|
217
218
|
*/
|
|
218
219
|
const eventsSubscriptions = <TSchema extends z.ZodTypeAny = never>(
|
|
219
220
|
handlers: EventHandlers<TSchema>,
|
|
@@ -224,10 +225,12 @@ const eventsSubscriptions = <TSchema extends z.ZodTypeAny = never>(
|
|
|
224
225
|
const subscriptions: EventSubscription[] = [];
|
|
225
226
|
for (const [, value] of Object.entries(state)) {
|
|
226
227
|
if (isBinding(value)) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
for (const eventType of handlers.events) {
|
|
229
|
+
subscriptions.push({
|
|
230
|
+
eventType,
|
|
231
|
+
publisher: value.value,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
return subscriptions;
|
|
@@ -239,10 +242,12 @@ const eventsSubscriptions = <TSchema extends z.ZodTypeAny = never>(
|
|
|
239
242
|
if (!isBinding(bindingValue)) continue;
|
|
240
243
|
|
|
241
244
|
const eventTypes = getEventTypesForBinding(handlers, binding);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
245
|
+
for (const eventType of eventTypes) {
|
|
246
|
+
subscriptions.push({
|
|
247
|
+
eventType,
|
|
248
|
+
publisher: bindingValue.value,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
246
251
|
}
|
|
247
252
|
return subscriptions;
|
|
248
253
|
};
|
package/src/tools.ts
CHANGED
|
@@ -314,24 +314,12 @@ const toolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
|
314
314
|
});
|
|
315
315
|
const bus = getEventBus(busProp, input.runtimeContext.env);
|
|
316
316
|
if (events && state && bus) {
|
|
317
|
-
//
|
|
317
|
+
// Sync subscriptions - always call to handle deletions too
|
|
318
318
|
const subscriptions = Event.subscriptions(
|
|
319
319
|
events?.handlers ?? {},
|
|
320
320
|
state,
|
|
321
321
|
);
|
|
322
|
-
|
|
323
|
-
await Promise.all(
|
|
324
|
-
subscriptions.map(async (subscription) => {
|
|
325
|
-
return Promise.all(
|
|
326
|
-
subscription.events.map(async (event) => {
|
|
327
|
-
return bus.EVENT_SUBSCRIBE({
|
|
328
|
-
publisher: subscription.connectionId,
|
|
329
|
-
eventType: event,
|
|
330
|
-
});
|
|
331
|
-
}),
|
|
332
|
-
);
|
|
333
|
-
}),
|
|
334
|
-
);
|
|
322
|
+
await bus.EVENT_SYNC_SUBSCRIPTIONS({ subscriptions });
|
|
335
323
|
}
|
|
336
324
|
return Promise.resolve({});
|
|
337
325
|
},
|
|
@@ -375,7 +363,7 @@ const toolsFor = <TSchema extends z.ZodTypeAny = never>({
|
|
|
375
363
|
scopes: [
|
|
376
364
|
...(scopes ?? []),
|
|
377
365
|
...Event.scopes(events?.handlers ?? {}),
|
|
378
|
-
...(busProp ? [`${busProp}::
|
|
366
|
+
...(busProp ? [`${busProp}::EVENT_SYNC_SUBSCRIPTIONS`] : []),
|
|
379
367
|
],
|
|
380
368
|
});
|
|
381
369
|
},
|