@inf-monkeys-tech/monkeys 1.1.17 → 1.1.19

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.
Files changed (55) hide show
  1. package/README.md +20 -0
  2. package/lib/contracts/action-program-http.d.ts +1021 -0
  3. package/lib/contracts/action-program-http.d.ts.map +1 -0
  4. package/lib/contracts/action-program-http.js +42 -0
  5. package/lib/contracts/action-program-http.js.map +1 -0
  6. package/lib/contracts/declarative-control-http.d.ts +11365 -18
  7. package/lib/contracts/declarative-control-http.d.ts.map +1 -1
  8. package/lib/contracts/declarative-control.d.ts +3263 -1022
  9. package/lib/contracts/declarative-control.d.ts.map +1 -1
  10. package/lib/contracts/declarative-control.js +278 -5
  11. package/lib/contracts/declarative-control.js.map +1 -1
  12. package/lib/contracts/declarative-publication-job.d.ts +3356 -8
  13. package/lib/contracts/declarative-publication-job.d.ts.map +1 -1
  14. package/lib/contracts/index.d.ts +1 -0
  15. package/lib/contracts/index.d.ts.map +1 -1
  16. package/lib/contracts/index.js +1 -0
  17. package/lib/contracts/index.js.map +1 -1
  18. package/lib/esm/contracts/index.mjs +342 -3
  19. package/lib/esm/contracts/index.mjs.map +1 -1
  20. package/lib/esm/index.mjs +696 -31
  21. package/lib/esm/index.mjs.map +1 -1
  22. package/lib/esm/runtime/index.mjs +646 -31
  23. package/lib/esm/runtime/index.mjs.map +1 -1
  24. package/lib/esm/schemas/index.mjs +4088 -3797
  25. package/lib/esm/schemas/index.mjs.map +1 -1
  26. package/lib/json-schema/action-program-artifact.schema.json +1226 -0
  27. package/lib/json-schema/action-program-definition.schema.json +1205 -0
  28. package/lib/json-schema/index.json +2 -0
  29. package/lib/json-schema/navigation-release.schema.json +1 -0
  30. package/lib/json-schema/navigation-runtime-bundle.schema.json +1 -0
  31. package/lib/json-schema/page-release.schema.json +1 -0
  32. package/lib/json-schema/page-runtime-bundle.schema.json +2436 -0
  33. package/lib/json-schema/page.schema.json +941 -0
  34. package/lib/json-schema/workbench-release.schema.json +1 -0
  35. package/lib/json-schema/workbench-runtime-bundle.schema.json +1 -0
  36. package/lib/runtime/action-program-author.d.ts +40 -0
  37. package/lib/runtime/action-program-author.d.ts.map +1 -0
  38. package/lib/runtime/action-program-author.js +178 -0
  39. package/lib/runtime/action-program-author.js.map +1 -0
  40. package/lib/runtime/declarative-control-compiler.d.ts +9 -1
  41. package/lib/runtime/declarative-control-compiler.d.ts.map +1 -1
  42. package/lib/runtime/declarative-control-compiler.js +123 -7
  43. package/lib/runtime/declarative-control-compiler.js.map +1 -1
  44. package/lib/runtime/declarative-runtime-contract.d.ts.map +1 -1
  45. package/lib/runtime/declarative-runtime-contract.js +46 -2
  46. package/lib/runtime/declarative-runtime-contract.js.map +1 -1
  47. package/lib/runtime/index.d.ts +1 -0
  48. package/lib/runtime/index.d.ts.map +1 -1
  49. package/lib/runtime/index.js +1 -0
  50. package/lib/runtime/index.js.map +1 -1
  51. package/lib/schemas/index.d.ts +2216 -1232
  52. package/lib/schemas/index.d.ts.map +1 -1
  53. package/lib/schemas/index.js +116 -111
  54. package/lib/schemas/index.js.map +1 -1
  55. package/package.json +4 -2
