@ai-matrx/alchemy 0.8.60 → 0.9.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +2 -0
  3. package/dist/actions.cjs +1 -1
  4. package/dist/actions.cjs.map +1 -1
  5. package/dist/actions.d.cts +300 -3
  6. package/dist/actions.d.ts +300 -3
  7. package/dist/actions.js +1 -1
  8. package/dist/actions.js.map +1 -1
  9. package/dist/checks.cjs +1 -1
  10. package/dist/checks.cjs.map +1 -1
  11. package/dist/checks.d.cts +22 -1
  12. package/dist/checks.d.ts +22 -1
  13. package/dist/checks.js +2 -2
  14. package/dist/checks.js.map +1 -1
  15. package/dist/core.d.cts +141 -26
  16. package/dist/core.d.ts +141 -26
  17. package/dist/declare.cjs +1 -1
  18. package/dist/declare.cjs.map +1 -1
  19. package/dist/declare.d.cts +12 -4
  20. package/dist/declare.d.ts +12 -4
  21. package/dist/declare.js +1 -1
  22. package/dist/declare.js.map +1 -1
  23. package/dist/index.d.cts +141 -26
  24. package/dist/index.d.ts +141 -26
  25. package/dist/menu.cjs +1 -1
  26. package/dist/menu.cjs.map +1 -1
  27. package/dist/menu.d.cts +109 -2
  28. package/dist/menu.d.ts +109 -2
  29. package/dist/menu.js +1 -1
  30. package/dist/menu.js.map +1 -1
  31. package/dist/operate-server.d.cts +6 -0
  32. package/dist/operate-server.d.ts +6 -0
  33. package/dist/operate.d.cts +141 -26
  34. package/dist/operate.d.ts +141 -26
  35. package/dist/ports.cjs.map +1 -1
  36. package/dist/ports.d.cts +116 -1
  37. package/dist/ports.d.ts +116 -1
  38. package/dist/react-bar.cjs +1 -1
  39. package/dist/react-bar.cjs.map +1 -1
  40. package/dist/react-bar.d.cts +4 -2
  41. package/dist/react-bar.d.ts +4 -2
  42. package/dist/react-bar.js +1 -1
  43. package/dist/react-bar.js.map +1 -1
  44. package/dist/react-host.d.cts +109 -2
  45. package/dist/react-host.d.ts +109 -2
  46. package/dist/react-menu.cjs +1 -1
  47. package/dist/react-menu.cjs.map +1 -1
  48. package/dist/react-menu.d.cts +4 -2
  49. package/dist/react-menu.d.ts +4 -2
  50. package/dist/react-menu.js +1 -1
  51. package/dist/react-menu.js.map +1 -1
  52. package/dist/react-overflow.cjs +1 -1
  53. package/dist/react-overflow.cjs.map +1 -1
  54. package/dist/react-overflow.d.cts +109 -2
  55. package/dist/react-overflow.d.ts +109 -2
  56. package/dist/react-overflow.js +1 -1
  57. package/dist/react-overflow.js.map +1 -1
  58. package/dist/react-palette.cjs +1 -1
  59. package/dist/react-palette.cjs.map +1 -1
  60. package/dist/react-palette.d.cts +4 -2
  61. package/dist/react-palette.d.ts +4 -2
  62. package/dist/react-palette.js +1 -1
  63. package/dist/react-palette.js.map +1 -1
  64. package/dist/react-selection.cjs +1 -1
  65. package/dist/react-selection.cjs.map +1 -1
  66. package/dist/react-selection.d.cts +4 -2
  67. package/dist/react-selection.d.ts +4 -2
  68. package/dist/react-selection.js +1 -1
  69. package/dist/react-selection.js.map +1 -1
  70. package/dist/react-sheet.cjs +1 -1
  71. package/dist/react-sheet.cjs.map +1 -1
  72. package/dist/react-sheet.d.cts +4 -2
  73. package/dist/react-sheet.d.ts +4 -2
  74. package/dist/react-sheet.js +1 -1
  75. package/dist/react-sheet.js.map +1 -1
  76. package/package.json +1 -1
@@ -250,6 +250,162 @@ interface ClickTarget {
250
250
  host?: unknown;
251
251
  }
252
252
 
