@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/core.d.cts
CHANGED
|
@@ -649,6 +649,125 @@ interface ClickTarget {
|
|
|
649
649
|
host?: unknown;
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
+
/**
|
|
653
|
+
* THE ONE WRITE DOOR (Matrx Alchemy ALC-17; Applets CONTRACTS §6 "receipts through the one write door").
|
|
654
|
+
*
|
|
655
|
+
* Every write — a person's edit, a menu row, a destination send, an agent, an applet, an automation,
|
|
656
|
+
* an Action projected from a write target — lands through `door.write`. The door:
|
|
657
|
+
*
|
|
658
|
+
* 1. resolves the DECLARED write target (the surface's own, then its ancestors'); an undeclared
|
|
659
|
+
* target is refused by name;
|
|
660
|
+
* 2. enforces the mode: `stream` takes ops from the target's `streamOps`; ops on any other target
|
|
661
|
+
* need `patchable` (+ `updatesValue`); a value on a `stream` target is refused;
|
|
662
|
+
* 3. checks the kind (rule 10): a person's mismatch WARNS (the receipt is still applied, with a
|
|
663
|
+
* `warning` and a `fix`); an agent's, applet's or automation's malformed write is REFUSED;
|
|
664
|
+
* 4. applies the policy: manual → a person only; ask → a person's own act is the approval, anyone
|
|
665
|
+
* else asks through `approvals`; queued → filed through `review`; auto → applies;
|
|
666
|
+
* 5. applies through the handler: the mounted page's LIVE handler wins over the HEADLESS one;
|
|
667
|
+
* neither → refused `unapplicable` ("open <surface> to apply it");
|
|
668
|
+
* 6. turns stale / missing record / broken protected span into "cannot apply" with a one-click
|
|
669
|
+
* remedy (rule 11).
|
|
670
|
+
*
|
|
671
|
+
* Every outcome is a `Receipt` carrying the system's own sentence. `write` never throws.
|
|
672
|
+
*
|
|
673
|
+
* Who counts as a person: `person`, `menu` and `destination` (a destination send is a person's own
|
|
674
|
+
* click on "Send to …"). `agent`, `applet` and `automation` are not.
|
|
675
|
+
*
|
|
676
|
+
* Open-risk ruling — stream ops into an entity target: an entity write is ONE atomic save. Ops reach
|
|
677
|
+
* an entity target only when it is declared `patchable` (the ops are handed to the handler in one
|
|
678
|
+
* call and commit as one save); a non-patchable entity target refuses ops with the remedy "stream
|
|
679
|
+
* into the editor, then save". Op-by-op persistence into a record does not exist.
|
|
680
|
+
*/
|
|
681
|
+
|
|
682
|
+
/** Who is writing. `menu` and `destination` are a person's own act. */
|
|
683
|
+
type WriteCaller = "person" | "agent" | "applet" | "automation" | "destination" | "menu";
|
|
684
|
+
/** One text op for a `stream` (or `patchable`) target — the WidgetHandle op set. */
|
|
685
|
+
interface WriteOp {
|
|
686
|
+
op: StreamOp;
|
|
687
|
+
/** The text the op inserts or replaces with. */
|
|
688
|
+
text?: string;
|
|
689
|
+
/** What `replace` / `insert_before` / `insert_after` / `patch` anchor on. */
|
|
690
|
+
find?: string;
|
|
691
|
+
}
|
|
692
|
+
interface WriteRequest {
|
|
693
|
+
surfaceName: string;
|
|
694
|
+
/** A write target name; `"<itemType>.<name>"` names an item's target. */
|
|
695
|
+
target: string;
|
|
696
|
+
itemType?: string;
|
|
697
|
+
/** Which item, by its declared identity values. Required for an item target. */
|
|
698
|
+
itemIdentity?: Record<string, string>;
|
|
699
|
+
/** A whole value. Exactly one of `value` / `ops`. */
|
|
700
|
+
value?: unknown;
|
|
701
|
+
/** Text ops (stream / patchable targets). */
|
|
702
|
+
ops?: readonly WriteOp[];
|
|
703
|
+
by: WriteCaller;
|
|
704
|
+
runId?: string;
|
|
705
|
+
}
|
|
706
|
+
/** What a handler receives: the request plus the declared target it resolved to. */
|
|
707
|
+
interface WriteApplyRequest {
|
|
708
|
+
surfaceName: string;
|
|
709
|
+
/** The surface that declares the target (an ancestor when inherited). */
|
|
710
|
+
declaredOn: string;
|
|
711
|
+
target: WriteTarget;
|
|
712
|
+
item?: {
|
|
713
|
+
itemType: string;
|
|
714
|
+
identity: Record<string, string>;
|
|
715
|
+
};
|
|
716
|
+
value?: unknown;
|
|
717
|
+
ops?: readonly WriteOp[];
|
|
718
|
+
by: WriteCaller;
|
|
719
|
+
runId?: string;
|
|
720
|
+
}
|
|
721
|
+
/** Rule 11: the three "cannot apply" signals. */
|
|
722
|
+
type CannotApply = "stale" | "missing-record" | "broken-span";
|
|
723
|
+
/**
|
|
724
|
+
* A handler applies the write. Return nothing (or `{ status: "applied" }`) when it landed, or a
|
|
725
|
+
* `cannotApply` signal; THROWING an error whose `code` is a `CannotApply` signal means the same.
|
|
726
|
+
*/
|
|
727
|
+
type WriteHandlerResult = void | {
|
|
728
|
+
status: "applied";
|
|
729
|
+
sentence?: string;
|
|
730
|
+
} | {
|
|
731
|
+
status: "cannot-apply";
|
|
732
|
+
cannotApply: CannotApply;
|
|
733
|
+
sentence?: string;
|
|
734
|
+
remedy?: string;
|
|
735
|
+
};
|
|
736
|
+
type WriteHandler = (request: WriteApplyRequest, signal: AbortSignal) => WriteHandlerResult | Promise<WriteHandlerResult>;
|
|
737
|
+
/** Files a `queued` write for an organization's review. */
|
|
738
|
+
interface WriteReviewPort {
|
|
739
|
+
file(request: WriteApplyRequest): Promise<{
|
|
740
|
+
sentence?: string;
|
|
741
|
+
remedy?: string;
|
|
742
|
+
} | void>;
|
|
743
|
+
}
|
|
744
|
+
/** Why a write was refused. */
|
|
745
|
+
type WriteRefusalReason = "undeclared" | "needs_item" | "malformed" | "declaration_broken" | "manual_only" | "needs_approval" | "declined" | "no_review" | "unapplicable" | "cannot_apply" | "cancelled" | "failed";
|
|
746
|
+
interface WriteDoor {
|
|
747
|
+
write(request: WriteRequest, signal?: AbortSignal): Promise<Receipt>;
|
|
748
|
+
/** A feature's write handler that works with no page mounted. Refuses a second one for the same target. */
|
|
749
|
+
registerHeadless(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
750
|
+
/** A mounted page's handler; wins over the headless one while registered. Returns unregister. */
|
|
751
|
+
registerLive(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
752
|
+
}
|
|
753
|
+
/** The declarations the door reads: a `DeclarationRegistry` satisfies it. */
|
|
754
|
+
interface WriteDoorDeclarations {
|
|
755
|
+
get(surfaceName: string): {
|
|
756
|
+
writeTargets?: readonly WriteTarget[];
|
|
757
|
+
itemTypes?: readonly ItemType[];
|
|
758
|
+
} | undefined;
|
|
759
|
+
/** Parent chain, root first (the registry's `ancestry`). Absent = no inheritance. */
|
|
760
|
+
ancestry?(surfaceName: string): string[];
|
|
761
|
+
}
|
|
762
|
+
type WriteDoorPorts = Pick<AlchemyHostPorts, "diagnostics" | "kinds" | "approvals" | "review">;
|
|
763
|
+
declare class DuplicateWriteHandlerError extends Error {
|
|
764
|
+
constructor(surfaceName: string, targetName: string);
|
|
765
|
+
}
|
|
766
|
+
declare function createWriteDoor(options: {
|
|
767
|
+
ports: WriteDoorPorts;
|
|
768
|
+
declarations: WriteDoorDeclarations;
|
|
769
|
+
}): WriteDoor;
|
|
770
|
+
|
|
652
771
|
/**
|
|
653
772
|
* Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
|
|
654
773
|
*
|
|
@@ -680,6 +799,8 @@ interface ActionError {
|
|
|
680
799
|
message: string;
|
|
681
800
|
retryable: boolean;
|
|
682
801
|
diagnostic?: string;
|
|
802
|
+
/** Superset: the one-click remedy a write door refusal names. */
|
|
803
|
+
remedy?: string;
|
|
683
804
|
}
|
|
684
805
|
/** CONTRACTS §0 `Result<T>`. */
|
|
685
806
|
type ActionResult<T = unknown> = {
|
|
@@ -717,6 +838,17 @@ type MandateRunRequest = ({
|
|
|
717
838
|
by: ActionCaller;
|
|
718
839
|
policy: ActionPolicy;
|
|
719
840
|
};
|
|
841
|
+
/**
|
|
842
|
+
* CONTRACTS §0/§3 `RunRef` — the serializable identity of a started mandate run. A mandate
|
|
843
|
+
* Action answers with THIS, not the run's result: the result arrives later on the event stream
|
|
844
|
+
* `run:<requestId>` (or `IntelligencePort.result(ref)`). Same fields as `@ai-matrx/agents`'s
|
|
845
|
+
* `RunRef`, declared here because alchemy sits below agents and never imports it.
|
|
846
|
+
*/
|
|
847
|
+
interface MandateRunRef {
|
|
848
|
+
requestId: string;
|
|
849
|
+
conversationId: string;
|
|
850
|
+
mandateKey: string;
|
|
851
|
+
}
|
|
720
852
|
|
|
721
853
|
/**
|
|
722
854
|
* `@ai-matrx/alchemy/ports` — the host ports (Matrx Alchemy CONTRACT §2.2).
|
|
@@ -736,7 +868,7 @@ type MandateRunRequest = ({
|
|
|
736
868
|
* PP-01a `window` (host-rendered windows for a live preparation session)
|
|
737
869
|
* PP-13a `transferKnobs` (organization default recipes)
|
|
738
870
|
*
|
|
739
|
-
*
|
|
871
|
+
* ALC-17 `door` (the one write door), `review` (queued writes)
|
|
740
872
|
*
|
|
741
873
|
* ── Absent-port semantics ───────────────────────────────────────────────────
|
|
742
874
|
*
|
|
@@ -772,6 +904,10 @@ type MandateRunRequest = ({
|
|
|
772
904
|
* approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
|
|
773
905
|
* ("needs a person's approval"); a person's own click is the approval
|
|
774
906
|
* (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
|
|
907
|
+
* door absent → write-target Actions dispatch to `pageActions` as before, and
|
|
908
|
+
* `Delivery.send` is refused with a remedy; bound → every such write goes
|
|
909
|
+
* through it and returns its receipt
|
|
910
|
+
* review absent → a write to a `queued` target is refused ("review isn't available here")
|
|
775
911
|
*
|
|
776
912
|
* Types only: this entry has no runtime code.
|
|
777
913
|
*/
|
|
@@ -925,13 +1061,20 @@ interface AlchemyHostPorts {
|
|
|
925
1061
|
pageActions?: PageActionPort;
|
|
926
1062
|
/** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
|
|
927
1063
|
approvals?: ApprovalPort;
|
|
1064
|
+
/** `createWriteDoor(...)`: every write to a declared target lands here and returns a receipt. */
|
|
1065
|
+
door?: WriteDoor;
|
|
1066
|
+
/** Files a write to a `queued` target for an organization's review. */
|
|
1067
|
+
review?: WriteReviewPort;
|
|
928
1068
|
}
|
|
929
1069
|
interface ServerActionPort {
|
|
930
1070
|
run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
|
|
931
1071
|
}
|
|
932
1072
|
interface MandatePort {
|
|
933
|
-
/**
|
|
934
|
-
|
|
1073
|
+
/**
|
|
1074
|
+
* STARTS the run and resolves with its `RunRef` (CONTRACTS §3/§6) — never the run's result, which
|
|
1075
|
+
* arrives later on `run:<requestId>` / `IntelligencePort.result(ref)`. Rejects with the system's sentence.
|
|
1076
|
+
*/
|
|
1077
|
+
run(request: MandateRunRequest): Promise<MandateRunRef>;
|
|
935
1078
|
}
|
|
936
1079
|
interface ApprovalRequest {
|
|
937
1080
|
action: string;
|
|
@@ -1079,7 +1222,7 @@ type Notice = {
|
|
|
1079
1222
|
sentence: string;
|
|
1080
1223
|
remedy: string;
|
|
1081
1224
|
};
|
|
1082
|
-
/** A reference to a declared write target (the write door
|
|
1225
|
+
/** A reference to a declared write target (resolved by the one write door, ALC-17). */
|
|
1083
1226
|
interface WriteTargetRef {
|
|
1084
1227
|
surfaceName?: string;
|
|
1085
1228
|
target: string;
|
|
@@ -1154,11 +1297,17 @@ declare const sealed: unique symbol;
|
|
|
1154
1297
|
type SealedArtifact = Artifact & {
|
|
1155
1298
|
readonly [sealed]: true;
|
|
1156
1299
|
};
|
|
1157
|
-
/**
|
|
1300
|
+
/**
|
|
1301
|
+
* Every write returns one (CONTRACT §2.3; the door is `createWriteDoor`, ALC-17). An applied
|
|
1302
|
+
* receipt may carry a `warning` with its `fix` (rule 10: a person's kind mismatch warns, never refuses).
|
|
1303
|
+
* A refusal's `reason` is a `WriteRefusalReason` (`./door`).
|
|
1304
|
+
*/
|
|
1158
1305
|
type Receipt = {
|
|
1159
1306
|
status: "applied";
|
|
1160
1307
|
to: WriteTargetRef;
|
|
1161
1308
|
sentence: string;
|
|
1309
|
+
warning?: string;
|
|
1310
|
+
fix?: string;
|
|
1162
1311
|
} | {
|
|
1163
1312
|
status: "queued";
|
|
1164
1313
|
to: WriteTargetRef;
|
|
@@ -1182,7 +1331,7 @@ interface Delivery {
|
|
|
1182
1331
|
html?: boolean;
|
|
1183
1332
|
}): Promise<DeliveryOutcome>;
|
|
1184
1333
|
download(artifact: SealedArtifact, signal: AbortSignal): Promise<DeliveryOutcome>;
|
|
1185
|
-
/** Sends the sealed bytes through the write door (
|
|
1334
|
+
/** Sends the sealed bytes through the write door (`by: "destination"`). Without a door: refused, with a remedy. */
|
|
1186
1335
|
send(artifact: SealedArtifact, to: WriteTargetRef, via: "destination"): Promise<Receipt>;
|
|
1187
1336
|
}
|
|
1188
1337
|
|
|
@@ -1245,19 +1394,13 @@ declare function openPreparation(source: Source | Payload, scope: TransferScope,
|
|
|
1245
1394
|
declare function sealDraft(draft: Draft, format: string, options: FormatOptions, signal: AbortSignal, formats?: readonly FormatAdapter[]): Promise<SealedArtifact>;
|
|
1246
1395
|
/**
|
|
1247
1396
|
* The one delivery. `transport` defaults to the browser (clipboard + download link); a non-browser
|
|
1248
|
-
* host binds its own (`TransportPort`). `send`
|
|
1397
|
+
* host binds its own (`TransportPort`). `send` goes through the one write door (ALC-17): without one it is
|
|
1249
1398
|
* refused with a remedy, never faked.
|
|
1250
1399
|
*/
|
|
1251
1400
|
declare function createDelivery(ports?: {
|
|
1252
1401
|
transport?: Transport;
|
|
1253
|
-
door
|
|
1254
|
-
|
|
1255
|
-
to: WriteTargetRef;
|
|
1256
|
-
value: unknown;
|
|
1257
|
-
origin: "user";
|
|
1258
|
-
via: "destination";
|
|
1259
|
-
}): Promise<Receipt>;
|
|
1260
|
-
};
|
|
1402
|
+
/** The one write door (`createWriteDoor`). Absent → `send` is refused with a remedy. */
|
|
1403
|
+
door?: Pick<WriteDoor, "write">;
|
|
1261
1404
|
}): Delivery;
|
|
1262
1405
|
|
|
1263
1406
|
/**
|
|
@@ -1436,4 +1579,4 @@ declare function setPersonDefaultRecipe(ports: Pick<AlchemyHostPorts, "persisten
|
|
|
1436
1579
|
[key: string]: Json;
|
|
1437
1580
|
} | null): Promise<void>;
|
|
1438
1581
|
|
|
1439
|
-
export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
|
|
1582
|
+
export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CannotApply, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, DuplicateWriteHandlerError, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteApplyRequest, type WriteCaller, type WriteDoor, type WriteDoorDeclarations, type WriteDoorPorts, type WriteHandler, type WriteHandlerResult, type WriteOp, type WriteRefusalReason, type WriteRequest, type WriteReviewPort, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, createWriteDoor, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
|
package/dist/core.d.ts
CHANGED
|
@@ -649,6 +649,125 @@ interface ClickTarget {
|
|
|
649
649
|
host?: unknown;
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
+
/**
|
|
653
|
+
* THE ONE WRITE DOOR (Matrx Alchemy ALC-17; Applets CONTRACTS §6 "receipts through the one write door").
|
|
654
|
+
*
|
|
655
|
+
* Every write — a person's edit, a menu row, a destination send, an agent, an applet, an automation,
|
|
656
|
+
* an Action projected from a write target — lands through `door.write`. The door:
|
|
657
|
+
*
|
|
658
|
+
* 1. resolves the DECLARED write target (the surface's own, then its ancestors'); an undeclared
|
|
659
|
+
* target is refused by name;
|
|
660
|
+
* 2. enforces the mode: `stream` takes ops from the target's `streamOps`; ops on any other target
|
|
661
|
+
* need `patchable` (+ `updatesValue`); a value on a `stream` target is refused;
|
|
662
|
+
* 3. checks the kind (rule 10): a person's mismatch WARNS (the receipt is still applied, with a
|
|
663
|
+
* `warning` and a `fix`); an agent's, applet's or automation's malformed write is REFUSED;
|
|
664
|
+
* 4. applies the policy: manual → a person only; ask → a person's own act is the approval, anyone
|
|
665
|
+
* else asks through `approvals`; queued → filed through `review`; auto → applies;
|
|
666
|
+
* 5. applies through the handler: the mounted page's LIVE handler wins over the HEADLESS one;
|
|
667
|
+
* neither → refused `unapplicable` ("open <surface> to apply it");
|
|
668
|
+
* 6. turns stale / missing record / broken protected span into "cannot apply" with a one-click
|
|
669
|
+
* remedy (rule 11).
|
|
670
|
+
*
|
|
671
|
+
* Every outcome is a `Receipt` carrying the system's own sentence. `write` never throws.
|
|
672
|
+
*
|
|
673
|
+
* Who counts as a person: `person`, `menu` and `destination` (a destination send is a person's own
|
|
674
|
+
* click on "Send to …"). `agent`, `applet` and `automation` are not.
|
|
675
|
+
*
|
|
676
|
+
* Open-risk ruling — stream ops into an entity target: an entity write is ONE atomic save. Ops reach
|
|
677
|
+
* an entity target only when it is declared `patchable` (the ops are handed to the handler in one
|
|
678
|
+
* call and commit as one save); a non-patchable entity target refuses ops with the remedy "stream
|
|
679
|
+
* into the editor, then save". Op-by-op persistence into a record does not exist.
|
|
680
|
+
*/
|
|
681
|
+
|
|
682
|
+
/** Who is writing. `menu` and `destination` are a person's own act. */
|
|
683
|
+
type WriteCaller = "person" | "agent" | "applet" | "automation" | "destination" | "menu";
|
|
684
|
+
/** One text op for a `stream` (or `patchable`) target — the WidgetHandle op set. */
|
|
685
|
+
interface WriteOp {
|
|
686
|
+
op: StreamOp;
|
|
687
|
+
/** The text the op inserts or replaces with. */
|
|
688
|
+
text?: string;
|
|
689
|
+
/** What `replace` / `insert_before` / `insert_after` / `patch` anchor on. */
|
|
690
|
+
find?: string;
|
|
691
|
+
}
|
|
692
|
+
interface WriteRequest {
|
|
693
|
+
surfaceName: string;
|
|
694
|
+
/** A write target name; `"<itemType>.<name>"` names an item's target. */
|
|
695
|
+
target: string;
|
|
696
|
+
itemType?: string;
|
|
697
|
+
/** Which item, by its declared identity values. Required for an item target. */
|
|
698
|
+
itemIdentity?: Record<string, string>;
|
|
699
|
+
/** A whole value. Exactly one of `value` / `ops`. */
|
|
700
|
+
value?: unknown;
|
|
701
|
+
/** Text ops (stream / patchable targets). */
|
|
702
|
+
ops?: readonly WriteOp[];
|
|
703
|
+
by: WriteCaller;
|
|
704
|
+
runId?: string;
|
|
705
|
+
}
|
|
706
|
+
/** What a handler receives: the request plus the declared target it resolved to. */
|
|
707
|
+
interface WriteApplyRequest {
|
|
708
|
+
surfaceName: string;
|
|
709
|
+
/** The surface that declares the target (an ancestor when inherited). */
|
|
710
|
+
declaredOn: string;
|
|
711
|
+
target: WriteTarget;
|
|
712
|
+
item?: {
|
|
713
|
+
itemType: string;
|
|
714
|
+
identity: Record<string, string>;
|
|
715
|
+
};
|
|
716
|
+
value?: unknown;
|
|
717
|
+
ops?: readonly WriteOp[];
|
|
718
|
+
by: WriteCaller;
|
|
719
|
+
runId?: string;
|
|
720
|
+
}
|
|
721
|
+
/** Rule 11: the three "cannot apply" signals. */
|
|
722
|
+
type CannotApply = "stale" | "missing-record" | "broken-span";
|
|
723
|
+
/**
|
|
724
|
+
* A handler applies the write. Return nothing (or `{ status: "applied" }`) when it landed, or a
|
|
725
|
+
* `cannotApply` signal; THROWING an error whose `code` is a `CannotApply` signal means the same.
|
|
726
|
+
*/
|
|
727
|
+
type WriteHandlerResult = void | {
|
|
728
|
+
status: "applied";
|
|
729
|
+
sentence?: string;
|
|
730
|
+
} | {
|
|
731
|
+
status: "cannot-apply";
|
|
732
|
+
cannotApply: CannotApply;
|
|
733
|
+
sentence?: string;
|
|
734
|
+
remedy?: string;
|
|
735
|
+
};
|
|
736
|
+
type WriteHandler = (request: WriteApplyRequest, signal: AbortSignal) => WriteHandlerResult | Promise<WriteHandlerResult>;
|
|
737
|
+
/** Files a `queued` write for an organization's review. */
|
|
738
|
+
interface WriteReviewPort {
|
|
739
|
+
file(request: WriteApplyRequest): Promise<{
|
|
740
|
+
sentence?: string;
|
|
741
|
+
remedy?: string;
|
|
742
|
+
} | void>;
|
|
743
|
+
}
|
|
744
|
+
/** Why a write was refused. */
|
|
745
|
+
type WriteRefusalReason = "undeclared" | "needs_item" | "malformed" | "declaration_broken" | "manual_only" | "needs_approval" | "declined" | "no_review" | "unapplicable" | "cannot_apply" | "cancelled" | "failed";
|
|
746
|
+
interface WriteDoor {
|
|
747
|
+
write(request: WriteRequest, signal?: AbortSignal): Promise<Receipt>;
|
|
748
|
+
/** A feature's write handler that works with no page mounted. Refuses a second one for the same target. */
|
|
749
|
+
registerHeadless(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
750
|
+
/** A mounted page's handler; wins over the headless one while registered. Returns unregister. */
|
|
751
|
+
registerLive(surfaceName: string, targetName: string, handler: WriteHandler): () => void;
|
|
752
|
+
}
|
|
753
|
+
/** The declarations the door reads: a `DeclarationRegistry` satisfies it. */
|
|
754
|
+
interface WriteDoorDeclarations {
|
|
755
|
+
get(surfaceName: string): {
|
|
756
|
+
writeTargets?: readonly WriteTarget[];
|
|
757
|
+
itemTypes?: readonly ItemType[];
|
|
758
|
+
} | undefined;
|
|
759
|
+
/** Parent chain, root first (the registry's `ancestry`). Absent = no inheritance. */
|
|
760
|
+
ancestry?(surfaceName: string): string[];
|
|
761
|
+
}
|
|
762
|
+
type WriteDoorPorts = Pick<AlchemyHostPorts, "diagnostics" | "kinds" | "approvals" | "review">;
|
|
763
|
+
declare class DuplicateWriteHandlerError extends Error {
|
|
764
|
+
constructor(surfaceName: string, targetName: string);
|
|
765
|
+
}
|
|
766
|
+
declare function createWriteDoor(options: {
|
|
767
|
+
ports: WriteDoorPorts;
|
|
768
|
+
declarations: WriteDoorDeclarations;
|
|
769
|
+
}): WriteDoor;
|
|
770
|
+
|
|
652
771
|
/**
|
|
653
772
|
* Surface Actions — the shapes (Applets CONTRACTS §6, FROZEN; exported here as a superset).
|
|
654
773
|
*
|
|
@@ -680,6 +799,8 @@ interface ActionError {
|
|
|
680
799
|
message: string;
|
|
681
800
|
retryable: boolean;
|
|
682
801
|
diagnostic?: string;
|
|
802
|
+
/** Superset: the one-click remedy a write door refusal names. */
|
|
803
|
+
remedy?: string;
|
|
683
804
|
}
|
|
684
805
|
/** CONTRACTS §0 `Result<T>`. */
|
|
685
806
|
type ActionResult<T = unknown> = {
|
|
@@ -717,6 +838,17 @@ type MandateRunRequest = ({
|
|
|
717
838
|
by: ActionCaller;
|
|
718
839
|
policy: ActionPolicy;
|
|
719
840
|
};
|
|
841
|
+
/**
|
|
842
|
+
* CONTRACTS §0/§3 `RunRef` — the serializable identity of a started mandate run. A mandate
|
|
843
|
+
* Action answers with THIS, not the run's result: the result arrives later on the event stream
|
|
844
|
+
* `run:<requestId>` (or `IntelligencePort.result(ref)`). Same fields as `@ai-matrx/agents`'s
|
|
845
|
+
* `RunRef`, declared here because alchemy sits below agents and never imports it.
|
|
846
|
+
*/
|
|
847
|
+
interface MandateRunRef {
|
|
848
|
+
requestId: string;
|
|
849
|
+
conversationId: string;
|
|
850
|
+
mandateKey: string;
|
|
851
|
+
}
|
|
720
852
|
|
|
721
853
|
/**
|
|
722
854
|
* `@ai-matrx/alchemy/ports` — the host ports (Matrx Alchemy CONTRACT §2.2).
|
|
@@ -736,7 +868,7 @@ type MandateRunRequest = ({
|
|
|
736
868
|
* PP-01a `window` (host-rendered windows for a live preparation session)
|
|
737
869
|
* PP-13a `transferKnobs` (organization default recipes)
|
|
738
870
|
*
|
|
739
|
-
*
|
|
871
|
+
* ALC-17 `door` (the one write door), `review` (queued writes)
|
|
740
872
|
*
|
|
741
873
|
* ── Absent-port semantics ───────────────────────────────────────────────────
|
|
742
874
|
*
|
|
@@ -772,6 +904,10 @@ type MandateRunRequest = ({
|
|
|
772
904
|
* approvals absent → a policy "ask" Action started by an agent, applet or automation is refused
|
|
773
905
|
* ("needs a person's approval"); a person's own click is the approval
|
|
774
906
|
* (`runs: "navigate"` goes through `overlay.navigate`; overlay absent → refused)
|
|
907
|
+
* door absent → write-target Actions dispatch to `pageActions` as before, and
|
|
908
|
+
* `Delivery.send` is refused with a remedy; bound → every such write goes
|
|
909
|
+
* through it and returns its receipt
|
|
910
|
+
* review absent → a write to a `queued` target is refused ("review isn't available here")
|
|
775
911
|
*
|
|
776
912
|
* Types only: this entry has no runtime code.
|
|
777
913
|
*/
|
|
@@ -925,13 +1061,20 @@ interface AlchemyHostPorts {
|
|
|
925
1061
|
pageActions?: PageActionPort;
|
|
926
1062
|
/** Asks a person, in place, to approve an `ask` Action that an agent, applet or automation started. */
|
|
927
1063
|
approvals?: ApprovalPort;
|
|
1064
|
+
/** `createWriteDoor(...)`: every write to a declared target lands here and returns a receipt. */
|
|
1065
|
+
door?: WriteDoor;
|
|
1066
|
+
/** Files a write to a `queued` target for an organization's review. */
|
|
1067
|
+
review?: WriteReviewPort;
|
|
928
1068
|
}
|
|
929
1069
|
interface ServerActionPort {
|
|
930
1070
|
run(request: ServerActionRunRequest): Promise<ServerActionRunResponse>;
|
|
931
1071
|
}
|
|
932
1072
|
interface MandatePort {
|
|
933
|
-
/**
|
|
934
|
-
|
|
1073
|
+
/**
|
|
1074
|
+
* STARTS the run and resolves with its `RunRef` (CONTRACTS §3/§6) — never the run's result, which
|
|
1075
|
+
* arrives later on `run:<requestId>` / `IntelligencePort.result(ref)`. Rejects with the system's sentence.
|
|
1076
|
+
*/
|
|
1077
|
+
run(request: MandateRunRequest): Promise<MandateRunRef>;
|
|
935
1078
|
}
|
|
936
1079
|
interface ApprovalRequest {
|
|
937
1080
|
action: string;
|
|
@@ -1079,7 +1222,7 @@ type Notice = {
|
|
|
1079
1222
|
sentence: string;
|
|
1080
1223
|
remedy: string;
|
|
1081
1224
|
};
|
|
1082
|
-
/** A reference to a declared write target (the write door
|
|
1225
|
+
/** A reference to a declared write target (resolved by the one write door, ALC-17). */
|
|
1083
1226
|
interface WriteTargetRef {
|
|
1084
1227
|
surfaceName?: string;
|
|
1085
1228
|
target: string;
|
|
@@ -1154,11 +1297,17 @@ declare const sealed: unique symbol;
|
|
|
1154
1297
|
type SealedArtifact = Artifact & {
|
|
1155
1298
|
readonly [sealed]: true;
|
|
1156
1299
|
};
|
|
1157
|
-
/**
|
|
1300
|
+
/**
|
|
1301
|
+
* Every write returns one (CONTRACT §2.3; the door is `createWriteDoor`, ALC-17). An applied
|
|
1302
|
+
* receipt may carry a `warning` with its `fix` (rule 10: a person's kind mismatch warns, never refuses).
|
|
1303
|
+
* A refusal's `reason` is a `WriteRefusalReason` (`./door`).
|
|
1304
|
+
*/
|
|
1158
1305
|
type Receipt = {
|
|
1159
1306
|
status: "applied";
|
|
1160
1307
|
to: WriteTargetRef;
|
|
1161
1308
|
sentence: string;
|
|
1309
|
+
warning?: string;
|
|
1310
|
+
fix?: string;
|
|
1162
1311
|
} | {
|
|
1163
1312
|
status: "queued";
|
|
1164
1313
|
to: WriteTargetRef;
|
|
@@ -1182,7 +1331,7 @@ interface Delivery {
|
|
|
1182
1331
|
html?: boolean;
|
|
1183
1332
|
}): Promise<DeliveryOutcome>;
|
|
1184
1333
|
download(artifact: SealedArtifact, signal: AbortSignal): Promise<DeliveryOutcome>;
|
|
1185
|
-
/** Sends the sealed bytes through the write door (
|
|
1334
|
+
/** Sends the sealed bytes through the write door (`by: "destination"`). Without a door: refused, with a remedy. */
|
|
1186
1335
|
send(artifact: SealedArtifact, to: WriteTargetRef, via: "destination"): Promise<Receipt>;
|
|
1187
1336
|
}
|
|
1188
1337
|
|
|
@@ -1245,19 +1394,13 @@ declare function openPreparation(source: Source | Payload, scope: TransferScope,
|
|
|
1245
1394
|
declare function sealDraft(draft: Draft, format: string, options: FormatOptions, signal: AbortSignal, formats?: readonly FormatAdapter[]): Promise<SealedArtifact>;
|
|
1246
1395
|
/**
|
|
1247
1396
|
* The one delivery. `transport` defaults to the browser (clipboard + download link); a non-browser
|
|
1248
|
-
* host binds its own (`TransportPort`). `send`
|
|
1397
|
+
* host binds its own (`TransportPort`). `send` goes through the one write door (ALC-17): without one it is
|
|
1249
1398
|
* refused with a remedy, never faked.
|
|
1250
1399
|
*/
|
|
1251
1400
|
declare function createDelivery(ports?: {
|
|
1252
1401
|
transport?: Transport;
|
|
1253
|
-
door
|
|
1254
|
-
|
|
1255
|
-
to: WriteTargetRef;
|
|
1256
|
-
value: unknown;
|
|
1257
|
-
origin: "user";
|
|
1258
|
-
via: "destination";
|
|
1259
|
-
}): Promise<Receipt>;
|
|
1260
|
-
};
|
|
1402
|
+
/** The one write door (`createWriteDoor`). Absent → `send` is refused with a remedy. */
|
|
1403
|
+
door?: Pick<WriteDoor, "write">;
|
|
1261
1404
|
}): Delivery;
|
|
1262
1405
|
|
|
1263
1406
|
/**
|
|
@@ -1436,4 +1579,4 @@ declare function setPersonDefaultRecipe(ports: Pick<AlchemyHostPorts, "persisten
|
|
|
1436
1579
|
[key: string]: Json;
|
|
1437
1580
|
} | null): Promise<void>;
|
|
1438
1581
|
|
|
1439
|
-
export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
|
|
1582
|
+
export { type AgentPayloadEnvironment, type AgentPayloadInput, type AiPreparation, type Artifact, type BoundAllMatching, type BuiltInFormatId, type CannotApply, type CapturedAllMatching, type CapturedSource, type Column, ContentTransferError, type Coverage, type Delivery, type DeliveryOutcome, type Draft, DuplicateWriteHandlerError, EMPTY_STRUCTURE, type ExportPage, type ExportProjection, FORMAT_ADAPTERS, type FormatAdapter, type FormatEngine, type FormatOptions, type Json$2 as Json, type NodeLimit, type NormalizeTransferJsonOptions, type Notice, type Omission, type OutputSpan, type PageAction, type Payload, type PreparationOptions, type PreparationSession, type QuerySnapshot, type RawSnapshot, type Receipt, type RecipeOrigin, type ResolvedRecipe, type SealedArtifact, type Section, type SectionLayout, type ServerOperation, type Snapshot, type Source, type SpanMap, type StructureRecipe, type SurfaceHandle, TRANSFER_DEFAULT_RECIPE_SETTING, type TransferLimits, type TransferOperation, type TransferOutcome, type TransferPreferenceOverrides, type TransferPreferences, type TransferScope, type TransferSurfaceDeclaration, type TransferTarget, type Transform, type Transport, type WriteApplyRequest, type WriteCaller, type WriteDoor, type WriteDoorDeclarations, type WriteDoorPorts, type WriteHandler, type WriteHandlerResult, type WriteOp, type WriteRefusalReason, type WriteRequest, type WriteReviewPort, type WriteTargetRef, agentPayloadWithSpans, applyJsonStructure, applySectionSelection, applySectionStructure, applyStructureToJson, applyTransferLimits, assembleAgentPayload, buildAgentPayload, capture, collectAllMatching, concretePointers, createBrowserTransport, createDelivery, createDraft, createSurfaceTransferHandle, createWriteDoor, deriveDraft, directSource, displayPath, editDraft, eligibleFormats, exportedColumns, extensionForLanguage, fenceJsonBlock, formatAdapter, isProseSection, isSealed, joinPointer, jsonSize, jsonTextSpans, nodeChars, normalizeTransferJson, offsetSpans, openPreparation, outputPointer, patternBelow, patternCovers, patternMatches, pointerSegments, projectSnapshot, readTransferCell, recipeKey, reduceJson, refreshDraft, resetDraft, resolveDefaultRecipe, resolveTransferPreferences, resolveTransferRegistry, sealArtifact, sealDraft, sealTransferArtifact, sectionLayout, serialize, setPersonDefaultRecipe, sourceChanged, spanMap, stubText, transformRows, undoDraft };
|