@decocms/runtime 1.0.0-alpha.38 → 1.0.0-alpha.39

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/runtime",
3
- "version": "1.0.0-alpha.38",
3
+ "version": "1.0.0-alpha.39",
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.21",
11
+ "@decocms/bindings": "1.0.1-alpha.23",
12
12
  "@modelcontextprotocol/sdk": "1.20.2",
13
13
  "@ai-sdk/provider": "^2.0.0",
14
14
  "hono": "^4.10.7",
package/src/bindings.ts CHANGED
@@ -31,11 +31,14 @@ export type BindingRegistry = Record<string, readonly ToolBinder[]>;
31
31
  /**
32
32
  * Function that returns Zod Schema
33
33
  */
34
- export const BindingOf = <TRegistry extends BindingRegistry>(
35
- name: keyof TRegistry | "*",
34
+ export const BindingOf = <
35
+ TRegistry extends BindingRegistry,
36
+ TName extends keyof TRegistry | "*",
37
+ >(
38
+ name: TName,
36
39
  ) => {
37
40
  return z.object({
38
- __type: z.literal(name).default(name as any),
41
+ __type: z.literal<TName>(name).default(name),
39
42
  value: z.string(),
40
43
  });
41
44
  };
@@ -84,10 +87,8 @@ export const isBinding = (v: unknown): v is Binding => {
84
87
  return (
85
88
  typeof v === "object" &&
86
89
  v !== null &&
87
- "__type" in v &&
88
- typeof v.__type === "string" &&
89
- "value" in v &&
90
- typeof v.value === "string"
90
+ typeof (v as { __type: string }).__type === "string" &&
91
+ typeof (v as { value: string }).value === "string"
91
92
  );
92
93
  };
93
94
 
@@ -169,9 +170,9 @@ export const initializeBindings = <
169
170
  TBindings extends BindingRegistry = BindingRegistry,
170
171
  >(
171
172
  ctx: RequestContext,
172
- ): void => {
173
+ ): ResolvedBindings<T, TBindings> => {
173
174
  // resolves the state in-place
174
- traverseAndReplace(ctx.state, ctx) as ResolvedBindings<T, TBindings>;
175
+ return traverseAndReplace(ctx.state, ctx) as ResolvedBindings<T, TBindings>;
175
176
  };
176
177
 
177
178
  interface DefaultRegistry extends BindingRegistry {
package/src/events.ts CHANGED
@@ -184,28 +184,6 @@ const getEventTypesForBinding = <TEnv, TSchema extends z.ZodTypeAny>(
184
184
  return Object.keys(bindingHandler);
185
185
  };
186
186
 
187
- /**
188
- * Get scopes from event handlers for subscription
189
- */
190
- const scopesFromEvents = <TEnv, TSchema extends z.ZodTypeAny = never>(
191
- handlers: EventHandlers<TEnv, TSchema>,
192
- ): string[] => {
193
- if (isGlobalHandler<TEnv>(handlers)) {
194
- // Global handler - scopes are based on explicit events array
195
- // Note: "*" binding means all bindings
196
- return handlers.events.map((event) => `*::event@${event}`);
197
- }
198
-
199
- const scopes: string[] = [];
200
- for (const binding of getBindingKeys(handlers)) {
201
- const eventTypes = getEventTypesForBinding(handlers, binding);
202
- for (const eventType of eventTypes) {
203
- scopes.push(`${binding}::event@${eventType}`);
204
- }
205
- }
206
- return scopes;
207
- };
208
-
209
187
  /**
210
188
  * Get subscriptions from event handlers and state
211
189
  * Returns flat array of { eventType, publisher } for EVENT_SYNC_SUBSCRIPTIONS
@@ -490,6 +468,5 @@ const executeEventHandlers = async <TEnv, TSchema extends z.ZodTypeAny>(
490
468
  */
491
469
  export const Event = {
492
470
  subscriptions: eventsSubscriptions,
493
- scopes: scopesFromEvents,
494
471
  execute: executeEventHandlers,
495
472
  };
package/src/index.ts CHANGED
@@ -214,7 +214,7 @@ export const withBindings = <TEnv>({
214
214
  }
215
215
 
216
216
  env.MESH_REQUEST_CONTEXT = context;
217
- initializeBindings(context);
217
+ context.state = initializeBindings(context);
218
218
 
219
219
  withDefaultBindings({
220
220
  env,
package/src/tools.ts CHANGED
@@ -279,7 +279,9 @@ const getEventBus = (
279
279
  env: DefaultEnv,
280
280
  ): EventBusBindingClient | undefined => {
281
281
  const bus = env as unknown as { [prop]: EventBusBindingClient };
282
- return typeof bus[prop] !== "undefined" ? bus[prop] : undefined;
282
+ return typeof bus[prop] !== "undefined"
283
+ ? bus[prop]
284
+ : env?.MESH_REQUEST_CONTEXT.state[prop];
283
285
  };
284
286
 
285
287
  const toolsFor = <TSchema extends z.ZodTypeAny = never>({
@@ -291,7 +293,7 @@ const toolsFor = <TSchema extends z.ZodTypeAny = never>({
291
293
  : { type: "object", properties: {} };
292
294
  const busProp = String(events?.bus ?? "EVENT_BUS");
293
295
  return [
294
- ...(onChange
296
+ ...(onChange || events
295
297
  ? [
296
298
  createTool({
297
299
  id: "ON_MCP_CONFIGURATION",
@@ -307,7 +309,7 @@ const toolsFor = <TSchema extends z.ZodTypeAny = never>({
307
309
  outputSchema: z.object({}),
308
310
  execute: async (input) => {
309
311
  const state = input.context.state as z.infer<TSchema>;
310
- await onChange(input.runtimeContext.env, {
312
+ await onChange?.(input.runtimeContext.env, {
311
313
  state,
312
314
  scopes: input.context.scopes,
313
315
  });
@@ -361,7 +363,6 @@ const toolsFor = <TSchema extends z.ZodTypeAny = never>({
361
363
  stateSchema: jsonSchema,
362
364
  scopes: [
363
365
  ...((scopes as string[]) ?? []),
364
- ...Event.scopes(events?.handlers ?? {}),
365
366
  ...(events ? [`${busProp}::EVENT_SYNC_SUBSCRIPTIONS`] : []),
366
367
  ],
367
368
  });