@weiliang0121/capix-runtime 0.0.0-stage → 0.1.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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/dist/binding/access.d.ts +24 -0
  4. package/dist/binding/access.js +2 -0
  5. package/dist/binding/callable.d.ts +14 -0
  6. package/dist/binding/callable.js +2 -0
  7. package/dist/binding/calls.d.ts +41 -0
  8. package/dist/binding/calls.js +2 -0
  9. package/dist/binding/checkpoint-list.d.ts +1 -0
  10. package/dist/binding/checkpoint-list.js +2 -0
  11. package/dist/binding/checkpoint.d.ts +9 -0
  12. package/dist/binding/checkpoint.js +2 -0
  13. package/dist/binding/children/binding.d.ts +34 -0
  14. package/dist/binding/children/binding.js +2 -0
  15. package/dist/binding/children/bound.d.ts +19 -0
  16. package/dist/binding/children/bound.js +2 -0
  17. package/dist/binding/children/builder.d.ts +18 -0
  18. package/dist/binding/children/builder.js +2 -0
  19. package/dist/binding/children/references.d.ts +29 -0
  20. package/dist/binding/children/references.js +2 -0
  21. package/dist/binding/contract.d.ts +27 -0
  22. package/dist/binding/contract.js +1 -0
  23. package/dist/binding/declarations.d.ts +18 -0
  24. package/dist/binding/declarations.js +2 -0
  25. package/dist/binding/hooks.d.ts +32 -0
  26. package/dist/binding/hooks.js +2 -0
  27. package/dist/binding/observation.d.ts +27 -0
  28. package/dist/binding/observation.js +2 -0
  29. package/dist/binding/receptions.d.ts +9 -0
  30. package/dist/binding/receptions.js +2 -0
  31. package/dist/binding/resources.d.ts +18 -0
  32. package/dist/binding/resources.js +2 -0
  33. package/dist/binding/snapshot.d.ts +16 -0
  34. package/dist/binding/snapshot.js +2 -0
  35. package/dist/binding/work.d.ts +20 -0
  36. package/dist/binding/work.js +2 -0
  37. package/dist/construction/calls.d.ts +21 -0
  38. package/dist/construction/calls.js +2 -0
  39. package/dist/construction/capabilities.d.ts +11 -0
  40. package/dist/construction/capabilities.js +2 -0
  41. package/dist/construction/feedback.d.ts +15 -0
  42. package/dist/construction/feedback.js +2 -0
  43. package/dist/construction/invocation.d.ts +38 -0
  44. package/dist/construction/invocation.js +2 -0
  45. package/dist/construction.d.ts +25 -0
  46. package/dist/construction.js +2 -0
  47. package/dist/definition/observation.d.ts +18 -0
  48. package/dist/definition/observation.js +2 -0
  49. package/dist/entry.d.ts +32 -0
  50. package/dist/entry.js +2 -0
  51. package/dist/index.d.ts +25 -0
  52. package/dist/index.js +2 -0
  53. package/dist/initializer.d.ts +7 -0
  54. package/dist/initializer.js +2 -0
  55. package/dist/legacy/binding.d.ts +14 -0
  56. package/dist/legacy/binding.js +2 -0
  57. package/dist/legacy/driver.d.ts +20 -0
  58. package/dist/legacy/driver.js +2 -0
  59. package/dist/legacy/sources.d.ts +41 -0
  60. package/dist/legacy/sources.js +2 -0
  61. package/dist/observation/driver.d.ts +24 -0
  62. package/dist/observation/driver.js +1 -0
  63. package/dist/recording.d.ts +3 -0
  64. package/dist/recording.js +2 -0
  65. package/dist/records/observation/declaration.d.ts +18 -0
  66. package/dist/records/observation/declaration.js +2 -0
  67. package/dist/records/observation/installation.d.ts +37 -0
  68. package/dist/records/observation/installation.js +2 -0
  69. package/dist/records/observation/invocation.d.ts +34 -0
  70. package/dist/records/observation/invocation.js +2 -0
  71. package/dist/records/observation/mapping.d.ts +7 -0
  72. package/dist/records/observation/mapping.js +2 -0
  73. package/dist/resource/installation.d.ts +9 -0
  74. package/dist/resource/installation.js +2 -0
  75. package/dist/resource/resources.d.ts +37 -0
  76. package/dist/resource/resources.js +2 -0
  77. package/dist/runner/cancellation.d.ts +9 -0
  78. package/dist/runner/cancellation.js +2 -0
  79. package/dist/runner/feedback.d.ts +20 -0
  80. package/dist/runner/feedback.js +2 -0
  81. package/dist/runner/observation-contract.d.ts +137 -0
  82. package/dist/runner/observation-contract.js +1 -0
  83. package/dist/runner/observation-projection.d.ts +7 -0
  84. package/dist/runner/observation-projection.js +2 -0
  85. package/dist/runner/observation.d.ts +14 -0
  86. package/dist/runner/observation.js +2 -0
  87. package/dist/runner/output.d.ts +14 -0
  88. package/dist/runner/output.js +2 -0
  89. package/dist/runner.d.ts +37 -0
  90. package/dist/runner.js +2 -0
  91. package/dist/structure/builder.d.ts +12 -0
  92. package/dist/structure/builder.js +2 -0
  93. package/dist/structure/construction.d.ts +22 -0
  94. package/dist/structure/construction.js +2 -0
  95. package/dist/structure/install.d.ts +5 -0
  96. package/dist/structure/install.js +2 -0
  97. package/package.json +57 -3
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{ChildBindingsBuilder}from"./children/builder.js";import{InvocationAccess}from"./access.js";import{originalCheckpointPoint}from"./snapshot.js";import{savedCheckpointFacts}from"./checkpoint.js";import{BoundReceptions}from"./receptions.js";import{checkpointList}from"./checkpoint-list.js";class InvocationWorkBinding{static{__name(this,"InvocationWorkBinding")}declaration;children;composite;output;checkpoint;#childBindingsBuilder;#accesses=new WeakMap;#entries=new WeakMap;#selections=new WeakMap;#savedSelections=new WeakMap;constructor(declaration,children,composite){this.declaration=declaration,this.children=children,this.composite=composite,this.#childBindingsBuilder=new ChildBindingsBuilder(children,new BoundReceptions(declaration.checkpoint?.receptions??[],children)),this.output=declaration.output,this.checkpoint=declaration.checkpoint?this.bindCheckpoint(declaration.checkpoint):void 0}execute(_context,invocation){const declaration=this.declaration,access=this.accessFor(invocation).enter("run",declaration.deps);return this.#entries.set(invocation,access),declaration.run(this.executionWork(invocation,access))}close(_context,invocation){const access=this.#entries.get(invocation);this.#entries.delete(invocation);try{return access?.close(),{status:"succeeded",value:void 0}}catch(failure){return{status:"failed",failure}}}resume(point,invocation,state,references){const access=this.accessFor(invocation).enter(`checkpoint:${point.name}`,point.resume.deps,point.resume.uses??[]);this.#entries.set(invocation,access);const registry=this.accessFor(invocation).references,saved=Object.freeze(Object.fromEntries(Object.entries(references).map(([name,value])=>{if(!Array.isArray(value))return[name,registry.fromSaved(value)];const list=checkpointList(()=>value.length,index=>registry.fromSaved(value[index]),access.validate);return this.#savedSelections.set(list,{invocation,references:value}),[name,list]})));return point.resume.run({...this.executionWork(invocation,access),initialInput:invocation.context.input,round:invocation.context.progress.round,...invocation.context.continuation?{continuation:registry.continuation(invocation.context.continuation)}:{}},state,saved)}childPort(access){return this.composite?{children:access.children}:{}}executionWork(invocation,access){const writer=invocation.checkpointWriter,guarded=__name(operation=>{try{return access.validate(),operation()}catch(error){throw invocation.reject(error),error}},"guarded"),registry=this.accessFor(invocation).references,checkpoint=writer?Object.freeze(Object.assign(options=>guarded(()=>{const registered=this.declaration.checkpoint?.points.find(candidate=>originalCheckpointPoint(candidate)===originalCheckpointPoint(options.point));if(!registered)throw new Error("Checkpoint point is not registered on this declaration");const references=Object.fromEntries(Object.entries(options.refs??{}).map(([name,value])=>{const selection=value&&typeof value=="object"?this.#selections.get(value):void 0;if(selection){if(selection.invocation!==invocation)throw new Error("Checkpoint selection belongs to another invocation");return[name,selection.raw]}return[name,Array.isArray(value)?value.map(ref=>registry.encode(ref)):registry.encode(value)]}));writer.save(registered.name,options.state,references)}),{select:__name((definition,initial)=>guarded(()=>{const position=this.children.position(definition),restored=initial?this.#savedSelections.get(initial):void 0;if(restored&&restored.invocation!==invocation)throw new Error("Saved checkpoint selection belongs to another invocation");const raw=writer.select(position,restored?restored.references:initial?.map(ref=>registry.encode(ref))),selected=Object.freeze({get length(){return guarded(()=>raw.length)},at:__name(index=>guarded(()=>{const ref=raw.at(index);return ref?registry.fromSaved(ref):void 0}),"at"),occurrenceAt:__name(index=>guarded(()=>raw.occurrenceAt(index)),"occurrenceAt"),add:__name(ref=>guarded(()=>{const encoded=registry.encode(ref);if(encoded.target.position!==position)throw new Error("Checkpoint selection child declaration differs");return raw.add(encoded)}),"add"),remove:__name(occurrence=>guarded(()=>raw.remove(occurrence)),"remove"),*[Symbol.iterator](){const iterator=guarded(()=>raw[Symbol.iterator]());for(let next=guarded(()=>iterator.next());!next.done;next=guarded(()=>iterator.next()))yield guarded(()=>registry.fromSaved(next.value))}});return this.#selections.set(selected,{invocation,raw}),selected}),"select")})):void 0,output=this.declaration.output?.delta?invocation.outputWriter:void 0;return Object.freeze({...access.base,...this.childPort(access),...checkpoint?{checkpoint}:{},...output?{output}:{}})}accessFor(invocation){let access=this.#accesses.get(invocation);return access||(access=new InvocationAccess(invocation,this.#childBindingsBuilder),this.#accesses.set(invocation,access)),access}bindCheckpoint(checkpoint){const points=Object.fromEntries(checkpoint.points.map(point=>[point.name,{state:point.state,references:Object.fromEntries(Object.entries(point.references).map(([name,slot])=>{const reference=slot;return[name,{cardinality:reference.many?"many":"one",position:this.children.position(reference.definition)}]})),check:__name((_frame,state,references,decoded)=>{const query=savedCheckpointFacts(decoded,references,this.children,this.#childBindingsBuilder.receptions);try{return point.check?.(state,query.facts)}finally{query.close()}},"check"),execute:__name((_context,invocation,state,references)=>this.resume(point,invocation,state,references),"execute")}]));return{key:checkpoint.key,version:checkpoint.version,input:checkpoint.input,output:checkpoint.output,children:this.children.checkpointLayout(),receptions:this.#childBindingsBuilder.receptions.bindings(),points}}}export{InvocationWorkBinding};
@@ -0,0 +1,21 @@
1
+ import { type Invocation, type CallableContext, type InvocationControls, type InvocationRelationOptions } from '@weiliang0121/capix-invocation';
2
+ import type { CallableInput, CallableOutput, CallableDelta, InvocationOutputReceiver, InvocationIdentity, ProgressReceiver } from '@weiliang0121/capix-contracts';
3
+ import type { CallableFeedback } from './feedback.js';
4
+ import type { AnyCallable } from '../binding/declarations.js';
5
+ import { type AnyBuiltCallable, type BuiltCallable, type BuiltOptions } from '../structure/construction.js';
6
+ import type { CallableInvocationStarted } from './invocation.js';
7
+ import { type Stable } from '@weiliang0121/capix-contracts';
8
+ export interface CallableInvocationCallbacks<Input, Output, Resources extends object> {
9
+ readonly started?: CallableInvocationStarted<Input, Output, Resources>;
10
+ }
11
+ export interface RootInvocationOptions<Output, Delta = unknown> extends InvocationControls {
12
+ readonly output?: InvocationOutputReceiver<Output, Delta>;
13
+ readonly feedback?: CallableFeedback;
14
+ readonly created?: ProgressReceiver<InvocationIdentity>;
15
+ }
16
+ export declare function createCallableInvocation<Structure extends AnyCallable>(structure: Structure, parent: Invocation<unknown, unknown, CallableContext>, input: CallableInput<Structure> | Stable<CallableInput<Structure>>, options?: InvocationRelationOptions): Invocation<CallableInput<Structure>, CallableOutput<Structure>, CallableContext<CallableInput<Structure>, CallableOutput<Structure>>>;
17
+ export declare function createRootInvocation<Structure extends AnyCallable, Options>(structure: BuiltCallable<Structure, Options>, input: NoInfer<CallableInput<Structure> | Stable<CallableInput<Structure>>>, options: NoInfer<Options>, controls?: RootInvocationOptions<CallableOutput<Structure>, CallableDelta<Structure>>): Invocation<CallableInput<Structure>, CallableOutput<Structure>, CallableContext<CallableInput<Structure>, CallableOutput<Structure>>>;
18
+ export declare function createRootInvocation<Structure extends AnyBuiltCallable>(structure: Structure, input: NoInfer<CallableInput<Structure> | Stable<CallableInput<Structure>>>, options: NoInfer<BuiltOptions<Structure>>, controls?: RootInvocationOptions<CallableOutput<Structure>, CallableDelta<Structure>>): Invocation<CallableInput<Structure>, CallableOutput<Structure>, CallableContext<CallableInput<Structure>, CallableOutput<Structure>>>;
19
+ export declare function restoreCallableInvocation<Structure extends AnyCallable>(structure: Structure, parent: Invocation<unknown, unknown, CallableContext>, contextId: string, options?: InvocationRelationOptions): Invocation<CallableInput<Structure>, CallableOutput<Structure>, CallableContext<CallableInput<Structure>, CallableOutput<Structure>>>;
20
+ export declare function restoreRootInvocation<Structure extends AnyCallable, Options>(structure: BuiltCallable<Structure, Options>, contextId: string, options: NoInfer<Options>, controls?: RootInvocationOptions<CallableOutput<Structure>, CallableDelta<Structure>>): Invocation<CallableInput<Structure>, CallableOutput<Structure>, CallableContext<CallableInput<Structure>, CallableOutput<Structure>>>;
21
+ export declare function restoreRootInvocation<Structure extends AnyBuiltCallable>(structure: Structure, contextId: string, options: NoInfer<BuiltOptions<Structure>>, controls?: RootInvocationOptions<CallableOutput<Structure>, CallableDelta<Structure>>): Invocation<CallableInput<Structure>, CallableOutput<Structure>, CallableContext<CallableInput<Structure>, CallableOutput<Structure>>>;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{combineOutputReceivers,requireNotCancelled}from"@weiliang0121/capix-invocation";import{callableConstruction}from"../structure/construction.js";import{stableValue}from"@weiliang0121/capix-contracts";function createCallableInvocation(structure,parent,input,options={}){const construction=callableConstruction(structure);construction.invocations.check(parent);const scope=construction.calls.require(parent.construction);return construct(structure,input,scope,{},parent,options)}__name(createCallableInvocation,"createCallableInvocation");function createRootInvocation(structure,input,options,controls={}){controls.signal&&requireNotCancelled(controls.signal);const scope=callableConstruction(structure).calls.begin(options,controls.feedback);return construct(structure,input,scope,controls)}__name(createRootInvocation,"createRootInvocation");function restoreCallableInvocation(structure,parent,contextId,options={}){const construction=callableConstruction(structure);construction.invocations.check(parent);const scope=construction.calls.require(parent.construction);return restore(structure,contextId,scope,{},parent,options)}__name(restoreCallableInvocation,"restoreCallableInvocation");function restoreRootInvocation(structure,contextId,options,controls={}){controls.signal&&requireNotCancelled(controls.signal);const scope=callableConstruction(structure).calls.begin(options,controls.feedback);return restore(structure,contextId,scope,controls)}__name(restoreRootInvocation,"restoreRootInvocation");function restore(structure,contextId,scope,controls,parent,options={}){controls.signal&&requireNotCancelled(controls.signal);const{binding,invocations}=callableConstruction(structure);return invocations.restoration(contextId,binding.work,binding.declaration.kind,parent?.context.id,restoration=>{const input=binding.declaration.checkpoint.input.decode(restoration.head.image.frame.input);return construct(structure,input,scope,controls,parent,options,restoration)},scope.feedback)}__name(restore,"restore");function construct(structure,input,scope,controls,parent,options={},restore2){const{binding,invocations}=callableConstruction(structure),declaration=binding.declaration,initial=restore2?declaration.checkpoint?.points.find(point=>point.name===restore2.head.image.point)?.resume.deps:declaration.deps;if(!initial)throw new Error("Checkpoint point is not declared");const signal=parent?.context.signal??controls.signal;signal&&requireNotCancelled(signal);const fixedInput=stableValue(input);parent&&invocations.check(parent),signal&&requireNotCancelled(signal);const prepared=scope.prepare(structure,fixedInput,!!restore2,parent?.context.resources.supply,signal);signal&&requireNotCancelled(signal);const{name,label,source}=declaration;return invocations.create(fixedInput,{kind:declaration.kind,controls,parent,construction:scope,key:options.key,declarationPosition:options.declarationPosition,receiveFailure:options.receiveFailure,deps:binding.deps,supply:binding.supply,initial,refinements:binding.refinements,supplied:prepared.supply,observation:binding.observations,description:{id:structure.id,name,label,source},work:binding.work,started:prepared.started,progress:prepared.progress,output:combineOutputReceivers(controls.output,options.output,prepared.output),restore:restore2,feedback:scope.feedback})}__name(construct,"construct");export{createCallableInvocation,createRootInvocation,restoreCallableInvocation,restoreRootInvocation};
@@ -0,0 +1,11 @@
1
+ import type { CheckpointInstallation, Clock } from '@weiliang0121/capix-invocation';
2
+ import type { InvocationEvent } from '@weiliang0121/capix-protocol';
3
+ import type { ChangeCapture } from '@weiliang0121/capix-changes';
4
+ import type { ObservationInstallation } from '../binding/observation.js';
5
+ export interface InvocationCapabilities {
6
+ readonly clock?: Clock;
7
+ readonly checkpoints?: CheckpointInstallation;
8
+ readonly observations?: readonly ObservationInstallation[];
9
+ readonly changes?: ChangeCapture<InvocationEvent>;
10
+ }
11
+ export declare function snapshotInvocationCapabilities(options: InvocationCapabilities): InvocationCapabilities;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});function snapshotInvocationCapabilities(options){const observation=options.checkpoints?.observation,feedback=options.checkpoints?.feedback;return Object.freeze({...options,observations:options.observations?Object.freeze([...options.observations]):void 0,checkpoints:options.checkpoints?Object.freeze({store:options.checkpoints.store,observation:observation?Object.freeze({observe:observation.observe.bind(observation),failure:observation.failure}):void 0,feedback:feedback?Object.freeze({receive:feedback.receive.bind(feedback),failed:feedback.failed?.bind(feedback)}):void 0}):void 0})}__name(snapshotInvocationCapabilities,"snapshotInvocationCapabilities");export{snapshotInvocationCapabilities};
@@ -0,0 +1,15 @@
1
+ import type { CheckpointInstallation, CheckpointFact, InvocationFact, ResourceObservation, BusinessObservation } from '@weiliang0121/capix-invocation';
2
+ import { type ProgressReceiver } from '@weiliang0121/capix-changes';
3
+ import type { ObservationInstallation } from '../binding/observation.js';
4
+ export interface CallableFeedback {
5
+ readonly invocation?: ProgressReceiver<InvocationFact>;
6
+ readonly resource?: ProgressReceiver<ResourceObservation>;
7
+ readonly business?: ProgressReceiver<BusinessObservation>;
8
+ readonly checkpoint?: ProgressReceiver<CheckpointFact>;
9
+ }
10
+ export interface CallableFeedbackBinding {
11
+ readonly observation: ObservationInstallation;
12
+ readonly checkpoint?: ProgressReceiver<CheckpointFact>;
13
+ }
14
+ export declare function bindCallableFeedback(feedback: CallableFeedback): CallableFeedbackBinding;
15
+ export declare function checkpointFeedback(installation: CheckpointInstallation | undefined, feedback?: ProgressReceiver<CheckpointFact>): CheckpointInstallation | undefined;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{ProgressChannel}from"@weiliang0121/capix-changes";function bindCallableFeedback(feedback){const invocation=fixedReceiver(feedback.invocation),resource=fixedReceiver(feedback.resource),business=fixedReceiver(feedback.business),checkpoint=fixedReceiver(feedback.checkpoint);return Object.freeze({checkpoint,observation:Object.freeze({bindInvocation:__name(()=>{const calls=invocation?new ProgressChannel(invocation):void 0,resources=resource?new ProgressChannel(resource):void 0,annotations=business?new ProgressChannel(business):void 0;return{observe:__name(fact=>calls?.publish(fact),"observe"),resource:__name(fact=>resources?.publish(fact),"resource"),business:__name(fact=>annotations?.publish(fact),"business")}},"bindInvocation")})})}__name(bindCallableFeedback,"bindCallableFeedback");function checkpointFeedback(installation,feedback){if(!installation||!feedback)return installation;const additional=new ProgressChannel(feedback),installed=installation.feedback?new ProgressChannel(installation.feedback):void 0;return Object.freeze({...installation,feedback:Object.freeze({receive(fact){additional.publish(fact),installed?.publish(fact)}})})}__name(checkpointFeedback,"checkpointFeedback");function fixedReceiver(receiver){return receiver?Object.freeze({receive:receiver.receive.bind(receiver),failed:receiver.failed?.bind(receiver)}):void 0}__name(fixedReceiver,"fixedReceiver");export{bindCallableFeedback,checkpointFeedback};
@@ -0,0 +1,38 @@
1
+ import { InvocationResources, type CheckpointRestoration, type InvocationProgress, type InvocationDescription, Invocation, type InvocationStarted, type InvocationWork, CallableContext, type InvocationControls, type InvocationRelationOptions } from '@weiliang0121/capix-invocation';
2
+ import type { CallableKind, InvocationOutputReceiver } from '@weiliang0121/capix-contracts';
3
+ import type { ProgressReceiver } from '@weiliang0121/capix-changes';
4
+ import type { InvocationObservationDeclaration } from '../binding/observation.js';
5
+ import { type ResourceRequirements, ResourceSupply } from '@weiliang0121/capix-resources';
6
+ import type { ResourceRefinement } from '@weiliang0121/capix-resources';
7
+ import type { InvocationCapabilities } from './capabilities.js';
8
+ import { type CallableFeedbackBinding } from './feedback.js';
9
+ import { type Stable } from '@weiliang0121/capix-contracts';
10
+ export type CallableInvocationStarted<Input, Output, Resources extends object = object> = InvocationStarted<Input, Output, CallableContext<Input, Output, Resources>>;
11
+ export interface CallableInvocationRequest<Input, Output, Resources extends object = object> extends InvocationRelationOptions {
12
+ readonly kind: CallableKind;
13
+ readonly controls?: InvocationControls;
14
+ readonly parent?: Invocation<unknown, unknown, CallableContext>;
15
+ readonly construction?: object;
16
+ readonly restore?: CheckpointRestoration;
17
+ readonly progress?: ProgressReceiver<InvocationProgress>;
18
+ readonly output?: InvocationOutputReceiver<Output>;
19
+ readonly resources?: InvocationResources;
20
+ readonly supplied?: ResourceSupply;
21
+ readonly deps?: ResourceRequirements<Resources>;
22
+ readonly initial?: ResourceRequirements;
23
+ readonly supply?: ResourceRequirements;
24
+ readonly refinements?: readonly ResourceRefinement<Stable<Input>>[];
25
+ readonly observation?: readonly InvocationObservationDeclaration[];
26
+ readonly description?: InvocationDescription;
27
+ readonly work: InvocationWork<Input, Output, CallableContext<Input, Output, Resources>>;
28
+ readonly started?: CallableInvocationStarted<Input, Output, Resources>;
29
+ readonly feedback?: CallableFeedbackBinding;
30
+ }
31
+ export declare class CallableInvocationBuilder {
32
+ private readonly capabilities;
33
+ constructor(capabilities?: InvocationCapabilities);
34
+ check(parent: Invocation<unknown, unknown, CallableContext>): void;
35
+ restoration<Input, Output, Resources extends object = object>(contextId: string, work: InvocationWork<Input, Output, CallableContext<Input, Output, Resources>>, kind: CallableKind, parentContextId?: string): CheckpointRestoration;
36
+ restoration<Input, Output, Resources extends object, Value>(contextId: string, work: InvocationWork<Input, Output, CallableContext<Input, Output, Resources>>, kind: CallableKind, parentContextId: string | undefined, construct: (restoration: CheckpointRestoration) => Value, feedback?: CallableFeedbackBinding): Value;
37
+ create<Input, Output, Resources extends object = object>(input: Input | Stable<Input>, request: CallableInvocationRequest<Input, Output, Resources>): Invocation<Input, Output, CallableContext<Input, Output, Resources>>;
38
+ }
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{InvocationResources,requireNotCancelled,restoreCheckpointContinuation,prepareCheckpointRestoration,attachInvocationResources,InvocationChangeEmitter,Invocation,CallableContext}from"@weiliang0121/capix-invocation";import{bindInvocationObservation}from"../binding/observation.js";import{ResourceSupply}from"@weiliang0121/capix-resources";import{checkpointFeedback}from"./feedback.js";import{stableValue}from"@weiliang0121/capix-contracts";class CallableInvocationBuilder{static{__name(this,"CallableInvocationBuilder")}capabilities;constructor(capabilities={}){this.capabilities=capabilities}check(parent){if(parent.requireActive(),parent.context.requireActive(),!parent.context.belongsTo(this))throw new Error("Call belongs to another binding installation")}restoration(contextId,work,kind,parentContextId,construct,feedback){return prepareCheckpointRestoration(checkpointFeedback(this.capabilities.checkpoints,feedback?.checkpoint),work.checkpoint,contextId,{kind,...parentContextId?{parentContextId}:{}},construct)}create(input,request){const parent=request.parent;parent&&this.check(parent);const controls=parent?{signal:parent.context.signal}:request.controls;if(controls?.signal&&requireNotCancelled(controls.signal),request.supplied&&request.resources)throw new Error("Call construction must provide one resource supply");const supplied=request.supplied??request.resources?.supply??parent?.context.resources.supply??new ResourceSupply,deps=request.deps??{},fixedInput=stableValue(input);parent&&this.check(parent),controls?.signal&&requireNotCancelled(controls.signal);const selected=supplied.select(request.supply??deps).refine(fixedInput,request.refinements??[]),resources=new InvocationResources(deps,selected.entries,request.initial,request.supply);parent&&this.check(parent),controls?.signal&&requireNotCancelled(controls.signal);const context=new CallableContext(fixedInput,request.kind,controls,resources,this);if(request.restore){if(!request.work.checkpoint)throw new Error("Checkpoint declaration is missing");const frame=request.restore.head.image.frame;context.installCheckpoint({id:frame.owner.contextId,round:frame.round,currentInput:request.work.checkpoint.input.decode(frame.currentInput),continuation:restoreCheckpointContinuation(frame)})}const identity={contextId:context.id,kind:request.kind,...parent?{parentContextId:parent.context.id}:{}},recovering=!!request.restore||!!parent?.recovering,installations=request.feedback?[request.feedback.observation,...this.capabilities.observations??[]]:this.capabilities.observations,observation=recovering?void 0:bindInvocationObservation({identity,description:request.description,declarations:request.observation,resources},installations,parent?.observation);parent&&this.check(parent),controls?.signal&&requireNotCancelled(controls.signal);const changes=!recovering&&this.capabilities.changes?new InvocationChangeEmitter(identity,this.capabilities.changes):void 0,invocation=new Invocation({...parent?{parent:{invocation:parent,key:request.key,declarationPosition:request.declarationPosition,receiveFailure:request.receiveFailure}}:{},context,construction:request.construction??parent?.construction,work:request.work,checkpoints:checkpointFeedback(this.capabilities.checkpoints,request.feedback?.checkpoint),restore:request.restore,progress:request.progress,output:request.output,clock:this.capabilities.clock,signal:context.signal,observation,identity,description:request.description,started:request.started,changes});return attachInvocationResources(invocation,resources),invocation}}export{CallableInvocationBuilder};
@@ -0,0 +1,25 @@
1
+ export type { BuiltCallable, AnyBuiltCallable, BuiltOptions } from './structure/construction.js';
2
+ export { callableConstruction } from './structure/construction.js';
3
+ export * from './structure/builder.js';
4
+ export * from './construction/calls.js';
5
+ export * from './binding/children/bound.js';
6
+ export * from './binding/children/builder.js';
7
+ export * from './binding/receptions.js';
8
+ export * from './binding/callable.js';
9
+ export * from './binding/calls.js';
10
+ export * from './legacy/sources.js';
11
+ export { buildCallableFromSource, type CallableBindingOptions } from './legacy/binding.js';
12
+ export * from './binding/contract.js';
13
+ export * from './binding/declarations.js';
14
+ export * from './binding/work.js';
15
+ export { InvocationContext, CallableContext, Invocation } from '@weiliang0121/capix-invocation';
16
+ export type { InvocationControls, ContextState, InvocationStarted, InvocationOptions } from '@weiliang0121/capix-invocation';
17
+ export * from './construction/invocation.js';
18
+ export { InvocationChildren, InvocationRelation } from '@weiliang0121/capix-invocation';
19
+ export type { ParentInvocation, InvocationChildBaseline, InvocationRelationOptions, InvocationTarget, InvocationRelationReception, InvocationRelationBaseline, InvocationRelationOwner, InvocationRelationSetup, InvocationReceptionBinding } from '@weiliang0121/capix-invocation';
20
+ export type { InvocationCapabilities } from './construction/capabilities.js';
21
+ export { invocationResourceFailures } from '@weiliang0121/capix-invocation';
22
+ export type { CheckpointChildBinding, CheckpointReferenceSlot, InvocationCheckpointWork, CheckpointBinding, DecodedCheckpointReception, DecodedCheckpointHandledReception, DecodedCheckpointChild, DecodedCheckpointFrame, CheckpointContinuationFact } from '@weiliang0121/capix-invocation';
23
+ export { checkpointChildBinding, checkpointReceptionBinding, decodeCheckpointReception, decodeCheckpointHandledReception, checkCheckpointReferences, decodeCheckpointFrame, decodeCheckpointDiagnostic, captureCheckpointContinuation, restoreCheckpointContinuation, inspectChildCallFailure } from '@weiliang0121/capix-invocation';
24
+ export { savedCheckpointFacts } from './binding/checkpoint.js';
25
+ export { InvocationResources, type InvocationResourceOwner } from '@weiliang0121/capix-invocation';
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ import{callableConstruction}from"./structure/construction.js";export*from"./structure/builder.js";export*from"./construction/calls.js";export*from"./binding/children/bound.js";export*from"./binding/children/builder.js";export*from"./binding/receptions.js";export*from"./binding/callable.js";export*from"./binding/calls.js";export*from"./legacy/sources.js";import{buildCallableFromSource}from"./legacy/binding.js";export*from"./binding/contract.js";export*from"./binding/declarations.js";export*from"./binding/work.js";import{InvocationContext,CallableContext,Invocation}from"@weiliang0121/capix-invocation";export*from"./construction/invocation.js";import{InvocationChildren,InvocationRelation}from"@weiliang0121/capix-invocation";import{invocationResourceFailures}from"@weiliang0121/capix-invocation";import{checkpointChildBinding,checkpointReceptionBinding,decodeCheckpointReception,decodeCheckpointHandledReception,checkCheckpointReferences,decodeCheckpointFrame,decodeCheckpointDiagnostic,captureCheckpointContinuation,restoreCheckpointContinuation,inspectChildCallFailure}from"@weiliang0121/capix-invocation";import{savedCheckpointFacts}from"./binding/checkpoint.js";import{InvocationResources}from"@weiliang0121/capix-invocation";export{CallableContext,Invocation,InvocationChildren,InvocationContext,InvocationRelation,InvocationResources,buildCallableFromSource,callableConstruction,captureCheckpointContinuation,checkCheckpointReferences,checkpointChildBinding,checkpointReceptionBinding,decodeCheckpointDiagnostic,decodeCheckpointFrame,decodeCheckpointHandledReception,decodeCheckpointReception,inspectChildCallFailure,invocationResourceFailures,restoreCheckpointContinuation,savedCheckpointFacts};
@@ -0,0 +1,18 @@
1
+ import type { CallableKind } from '@weiliang0121/capix-contracts';
2
+ import type { ResourceRequirements } from '@weiliang0121/capix-resources';
3
+ export interface ObservationDefinition<Fact, Ports extends object> {
4
+ readonly deps: ResourceRequirements<Ports>;
5
+ observe(fact: Fact, ports: Readonly<Ports>): undefined;
6
+ }
7
+ export interface ObservationDeclaration<Fact> {
8
+ readonly deps: ResourceRequirements;
9
+ readonly observe: (fact: Fact, ports: Readonly<object>) => undefined;
10
+ readonly failure?: 'isolate' | 'propagate';
11
+ }
12
+ export interface ObservationDeclarationScope {
13
+ readonly kind: CallableKind;
14
+ readonly id?: string;
15
+ }
16
+ export declare function defineObservation<Fact, Ports extends object>(definition: ObservationDefinition<Fact, Ports>, options?: {
17
+ failure?: 'isolate' | 'propagate';
18
+ }): ObservationDeclaration<Fact>;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});function defineObservation(definition,options={}){const observe=definition.observe.bind(definition);return Object.freeze({deps:Object.freeze({...definition.deps}),failure:options.failure,observe:__name((fact,ports)=>observe(fact,ports),"observe")})}__name(defineObservation,"defineObservation");export{defineObservation};
@@ -0,0 +1,32 @@
1
+ import { type CallableInput, type CallableOutput, type Stable } from '@weiliang0121/capix-contracts';
2
+ import { type InvocationControls } from '@weiliang0121/capix-invocation';
3
+ import type { AnyBuiltCallable, BuiltCallable, BuiltOptions } from './structure/construction.js';
4
+ import type { AnyCallable } from './binding/declarations.js';
5
+ import { type RootInvocationOptions } from './construction/calls.js';
6
+ export interface EntryState {
7
+ running: boolean;
8
+ }
9
+ export type EntryChange = {
10
+ kind: 'established';
11
+ } | ({
12
+ boundId: string;
13
+ } & ({
14
+ kind: 'acquired' | 'released';
15
+ } | {
16
+ kind: 'rejected';
17
+ reason: 'busy';
18
+ error: unknown;
19
+ } | {
20
+ kind: 'entry-failed';
21
+ error: unknown;
22
+ }));
23
+ export declare function runEntry<Structure extends AnyCallable, Options>(entry: EntryState, structure: BuiltCallable<Structure, Options>, request: {
24
+ input: NoInfer<CallableInput<Structure> | Stable<CallableInput<Structure>>>;
25
+ } | {
26
+ contextId: string;
27
+ }, options: NoInfer<Options> & InvocationControls, publish: (change: EntryChange) => void, execution?: RootInvocationOptions<CallableOutput<Structure>>): Promise<Stable<CallableOutput<Structure>>>;
28
+ export declare function runEntry<Structure extends AnyBuiltCallable>(entry: EntryState, structure: Structure, request: {
29
+ input: NoInfer<CallableInput<Structure> | Stable<CallableInput<Structure>>>;
30
+ } | {
31
+ contextId: string;
32
+ }, options: NoInfer<BuiltOptions<Structure>> & InvocationControls, publish: (change: EntryChange) => void, execution?: RootInvocationOptions<CallableOutput<Structure>>): Promise<Stable<CallableOutput<Structure>>>;
package/dist/entry.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{RuntimeError}from"@weiliang0121/capix-contracts";import{requireNotCancelled}from"@weiliang0121/capix-invocation";import{createRootInvocation,restoreRootInvocation}from"./construction/calls.js";import{ProgressChannel}from"@weiliang0121/capix-changes";async function runEntry(entry,structure,request,options,publish,execution){const boundId=structure.id;if(entry.running){const error=new RuntimeError("RUNTIME_BUSY","\u5F53\u524D\u73AF\u5883\u6B63\u5728\u6267\u884C\uFF0C\u8BF7\u7B49\u5F85\u672C\u6B21\u8C03\u7528\u7ED3\u675F\u3002");try{publish({kind:"rejected",boundId,reason:"busy",error})}catch(observation){throw new AggregateError([error,observation],"Entry rejection and observation both failed",{cause:error})}throw error}entry.running=!0;let failed=!1,failure;try{publish({kind:"acquired",boundId});let invocation;try{const controls=execution??{signal:options?.signal};controls.signal&&requireNotCancelled(controls.signal),invocation="contextId"in request?restoreRootInvocation(structure,request.contextId,options,controls):createRootInvocation(structure,request.input,options,controls)}catch(error){try{publish({kind:"entry-failed",boundId,error})}catch(observation){throw new AggregateError([error,observation],"Call construction and observation both failed",{cause:error})}throw error}execution?.created&&new ProgressChannel(execution.created).publish(invocation.identity);const signal=execution?.signal??options?.signal;return signal&&requireNotCancelled(signal),await invocation.run()}catch(error){throw failed=!0,failure=error,error}finally{entry.running=!1;try{publish({kind:"released",boundId})}catch(observation){throw failed?new AggregateError([failure,observation],"Call delivery and release observation both failed",{cause:failure}):observation}}}__name(runEntry,"runEntry");export{runEntry};
@@ -0,0 +1,25 @@
1
+ export * from '@weiliang0121/capix-structure';
2
+ export { ChildCallFailure, ExceptionContract, DeclaredException } from '@weiliang0121/capix-invocation';
3
+ export * from './definition/observation.js';
4
+ export * from './legacy/driver.js';
5
+ export * from './runner.js';
6
+ export { callableHooks, type CallableHookDeclaration, type CallableHookBinding } from './binding/hooks.js';
7
+ export * from './binding/callable.js';
8
+ export * from './binding/observation.js';
9
+ export * from './binding/resources.js';
10
+ export { Resources, CapturedResources } from './resource/resources.js';
11
+ export * from './initializer.js';
12
+ export * from '@weiliang0121/capix-interaction';
13
+ export { invocationContextView, invocationView, childInvocationView, Clock, InvocationCancelled, isInvocationCancelled } from '@weiliang0121/capix-invocation';
14
+ export type { InvocationContextView, CallableContextView, ContextViewOf, ContextViewResources, ContextFactsOf, InvocationRelationView, InvocationView, ChildInvocationView, InvocationViewSource, InvocationProgress, InvocationResult, InvocationFailure, InvocationPhase } from '@weiliang0121/capix-invocation';
15
+ export type { InvocationIdentity } from '@weiliang0121/capix-contracts';
16
+ export { InvocationChangeEmitter, InvocationObservation, ObservationError } from '@weiliang0121/capix-invocation';
17
+ export type { InvocationRelationIdentity, InvocationDescription, InvocationRelationChange, InvocationChange, InvocationFact, ResourceObservation, BusinessEvent, BusinessObservation, InvocationObserver } from '@weiliang0121/capix-invocation';
18
+ export type { EventConsumer } from '@weiliang0121/capix-changes';
19
+ export type { DriverFact, DriverObserver } from './observation/driver.js';
20
+ export * from './construction.js';
21
+ export * from './recording.js';
22
+ export { RuntimeError } from '@weiliang0121/capix-contracts';
23
+ export { PersistenceError, RuntimeErrorHelper } from '@weiliang0121/capix-diagnostics';
24
+ export { isNonEmptyArray, hasUniqueItems, isObject, isObjectLike, isNonBlankString, nonBlankStringPattern } from '@weiliang0121/capix-invocation';
25
+ export type { CheckpointFact, CheckpointInstallation, CheckpointWriter, CheckpointRestoration } from '@weiliang0121/capix-invocation';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ export*from"@weiliang0121/capix-structure";import{ChildCallFailure,ExceptionContract,DeclaredException}from"@weiliang0121/capix-invocation";export*from"./definition/observation.js";export*from"./legacy/driver.js";export*from"./runner.js";import{callableHooks}from"./binding/hooks.js";export*from"./binding/callable.js";export*from"./binding/observation.js";export*from"./binding/resources.js";import{Resources,CapturedResources}from"./resource/resources.js";export*from"./initializer.js";export*from"@weiliang0121/capix-interaction";import{invocationContextView,invocationView,childInvocationView,Clock,InvocationCancelled,isInvocationCancelled}from"@weiliang0121/capix-invocation";import{InvocationChangeEmitter,InvocationObservation,ObservationError}from"@weiliang0121/capix-invocation";export*from"./construction.js";export*from"./recording.js";import{RuntimeError}from"@weiliang0121/capix-contracts";import{PersistenceError,RuntimeErrorHelper}from"@weiliang0121/capix-diagnostics";import{isNonEmptyArray,hasUniqueItems,isObject,isObjectLike,isNonBlankString,nonBlankStringPattern}from"@weiliang0121/capix-invocation";export{CapturedResources,ChildCallFailure,Clock,DeclaredException,ExceptionContract,InvocationCancelled,InvocationChangeEmitter,InvocationObservation,ObservationError,PersistenceError,Resources,RuntimeError,RuntimeErrorHelper,callableHooks,childInvocationView,hasUniqueItems,invocationContextView,invocationView,isInvocationCancelled,isNonBlankString,isNonEmptyArray,isObject,isObjectLike,nonBlankStringPattern};
@@ -0,0 +1,7 @@
1
+ export declare class Initializer<T> {
2
+ #private;
3
+ private readonly create;
4
+ constructor(create: () => T);
5
+ get initialized(): boolean;
6
+ get(): T;
7
+ }
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});class Initializer{static{__name(this,"Initializer")}create;#state={status:"idle"};constructor(create){this.create=create}get initialized(){return this.#state.status==="ready"}get(){const state=this.#state;if(state.status==="ready")return state.value;if(state.status==="failed")throw state.error;if(state.status==="creating")throw new Error("Recursive initialization");this.#state={status:"creating"};try{const value=this.create();return this.#state={status:"ready",value},value}catch(error){throw this.#state={status:"failed",error},error}}}export{Initializer};
@@ -0,0 +1,14 @@
1
+ import type { ResourceProvider } from '@weiliang0121/capix-resources';
2
+ import type { CallableInput } from '@weiliang0121/capix-contracts';
3
+ import { type InvocationCapabilities } from '../construction/capabilities.js';
4
+ import { type ChildResourceBinding } from '../binding/resources.js';
5
+ import { type AnyCallable } from '../binding/declarations.js';
6
+ import { type CallableCallSource, type CallableSourceBinding } from './sources.js';
7
+ import type { BuiltCallable } from '../structure/construction.js';
8
+ export interface CallableBindingOptions<Input, Options, Source> {
9
+ readonly providers: readonly ResourceProvider<Source>[];
10
+ readonly source: CallableCallSource<Input, Options, Source>;
11
+ readonly bindings?: readonly CallableSourceBinding<Options, Source>[];
12
+ readonly childResources?: readonly ChildResourceBinding[];
13
+ }
14
+ export declare function buildCallableFromSource<Structure extends AnyCallable, Options, Source>(structure: Structure, options: CallableBindingOptions<NoInfer<CallableInput<Structure>>, Options, Source>, capabilities?: InvocationCapabilities): BuiltCallable<Structure, Options>;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{snapshotInvocationCapabilities}from"../construction/capabilities.js";import{collectObservationProvides}from"../binding/resources.js";import{resolveDeclaration}from"../binding/declarations.js";import{bindCallableSources}from"./sources.js";import{installCallable}from"../structure/install.js";function buildCallableFromSource(structure,options,capabilities={}){const fixed=snapshotInvocationCapabilities(capabilities);return installCallable(structure,fixed,()=>bindSource(structure,options,fixed))}__name(buildCallableFromSource,"buildCallableFromSource");function bindSource(structure,options,capabilities){const bindings=Object.freeze([...options.bindings??[]]),root=resolveDeclaration(structure,{observationProvides:collectObservationProvides(capabilities.observations),observations:capabilities.observations,childResources:options.childResources,sources:bindings.filter(binding=>!!binding.capture).map(binding=>binding.definition)});return Object.freeze({root,calls:bindCallableSources(root,options.providers,options.source,bindings)})}__name(bindSource,"bindSource");export{buildCallableFromSource};
@@ -0,0 +1,20 @@
1
+ import { type InvocationControls } from '@weiliang0121/capix-invocation';
2
+ import type { AnyBuiltCallable, BuiltCallable, BuiltOptions } from '../structure/construction.js';
3
+ import { type InvocationCapabilities } from '../construction/capabilities.js';
4
+ import { type CallableBindingOptions } from './binding.js';
5
+ import type { AnyCallable } from '../binding/declarations.js';
6
+ import type { CallableInput, CallableOutput, Stable } from '@weiliang0121/capix-contracts';
7
+ import type { CheckpointStore } from '@weiliang0121/capix-checkpoint';
8
+ export declare class Driver {
9
+ #private;
10
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
11
+ constructor(options?: InvocationCapabilities);
12
+ get checkpointStore(): CheckpointStore | undefined;
13
+ build<Structure extends AnyCallable, Options, Source>(structure: Structure, options: CallableBindingOptions<NoInfer<CallableInput<Structure>>, Options, Source>): BuiltCallable<Structure, Options>;
14
+ isRunning(structure: AnyBuiltCallable): boolean;
15
+ run<Structure extends AnyBuiltCallable>(structure: Structure, input: NoInfer<CallableInput<Structure> | Stable<CallableInput<Structure>>>, options: NoInfer<BuiltOptions<Structure>> & InvocationControls): Promise<Stable<CallableOutput<Structure>>>;
16
+ resume<Structure extends AnyBuiltCallable>(structure: Structure, contextId: string, options: NoInfer<BuiltOptions<Structure>> & InvocationControls): Promise<Stable<CallableOutput<Structure>>>;
17
+ private entry;
18
+ private perform;
19
+ private publish;
20
+ }
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{randomUUID}from"node:crypto";import{isUndefined}from"es-toolkit/predicate";import{Clock}from"@weiliang0121/capix-invocation";import{bindDriverObservation}from"../binding/observation.js";import{RuntimeError}from"@weiliang0121/capix-contracts";import{buildCallableFromSource}from"./binding.js";import{runEntry}from"../entry.js";import{snapshotInvocationCapabilities}from"../construction/capabilities.js";import"./binding.js";class Driver{static{__name(this,"Driver")}id=randomUUID();#entries=new WeakMap;#capabilities;#clock;#checkpointStore;#observation;#sequence=0;constructor(options={}){this.#clock=options.clock??new Clock;const capabilities=snapshotInvocationCapabilities({...options,clock:this.#clock});this.#checkpointStore=capabilities.checkpoints?.store,this.#capabilities=capabilities,this.#observation=bindDriverObservation(this.id,capabilities.observations),this.publish({kind:"established"})}get checkpointStore(){return this.#checkpointStore}build(structure,options){const built=buildCallableFromSource(structure,options,this.#capabilities);return this.#entries.set(built,{running:!1}),built}isRunning(structure){return this.entry(structure).running}run(structure,input,options){return this.perform(structure,{input},options)}resume(structure,contextId,options){return this.perform(structure,{contextId},options)}entry(bound){const entry=this.#entries.get(bound);if(!entry)throw new RuntimeError("FOREIGN_BINDING","\u8C03\u7528\u7ED3\u6784\u4E0D\u5C5E\u4E8E\u5F53\u524D Driver\u3002");return entry}async perform(structure,request,options){const entry=this.entry(structure);return runEntry(entry,structure,request,options,change=>this.publish(change))}publish(change){const fault=this.#observation.publish(Object.freeze({...change,driverId:this.id,sequence:++this.#sequence,occurredAt:this.#clock.now()}));if(!isUndefined(fault))throw fault}}export{Driver};
@@ -0,0 +1,41 @@
1
+ import { InvocationResources, type InvocationProgress } from '@weiliang0121/capix-invocation';
2
+ import type { ChildCallable } from '@weiliang0121/capix-structure';
3
+ import type { InvocationOutputReceiver, CallableInput } from '@weiliang0121/capix-contracts';
4
+ import type { ResourceProvider } from '@weiliang0121/capix-resources';
5
+ import type { ProgressReceiver } from '@weiliang0121/capix-changes';
6
+ import type { CallableInvocationStarted } from '../construction/invocation.js';
7
+ import type { AnyCallable, ResolvedCallable } from '../binding/declarations.js';
8
+ import { CallableCallScope, type PreparedCall, type CallInstallation } from '../binding/calls.js';
9
+ import type { CallableFeedback } from '../construction/feedback.js';
10
+ import { type Stable } from '@weiliang0121/capix-contracts';
11
+ export interface CallableCallSource<Input, Options, Source> {
12
+ capture(input: Stable<Input>, options: Options): Source;
13
+ validate?(options: Options): void;
14
+ started?(options: Options): CallableInvocationStarted<any, any, any> | undefined;
15
+ progress?(input: Stable<Input>, options: Options): ProgressReceiver<InvocationProgress> | undefined;
16
+ output?(input: Stable<Input>, options: Options): InvocationOutputReceiver<any, any> | undefined;
17
+ }
18
+ export interface CallableSourceBinding<Options, Source, Definition extends ChildCallable = ChildCallable> {
19
+ readonly definition: Definition;
20
+ capture?(input: Stable<CallableInput<Definition>>, options: Options): Source;
21
+ started?(options: Options): CallableInvocationStarted<any, any, any> | undefined;
22
+ progress?(options: Options): ProgressReceiver<InvocationProgress> | undefined;
23
+ output?(options: Options): InvocationOutputReceiver<any, any> | undefined;
24
+ }
25
+ export declare function bindCallSource<Definition extends ChildCallable, Options, Source>(definition: Definition, source: Omit<CallableSourceBinding<Options, Source, NoInfer<Definition>>, 'definition'>): CallableSourceBinding<Options, Source, Definition>;
26
+ interface FixedSource<Options> {
27
+ readonly capture?: (input: unknown, options: Options) => InvocationResources;
28
+ readonly started?: (options: Options) => CallableInvocationStarted<any, any, any> | undefined;
29
+ readonly progress?: (input: unknown, options: Options) => ProgressReceiver<InvocationProgress> | undefined;
30
+ readonly output?: (input: unknown, options: Options) => InvocationOutputReceiver<any, any> | undefined;
31
+ }
32
+ export declare class CallableSources<Options = unknown> implements CallInstallation<Options> {
33
+ private readonly sources;
34
+ private readonly validate?;
35
+ constructor(sources: ReadonlyMap<AnyCallable, FixedSource<Options>>, validate?: ((options: Options) => void) | undefined);
36
+ begin(options: Options, feedback?: CallableFeedback): CallableCallScope<Options>;
37
+ require(value: object | undefined): CallableCallScope<Options>;
38
+ prepare(definition: AnyCallable, input: unknown, options: Options, restoring: boolean): PreparedCall;
39
+ }
40
+ export declare function bindCallableSources<Input, Options, Source>(root: ResolvedCallable, providers: readonly ResourceProvider<Source>[], source: CallableCallSource<Input, Options, Source>, bindings: readonly CallableSourceBinding<Options, Source>[]): CallableSources<Options>;
41
+ export {};
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{InvocationResources}from"@weiliang0121/capix-invocation";import{ResourceSupply,checkResourceProviders,resourceRequests}from"@weiliang0121/capix-resources";import{CallableCallScope}from"../binding/calls.js";import{stableValue}from"@weiliang0121/capix-contracts";function bindCallSource(definition,source){return Object.freeze({definition,...source})}__name(bindCallSource,"bindCallSource");class CallableSources{static{__name(this,"CallableSources")}sources;validate;constructor(sources,validate){this.sources=sources,this.validate=validate}begin(options,feedback){return this.validate?.(options),new CallableCallScope(this,options,feedback)}require(value){if(!(value instanceof CallableCallScope)||!value.belongsTo(this))throw new Error("Call construction belongs to another binding installation");return value}prepare(definition,input,options,restoring){const source=this.sources.get(definition);if(!source)throw new Error("Callable source is not registered in this installation");const fixedInput=stableValue(input);return{supply:source.capture?.(fixedInput,options).supply,started:restoring?void 0:source.started?.(options),progress:source.progress?.(fixedInput,options),output:source.output?.(fixedInput,options)}}}function bindCallableSources(root,providers,source,bindings){const registered=new Map;for(const binding of bindings){if(binding.definition===root.definition)throw new Error("The root callable source must be configured through source");if(registered.has(binding.definition))throw new Error("Duplicate callable source binding");registered.set(binding.definition,binding)}const fixed=new Map,rootCapture=source.capture.bind(source),rootStarted=source.started?.bind(source),rootProgress=source.progress?.bind(source),rootOutput=source.output?.bind(source),validate=source.validate?.bind(source),visit=__name(resolved=>{if(fixed.has(resolved.definition))return;const requests=resourceRequests(resolved.supply);checkResourceProviders(requests,providers);const offers=new Set(requests.map(request=>request.offer)),selected=providers.filter(provider=>offers.has(provider.offer)).map(provider=>Object.freeze({offer:provider.offer,readMaterial:provider.readMaterial.bind(provider)})),capture=__name(value=>new InvocationResources(resolved.supply,ResourceSupply.capture(selected,value).entries),"capture");if(resolved===root)fixed.set(resolved.definition,{capture:__name((input,options)=>capture(rootCapture(input,options)),"capture"),started:rootStarted,progress:rootProgress?(input,options)=>rootProgress(input,options):void 0,output:rootOutput?(input,options)=>rootOutput(input,options):void 0});else{const binding=registered.get(resolved.definition),select=binding?.capture?.bind(binding),progress=binding?.progress?.bind(binding),output=binding?.output?.bind(binding);fixed.set(resolved.definition,{capture:select?(input,options)=>capture(select(input,options)):void 0,started:binding?.started?.bind(binding),progress:progress?(_input,options)=>progress(options):void 0,output:output?(_input,options)=>output(options):void 0})}for(const member of resolved.members)visit(member)},"visit");visit(root);for(const definition of registered.keys())if(!fixed.has(definition))throw new Error("Call source requires a registered member");return new CallableSources(fixed,validate)}__name(bindCallableSources,"bindCallableSources");export{CallableSources,bindCallSource,bindCallableSources};
@@ -0,0 +1,24 @@
1
+ export type DriverFact = Readonly<{
2
+ driverId: string;
3
+ sequence: number;
4
+ occurredAt: string;
5
+ } & ({
6
+ kind: 'established';
7
+ } | ({
8
+ boundId: string;
9
+ } & ({
10
+ kind: 'acquired';
11
+ } | {
12
+ kind: 'released';
13
+ } | {
14
+ kind: 'rejected';
15
+ reason: 'busy';
16
+ error: unknown;
17
+ } | {
18
+ kind: 'entry-failed';
19
+ error: unknown;
20
+ })))>;
21
+ export interface DriverObserver {
22
+ observe(fact: DriverFact): undefined;
23
+ available?(): boolean;
24
+ }
@@ -0,0 +1 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
@@ -0,0 +1,3 @@
1
+ export * from './records/observation/declaration.js';
2
+ export * from './records/observation/installation.js';
3
+ export * from './records/observation/invocation.js';
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ export*from"./records/observation/declaration.js";export*from"./records/observation/installation.js";export*from"./records/observation/invocation.js";
@@ -0,0 +1,18 @@
1
+ import type { InvocationRelationIdentity } from '@weiliang0121/capix-protocol';
2
+ import type { InvocationFact } from '@weiliang0121/capix-invocation';
3
+ import { ResourceOffer } from '@weiliang0121/capix-resources';
4
+ import type { InvocationRecording } from './invocation.js';
5
+ export interface InvocationRecordDescription<Input = unknown, Output = unknown> {
6
+ readonly role?: string;
7
+ readonly input?: (input: Input) => unknown;
8
+ readonly output?: (output: Output) => unknown;
9
+ readonly relationAccepted?: (output: unknown, relation: InvocationRelationIdentity) => unknown;
10
+ readonly relationHandled?: (output: unknown, relation: InvocationRelationIdentity) => unknown;
11
+ }
12
+ export interface InvocationRecordWriter {
13
+ observe(fact: InvocationFact, description?: InvocationRecordDescription): undefined;
14
+ }
15
+ export declare const InvocationRecordAccess: ResourceOffer<InvocationRecording, InvocationRecordWriter, InvocationRecording, never>;
16
+ export declare function invocationRecording<Input = unknown, Output = unknown>(description?: InvocationRecordDescription<Input, Output>, options?: {
17
+ failure?: 'isolate' | 'propagate';
18
+ }): import("../../definition/observation.js").ObservationDeclaration<InvocationFact>;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{defineObservation}from"../../definition/observation.js";import{ResourceOffer}from"@weiliang0121/capix-resources";const InvocationRecordAccess=new ResourceOffer({name:"observation.call-record",expose:__name((recording,activity)=>Object.freeze({observe(fact,description){activity.validate(),recording.observeDescribed(fact,description)}}),"expose")});function invocationRecording(description={},options={}){const input=description.input?.bind(description),output=description.output?.bind(description),relationAccepted=description.relationAccepted?.bind(description),relationHandled=description.relationHandled?.bind(description),mapped={...description.role!==void 0?{role:description.role}:{},...input?{input:__name(value=>input(value),"input")}:{},...output?{output:__name(value=>output(value),"output")}:{},...relationAccepted?{relationAccepted}:{},...relationHandled?{relationHandled}:{}};return defineObservation({deps:{record:InvocationRecordAccess.request()},observe(fact,ports){return ports.record.observe(fact,mapped)}},options)}__name(invocationRecording,"invocationRecording");export{InvocationRecordAccess,invocationRecording};
@@ -0,0 +1,37 @@
1
+ import type { MemoryEvent, TranscriptEvent } from '@weiliang0121/capix-protocol';
2
+ import type { InvocationObservationSetup, ObservationInstallation } from '../../binding/observation.js';
3
+ import type { ObservationDeclarationScope } from '../../definition/observation.js';
4
+ import { type InvocationObserver } from '@weiliang0121/capix-invocation';
5
+ import type { EventConsumer } from '@weiliang0121/capix-changes';
6
+ import type { Recorder, RecordingRootRecord } from '@weiliang0121/capix-records';
7
+ import { type RecordWriter } from '@weiliang0121/capix-records/construction';
8
+ import { type ResourceBinding } from '@weiliang0121/capix-resources';
9
+ import { type InvocationRecordDescription } from './declaration.js';
10
+ import type { CallableInput, CallableOutput } from '@weiliang0121/capix-contracts';
11
+ import { InvocationRecording } from './invocation.js';
12
+ export interface RecordingOptions {
13
+ readonly failure?: 'isolate' | 'propagate';
14
+ readonly invalidate?: (error: unknown) => void;
15
+ }
16
+ export declare class RecordingInstallation implements ObservationInstallation {
17
+ #private;
18
+ readonly recorder: Recorder;
19
+ private readonly options;
20
+ readonly root: RecordingRootRecord;
21
+ readonly records: ResourceBinding<{
22
+ record: RecordWriter;
23
+ }>;
24
+ readonly provides: Readonly<{
25
+ record: import("@weiliang0121/capix-resources").ResourceRequest<import("./declaration.js").InvocationRecordWriter>;
26
+ }>;
27
+ readonly transcript: EventConsumer<TranscriptEvent>;
28
+ readonly memory: EventConsumer<MemoryEvent>;
29
+ readonly failure: 'isolate' | 'propagate';
30
+ constructor(recorder: Recorder, options?: RecordingOptions);
31
+ describe<Structure extends ObservationDeclarationScope>(structure: Structure, description: InvocationRecordDescription<CallableInput<Structure>, CallableOutput<Structure>>): this;
32
+ declarations(structure: ObservationDeclarationScope): import("../../definition/observation.js").ObservationDeclaration<import("@weiliang0121/capix-invocation").InvocationFact>[];
33
+ bindInvocation(setup: InvocationObservationSetup, parent?: InvocationObserver): InvocationRecording;
34
+ invalidate(error: unknown): void;
35
+ private consumer;
36
+ }
37
+ export declare function bindRecording(recorder: Recorder, options?: RecordingOptions): RecordingInstallation;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{ObservationError}from"@weiliang0121/capix-invocation";import{RecordWriterResource}from"@weiliang0121/capix-records/construction";import{Resource,Resources}from"@weiliang0121/capix-resources";import{InvocationRecordAccess,invocationRecording}from"./declaration.js";import{assertStructureConfigurable}from"@weiliang0121/capix-structure/construction";import{InvocationRecording}from"./invocation.js";import{memoryRecord,transcriptRecord}from"./mapping.js";class RecordingInstallation{static{__name(this,"RecordingInstallation")}recorder;options;#descriptions=new WeakMap;root;records;provides=Object.freeze({record:InvocationRecordAccess.request()});transcript=this.consumer((event,writer)=>writer.add(transcriptRecord(event)));memory=this.consumer((event,writer)=>writer.add(memoryRecord(event)));failure;constructor(recorder,options={}){this.recorder=recorder,this.options=options,this.records=new Resources().register(new Resource(recorder),RecordWriterResource).bind({record:RecordWriterResource.request()});const access=this.records.open();try{this.root=access.endpoints.record.root()}finally{access.close()}this.failure=options.failure??"isolate"}describe(structure,description){if(assertStructureConfigurable(structure),this.#descriptions.has(structure))throw new Error("Recording description is already registered for this structure");return this.#descriptions.set(structure,description),this}declarations(structure){return[invocationRecording(this.#descriptions.get(structure))]}bindInvocation(setup,parent){if(parent&&!(parent instanceof InvocationRecording))throw new Error("Recording parent belongs to another observation capability");return new InvocationRecording(this,setup,parent)}invalidate(error){this.options.invalidate?.(error)}consumer(work){let active=!0;return{publish:__name(event=>{if(active)try{const access=this.records.open();try{work(event,access.endpoints.record)}finally{access.close()}return}catch(cause){active=!1;const error=new ObservationError(cause);return this.invalidate(error),this.failure==="propagate"?error:void 0}},"publish")}}}function bindRecording(recorder,options={}){return new RecordingInstallation(recorder,options)}__name(bindRecording,"bindRecording");export{RecordingInstallation,bindRecording};
@@ -0,0 +1,34 @@
1
+ import { InvocationResources, type InvocationFact, type ResourceObservation, type InvocationObserver } from '@weiliang0121/capix-invocation';
2
+ import type { MemoryEvent, TranscriptEvent } from '@weiliang0121/capix-protocol';
3
+ import type { InvocationObservationSetup } from '../../binding/observation.js';
4
+ import { CallableRecord } from '@weiliang0121/capix-records';
5
+ import { type InvocationRecordDescription, type InvocationRecordWriter } from './declaration.js';
6
+ import type { RecordingInstallation } from './installation.js';
7
+ export declare class InvocationRecording implements InvocationObserver {
8
+ #private;
9
+ private readonly installation;
10
+ readonly setup: InvocationObservationSetup;
11
+ private readonly parentRecording?;
12
+ readonly resources: InvocationResources<{
13
+ record: InvocationRecordWriter;
14
+ }>;
15
+ constructor(installation: RecordingInstallation, setup: InvocationObservationSetup, parentRecording?: InvocationRecording | undefined);
16
+ get record(): CallableRecord | undefined;
17
+ available(): boolean;
18
+ observe(_fact: InvocationFact): undefined;
19
+ observeDescribed(fact: InvocationFact, description?: InvocationRecordDescription): void;
20
+ resource(fact: ResourceObservation): void;
21
+ transcript(event: TranscriptEvent): void;
22
+ memory(event: MemoryEvent): void;
23
+ private requireRecord;
24
+ private checkOrigin;
25
+ private source;
26
+ private begin;
27
+ private process;
28
+ private relation;
29
+ private finish;
30
+ private timingRoot;
31
+ private offset;
32
+ private boundary;
33
+ private protect;
34
+ }
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{InvocationResources,RuntimeErrorHelper,failureFact}from"@weiliang0121/capix-invocation";import{isUndefined}from"es-toolkit/predicate";import{pick}from"es-toolkit/object";import{ResourceSupply,resourceRequests}from"@weiliang0121/capix-resources";import{CallableRecord,InvocationRecordHelper,ResourceRecord}from"@weiliang0121/capix-records";import{InvocationRecordAccess}from"./declaration.js";import{memoryRecord,recordedResult,transcriptRecord}from"./mapping.js";class InvocationRecording{static{__name(this,"InvocationRecording")}installation;setup;parentRecording;resources;#childRecordings=new Map;#pendingAttachments=[];#record;#startedTick;#failed=!1;#enabled;#recordDescription={};constructor(installation,setup,parentRecording){if(this.installation=installation,this.setup=setup,this.parentRecording=parentRecording,this.#enabled=(setup.declarations??[]).some(declaration=>resourceRequests(declaration.deps).some(request=>request.offer===InvocationRecordAccess.request().offer)),parentRecording&&parentRecording.installation!==installation)throw new Error("Recording parent belongs to another installation");parentRecording&&parentRecording.#childRecordings.set(setup.identity.contextId,this),this.resources=new InvocationResources({record:InvocationRecordAccess.request()},ResourceSupply.capture([InvocationRecordAccess.provide(()=>this)],void 0).entries)}get record(){return this.#record}available(){return this.#enabled&&!this.#failed&&(this.parentRecording?.available()??!0)}observe(_fact){}observeDescribed(fact,description={}){this.protect(writer=>{if(fact.identity.contextId!==this.setup.identity.contextId||fact.identity.kind!==this.setup.identity.kind)throw new Error("Call fact belongs to another local observation");this.#recordDescription=description,fact.kind==="started"?this.begin(fact,writer):fact.kind==="process"?this.process(fact,writer):fact.kind==="relation"?!this.#record&&fact.change.kind==="attached"?this.#pendingAttachments.push({...fact,identity:{...fact.identity},relation:{...fact.relation},change:{kind:"attached"}}):this.relation(fact,writer):this.finish(fact,writer)})}resource(fact){this.protect(writer=>{const record=this.requireRecord();if(fact.contextId!==record.contextId)throw new Error("Resource fact belongs to another call");writer.add(new ResourceRecord({parentId:record.id,access:fact.access,supplyId:fact.supplyId,sequence:fact.sequence,occurredAt:fact.occurredAt,phase:fact.phase,...fact.interactionId?{interactionId:fact.interactionId}:{}},fact.describe()))})}transcript(event){this.protect(writer=>{this.checkOrigin(event.origin),writer.add(transcriptRecord(event,this.source()))})}memory(event){this.protect(writer=>{this.checkOrigin(event.origin),writer.add(memoryRecord(event,this.source()))})}requireRecord(){if(!this.#record)throw new Error("The call recording has not started");return this.#record}checkOrigin(origin){if(origin?.contextId!==this.setup.identity.contextId)throw new Error("Entity fact belongs to another call")}source(){const record=this.requireRecord();return{contextId:record.contextId,callId:record.id}}begin(fact,writer){if(this.#record)throw new Error("A call recording can only start once");const input=this.#recordDescription.input?this.#recordDescription.input(fact.input):fact.input,description=fact.description??this.setup.description??{},parentRecord=this.parentRecording?.requireRecord();if(fact.identity.parentContextId!==void 0!=!!parentRecord||parentRecord&&parentRecord.contextId!==fact.identity.parentContextId)throw new Error("Call recording parent differs from its invocation relationship");this.#record=writer.add(new CallableRecord({contextId:fact.identity.contextId,structureKind:fact.identity.kind,parentId:parentRecord?.id??this.installation.root.id,...description.id!==void 0?{structureId:description.id}:{},...pick(description,["name","label","source"]),...this.#recordDescription.role!==void 0||description.role!==void 0?{role:this.#recordDescription.role??description.role}:{}},{input,startedAt:fact.occurredAt})),this.#startedTick=fact.monotonicTime,this.boundary(fact,"call",writer);for(const attachment of this.#pendingAttachments.splice(0))this.relation(attachment,writer,Math.max(0,this.offset(attachment.monotonicTime)))}process(fact,writer){const record=this.requireRecord(),process=fact.process;let body;"error"in process?body={...process,error:RuntimeErrorHelper.format(process.error),...process.failure?{failure:failureFact(process.failure)}:{}}:"input"in process&&this.#recordDescription.input?body={...process,input:this.#recordDescription.input(process.input)}:"output"in process&&this.#recordDescription.output?body={...process,output:this.#recordDescription.output(process.output)}:body=process;const entry={...body,sequence:fact.processSequence,eventSequence:fact.eventSequence,round:fact.round,occurredAt:fact.occurredAt,offsetMs:this.offset(fact.monotonicTime)};writer.update(record,current=>current.append(entry),current=>({kind:"process-appended",id:current.id,process:current.value.processes.at(-1)}))}relation(fact,writer,offsetMs=this.offset(fact.monotonicTime)){const record=this.requireRecord(),childRecording=this.#childRecordings.get(fact.relation.childContextId);if(fact.relation.parentContextId!==record.contextId)throw new Error("Relation fact belongs to another parent");let change;fact.change.kind==="returned"?change={kind:"returned",result:recordedResult(fact.change.result,childRecording?childRecording.#recordDescription:void 0)}:fact.change.kind==="accepted"&&this.#recordDescription.relationAccepted?change={kind:"accepted",output:this.#recordDescription.relationAccepted(fact.change.output,fact.relation)}:fact.change.kind==="handled"&&this.#recordDescription.relationHandled?change={kind:"handled",output:this.#recordDescription.relationHandled(fact.change.output,fact.relation)}:fact.change.kind==="failed"?change={kind:"failed",source:fact.change.source,error:RuntimeErrorHelper.format(fact.change.error),...fact.change.failure?{failure:failureFact(fact.change.failure)}:{}}:change=fact.change;const relation={identity:fact.relation,eventSequence:fact.eventSequence,occurredAt:fact.occurredAt,offsetMs,...childRecording?.record?{childId:childRecording.record.id}:{},change};writer.update(record,current=>current.appendRelation(relation),current=>({kind:"relation-appended",id:current.id,relation:current.value.relationChanges.at(-1)}))}finish(fact,writer){const state=fact.state;if(!this.#record&&state.status==="failed")return;const record=this.requireRecord();if(state.status==="running")throw new Error("A terminal call fact requires an outcome");if(state.status==="failed")InvocationRecordHelper.finish(writer,record,current=>current.fail(RuntimeErrorHelper.format(state.error),state.failure?failureFact(state.failure):void 0));else{const last=record.value.processes.at(-1),resultOf=last?.type==="return"?"resultOf"in last?last.resultOf:last.sequence:void 0,output=isUndefined(resultOf)?this.#recordDescription.output?this.#recordDescription.output(state.output):state.output:void 0;InvocationRecordHelper.finish(writer,record,current=>current.complete(output,resultOf))}this.boundary(fact,state.status==="succeeded"?"return":"throw",writer)}timingRoot(){let recording=this;for(;recording.parentRecording;)recording=recording.parentRecording;return recording}offset(time){const timingRecording=this.timingRoot();if(isUndefined(timingRecording.#startedTick))throw new Error("Call recording has no timing origin");return time-timingRecording.#startedTick}boundary(fact,type,writer){const timingRecording=this.timingRoot();writer.boundary({start:timingRecording.#startedTick,scopeId:timingRecording.requireRecord().id,callId:this.requireRecord().id,occurredAt:fact.occurredAt,offsetMs:this.offset(fact.monotonicTime)},type)}protect(work){if(this.available())try{const access=this.installation.records.open();try{work(access.endpoints.record)}finally{access.close()}}catch(error){throw this.#failed=!0,this.installation.invalidate(error),error}}}export{InvocationRecording};
@@ -0,0 +1,7 @@
1
+ import type { MemoryEvent, TranscriptEvent, RecordedInvocationResult } from '@weiliang0121/capix-protocol';
2
+ import { type InvocationResult } from '@weiliang0121/capix-invocation';
3
+ import { MemoryRecord, TranscriptRecord, type RecordChangeSource } from '@weiliang0121/capix-records';
4
+ import type { InvocationRecordDescription } from './declaration.js';
5
+ export declare function recordedResult(result: InvocationResult<unknown>, description?: InvocationRecordDescription): RecordedInvocationResult;
6
+ export declare function transcriptRecord(event: TranscriptEvent, source?: RecordChangeSource): TranscriptRecord;
7
+ export declare function memoryRecord(event: MemoryEvent, source?: RecordChangeSource): MemoryRecord;
@@ -0,0 +1,2 @@
1
+ /*! MIT License | Copyright (c) 2026 wei.liang | See LICENSE */
2
+ var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});import{RuntimeErrorHelper,failureFact}from"@weiliang0121/capix-invocation";import{MemoryRecord,TranscriptRecord}from"@weiliang0121/capix-records";function recordedResult(result,description){return result.status==="succeeded"?{status:"succeeded",output:description?.output?description.output(result.output):result.output}:{status:"failed",error:RuntimeErrorHelper.format(result.error),...result.failure?{failure:failureFact(result.failure)}:{}}}__name(recordedResult,"recordedResult");function transcriptRecord(event,source){const change=event.change;return new TranscriptRecord({transcriptId:event.transcriptId,revision:event.revision,occurredAt:event.occurredAt,...source?{source}:{}},change.kind==="messages-appended"?{action:"append",start:change.start,end:change.start+change.messages.length}:{action:"segment",previousStart:change.previousStart,start:change.start,end:change.end})}__name(transcriptRecord,"transcriptRecord");function memoryRecord(event,source){return new MemoryRecord({memoriesId:event.memoriesId,memoryId:event.change.memoryId,sequence:event.sequence,...source?{source}:{}},{action:event.change.action,change:event.change.explanation,sourceIndexes:event.change.sourceIndexes,...event.change.sourceResults?{sourceResults:event.change.sourceResults}:{},result:event.change.result})}__name(memoryRecord,"memoryRecord");export{memoryRecord,recordedResult,transcriptRecord};