253
+ /**
254
+ * Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
255
+ *
256
+ * An Action is one thing a surface can have done to it, by a person, an agent,
257
+ * an applet or an automation: a write target, a client tool, a Kind Action or a
258
+ * row in `ui.ui_surface_action`. All of them project onto `ActionDeclaration`
259
+ * (`./declarations.ts`) and run through ONE runner (`./surface-run.ts`). There is
260
+ * never a second registry: `name` IS the alchemy action id, and `category`
261
+ * defaults to "applet" in alchemy's closed `ActionCategory` union.
262
+ *
263
+ * Types only — no runtime code, no React, no `@ai-matrx/agents`. `/ports`
264
+ * imports from here, so this file imports nothing but local types.
265
+ */
266
+
267
+ /** Who started a run. */
268
+ type ActionCaller = "person" | "agent" | "applet" | "automation";
269
+ /** Where a run goes: the page's own handler, an aidream server action, a mandate, or a route. */
270
+ type ActionRuns = "page" | "server" | "mandate" | "navigate";
271
+ /** Who may run it without a click: "manual" = only a person; "ask" = proposed first; "auto" = runs. */
272
+ type ActionPolicy = "ask" | "auto" | "manual";
273
+ /** A registered kind slug (`KindRef`, content-ir) or an inline JSON Schema. */
274
+ type ActionInput = string | {
275
+ jsonSchema: object;
276
+ };
277
+ /** Who authored the row (`ui.ui_surface*.declared_by`). Code sync touches only "code". */
278
+ type ActionDeclaredBy = "code" | "database";
279
+ /** The write-target modes (WriteMode), kept losslessly. CONTRACTS §6 names three; "stream" is the superset. */
280
+ type ActionWriteMode = "ui" | "draft" | "entity" | "stream";
281
+ /** Where the Action came from — superset field so a projection loses nothing. */
282
+ interface ActionOrigin {
283
+ source: "write-target" | "client-tool" | "surface-action";
284
+ surfaceName?: string;
285
+ surfaceId?: string;
286
+ /** The source row's id, when it came from a row. */
287
+ id?: string;
288
+ declaredBy?: ActionDeclaredBy;
289
+ /** `ui.ui_surface_action.code_ref`: the code item a database Action names. */
290
+ codeRef?: string;
291
+ }
292
+ interface ActionDeclaration {
293
+ /** The Action's unique id within its chain (alchemy's `Action.id`). */
294
+ name: string;
295
+ /** Defaults to "applet". A value of alchemy's `ActionCategory` union. */
296
+ category?: string;
297
+ label: string;
298
+ description: string;
299
+ input?: ActionInput;
300
+ /** KindRef of what the run returns. */
301
+ output?: string;
302
+ runs: ActionRuns;
303
+ /** Server action name | mandate alias | route. `{param}` placeholders are filled from the input. */
304
+ target?: string;
305
+ triggeredBy: ActionCaller[];
306
+ policy: ActionPolicy;
307
+ updatesValue?: string;
308
+ mode?: ActionWriteMode;
309
+ patchable?: boolean;
310
+ approvalComparison?: string;
311
+ streamOps?: string[];
312
+ /** CONTRACTS §6 types it `string`; a write target's is a boolean flag. */
313
+ destination?: string | boolean;
314
+ groupKey?: string;
315
+ itemType?: string;
316
+ /** The write target's own apply policy, kept when it differs from `policy` ("queued" → policy "ask"). */
317
+ applyPolicy?: "manual" | "ask" | "auto" | "queued";
318
+ valueType?: string;
319
+ valueKind?: string;
320
+ sortOrder?: number;
321
+ origin?: ActionOrigin;
322
+ }
323
+ /** JSON only: what a lister (an agent, the menu, an applet) sees. */
324
+ interface ActionInfo {
325
+ name: string;
326
+ category: string;
327
+ label: string;
328
+ description: string;
329
+ runs: ActionRuns;
330
+ policy: ActionPolicy;
331
+ triggeredBy: ActionCaller[];
332
+ input?: ActionInput;
333
+ output?: string;
334
+ /** The surface that declared it (a child's override names the child). */
335
+ declaredOn: string;
336
+ target?: string;
337
+ updatesValue?: string;
338
+ itemType?: string;
339
+ }
340
+ interface ActionContext {
341
+ runId: string;
342
+ by: ActionCaller;
343
+ viewerId: string | null;
344
+ surfaceName?: string;
345
+ policy?: ActionPolicy;
346
+ }
347
+ /** The system's own sentence, never thrown into a UI. Superset of RecordsError (CONTRACTS §0 `AppletError`). */
348
+ interface ActionError {
349
+ code: string;
350
+ message: string;
351
+ retryable: boolean;
352
+ diagnostic?: string;
353
+ }
354
+ /** CONTRACTS §0 `Result<T>`. */
355
+ type ActionResult<T = unknown> = {
356
+ ok: true;
357
+ data: T;
358
+ } | {
359
+ ok: false;
360
+ error: ActionError;
361
+ };
362
+ /** `POST /actions/run` (aidream) — the request. */
363
+ interface ServerActionRunRequest {
364
+ name: string;
365
+ input: Json$1;
366
+ by: ActionCaller;
367
+ surface_name?: string;
368
+ policy?: ActionPolicy;
369
+ }
370
+ /** `POST /actions/run` (aidream) — the response. */
371
+ interface ServerActionRunResponse {
372
+ status: "applied" | "proposed" | "refused";
373
+ message: string;
374
+ receipts: Json$1[];
375
+ proposal?: Json$1;
376
+ }
377
+ /** A mandate run request: by alias (an Action's `target`) or by key. */
378
+ type MandateRunRequest = ({
379
+ alias: string;
380
+ key?: never;
381
+ } | {
382
+ key: string;
383
+ alias?: never;
384
+ }) & {
385
+ variables: Record<string, Json$1>;
386
+ userInput?: string;
387
+ by: ActionCaller;
388
+ policy: ActionPolicy;
389
+ };
390
+ /**
391
+ * CONTRACTS §6 `SurfacePort` — the surface runtime as the frame sees it. Types
392
+ * only here; the in-page host is AP-0's.
393
+ */
394
+ interface SurfacePort {
395
+ /** Joins the runtime chain. */
396
+ mount(name: string, parent: string | null): Promise<ActionResult<{
397
+ mountId: string;
398
+ }>>;
399
+ unmount(mountId: string): Promise<void>;
400
+ getValue(name: string): Promise<unknown>;
401
+ setValue(name: string, v: unknown): Promise<void>;
402
+ /** This mount's own Actions plus inherited ones. */
403
+ listActions(): Promise<ActionInfo[]>;
404
+ runAction(name: string, input: unknown, by: ActionCaller): Promise<ActionResult<unknown>>;
405
+ /** A "page" Action is routed to the frame as `{ action, input, runId }`; the frame answers here. */
406
+ completeAction(runId: string, result: ActionResult<unknown>): Promise<void>;
407
+ }
408
+
253
409
  /**
254
410
  * `@ai-matrx/alchemy/ports` — the host ports (Matrx Alchemy CONTRACT §2.2).
255
411
  *
@@ -298,6 +454,12 @@ interface ClickTarget {
298
454
  * to an overlay carrying the session as data)
299
455
  * transferKnobs absent → no organization default recipe; a person's own
300
456
  * default (persistence) or the package's Full applies
457
+ * serverActions absent → `runs: "server"` Actions refuse with "not available here"
458
+ * mandates absent → `runs: "mandate"` Actions refuse the same way
459
+ * pageActions absent → `runs: "page"` Actions refuse the same way
460
+ * approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
461
+ * ("needs a person's approval"); a person's own click is the approval
462
+ * (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
301
463
  *
302
464
  * Types only: this entry has no runtime code.
303
465
  */
