@fabricorg/platform-host 0.3.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActionId, ActorType, ActionStatus, PolicyOutcome, AssetEventEnvelope, AdapterImplementation, FabricRuntimeServices, RuntimePolicyDefinition } from '@fabricorg/platform';
1
+ import { ActorType, ActionId, ActionStatus, AgentActionRoute, AgentActionRiskTier, PolicyOutcome, AssetEventEnvelope, AdapterImplementation, FabricRuntimeServices, AgentActionPolicyEvaluator, RuntimePolicyDefinition } from '@fabricorg/platform';
2
2
 
3
3
  interface PendingAssetEvent {
4
4
  eventType: string;
@@ -24,10 +24,33 @@ interface ActionInvocationRecord {
24
24
  attemptCount: number;
25
25
  leaseOwner?: string;
26
26
  leaseExpiresAt?: Date;
27
+ hitlRoute?: AgentActionRoute;
28
+ hitlRiskTier?: AgentActionRiskTier;
29
+ hitlReason?: string;
30
+ hitlPolicyVersion?: string;
31
+ approvalDecision?: PersistedActionApprovalDecision;
27
32
  error?: string;
28
33
  createdAt: Date;
29
34
  updatedAt: Date;
30
35
  }
36
+ interface HitlDecisionEvidence {
37
+ route: AgentActionRoute;
38
+ riskTier: AgentActionRiskTier;
39
+ reason: string;
40
+ policyVersion?: string;
41
+ evaluatedAt: Date;
42
+ }
43
+ interface ActionApprovalDecision {
44
+ approved: boolean;
45
+ approverId: string;
46
+ approverType: ActorType;
47
+ reason?: string;
48
+ editsReference?: string;
49
+ decidedAt?: Date;
50
+ }
51
+ interface PersistedActionApprovalDecision extends Omit<ActionApprovalDecision, "decidedAt"> {
52
+ decidedAt: Date;
53
+ }
31
54
  interface PolicyEvaluationRecord {
32
55
  id: string;
33
56
  actionInvocationId: string;
@@ -63,11 +86,30 @@ interface PlatformHostStore<TDb> {
63
86
  updateActionInvocation(id: string, tenantId: string, spaceId: string, patch: Partial<Pick<ActionInvocationRecord, "status" | "result" | "error">>): Promise<void>;
64
87
  appendPolicyEvaluation(record: PolicyEvaluationRecord): Promise<void>;
65
88
  createAdapterInvocation(record: AdapterInvocationRecord): Promise<void>;
89
+ getAdapterInvocation(id: string): Promise<AdapterInvocationRecord | undefined>;
66
90
  updateAdapterInvocation(id: string, patch: Partial<Pick<AdapterInvocationRecord, "status" | "output" | "error" | "attempt" | "updatedAt">>): Promise<void>;
67
91
  appendEvent(event: AssetEventEnvelope): Promise<void>;
68
92
  nextEventSequence(tenantId: string, spaceId: string): Promise<number>;
69
93
  getEntityState(tenantId: string, spaceId: string, entityType: string, entityId: string): Promise<string | undefined>;
70
94
  }
95
+ interface BeginApprovalDecisionInput {
96
+ actionInvocationId: string;
97
+ tenantId: string;
98
+ spaceId: string;
99
+ decision: PersistedActionApprovalDecision;
100
+ leaseOwner: string;
101
+ leaseDurationMs: number;
102
+ now: Date;
103
+ }
104
+ interface ApprovalDecisionTransitionResult {
105
+ applied: boolean;
106
+ invocation?: ActionInvocationRecord;
107
+ }
108
+ /** Optional store capability required only when agent HITL or approval resume is used. */
109
+ interface ApprovalPlatformHostStore<TDb> extends PlatformHostStore<TDb> {
110
+ recordHitlDecision(actionInvocationId: string, tenantId: string, spaceId: string, decision: HitlDecisionEvidence): Promise<ActionInvocationRecord>;
111
+ beginApprovalDecision(input: BeginApprovalDecisionInput): Promise<ApprovalDecisionTransitionResult>;
112
+ }
71
113
  interface ListActionInvocationsInput {
72
114
  tenantId?: string;
73
115
  spaceId?: string;
@@ -102,6 +144,10 @@ interface ActionAuthorizationInput {
102
144
  interface PlatformHostAuthorization {
103
145
  checkEntitlement(input: ActionAuthorizationInput): Promise<boolean>;
104
146
  authorize(input: ActionAuthorizationInput): Promise<boolean>;
147
+ /** Optional distinct authorization boundary for human/system approval decisions. */
148
+ authorizeApproval?(input: ActionAuthorizationInput & {
149
+ decision: ActionApprovalDecision;
150
+ }): Promise<boolean>;
105
151
  }
106
152
  interface DispatchActionInput {
107
153
  actionInvocationId: string;
@@ -135,12 +181,20 @@ interface SubmitActionResult {
135
181
  runId?: string;
136
182
  result?: Record<string, unknown>;
137
183
  error?: string;
184
+ hitlRoute?: AgentActionRoute;
185
+ hitlRiskTier?: AgentActionRiskTier;
138
186
  }
139
187
  interface ExecuteActionResult {
140
188
  actionInvocationId: string;
141
189
  status: ActionStatus;
142
190
  result?: Record<string, unknown>;
143
191
  error?: string;
192
+ hitlRoute?: AgentActionRoute;
193
+ hitlRiskTier?: AgentActionRiskTier;
194
+ }
195
+ interface ExecuteInvocationOptions {
196
+ /** Required when executing a row already protected by a worker or approval-resume lease. */
197
+ leaseOwner?: string;
144
198
  }
145
199
  interface PlatformActionWorkerOptions<TDb> {
146
200
  host: GovernedActionHost;
@@ -158,6 +212,8 @@ interface PlatformActionWorkerCycleResult {
158
212
  claimed: number;
159
213
  completed: number;
160
214
  failed: number;
215
+ /** Present when claimed agent work was durably parked instead of failing. */
216
+ waitingForApproval?: number;
161
217
  }
162
218
  interface PlatformHostOptions<TDb> {
163
219
  store: PlatformHostStore<TDb>;
@@ -165,6 +221,12 @@ interface PlatformHostOptions<TDb> {
165
221
  adapters?: readonly AdapterImplementation[];
166
222
  dispatcher?: PlatformActionDispatcher;
167
223
  services?: FabricRuntimeServices;
224
+ /** Optional vertical-owned evaluator. When absent, agent behavior is unchanged. */
225
+ hitlEvaluator?: AgentActionPolicyEvaluator;
226
+ /** Durable evaluator/ruleset version recorded with every HITL decision. */
227
+ hitlPolicyVersion?: string;
228
+ /** Lease held while an approved invocation resumes; defaults to five minutes. */
229
+ approvalResumeLeaseDurationMs?: number;
168
230
  /** Remove forbidden/sensitive fields before durable invocation persistence. */
169
231
  redactActionParameters?: (actionId: ActionId, parameters: Record<string, unknown>) => Record<string, unknown>;
170
232
  resolvePolicies?: (input: ActionAuthorizationInput & {
@@ -180,12 +242,13 @@ interface PlatformHostOptions<TDb> {
180
242
  }
181
243
  interface GovernedActionHost {
182
244
  submitAction(input: SubmitActionInput): Promise<SubmitActionResult>;
183
- executeInvocation(actionInvocationId: string, tenantId: string, spaceId: string): Promise<ExecuteActionResult>;
245
+ executeInvocation(actionInvocationId: string, tenantId: string, spaceId: string, options?: ExecuteInvocationOptions): Promise<ExecuteActionResult>;
246
+ resumeApprovedInvocation(actionInvocationId: string, tenantId: string, spaceId: string, decision: ActionApprovalDecision): Promise<ExecuteActionResult>;
184
247
  }
185
248
 
186
249
  declare function createGovernedActionHost<TDb>(options: PlatformHostOptions<TDb>): GovernedActionHost;
187
250
 
188
- declare class MemoryPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
251
+ declare class MemoryPlatformHostStore<TDb> implements RecoverablePlatformHostStore<TDb>, ApprovalPlatformHostStore<TDb> {
189
252
  readonly db: TDb;
190
253
  readonly invocations: ActionInvocationRecord[];
191
254
  readonly policyEvaluations: PolicyEvaluationRecord[];
@@ -196,8 +259,11 @@ declare class MemoryPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
196
259
  createActionInvocation(input: CreateActionInvocationInput): Promise<ActionInvocationRecord>;
197
260
  getActionInvocation(id: string, tenantId: string, spaceId: string): Promise<ActionInvocationRecord | undefined>;
198
261
  updateActionInvocation(id: string, tenantId: string, spaceId: string, patch: Partial<Pick<ActionInvocationRecord, "status" | "result" | "error">>): Promise<void>;
262
+ recordHitlDecision(actionInvocationId: string, tenantId: string, spaceId: string, decision: HitlDecisionEvidence): Promise<ActionInvocationRecord>;
263
+ beginApprovalDecision(input: BeginApprovalDecisionInput): Promise<ApprovalDecisionTransitionResult>;
199
264
  appendPolicyEvaluation(record: PolicyEvaluationRecord): Promise<void>;
200
265
  createAdapterInvocation(record: AdapterInvocationRecord): Promise<void>;
266
+ getAdapterInvocation(id: string): Promise<AdapterInvocationRecord | undefined>;
201
267
  updateAdapterInvocation(id: string, patch: Partial<Pick<AdapterInvocationRecord, "status" | "output" | "error" | "attempt" | "updatedAt">>): Promise<void>;
202
268
  appendEvent(event: AssetEventEnvelope): Promise<void>;
203
269
  nextEventSequence(tenantId: string, spaceId: string): Promise<number>;
@@ -215,7 +281,7 @@ interface PlatformHostSqlClient {
215
281
  query<Row = Record<string, unknown>>(sql: string, values?: unknown[]): Promise<PlatformHostSqlResult<Row>>;
216
282
  }
217
283
  /** Durable mutation-pipeline ledger for Databricks Lakebase or standard Postgres. */
218
- declare class PostgresPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
284
+ declare class PostgresPlatformHostStore<TDb> implements RecoverablePlatformHostStore<TDb>, ApprovalPlatformHostStore<TDb> {
219
285
  readonly db: TDb;
220
286
  private readonly sql;
221
287
  constructor(db: TDb, sql: PlatformHostSqlClient);
@@ -224,8 +290,11 @@ declare class PostgresPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
224
290
  createActionInvocation(input: CreateActionInvocationInput): Promise<ActionInvocationRecord>;
225
291
  getActionInvocation(id: string, tenantId: string, spaceId: string): Promise<ActionInvocationRecord | undefined>;
226
292
  updateActionInvocation(id: string, tenantId: string, spaceId: string, patch: Partial<Pick<ActionInvocationRecord, "status" | "result" | "error">>): Promise<void>;
293
+ recordHitlDecision(actionInvocationId: string, tenantId: string, spaceId: string, decision: HitlDecisionEvidence): Promise<ActionInvocationRecord>;
294
+ beginApprovalDecision(input: BeginApprovalDecisionInput): Promise<ApprovalDecisionTransitionResult>;
227
295
  appendPolicyEvaluation(record: PolicyEvaluationRecord): Promise<void>;
228
296
  createAdapterInvocation(record: AdapterInvocationRecord): Promise<void>;
297
+ getAdapterInvocation(id: string): Promise<AdapterInvocationRecord | undefined>;
229
298
  updateAdapterInvocation(id: string, patch: Partial<Pick<AdapterInvocationRecord, "status" | "output" | "error" | "attempt" | "updatedAt">>): Promise<void>;
230
299
  appendEvent(event: AssetEventEnvelope): Promise<void>;
231
300
  nextEventSequence(tenantId: string, spaceId: string): Promise<number>;
@@ -245,4 +314,4 @@ declare function runPlatformActionWorkerCycle<TDb>(options: PlatformActionWorker
245
314
  /** Poll until aborted. Each iteration is bounded and waits without busy-spinning. */
246
315
  declare function runPlatformActionWorker<TDb>(options: PlatformActionWorkerOptions<TDb>): Promise<void>;
247
316
 
248
- export { type ActionAuthorizationInput, type ActionInvocationRecord, type AdapterInvocationRecord, type AdapterInvocationStatus, type ClaimActionInvocationsInput, type CreateActionInvocationInput, type DispatchActionInput, type DispatchActionResult, type ExecuteActionResult, type GovernedActionHost, type ListActionInvocationsInput, MemoryPlatformHostStore, type PendingAssetEvent, type PlatformActionDispatcher, type PlatformActionWorkerCycleResult, type PlatformActionWorkerOptions, type PlatformHostAuthorization, type PlatformHostOptions, type PlatformHostSqlClient, type PlatformHostSqlResult, type PlatformHostStore, type PolicyEvaluationRecord, PostgresPlatformHostStore, type RecoverablePlatformHostStore, type SubmitActionInput, type SubmitActionResult, createGovernedActionHost, createStoreBackedActionDispatcher, runPlatformActionWorker, runPlatformActionWorkerCycle };
317
+ export { type ActionApprovalDecision, type ActionAuthorizationInput, type ActionInvocationRecord, type AdapterInvocationRecord, type AdapterInvocationStatus, type ApprovalDecisionTransitionResult, type ApprovalPlatformHostStore, type BeginApprovalDecisionInput, type ClaimActionInvocationsInput, type CreateActionInvocationInput, type DispatchActionInput, type DispatchActionResult, type ExecuteActionResult, type ExecuteInvocationOptions, type GovernedActionHost, type HitlDecisionEvidence, type ListActionInvocationsInput, MemoryPlatformHostStore, type PendingAssetEvent, type PersistedActionApprovalDecision, type PlatformActionDispatcher, type PlatformActionWorkerCycleResult, type PlatformActionWorkerOptions, type PlatformHostAuthorization, type PlatformHostOptions, type PlatformHostSqlClient, type PlatformHostSqlResult, type PlatformHostStore, type PolicyEvaluationRecord, PostgresPlatformHostStore, type RecoverablePlatformHostStore, type SubmitActionInput, type SubmitActionResult, createGovernedActionHost, createStoreBackedActionDispatcher, runPlatformActionWorker, runPlatformActionWorkerCycle };