package/lib/esm/index.mjs CHANGED
@@ -7321,7 +7321,7 @@ var require__ = __commonJS({
7321
7321
  var discriminator_1 = require_discriminator();
7322
7322
  var json_schema_2020_12_1 = require_json_schema_2020_12();
7323
7323
  var META_SCHEMA_ID = "https://json-schema.org/draft/2020-12/schema";
7324
- var Ajv20202 = class extends core_1.default {
7324
+ var Ajv20203 = class extends core_1.default {
7325
7325
  constructor(opts = {}) {
7326
7326
  super({
7327
7327
  ...opts,
@@ -7348,11 +7348,11 @@ var require__ = __commonJS({
7348
7348
  return this.opts.defaultMeta = super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : void 0);
7349
7349
  }
7350
7350
  };
7351
- exports.Ajv2020 = Ajv20202;
7352
- module.exports = exports = Ajv20202;
7353
- module.exports.Ajv2020 = Ajv20202;
7351
+ exports.Ajv2020 = Ajv20203;
7352
+ module.exports = exports = Ajv20203;
7353
+ module.exports.Ajv2020 = Ajv20203;
7354
7354
  Object.defineProperty(exports, "__esModule", { value: true });
7355
- exports.default = Ajv20202;
7355
+ exports.default = Ajv20203;
7356
7356
  var validate_1 = require_validate();
7357
7357
  Object.defineProperty(exports, "KeywordCxt", { enumerable: true, get: function() {
7358
7358
  return validate_1.KeywordCxt;
@@ -10437,6 +10437,7 @@ var ReleaseDependencyRoleSchema = z15.enum([
10437
10437
  "view",
10438
10438
  "projection",
10439
10439
  "action",
10440
+ "action-program",
10440
10441
  "token",
10441
10442
  "schema",
10442
10443
  "compiler",
@@ -10467,6 +10468,7 @@ var DependencyKindByRole = {
10467
10468
  view: "view",
10468
10469
  projection: "projection",
10469
10470
  action: "domain-command",
10471
+ "action-program": "action-program",
10470
10472
  token: "design-token",
10471
10473
  schema: "schema",
10472
10474
  compiler: "compiler",
@@ -11419,8 +11421,14 @@ var QueryBindingSchema = z15.object({
11419
11421
  }).strict().superRefine((value, context) => {
11420
11422
  if (value.draftRetention) {
11421
11423
  const names = value.draftRetention.identityParameters;
11422
- if (value.execution !== "server" || new Set(names).size !== names.length || names.some((name) => !Object.prototype.hasOwnProperty.call(value.parameters, name))) {
11423
- context.addIssue({ code: "custom", path: ["draftRetention"], message: "Draft retention requires distinct declared Server query identity parameters." });
11424
+ if (value.execution !== "server" || new Set(names).size !== names.length || names.some(
11425
+ (name) => !Object.prototype.hasOwnProperty.call(value.parameters, name)
11426
+ )) {
11427
+ context.addIssue({
11428
+ code: "custom",
11429
+ path: ["draftRetention"],
11430
+ message: "Draft retention requires distinct declared Server query identity parameters."
11431
+ });
11424
11432
  }
11425
11433
  }
11426
11434
  if (value.targetProjection) {
@@ -12114,6 +12122,237 @@ var PageDataSchema = QueryBindingSchema.omit({
12114
12122
  cursorWindow: PageCursorWindowSchema.optional(),
12115
12123
  resultStateBindings: z15.array(PageResultStateBindingSchema).max(32).optional()
12116
12124
  }).strict();
12125
+ var ACTION_PROGRAM_ABI = "monkeys.action-program/2";
12126
+ var ActionProgramBudgetsSchema = z15.object({
12127
+ rpcMs: z15.number().int().positive().max(3e4),
12128
+ concurrentCalls: z15.number().int().positive().max(4),
12129
+ calls: z15.number().int().positive().max(128),
12130
+ messageBytes: z15.number().int().positive().max(1048576),
12131
+ activeMs: z15.number().int().positive().max(12e4),
12132
+ formMs: z15.number().int().positive().max(3e5),
12133
+ wallMs: z15.number().int().positive().max(6e5)
12134
+ }).strict();
12135
+ var DEFAULT_ACTION_PROGRAM_BUDGETS = Object.freeze({
12136
+ rpcMs: 3e4,
12137
+ concurrentCalls: 4,
12138
+ calls: 128,
12139
+ messageBytes: 1048576,
12140
+ activeMs: 12e4,
12141
+ formMs: 3e5,
12142
+ wallMs: 6e5
12143
+ });
12144
+ var ProgramSchemaRefSchema = RevisionRefSchema.refine(
12145
+ (ref2) => ref2.kind === "schema",
12146
+ "Expected an exact Schema reference."
12147
+ );
12148
+ var ActionProgramDependencySchema = z15.object({
12149
+ kind: z15.enum(["query", "command"]),
12150
+ revisionRef: RevisionRefSchema,
12151
+ inputSchemaRevisionRef: ProgramSchemaRefSchema,
12152
+ resultSchemaRevisionRef: ProgramSchemaRefSchema,
12153
+ download: ActionBindingSchema.shape.success.shape.download,
12154
+ // Fixed/identity arguments are injected by the trusted caller, never by guest code.
12155
+ dynamicInputKeys: z15.array(ContractIdentifierSchema).max(128)
12156
+ }).strict().superRefine((value, context) => {
12157
+ const expected = value.kind === "query" ? "domain-query-definition" : "domain-command";
12158
+ if (value.revisionRef.kind !== expected)
12159
+ context.addIssue({
12160
+ code: "custom",
12161
+ path: ["revisionRef", "kind"],
12162
+ message: `Expected ${expected}.`
12163
+ });
12164
+ if (new Set(value.dynamicInputKeys).size !== value.dynamicInputKeys.length)
12165
+ context.addIssue({
12166
+ code: "custom",
12167
+ path: ["dynamicInputKeys"],
12168
+ message: "Dynamic input keys must be unique."
12169
+ });
12170
+ });
12171
+ var ActionProgramDefinitionSchema = z15.object({
12172
+ contract: z15.literal("ActionProgramDefinition"),
12173
+ schemaVersion: z15.literal(1),
12174
+ programId: ContractIdentifierSchema,
12175
+ ownerRepo: ContractIdentifierSchema,
12176
+ tenantScope: TenantScopeSchema,
12177
+ supportedSurface: z15.literal("studio"),
12178
+ inputSchemaRevisionRef: ProgramSchemaRefSchema,
12179
+ resultSchemaRevisionRef: ProgramSchemaRefSchema,
12180
+ entry: z15.literal("main"),
12181
+ abi: z15.literal(ACTION_PROGRAM_ABI),
12182
+ compiler: z15.string().trim().min(1).max(128),
12183
+ target: z15.literal("browser-worker-es2020"),
12184
+ sourceHash: Sha256Schema,
12185
+ compiledHash: Sha256Schema,
12186
+ sourceMapHash: Sha256Schema,
12187
+ dependencies: z15.array(ActionProgramDependencySchema).max(128),
12188
+ effects: z15.array(
12189
+ z15.enum([
12190
+ "form",
12191
+ "toast",
12192
+ "refresh",
12193
+ "download",
12194
+ "state.get",
12195
+ "state.set"
12196
+ ])
12197
+ ).max(6),
12198
+ refreshAliases: z15.array(ContractIdentifierSchema).max(128),
12199
+ stateAliases: z15.array(
12200
+ z15.object({
12201
+ alias: ContractIdentifierSchema,
12202
+ schemaRevisionRef: ProgramSchemaRefSchema
12203
+ }).strict()
12204
+ ).max(128),
12205
+ budgets: ActionProgramBudgetsSchema
12206
+ }).strict().superRefine((value, context) => {
12207
+ for (const [name, keys] of [
12208
+ [
12209
+ "dependencies",
12210
+ value.dependencies.map((dep) => `${dep.kind}:${dep.revisionRef.id}`)
12211
+ ],
12212
+ ["effects", value.effects],
12213
+ ["refreshAliases", value.refreshAliases],
12214
+ ["stateAliases", value.stateAliases.map((entry) => entry.alias)]
12215
+ ])
12216
+ if (new Set(keys).size !== keys.length)
12217
+ context.addIssue({
12218
+ code: "custom",
12219
+ path: [name],
12220
+ message: "Program declarations must be unique."
12221
+ });
12222
+ const refs = [
12223
+ value.inputSchemaRevisionRef,
12224
+ value.resultSchemaRevisionRef,
12225
+ ...value.dependencies.flatMap((dep) => [
12226
+ dep.revisionRef,
12227
+ dep.inputSchemaRevisionRef,
12228
+ dep.resultSchemaRevisionRef
12229
+ ]),
12230
+ ...value.stateAliases.map((entry) => entry.schemaRevisionRef)
12231
+ ];
12232
+ refs.forEach((ref2, index) => {
12233
+ if (ref2.visibility === "tenant" && ref2.tenantScope && tenantScopeKey(ref2.tenantScope) !== tenantScopeKey(value.tenantScope))
12234
+ context.addIssue({
12235
+ code: "custom",
12236
+ path: ["dependencies"],
12237
+ message: `Cross-tenant program reference ${index}.`
12238
+ });
12239
+ });
12240
+ });
12241
+ var ActionProgramArtifactSchema = z15.object({
12242
+ definition: ActionProgramDefinitionSchema,
12243
+ // Hashes use canonicalContentHash of the exact UTF-8 string, not engine bytecode.
12244
+ javascript: z15.string().min(1).max(262144).refine(
12245
+ (value) => new TextEncoder().encode(value).length <= 262144,
12246
+ "Program exceeds 256 KiB."
12247
+ ),
12248
+ sourceMap: z15.string().min(1).max(524288).refine(
12249
+ (value) => new TextEncoder().encode(value).length <= 524288,
12250
+ "Source map exceeds 512 KiB."
12251
+ )
12252
+ }).strict();
12253
+ var ProgramInputSourceSchema = z15.discriminatedUnion("kind", [
12254
+ ...BindingSourceSchema.options,
12255
+ ExpressionBindingSourceSchema
12256
+ ]);
12257
+ var ProgramBindingShape = {
12258
+ bindingId: ContractIdentifierSchema,
12259
+ inputMapping: z15.record(ContractIdentifierSchema, ProgramInputSourceSchema),
12260
+ dependencyInputs: z15.record(
12261
+ ContractIdentifierSchema,
12262
+ z15.record(ContractIdentifierSchema, ProgramInputSourceSchema)
12263
+ ),
12264
+ accessPolicy: AccessPolicySchema,
12265
+ confirmation: I18nTextSchema.optional(),
12266
+ when: PageExpressionSchema.optional(),
12267
+ concurrencyKeyPath: PageValuePathSchema.min(1),
12268
+ refreshAliases: z15.record(
12269
+ ContractIdentifierSchema,
12270
+ z15.array(ContractIdentifierSchema).min(1).max(128)
12271
+ ),
12272
+ stateAliases: z15.record(ContractIdentifierSchema, ContractIdentifierSchema)
12273
+ };
12274
+ var PageProgramActionSchema = z15.object({
12275
+ ...ProgramBindingShape,
12276
+ program: ContractIdentifierSchema,
12277
+ port: ContractIdentifierSchema
12278
+ }).strict();
12279
+ var ProgramBindingSchema = z15.object({
12280
+ ...ProgramBindingShape,
12281
+ source: z15.object({
12282
+ capabilityInstanceId: ContractIdentifierSchema,
12283
+ port: ContractIdentifierSchema
12284
+ }).strict(),
12285
+ sourceIntentSchemaRevisionRef: ProgramSchemaRefSchema,
12286
+ programRevisionRef: RevisionRefSchema.refine(
12287
+ (ref2) => ref2.kind === "action-program",
12288
+ "Expected action-program reference."
12289
+ ),
12290
+ definition: ActionProgramDefinitionSchema
12291
+ }).strict();
12292
+ function validateProgramBindingTargets(page, context) {
12293
+ const ids = new Set(page.actionBindings.map((binding) => binding.bindingId));
12294
+ const ports = new Set(
12295
+ page.actionBindings.map(
12296
+ (binding) => `${binding.source.capabilityInstanceId}:${binding.source.port}`
12297
+ )
12298
+ );
12299
+ const dataIds = new Set(
12300
+ [...page.ontologyBindings, ...page.queryBindings ?? []].map(
12301
+ (binding) => binding.bindingId
12302
+ )
12303
+ );
12304
+ for (const [index, binding] of (page.programBindings ?? []).entries()) {
12305
+ const issue = (message) => context.addIssue({
12306
+ code: "custom",
12307
+ path: ["programBindings", index],
12308
+ message
12309
+ });
12310
+ const port = `${binding.source.capabilityInstanceId}:${binding.source.port}`;
12311
+ if (ids.has(binding.bindingId) || ports.has(port))
12312
+ issue("Program binding id and event must be exclusive.");
12313
+ ids.add(binding.bindingId);
12314
+ ports.add(port);
12315
+ if (!page.capabilityInstances.some(
12316
+ (instance) => instance.instanceId === binding.source.capabilityInstanceId
12317
+ ))
12318
+ issue("Program source instance is missing.");
12319
+ const exactKeys = (keys, expected) => keys.length === expected.length && keys.every((key) => expected.includes(key));
12320
+ if (!exactKeys(
12321
+ Object.keys(binding.refreshAliases),
12322
+ binding.definition.refreshAliases
12323
+ ) || Object.values(binding.refreshAliases).some(
12324
+ (targets) => targets.some((target) => !dataIds.has(target))
12325
+ ))
12326
+ issue(
12327
+ "Program refresh aliases must resolve exactly to declared data bindings."
12328
+ );
12329
+ if (!exactKeys(
12330
+ Object.keys(binding.stateAliases),
12331
+ binding.definition.stateAliases.map((entry) => entry.alias)
12332
+ ))
12333
+ issue("Program state aliases must match its manifest.");
12334
+ for (const entry of binding.definition.stateAliases) {
12335
+ const state = page.stateDefinitions?.find(
12336
+ (state2) => state2.stateId === binding.stateAliases[entry.alias]
12337
+ );
12338
+ if (!state || !exactRevisionRef(state.schemaRevisionRef, entry.schemaRevisionRef))
12339
+ issue("Program state alias has an incompatible Schema.");
12340
+ }
12341
+ const dependencyIds = binding.definition.dependencies.map(
12342
+ (dep) => dep.revisionRef.id
12343
+ );
12344
+ if (!Object.keys(binding.dependencyInputs).every(
12345
+ (key) => dependencyIds.includes(key)
12346
+ ))
12347
+ issue("Unknown program dependency input mapping.");
12348
+ for (const dep of binding.definition.dependencies) {
12349
+ if (Object.keys(binding.dependencyInputs[dep.revisionRef.id] ?? {}).some(
12350
+ (key) => dep.dynamicInputKeys.includes(key)
12351
+ ))
12352
+ issue("Fixed dependency arguments cannot also be guest-writable.");
12353
+ }
12354
+ }
12355
+ }
12117
12356
  var PageActionSchema = ActionBindingSchema.omit({
12118
12357
  commandRevisionRef: true,
12119
12358
  source: true,
@@ -12156,6 +12395,7 @@ var PageNodeSchema = z15.lazy(
12156
12395
  }).strict().optional(),
12157
12396
  data: z15.array(PageDataSchema).optional(),
12158
12397
  actions: z15.array(PageActionSchema).optional(),
12398
+ programActions: z15.array(PageProgramActionSchema).max(128).optional(),
12159
12399
  on: z15.array(PageInteractionSchema).optional(),
12160
12400
  effects: z15.array(PageEventEffectSchema).optional(),
12161
12401
  eventPayloads: z15.array(
@@ -12234,6 +12474,7 @@ var PageSchema = z15.object({
12234
12474
  for (const [field, values, target] of [
12235
12475
  ["data", node.data ?? [], dataIds],
12236
12476
  ["actions", node.actions ?? [], actionIds],
12477
+ ["programActions", node.programActions ?? [], actionIds],
12237
12478
  ["on", node.on ?? [], interactionIds]
12238
12479
  ])
12239
12480
  for (const [index, value] of values.entries()) {
@@ -12287,6 +12528,7 @@ var ResolvedPageSchema = z15.object({
12287
12528
  ontologyBindings: z15.array(PersistedOntologyBindingSchema),
12288
12529
  queryBindings: z15.array(QueryBindingSchema).optional(),
12289
12530
  actionBindings: z15.array(ActionBindingSchema),
12531
+ programBindings: z15.array(ProgramBindingSchema).max(128).optional(),
12290
12532
  pageAccessPolicy: AccessPolicySchema,
12291
12533
  managementAccess: ManagementAccessSchema,
12292
12534
  tokenRevisionRefs: z15.array(RevisionRefSchema).min(1),
@@ -12299,6 +12541,7 @@ var ResolvedPageSchema = z15.object({
12299
12541
  "restricted"
12300
12542
  ])
12301
12543
  }).strict().superRefine((value, context) => {
12544
+ validateProgramBindingTargets(value, context);
12302
12545
  validateDeclaredRouteSurfaces(
12303
12546
  value.supportedSurfaces,
12304
12547
  value.routeClaims,
@@ -12656,6 +12899,35 @@ var ResolvedPageSchema = z15.object({
12656
12899
  )
12657
12900
  );
12658
12901
  }
12902
+ (value.programBindings ?? []).forEach((binding, index) => {
12903
+ const scopes = scopesForNode(
12904
+ instanceNodes.get(binding.source.capabilityInstanceId)
12905
+ );
12906
+ checkScopedSources(binding.inputMapping, scopes, [
12907
+ "programBindings",
12908
+ index,
12909
+ "inputMapping"
12910
+ ]);
12911
+ for (const [id, mapping] of Object.entries(binding.dependencyInputs))
12912
+ checkScopedSources(mapping, scopes, [
12913
+ "programBindings",
12914
+ index,
12915
+ "dependencyInputs",
12916
+ id
12917
+ ]);
12918
+ if (binding.when) {
12919
+ const reads = collectPageExpressionReads(binding.when);
12920
+ checkScopedReads(reads, scopes, ["programBindings", index, "when"]);
12921
+ if (reads.some(
12922
+ (read) => read.root === "state" && !stateIds.has(read.path[0])
12923
+ ))
12924
+ context.addIssue({
12925
+ code: "custom",
12926
+ path: ["programBindings", index, "when"],
12927
+ message: "Program condition references an unknown Page state."
12928
+ });
12929
+ }
12930
+ });
12659
12931
  value.actionBindings.forEach((binding, index) => {
12660
12932
  const scopes = scopesForNode(
12661
12933
  instanceNodes.get(binding.source.capabilityInstanceId)
@@ -13236,7 +13508,10 @@ var ResolvedPageSchema = z15.object({
13236
13508
  const conflictingInteraction = interactionBindings.some(
13237
13509
  (candidate) => candidate.source.capabilityInstanceId === sourceId && candidate.source.port === binding.cursorWindow.pageChangePort
13238
13510
  );
13239
- const conflictingAction = value.actionBindings.some(
13511
+ const conflictingAction = [
13512
+ ...value.actionBindings,
13513
+ ...value.programBindings ?? []
13514
+ ].some(
13240
13515
  (candidate) => candidate.source.capabilityInstanceId === sourceId && candidate.source.port === binding.cursorWindow.pageChangePort
13241
13516
  );
13242
13517
  if (conflictingInteraction || conflictingAction) {
@@ -13247,6 +13522,20 @@ var ResolvedPageSchema = z15.object({
13247
13522
  });
13248
13523
  }
13249
13524
  });
13525
+ (value.programBindings ?? []).forEach((binding, index) => {
13526
+ validatePageStateSources(binding.inputMapping, [
13527
+ "programBindings",
13528
+ index,
13529
+ "inputMapping"
13530
+ ]);
13531
+ for (const [id, mapping] of Object.entries(binding.dependencyInputs))
13532
+ validatePageStateSources(mapping, [
13533
+ "programBindings",
13534
+ index,
13535
+ "dependencyInputs",
13536
+ id
13537
+ ]);
13538
+ });
13250
13539
  value.actionBindings.forEach((binding, index) => {
13251
13540
  if (!instanceIds.has(binding.source.capabilityInstanceId)) {
13252
13541
  context.addIssue({
@@ -14087,6 +14376,7 @@ var CompatiblePageRuntimeBundleSchema = z15.object({
14087
14376
  ontologyBindings: z15.array(PersistedOntologyBindingSchema),
14088
14377
  queryBindings: z15.array(QueryBindingSchema).default([]),
14089
14378
  actionBindings: z15.array(ActionBindingSchema),
14379
+ programBindings: z15.array(ProgramBindingSchema).max(128).optional(),
14090
14380
  pageAccessPolicy: AccessPolicySchema,
14091
14381
  tokenRevisionRefs: z15.array(RevisionRefSchema),
14092
14382
  performanceBudgetRef: RevisionRefSchema,
@@ -14109,6 +14399,7 @@ var CompatiblePageRuntimeBundleSchema = z15.object({
14109
14399
  message: "Denied capability identities must be unique declared instances."
14110
14400
  });
14111
14401
  }
14402
+ validateProgramBindingTargets(value, context);
14112
14403
  validateRuntimeBundleBase(value, "page-release", context);
14113
14404
  value.routeClaims.forEach((claim, index) => {
14114
14405
  if (claim.surface !== value.surface) {
@@ -21390,6 +21681,38 @@ var pageStreamRoutes = {
21390
21681
  };
21391
21682
  var PageStreamControlResultSchema = z30.object({ requestId: z30.string().uuid(), accepted: z30.literal(true) }).strict();
21392
21683
 
21684
+ // src/contracts/action-program-http.ts
21685
+ import { z as z31 } from "zod";
21686
+ var PrepareActionProgramRequestSchema = z31.object({
21687
+ artifact: ActionProgramArtifactSchema,
21688
+ expectedVersion: z31.number().int().min(0)
21689
+ }).strict();
21690
+ var RegisterActionProgramRequestSchema = PrepareActionProgramRequestSchema.extend({
21691
+ planHash: Sha256Schema,
21692
+ idempotencyKey: ContractIdentifierSchema
21693
+ }).strict();
21694
+ var ReadActionProgramRequestSchema = z31.object({ revisionRef: RevisionRefSchema }).strict();
21695
+ var RuntimeProgramLoadRequestSchema = z31.object({
21696
+ context: DeclarativeRuntimeActionExecuteIntentSchema
21697
+ }).strict();
21698
+ var RuntimeProgramCallRequestSchema = RuntimeProgramLoadRequestSchema.extend({
21699
+ kind: z31.enum(["query", "command"]),
21700
+ dependencyId: ContractIdentifierSchema,
21701
+ args: JsonObjectSchema,
21702
+ stepKey: z31.string().min(1).max(128),
21703
+ recoveryOnly: z31.literal(true).optional()
21704
+ }).strict();
21705
+ var RuntimeProgramLoadResultSchema = z31.object({
21706
+ artifact: ActionProgramArtifactSchema,
21707
+ input: JsonObjectSchema,
21708
+ schemas: z31.array(z31.object({ revisionRef: RevisionRefSchema, document: JsonObjectSchema }).strict()).max(512)
21709
+ }).strict();
21710
+ var RuntimeProgramCallResultSchema = z31.object({ value: JsonObjectSchema }).strict();
21711
+ var RuntimeProgramDownloadResultSchema = z31.discriminatedUnion("kind", [
21712
+ z31.object({ kind: z31.literal("native"), download: DeclarativeNativeDownloadSchema }).strict(),
21713
+ z31.object({ kind: z31.literal("text-artifact"), fileName: z31.string().min(1).max(255), mimeType: z31.enum(["application/json", "text/plain", "text/csv"]), content: z31.string().max(1048576) }).strict()
21714
+ ]);
21715
+
21393
21716
  // src/schemas/index.ts
21394
21717
  var canonicalContractSchemas = {
21395
21718
  "aggregate-commit-request": AggregateCommitRequestSchema,
@@ -21423,6 +21746,8 @@ var canonicalContractSchemas = {
21423
21746
  "domain-event": DomainEventSchema,
21424
21747
  "domain-command": DomainCommandSchema,
21425
21748
  "domain-command-definition": DomainCommandDefinitionSchema,
21749
+ "action-program-definition": ActionProgramDefinitionSchema,
21750
+ "action-program-artifact": ActionProgramArtifactSchema,
21426
21751
  "data-continuity-envelope": DataContinuityEnvelopeSchema,
21427
21752
  "domain-query-definition": DomainQueryDefinitionSchema,
21428
21753
  "declarative-control-ontology-definition": DeclarativeControlOntologyDefinitionSchema,
@@ -23024,6 +23349,17 @@ var pageDependencies = (page, compilerRevisionRef) => [
23024
23349
  }
23025
23350
  ] : []
23026
23351
  ]),
23352
+ ...(page.programBindings ?? []).flatMap((binding) => [
23353
+ {
23354
+ role: "action-program",
23355
+ revisionRef: binding.programRevisionRef
23356
+ },
23357
+ {
23358
+ role: "schema",
23359
+ revisionRef: binding.sourceIntentSchemaRevisionRef
23360
+ },
23361
+ ...programDependencies(binding.definition)
23362
+ ]),
23027
23363
  ...page.actionBindings.flatMap((binding) => [
23028
23364
  { role: "action", revisionRef: binding.commandRevisionRef },
23029
23365
  {
@@ -23255,6 +23591,7 @@ var resolvePage = (input) => {
23255
23591
  const capabilityInstances = [];
23256
23592
  const queryBindings = [];
23257
23593
  const actionBindings = [];
23594
+ const programBindings = [];
23258
23595
  const interactionBindings = [];
23259
23596
  const nodesById = /* @__PURE__ */ new Map();
23260
23597
  const indexNode = (node) => {
@@ -23467,6 +23804,76 @@ var resolvePage = (input) => {
23467
23804
  resultSchemaRevisionRef
23468
23805
  });
23469
23806
  }
23807
+ for (const [index, binding] of (node.programActions ?? []).entries()) {
23808
+ const path = `page.body.${node.id}.programActions[${index}]`;
23809
+ const matches = (input.programRegistry ?? []).filter(
23810
+ (entry) => entry.definition.programId === binding.program
23811
+ );
23812
+ if (matches.length !== 1)
23813
+ throw new DeclarativeControlCompilationError(
23814
+ "DEPENDENCY_MISSING",
23815
+ path,
23816
+ "Expected one exact program registration."
23817
+ );
23818
+ const program = matches[0];
23819
+ const definition = ActionProgramDefinitionSchema.parse(
23820
+ program.definition
23821
+ );
23822
+ assertProgramRegistration(program, page.tenantScope, page.surface, path);
23823
+ const port = registration.outputPorts.find(
23824
+ (candidate) => candidate.name === binding.port
23825
+ );
23826
+ if (!port)
23827
+ throw new DeclarativeControlCompilationError(
23828
+ "PORT_TYPE_MISMATCH",
23829
+ path,
23830
+ "Program source port is not registered."
23831
+ );
23832
+ if ((node.actions ?? []).some((action) => action.port === binding.port) || programBindings.some(
23833
+ (action) => action.source.capabilityInstanceId === node.id && action.source.port === binding.port
23834
+ ))
23835
+ throw new DeclarativeControlCompilationError(
23836
+ "CAPABILITY_BINDING_MISMATCH",
23837
+ path,
23838
+ "A program output port must have one exclusive action binding."
23839
+ );
23840
+ for (const dep of definition.dependencies) {
23841
+ const registrations = dep.kind === "query" ? queryRegistrations : commandRegistrations;
23842
+ const actual = registrations.find(
23843
+ (entry) => sameRevisionRef(entry.revisionRef, dep.revisionRef)
23844
+ );
23845
+ if (!actual || canonicalContentHash(actual.definition) !== dep.revisionRef.contentHash || "sensitiveInputPaths" in actual.definition && !!actual.definition.sensitiveInputPaths?.length || "sensitiveResultPaths" in actual.definition && !!actual.definition.sensitiveResultPaths?.length || ("queryId" in actual.definition ? !sameRevisionRef(
23846
+ actual.definition.inputSchemaRevisionRef,
23847
+ dep.inputSchemaRevisionRef
23848
+ ) || !sameRevisionRef(
23849
+ actual.definition.resultSchemaRevisionRef,
23850
+ dep.resultSchemaRevisionRef
23851
+ ) : actual.definition.inputSchemaRef !== dep.inputSchemaRevisionRef.id || actual.definition.outputSchemaRef !== dep.resultSchemaRevisionRef.id))
23852
+ throw new DeclarativeControlCompilationError(
23853
+ "DEPENDENCY_MISSING",
23854
+ path,
23855
+ "Program capability/schema revision is not registered."
23856
+ );
23857
+ }
23858
+ for (const ref2 of programDependencies(definition).filter((dep) => dep.role === "schema").map((dep) => dep.revisionRef)) {
23859
+ if (!schemaRegistrations.some(
23860
+ (entry) => sameRevisionRef(entry.revisionRef, ref2)
23861
+ ))
23862
+ throw new DeclarativeControlCompilationError(
23863
+ "SCHEMA_DEFINITION_MISMATCH",
23864
+ path,
23865
+ "Program requires an exact registered Schema."
23866
+ );
23867
+ }
23868
+ const { program: _program, port: _port, ...rest } = binding;
23869
+ programBindings.push({
23870
+ ...rest,
23871
+ source: { capabilityInstanceId: node.id, port: binding.port },
23872
+ sourceIntentSchemaRevisionRef: port.schemaRevisionRef,
23873
+ programRevisionRef: program.definitionRevisionRef,
23874
+ definition
23875
+ });
23876
+ }
23470
23877
  for (const [index, binding] of (node.on ?? []).entries()) {
23471
23878
  const port = registration.outputPorts.find(
23472
23879
  (candidate) => candidate.name === binding.port
@@ -23552,6 +23959,7 @@ var resolvePage = (input) => {
23552
23959
  ontologyBindings: [],
23553
23960
  ...queryBindings.length ? { queryBindings } : {},
23554
23961
  actionBindings,
23962
+ ...programBindings.length ? { programBindings } : {},
23555
23963
  pageAccessPolicy: page.access,
23556
23964
  managementAccess: page.managementAccess,
23557
23965
  tokenRevisionRefs,
@@ -24050,27 +24458,47 @@ var compilePageRuntimeBundleInternal = (input, legacy) => {
24050
24458
  );
24051
24459
  }
24052
24460
  });
24053
- page.actionBindings.forEach((binding, index) => {
24054
- const instance = page.capabilityInstances.find(
24055
- (candidate) => candidate.instanceId === binding.source.capabilityInstanceId
24461
+ (page.programBindings ?? []).forEach((binding, index) => {
24462
+ const path = `programBindings[${index}]`;
24463
+ const registration = (input.programRegistry ?? []).find(
24464
+ (entry) => sameRevisionRef(entry.definitionRevisionRef, binding.programRevisionRef)
24056
24465
  );
24057
- const registration = instance && registrationsByPair.get(
24058
- `${revisionRefKey(instance.capabilityRevisionRef)}:${revisionRefKey(instance.providerRevisionRef)}`
24059
- );
24060
- const port = registration?.outputPorts.find(
24061
- (candidate) => candidate.name === binding.source.port
24062
- );
24063
- if (!port || !sameSchemaContract(
24064
- port.schemaRevisionRef,
24065
- binding.sourceIntentSchemaRevisionRef
24066
- )) {
24466
+ if (!registration || canonicalContentHash(registration.definition) !== canonicalContentHash(binding.definition))
24067
24467
  throw new DeclarativeControlCompilationError(
24068
- "PORT_TYPE_MISMATCH",
24069
- `actionBindings[${index}].sourceIntentSchemaRevisionRef`,
24070
- "Action source intent does not match the registered capability output port."
24468
+ "DEPENDENCY_MISSING",
24469
+ path,
24470
+ "Exact program registration does not match binding."
24071
24471
  );
24072
- }
24472
+ assertProgramRegistration(
24473
+ registration,
24474
+ page.tenantScope,
24475
+ release.target.surface,
24476
+ path
24477
+ );
24073
24478
  });
24479
+ [...page.actionBindings, ...page.programBindings ?? []].forEach(
24480
+ (binding, index) => {
24481
+ const instance = page.capabilityInstances.find(
24482
+ (candidate) => candidate.instanceId === binding.source.capabilityInstanceId
24483
+ );
24484
+ const registration = instance && registrationsByPair.get(
24485
+ `${revisionRefKey(instance.capabilityRevisionRef)}:${revisionRefKey(instance.providerRevisionRef)}`
24486
+ );
24487
+ const port = registration?.outputPorts.find(
24488
+ (candidate) => candidate.name === binding.source.port
24489
+ );
24490
+ if (!port || !sameSchemaContract(
24491
+ port.schemaRevisionRef,
24492
+ binding.sourceIntentSchemaRevisionRef
24493
+ )) {
24494
+ throw new DeclarativeControlCompilationError(
24495
+ "PORT_TYPE_MISMATCH",
24496
+ `actionBindings[${index}].sourceIntentSchemaRevisionRef`,
24497
+ "Action source intent does not match the registered capability output port."
24498
+ );
24499
+ }
24500
+ }
24501
+ );
24074
24502
  const routeClaims = compileRouteClaims({
24075
24503
  claims: page.routeClaims,
24076
24504
  routeSpaces: input.routeSpaces,
@@ -24224,6 +24652,7 @@ var compilePageRuntimeBundleInternal = (input, legacy) => {
24224
24652
  ontologyBindings: page.ontologyBindings,
24225
24653
  queryBindings: page.queryBindings,
24226
24654
  actionBindings: page.actionBindings,
24655
+ ...page.programBindings?.length ? { programBindings: page.programBindings } : {},
24227
24656
  pageAccessPolicy: page.pageAccessPolicy,
24228
24657
  tokenRevisionRefs: page.tokenRevisionRefs,
24229
24658
  performanceBudgetRef: page.performanceBudgetRef,
@@ -24538,7 +24967,9 @@ var compileNavigationRuntimeBundle = (input) => {
24538
24967
  input.compilerRevisionRef
24539
24968
  );
24540
24969
  const scope = TenantScopeSchema.parse(navigation.tenantScope);
24541
- const verifiedKernelPageReferences = [...input.verifiedKernelPageReferences ?? []].map((reference, index) => {
24970
+ const verifiedKernelPageReferences = [
24971
+ ...input.verifiedKernelPageReferences ?? []
24972
+ ].map((reference, index) => {
24542
24973
  const parsed = RevisionRefSchema.parse(reference);
24543
24974
  if (release.target.surface !== "kernel" || parsed.visibility !== "tenant" || !parsed.tenantScope?.teamRef?.id.startsWith("kernel-page.") || parsed.ownerRepo !== "monkeys-server" || !["page", "page-release"].includes(parsed.kind)) {
24544
24975
  throw new DeclarativeControlCompilationError(
@@ -24752,8 +25183,14 @@ var compileNavigationRuntimeBundle = (input) => {
24752
25183
  const released = releasedByNodeId.get(node.nodeId);
24753
25184
  const unavailable = unavailableByNodeId.get(node.nodeId);
24754
25185
  if (!registration && node.targetRef.kind === "page" && (unavailable && sameStableRef(unavailable.stableTargetRef, node.targetRef) || released && sameStableRef(released.stableTargetRef, node.targetRef))) {
24755
- if (!released || !verifiedKernelPageReferenceKeys.has(revisionRefKey(released.targetRevisionRef))) {
24756
- assertTenantCompatible(node.targetRef, scope, `nodes[${index}].targetRef`);
25186
+ if (!released || !verifiedKernelPageReferenceKeys.has(
25187
+ revisionRefKey(released.targetRevisionRef)
25188
+ )) {
25189
+ assertTenantCompatible(
25190
+ node.targetRef,
25191
+ scope,
25192
+ `nodes[${index}].targetRef`
25193
+ );
24757
25194
  }
24758
25195
  if (unavailable?.accessPolicy && !accessPolicyChainImplies(
24759
25196
  [...ancestors, node.audience],
@@ -24782,7 +25219,10 @@ var compileNavigationRuntimeBundle = (input) => {
24782
25219
  if (!registration || !released && !(currentPage && unavailable && sameStableRef(unavailable.stableTargetRef, node.targetRef)) || !sameStableRef(
24783
25220
  registration.stableTargetRef,
24784
25221
  stableFromRevision(registration.targetRevisionRef)
24785
- ) || released && !sameStableRef(registration.stableTargetRef, released.stableTargetRef) || !currentPage && released && !sameRevisionRef(
25222
+ ) || released && !sameStableRef(
25223
+ registration.stableTargetRef,
25224
+ released.stableTargetRef
25225
+ ) || !currentPage && released && !sameRevisionRef(
24786
25226
  registration.targetRevisionRef,
24787
25227
  released.targetRevisionRef
24788
25228
  ) || !currentPage && released && registration.kind === "route" && (Boolean(registration.releaseRevisionRef) !== Boolean(released.releaseRevisionRef) || registration.releaseRevisionRef && released.releaseRevisionRef && !sameRevisionRef(
@@ -25044,6 +25484,33 @@ var resolveWorkbenchEntry = (input) => {
25044
25484
  };
25045
25485
  return { status: "forbidden", workbenchId: "" };
25046
25486
  };
25487
+ var programDependencies = (definition) => [
25488
+ ...[
25489
+ definition.inputSchemaRevisionRef,
25490
+ definition.resultSchemaRevisionRef,
25491
+ ...definition.stateAliases.map((entry) => entry.schemaRevisionRef)
25492
+ ].map((revisionRef) => ({ role: "schema", revisionRef })),
25493
+ ...definition.dependencies.flatMap((dep) => [
25494
+ {
25495
+ role: dep.kind === "query" ? "query-definition" : "action",
25496
+ revisionRef: dep.revisionRef
25497
+ },
25498
+ { role: "schema", revisionRef: dep.inputSchemaRevisionRef },
25499
+ { role: "schema", revisionRef: dep.resultSchemaRevisionRef }
25500
+ ])
25501
+ ];
25502
+ function assertProgramRegistration(registration, scope, surface, path = "program") {
25503
+ const definition = ActionProgramDefinitionSchema.parse(
25504
+ registration.definition
25505
+ );
25506
+ const ref2 = RevisionRefSchema.parse(registration.definitionRevisionRef);
25507
+ if (ref2.kind !== "action-program" || ref2.id !== definition.programId || ref2.ownerRepo !== definition.ownerRepo || ref2.visibility !== "tenant" || canonicalContentHash(ref2.tenantScope) !== canonicalContentHash(scope) || canonicalContentHash(definition.tenantScope) !== canonicalContentHash(scope) || ref2.schemaVersion !== definition.schemaVersion || ref2.contentHash !== canonicalContentHash(definition) || definition.supportedSurface !== surface)
25508
+ throw new DeclarativeControlCompilationError(
25509
+ "CROSS_TENANT_REFERENCE",
25510
+ path,
25511
+ "Program identity, scope, surface or content hash does not match its exact reference."
25512
+ );
25513
+ }
25047
25514
 
25048
25515
  // src/runtime/navigation-availability.ts
25049
25516
  var NAVIGATION_UNAVAILABLE_CAPABILITY_HEADER = "x-monkeys-navigation-capabilities";
@@ -26163,6 +26630,19 @@ var assertDeclarativeCapabilityContract = (entry, request) => {
26163
26630
  throw new TypeError("The historical capability snapshot is not supported by the current runtime contract.");
26164
26631
  }
26165
26632
  };
26633
+ var schemasCannotOverlap = (left, right) => {
26634
+ if (left === false || right === false) return true;
26635
+ if (!left || !right || typeof left !== "object" || typeof right !== "object" || Array.isArray(left) || Array.isArray(right)) return false;
26636
+ const a = left;
26637
+ const b = right;
26638
+ if (a.$ref || b.$ref) return false;
26639
+ const values = (schema2) => Object.prototype.hasOwnProperty.call(schema2, "const") ? [schema2.const] : Array.isArray(schema2.enum) ? schema2.enum : void 0;
26640
+ const av = values(a), bv = values(b);
26641
+ if (av && bv && av.every((value) => !bv.some((other) => canonicalContentHash(value) === canonicalContentHash(other)))) return true;
26642
+ if (a.type !== "object" || b.type !== "object") return false;
26643
+ const property = (schema2, key) => schema2.properties?.[key] ?? (schema2.patternProperties ? true : schema2.additionalProperties ?? true);
26644
+ return [...a.required ?? [], ...b.required ?? []].some((key) => schemasCannotOverlap(property(a, key), property(b, key)));
26645
+ };
26166
26646
  var acceptsPreviousSchema = (previous, next) => {
26167
26647
  if (canonicalContentHash(previous) === canonicalContentHash(next) || next === true) return true;
26168
26648
  if (previous === false) return true;
@@ -26170,6 +26650,11 @@ var acceptsPreviousSchema = (previous, next) => {
26170
26650
  const withoutAnnotations = (schema2) => Object.fromEntries(Object.entries(schema2).filter(([key]) => !["title", "description", "examples", "$comment"].includes(key)));
26171
26651
  const before = withoutAnnotations(previous);
26172
26652
  const after = withoutAnnotations(next);
26653
+ const branches = (schema2) => Object.keys(schema2).length === 1 ? Array.isArray(schema2.anyOf) ? schema2.anyOf : Array.isArray(schema2.oneOf) ? schema2.oneOf : void 0 : void 0;
26654
+ const oldBranches = branches(before);
26655
+ if (oldBranches) return oldBranches.every((branch) => acceptsPreviousSchema(branch, next));
26656
+ const newBranches = branches(after);
26657
+ if (newBranches) return newBranches.some((branch, index) => acceptsPreviousSchema(previous, branch) && (!after.oneOf || newBranches.every((other, otherIndex) => index === otherIndex || schemasCannotOverlap(previous, other))));
26173
26658
  const {
26174
26659
  properties: oldProperties,
26175
26660
  required: oldRequired,
@@ -26219,7 +26704,7 @@ var assertCompatibleCapabilityUpgrade = (previous, next) => {
26219
26704
  const manifestContract = (entry) => ({
26220
26705
  kind: entry.manifest.kind,
26221
26706
  runtime: { ...entry.manifest.runtime, providerBindings: entry.manifest.runtime.providerBindings.map((binding) => ({ ...binding, providerRef: { ...binding.providerRef, version: void 0 } })) },
26222
- placement: entry.manifest.placement,
26707
+ placement: entry.manifest.placement && { ...entry.manifest.placement, slots: void 0 },
26223
26708
  accessibility: entry.manifest.accessibility
26224
26709
  });
26225
26710
  if (canonicalContentHash(manifestContract(previous)) !== canonicalContentHash(manifestContract(next))) {
@@ -26227,6 +26712,14 @@ var assertCompatibleCapabilityUpgrade = (previous, next) => {
26227
26712
  }
26228
26713
  const oldRegistration = previous.declarativeRegistration;
26229
26714
  const newRegistration = next.declarativeRegistration;
26715
+ for (const [oldSlots, newSlots] of [
26716
+ [previous.manifest.placement?.slots ?? [], next.manifest.placement?.slots ?? []],
26717
+ [oldRegistration.allowedSlots, newRegistration.allowedSlots]
26718
+ ]) {
26719
+ if (oldSlots.some((slot) => !newSlots.includes(slot))) {
26720
+ throw new TypeError("Published runtime slots cannot be removed.");
26721
+ }
26722
+ }
26230
26723
  const schema2 = (entry, reference) => {
26231
26724
  const document = entry.schemaDocuments.find((candidate) => sameSchemaContract(candidate.schemaRevisionRef, reference));
26232
26725
  if (!document || canonicalContentHash(document.document) !== reference.contentHash) throw new TypeError("Runtime contract schema integrity failed.");
@@ -26271,7 +26764,7 @@ var assertCompatibleCapabilityUpgrade = (previous, next) => {
26271
26764
  if (canonicalContentHash(oldRegistration.actionRequirements) !== canonicalContentHash(existingActions)) {
26272
26765
  throw new TypeError("Published output action and permission requirements changed.");
26273
26766
  }
26274
- for (const key of ["allowedSideEffects", "allowedSlots", "supportedSurfaces", "allowedParentCapabilityRefs", "allowedChildCapabilityRefs"]) {
26767
+ for (const key of ["allowedSideEffects", "supportedSurfaces", "allowedParentCapabilityRefs", "allowedChildCapabilityRefs"]) {
26275
26768
  if (canonicalContentHash(oldRegistration[key]) !== canonicalContentHash(newRegistration[key])) throw new TypeError(`Runtime contract ${key} changed.`);
26276
26769
  }
26277
26770
  };
@@ -27143,7 +27636,159 @@ function applyPageStreamEvent(state, input) {
27143
27636
  error: frame.type === "error" ? frame.payload : void 0
27144
27637
  };
27145
27638
  }
27639
+
27640
+ // src/runtime/action-program-author.ts
27641
+ var import__2 = __toESM(require__());
27642
+ function programSchemaType(schema2, path = "$", depth = 0) {
27643
+ if (depth > 32 || !schema2 || typeof schema2 !== "object" || Array.isArray(schema2))
27644
+ throw new Error(`Unsupported schema at ${path}`);
27645
+ const value = schema2;
27646
+ const allowed = /* @__PURE__ */ new Set([
27647
+ "$schema",
27648
+ "$id",
27649
+ "title",
27650
+ "description",
27651
+ "type",
27652
+ "properties",
27653
+ "required",
27654
+ "additionalProperties",
27655
+ "items",
27656
+ "enum",
27657
+ "const",
27658
+ "anyOf",
27659
+ "oneOf",
27660
+ "minLength",
27661
+ "maxLength",
27662
+ "pattern",
27663
+ "format",
27664
+ "minimum",
27665
+ "maximum",
27666
+ "exclusiveMinimum",
27667
+ "exclusiveMaximum",
27668
+ "multipleOf",
27669
+ "minItems",
27670
+ "maxItems",
27671
+ "uniqueItems",
27672
+ "minProperties",
27673
+ "maxProperties",
27674
+ "default",
27675
+ "examples",
27676
+ "readOnly",
27677
+ "writeOnly"
27678
+ ]);
27679
+ for (const key of Object.keys(value))
27680
+ if (!allowed.has(key))
27681
+ throw new Error(`Unsupported schema keyword ${path}.${key}`);
27682
+ const child = (schema3, key) => programSchemaType(schema3, `${path}.${key}`, depth + 1);
27683
+ const literal = (input) => {
27684
+ if (input !== null && !["string", "number", "boolean"].includes(typeof input))
27685
+ throw new Error(`Unsupported literal at ${path}`);
27686
+ return JSON.stringify(input);
27687
+ };
27688
+ if ("const" in value) return literal(value.const);
27689
+ if (Array.isArray(value.enum) && value.enum.length)
27690
+ return value.enum.map(literal).join(" | ");
27691
+ if (Array.isArray(value.anyOf) || Array.isArray(value.oneOf))
27692
+ return (value.anyOf ?? value.oneOf).map((schema3, i) => `(${child(schema3, String(i))})`).join(" | ") || "never";
27693
+ if (Array.isArray(value.type))
27694
+ return value.type.map((type) => child({ ...value, type }, String(type))).join(" | ");
27695
+ switch (value.type) {
27696
+ case "null":
27697
+ return "null";
27698
+ case "boolean":
27699
+ return "boolean";
27700
+ case "string":
27701
+ return "string";
27702
+ case "number":
27703
+ case "integer":
27704
+ return "number";
27705
+ case "array":
27706
+ return `Array<${child(value.items, "items")}>`;
27707
+ case "object": {
27708
+ const properties = value.properties ?? {};
27709
+ if (typeof properties !== "object" || !properties || Array.isArray(properties))
27710
+ throw new Error(`Invalid properties at ${path}`);
27711
+ const required = value.required ?? [];
27712
+ if (!Array.isArray(required) || required.some(
27713
+ (key) => typeof key !== "string" || !Object.prototype.hasOwnProperty.call(properties, key)
27714
+ ))
27715
+ throw new Error(`Unsupported required keys at ${path}`);
27716
+ const fields = Object.entries(properties).map(
27717
+ ([key, schema3]) => `${JSON.stringify(key)}${required.includes(key) ? "" : "?"}: ${child(schema3, key)};`
27718
+ );
27719
+ if (value.additionalProperties !== false) {
27720
+ if (value.additionalProperties !== void 0 && value.additionalProperties !== true)
27721
+ throw new Error(`Unsupported additionalProperties at ${path}`);
27722
+ fields.push("[key: string]: unknown;");
27723
+ }
27724
+ return `{ ${fields.join(" ")} }`;
27725
+ }
27726
+ default:
27727
+ throw new Error(`Schema needs a supported explicit type at ${path}`);
27728
+ }
27729
+ }
27730
+ function generateActionProgramTypes(definition, schemas) {
27731
+ const resolve = (ref2) => {
27732
+ const matches = schemas.filter(
27733
+ (entry) => sameRevisionRef(entry.definitionRevisionRef, ref2)
27734
+ );
27735
+ if (matches.length !== 1 || canonicalContentHash(matches[0].definition) !== ref2.contentHash)
27736
+ throw new Error(`Missing exact Schema ${ref2.id}`);
27737
+ return programSchemaType(matches[0].definition.document);
27738
+ };
27739
+ const formRefs = new Map(
27740
+ [
27741
+ definition.inputSchemaRevisionRef,
27742
+ definition.resultSchemaRevisionRef,
27743
+ ...definition.dependencies.flatMap((dep) => [
27744
+ dep.inputSchemaRevisionRef,
27745
+ dep.resultSchemaRevisionRef
27746
+ ])
27747
+ ].map((ref2) => [ref2.id, ref2])
27748
+ );
27749
+ for (const ref2 of [
27750
+ definition.inputSchemaRevisionRef,
27751
+ definition.resultSchemaRevisionRef,
27752
+ ...definition.dependencies.flatMap((dep) => [
27753
+ dep.inputSchemaRevisionRef,
27754
+ dep.resultSchemaRevisionRef
27755
+ ])
27756
+ ]) {
27757
+ if (!sameRevisionRef(formRefs.get(ref2.id), ref2))
27758
+ throw new Error("Ambiguous form Schema revision " + ref2.id);
27759
+ }
27760
+ const forms = "{" + [...formRefs].map(([id, ref2]) => JSON.stringify(id) + ": " + resolve(ref2) + ";").join(" ") + "}";
27761
+ const states = "{" + definition.stateAliases.map(
27762
+ (entry) => JSON.stringify(entry.alias) + ": " + resolve(entry.schemaRevisionRef) + ";"
27763
+ ).join(" ") + "}";
27764
+ const refresh = definition.refreshAliases.map((alias) => JSON.stringify(alias)).join(" | ") || "never";
27765
+ const capabilityMap = (kind) => `{
27766
+ ${definition.dependencies.filter((dep) => dep.kind === kind).map(
27767
+ (dep) => `${JSON.stringify(dep.revisionRef.id)}: {input: ${"Pick<" + resolve(dep.inputSchemaRevisionRef) + ", " + (dep.dynamicInputKeys.map((key) => JSON.stringify(key)).join(" | ") || "never") + ">"}; result: ${resolve(dep.resultSchemaRevisionRef)}};`
27768
+ ).join("\n")}
27769
+ }`;
27770
+ return `// Generated from exact program/schema revisions. Do not edit.
27771
+ import type { ActionProgramContext } from "@inf-monkeys-tech/monkeys";
27772
+ export type Input = ${resolve(definition.inputSchemaRevisionRef)};
27773
+ export type Result = ${resolve(definition.resultSchemaRevisionRef)};
27774
+ export type Queries = ${capabilityMap("query")};
27775
+ export type Commands = ${capabilityMap("command")};
27776
+ export type BaseContext = ActionProgramContext<Queries, Commands, ${forms}, ${states}, ${refresh}>;
27777
+ export type Context = Omit<BaseContext, "ui" | "state"> & {ui: Pick<BaseContext["ui"], ${definition.effects.filter((effect) => !effect.startsWith("state.")).map((effect) => JSON.stringify(effect)).join(" | ") || "never"}>; state: Pick<BaseContext["state"], ${definition.effects.filter((effect) => effect.startsWith("state.")).map((effect) => JSON.stringify(effect.slice(6))).join(" | ") || "never"}>};
27778
+ export type Program = (context: Context, input: Input) => Promise<Result>;
27779
+ `;
27780
+ }
27781
+ function compileProgramValueValidator(schema2, documents = []) {
27782
+ const ajv2 = new import__2.default({ strict: false, allErrors: false, coerceTypes: false, removeAdditional: false, useDefaults: false });
27783
+ const ids = /* @__PURE__ */ new Set();
27784
+ for (const document of documents) if (typeof document.$id === "string" && document.$id !== schema2.$id && !ids.has(document.$id)) {
27785
+ ajv2.addSchema(document);
27786
+ ids.add(document.$id);
27787
+ }
27788
+ return ajv2.compile(schema2);
27789
+ }
27146
27790
  export {
27791
+ ACTION_PROGRAM_ABI,
27147
27792
  AGENT_MODE_CAPABILITIES,
27148
27793
  AGENT_SESSION_CAPABILITY_EVIDENCE,
27149
27794
  AGENT_SESSION_COMMAND_POLICIES,
@@ -27151,6 +27796,10 @@ export {
27151
27796
  APPLICATION_HANDOFF_QUERY_PARAMETER,
27152
27797
  AccessPolicySchema,
27153
27798
  ActionBindingSchema,
27799
+ ActionProgramArtifactSchema,
27800
+ ActionProgramBudgetsSchema,
27801
+ ActionProgramDefinitionSchema,
27802
+ ActionProgramDependencySchema,
27154
27803
  ActionResultBindingEffectSchema,
27155
27804
  ActionResultBindingEffectSourceSchema,
27156
27805
  ActionResultClipboardEffectSchema,
@@ -27290,6 +27939,7 @@ export {
27290
27939
  DECLARATIVE_CONTROL_ONTOLOGY_DEFINITIONS,
27291
27940
  DECLARATIVE_CONTROL_SCHEMA_VERSION,
27292
27941
  DECLARATIVE_MIGRATION_ERROR_CODES,
27942
+ DEFAULT_ACTION_PROGRAM_BUDGETS,
27293
27943
  DEFAULT_AGENT_WORKBENCH_SIDEBAR_SECTIONS,
27294
27944
  DEFAULT_CONDUCTOR_OWNER_EMAIL,
27295
27945
  DataContinuityEnvelopeSchema,
@@ -27516,6 +28166,7 @@ export {
27516
28166
  PageNavigationProjectionSchema,
27517
28167
  PageNodeSchema,
27518
28168
  PageOperatorSchema,
28169
+ PageProgramActionSchema,
27519
28170
  PagePropertyBindingSchema,
27520
28171
  PageReleaseSchema,
27521
28172
  PageRendererProjectionSchema,
@@ -27544,6 +28195,7 @@ export {
27544
28195
  PermissionBundleSchema,
27545
28196
  PermissionDefinitionSchema,
27546
28197
  PersistedOntologyBindingSchema,
28198
+ PrepareActionProgramRequestSchema,
27547
28199
  ProductAccessDeclarationSchema,
27548
28200
  ProductBodySchema,
27549
28201
  ProductContextSchema,
@@ -27551,6 +28203,7 @@ export {
27551
28203
  ProductDeclarativeAuthoringCatalogSchema,
27552
28204
  ProductDeclarativeCapabilityRegistrationSchema,
27553
28205
  ProductSurfaceSchema,
28206
+ ProgramBindingSchema,
27554
28207
  ProjectionSpecSchema,
27555
28208
  PublicationPlanOperationSchema,
27556
28209
  PublicationPlanSchema,
@@ -27571,6 +28224,7 @@ export {
27571
28224
  RadarScoreProjectionSchema,
27572
28225
  RadarSelectionSchema,
27573
28226
  RadarWritebackRecordSchema,
28227
+ ReadActionProgramRequestSchema,
27574
28228
  ReadablePageRuntimeBundleSchema,
27575
28229
  RecordEditorDraftOperationSchema,
27576
28230
  RecordEditorDraftSchema,
@@ -27579,6 +28233,7 @@ export {
27579
28233
  RecordEditorSubmissionSnapshotSchema,
27580
28234
  RecordEditorValidationDetailsSchema,
27581
28235
  ReferenceVisibilitySchema,
28236
+ RegisterActionProgramRequestSchema,
27582
28237
  RegisteredServiceDomainQueryDataSourceSchema,
27583
28238
  ReleaseDependencyRoleSchema,
27584
28239
  ReleaseDependencySchema,
@@ -27609,6 +28264,11 @@ export {
27609
28264
  RoutePathTemplateSchema,
27610
28265
  RouteSpaceParameterSchema,
27611
28266
  RouteSpaceSchema,
28267
+ RuntimeProgramCallRequestSchema,
28268
+ RuntimeProgramCallResultSchema,
28269
+ RuntimeProgramDownloadResultSchema,
28270
+ RuntimeProgramLoadRequestSchema,
28271
+ RuntimeProgramLoadResultSchema,
27612
28272
  SavedRadarQuerySchema,
27613
28273
  SchemaDefinitionSchema,
27614
28274
  ScopedIdentityRefSchema,
@@ -27708,6 +28368,7 @@ export {
27708
28368
  assertDeclarativeCapabilityContract,
27709
28369
  assertMonkeysThemeTokensComplete,
27710
28370
  assertPageValueBudget,
28371
+ assertProgramRegistration,
27711
28372
  assertThemeTokensDocumentStructure,
27712
28373
  assertViewProviderContract,
27713
28374
  buildApplicationHandoffUrl,
@@ -27735,6 +28396,7 @@ export {
27735
28396
  compileProductAccessDeclaration,
27736
28397
  compileProductDeclaration,
27737
28398
  compileProductRuntimeCatalog,
28399
+ compileProgramValueValidator,
27738
28400
  compileRenderTree,
27739
28401
  compileRouteClaims,
27740
28402
  compileTargetRenderModelValidator,
@@ -27768,6 +28430,7 @@ export {
27768
28430
  evaluatePageExpression,
27769
28431
  extractOpenApiCapabilityManifests,
27770
28432
  findUnsupportedAgentSessionCapabilities,
28433
+ generateActionProgramTypes,
27771
28434
  getAgentModeCapabilities,
27772
28435
  getAgentSessionCommandPolicy,
27773
28436
  getAgentSessionRuntimeCapabilities,
@@ -27789,6 +28452,8 @@ export {
27789
28452
  parseExactProductDeclarativeCapabilityRegistration,
27790
28453
  parseWorkflowColumnBinding,
27791
28454
  permissionAlternativePolicyAllows,
28455
+ programDependencies,
28456
+ programSchemaType,
27792
28457
  projectAgentSessionEvents,
27793
28458
  projectCurrentNavigationPages,
27794
28459
  projectNavigationCompatibility,