@@ -443,6 +605,36 @@ interface AlchemyHostPorts {
443
605
  window?: WindowPort;
444
606
  /** Organization default recipes, resolved by the host's Feature Knob ladder (platform → organization). */
445
607
  transferKnobs?: TransferKnobsPort;
608
+ /** aidream `POST /actions/run`: a registered server action by name, as the caller, under the apply-policy cascade. */
609
+ serverActions?: ServerActionPort;
610
+ /** Runs a mandate by alias or key (the host binds `@ai-matrx/agents`; alchemy never imports it). */
611
+ mandates?: MandatePort;
612
+ /** The page's own handlers for `runs: "page"` Actions (in an applet frame: routed as `{ action, input, runId }`). */
613
+ pageActions?: PageActionPort;
614
+ /** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
615
+ approvals?: ApprovalPort;
616
+ }
617
+ interface ServerActionPort {
618
+ run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
619
+ }
620
+ interface MandatePort {
621
+ /** Resolves with the run's result (a kind envelope or JSON); rejects with the system's sentence. */
622
+ run(request: MandateRunRequest): Promise<unknown>;
623
+ }
624
+ interface ApprovalRequest {
625
+ action: string;
626
+ label: string;
627
+ description: string;
628
+ input: Json;
629
+ by: "agent" | "applet" | "automation";
630
+ surfaceName: string;
631
+ }
632
+ interface ApprovalPort {
633
+ /** Resolves true when the person approves; false when they decline or dismiss. */
634
+ ask(request: ApprovalRequest): Promise<boolean>;
635
+ }
636
+ interface PageActionPort {
637
+ dispatch(name: string, input: unknown, context: ActionContext): Promise<ActionResult<unknown>>;
446
638
  }
447
639
  /**
448
640
  * Why a port and not `OverlayHostPort`: an overlay's `data` is `Json`, and a live preparation
@@ -596,8 +788,10 @@ type Eligibility = {
596
788
  status: "unavailable";
597
789
  sentence: string;
598
790
  };
599
- /** rich-document's ActionCategory, unchanged, plus the three the context menu groups by. */
600
- type ActionCategory = "feedback" | "copy" | "export" | "save" | "edit" | "share" | "creator" | "app" | "listen" | "study" | "ask" | "ai" | "admin" | "clipboard" | "history" | "surface-info";
791
+ /** rich-document's ActionCategory, unchanged, plus the three the context menu groups by, plus "applet" (surface Actions). */
792
+ type ActionCategory = "feedback" | "copy" | "export" | "save" | "edit" | "share" | "creator" | "app" | "listen" | "study" | "ask" | "ai" | "admin" | "clipboard" | "history" | "surface-info"
793
+ /** Surface Actions (Applets CONTRACTS §6): the default category of an `ActionDeclaration`. */
794
+ | "applet";
601
795
  declare const ACTION_CATEGORIES: readonly ActionCategory[];
