@ixo/flow-work 0.3.0 → 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/README.md +135 -9
- package/dist/capability.d.ts +21 -10
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/input-requests.d.ts +65 -0
- package/dist/input-requests.d.ts.map +1 -0
- package/dist/input-requests.js +397 -0
- package/dist/input-requests.js.map +1 -0
- package/dist/input.d.ts +199 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +198 -0
- package/dist/input.js.map +1 -0
- package/dist/listener.d.ts +28 -0
- package/dist/listener.d.ts.map +1 -1
- package/dist/listener.js +105 -4
- package/dist/listener.js.map +1 -1
- package/dist/matrix-port.d.ts +21 -3
- package/dist/matrix-port.d.ts.map +1 -1
- package/dist/matrix-port.js +47 -1
- package/dist/matrix-port.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +1 -1
- package/dist/protocol.js.map +1 -1
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -2,16 +2,111 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@ixo/flow-work)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
from the IXO flow-manager over Matrix and post receipts.
|
|
5
|
+
Helper-oracle-side flow-work plugin: accept UCAN-delegated `ixo.flow.work`
|
|
6
|
+
invocations from the IXO flow-manager over Matrix and post receipts.
|
|
7
7
|
|
|
8
|
-
It is the
|
|
9
|
-
capable oracle, mints a UCAN delegation scoped to a flow node, and sends
|
|
10
|
-
`ixo.flow.work.invoke` event carrying the work brief by value.
|
|
11
|
-
validates the delegation (audience, expiry, signature chain,
|
|
12
|
-
runs the matching capability handler, and posts an
|
|
13
|
-
The oracle never gains read authority
|
|
14
|
-
|
|
8
|
+
It is the helper half of the flow-work contract. Flow-manager discovers a
|
|
9
|
+
capable helper-oracle, mints a UCAN delegation scoped to a flow node, and sends
|
|
10
|
+
an `ixo.flow.work.invoke` event carrying the work brief by value.
|
|
11
|
+
`FlowWorkListener` validates the delegation (audience, expiry, signature chain,
|
|
12
|
+
nb caveats), runs the matching capability handler, and posts an
|
|
13
|
+
`ixo.flow.work.receipt`. The helper-oracle never gains general read authority
|
|
14
|
+
over the flow document: inputs arrive in the invocation and the result leaves
|
|
15
|
+
in the receipt.
|
|
16
|
+
|
|
17
|
+
## Keep the two oracle paths separate
|
|
18
|
+
|
|
19
|
+
An IXO **standard oracle** is user-facing, typically a chat or AI agent.
|
|
20
|
+
Flow-manager is one standard oracle among many; it also contracts work as an
|
|
21
|
+
orchestrator. Standard oracles use the existing standard-oracle Composio UCAN
|
|
22
|
+
path.
|
|
23
|
+
|
|
24
|
+
A **helper-oracle** is a non-user-facing specialist, such as `xero-oracle` or
|
|
25
|
+
`diagnostic-oracle`. A user does not technically contact it. Flow-manager hires
|
|
26
|
+
it through a flow-work contract, and it is the terminal executor of that
|
|
27
|
+
contract.
|
|
28
|
+
|
|
29
|
+
`@ixo/flow-work` exists only for the helper-oracle path. It must not intercept,
|
|
30
|
+
replace, or reinterpret the standard-oracle chat/Composio path.
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
standard path: user <-> standard oracle <-> standard-oracle Composio path
|
|
34
|
+
|
|
35
|
+
helper path: user -> flow-manager -> @ixo/flow-work helper -> downstream service
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Calling a downstream service
|
|
39
|
+
|
|
40
|
+
A work contract and downstream authority are different capabilities:
|
|
41
|
+
|
|
42
|
+
- The flow-work capability authorizes one helper task on one flow node.
|
|
43
|
+
- A supplementary capability, when required, authorizes the helper to call a
|
|
44
|
+
particular downstream service.
|
|
45
|
+
|
|
46
|
+
For Composio work, flow-manager adds the user's existing `composio/proxy`
|
|
47
|
+
capability for one concrete entity to the helper-addressed delegation. It does
|
|
48
|
+
not derive that authority from Matrix content, caveats, or the helper's API
|
|
49
|
+
key. The helper then passes the validated flow-work delegation to the ambient
|
|
50
|
+
oracle-runtime UCAN minter:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import type { FlowWorkCapability } from '@ixo/flow-work';
|
|
54
|
+
|
|
55
|
+
const capability: FlowWorkCapability = {
|
|
56
|
+
can: 'flow/xero.invoice.create',
|
|
57
|
+
actionType: 'xero_invoice_create',
|
|
58
|
+
description: 'Create one Xero invoice',
|
|
59
|
+
inputSchema,
|
|
60
|
+
handler: async (inputs, context) => {
|
|
61
|
+
const composioResource = context.contractCaveats.composioResource;
|
|
62
|
+
if (typeof composioResource !== 'string') {
|
|
63
|
+
throw new Error('The contract has no Composio entity resource.');
|
|
64
|
+
}
|
|
65
|
+
const remainingSeconds = Math.floor(
|
|
66
|
+
(context.deadline - Date.now()) / 1_000,
|
|
67
|
+
);
|
|
68
|
+
if (remainingSeconds <= 0) {
|
|
69
|
+
throw new Error('The flow-work contract has expired.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const minted = await getUcan().createInvocationFromDelegation(
|
|
73
|
+
context.delegation,
|
|
74
|
+
composioWorkerUrl,
|
|
75
|
+
{
|
|
76
|
+
can: 'composio/proxy',
|
|
77
|
+
with: composioResource,
|
|
78
|
+
},
|
|
79
|
+
{ maxTtlSeconds: Math.min(120, remainingSeconds) },
|
|
80
|
+
);
|
|
81
|
+
if ('error' in minted) throw new Error(minted.error);
|
|
82
|
+
|
|
83
|
+
return callComposio(inputs, minted.invocation);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The helper is responsible for failing closed unless:
|
|
89
|
+
|
|
90
|
+
- the signed delegation is addressed to the contracted helper;
|
|
91
|
+
- it carries that exact supplementary capability; and
|
|
92
|
+
- the downstream invocation expires no later than the work deadline.
|
|
93
|
+
|
|
94
|
+
The ambient minter verifies that the configured helper DID matches the
|
|
95
|
+
delegation audience before signing and clamps to the requested TTL and
|
|
96
|
+
delegation expiration. The helper must additionally clamp that requested TTL
|
|
97
|
+
to `context.deadline`, as shown above. The downstream service cryptographically
|
|
98
|
+
rejects capabilities the proof chain does not authorize. The resulting chain
|
|
99
|
+
is:
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
user --composio/proxy(entity)--> flow-manager
|
|
103
|
+
--flow-work + composio/proxy(entity)--> helper-oracle
|
|
104
|
+
--composio/proxy(entity) invocation--> Composio worker
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The Composio API key identifies and can revoke the helper actor. It does not
|
|
108
|
+
choose the user/entity tenant. A diagnostic helper receives no Composio grant
|
|
109
|
+
unless its specific contract genuinely needs one.
|
|
15
110
|
|
|
16
111
|
## Install
|
|
17
112
|
|
|
@@ -22,6 +117,37 @@ pnpm add @ixo/flow-work
|
|
|
22
117
|
Peer dependencies: `@ixo/oracle-runtime`, `@ixo/ucan`, `@nestjs/common`,
|
|
23
118
|
`matrix-js-sdk`.
|
|
24
119
|
|
|
120
|
+
## Requesting user input
|
|
121
|
+
|
|
122
|
+
Capability handlers can pause for durable, structured human input in the flow
|
|
123
|
+
room. Use a stable `requestKey` derived from the node and purpose, never the
|
|
124
|
+
attempt's `invocationId`; retries then re-arm the same request instead of
|
|
125
|
+
posting a duplicate.
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
async function handler(inputs: MyInputs, context: FlowWorkInvocationContext) {
|
|
129
|
+
const outcome = await context.input.request({
|
|
130
|
+
requestKey: `${context.nodeId}:approve-payment`,
|
|
131
|
+
template: 'approval',
|
|
132
|
+
prompt: `Pay invoice ${inputs.invoiceId} (${inputs.amount})?`,
|
|
133
|
+
deadline: Date.now() + 4 * 60 * 60 * 1000,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (outcome.status === 'expired' || !outcome.response.approved) {
|
|
137
|
+
return {
|
|
138
|
+
approved: false,
|
|
139
|
+
reason: outcome.status === 'expired' ? 'timeout' : 'declined',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return pay(inputs);
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The `approval`, `select`, `entity-select`, and `text` templates are exported
|
|
147
|
+
from the browser-safe `@ixo/flow-work/input` subpath. An attempt-window closure
|
|
148
|
+
is retried by flow-manager automatically; an actual request deadline resolves
|
|
149
|
+
as `{ status: 'expired' }` so the handler can return a domain result.
|
|
150
|
+
|
|
25
151
|
## Releasing
|
|
26
152
|
|
|
27
153
|
This package versions independently of the flow-manager app via
|
package/dist/capability.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
+
import type { InputOutcomeFor, RequestUserInputParams } from './input-requests.js';
|
|
3
|
+
import type { FlowWorkInputTemplate } from './input.js';
|
|
4
|
+
export interface FlowWorkInputApi {
|
|
5
|
+
request<T extends FlowWorkInputTemplate>(params: Extract<RequestUserInputParams, {
|
|
6
|
+
template: T;
|
|
7
|
+
}>): Promise<InputOutcomeFor<T>>;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* What the listener hands a capability handler alongside its validated inputs:
|
|
4
11
|
* the invocation's identity and the UCAN delegation that authorized it. The
|
|
@@ -6,11 +13,12 @@ import type { z } from 'zod';
|
|
|
6
13
|
* before the handler runs — this context is for handlers that need to *act* on
|
|
7
14
|
* it, not re-check it.
|
|
8
15
|
*
|
|
9
|
-
* A handler that calls a downstream UCAN-guarded service (e.g.
|
|
10
|
-
* worker)
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
16
|
+
* A helper-oracle handler that calls a downstream UCAN-guarded service (e.g.
|
|
17
|
+
* the Composio worker) passes `delegation` to the oracle runtime's ambient
|
|
18
|
+
* `createInvocationFromDelegation` minter. That creates a fresh invocation
|
|
19
|
+
* signed by the helper while retaining the user-rooted authorization chain.
|
|
20
|
+
* `invocationId` / `nodeId` are the natural idempotency key for writes bound
|
|
21
|
+
* to a single flow node.
|
|
14
22
|
*/
|
|
15
23
|
export interface FlowWorkInvocationContext {
|
|
16
24
|
/** Unique id of this invocation — stable across redelivery. */
|
|
@@ -35,12 +43,14 @@ export interface FlowWorkInvocationContext {
|
|
|
35
43
|
/** This oracle's DID — the delegation audience. */
|
|
36
44
|
audience: string;
|
|
37
45
|
/**
|
|
38
|
-
* The serialized UCAN delegation (base64 CAR)
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
46
|
+
* The serialized UCAN delegation (base64 CAR) already validated by the
|
|
47
|
+
* listener. It always carries the flow-work grant and may also carry
|
|
48
|
+
* separately proven supplementary grants for downstream services. Do not
|
|
49
|
+
* treat Matrix inputs or `contractCaveats` as authority.
|
|
42
50
|
*/
|
|
43
51
|
delegation: string;
|
|
52
|
+
/** Ask a human for structured input in the invocation's Matrix room. */
|
|
53
|
+
input: FlowWorkInputApi;
|
|
44
54
|
}
|
|
45
55
|
/**
|
|
46
56
|
* A contractable capability: the unit of work this oracle accepts from
|
|
@@ -72,7 +82,8 @@ export interface FlowWorkCapability<Schema extends z.ZodType = z.ZodType> {
|
|
|
72
82
|
/**
|
|
73
83
|
* Runs the work. Receives the validated inputs and the invocation context.
|
|
74
84
|
* Pure, self-contained handlers (no downstream auth) may ignore the second
|
|
75
|
-
* argument; handlers that call UCAN-guarded services
|
|
85
|
+
* argument; handlers that call UCAN-guarded services pass its `delegation`
|
|
86
|
+
* to the oracle runtime's ambient UCAN minter.
|
|
76
87
|
*/
|
|
77
88
|
handler: (inputs: z.infer<Schema>, context: FlowWorkInvocationContext) => Promise<unknown>;
|
|
78
89
|
}
|
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK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AAC,OAAO;IACtE,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;IACzB;;;;;OAKG;IACH,OAAO,EAAE,CACP,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,EACvB,OAAO,EAAE,yBAAyB,KAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;CACvB;AAED,wBAAgB,cAAc,CAC5B,YAAY,EAAE,SAAS,kBAAkB,EAAE,EAC3C,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GACjB,kBAAkB,GAAG,SAAS,CAIhC"}
|
package/dist/capability.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAmGA,MAAM,UAAU,cAAc,CAC5B,YAA2C,EAC3C,GAAW,EACX,UAAkB;IAElB,OAAO,YAAY,CAAC,IAAI,CACtB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,IAAI,KAAK,CAAC,UAAU,KAAK,UAAU,CAChE,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { FlowWorkPlugin, type FlowWorkPluginOptions, } from './flow-work.plugin.js';
|
|
2
|
-
export { findCapability, type FlowWorkCapability, type FlowWorkInvocationContext, } from './capability.js';
|
|
3
|
-
export { FlowWorkListener } from './listener.js';
|
|
2
|
+
export { findCapability, type FlowWorkCapability, type FlowWorkInputApi, type FlowWorkInvocationContext, } from './capability.js';
|
|
3
|
+
export { FlowWorkListener, type FlowWorkLogger } from './listener.js';
|
|
4
4
|
export { adaptMatrixClient, type FlowWorkInvite, type FlowWorkMatrixPort, type FlowWorkRoomEvent, } from './matrix-port.js';
|
|
5
|
+
export * from './input.js';
|
|
6
|
+
export { FlowWorkInputError, InputRequestCoordinator, computeInputContentHash, requestStateKey, type FlowWorkInputErrorCode, type InputOutcome, type InputOutcomeFor, type RequestUserInputParams, } from './input-requests.js';
|
|
5
7
|
export { FLOW_WORK_ASSIGN_EVENT, FLOW_WORK_BINDING_FIELDS, FLOW_WORK_INVOKE_EVENT, FLOW_WORK_READY_EVENT, FLOW_WORK_RECEIPT_EVENT, computeFlowWorkInputHash, flowWorkAssignSchema, flowWorkBindingSchema, flowWorkInvokeSchema, flowWorkNbFor, flowWorkReadySchema, flowWorkReceiptSchema, sameFlowWorkBinding, sameFlowWorkNb, type FlowWorkAssign, type FlowWorkBinding, type FlowWorkErrorCode, type FlowWorkInvoke, type FlowWorkNb, type FlowWorkReady, type FlowWorkReceipt, } from './protocol.js';
|
|
6
8
|
export { buildDelegationValidator, type DelegationValidator } from './ucan.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EACL,iBAAiB,EACjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAAE,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@ export { FlowWorkPlugin, } from './flow-work.plugin.js';
|
|
|
2
2
|
export { findCapability, } from './capability.js';
|
|
3
3
|
export { FlowWorkListener } from './listener.js';
|
|
4
4
|
export { adaptMatrixClient, } from './matrix-port.js';
|
|
5
|
+
export * from './input.js';
|
|
6
|
+
export { FlowWorkInputError, InputRequestCoordinator, computeInputContentHash, requestStateKey, } from './input-requests.js';
|
|
5
7
|
export { FLOW_WORK_ASSIGN_EVENT, FLOW_WORK_BINDING_FIELDS, FLOW_WORK_INVOKE_EVENT, FLOW_WORK_READY_EVENT, FLOW_WORK_RECEIPT_EVENT, computeFlowWorkInputHash, flowWorkAssignSchema, flowWorkBindingSchema, flowWorkInvokeSchema, flowWorkNbFor, flowWorkReadySchema, flowWorkReceiptSchema, sameFlowWorkBinding, sameFlowWorkNb, } from './protocol.js';
|
|
6
8
|
export { buildDelegationValidator } from './ucan.js';
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAEf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAEf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,cAAc,GAIf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAuB,MAAM,eAAe,CAAC;AACtE,OAAO,EACL,iBAAiB,GAIlB,MAAM,kBAAkB,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,eAAe,GAKhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GAQf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,wBAAwB,EAA4B,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { FlowWorkLogger } from './listener.js';
|
|
2
|
+
import type { FlowWorkMatrixPort } from './matrix-port.js';
|
|
3
|
+
import { type FlowWorkInputRequest, type FlowWorkInputResponse, type FlowWorkInputTemplate } from './input.js';
|
|
4
|
+
export type RequestUserInputParams = FlowWorkInputRequest extends infer R ? R extends FlowWorkInputRequest ? Omit<R, 'protocolVersion' | 'invocationId'> & {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
} : never : never;
|
|
7
|
+
export type InputOutcomeFor<T extends FlowWorkInputTemplate> = {
|
|
8
|
+
status: 'answered';
|
|
9
|
+
response: Extract<FlowWorkInputResponse, {
|
|
10
|
+
template: T;
|
|
11
|
+
}>;
|
|
12
|
+
requestEventId: string;
|
|
13
|
+
responseEventId: string;
|
|
14
|
+
sender: string;
|
|
15
|
+
respondedAtMs: number;
|
|
16
|
+
fromHistory: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
status: 'expired';
|
|
19
|
+
requestEventId?: string;
|
|
20
|
+
deadline: number;
|
|
21
|
+
};
|
|
22
|
+
export type InputOutcome = InputOutcomeFor<FlowWorkInputTemplate>;
|
|
23
|
+
export type FlowWorkInputErrorCode = 'invalid_request' | 'send_failed' | 'request_conflict' | 'await_window_closed' | 'aborted';
|
|
24
|
+
export declare class FlowWorkInputError extends Error {
|
|
25
|
+
readonly code: FlowWorkInputErrorCode;
|
|
26
|
+
constructor(code: FlowWorkInputErrorCode, message: string);
|
|
27
|
+
}
|
|
28
|
+
export declare function requestStateKey(sender: string, nodeId: string, requestKey: string): string;
|
|
29
|
+
export declare function computeInputContentHash(content: Omit<FlowWorkInputRequest, 'protocolVersion' | 'invocationId' | 'deadline'>): string;
|
|
30
|
+
interface RequestScope {
|
|
31
|
+
roomId: string;
|
|
32
|
+
invocationId: string;
|
|
33
|
+
nodeId: string;
|
|
34
|
+
attempt: number;
|
|
35
|
+
inputHash: string;
|
|
36
|
+
bindingDeadline: number;
|
|
37
|
+
}
|
|
38
|
+
interface CoordinatorOptions {
|
|
39
|
+
port: FlowWorkMatrixPort;
|
|
40
|
+
logger: FlowWorkLogger;
|
|
41
|
+
now: () => number;
|
|
42
|
+
retryMs: number;
|
|
43
|
+
}
|
|
44
|
+
export declare class InputRequestCoordinator {
|
|
45
|
+
private readonly options;
|
|
46
|
+
private readonly pending;
|
|
47
|
+
private readonly inFlight;
|
|
48
|
+
private unsubscribe?;
|
|
49
|
+
private started;
|
|
50
|
+
private lifecycleController;
|
|
51
|
+
constructor(options: CoordinatorOptions);
|
|
52
|
+
start(): void;
|
|
53
|
+
stop(): void;
|
|
54
|
+
request<T extends FlowWorkInputTemplate>(scope: RequestScope, params: Extract<RequestUserInputParams, {
|
|
55
|
+
template: T;
|
|
56
|
+
}>): Promise<InputOutcomeFor<T>>;
|
|
57
|
+
private run;
|
|
58
|
+
private adoptRecentRequest;
|
|
59
|
+
private writeIndex;
|
|
60
|
+
private historyWinner;
|
|
61
|
+
private awaitResponse;
|
|
62
|
+
private retryMs;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
65
|
+
//# sourceMappingURL=input-requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-requests.d.ts","sourceRoot":"","sources":["../src/input-requests.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAqB,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAWL,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,SAAS,MAAM,CAAC,GACrE,CAAC,SAAS,oBAAoB,GAC5B,IAAI,CAAC,CAAC,EAAE,iBAAiB,GAAG,cAAc,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,GACtE,KAAK,GACP,KAAK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