@fabricorg/platform-host 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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, ActionDefinition, 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;
@@ -69,6 +92,24 @@ interface PlatformHostStore<TDb> {
69
92
  nextEventSequence(tenantId: string, spaceId: string): Promise<number>;
70
93
  getEntityState(tenantId: string, spaceId: string, entityType: string, entityId: string): Promise<string | undefined>;
71
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
+ }
72
113
  interface ListActionInvocationsInput {
73
114
  tenantId?: string;
74
115
  spaceId?: string;
@@ -103,6 +144,10 @@ interface ActionAuthorizationInput {
103
144
  interface PlatformHostAuthorization {
104
145
  checkEntitlement(input: ActionAuthorizationInput): Promise<boolean>;
105
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>;
106
151
  }
107
152
  interface DispatchActionInput {
108
153
  actionInvocationId: string;
@@ -136,12 +181,20 @@ interface SubmitActionResult {
136
181
  runId?: string;
137
182
  result?: Record<string, unknown>;
138
183
  error?: string;
184
+ hitlRoute?: AgentActionRoute;
185
+ hitlRiskTier?: AgentActionRiskTier;
139
186
  }
140
187
  interface ExecuteActionResult {
141
188
  actionInvocationId: string;
142
189
  status: ActionStatus;
143
190
  result?: Record<string, unknown>;
144
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;
145
198
  }
146
199
  interface PlatformActionWorkerOptions<TDb> {
147
200
  host: GovernedActionHost;
@@ -159,19 +212,31 @@ interface PlatformActionWorkerCycleResult {
159
212
  claimed: number;
160
213
  completed: number;
161
214
  failed: number;
215
+ /** Present when claimed agent work was durably parked instead of failing. */
216
+ waitingForApproval?: number;
162
217
  }
163
218
  interface PlatformHostOptions<TDb> {
164
219
  store: PlatformHostStore<TDb>;
165
220
  authorization: PlatformHostAuthorization;
221
+ /** Resolve vertical- or runtime-local actions without mutating the process-wide registry. */
222
+ resolveAction?: (actionId: ActionId) => ActionDefinition<TDb> | undefined;
166
223
  adapters?: readonly AdapterImplementation[];
167
224
  dispatcher?: PlatformActionDispatcher;
168
225
  services?: FabricRuntimeServices;
226
+ /** Optional vertical-owned evaluator. When absent, agent behavior is unchanged. */
227
+ hitlEvaluator?: AgentActionPolicyEvaluator;
228
+ /** Durable evaluator/ruleset version recorded with every HITL decision. */
229
+ hitlPolicyVersion?: string;
230
+ /** Lease held while an approved invocation resumes; defaults to five minutes. */
231
+ approvalResumeLeaseDurationMs?: number;
169
232
  /** Remove forbidden/sensitive fields before durable invocation persistence. */
170
233
  redactActionParameters?: (actionId: ActionId, parameters: Record<string, unknown>) => Record<string, unknown>;
171
234
  resolvePolicies?: (input: ActionAuthorizationInput & {
172
235
  declaredPolicyIds: readonly string[];
173
236
  }) => Promise<RuntimePolicyDefinition[]>;
174
237
  extractEvents?: (data: Record<string, unknown>) => PendingAssetEvent[];
238
+ /** Handler-result fields consumed by extractEvents and omitted from the durable result. */
239
+ eventResultFields?: readonly string[];
175
240
  redactAdapterInput?: (actionId: ActionId, adapterType: string, operation: string, input: Record<string, unknown>) => Record<string, unknown>;
176
241
  adapterEventSubject?: (actionId: ActionId, parameters: unknown, handlerResult: Record<string, unknown>) => {
177
242
  subjectType: string;
@@ -181,12 +246,13 @@ interface PlatformHostOptions<TDb> {
181
246
  }
182
247
  interface GovernedActionHost {
183
248
  submitAction(input: SubmitActionInput): Promise<SubmitActionResult>;
184
- executeInvocation(actionInvocationId: string, tenantId: string, spaceId: string): Promise<ExecuteActionResult>;
249
+ executeInvocation(actionInvocationId: string, tenantId: string, spaceId: string, options?: ExecuteInvocationOptions): Promise<ExecuteActionResult>;
250
+ resumeApprovedInvocation(actionInvocationId: string, tenantId: string, spaceId: string, decision: ActionApprovalDecision): Promise<ExecuteActionResult>;
185
251
  }
186
252
 
187
253
  declare function createGovernedActionHost<TDb>(options: PlatformHostOptions<TDb>): GovernedActionHost;
188
254
 
189
- declare class MemoryPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
255
+ declare class MemoryPlatformHostStore<TDb> implements RecoverablePlatformHostStore<TDb>, ApprovalPlatformHostStore<TDb> {
190
256
  readonly db: TDb;
191
257
  readonly invocations: ActionInvocationRecord[];
192
258
  readonly policyEvaluations: PolicyEvaluationRecord[];
@@ -197,6 +263,8 @@ declare class MemoryPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
197
263
  createActionInvocation(input: CreateActionInvocationInput): Promise<ActionInvocationRecord>;
198
264
  getActionInvocation(id: string, tenantId: string, spaceId: string): Promise<ActionInvocationRecord | undefined>;
199
265
  updateActionInvocation(id: string, tenantId: string, spaceId: string, patch: Partial<Pick<ActionInvocationRecord, "status" | "result" | "error">>): Promise<void>;
266
+ recordHitlDecision(actionInvocationId: string, tenantId: string, spaceId: string, decision: HitlDecisionEvidence): Promise<ActionInvocationRecord>;
267
+ beginApprovalDecision(input: BeginApprovalDecisionInput): Promise<ApprovalDecisionTransitionResult>;
200
268
  appendPolicyEvaluation(record: PolicyEvaluationRecord): Promise<void>;
201
269
  createAdapterInvocation(record: AdapterInvocationRecord): Promise<void>;
202
270
  getAdapterInvocation(id: string): Promise<AdapterInvocationRecord | undefined>;
@@ -217,7 +285,7 @@ interface PlatformHostSqlClient {
217
285
  query<Row = Record<string, unknown>>(sql: string, values?: unknown[]): Promise<PlatformHostSqlResult<Row>>;
218
286
  }
219
287
  /** Durable mutation-pipeline ledger for Databricks Lakebase or standard Postgres. */
220
- declare class PostgresPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
288
+ declare class PostgresPlatformHostStore<TDb> implements RecoverablePlatformHostStore<TDb>, ApprovalPlatformHostStore<TDb> {
221
289
  readonly db: TDb;
222
290
  private readonly sql;
223
291
  constructor(db: TDb, sql: PlatformHostSqlClient);
@@ -226,6 +294,8 @@ declare class PostgresPlatformHostStore<TDb> implements PlatformHostStore<TDb> {
226
294
  createActionInvocation(input: CreateActionInvocationInput): Promise<ActionInvocationRecord>;
227
295
  getActionInvocation(id: string, tenantId: string, spaceId: string): Promise<ActionInvocationRecord | undefined>;
228
296
  updateActionInvocation(id: string, tenantId: string, spaceId: string, patch: Partial<Pick<ActionInvocationRecord, "status" | "result" | "error">>): Promise<void>;
297
+ recordHitlDecision(actionInvocationId: string, tenantId: string, spaceId: string, decision: HitlDecisionEvidence): Promise<ActionInvocationRecord>;
298
+ beginApprovalDecision(input: BeginApprovalDecisionInput): Promise<ApprovalDecisionTransitionResult>;
229
299
  appendPolicyEvaluation(record: PolicyEvaluationRecord): Promise<void>;
230
300
  createAdapterInvocation(record: AdapterInvocationRecord): Promise<void>;
231
301
  getAdapterInvocation(id: string): Promise<AdapterInvocationRecord | undefined>;
@@ -248,4 +318,4 @@ declare function runPlatformActionWorkerCycle<TDb>(options: PlatformActionWorker
248
318
  /** Poll until aborted. Each iteration is bounded and waits without busy-spinning. */
249
319
  declare function runPlatformActionWorker<TDb>(options: PlatformActionWorkerOptions<TDb>): Promise<void>;
250
320
 
251
- 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 };
321
+ 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 };