602
796
  /**
603
797
  * An optional named section inside the action's group (a grid's cell / row /
@@ -871,4 +1065,107 @@ type RunResult = {
871
1065
  };
872
1066
  declare function runAction(action: Action, target: ClickTarget, options: RunActionOptions): Promise<RunResult>;
873
1067
 
874
- export { ACTION_CATEGORIES, type Action, type ActionCategory, type ActionProvider, type ActionRegistry, type ActionRegistryOptions, type ActionRunContext, type ActionSection, type ClickTarget, type ClickTargetInput, DuplicateActionError, DuplicateProviderError, type Eligibility, type ProjectedReads, type ProjectionSource, type ReadOmission, type ResolveRestriction, type ResolvedAction, type RunActionOptions, type RunResult, UNIVERSAL_VERBS, type UniversalVerb, alwaysEligible, computeEligibility, createActionRegistry, createClickTarget, createProjectedReads, projectValues, runAction, staticActionProvider };
1068
+ /** Default `category` of an Action that names none. */
1069
+ declare const APPLET_CATEGORY = "applet";
1070
+ /** The DB default of `ui.ui_surface_action.triggered_by`, used where a source carries no list. */
1071
+ declare const DEFAULT_TRIGGERED_BY: readonly ActionCaller[];
1072
+ declare const ACTION_CALLERS: readonly ActionCaller[];
1073
+ declare const ACTION_RUNS: readonly ActionRuns[];
1074
+ declare const ACTION_POLICIES: readonly ActionPolicy[];
1075
+ /** A `ui.ui_surface_client_tool` row (live columns that carry meaning). */
1076
+ interface ClientToolRow {
1077
+ id?: string;
1078
+ surface_name: string;
1079
+ name: string;
1080
+ label: string;
1081
+ description: string;
1082
+ input_schema: Json$1;
1083
+ /** Live values: "ui" (applied directly) | "draft" (proposed for review). */
1084
+ mode: "ui" | "draft";
1085
+ declared_by?: ActionDeclaredBy;
1086
+ }
1087
+ /** A `ui.ui_surface_action` row. */
1088
+ interface SurfaceActionRow {
1089
+ id?: string;
1090
+ surface_id: string;
1091
+ surface_name: string;
1092
+ /** '' = the screen itself. */
1093
+ item_type: string;
1094
+ name: string;
1095
+ category: string;
1096
+ label: string;
1097
+ description: string;
1098
+ input: ActionInput | null;
1099
+ output: string | null;
1100
+ runs: ActionRuns;
1101
+ target: string | null;
1102
+ triggered_by: ActionCaller[];
1103
+ policy: ActionPolicy;
1104
+ updates_value: string | null;
1105
+ code_ref: string | null;
1106
+ declared_by: ActionDeclaredBy;
1107
+ sort_order: number;
1108
+ }
1109
+ /** A declared write target → an Action that runs on the page. */
1110
+ declare function writeTargetToAction(target: WriteTarget): ActionDeclaration;
1111
+ /** A client tool row → an Action an agent runs on the page ("draft" tools are proposed first). */
1112
+ declare function clientToolToAction(row: ClientToolRow): ActionDeclaration;
1113
+ /** A `ui.ui_surface_action` row → its Action. */
1114
+ declare function surfaceActionRowToAction(row: SurfaceActionRow): ActionDeclaration;
1115
+ /** JSON-only view of an Action as declared on `declaredOn`. */
1116
+ declare function toActionInfo(declaration: ActionDeclaration, declaredOn: string): ActionInfo;
1117
+ interface ActionChainLink {
1118
+ surfaceName: string;
1119
+ actions: readonly ActionDeclaration[];
1120
+ }
1121
+ /**
1122
+ * The Actions a mount sees: its own plus every ancestor's, a child winning by
1123
+ * name. `chain` runs MOST GENERAL FIRST (root parent … the mounted surface),
1124
+ * as `DeclarationRegistry` resolves inheritance. Guards are loud, like the
1125
+ * declaration registry's: a surface twice in the chain is a cycle, more
1126
+ * ancestors than `maxDepth` throws, and one surface naming an Action twice throws.
1127
+ */
1128
+ declare function resolveActionChain(chain: readonly ActionChainLink[], options?: {
1129
+ maxDepth?: number;
1130
+ }): ActionInfo[];
1131
+
1132
+ /**
1133
+ * THE ONE RUNNER for surface Actions (Applets CONTRACTS §6). Every caller — a
1134
+ * person's click, an agent, an applet, an automation — runs an Action through
1135
+ * here, so policy and caller rules live once.
1136
+ *
1137
+ * Policy "ask": a person's own click is the approval. Started by an agent, applet or automation,
1138
+ * a "server" run carries the policy to aidream (which answers with a proposal); every other run
1139
+ * asks the person through `ports.approvals` first, and is refused by name without that port.
1140
+ *
1141
+ * Dispatch by `runs`:
1142
+ * "server" → `ports.serverActions.run({ name: target, input, by, surface_name, policy })`
1143
+ * "mandate" → `ports.mandates.run({ alias: target, variables, by, policy })`
1144
+ * "navigate" → `ports.overlay.navigate(target)` with `{param}` filled from the input
1145
+ * "page" → `ports.pageActions.dispatch(name, input, context)`
1146
+ * A port the host did not bind means that capability is ABSENT: the run is
1147
+ * refused with a sentence, never stubbed (ports rule).
1148
+ *
1149
+ * Never throws: every outcome is a `Result` whose error message is the
1150
+ * system's own sentence.
1151
+ */
1152
+
1153
+ type SurfaceActionPorts = Pick<AlchemyHostPorts, "diagnostics" | "serverActions" | "mandates" | "pageActions" | "overlay" | "approvals">;
1154
+ interface RunSurfaceActionOptions {
1155
+ runId?: string;
1156
+ viewerId?: string | null;
1157
+ signal?: AbortSignal;
1158
+ }
1159
+ /** Fill `{param}` placeholders from the input object. Returns the names it could not fill. */
1160
+ declare function fillActionTarget(template: string, input: unknown): {
1161
+ value: string;
1162
+ missing: string[];
1163
+ };
1164
+ /**
1165
+ * Who may run this Action, under its policy. Returns the refusal, or null.
1166
+ * "manual" = a person only. `triggeredBy` lists every caller allowed at all.
1167
+ */
1168
+ declare function refuseCaller(info: Pick<ActionInfo, "name" | "label" | "policy" | "triggeredBy">, by: ActionCaller): ActionError | null;
1169
+ declare function runSurfaceAction(info: ActionInfo, input: unknown, by: ActionCaller, ports: SurfaceActionPorts, options?: RunSurfaceActionOptions): Promise<ActionResult<unknown>>;
1170
+
1171
+ export { ACTION_CALLERS, ACTION_CATEGORIES, ACTION_POLICIES, ACTION_RUNS, APPLET_CATEGORY, type Action, type ActionCaller, type ActionCategory, type ActionChainLink, type ActionContext, type ActionDeclaration, type ActionDeclaredBy, type ActionError, type ActionInfo, type ActionInput, type ActionOrigin, type ActionPolicy, type ActionProvider, type ActionRegistry, type ActionRegistryOptions, type ActionResult, type ActionRunContext, type ActionRuns, type ActionSection, type ActionWriteMode, type ClickTarget, type ClickTargetInput, type ClientToolRow, DEFAULT_TRIGGERED_BY, DuplicateActionError, DuplicateProviderError, type Eligibility, type MandateRunRequest, type ProjectedReads, type ProjectionSource, type ReadOmission, type ResolveRestriction, type ResolvedAction, type RunActionOptions, type RunResult, type RunSurfaceActionOptions, type ServerActionRunRequest, type ServerActionRunResponse, type SurfaceActionPorts, type SurfaceActionRow, type SurfacePort, UNIVERSAL_VERBS, type UniversalVerb, alwaysEligible, clientToolToAction, computeEligibility, createActionRegistry, createClickTarget, createProjectedReads, fillActionTarget, projectValues, refuseCaller, resolveActionChain, runAction, runSurfaceAction, staticActionProvider, surfaceActionRowToAction, toActionInfo, writeTargetToAction };
package/dist/actions.d.ts CHANGED
@@ -250,6 +250,162 @@ interface ClickTarget {
250
250
  host?: unknown;
251
251
  }
