@decionis/agentsafe 0.5.0 → 0.6.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 +4 -1
- package/dist/Index.d.ts.map +1 -1
- package/dist/Index.js +4 -1
- package/dist/Index.js.map +1 -1
- package/dist/adapters/AdapterActionHandler.d.ts +36 -12
- package/dist/adapters/AdapterActionHandler.d.ts.map +1 -1
- package/dist/adapters/AdapterActionHandler.js +99 -100
- package/dist/adapters/AdapterActionHandler.js.map +1 -1
- package/dist/adapters/EffectAdapter.d.ts +7 -103
- package/dist/adapters/EffectAdapter.d.ts.map +1 -1
- package/dist/adapters/EffectAdapter.js +7 -18
- package/dist/adapters/EffectAdapter.js.map +1 -1
- package/dist/adapters/EffectAdapterExecutor.d.ts +93 -0
- package/dist/adapters/EffectAdapterExecutor.d.ts.map +1 -0
- package/dist/adapters/EffectAdapterExecutor.js +191 -0
- package/dist/adapters/EffectAdapterExecutor.js.map +1 -0
- package/dist/adapters/banking/BankingExecutor.d.ts +35 -0
- package/dist/adapters/banking/BankingExecutor.d.ts.map +1 -0
- package/dist/adapters/banking/BankingExecutor.js +64 -0
- package/dist/adapters/banking/BankingExecutor.js.map +1 -0
- package/dist/adapters/banking/BankingHandlers.d.ts.map +1 -1
- package/dist/adapters/banking/BankingHandlers.js +6 -3
- package/dist/adapters/banking/BankingHandlers.js.map +1 -1
- package/dist/adapters/cards/CardAuthorizationExecutor.d.ts +66 -0
- package/dist/adapters/cards/CardAuthorizationExecutor.d.ts.map +1 -0
- package/dist/adapters/cards/CardAuthorizationExecutor.js +116 -0
- package/dist/adapters/cards/CardAuthorizationExecutor.js.map +1 -0
- package/dist/cli/Doctor.d.ts.map +1 -1
- package/dist/cli/Doctor.js +2 -1
- package/dist/cli/Doctor.js.map +1 -1
- package/dist/journal/ExecutionJournal.d.ts +5 -120
- package/dist/journal/ExecutionJournal.d.ts.map +1 -1
- package/dist/journal/ExecutionJournal.js +5 -125
- package/dist/journal/ExecutionJournal.js.map +1 -1
- package/dist/journal/FileExecutionJournal.d.ts +1 -0
- package/dist/journal/FileExecutionJournal.d.ts.map +1 -1
- package/dist/journal/FileExecutionJournal.js +4 -1
- package/dist/journal/FileExecutionJournal.js.map +1 -1
- package/dist/journal/InMemoryExecutionJournal.d.ts +2 -1
- package/dist/journal/InMemoryExecutionJournal.d.ts.map +1 -1
- package/dist/journal/InMemoryExecutionJournal.js +4 -1
- package/dist/journal/InMemoryExecutionJournal.js.map +1 -1
- package/dist/service/TrustedExecutorService.d.ts.map +1 -1
- package/dist/service/TrustedExecutorService.js +19 -10
- package/dist/service/TrustedExecutorService.js.map +1 -1
- package/dist/time/MonotonicClock.d.ts +4 -32
- package/dist/time/MonotonicClock.d.ts.map +1 -1
- package/dist/time/MonotonicClock.js +4 -49
- package/dist/time/MonotonicClock.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,107 +1,11 @@
|
|
|
1
|
-
import type { JsonObject, JsonValue, VerifiedAuthorization } from "@decionis/agent-safe-pipeline";
|
|
2
|
-
import type { MonotonicDeadline } from "../time/MonotonicClock.js";
|
|
3
|
-
import type { Sha256 } from "./JcsDigest.js";
|
|
4
|
-
/** What the adapter worked out before anything left the process. */
|
|
5
|
-
export interface PreparedAction {
|
|
6
|
-
/** The effect the action asks for, as the profile's projection of it. */
|
|
7
|
-
readonly expectedEffect: JsonObject;
|
|
8
|
-
readonly expectedEffectDigest: Sha256;
|
|
9
|
-
/** The digest of the canonical action itself, for the authority's binding. */
|
|
10
|
-
readonly intentDigest: Sha256;
|
|
11
|
-
/** The digest of what will be sent, so a later reader can tell what was asked. */
|
|
12
|
-
readonly requestDigest: Sha256;
|
|
13
|
-
/** The resource the effect lands on, as the profile names it. */
|
|
14
|
-
readonly resourceRef: string;
|
|
15
|
-
readonly effectType: string;
|
|
16
|
-
readonly domain: string;
|
|
17
|
-
readonly actionType: string;
|
|
18
|
-
}
|
|
19
|
-
/** What the provider said, as the adapter read it. Never a body, never a credential. */
|
|
20
|
-
export interface ProviderResult {
|
|
21
|
-
readonly status: "COMMITTED" | "FAILED";
|
|
22
|
-
readonly providerStatus: string | null;
|
|
23
|
-
readonly providerReference: string | null;
|
|
24
|
-
readonly responseDigest: Sha256 | null;
|
|
25
|
-
/** A profile reason code when the provider refused; null when it accepted. */
|
|
26
|
-
readonly failureReason: string | null;
|
|
27
|
-
/** The observed effect as the adapter could read it, or null when it could not. */
|
|
28
|
-
readonly observed: JsonObject | null;
|
|
29
|
-
readonly observationMethod: ObservationMethod;
|
|
30
|
-
readonly providerGenerated: boolean;
|
|
31
|
-
readonly source: string;
|
|
32
|
-
/**
|
|
33
|
-
* The provider's effect receipt (VP-3), verbatim, when its answer carried
|
|
34
|
-
* one in `x-agent-safe-effect-receipt`. Forwarded to the authority
|
|
35
|
-
* unread; its statement is compared with this executor's own account.
|
|
36
|
-
*/
|
|
37
|
-
readonly receipt?: string | null;
|
|
38
|
-
}
|
|
39
|
-
export type ObservationMethod = "DOWNSTREAM_ACK" | "READ_AFTER_WRITE" | "EVENT_CONFIRMATION" | "STATE_RECONCILIATION" | "SIGNED_RECEIPT" | "EXTERNAL_ATTESTATION" | "HUMAN_VALIDATION";
|
|
40
1
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
2
|
+
* The effect-adapter contract moved into `@decionis/agent-safe-pipeline`,
|
|
3
|
+
* where it is the dispatch style of `agent-safe.executors.native/1` under its
|
|
4
|
+
* earlier name (`EffectAdapterExecutor` runs one as a `NativeExecutor`).
|
|
5
|
+
* Re-exported here, unchanged, so every adapter and import written against
|
|
6
|
+
* this module keeps working.
|
|
44
7
|
*
|
|
45
|
-
*
|
|
46
|
-
* the effect all the same. `receipt` carries it to the finalization, where
|
|
47
|
-
* the authority verifies it, instead of it being dropped with the answer.
|
|
8
|
+
* @deprecated Implement the pipeline's `NativeExecutor` with `style: "dispatch"`.
|
|
48
9
|
*/
|
|
49
|
-
export
|
|
50
|
-
readonly reason: string;
|
|
51
|
-
readonly providerStatus: string | null;
|
|
52
|
-
readonly receipt: string | null;
|
|
53
|
-
constructor(reason: string, providerStatus?: string | null, receipt?: string | null);
|
|
54
|
-
}
|
|
55
|
-
export interface AdapterExecution<TAction> {
|
|
56
|
-
readonly action: TAction;
|
|
57
|
-
readonly prepared: PreparedAction;
|
|
58
|
-
readonly authorization: VerifiedAuthorization;
|
|
59
|
-
readonly idempotencyKey: string;
|
|
60
|
-
/** The budget left for this dispatch: the smaller of the timeout and the grant. */
|
|
61
|
-
readonly deadline: MonotonicDeadline;
|
|
62
|
-
}
|
|
63
|
-
export interface AdapterReconciliation {
|
|
64
|
-
readonly idempotencyKey: string;
|
|
65
|
-
readonly providerReference: string | null;
|
|
66
|
-
readonly intentHash: string;
|
|
67
|
-
readonly prepared: PreparedAction;
|
|
68
|
-
}
|
|
69
|
-
export type ProviderReconciliationResult = {
|
|
70
|
-
readonly status: "COMPLETED";
|
|
71
|
-
readonly result: ProviderResult;
|
|
72
|
-
} | {
|
|
73
|
-
readonly status: "NOT_EXECUTED";
|
|
74
|
-
} | {
|
|
75
|
-
readonly status: "UNKNOWN";
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* One contract for every family of consequential actions. It is deliberately
|
|
79
|
-
* four small methods, three of them pure:
|
|
80
|
-
*
|
|
81
|
-
* - `prepare` works out what the action asks for and what its effect should
|
|
82
|
-
* be. It reaches nothing and may be called before the authority is asked.
|
|
83
|
-
* - `execute` performs the side effect, once, inside the dispatch the
|
|
84
|
-
* pipeline opened. A provider that neither committed nor refused is an
|
|
85
|
-
* `IndeterminateOutcome`, never a guess.
|
|
86
|
-
* - `observeEffect` reads what the provider said into the profile's
|
|
87
|
-
* projection. Pure: no second call, no interpretation of silence.
|
|
88
|
-
* - `reconcile` asks the provider what it did with an idempotency key,
|
|
89
|
-
* read-only, and may never initiate anything.
|
|
90
|
-
*
|
|
91
|
-
* A second family is a directory beside `banking/`, not a rewrite: the
|
|
92
|
-
* handler bridge, the comparison, the evidence and the verifier all work off
|
|
93
|
-
* this contract alone.
|
|
94
|
-
*/
|
|
95
|
-
export interface EffectAdapter<TAction> {
|
|
96
|
-
readonly id: string;
|
|
97
|
-
readonly version: string;
|
|
98
|
-
/** The transport action names this adapter answers for. */
|
|
99
|
-
readonly actionTypes: readonly string[];
|
|
100
|
-
prepare(action: TAction): PreparedAction;
|
|
101
|
-
execute(execution: AdapterExecution<TAction>): Promise<ProviderResult>;
|
|
102
|
-
observeEffect(result: ProviderResult, prepared: PreparedAction): JsonObject | null;
|
|
103
|
-
reconcile(context: AdapterReconciliation): Promise<ProviderReconciliationResult>;
|
|
104
|
-
}
|
|
105
|
-
/** A value the projection can hold, narrowed for comparison. */
|
|
106
|
-
export type ProjectionValue = JsonValue;
|
|
10
|
+
export { IndeterminateOutcome, type AdapterExecution, type AdapterReconciliation, type EffectAdapter, type EffectPreparedAction as PreparedAction, type ObservationMethod, type ProjectionValue, type ProviderReconciliationResult, type ProviderResult, } from "@decionis/agent-safe-pipeline";
|
|
107
11
|
//# sourceMappingURL=EffectAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EffectAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/EffectAdapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"EffectAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/EffectAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,oBAAoB,IAAI,cAAc,EAC3C,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,4BAA4B,EACjC,KAAK,cAAc,GACpB,MAAM,+BAA+B,CAAC"}
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The effect-adapter contract moved into `@decionis/agent-safe-pipeline`,
|
|
3
|
+
* where it is the dispatch style of `agent-safe.executors.native/1` under its
|
|
4
|
+
* earlier name (`EffectAdapterExecutor` runs one as a `NativeExecutor`).
|
|
5
|
+
* Re-exported here, unchanged, so every adapter and import written against
|
|
6
|
+
* this module keeps working.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
* the effect all the same. `receipt` carries it to the finalization, where
|
|
8
|
-
* the authority verifies it, instead of it being dropped with the answer.
|
|
8
|
+
* @deprecated Implement the pipeline's `NativeExecutor` with `style: "dispatch"`.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
11
|
-
reason;
|
|
12
|
-
providerStatus;
|
|
13
|
-
receipt;
|
|
14
|
-
constructor(reason, providerStatus = null, receipt = null) {
|
|
15
|
-
super(reason);
|
|
16
|
-
this.reason = reason;
|
|
17
|
-
this.providerStatus = providerStatus;
|
|
18
|
-
this.receipt = receipt;
|
|
19
|
-
this.name = "IndeterminateOutcome";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
10
|
+
export { IndeterminateOutcome, } from "@decionis/agent-safe-pipeline";
|
|
22
11
|
//# sourceMappingURL=EffectAdapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EffectAdapter.js","sourceRoot":"","sources":["../../src/adapters/EffectAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EffectAdapter.js","sourceRoot":"","sources":["../../src/adapters/EffectAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,oBAAoB,GASrB,MAAM,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { AgentProposal, ClaimedExecution, DownstreamTarget, EffectAdapter, EffectObservation, EffectPreparedAction, ExecutionCapability, ExecutionEffect, ExecutorScope, JsonObject, NativeExecutor, PlatformId, PreparedAction, ProviderResult, ReconcileContext, ReconcileResult } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import type { RegisteredEffect } from "./EffectEvidenceRegister.js";
|
|
3
|
+
/** How an adapter's action is described to the authority: what `prepare` binds beyond the effect. */
|
|
4
|
+
export interface ActionDescription {
|
|
5
|
+
readonly proposal: AgentProposal;
|
|
6
|
+
readonly downstreamTarget: DownstreamTarget;
|
|
7
|
+
readonly idempotencyKey: string;
|
|
8
|
+
readonly facts: JsonObject;
|
|
9
|
+
}
|
|
10
|
+
export interface EffectAdapterExecutorOptions<TAction> {
|
|
11
|
+
readonly adapter: EffectAdapter<TAction>;
|
|
12
|
+
readonly platform: PlatformId;
|
|
13
|
+
/** How the action reads as an intent; the adapter itself only knows its effect. */
|
|
14
|
+
readonly describe: (action: TAction, prepared: EffectPreparedAction) => ActionDescription;
|
|
15
|
+
/** What the connection can execute; absent, every action type is stated as live. */
|
|
16
|
+
readonly capabilities?: (scope: ExecutorScope) => Promise<readonly ExecutionCapability[]>;
|
|
17
|
+
readonly clock?: () => Date;
|
|
18
|
+
}
|
|
19
|
+
/** What the adapter's dispatch left for `observe`: everything the effect record is built from. */
|
|
20
|
+
export interface AdapterDispatchReceipt {
|
|
21
|
+
readonly prepared: EffectPreparedAction;
|
|
22
|
+
readonly result: ProviderResult | null;
|
|
23
|
+
readonly indeterminate: {
|
|
24
|
+
readonly reason: string;
|
|
25
|
+
readonly providerStatus: string | null;
|
|
26
|
+
} | null;
|
|
27
|
+
readonly correlationId: string;
|
|
28
|
+
readonly idempotencyKey: string;
|
|
29
|
+
}
|
|
30
|
+
/** What `observe` reads a dispatch as: the effect record, and the attempt it was observed for. */
|
|
31
|
+
export interface AdapterObservation {
|
|
32
|
+
readonly record: RegisteredEffect;
|
|
33
|
+
readonly indeterminate: AdapterDispatchReceipt["indeterminate"];
|
|
34
|
+
readonly correlationId: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Any `EffectAdapter` as a dispatch-style `NativeExecutor`
|
|
38
|
+
* (`agent-safe.executors.native/1`): the adapter keeps its four methods and
|
|
39
|
+
* this class says them in the contract's terms. `prepare` is the adapter's,
|
|
40
|
+
* plus how the action reads as an intent; `execute` is the adapter's write,
|
|
41
|
+
* inside the dispatch the caller opened and within its deadline; `observe`
|
|
42
|
+
* is the adapter's projection turned into the effect record, field by field
|
|
43
|
+
* against what was authorised; `reconcile` is the adapter's read-only
|
|
44
|
+
* lookup, complete only on a matching read-back.
|
|
45
|
+
*
|
|
46
|
+
* The record is evidence, so it rides on the observation for whoever
|
|
47
|
+
* finalizes the grant — the runtime registers it for its verifier — and its
|
|
48
|
+
* wire form rides as `evidence` for a runner that finalizes directly.
|
|
49
|
+
*/
|
|
50
|
+
export declare class EffectAdapterExecutor<TAction> implements NativeExecutor<TAction, AdapterDispatchReceipt, AdapterObservation> {
|
|
51
|
+
private readonly options;
|
|
52
|
+
readonly platform: PlatformId;
|
|
53
|
+
readonly version: string;
|
|
54
|
+
readonly style: "dispatch";
|
|
55
|
+
private readonly clock;
|
|
56
|
+
/** The adapter's own preparation of each prepared action, so a write never prepares twice. */
|
|
57
|
+
private readonly effects;
|
|
58
|
+
constructor(options: EffectAdapterExecutorOptions<TAction>);
|
|
59
|
+
get actionTypes(): readonly string[];
|
|
60
|
+
/** The adapter's observer identity, as the effect record and the authority name it. */
|
|
61
|
+
get observer(): {
|
|
62
|
+
readonly id: string;
|
|
63
|
+
readonly version: string;
|
|
64
|
+
};
|
|
65
|
+
capabilities(scope: ExecutorScope): Promise<readonly ExecutionCapability[]>;
|
|
66
|
+
prepare(action: TAction): Promise<PreparedAction>;
|
|
67
|
+
/** `prepare`, synchronously: the adapter reaches nothing, so neither does this. */
|
|
68
|
+
prepareNow(action: TAction): PreparedAction;
|
|
69
|
+
/**
|
|
70
|
+
* The adapter's write, once, inside the caller's dispatch. A provider that
|
|
71
|
+
* neither committed nor refused is carried as indeterminate, with any
|
|
72
|
+
* receipt it gave; any other error after the dispatch began propagates, so
|
|
73
|
+
* the caller reports an outcome nobody knows.
|
|
74
|
+
*/
|
|
75
|
+
execute(run: ClaimedExecution<TAction>): Promise<ExecutionEffect<AdapterDispatchReceipt>>;
|
|
76
|
+
/**
|
|
77
|
+
* The provider's answer as the effect record: the adapter's projection,
|
|
78
|
+
* compared with what was authorised. An outcome nobody can determine stays
|
|
79
|
+
* undetermined; a provider that was reached and said no is a refusal, not
|
|
80
|
+
* a success whose effect block says otherwise.
|
|
81
|
+
*/
|
|
82
|
+
observe(effect: ExecutionEffect<AdapterDispatchReceipt>): Promise<EffectObservation<AdapterObservation>>;
|
|
83
|
+
/**
|
|
84
|
+
* The adapter's read-only lookup. Absence of an error is not success: only
|
|
85
|
+
* a read-back whose projection matches what was authorised completes a
|
|
86
|
+
* reconciliation.
|
|
87
|
+
*/
|
|
88
|
+
reconcile(context: ReconcileContext): Promise<ReconcileResult<AdapterObservation>>;
|
|
89
|
+
/** The adapter's preparation of a prepared action: remembered from `prepare`, or made again. */
|
|
90
|
+
private effectOf;
|
|
91
|
+
private evidenceOf;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=EffectAdapterExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EffectAdapterExecutor.d.ts","sourceRoot":"","sources":["../../src/adapters/EffectAdapterExecutor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EAEb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EAChB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,qGAAqG;AACrG,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,C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@decionis/agent-safe-pipeline";
|
|
2
|
+
import { authorityEffectEvidence, buildEffectRecord } from "./EffectEvidenceBuilder.js";
|
|
3
|
+
/**
|
|
4
|
+
* Any `EffectAdapter` as a dispatch-style `NativeExecutor`
|
|
5
|
+
* (`agent-safe.executors.native/1`): the adapter keeps its four methods and
|
|
6
|
+
* this class says them in the contract's terms. `prepare` is the adapter's,
|
|
7
|
+
* plus how the action reads as an intent; `execute` is the adapter's write,
|
|
8
|
+
* inside the dispatch the caller opened and within its deadline; `observe`
|
|
9
|
+
* is the adapter's projection turned into the effect record, field by field
|
|
10
|
+
* against what was authorised; `reconcile` is the adapter's read-only
|
|
11
|
+
* lookup, complete only on a matching read-back.
|
|
12
|
+
*
|
|
13
|
+
* The record is evidence, so it rides on the observation for whoever
|
|
14
|
+
* finalizes the grant — the runtime registers it for its verifier — and its
|
|
15
|
+
* wire form rides as `evidence` for a runner that finalizes directly.
|
|
16
|
+
*/
|
|
17
|
+
export class EffectAdapterExecutor {
|
|
18
|
+
options;
|
|
19
|
+
platform;
|
|
20
|
+
version;
|
|
21
|
+
style = "dispatch";
|
|
22
|
+
clock;
|
|
23
|
+
/** The adapter's own preparation of each prepared action, so a write never prepares twice. */
|
|
24
|
+
effects = new WeakMap();
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.platform = options.platform;
|
|
28
|
+
this.version = options.adapter.version;
|
|
29
|
+
this.clock = options.clock ?? (() => new Date());
|
|
30
|
+
}
|
|
31
|
+
get actionTypes() {
|
|
32
|
+
return this.options.adapter.actionTypes;
|
|
33
|
+
}
|
|
34
|
+
/** The adapter's observer identity, as the effect record and the authority name it. */
|
|
35
|
+
get observer() {
|
|
36
|
+
return { id: this.options.adapter.id, version: this.options.adapter.version };
|
|
37
|
+
}
|
|
38
|
+
async capabilities(scope) {
|
|
39
|
+
if (this.options.capabilities !== undefined)
|
|
40
|
+
return await this.options.capabilities(scope);
|
|
41
|
+
return this.actionTypes.map((actionType) => ({
|
|
42
|
+
platform: this.platform,
|
|
43
|
+
actionType,
|
|
44
|
+
enabled: true,
|
|
45
|
+
scopeGranted: true,
|
|
46
|
+
connected: true,
|
|
47
|
+
requirement: "",
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
async prepare(action) {
|
|
51
|
+
return await Promise.resolve(this.prepareNow(action));
|
|
52
|
+
}
|
|
53
|
+
/** `prepare`, synchronously: the adapter reaches nothing, so neither does this. */
|
|
54
|
+
prepareNow(action) {
|
|
55
|
+
const effect = this.options.adapter.prepare(action);
|
|
56
|
+
const description = this.options.describe(action, effect);
|
|
57
|
+
const prepared = Object.freeze({
|
|
58
|
+
actionType: description.proposal.action,
|
|
59
|
+
proposal: description.proposal,
|
|
60
|
+
downstreamTarget: description.downstreamTarget,
|
|
61
|
+
idempotencyKey: description.idempotencyKey,
|
|
62
|
+
expectedEffectDigest: effect.expectedEffectDigest,
|
|
63
|
+
requestDigest: effect.requestDigest,
|
|
64
|
+
facts: description.facts,
|
|
65
|
+
});
|
|
66
|
+
this.effects.set(prepared, effect);
|
|
67
|
+
return prepared;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The adapter's write, once, inside the caller's dispatch. A provider that
|
|
71
|
+
* neither committed nor refused is carried as indeterminate, with any
|
|
72
|
+
* receipt it gave; any other error after the dispatch began propagates, so
|
|
73
|
+
* the caller reports an outcome nobody knows.
|
|
74
|
+
*/
|
|
75
|
+
async execute(run) {
|
|
76
|
+
const prepared = this.effectOf(run.prepared, run.action);
|
|
77
|
+
let result = null;
|
|
78
|
+
let indeterminate = null;
|
|
79
|
+
let indeterminateReceipt = null;
|
|
80
|
+
try {
|
|
81
|
+
result = await run.dispatch.run(async () => await this.options.adapter.execute({
|
|
82
|
+
action: run.action,
|
|
83
|
+
prepared,
|
|
84
|
+
authorization: run.authorization,
|
|
85
|
+
idempotencyKey: run.dispatch.idempotencyKey,
|
|
86
|
+
deadline: run.deadline,
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (!(error instanceof IndeterminateOutcome))
|
|
91
|
+
throw error;
|
|
92
|
+
indeterminate = { reason: error.reason, providerStatus: error.providerStatus };
|
|
93
|
+
indeterminateReceipt = error.receipt;
|
|
94
|
+
}
|
|
95
|
+
const signedReceipt = result?.receipt ?? indeterminateReceipt;
|
|
96
|
+
return {
|
|
97
|
+
kind: "DISPATCHED",
|
|
98
|
+
receipt: {
|
|
99
|
+
prepared,
|
|
100
|
+
result,
|
|
101
|
+
indeterminate,
|
|
102
|
+
correlationId: run.intent.intent.intentId,
|
|
103
|
+
idempotencyKey: run.dispatch.idempotencyKey,
|
|
104
|
+
},
|
|
105
|
+
signedReceipt: typeof signedReceipt === "string" ? signedReceipt : null,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The provider's answer as the effect record: the adapter's projection,
|
|
110
|
+
* compared with what was authorised. An outcome nobody can determine stays
|
|
111
|
+
* undetermined; a provider that was reached and said no is a refusal, not
|
|
112
|
+
* a success whose effect block says otherwise.
|
|
113
|
+
*/
|
|
114
|
+
async observe(effect) {
|
|
115
|
+
if (effect.kind !== "DISPATCHED" || effect.receipt === null) {
|
|
116
|
+
return await Promise.resolve({ status: "INDETERMINATE", reason: null, result: null });
|
|
117
|
+
}
|
|
118
|
+
const dispatch = effect.receipt;
|
|
119
|
+
const observed = dispatch.result === null
|
|
120
|
+
? null
|
|
121
|
+
: this.options.adapter.observeEffect(dispatch.result, dispatch.prepared);
|
|
122
|
+
const record = buildEffectRecord({
|
|
123
|
+
prepared: dispatch.prepared,
|
|
124
|
+
result: dispatch.result === null ? null : { ...dispatch.result, observed },
|
|
125
|
+
...(dispatch.indeterminate === null ? {} : { indeterminate: dispatch.indeterminate }),
|
|
126
|
+
observer: this.observer,
|
|
127
|
+
correlationId: dispatch.correlationId,
|
|
128
|
+
idempotencyKey: dispatch.idempotencyKey,
|
|
129
|
+
observedAt: this.clock().toISOString(),
|
|
130
|
+
});
|
|
131
|
+
const observation = {
|
|
132
|
+
record,
|
|
133
|
+
indeterminate: dispatch.indeterminate,
|
|
134
|
+
correlationId: dispatch.correlationId,
|
|
135
|
+
};
|
|
136
|
+
const evidence = this.evidenceOf(record, dispatch.correlationId);
|
|
137
|
+
if (dispatch.indeterminate !== null) {
|
|
138
|
+
return { status: "INDETERMINATE", reason: null, result: observation, evidence };
|
|
139
|
+
}
|
|
140
|
+
if (record.outcome === "FAILED") {
|
|
141
|
+
return {
|
|
142
|
+
status: "FAILED",
|
|
143
|
+
reason: record.reasonCodes[0] ?? "PROVIDER_REFUSED",
|
|
144
|
+
result: observation,
|
|
145
|
+
evidence,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return { status: "COMMITTED", reason: null, result: observation, evidence };
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The adapter's read-only lookup. Absence of an error is not success: only
|
|
152
|
+
* a read-back whose projection matches what was authorised completes a
|
|
153
|
+
* reconciliation.
|
|
154
|
+
*/
|
|
155
|
+
async reconcile(context) {
|
|
156
|
+
const prepared = this.effectOf(context.prepared, context.prepared.proposal.parameters);
|
|
157
|
+
const answer = await this.options.adapter.reconcile({
|
|
158
|
+
idempotencyKey: context.idempotencyKey,
|
|
159
|
+
providerReference: context.providerReference,
|
|
160
|
+
intentHash: context.intent.intentHash,
|
|
161
|
+
prepared,
|
|
162
|
+
});
|
|
163
|
+
if (answer.status !== "COMPLETED")
|
|
164
|
+
return { status: answer.status };
|
|
165
|
+
const observed = this.options.adapter.observeEffect(answer.result, prepared);
|
|
166
|
+
const correlationId = context.intent.intent.intentId;
|
|
167
|
+
const record = buildEffectRecord({
|
|
168
|
+
prepared,
|
|
169
|
+
result: { ...answer.result, observed },
|
|
170
|
+
observer: this.observer,
|
|
171
|
+
correlationId,
|
|
172
|
+
idempotencyKey: context.idempotencyKey,
|
|
173
|
+
observedAt: this.clock().toISOString(),
|
|
174
|
+
});
|
|
175
|
+
if (record.comparison !== "MATCH")
|
|
176
|
+
return { status: "UNKNOWN" };
|
|
177
|
+
return {
|
|
178
|
+
status: "COMPLETED",
|
|
179
|
+
result: { record, indeterminate: null, correlationId },
|
|
180
|
+
evidence: this.evidenceOf(record, correlationId),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** The adapter's preparation of a prepared action: remembered from `prepare`, or made again. */
|
|
184
|
+
effectOf(prepared, action) {
|
|
185
|
+
return this.effects.get(prepared) ?? this.options.adapter.prepare(action);
|
|
186
|
+
}
|
|
187
|
+
evidenceOf(record, correlationId) {
|
|
188
|
+
return authorityEffectEvidence(record, correlationId, this.observer);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=EffectAdapterExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EffectAdapterExecutor.js","sourceRoot":"","sources":["../../src/adapters/EffectAdapterExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAoBrE,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAwCxF;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,qBAAqB;IAYI;IAPpB,QAAQ,CAAa;IACrB,OAAO,CAAS;IAChB,KAAK,GAAG,UAAmB,CAAC;IAC3B,KAAK,CAAa;IACnC,8FAA8F;IAC7E,OAAO,GAAG,IAAI,OAAO,EAAwC,CAAC;IAE/E,YAAoC,OAA8C;QAA9C,YAAO,GAAP,OAAO,CAAuC;QAChF,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAS,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;I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AAwB,EAAE,aAAqB;QAChE,OAAO,uBAAuB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACvE,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { EffectPreparedAction, ExecutionCapability, ExecutorScope } from "@decionis/agent-safe-pipeline";
|
|
2
|
+
import { EffectAdapterExecutor, type ActionDescription } from "../EffectAdapterExecutor.js";
|
|
3
|
+
import { type BankingAction } from "./BankingAction.js";
|
|
4
|
+
import type { BankingAdapter } from "./BankingAdapter.js";
|
|
5
|
+
export declare const CORE_BANKING_PLATFORM = "core-banking";
|
|
6
|
+
export interface BankingExecutorOptions {
|
|
7
|
+
readonly adapter: BankingAdapter;
|
|
8
|
+
/** What the connection can execute; absent, every registered action is stated as live. */
|
|
9
|
+
readonly capabilities?: (scope: ExecutorScope) => Promise<readonly ExecutionCapability[]>;
|
|
10
|
+
readonly clock?: () => Date;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The banking family on `agent-safe.executors.native/1`, dispatch style: the
|
|
14
|
+
* BEAP adapter performs the write against the core, once, inside the
|
|
15
|
+
* dispatch the runner opens. Everything the family does — the profile's
|
|
16
|
+
* arithmetic, the projection, the comparison, the effect record — is the
|
|
17
|
+
* adapter's, unchanged; this class says how a BEAP action reads as an
|
|
18
|
+
* intent:
|
|
19
|
+
*
|
|
20
|
+
* - the action is the transport name the profile assigns
|
|
21
|
+
* (`beap.<domain>.<type>`) and the resource its target;
|
|
22
|
+
* - the system of record is the downstream provider and operation the
|
|
23
|
+
* action names;
|
|
24
|
+
* - the retry identity is the action's own `request_id`, which the core
|
|
25
|
+
* holds as its idempotency key (by digest when it is longer than an
|
|
26
|
+
* intent carries);
|
|
27
|
+
* - the facts the authority decides with are the domain, the action type and
|
|
28
|
+
* the registered effect, never an amount or an account.
|
|
29
|
+
*/
|
|
30
|
+
export declare class BankingExecutor extends EffectAdapterExecutor<BankingAction> {
|
|
31
|
+
constructor(options: BankingExecutorOptions);
|
|
32
|
+
}
|
|
33
|
+
/** How a BEAP action reads as an `agent-safe.intent/1` binding. */
|
|
34
|
+
export declare function describeBankingAction(action: BankingAction, prepared: EffectPreparedAction): ActionDescription;
|
|
35
|
+
//# sourceMappingURL=BankingExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BankingExecutor.d.ts","sourceRoot":"","sources":["../../../src/adapters/banking/BankingExecutor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EAEd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,KAAK,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAwC,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,eAAO,MAAM,qBAAqB,iBAAiB,CAAC;AAKpD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,0FAA0F;IAC1F,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAAC;IAC1F,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,eAAgB,SAAQ,qBAAqB,CAAC,aAAa,CAAC;gBACpD,OAAO,EAAE,sBAAsB;CASnD;AAED,mEAAmE;AACnE,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,oBAAoB,GAC7B,iBAAiB,CA2BnB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { EffectAdapterExecutor } from "../EffectAdapterExecutor.js";
|
|
3
|
+
import { transportActionName, transportTarget } from "./BankingAction.js";
|
|
4
|
+
export const CORE_BANKING_PLATFORM = "core-banking";
|
|
5
|
+
/** The longest idempotency key an intent carries; a longer request id is carried by its digest. */
|
|
6
|
+
const MAX_IDEMPOTENCY_KEY = 180;
|
|
7
|
+
/**
|
|
8
|
+
* The banking family on `agent-safe.executors.native/1`, dispatch style: the
|
|
9
|
+
* BEAP adapter performs the write against the core, once, inside the
|
|
10
|
+
* dispatch the runner opens. Everything the family does — the profile's
|
|
11
|
+
* arithmetic, the projection, the comparison, the effect record — is the
|
|
12
|
+
* adapter's, unchanged; this class says how a BEAP action reads as an
|
|
13
|
+
* intent:
|
|
14
|
+
*
|
|
15
|
+
* - the action is the transport name the profile assigns
|
|
16
|
+
* (`beap.<domain>.<type>`) and the resource its target;
|
|
17
|
+
* - the system of record is the downstream provider and operation the
|
|
18
|
+
* action names;
|
|
19
|
+
* - the retry identity is the action's own `request_id`, which the core
|
|
20
|
+
* holds as its idempotency key (by digest when it is longer than an
|
|
21
|
+
* intent carries);
|
|
22
|
+
* - the facts the authority decides with are the domain, the action type and
|
|
23
|
+
* the registered effect, never an amount or an account.
|
|
24
|
+
*/
|
|
25
|
+
export class BankingExecutor extends EffectAdapterExecutor {
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super({
|
|
28
|
+
adapter: options.adapter,
|
|
29
|
+
platform: CORE_BANKING_PLATFORM,
|
|
30
|
+
describe: describeBankingAction,
|
|
31
|
+
...(options.capabilities === undefined ? {} : { capabilities: options.capabilities }),
|
|
32
|
+
...(options.clock === undefined ? {} : { clock: options.clock }),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** How a BEAP action reads as an `agent-safe.intent/1` binding. */
|
|
37
|
+
export function describeBankingAction(action, prepared) {
|
|
38
|
+
const requestId = action.action.request_id;
|
|
39
|
+
return {
|
|
40
|
+
proposal: {
|
|
41
|
+
action: transportActionName(action),
|
|
42
|
+
target: transportTarget(action),
|
|
43
|
+
parameters: action,
|
|
44
|
+
},
|
|
45
|
+
downstreamTarget: {
|
|
46
|
+
system: action.downstream.provider,
|
|
47
|
+
operation: action.downstream.operation,
|
|
48
|
+
...(action.downstream.environment === undefined
|
|
49
|
+
? {}
|
|
50
|
+
: { environment: action.downstream.environment }),
|
|
51
|
+
},
|
|
52
|
+
idempotencyKey: requestId.length <= MAX_IDEMPOTENCY_KEY
|
|
53
|
+
? requestId
|
|
54
|
+
: `sha256:${createHash("sha256").update(requestId, "utf8").digest("hex")}`,
|
|
55
|
+
facts: {
|
|
56
|
+
beap: {
|
|
57
|
+
domain: action.domain,
|
|
58
|
+
action_type: action.action.type,
|
|
59
|
+
effect_type: prepared.effectType,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=BankingExecutor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BankingExecutor.js","sourceRoot":"","sources":["../../../src/adapters/banking/BankingExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,OAAO,EAAE,qBAAqB,EAA0B,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AAG9F,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAEpD,mGAAmG;AACnG,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAShC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,eAAgB,SAAQ,qBAAoC;IACvE,YAAmB,OAA+B;QAChD,KAAK,CAAC;YACJ,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,QAAQ,EAAE,qBAAqB;YAC/B,QAAQ,EAAE,qBAAqB;YAC/B,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC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,"file":"BankingHandlers.d.ts","sourceRoot":"","sources":["../../../src/adapters/banking/BankingHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"BankingHandlers.d.ts","sourceRoot":"","sources":["../../../src/adapters/banking/BankingHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAQjF,MAAM,WAAW,qBAAqB;IACpC,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;CAC/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,qBAA0B,GAAG,mBAAmB,CA8BxF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { executorActionHandler } from "../AdapterActionHandler.js";
|
|
2
2
|
import { BankingActionWireSchema } from "./BankingAction.js";
|
|
3
3
|
import { BankingAdapter } from "./BankingAdapter.js";
|
|
4
|
+
import { BankingExecutor } from "./BankingExecutor.js";
|
|
4
5
|
import { CoreBankingHttpAdapter } from "./CoreBankingHttpAdapter.js";
|
|
5
6
|
import { REGISTERED_ACTIONS } from "./EffectProjections.js";
|
|
6
7
|
/**
|
|
@@ -31,8 +32,10 @@ export function bankingHandlers(options = {}) {
|
|
|
31
32
|
source: "CORE_BANKING_RESPONSE",
|
|
32
33
|
}),
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
// The family runs as its native executor: the registry reaches it through
|
|
36
|
+
// the runner, and the adapter's arithmetic, projection and evidence are
|
|
37
|
+
// exactly what they were.
|
|
38
|
+
const handler = executorActionHandler(new BankingExecutor({ adapter }), {
|
|
36
39
|
schema: BankingActionWireSchema,
|
|
37
40
|
register,
|
|
38
41
|
timeoutMs: context.downstream.timeoutMs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BankingHandlers.js","sourceRoot":"","sources":["../../../src/adapters/banking/BankingHandlers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BankingHandlers.js","sourceRoot":"","sources":["../../../src/adapters/banking/BankingHandlers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAsB,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAW5D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,eAAe,CAAC,UAAiC,EAAE;IACjE,OAAO,CAAC,OAAO,EAAE,EAAE;QACjB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QACjC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC;YACjC,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS;YAC3C,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc;YAC1D,SAAS,EAAE,IAAI,sBAAsB,CAAC;gBACpC,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG;gBAC3B,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,oBAAoB;gBA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