@ai-matrx/alchemy 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +2 -0
- package/dist/actions.cjs +1 -1
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.d.cts +192 -6
- package/dist/actions.d.ts +192 -6
- package/dist/actions.js +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +159 -16
- package/dist/core.d.ts +159 -16
- package/dist/core.js +2 -2
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -16
- package/dist/index.d.ts +159 -16
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/menu.d.cts +169 -3
- package/dist/menu.d.ts +169 -3
- package/dist/operate-server.d.cts +5 -1
- package/dist/operate-server.d.ts +5 -1
- package/dist/operate.cjs +1 -1
- package/dist/operate.cjs.map +1 -1
- package/dist/operate.d.cts +159 -16
- package/dist/operate.d.ts +159 -16
- package/dist/operate.js +2 -2
- package/dist/operate.js.map +1 -1
- package/dist/ports.cjs.map +1 -1
- package/dist/ports.d.cts +170 -4
- package/dist/ports.d.ts +170 -4
- package/dist/react-host.d.cts +169 -3
- package/dist/react-host.d.ts +169 -3
- package/dist/react-overflow.d.cts +169 -3
- package/dist/react-overflow.d.ts +169 -3
- package/dist/surface.cjs +2 -0
- package/dist/surface.cjs.map +1 -0
- package/dist/surface.d.cts +1045 -0
- package/dist/surface.d.ts +1045 -0
- package/dist/surface.js +2 -0
- package/dist/surface.js.map +1 -0
- package/package.json +13 -3
package/dist/actions.d.cts
CHANGED
|
@@ -250,6 +250,148 @@ interface ClickTarget {
|
|
|
250
250
|
host?: unknown;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Operate — the format and delivery contract (Matrx Alchemy CONTRACT §2.3, ALC-16).
|
|
255
|
+
*
|
|
256
|
+
* A format is an ADAPTER: `supports` is synchronous and loads nothing; `load` dynamically
|
|
257
|
+
* imports the engine the first time the format is chosen (print for rich-html/html/pdf/docx/
|
|
258
|
+
* epub, SheetJS for xlsx). Delivery accepts only a SEALED artifact, so the bytes previewed are
|
|
259
|
+
* the bytes copied, downloaded or sent.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
/** A reference to a declared write target (resolved by the one write door, ALC-17). */
|
|
263
|
+
interface WriteTargetRef {
|
|
264
|
+
surfaceName?: string;
|
|
265
|
+
target: string;
|
|
266
|
+
item?: {
|
|
267
|
+
itemType: string;
|
|
268
|
+
identity: Record<string, string>;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Every write returns one (CONTRACT §2.3; the door is `createWriteDoor`, ALC-17). An applied
|
|
273
|
+
* receipt may carry a `warning` with its `fix` (rule 10: a person's kind mismatch warns, never refuses).
|
|
274
|
+
* A refusal's `reason` is a `WriteRefusalReason` (`./door`).
|
|
275
|
+
*/
|
|
276
|
+
type Receipt = {
|
|
277
|
+
status: "applied";
|
|
278
|
+
to: WriteTargetRef;
|
|
279
|
+
sentence: string;
|
|
280
|
+
warning?: string;
|
|
281
|
+
fix?: string;
|
|
282
|
+
} | {
|
|
283
|
+
status: "queued";
|
|
284
|
+
to: WriteTargetRef;
|
|
285
|
+
sentence: string;
|
|
286
|
+
remedy: string;
|
|
287
|
+
} | {
|
|
288
|
+
status: "refused";
|
|
289
|
+
to: WriteTargetRef;
|
|
290
|
+
reason: string;
|
|
291
|
+
sentence: string;
|
|
292
|
+
remedy: string;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* THE ONE WRITE DOOR (Matrx Alchemy ALC-17; Applets CONTRACTS §6 "receipts through the one write door").
|
|
297
|
+
*
|
|
298
|
+
* Every write — a person's edit, a menu row, a destination send, an agent, an applet, an automation,
|
|
299
|
+
* an Action projected from a write target — lands through `door.write`. The door:
|
|
300
|
+
*
|
|
301
|
+
* 1. resolves the DECLARED write target (the surface's own, then its ancestors'); an undeclared
|
|
302
|
+
* target is refused by name;
|
|
303
|
+
* 2. enforces the mode: `stream` takes ops from the target's `streamOps`; ops on any other target
|
|
304
|
+
* need `patchable` (+ `updatesValue`); a value on a `stream` target is refused;
|
|
305
|
+
* 3. checks the kind (rule 10): a person's mismatch WARNS (the receipt is still applied, with a
|
|
306
|
+
* `warning` and a `fix`); an agent's, applet's or automation's malformed write is REFUSED;
|
|
307
|
+
* 4. applies the policy: manual → a person only; ask → a person's own act is the approval, anyone
|
|
308
|
+
* else asks through `approvals`; queued → filed through `review`; auto → applies;
|
|
309
|
+
* 5. applies through the handler: the mounted page's LIVE handler wins over the HEADLESS one;
|
|
310
|
+
* neither → refused `unapplicable` ("open <surface> to apply it");
|
|
311
|
+
* 6. turns stale / missing record / broken protected span into "cannot apply" with a one-click
|
|
312
|
+
* remedy (rule 11).
|
|
313
|
+
*
|
|
314
|
+
* Every outcome is a `Receipt` carrying the system's own sentence. `write` never throws.
|
|
315
|
+
*
|
|
316
|
+
* Who counts as a person: `person`, `menu` and `destination` (a destination send is a person's own
|
|
317
|
+
* click on "Send to …"). `agent`, `applet` and `automation` are not.
|
|
318
|
+
*
|
|
319
|
+
* Open-risk ruling — stream ops into an entity target: an entity write is ONE atomic save. Ops reach
|
|
320
|
+
* an entity target only when it is declared `patchable` (the ops are handed to the handler in one
|
|
321
|
+
* call and commit as one save); a non-patchable entity target refuses ops with the remedy "stream
|
|
322
|
+
* into the editor, then save". Op-by-op persistence into a record does not exist.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
/** Who is writing. `menu` and `destination` are a person's own act. */
|
|
326
|
+
type WriteCaller = "person" | "agent" | "applet" | "automation" | "destination" | "menu";
|
|
327
|
+
/** One text op for a `stream` (or `patchable`) target — the WidgetHandle op set. */
|
|
328
|
+
interface WriteOp {
|
|
329
|
+
op: StreamOp;
|
|
330
|
+
/** The text the op inserts or replaces with. */
|
|
331
|
+
text?: string;
|
|
332
|
+
/** What `replace` / `insert_before` / `insert_after` / `patch` anchor on. */
|
|
333
|
+
find?: string;
|
|
334
|
+
}
|
|
335
|
+
interface WriteRequest {
|
|
336
|
+
surfaceName: string;
|
|
337
|
+
/** A write target name; `"<itemType>.<name>"` names an item's target. */
|
|
338
|
+
target: string;
|
|
339
|
+
itemType?: string;
|
|
340
|
+
/** Which item, by its declared identity values. Required for an item target. */
|
|
341
|
+
itemIdentity?: Record<string, string>;
|
|
342
|
+
/** A whole value. Exactly one of `value` / `ops`. */
|
|
343
|
+
value?: unknown;
|
|
344
|
+
/** Text ops (stream / patchable targets). */
|
|
345
|
+
ops?: readonly WriteOp[];
|
|
346
|
+
by: WriteCaller;
|
|
347
|
+
runId?: string;
|
|
348
|
+
}
|
|
349
|
+
/** What a handler receives: the request plus the declared target it resolved to. */
|
|
350
|
+
interface WriteApplyRequest {
|
|
351
|
+
surfaceName: string;
|
|
352
|
+
/** The surface that declares the target (an ancestor when inherited). */
|
|
353
|
+
declaredOn: string;
|
|
354
|
+
target: WriteTarget;
|
|
355
|
+
item?: {
|
|
356
|
+
itemType: string;
|
|
357
|
+
identity: Record<string, string>;
|
|
358
|
+
};
|
|
359
|
+
value?: unknown;
|
|
360
|
+
ops?: readonly WriteOp[];
|
|
361
|
+
by: WriteCaller;
|
|
362
|
+
runId?: string;
|
|
363
|
+
}
|
|
364
|
+
/** Rule 11: the three "cannot apply" signals. */
|
|
365
|
+
type CannotApply = "stale" | "missing-record" | "broken-span";
|
|
366
|
+
/**
|
|
367
|
+
* A handler applies the write. Return nothing (or `{ status: "applied" }`) when it landed, or a
|
|
368
|
+
* `cannotApply` signal; THROWING an error whose `code` is a `CannotApply` signal means the same.
|
|
369
|
+
*/
|
|
370
|
+
type WriteHandlerResult = void | {
|
|
371
|
+
status: "applied";
|
|
372
|
+
sentence?: string;
|
|
373
|
+
} | {
|
|
374
|
+
status: "cannot-apply";
|
|
375
|
+
cannotApply: CannotApply;
|
|
376
|
+
sentence?: string;
|
|
377
|
+
remedy?: string;
|
|
378
|
+
};
|
|
379
|
+
type WriteHandler = (request: WriteApplyRequest, signal: AbortSignal) => WriteHandlerResult | Promise<WriteHandlerResult>;
|
|
380
|
+
/** Files a `queued` write for an organization's review. */
|
|
381
|
+
interface WriteReviewPort {
|
|
382
|
+
file(request: WriteApplyRequest): Promise<{
|
|
383
|
+
sentence?: string;
|
|
384
|
+
remedy?: string;
|
|
385
|
+
} | void>;
|
|
386
|
+
}
|
|
387
|
+
interface WriteDoor {
|
|
388
|
+
write(request: WriteRequest, signal?: AbortSignal): Promise<Receipt>;
|
|
389
|
+
/** A feature's write handler that works with no page mounted. Refuses a second one for the same target. */
|
|
390
|
+
registerHeadless(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
391
|
+
/** A mounted page's handler; wins over the headless one while registered. Returns unregister. */
|
|
392
|
+
registerLive(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
393
|
+
}
|
|
394
|
+
|
|
253
395
|
/**
|
|
254
396
|
* Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
|
|
255
397
|
*
|
|
@@ -288,6 +430,8 @@ interface ActionOrigin {
|
|
|
288
430
|
declaredBy?: ActionDeclaredBy;
|
|
289
431
|
/** `ui.ui_surface_action.code_ref`: the code item a database Action names. */
|
|
290
432
|
codeRef?: string;
|
|
433
|
+
/** The source row's organization (an organization extension applies only to its members). */
|
|
434
|
+
organizationId?: string;
|
|
291
435
|
}
|
|
292
436
|
interface ActionDeclaration {
|
|
293
437
|
/** The Action's unique id within its chain (alchemy's `Action.id`). */
|
|
@@ -336,6 +480,8 @@ interface ActionInfo {
|
|
|
336
480
|
target?: string;
|
|
337
481
|
updatesValue?: string;
|
|
338
482
|
itemType?: string;
|
|
483
|
+
/** Where it came from. "write-target" Actions go through the write door when one is bound (ALC-17). */
|
|
484
|
+
source?: ActionOrigin["source"];
|
|
339
485
|
}
|
|
340
486
|
interface ActionContext {
|
|
341
487
|
runId: string;
|
|
@@ -350,6 +496,8 @@ interface ActionError {
|
|
|
350
496
|
message: string;
|
|
351
497
|
retryable: boolean;
|
|
352
498
|
diagnostic?: string;
|
|
499
|
+
/** Superset: the one-click remedy a write door refusal names. */
|
|
500
|
+
remedy?: string;
|
|
353
501
|
}
|
|
354
502
|
/** CONTRACTS §0 `Result<T>`. */
|
|
355
503
|
type ActionResult<T = unknown> = {
|
|
@@ -387,6 +535,17 @@ type MandateRunRequest = ({
|
|
|
387
535
|
by: ActionCaller;
|
|
388
536
|
policy: ActionPolicy;
|
|
389
537
|
};
|
|
538
|
+
/**
|
|
539
|
+
* CONTRACTS §0/§3 `RunRef` — the serializable identity of a started mandate run. A mandate
|
|
540
|
+
* Action answers with THIS, not the run's result: the result arrives later on the event stream
|
|
541
|
+
* `run:<requestId>` (or `IntelligencePort.result(ref)`). Same fields as `@ai-matrx/agents`'s
|
|
542
|
+
* `RunRef`, declared here because alchemy sits below agents and never imports it.
|
|
543
|
+
*/
|
|
544
|
+
interface MandateRunRef {
|
|
545
|
+
requestId: string;
|
|
546
|
+
conversationId: string;
|
|
547
|
+
mandateKey: string;
|
|
548
|
+
}
|
|
390
549
|
/**
|
|
391
550
|
* CONTRACTS §6 `SurfacePort` — the surface runtime as the frame sees it. Types
|
|
392
551
|
* only here; the in-page host is AP-0's.
|
|
@@ -424,7 +583,7 @@ interface SurfacePort {
|
|
|
424
583
|
* PP-01a `window` (host-rendered windows for a live preparation session)
|
|
425
584
|
* PP-13a `transferKnobs` (organization default recipes)
|
|
426
585
|
*
|
|
427
|
-
*
|
|
586
|
+
* ALC-17 `door` (the one write door), `review` (queued writes)
|
|
428
587
|
*
|
|
429
588
|
* ── Absent-port semantics ───────────────────────────────────────────────────
|
|
430
589
|
*
|
|
@@ -460,6 +619,10 @@ interface SurfacePort {
|
|
|
460
619
|
* approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
|
|
461
620
|
* ("needs a person's approval"); a person's own click is the approval
|
|
462
621
|
* (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
|
|
622
|
+
* door absent → write-target Actions dispatch to `pageActions` as before, and
|
|
623
|
+
* `Delivery.send` is refused with a remedy; bound → every such write goes
|
|
624
|
+
* through it and returns its receipt
|
|
625
|
+
* review absent → a write to a `queued` target is refused ("review isn't available here")
|
|
463
626
|
*
|
|
464
627
|
* Types only: this entry has no runtime code.
|
|
465
628
|
*/
|
|
@@ -613,13 +776,20 @@ interface AlchemyHostPorts {
|
|
|
613
776
|
pageActions?: PageActionPort;
|
|
614
777
|
/** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
|
|
615
778
|
approvals?: ApprovalPort;
|
|
779
|
+
/** `createWriteDoor(...)`: every write to a declared target lands here and returns a receipt. */
|
|
780
|
+
door?: WriteDoor;
|
|
781
|
+
/** Files a write to a `queued` target for an organization's review. */
|
|
782
|
+
review?: WriteReviewPort;
|
|
616
783
|
}
|
|
617
784
|
interface ServerActionPort {
|
|
618
785
|
run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
|
|
619
786
|
}
|
|
620
787
|
interface MandatePort {
|
|
621
|
-
/**
|
|
622
|
-
|
|
788
|
+
/**
|
|
789
|
+
* STARTS the run and resolves with its `RunRef` (CONTRACTS §3/§6) — never the run's result, which
|
|
790
|
+
* arrives later on `run:<requestId>` / `IntelligencePort.result(ref)`. Rejects with the system's sentence.
|
|
791
|
+
*/
|
|
792
|
+
run(request: MandateRunRequest): Promise<MandateRunRef>;
|
|
623
793
|
}
|
|
624
794
|
interface ApprovalRequest {
|
|
625
795
|
action: string;
|
|
@@ -1105,6 +1275,11 @@ interface SurfaceActionRow {
|
|
|
1105
1275
|
code_ref: string | null;
|
|
1106
1276
|
declared_by: ActionDeclaredBy;
|
|
1107
1277
|
sort_order: number;
|
|
1278
|
+
/**
|
|
1279
|
+
* The row's organization. A `declared_by='database'` row on a surface outside `applets/` is that
|
|
1280
|
+
* organization's EXTENSION and applies only to its members (`readSurfaceChain`, aidream `visible_actions`).
|
|
1281
|
+
*/
|
|
1282
|
+
organization_id?: string | null;
|
|
1108
1283
|
}
|
|
1109
1284
|
/** A declared write target → an Action that runs on the page. */
|
|
1110
1285
|
declare function writeTargetToAction(target: WriteTarget): ActionDeclaration;
|
|
@@ -1140,21 +1315,32 @@ declare function resolveActionChain(chain: readonly ActionChainLink[], options?:
|
|
|
1140
1315
|
*
|
|
1141
1316
|
* Dispatch by `runs`:
|
|
1142
1317
|
* "server" → `ports.serverActions.run({ name: target, input, by, surface_name, policy })`
|
|
1143
|
-
* "mandate" → `ports.mandates.run({ alias: target, variables, by, policy })`
|
|
1318
|
+
* "mandate" → `ports.mandates.run({ alias: target, variables, by, policy })` — answers with the
|
|
1319
|
+
* started run's `MandateRunRef`; the result streams later on `run:<requestId>`
|
|
1144
1320
|
* "navigate" → `ports.overlay.navigate(target)` with `{param}` filled from the input
|
|
1145
1321
|
* "page" → `ports.pageActions.dispatch(name, input, context)`
|
|
1146
1322
|
* A port the host did not bind means that capability is ABSENT: the run is
|
|
1147
1323
|
* refused with a sentence, never stubbed (ports rule).
|
|
1148
1324
|
*
|
|
1325
|
+
* Write targets (ALC-17): an Action projected from a declared write target (`source: "write-target"`)
|
|
1326
|
+
* goes through `ports.door.write` when a door is bound — the door applies the target's own policy
|
|
1327
|
+
* (manual / ask / queued / auto) and its receipt becomes the result (`applied` / `queued` → ok with
|
|
1328
|
+
* the receipt; refused → an error whose code is the refusal reason and whose `remedy` is the door's).
|
|
1329
|
+
* Without a door it dispatches to `pageActions` as before.
|
|
1330
|
+
*
|
|
1149
1331
|
* Never throws: every outcome is a `Result` whose error message is the
|
|
1150
1332
|
* system's own sentence.
|
|
1151
1333
|
*/
|
|
1152
1334
|
|
|
1153
|
-
type SurfaceActionPorts = Pick<AlchemyHostPorts, "diagnostics" | "serverActions" | "mandates" | "pageActions" | "overlay" | "approvals">;
|
|
1335
|
+
type SurfaceActionPorts = Pick<AlchemyHostPorts, "diagnostics" | "serverActions" | "mandates" | "pageActions" | "overlay" | "approvals" | "door">;
|
|
1154
1336
|
interface RunSurfaceActionOptions {
|
|
1155
1337
|
runId?: string;
|
|
1156
1338
|
viewerId?: string | null;
|
|
1157
1339
|
signal?: AbortSignal;
|
|
1340
|
+
/** Which item a write-target Action writes into (by its declared identity values). */
|
|
1341
|
+
itemIdentity?: Record<string, string>;
|
|
1342
|
+
/** Text edits for a stream or patchable write target, instead of the input as the whole value. */
|
|
1343
|
+
ops?: readonly WriteOp[];
|
|
1158
1344
|
}
|
|
1159
1345
|
/** Fill `{param}` placeholders from the input object. Returns the names it could not fill. */
|
|
1160
1346
|
declare function fillActionTarget(template: string, input: unknown): {
|
|
@@ -1168,4 +1354,4 @@ declare function fillActionTarget(template: string, input: unknown): {
|
|
|
1168
1354
|
declare function refuseCaller(info: Pick<ActionInfo, "name" | "label" | "policy" | "triggeredBy">, by: ActionCaller): ActionError | null;
|
|
1169
1355
|
declare function runSurfaceAction(info: ActionInfo, input: unknown, by: ActionCaller, ports: SurfaceActionPorts, options?: RunSurfaceActionOptions): Promise<ActionResult<unknown>>;
|
|
1170
1356
|
|
|
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 };
|
|
1357
|
+
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 MandateRunRef, 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,148 @@ interface ClickTarget {
|
|
|
250
250
|
host?: unknown;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Operate — the format and delivery contract (Matrx Alchemy CONTRACT §2.3, ALC-16).
|
|
255
|
+
*
|
|
256
|
+
* A format is an ADAPTER: `supports` is synchronous and loads nothing; `load` dynamically
|
|
257
|
+
* imports the engine the first time the format is chosen (print for rich-html/html/pdf/docx/
|
|
258
|
+
* epub, SheetJS for xlsx). Delivery accepts only a SEALED artifact, so the bytes previewed are
|
|
259
|
+
* the bytes copied, downloaded or sent.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
/** A reference to a declared write target (resolved by the one write door, ALC-17). */
|
|
263
|
+
interface WriteTargetRef {
|
|
264
|
+
surfaceName?: string;
|
|
265
|
+
target: string;
|
|
266
|
+
item?: {
|
|
267
|
+
itemType: string;
|
|
268
|
+
identity: Record<string, string>;
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Every write returns one (CONTRACT §2.3; the door is `createWriteDoor`, ALC-17). An applied
|
|
273
|
+
* receipt may carry a `warning` with its `fix` (rule 10: a person's kind mismatch warns, never refuses).
|
|
274
|
+
* A refusal's `reason` is a `WriteRefusalReason` (`./door`).
|
|
275
|
+
*/
|
|
276
|
+
type Receipt = {
|
|
277
|
+
status: "applied";
|
|
278
|
+
to: WriteTargetRef;
|
|
279
|
+
sentence: string;
|
|
280
|
+
warning?: string;
|
|
281
|
+
fix?: string;
|
|
282
|
+
} | {
|
|
283
|
+
status: "queued";
|
|
284
|
+
to: WriteTargetRef;
|
|
285
|
+
sentence: string;
|
|
286
|
+
remedy: string;
|
|
287
|
+
} | {
|
|
288
|
+
status: "refused";
|
|
289
|
+
to: WriteTargetRef;
|
|
290
|
+
reason: string;
|
|
291
|
+
sentence: string;
|
|
292
|
+
remedy: string;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* THE ONE WRITE DOOR (Matrx Alchemy ALC-17; Applets CONTRACTS §6 "receipts through the one write door").
|
|
297
|
+
*
|
|
298
|
+
* Every write — a person's edit, a menu row, a destination send, an agent, an applet, an automation,
|
|
299
|
+
* an Action projected from a write target — lands through `door.write`. The door:
|
|
300
|
+
*
|
|
301
|
+
* 1. resolves the DECLARED write target (the surface's own, then its ancestors'); an undeclared
|
|
302
|
+
* target is refused by name;
|
|
303
|
+
* 2. enforces the mode: `stream` takes ops from the target's `streamOps`; ops on any other target
|
|
304
|
+
* need `patchable` (+ `updatesValue`); a value on a `stream` target is refused;
|
|
305
|
+
* 3. checks the kind (rule 10): a person's mismatch WARNS (the receipt is still applied, with a
|
|
306
|
+
* `warning` and a `fix`); an agent's, applet's or automation's malformed write is REFUSED;
|
|
307
|
+
* 4. applies the policy: manual → a person only; ask → a person's own act is the approval, anyone
|
|
308
|
+
* else asks through `approvals`; queued → filed through `review`; auto → applies;
|
|
309
|
+
* 5. applies through the handler: the mounted page's LIVE handler wins over the HEADLESS one;
|
|
310
|
+
* neither → refused `unapplicable` ("open <surface> to apply it");
|
|
311
|
+
* 6. turns stale / missing record / broken protected span into "cannot apply" with a one-click
|
|
312
|
+
* remedy (rule 11).
|
|
313
|
+
*
|
|
314
|
+
* Every outcome is a `Receipt` carrying the system's own sentence. `write` never throws.
|
|
315
|
+
*
|
|
316
|
+
* Who counts as a person: `person`, `menu` and `destination` (a destination send is a person's own
|
|
317
|
+
* click on "Send to …"). `agent`, `applet` and `automation` are not.
|
|
318
|
+
*
|
|
319
|
+
* Open-risk ruling — stream ops into an entity target: an entity write is ONE atomic save. Ops reach
|
|
320
|
+
* an entity target only when it is declared `patchable` (the ops are handed to the handler in one
|
|
321
|
+
* call and commit as one save); a non-patchable entity target refuses ops with the remedy "stream
|
|
322
|
+
* into the editor, then save". Op-by-op persistence into a record does not exist.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
/** Who is writing. `menu` and `destination` are a person's own act. */
|
|
326
|
+
type WriteCaller = "person" | "agent" | "applet" | "automation" | "destination" | "menu";
|
|
327
|
+
/** One text op for a `stream` (or `patchable`) target — the WidgetHandle op set. */
|
|
328
|
+
interface WriteOp {
|
|
329
|
+
op: StreamOp;
|
|
330
|
+
/** The text the op inserts or replaces with. */
|
|
331
|
+
text?: string;
|
|
332
|
+
/** What `replace` / `insert_before` / `insert_after` / `patch` anchor on. */
|
|
333
|
+
find?: string;
|
|
334
|
+
}
|
|
335
|
+
interface WriteRequest {
|
|
336
|
+
surfaceName: string;
|
|
337
|
+
/** A write target name; `"<itemType>.<name>"` names an item's target. */
|
|
338
|
+
target: string;
|
|
339
|
+
itemType?: string;
|
|
340
|
+
/** Which item, by its declared identity values. Required for an item target. */
|
|
341
|
+
itemIdentity?: Record<string, string>;
|
|
342
|
+
/** A whole value. Exactly one of `value` / `ops`. */
|
|
343
|
+
value?: unknown;
|
|
344
|
+
/** Text ops (stream / patchable targets). */
|
|
345
|
+
ops?: readonly WriteOp[];
|
|
346
|
+
by: WriteCaller;
|
|
347
|
+
runId?: string;
|
|
348
|
+
}
|
|
349
|
+
/** What a handler receives: the request plus the declared target it resolved to. */
|
|
350
|
+
interface WriteApplyRequest {
|
|
351
|
+
surfaceName: string;
|
|
352
|
+
/** The surface that declares the target (an ancestor when inherited). */
|
|
353
|
+
declaredOn: string;
|
|
354
|
+
target: WriteTarget;
|
|
355
|
+
item?: {
|
|
356
|
+
itemType: string;
|
|
357
|
+
identity: Record<string, string>;
|
|
358
|
+
};
|
|
359
|
+
value?: unknown;
|
|
360
|
+
ops?: readonly WriteOp[];
|
|
361
|
+
by: WriteCaller;
|
|
362
|
+
runId?: string;
|
|
363
|
+
}
|
|
364
|
+
/** Rule 11: the three "cannot apply" signals. */
|
|
365
|
+
type CannotApply = "stale" | "missing-record" | "broken-span";
|
|
366
|
+
/**
|
|
367
|
+
* A handler applies the write. Return nothing (or `{ status: "applied" }`) when it landed, or a
|
|
368
|
+
* `cannotApply` signal; THROWING an error whose `code` is a `CannotApply` signal means the same.
|
|
369
|
+
*/
|
|
370
|
+
type WriteHandlerResult = void | {
|
|
371
|
+
status: "applied";
|
|
372
|
+
sentence?: string;
|
|
373
|
+
} | {
|
|
374
|
+
status: "cannot-apply";
|
|
375
|
+
cannotApply: CannotApply;
|
|
376
|
+
sentence?: string;
|
|
377
|
+
remedy?: string;
|
|
378
|
+
};
|
|
379
|
+
type WriteHandler = (request: WriteApplyRequest, signal: AbortSignal) => WriteHandlerResult | Promise<WriteHandlerResult>;
|
|
380
|
+
/** Files a `queued` write for an organization's review. */
|
|
381
|
+
interface WriteReviewPort {
|
|
382
|
+
file(request: WriteApplyRequest): Promise<{
|
|
383
|
+
sentence?: string;
|
|
384
|
+
remedy?: string;
|
|
385
|
+
} | void>;
|
|
386
|
+
}
|
|
387
|
+
interface WriteDoor {
|
|
388
|
+
write(request: WriteRequest, signal?: AbortSignal): Promise<Receipt>;
|
|
389
|
+
/** A feature's write handler that works with no page mounted. Refuses a second one for the same target. */
|
|
390
|
+
registerHeadless(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
391
|
+
/** A mounted page's handler; wins over the headless one while registered. Returns unregister. */
|
|
392
|
+
registerLive(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
393
|
+
}
|
|
394
|
+
|
|
253
395
|
/**
|
|
254
396
|
* Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
|
|
255
397
|
*
|
|
@@ -288,6 +430,8 @@ interface ActionOrigin {
|
|
|
288
430
|
declaredBy?: ActionDeclaredBy;
|
|
289
431
|
/** `ui.ui_surface_action.code_ref`: the code item a database Action names. */
|
|
290
432
|
codeRef?: string;
|
|
433
|
+
/** The source row's organization (an organization extension applies only to its members). */
|
|
434
|
+
organizationId?: string;
|
|
291
435
|
}
|
|
292
436
|
interface ActionDeclaration {
|
|
293
437
|
/** The Action's unique id within its chain (alchemy's `Action.id`). */
|
|
@@ -336,6 +480,8 @@ interface ActionInfo {
|
|
|
336
480
|
target?: string;
|
|
337
481
|
updatesValue?: string;
|
|
338
482
|
itemType?: string;
|
|
483
|
+
/** Where it came from. "write-target" Actions go through the write door when one is bound (ALC-17). */
|
|
484
|
+
source?: ActionOrigin["source"];
|
|
339
485
|
}
|
|
340
486
|
interface ActionContext {
|
|
341
487
|
runId: string;
|
|
@@ -350,6 +496,8 @@ interface ActionError {
|
|
|
350
496
|
message: string;
|
|
351
497
|
retryable: boolean;
|
|
352
498
|
diagnostic?: string;
|
|
499
|
+
/** Superset: the one-click remedy a write door refusal names. */
|
|
500
|
+
remedy?: string;
|
|
353
501
|
}
|
|
354
502
|
/** CONTRACTS §0 `Result<T>`. */
|
|
355
503
|
type ActionResult<T = unknown> = {
|
|
@@ -387,6 +535,17 @@ type MandateRunRequest = ({
|
|
|
387
535
|
by: ActionCaller;
|
|
388
536
|
policy: ActionPolicy;
|
|
389
537
|
};
|
|
538
|
+
/**
|
|
539
|
+
* CONTRACTS §0/§3 `RunRef` — the serializable identity of a started mandate run. A mandate
|
|
540
|
+
* Action answers with THIS, not the run's result: the result arrives later on the event stream
|
|
541
|
+
* `run:<requestId>` (or `IntelligencePort.result(ref)`). Same fields as `@ai-matrx/agents`'s
|
|
542
|
+
* `RunRef`, declared here because alchemy sits below agents and never imports it.
|
|
543
|
+
*/
|
|
544
|
+
interface MandateRunRef {
|
|
545
|
+
requestId: string;
|
|
546
|
+
conversationId: string;
|
|
547
|
+
mandateKey: string;
|
|
548
|
+
}
|
|
390
549
|
/**
|
|
391
550
|
* CONTRACTS §6 `SurfacePort` — the surface runtime as the frame sees it. Types
|
|
392
551
|
* only here; the in-page host is AP-0's.
|
|
@@ -424,7 +583,7 @@ interface SurfacePort {
|
|
|
424
583
|
* PP-01a `window` (host-rendered windows for a live preparation session)
|
|
425
584
|
* PP-13a `transferKnobs` (organization default recipes)
|
|
426
585
|
*
|
|
427
|
-
*
|
|
586
|
+
* ALC-17 `door` (the one write door), `review` (queued writes)
|
|
428
587
|
*
|
|
429
588
|
* ── Absent-port semantics ───────────────────────────────────────────────────
|
|
430
589
|
*
|
|
@@ -460,6 +619,10 @@ interface SurfacePort {
|
|
|
460
619
|
* approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
|
|
461
620
|
* ("needs a person's approval"); a person's own click is the approval
|
|
462
621
|
* (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
|
|
622
|
+
* door absent → write-target Actions dispatch to `pageActions` as before, and
|
|
623
|
+
* `Delivery.send` is refused with a remedy; bound → every such write goes
|
|
624
|
+
* through it and returns its receipt
|
|
625
|
+
* review absent → a write to a `queued` target is refused ("review isn't available here")
|
|
463
626
|
*
|
|
464
627
|
* Types only: this entry has no runtime code.
|
|
465
628
|
*/
|
|
@@ -613,13 +776,20 @@ interface AlchemyHostPorts {
|
|
|
613
776
|
pageActions?: PageActionPort;
|
|
614
777
|
/** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
|
|
615
778
|
approvals?: ApprovalPort;
|
|
779
|
+
/** `createWriteDoor(...)`: every write to a declared target lands here and returns a receipt. */
|
|
780
|
+
door?: WriteDoor;
|
|
781
|
+
/** Files a write to a `queued` target for an organization's review. */
|
|
782
|
+
review?: WriteReviewPort;
|
|
616
783
|
}
|
|
617
784
|
interface ServerActionPort {
|
|
618
785
|
run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
|
|
619
786
|
}
|
|
620
787
|
interface MandatePort {
|
|
621
|
-
/**
|
|
622
|
-
|
|
788
|
+
/**
|
|
789
|
+
* STARTS the run and resolves with its `RunRef` (CONTRACTS §3/§6) — never the run's result, which
|
|
790
|
+
* arrives later on `run:<requestId>` / `IntelligencePort.result(ref)`. Rejects with the system's sentence.
|
|
791
|
+
*/
|
|
792
|
+
run(request: MandateRunRequest): Promise<MandateRunRef>;
|
|
623
793
|
}
|
|
624
794
|
interface ApprovalRequest {
|
|
625
795
|
action: string;
|
|
@@ -1105,6 +1275,11 @@ interface SurfaceActionRow {
|
|
|
1105
1275
|
code_ref: string | null;
|
|
1106
1276
|
declared_by: ActionDeclaredBy;
|
|
1107
1277
|
sort_order: number;
|
|
1278
|
+
/**
|
|
1279
|
+
* The row's organization. A `declared_by='database'` row on a surface outside `applets/` is that
|
|
1280
|
+
* organization's EXTENSION and applies only to its members (`readSurfaceChain`, aidream `visible_actions`).
|
|
1281
|
+
*/
|
|
1282
|
+
organization_id?: string | null;
|
|
1108
1283
|
}
|
|
1109
1284
|
/** A declared write target → an Action that runs on the page. */
|
|
1110
1285
|
declare function writeTargetToAction(target: WriteTarget): ActionDeclaration;
|
|
@@ -1140,21 +1315,32 @@ declare function resolveActionChain(chain: readonly ActionChainLink[], options?:
|
|
|
1140
1315
|
*
|
|
1141
1316
|
* Dispatch by `runs`:
|
|
1142
1317
|
* "server" → `ports.serverActions.run({ name: target, input, by, surface_name, policy })`
|
|
1143
|
-
* "mandate" → `ports.mandates.run({ alias: target, variables, by, policy })`
|
|
1318
|
+
* "mandate" → `ports.mandates.run({ alias: target, variables, by, policy })` — answers with the
|
|
1319
|
+
* started run's `MandateRunRef`; the result streams later on `run:<requestId>`
|
|
1144
1320
|
* "navigate" → `ports.overlay.navigate(target)` with `{param}` filled from the input
|
|
1145
1321
|
* "page" → `ports.pageActions.dispatch(name, input, context)`
|
|
1146
1322
|
* A port the host did not bind means that capability is ABSENT: the run is
|
|
1147
1323
|
* refused with a sentence, never stubbed (ports rule).
|
|
1148
1324
|
*
|
|
1325
|
+
* Write targets (ALC-17): an Action projected from a declared write target (`source: "write-target"`)
|
|
1326
|
+
* goes through `ports.door.write` when a door is bound — the door applies the target's own policy
|
|
1327
|
+
* (manual / ask / queued / auto) and its receipt becomes the result (`applied` / `queued` → ok with
|
|
1328
|
+
* the receipt; refused → an error whose code is the refusal reason and whose `remedy` is the door's).
|
|
1329
|
+
* Without a door it dispatches to `pageActions` as before.
|
|
1330
|
+
*
|
|
1149
1331
|
* Never throws: every outcome is a `Result` whose error message is the
|
|
1150
1332
|
* system's own sentence.
|
|
1151
1333
|
*/
|
|
1152
1334
|
|
|
1153
|
-
type SurfaceActionPorts = Pick<AlchemyHostPorts, "diagnostics" | "serverActions" | "mandates" | "pageActions" | "overlay" | "approvals">;
|
|
1335
|
+
type SurfaceActionPorts = Pick<AlchemyHostPorts, "diagnostics" | "serverActions" | "mandates" | "pageActions" | "overlay" | "approvals" | "door">;
|
|
1154
1336
|
interface RunSurfaceActionOptions {
|
|
1155
1337
|
runId?: string;
|
|
1156
1338
|
viewerId?: string | null;
|
|
1157
1339
|
signal?: AbortSignal;
|
|
1340
|
+
/** Which item a write-target Action writes into (by its declared identity values). */
|
|
1341
|
+
itemIdentity?: Record<string, string>;
|
|
1342
|
+
/** Text edits for a stream or patchable write target, instead of the input as the whole value. */
|
|
1343
|
+
ops?: readonly WriteOp[];
|
|
1158
1344
|
}
|
|
1159
1345
|
/** Fill `{param}` placeholders from the input object. Returns the names it could not fill. */
|
|
1160
1346
|
declare function fillActionTarget(template: string, input: unknown): {
|
|
@@ -1168,4 +1354,4 @@ declare function fillActionTarget(template: string, input: unknown): {
|
|
|
1168
1354
|
declare function refuseCaller(info: Pick<ActionInfo, "name" | "label" | "policy" | "triggeredBy">, by: ActionCaller): ActionError | null;
|
|
1169
1355
|
declare function runSurfaceAction(info: ActionInfo, input: unknown, by: ActionCaller, ports: SurfaceActionPorts, options?: RunSurfaceActionOptions): Promise<ActionResult<unknown>>;
|
|
1170
1356
|
|
|
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 };
|
|
1357
|
+
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 MandateRunRef, 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 };
|