252
252
 
253
+ /**
254
+ * Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
255
+ *
256
+ * An Action is one thing a surface can have done to it, by a person, an agent,
257
+ * an applet or an automation: a write target, a client tool, a Kind Action or a
258
+ * row in `ui.ui_surface_action`. All of them project onto `ActionDeclaration`
259
+ * (`./declarations.ts`) and run through ONE runner (`./surface-run.ts`). There is
260
+ * never a second registry: `name` IS the alchemy action id, and `category`
261
+ * defaults to "applet" in alchemy's closed `ActionCategory` union.
262
+ *
263
+ * Types only — no runtime code, no React, no `@ai-matrx/agents`. `/ports`
264
+ * imports from here, so this file imports nothing but local types.
265
+ */
266
+
267
+ /** Who started a run. */
268
+ type ActionCaller = "person" | "agent" | "applet" | "automation";
269
+ /** Where a run goes: the page's own handler, an aidream server action, a mandate, or a route. */
270
+ type ActionRuns = "page" | "server" | "mandate" | "navigate";
271
+ /** Who may run it without a click: "manual" = only a person; "ask" = proposed first; "auto" = runs. */
272
+ type ActionPolicy = "ask" | "auto" | "manual";
273
+ /** A registered kind slug (`KindRef`, content-ir) or an inline JSON Schema. */
274
+ type ActionInput = string | {
275
+ jsonSchema: object;
276
+ };
277
+ /** Who authored the row (`ui.ui_surface*.declared_by`). Code sync touches only "code". */
278
+ type ActionDeclaredBy = "code" | "database";
279
+ /** The write-target modes (WriteMode), kept losslessly. CONTRACTS §6 names three; "stream" is the superset. */
280
+ type ActionWriteMode = "ui" | "draft" | "entity" | "stream";
281
+ /** Where the Action came from — superset field so a projection loses nothing. */
282
+ interface ActionOrigin {
283
+ source: "write-target" | "client-tool" | "surface-action";
284
+ surfaceName?: string;
285
+ surfaceId?: string;
286
+ /** The source row's id, when it came from a row. */
287
+ id?: string;
288
+ declaredBy?: ActionDeclaredBy;
289
+ /** `ui.ui_surface_action.code_ref`: the code item a database Action names. */
290
+ codeRef?: string;
291
+ }
292
+ interface ActionDeclaration {
293
+ /** The Action's unique id within its chain (alchemy's `Action.id`). */
294
+ name: string;
295
+ /** Defaults to "applet". A value of alchemy's `ActionCategory` union. */
296
+ category?: string;
297
+ label: string;
298
+ description: string;
299
+ input?: ActionInput;
300
+ /** KindRef of what the run returns. */
301
+ output?: string;
302
+ runs: ActionRuns;
303
+ /** Server action name | mandate alias | route. `{param}` placeholders are filled from the input. */
304
+ target?: string;
305
+ triggeredBy: ActionCaller[];
306
+ policy: ActionPolicy;
307
+ updatesValue?: string;
308
+ mode?: ActionWriteMode;
309
+ patchable?: boolean;
310
+ approvalComparison?: string;
311
+ streamOps?: string[];
312
+ /** CONTRACTS §6 types it `string`; a write target's is a boolean flag. */
313
+ destination?: string | boolean;
314
+ groupKey?: string;
315
+ itemType?: string;
316
+ /** The write target's own apply policy, kept when it differs from `policy` ("queued" → policy "ask"). */
317
+ applyPolicy?: "manual" | "ask" | "auto" | "queued";
318
+ valueType?: string;
319
+ valueKind?: string;
320
+ sortOrder?: number;
321
+ origin?: ActionOrigin;
322
+ }
323
+ /** JSON only: what a lister (an agent, the menu, an applet) sees. */
324
+ interface ActionInfo {
325
+ name: string;
326
+ category: string;
327
+ label: string;
328
+ description: string;
329
+ runs: ActionRuns;
330
+ policy: ActionPolicy;
331
+ triggeredBy: ActionCaller[];
332
+ input?: ActionInput;
333
+ output?: string;
334
+ /** The surface that declared it (a child's override names the child). */
335
+ declaredOn: string;
336
+ target?: string;
337
+ updatesValue?: string;
338
+ itemType?: string;
339
+ }
340
+ interface ActionContext {
341
+ runId: string;
342
+ by: ActionCaller;
343
+ viewerId: string | null;
344
+ surfaceName?: string;
345
+ policy?: ActionPolicy;
346
+ }
347
+ /** The system's own sentence, never thrown into a UI. Superset of RecordsError (CONTRACTS §0 `AppletError`). */
348
+ interface ActionError {
349
+ code: string;
350
+ message: string;
351
+ retryable: boolean;
352
+ diagnostic?: string;
353
+ }
354
+ /** CONTRACTS §0 `Result<T>`. */
355
+ type ActionResult<T = unknown> = {
356
+ ok: true;
357
+ data: T;
358
+ } | {
359
+ ok: false;
360
+ error: ActionError;
361
+ };
362
+ /** `POST /actions/run` (aidream) — the request. */
363
+ interface ServerActionRunRequest {
364
+ name: string;
365
+ input: Json$1;
366
+ by: ActionCaller;
367
+ surface_name?: string;
368
+ policy?: ActionPolicy;
369
+ }
370
+ /** `POST /actions/run` (aidream) — the response. */
371
+ interface ServerActionRunResponse {
372
+ status: "applied" | "proposed" | "refused";
373
+ message: string;
374
+ receipts: Json$1[];
375
+ proposal?: Json$1;
376
+ }
377
+ /** A mandate run request: by alias (an Action's `target`) or by key. */
378
+ type MandateRunRequest = ({
379
+ alias: string;
380
+ key?: never;
381
+ } | {
382
+ key: string;
383
+ alias?: never;
384
+ }) & {
385
+ variables: Record<string, Json$1>;
386
+ userInput?: string;
387
+ by: ActionCaller;
388
+ policy: ActionPolicy;
389
+ };
390
+ /**
391
+ * CONTRACTS §6 `SurfacePort` — the surface runtime as the frame sees it. Types
392
+ * only here; the in-page host is AP-0's.
393
+ */
394
+ interface SurfacePort {
395
+ /** Joins the runtime chain. */
396
+ mount(name: string, parent: string | null): Promise<ActionResult<{
397
+ mountId: string;
398
+ }>>;
399
+ unmount(mountId: string): Promise<void>;
400
+ getValue(name: string): Promise<unknown>;
401
+ setValue(name: string, v: unknown): Promise<void>;
402
+ /** This mount's own Actions plus inherited ones. */
403
+ listActions(): Promise<ActionInfo[]>;
404
+ runAction(name: string, input: unknown, by: ActionCaller): Promise<ActionResult<unknown>>;
405
+ /** A "page" Action is routed to the frame as `{ action, input, runId }`; the frame answers here. */
406
+ completeAction(runId: string, result: ActionResult<unknown>): Promise<void>;
407
+ }
408
+
253
409
  /**
254
410
  * `@ai-matrx/alchemy/ports` — the host ports (Matrx Alchemy CONTRACT §2.2).
255
411
  *
@@ -298,6 +454,12 @@ interface ClickTarget {
298
454
  * to an overlay carrying the session as data)
299
455
  * transferKnobs absent → no organization default recipe; a person's own
300
456
  * default (persistence) or the package's Full applies
457
+ * serverActions absent → `runs: "server"` Actions refuse with "not available here"
458
+ * mandates absent → `runs: "mandate"` Actions refuse the same way
459
+ * pageActions absent → `runs: "page"` Actions refuse the same way
460
+ * approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
461
+ * ("needs a person's approval"); a person's own click is the approval
462
+ * (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
301
463
  *
302
464
  * Types only: this entry has no runtime code.
303
465
  */
