@ironflow/browser 0.20.0 → 0.20.2
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/LICENSE +181 -0
- package/package.json +9 -9
- package/dist/agents/index.d.ts +0 -34
- package/dist/agents/index.d.ts.map +0 -1
- package/dist/agents/index.js +0 -24
- package/dist/agents/index.js.map +0 -1
- package/dist/agents/invoke.d.ts +0 -16
- package/dist/agents/invoke.d.ts.map +0 -1
- package/dist/agents/invoke.js +0 -222
- package/dist/agents/invoke.js.map +0 -1
- package/dist/agents/readMemory.d.ts +0 -18
- package/dist/agents/readMemory.d.ts.map +0 -1
- package/dist/agents/readMemory.js +0 -87
- package/dist/agents/readMemory.js.map +0 -1
- package/dist/agents/subscribe.d.ts +0 -23
- package/dist/agents/subscribe.d.ts.map +0 -1
- package/dist/agents/subscribe.js +0 -117
- package/dist/agents/subscribe.js.map +0 -1
- package/dist/agents/types.d.ts +0 -156
- package/dist/agents/types.d.ts.map +0 -1
- package/dist/agents/types.js +0 -7
- package/dist/agents/types.js.map +0 -1
- package/dist/client.d.ts +0 -844
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -2243
- package/dist/client.js.map +0 -1
- package/dist/config-client.d.ts +0 -43
- package/dist/config-client.d.ts.map +0 -1
- package/dist/config-client.js +0 -134
- package/dist/config-client.js.map +0 -1
- package/dist/config.d.ts +0 -91
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -55
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -53
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -53
- package/dist/index.js.map +0 -1
- package/dist/kv.d.ts +0 -79
- package/dist/kv.d.ts.map +0 -1
- package/dist/kv.js +0 -289
- package/dist/kv.js.map +0 -1
- package/dist/projection-stream.d.ts +0 -42
- package/dist/projection-stream.d.ts.map +0 -1
- package/dist/projection-stream.js +0 -48
- package/dist/projection-stream.js.map +0 -1
- package/dist/subscription.d.ts +0 -107
- package/dist/subscription.d.ts.map +0 -1
- package/dist/subscription.js +0 -450
- package/dist/subscription.js.map +0 -1
- package/dist/transport/connectrpc.d.ts +0 -74
- package/dist/transport/connectrpc.d.ts.map +0 -1
- package/dist/transport/connectrpc.js +0 -393
- package/dist/transport/connectrpc.js.map +0 -1
- package/dist/transport/index.d.ts +0 -7
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/index.js +0 -6
- package/dist/transport/index.js.map +0 -1
- package/dist/transport/types.d.ts +0 -69
- package/dist/transport/types.d.ts.map +0 -1
- package/dist/transport/types.js +0 -5
- package/dist/transport/types.js.map +0 -1
- package/dist/transport/websocket.d.ts +0 -38
- package/dist/transport/websocket.d.ts.map +0 -1
- package/dist/transport/websocket.js +0 -276
- package/dist/transport/websocket.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Ironflow License
|
|
2
|
+
|
|
3
|
+
**Version 1.0 — 2026-05-08**
|
|
4
|
+
|
|
5
|
+
This file contains the binding legal terms under which Ironflow is offered.
|
|
6
|
+
A plain-English summary lives at `docs/explanation/licensing.md`. If the two
|
|
7
|
+
disagree, this file controls.
|
|
8
|
+
|
|
9
|
+
> **Lawyer review status:** v1 DIY-substitute. Pending counsel review before
|
|
10
|
+
> the first paid customer ships (issue #777). All of the following MUST be
|
|
11
|
+
> resolved before this license is published on the public release mirror:
|
|
12
|
+
>
|
|
13
|
+
> - `[LICENSOR_ENTITY]` placeholder filled with the legal entity name
|
|
14
|
+
> - `[LICENSE_EMAIL]` placeholder filled with the commercial-licensing
|
|
15
|
+
> contact address
|
|
16
|
+
> - "Personal-Use and Evaluation Carve-Out" section reviewed by counsel —
|
|
17
|
+
> this is supplemental to the FSL Permitted Purpose and was added to
|
|
18
|
+
> match the worked examples in `docs/explanation/licensing.md` per the
|
|
19
|
+
> plan body. JetBrains Toolbox + Postman free-tier EULAs were the
|
|
20
|
+
> reference for the carve-out shape, but the wording is original prose
|
|
21
|
+
> and has not been counsel-reviewed.
|
|
22
|
+
> - "Governing Law and Venue" + "Commercial Licensing" sections reviewed
|
|
23
|
+
> by counsel — these are original prose, not part of the FSL template.
|
|
24
|
+
>
|
|
25
|
+
> **Versioning:** revised terms apply on next install. Each release ships
|
|
26
|
+
> the LICENSE that was effective at the time the artifact was built.
|
|
27
|
+
> Continuing to use a previously installed version under its prior terms
|
|
28
|
+
> is permitted; upgrading to a newer release accepts the LICENSE shipped
|
|
29
|
+
> with that release.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Functional Source License, Version 1.1, ALv2 Future License
|
|
34
|
+
|
|
35
|
+
## Abbreviation
|
|
36
|
+
|
|
37
|
+
FSL-1.1-ALv2
|
|
38
|
+
|
|
39
|
+
## Notice
|
|
40
|
+
|
|
41
|
+
Copyright 2026 [LICENSOR_ENTITY]
|
|
42
|
+
|
|
43
|
+
## Terms and Conditions
|
|
44
|
+
|
|
45
|
+
### Licensor ("We")
|
|
46
|
+
|
|
47
|
+
The party offering the Software under these Terms and Conditions.
|
|
48
|
+
|
|
49
|
+
### The Software
|
|
50
|
+
|
|
51
|
+
The "Software" is each version of the software that we make available under
|
|
52
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
53
|
+
Conditions with the Software.
|
|
54
|
+
|
|
55
|
+
### License Grant
|
|
56
|
+
|
|
57
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
58
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
59
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
60
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
61
|
+
|
|
62
|
+
### Permitted Purpose
|
|
63
|
+
|
|
64
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
65
|
+
means making the Software available to others in a commercial product or
|
|
66
|
+
service that:
|
|
67
|
+
|
|
68
|
+
1. substitutes for the Software;
|
|
69
|
+
|
|
70
|
+
2. substitutes for any other product or service we offer using the Software
|
|
71
|
+
that exists as of the date we make the Software available; or
|
|
72
|
+
|
|
73
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
74
|
+
|
|
75
|
+
Permitted Purposes specifically include using the Software:
|
|
76
|
+
|
|
77
|
+
1. for your internal use and access;
|
|
78
|
+
|
|
79
|
+
2. for non-commercial education;
|
|
80
|
+
|
|
81
|
+
3. for non-commercial research; and
|
|
82
|
+
|
|
83
|
+
4. in connection with professional services that you provide to a licensee
|
|
84
|
+
using the Software in accordance with these Terms and Conditions.
|
|
85
|
+
|
|
86
|
+
### Patents
|
|
87
|
+
|
|
88
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
89
|
+
patents, the license grant above includes a license under our patents. If you
|
|
90
|
+
make a claim against any party that the Software infringes or contributes to
|
|
91
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
92
|
+
immediately.
|
|
93
|
+
|
|
94
|
+
### Redistribution
|
|
95
|
+
|
|
96
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
97
|
+
the Software.
|
|
98
|
+
|
|
99
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
100
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
101
|
+
remove any copyright notices provided in or with the Software.
|
|
102
|
+
|
|
103
|
+
### Disclaimer
|
|
104
|
+
|
|
105
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
106
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
107
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
108
|
+
|
|
109
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
110
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
111
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
112
|
+
|
|
113
|
+
### Trademarks
|
|
114
|
+
|
|
115
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
116
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
117
|
+
trademarks, trade names, service marks or product names.
|
|
118
|
+
|
|
119
|
+
## Grant of Future License
|
|
120
|
+
|
|
121
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
122
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
123
|
+
the date we make the Software available. On or after that date, you may use the
|
|
124
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
125
|
+
will apply:
|
|
126
|
+
|
|
127
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
128
|
+
this file except in compliance with the License.
|
|
129
|
+
|
|
130
|
+
You may obtain a copy of the License at
|
|
131
|
+
|
|
132
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
133
|
+
|
|
134
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
135
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
136
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
137
|
+
specific language governing permissions and limitations under the License.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Personal-Use and Evaluation Carve-Out
|
|
142
|
+
|
|
143
|
+
> _Supplemental to the FSL Permitted Purpose above. Pending counsel review._
|
|
144
|
+
|
|
145
|
+
The following uses are explicitly permitted in addition to the FSL Permitted
|
|
146
|
+
Purposes listed above:
|
|
147
|
+
|
|
148
|
+
1. **Personal use.** Use of the Software by a natural person for that
|
|
149
|
+
person's personal, non-commercial purposes — including hobby projects,
|
|
150
|
+
self-education, and side projects that do not generate revenue or
|
|
151
|
+
commercial advantage.
|
|
152
|
+
|
|
153
|
+
2. **Evaluation.** Use of the Software by any individual or organization for
|
|
154
|
+
the purpose of evaluating the Software prior to a commercial purchase
|
|
155
|
+
decision, for a period of up to ninety (90) days from first install.
|
|
156
|
+
Evaluation use does not require notification.
|
|
157
|
+
|
|
158
|
+
These carve-outs are non-transferable and do not extend to redistribution,
|
|
159
|
+
sublicensing, or any Competing Use as defined in the FSL Permitted Purpose
|
|
160
|
+
section.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Governing Law and Venue
|
|
165
|
+
|
|
166
|
+
These Terms and Conditions are governed by the laws of the State of Delaware,
|
|
167
|
+
United States of America, without regard to its conflict-of-laws provisions.
|
|
168
|
+
Any dispute arising out of or relating to these Terms and Conditions shall be
|
|
169
|
+
brought exclusively in the state or federal courts located in Delaware, and
|
|
170
|
+
you consent to the personal jurisdiction of those courts.
|
|
171
|
+
|
|
172
|
+
## Commercial Licensing
|
|
173
|
+
|
|
174
|
+
For uses that fall outside the Permitted Purpose — including any Competing
|
|
175
|
+
Use, or any commercial use case for which a separate paid license is required
|
|
176
|
+
under our Cloud or Enterprise terms — contact `[LICENSE_EMAIL]` to discuss
|
|
177
|
+
a commercial license.
|
|
178
|
+
|
|
179
|
+
## SPDX Identifier
|
|
180
|
+
|
|
181
|
+
`LicenseRef-Ironflow-EULA`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ironflow/browser",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.2",
|
|
4
4
|
"description": "Browser client for Ironflow event-driven backend platform - real-time subscriptions, workflow triggers, and event emission",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@bufbuild/protobuf": "^2.
|
|
21
|
+
"@bufbuild/protobuf": "^2.12.0",
|
|
22
22
|
"@connectrpc/connect": "^2.1.1",
|
|
23
23
|
"@connectrpc/connect-web": "^2.1.1",
|
|
24
|
-
"zod": "^4.3
|
|
25
|
-
"@ironflow/core": "^0.20.
|
|
24
|
+
"zod": "^4.4.3",
|
|
25
|
+
"@ironflow/core": "^0.20.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^22.
|
|
29
|
-
"esbuild": "^0.27.
|
|
30
|
-
"jsdom": "^26.
|
|
28
|
+
"@types/node": "^22.19.18",
|
|
29
|
+
"esbuild": "^0.27.7",
|
|
30
|
+
"jsdom": "^26.1.0",
|
|
31
31
|
"typescript": "^5.9.3",
|
|
32
32
|
"vitest": "^2.1.9"
|
|
33
33
|
},
|
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
"subscriptions"
|
|
52
52
|
],
|
|
53
53
|
"author": "Ironflow",
|
|
54
|
-
"license": "
|
|
54
|
+
"license": "LicenseRef-Ironflow-EULA",
|
|
55
55
|
"repository": {
|
|
56
56
|
"type": "git",
|
|
57
57
|
"url": "https://github.com/ironflowapp/ironflow.git",
|
|
58
58
|
"directory": "sdk/js/browser"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
|
-
"access": "
|
|
61
|
+
"access": "public"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsc --build tsconfig.build.json",
|
package/dist/agents/index.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ironflow.agents` namespace.
|
|
3
|
-
*
|
|
4
|
-
* Browser-facing helpers for `agent()` functions: fire-and-wait `invoke`,
|
|
5
|
-
* typed `subscribe` for run/step events, and `readMemory` for typed
|
|
6
|
-
* projection state reads.
|
|
7
|
-
*
|
|
8
|
-
* Spec: ./spec.md
|
|
9
|
-
*/
|
|
10
|
-
import type { Subscription } from "@ironflow/core";
|
|
11
|
-
import type { AgentClientLike, AgentInvokeOptions, AgentInvokeResult, AgentMemoryResult, AgentReadMemoryOptions, AgentSubscribeCallbacks } from "./types.js";
|
|
12
|
-
export type { AgentClientLike, AgentInvokeOptions, AgentInvokeResult, AgentMemoryResult, AgentProgressEvent, AgentReadMemoryOptions, AgentStepEvent, AgentSubscribeCallbacks, } from "./types.js";
|
|
13
|
-
/**
|
|
14
|
-
* The shape exposed as `ironflow.agents`.
|
|
15
|
-
*/
|
|
16
|
-
export interface AgentSubscribeRuntimeOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Number of historical events to replay on attach. Default: 1000.
|
|
19
|
-
* Covers events emitted between `agents.invoke()` returning a runId
|
|
20
|
-
* via `onRunStarted` and this subscribe attaching.
|
|
21
|
-
*/
|
|
22
|
-
replay?: number;
|
|
23
|
-
}
|
|
24
|
-
export interface AgentsNamespace {
|
|
25
|
-
invoke<TOutput = unknown>(name: string, payload: unknown, opts?: AgentInvokeOptions): Promise<AgentInvokeResult<TOutput>>;
|
|
26
|
-
subscribe(runId: string, callbacks: AgentSubscribeCallbacks, opts?: AgentSubscribeRuntimeOptions): Promise<Subscription>;
|
|
27
|
-
readMemory<TState = unknown>(projection: string, opts?: AgentReadMemoryOptions): Promise<AgentMemoryResult<TState>>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Build the `agents` namespace bound to a specific client. Called by
|
|
31
|
-
* the IronflowClient constructor.
|
|
32
|
-
*/
|
|
33
|
-
export declare function createAgentsNamespace(client: AgentClientLike): AgentsNamespace;
|
|
34
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,cAAc,EACd,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,OAAO,GAAG,OAAO,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IAEvC,SAAS,CACP,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,uBAAuB,EAClC,IAAI,CAAC,EAAE,4BAA4B,GAClC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEzB,UAAU,CAAC,MAAM,GAAG,OAAO,EACzB,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,sBAAsB,GAC5B,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,eAAe,GACtB,eAAe,CAOjB"}
|
package/dist/agents/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ironflow.agents` namespace.
|
|
3
|
-
*
|
|
4
|
-
* Browser-facing helpers for `agent()` functions: fire-and-wait `invoke`,
|
|
5
|
-
* typed `subscribe` for run/step events, and `readMemory` for typed
|
|
6
|
-
* projection state reads.
|
|
7
|
-
*
|
|
8
|
-
* Spec: ./spec.md
|
|
9
|
-
*/
|
|
10
|
-
import { invoke as agentInvoke } from "./invoke.js";
|
|
11
|
-
import { readMemory as agentReadMemory } from "./readMemory.js";
|
|
12
|
-
import { subscribe as agentSubscribe } from "./subscribe.js";
|
|
13
|
-
/**
|
|
14
|
-
* Build the `agents` namespace bound to a specific client. Called by
|
|
15
|
-
* the IronflowClient constructor.
|
|
16
|
-
*/
|
|
17
|
-
export function createAgentsNamespace(client) {
|
|
18
|
-
return {
|
|
19
|
-
invoke: (name, payload, opts) => agentInvoke(client, name, payload, opts),
|
|
20
|
-
subscribe: (runId, callbacks, opts) => agentSubscribe(client, runId, callbacks, opts),
|
|
21
|
-
readMemory: (projection, opts) => agentReadMemory(client, projection, opts),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
package/dist/agents/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,SAAS,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAoD7D;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAuB;IAEvB,OAAO;QACL,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC;QACzE,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CACpC,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC;QAChD,UAAU,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,CAAC;KAC5E,CAAC;AACJ,CAAC"}
|
package/dist/agents/invoke.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ironflow.agents.invoke()` — fire-and-wait against an agent function.
|
|
3
|
-
*
|
|
4
|
-
* Composes the existing async `client.invoke()` + `client.subscribe()` to
|
|
5
|
-
* deliver a single Promise<{runId, output, durationMs}>.
|
|
6
|
-
*
|
|
7
|
-
* Race window between Trigger return and subscribe attach is covered by
|
|
8
|
-
* `subscribe({replay})` — see ./spec.md.
|
|
9
|
-
*/
|
|
10
|
-
import type { AgentClientLike, AgentInvokeOptions, AgentInvokeResult } from "./types.js";
|
|
11
|
-
/**
|
|
12
|
-
* Fire-and-wait: trigger the named agent function, subscribe to its run
|
|
13
|
-
* events, and resolve when a terminal event arrives.
|
|
14
|
-
*/
|
|
15
|
-
export declare function invoke<TOutput = unknown>(client: AgentClientLike, name: string, payload: unknown, opts?: AgentInvokeOptions): Promise<AgentInvokeResult<TOutput>>;
|
|
16
|
-
//# sourceMappingURL=invoke.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../src/agents/invoke.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAWH,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAsEpB;;;GAGG;AACH,wBAAsB,MAAM,CAAC,OAAO,GAAG,OAAO,EAC5C,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAiKrC"}
|
package/dist/agents/invoke.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ironflow.agents.invoke()` — fire-and-wait against an agent function.
|
|
3
|
-
*
|
|
4
|
-
* Composes the existing async `client.invoke()` + `client.subscribe()` to
|
|
5
|
-
* deliver a single Promise<{runId, output, durationMs}>.
|
|
6
|
-
*
|
|
7
|
-
* Race window between Trigger return and subscribe attach is covered by
|
|
8
|
-
* `subscribe({replay})` — see ./spec.md.
|
|
9
|
-
*/
|
|
10
|
-
import { AgentInvokeTimeoutError, NoRunCreatedError, RunCancelledError, RunFailedError, ValidationError, } from "@ironflow/core";
|
|
11
|
-
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
12
|
-
// Match the server-side `ReplayMaxEvents` default (1000). Replay-from-zero
|
|
13
|
-
// against a per-run subject is bounded by the run's own emission rate, so
|
|
14
|
-
// 1000 covers ~500 steps (each emits `created`+`completed`) plus run
|
|
15
|
-
// lifecycle events. Step-heavier agents should raise both this option and
|
|
16
|
-
// the server's `ReplayMaxEvents` config.
|
|
17
|
-
const DEFAULT_REPLAY = 1000;
|
|
18
|
-
const MAX_NAME_LENGTH = 256;
|
|
19
|
-
// Defense-in-depth: even though the server is the source of `runId`, we
|
|
20
|
-
// guard against a misbehaving server or mock returning NATS metacharacters
|
|
21
|
-
// (`*`, `>`, `.`) that would widen the subscribe pattern.
|
|
22
|
-
const RUN_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
23
|
-
/**
|
|
24
|
-
* Validate the function name argument. Server validates the rest; we just
|
|
25
|
-
* catch the obviously broken cases client-side to fail fast.
|
|
26
|
-
*/
|
|
27
|
-
function validateName(name) {
|
|
28
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
29
|
-
throw new ValidationError("agents.invoke: name must be a non-empty string");
|
|
30
|
-
}
|
|
31
|
-
if (name.length > MAX_NAME_LENGTH) {
|
|
32
|
-
throw new ValidationError(`agents.invoke: name exceeds ${MAX_NAME_LENGTH} chars`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Extract terminal-event verdict from a topic suffix. Returns null for
|
|
37
|
-
* non-terminal events.
|
|
38
|
-
*
|
|
39
|
-
* Topics: `system.run.{runId}.{event}` where event ∈
|
|
40
|
-
* { created, updated, resumed, completed, failed, cancelled }.
|
|
41
|
-
* Step events live under `.step.{stepId}.{type}`.
|
|
42
|
-
*/
|
|
43
|
-
function classifyTerminal(topic) {
|
|
44
|
-
if (topic.includes(".step."))
|
|
45
|
-
return null;
|
|
46
|
-
if (topic.endsWith(".completed"))
|
|
47
|
-
return "completed";
|
|
48
|
-
if (topic.endsWith(".failed"))
|
|
49
|
-
return "failed";
|
|
50
|
-
if (topic.endsWith(".cancelled"))
|
|
51
|
-
return "cancelled";
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
function extractError(data) {
|
|
55
|
-
if (data && typeof data === "object" && "error" in data) {
|
|
56
|
-
const err = data.error;
|
|
57
|
-
if (typeof err === "string") {
|
|
58
|
-
return { message: err };
|
|
59
|
-
}
|
|
60
|
-
if (err && typeof err === "object") {
|
|
61
|
-
return {
|
|
62
|
-
message: err.message ?? "Run failed",
|
|
63
|
-
code: err.code,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return { message: "Run failed" };
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Fire-and-wait: trigger the named agent function, subscribe to its run
|
|
71
|
-
* events, and resolve when a terminal event arrives.
|
|
72
|
-
*/
|
|
73
|
-
export async function invoke(client, name, payload, opts = {}) {
|
|
74
|
-
validateName(name);
|
|
75
|
-
// Pre-flight abort: throw before any network I/O.
|
|
76
|
-
if (opts.signal?.aborted) {
|
|
77
|
-
throw new DOMException("Aborted", "AbortError");
|
|
78
|
-
}
|
|
79
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
80
|
-
const replay = opts.replay ?? DEFAULT_REPLAY;
|
|
81
|
-
const startedAt = Date.now();
|
|
82
|
-
// 1) Trigger the agent. Server returns runId.
|
|
83
|
-
const triggerResult = await client.invoke(name, {
|
|
84
|
-
data: payload,
|
|
85
|
-
idempotencyKey: opts.idempotencyKey,
|
|
86
|
-
});
|
|
87
|
-
const runId = triggerResult.runIds?.[0];
|
|
88
|
-
if (!runId) {
|
|
89
|
-
throw new NoRunCreatedError(name);
|
|
90
|
-
}
|
|
91
|
-
// Defense-in-depth: server is the source of truth, but reject obviously
|
|
92
|
-
// malformed runIds before interpolating them into a NATS subject.
|
|
93
|
-
if (!RUN_ID_PATTERN.test(runId)) {
|
|
94
|
-
throw new ValidationError(`agents.invoke: server returned invalid runId "${runId}" (must match ${RUN_ID_PATTERN})`);
|
|
95
|
-
}
|
|
96
|
-
// Single deferred. resolve/reject from subscribe callback, timeout, or abort.
|
|
97
|
-
let settled = false;
|
|
98
|
-
let resolveOuter = () => { };
|
|
99
|
-
let rejectOuter = () => { };
|
|
100
|
-
const settle = (fn) => {
|
|
101
|
-
if (settled)
|
|
102
|
-
return;
|
|
103
|
-
settled = true;
|
|
104
|
-
fn();
|
|
105
|
-
};
|
|
106
|
-
const outer = new Promise((res, rej) => {
|
|
107
|
-
resolveOuter = res;
|
|
108
|
-
rejectOuter = rej;
|
|
109
|
-
});
|
|
110
|
-
// Attach a no-op handler eagerly so a fast settle() (e.g., synchronous
|
|
111
|
-
// timer or pre-subscribe abort) does not surface as an unhandled
|
|
112
|
-
// rejection before the awaiter below attaches. The original `outer`
|
|
113
|
-
// promise is unchanged and will still reject through `await outer`.
|
|
114
|
-
outer.catch(() => {
|
|
115
|
-
/* observed; real consumer is `await outer` below */
|
|
116
|
-
});
|
|
117
|
-
// Arm timeout + abort BEFORE running the user-provided onRunStarted hook
|
|
118
|
-
// so a hanging hook cannot bypass `timeoutMs` / `signal`.
|
|
119
|
-
const timeoutHandle = setTimeout(() => {
|
|
120
|
-
settle(() => rejectOuter(new AgentInvokeTimeoutError(runId, timeoutMs)));
|
|
121
|
-
}, timeoutMs);
|
|
122
|
-
const abortHandler = () => {
|
|
123
|
-
settle(() => rejectOuter(new DOMException("Aborted", "AbortError")));
|
|
124
|
-
};
|
|
125
|
-
opts.signal?.addEventListener("abort", abortHandler, { once: true });
|
|
126
|
-
// Surface runId immediately so callers can attach a separate progress
|
|
127
|
-
// subscription via agents.subscribe(runId) without waiting for terminal.
|
|
128
|
-
// We await onRunStarted so the caller's async hook (e.g., attaching a
|
|
129
|
-
// watcher) completes before the SDK starts dispatching terminal events,
|
|
130
|
-
// preventing late events from leaking into a subsequent run's UI. The
|
|
131
|
-
// hook is bounded by the timeout/abort armed above.
|
|
132
|
-
if (opts.onRunStarted && !settled) {
|
|
133
|
-
try {
|
|
134
|
-
await opts.onRunStarted(runId);
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
/* swallow — caller's bug is not ours */
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
// Subscribe and wire dispatch. Race the attach against the deferred so
|
|
141
|
-
// a hung subscribe call cannot wedge the invoke past `timeoutMs`/abort.
|
|
142
|
-
let unsubscribe;
|
|
143
|
-
const subscribePromise = client
|
|
144
|
-
.subscribe(`system.run.${runId}.>`, {
|
|
145
|
-
replay,
|
|
146
|
-
onEvent: (event) => {
|
|
147
|
-
if (settled)
|
|
148
|
-
return;
|
|
149
|
-
const verdict = classifyTerminal(event.topic);
|
|
150
|
-
if (!verdict)
|
|
151
|
-
return;
|
|
152
|
-
if (verdict === "completed") {
|
|
153
|
-
const output = event.data?.output;
|
|
154
|
-
settle(() => resolveOuter({
|
|
155
|
-
runId,
|
|
156
|
-
output,
|
|
157
|
-
durationMs: Date.now() - startedAt,
|
|
158
|
-
}));
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (verdict === "failed") {
|
|
162
|
-
const err = extractError(event.data);
|
|
163
|
-
settle(() => rejectOuter(new RunFailedError(runId, event.data, err.message)));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
settle(() => rejectOuter(new RunCancelledError(runId)));
|
|
167
|
-
},
|
|
168
|
-
onError: (subErr) => {
|
|
169
|
-
settle(() => rejectOuter(new Error(`agents.invoke subscription error: ${subErr.message}`)));
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
.then((sub) => {
|
|
173
|
-
unsubscribe = () => {
|
|
174
|
-
try {
|
|
175
|
-
sub.unsubscribe();
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
/* idempotent */
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
// Race already settled before subscribe attached: clean up now.
|
|
182
|
-
if (settled)
|
|
183
|
-
unsubscribe();
|
|
184
|
-
})
|
|
185
|
-
.catch((err) => {
|
|
186
|
-
settle(() => rejectOuter(err));
|
|
187
|
-
});
|
|
188
|
-
// Don't block on subscribePromise; the outer race continues to fire on
|
|
189
|
-
// timeout/abort even if the attach never resolves.
|
|
190
|
-
void subscribePromise;
|
|
191
|
-
try {
|
|
192
|
-
return await outer;
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
// Property check on `name` instead of `instanceof DOMException` for
|
|
196
|
-
// cross-runtime compatibility (some test runners and older Node
|
|
197
|
-
// builds don't share a DOMException prototype).
|
|
198
|
-
const isAbort = typeof err === "object" &&
|
|
199
|
-
err !== null &&
|
|
200
|
-
"name" in err &&
|
|
201
|
-
err.name === "AbortError";
|
|
202
|
-
if (err instanceof AgentInvokeTimeoutError || isAbort) {
|
|
203
|
-
// Fire-and-forget: do NOT await the cancel. A hanging cancelRun
|
|
204
|
-
// would block propagation of the original timeout/abort error to
|
|
205
|
-
// the caller. The unhandled-rejection guard preserves error
|
|
206
|
-
// observability without blocking.
|
|
207
|
-
void client
|
|
208
|
-
.cancelRun(runId, "agents.invoke aborted")
|
|
209
|
-
.catch(() => {
|
|
210
|
-
/* swallow — best-effort */
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
throw err;
|
|
214
|
-
}
|
|
215
|
-
finally {
|
|
216
|
-
clearTimeout(timeoutHandle);
|
|
217
|
-
opts.signal?.removeEventListener("abort", abortHandler);
|
|
218
|
-
if (unsubscribe)
|
|
219
|
-
unsubscribe();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
//# sourceMappingURL=invoke.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoke.js","sourceRoot":"","sources":["../../src/agents/invoke.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;A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QACD,MAAM,GAAG,CAAC;IACZ,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,aAAa,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACxD,IAAI,WAAW;YAAE,WAAW,EAAE,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ironflow.agents.readMemory()` — typed read of an agent memory
|
|
3
|
-
* projection with optional read-your-writes catchup.
|
|
4
|
-
*
|
|
5
|
-
* Composes `client.waitForProjectionCatchup` (when `opts.minSeq` is set)
|
|
6
|
-
* + `client.getProjection`. See ./spec.md.
|
|
7
|
-
*/
|
|
8
|
-
import type { AgentClientLike, AgentMemoryResult, AgentReadMemoryOptions } from "./types.js";
|
|
9
|
-
/**
|
|
10
|
-
* Read materialized projection state for an agent memory.
|
|
11
|
-
*
|
|
12
|
-
* When `opts.minSeq` is provided, waits for the projection to catch up
|
|
13
|
-
* before reading. This delivers read-your-writes semantics for callers
|
|
14
|
-
* that just appended an event (use the seq returned from
|
|
15
|
-
* `streams.append`).
|
|
16
|
-
*/
|
|
17
|
-
export declare function readMemory<TState = unknown>(client: AgentClientLike, projection: string, opts?: AgentReadMemoryOptions): Promise<AgentMemoryResult<TState>>;
|
|
18
|
-
//# sourceMappingURL=readMemory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readMemory.d.ts","sourceRoot":"","sources":["../../src/agents/readMemory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAsDpB;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,MAAM,GAAG,OAAO,EAC/C,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CA4CpC"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ironflow.agents.readMemory()` — typed read of an agent memory
|
|
3
|
-
* projection with optional read-your-writes catchup.
|
|
4
|
-
*
|
|
5
|
-
* Composes `client.waitForProjectionCatchup` (when `opts.minSeq` is set)
|
|
6
|
-
* + `client.getProjection`. See ./spec.md.
|
|
7
|
-
*/
|
|
8
|
-
import { MemoryCatchupTimeoutError, ValidationError, } from "@ironflow/core";
|
|
9
|
-
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
10
|
-
const MAX_NAME_LENGTH = 256;
|
|
11
|
-
function validateProjection(name) {
|
|
12
|
-
if (typeof name !== "string" || name.length === 0) {
|
|
13
|
-
throw new ValidationError("agents.readMemory: projection must be a non-empty string");
|
|
14
|
-
}
|
|
15
|
-
if (name.length > MAX_NAME_LENGTH) {
|
|
16
|
-
throw new ValidationError(`agents.readMemory: projection exceeds ${MAX_NAME_LENGTH} chars`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function throwIfAborted(signal) {
|
|
20
|
-
if (signal?.aborted) {
|
|
21
|
-
throw new DOMException("Aborted", "AbortError");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Race a Promise against a caller-supplied AbortSignal. Resolves with
|
|
26
|
-
* the original promise unless the signal aborts first, in which case
|
|
27
|
-
* an AbortError is thrown. The original promise is left to settle in
|
|
28
|
-
* the background — its result is discarded.
|
|
29
|
-
*/
|
|
30
|
-
function raceAbort(p, signal) {
|
|
31
|
-
if (!signal)
|
|
32
|
-
return p;
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
const onAbort = () => {
|
|
35
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
36
|
-
};
|
|
37
|
-
if (signal.aborted) {
|
|
38
|
-
onAbort();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
42
|
-
p.then((v) => {
|
|
43
|
-
signal.removeEventListener("abort", onAbort);
|
|
44
|
-
resolve(v);
|
|
45
|
-
}, (err) => {
|
|
46
|
-
signal.removeEventListener("abort", onAbort);
|
|
47
|
-
reject(err);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Read materialized projection state for an agent memory.
|
|
53
|
-
*
|
|
54
|
-
* When `opts.minSeq` is provided, waits for the projection to catch up
|
|
55
|
-
* before reading. This delivers read-your-writes semantics for callers
|
|
56
|
-
* that just appended an event (use the seq returned from
|
|
57
|
-
* `streams.append`).
|
|
58
|
-
*/
|
|
59
|
-
export async function readMemory(client, projection, opts = {}) {
|
|
60
|
-
validateProjection(projection);
|
|
61
|
-
throwIfAborted(opts.signal);
|
|
62
|
-
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
63
|
-
// Treat `minSeq=0` / `0n` as "no catchup required" per the spec —
|
|
64
|
-
// saves a no-op round trip when callers default the param.
|
|
65
|
-
const minSeqProvided = opts.minSeq !== undefined && opts.minSeq !== 0 && opts.minSeq !== 0n;
|
|
66
|
-
if (minSeqProvided) {
|
|
67
|
-
const waitResult = await raceAbort(client.waitForProjectionCatchup(projection, {
|
|
68
|
-
minSeq: opts.minSeq,
|
|
69
|
-
timeoutMs,
|
|
70
|
-
partition: opts.partition,
|
|
71
|
-
}), opts.signal);
|
|
72
|
-
if (waitResult.timedOut) {
|
|
73
|
-
throw new MemoryCatchupTimeoutError(projection, BigInt(opts.minSeq), timeoutMs);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
throwIfAborted(opts.signal);
|
|
77
|
-
const stateResult = await raceAbort(client.getProjection(projection, {
|
|
78
|
-
partition: opts.partition,
|
|
79
|
-
}), opts.signal);
|
|
80
|
-
return {
|
|
81
|
-
state: stateResult.state,
|
|
82
|
-
version: stateResult.version,
|
|
83
|
-
lastEventId: stateResult.lastEventId || undefined,
|
|
84
|
-
caughtUp: true,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=readMemory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"readMemory.js","sourceRoot":"","sources":["../../src/agents/readMemory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,yBAAyB,EACzB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAQxB,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,SAAS,kBAAkB,CAAC,IAAY;IACtC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,eAAe,CACvB,0DAA0D,CAC3D,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;QAClC,MAAM,IAAI,eAAe,CACvB,yCAAyC,eAAe,QAAQ,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,MAA+B;IACrD,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAI,CAAa,EAAE,MAA+B;IAClE,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IACtB,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACxC,MAAM,OAAO,GAAG,GAAS,EAAE;YACzB,MAAM,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC;QACF,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,EAAE,CAAC;YACV,OAA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