@@ -443,6 +605,36 @@ interface AlchemyHostPorts {
443
605
  window?: WindowPort;
444
606
  /** Organization default recipes, resolved by the host's Feature Knob ladder (platform → organization). */
445
607
  transferKnobs?: TransferKnobsPort;
608
+ /** aidream `POST /actions/run`: a registered server action by name, as the caller, under the apply-policy cascade. */
609
+ serverActions?: ServerActionPort;
610
+ /** Runs a mandate by alias or key (the host binds `@ai-matrx/agents`; alchemy never imports it). */
611
+ mandates?: MandatePort;
612
+ /** The page's own handlers for `runs: "page"` Actions (in an applet frame: routed as `{ action, input, runId }`). */
613
+ pageActions?: PageActionPort;
614
+ /** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
615
+ approvals?: ApprovalPort;
616
+ }
617
+ interface ServerActionPort {
618
+ run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
619
+ }
620
+ interface MandatePort {
621
+ /** Resolves with the run's result (a kind envelope or JSON); rejects with the system's sentence. */
622
+ run(request: MandateRunRequest): Promise<unknown>;
623
+ }
624
+ interface ApprovalRequest {
625
+ action: string;
626
+ label: string;
627
+ description: string;
628
+ input: Json;
629
+ by: "agent" | "applet" | "automation";
630
+ surfaceName: string;
631
+ }
632
+ interface ApprovalPort {
633
+ /** Resolves true when the person approves; false when they decline or dismiss. */
634
+ ask(request: ApprovalRequest): Promise<boolean>;
635
+ }
636
+ interface PageActionPort {
637
+ dispatch(name: string, input: unknown, context: ActionContext): Promise<ActionResult<unknown>>;
446
638
  }
447
639
  /**
448
640
  * Why a port and not `OverlayHostPort`: an overlay's `data` is `Json`, and a live preparation
@@ -596,8 +788,10 @@ type Eligibility = {
596
788
  status: "unavailable";
597
789
  sentence: string;
598
790
  };
599
- /** rich-document's ActionCategory, unchanged, plus the three the context menu groups by. */
600
- type ActionCategory = "feedback" | "copy" | "export" | "save" | "edit" | "share" | "creator" | "app" | "listen" | "study" | "ask" | "ai" | "admin" | "clipboard" | "history" | "surface-info";
791
+ /** rich-document's ActionCategory, unchanged, plus the three the context menu groups by, plus "applet" (surface Actions). */
792
+ type ActionCategory = "feedback" | "copy" | "export" | "save" | "edit" | "share" | "creator" | "app" | "listen" | "study" | "ask" | "ai" | "admin" | "clipboard" | "history" | "surface-info"
793
+ /** Surface Actions (Applets CONTRACTS §6): the default category of an `ActionDeclaration`. */
794
+ | "applet";
601
795
  declare const ACTION_CATEGORIES: readonly ActionCategory[];
602
796
  /**
603
797
  * An optional named section inside the action's group (a grid's cell / row /
@@ -871,4 +1065,107 @@ type RunResult = {
871
1065
  };
872
1066
  declare function runAction(action: Action, target: ClickTarget, options: RunActionOptions): Promise<RunResult>;
873
1067
 
874
- export { ACTION_CATEGORIES, type Action, type ActionCategory, type ActionProvider, type ActionRegistry, type ActionRegistryOptions, type ActionRunContext, type ActionSection, type ClickTarget, type ClickTargetInput, DuplicateActionError, DuplicateProviderError, type Eligibility, type ProjectedReads, type ProjectionSource, type ReadOmission, type ResolveRestriction, type ResolvedAction, type RunActionOptions, type RunResult, UNIVERSAL_VERBS, type UniversalVerb, alwaysEligible, computeEligibility, createActionRegistry, createClickTarget, createProjectedReads, projectValues, runAction, staticActionProvider };
1068
+ /** Default `category` of an Action that names none. */
1069
+ declare const APPLET_CATEGORY = "applet";
1070
+ /** The DB default of `ui.ui_surface_action.triggered_by`, used where a source carries no list. */
1071
+ declare const DEFAULT_TRIGGERED_BY: readonly ActionCaller[];
1072
+ declare const ACTION_CALLERS: readonly ActionCaller[];
1073
+ declare const ACTION_RUNS: readonly ActionRuns[];
1074
+ declare const ACTION_POLICIES: readonly ActionPolicy[];
1075
+ /** A `ui.ui_surface_client_tool` row (live columns that carry meaning). */
1076
+ interface ClientToolRow {
1077
+ id?: string;
1078
+ surface_name: string;
1079
+ name: string;
1080
+ label: string;
1081
+ description: string;
1082
+ input_schema: Json$1;
1083
+ /** Live values: "ui" (applied directly) | "draft" (proposed for review). */
1084
+ mode: "ui" | "draft";
1085
+ declared_by?: ActionDeclaredBy;
1086
+ }
1087
+ /** A `ui.ui_surface_action` row. */
1088
+ interface SurfaceActionRow {
1089
+ id?: string;
1090
+ surface_id: string;
1091
+ surface_name: string;
1092
+ /** '' = the screen itself. */
1093
+ item_type: string;
1094
+ name: string;
1095
+ category: string;
1096
+ label: string;
1097
+ description: string;
1098
+ input: ActionInput | null;
1099
+ output: string | null;
1100
+ runs: ActionRuns;
1101
+ target: string | null;
1102
+ triggered_by: ActionCaller[];
1103
+ policy: ActionPolicy;
1104
+ updates_value: string | null;
1105
+ code_ref: string | null;
1106
+ declared_by: ActionDeclaredBy;
1107
+ sort_order: number;
1108
+ }
1109
+ /** A declared write target → an Action that runs on the page. */
1110
+ declare function writeTargetToAction(target: WriteTarget): ActionDeclaration;
1111
+ /** A client tool row → an Action an agent runs on the page ("draft" tools are proposed first). */
1112
+ declare function clientToolToAction(row: ClientToolRow): ActionDeclaration;
1113
+ /** A `ui.ui_surface_action` row → its Action. */
1114
+ declare function surfaceActionRowToAction(row: SurfaceActionRow): ActionDeclaration;
1115
+ /** JSON-only view of an Action as declared on `declaredOn`. */
1116
+ declare function toActionInfo(declaration: ActionDeclaration, declaredOn: string): ActionInfo;
1117
+ interface ActionChainLink {
1118
+ surfaceName: string;
1119
+ actions: readonly ActionDeclaration[];
1120
+ }
1121
+ /**
1122
+ * The Actions a mount sees: its own plus every ancestor's, a child winning by
1123
+ * name. `chain` runs MOST GENERAL FIRST (root parent … the mounted surface),
1124
+ * as `DeclarationRegistry` resolves inheritance. Guards are loud, like the
1125
+ * declaration registry's: a surface twice in the chain is a cycle, more
1126
+ * ancestors than `maxDepth` throws, and one surface naming an Action twice throws.
1127
+ */
1128
+ declare function resolveActionChain(chain: readonly ActionChainLink[], options?: {
1129
+ maxDepth?: number;
1130
+ }): ActionInfo[];
1131
+
1132
+ /**
1133
+ * THE ONE RUNNER for surface Actions (Applets CONTRACTS §6). Every caller — a
1134
+ * person's click, an agent, an applet, an automation — runs an Action through
1135
+ * here, so policy and caller rules live once.
1136
+ *
1137
+ * Policy "ask": a person's own click is the approval. Started by an agent, applet or automation,
1138
+ * a "server" run carries the policy to aidream (which answers with a proposal); every other run
1139
+ * asks the person through `ports.approvals` first, and is refused by name without that port.
1140
+ *
1141
+ * Dispatch by `runs`:
1142
+ * "server" → `ports.serverActions.run({ name: target, input, by, surface_name, policy })`
1143
+ * "mandate" → `ports.mandates.run({ alias: target, variables, by, policy })`
1144
+ * "navigate" → `ports.overlay.navigate(target)` with `{param}` filled from the input
1145
+ * "page" → `ports.pageActions.dispatch(name, input, context)`
1146
+ * A port the host did not bind means that capability is ABSENT: the run is
1147
+ * refused with a sentence, never stubbed (ports rule).
1148
+ *
1149
+ * Never throws: every outcome is a `Result` whose error message is the
1150
+ * system's own sentence.
1151
+ */
1152
+
1153
+ type SurfaceActionPorts = Pick<AlchemyHostPorts, "diagnostics" | "serverActions" | "mandates" | "pageActions" | "overlay" | "approvals">;
1154
+ interface RunSurfaceActionOptions {
1155
+ runId?: string;
1156
+ viewerId?: string | null;
1157
+ signal?: AbortSignal;
1158
+ }
1159
+ /** Fill `{param}` placeholders from the input object. Returns the names it could not fill. */
1160
+ declare function fillActionTarget(template: string, input: unknown): {
1161
+ value: string;
1162
+ missing: string[];
1163
+ };
1164
+ /**
1165
+ * Who may run this Action, under its policy. Returns the refusal, or null.
1166
+ * "manual" = a person only. `triggeredBy` lists every caller allowed at all.
1167
+ */
1168
+ declare function refuseCaller(info: Pick<ActionInfo, "name" | "label" | "policy" | "triggeredBy">, by: ActionCaller): ActionError | null;
1169
+ declare function runSurfaceAction(info: ActionInfo, input: unknown, by: ActionCaller, ports: SurfaceActionPorts, options?: RunSurfaceActionOptions): Promise<ActionResult<unknown>>;
1170
+
1171
+ export { ACTION_CALLERS, ACTION_CATEGORIES, ACTION_POLICIES, ACTION_RUNS, APPLET_CATEGORY, type Action, type ActionCaller, type ActionCategory, type ActionChainLink, type ActionContext, type ActionDeclaration, type ActionDeclaredBy, type ActionError, type ActionInfo, type ActionInput, type ActionOrigin, type ActionPolicy, type ActionProvider, type ActionRegistry, type ActionRegistryOptions, type ActionResult, type ActionRunContext, type ActionRuns, type ActionSection, type ActionWriteMode, type ClickTarget, type ClickTargetInput, type ClientToolRow, DEFAULT_TRIGGERED_BY, DuplicateActionError, DuplicateProviderError, type Eligibility, type MandateRunRequest, type ProjectedReads, type ProjectionSource, type ReadOmission, type ResolveRestriction, type ResolvedAction, type RunActionOptions, type RunResult, type RunSurfaceActionOptions, type ServerActionRunRequest, type ServerActionRunResponse, type SurfaceActionPorts, type SurfaceActionRow, type SurfacePort, UNIVERSAL_VERBS, type UniversalVerb, alwaysEligible, clientToolToAction, computeEligibility, createActionRegistry, createClickTarget, createProjectedReads, fillActionTarget, projectValues, refuseCaller, resolveActionChain, runAction, runSurfaceAction, staticActionProvider, surfaceActionRowToAction, toActionInfo, writeTargetToAction };