@kuralle-agents/core 0.2.1 → 0.3.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/LICENSE +202 -0
- package/dist/debug.d.ts +3 -0
- package/dist/debug.js +7 -0
- package/dist/flow/emitInteractive.d.ts +3 -0
- package/dist/flow/emitInteractive.js +43 -0
- package/dist/flow/extraction.d.ts +0 -6
- package/dist/flow/extraction.js +6 -6
- package/dist/flow/nodeBuilders.d.ts +0 -2
- package/dist/flow/nodeBuilders.js +1 -1
- package/dist/flow/normalizeTransition.d.ts +0 -1
- package/dist/flow/normalizeTransition.js +1 -1
- package/dist/flow/reduceTransition.js +2 -0
- package/dist/flow/runFlow.d.ts +1 -3
- package/dist/flow/runFlow.js +4 -2
- package/dist/flows/extraction.d.ts +0 -7
- package/dist/flows/extraction.js +0 -16
- package/dist/flows/template.d.ts +2 -3
- package/dist/flows/template.js +0 -3
- package/dist/flows/transitions.d.ts +4 -32
- package/dist/flows/transitions.js +0 -20
- package/dist/guards/ToolEnforcer.js +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/runtime/Runtime.d.ts +4 -0
- package/dist/runtime/Runtime.js +9 -0
- package/dist/runtime/channels/TextDriver.js +14 -10
- package/dist/runtime/channels/VoiceDriver.js +14 -10
- package/dist/runtime/channels/index.d.ts +1 -1
- package/dist/runtime/channels/index.js +1 -1
- package/dist/runtime/channels/voiceTools.d.ts +0 -1
- package/dist/runtime/channels/voiceTools.js +0 -10
- package/dist/runtime/citations/index.d.ts +1 -12
- package/dist/runtime/citations/index.js +0 -36
- package/dist/runtime/contextOverflow.d.ts +0 -11
- package/dist/runtime/contextOverflow.js +0 -23
- package/dist/runtime/ctx.d.ts +2 -2
- package/dist/runtime/ctx.js +20 -1
- package/dist/runtime/durable/idempotency.d.ts +0 -1
- package/dist/runtime/durable/idempotency.js +1 -1
- package/dist/runtime/durable/replay.d.ts +0 -1
- package/dist/runtime/durable/replay.js +1 -1
- package/dist/runtime/durable/types.d.ts +2 -1
- package/dist/runtime/openRun.d.ts +2 -0
- package/dist/runtime/openRun.js +9 -3
- package/dist/runtime/policies/agentTurn.d.ts +0 -5
- package/dist/runtime/policies/agentTurn.js +0 -6
- package/dist/runtime/policies/limits.d.ts +0 -1
- package/dist/runtime/policies/limits.js +1 -1
- package/dist/runtime/policies/resolvePolicies.d.ts +0 -3
- package/dist/runtime/policies/resolvePolicies.js +0 -13
- package/dist/runtime/promptCache.d.ts +0 -4
- package/dist/tools/Tool.d.ts +0 -6
- package/dist/tools/Tool.js +0 -8
- package/dist/tools/effect/ToolExecutor.d.ts +2 -0
- package/dist/tools/effect/ToolExecutor.js +6 -1
- package/dist/tools/effect/errors.d.ts +10 -0
- package/dist/tools/effect/errors.js +15 -0
- package/dist/tools/effect/index.d.ts +1 -0
- package/dist/tools/effect/index.js +1 -0
- package/dist/tools/errorHandling.d.ts +0 -1
- package/dist/types/channel.d.ts +2 -1
- package/dist/types/flow.d.ts +3 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/run-context.d.ts +7 -0
- package/dist/types/selection.d.ts +18 -0
- package/dist/types/selection.js +1 -0
- package/dist/types/stream.d.ts +11 -0
- package/package.json +14 -10
- package/dist/events/index.d.ts +0 -2
- package/dist/events/index.js +0 -1
- package/dist/flow/index.d.ts +0 -10
- package/dist/flow/index.js +0 -10
- package/dist/runtime/SessionEventManager.d.ts +0 -16
- package/dist/runtime/SessionEventManager.js +0 -148
- package/dist/runtime/durable/index.d.ts +0 -5
- package/dist/runtime/durable/index.js +0 -5
- package/dist/runtime/policies/index.d.ts +0 -3
- package/dist/runtime/policies/index.js +0 -3
- package/dist/runtime/tokenSessionUtils.d.ts +0 -5
- package/dist/runtime/tokenSessionUtils.js +0 -24
- package/dist/tools/transferToTriage.d.ts +0 -15
- package/dist/tools/transferToTriage.js +0 -48
- package/dist/utils/aiStream.d.ts +0 -6
- package/dist/utils/aiStream.js +0 -48
- package/dist/utils/streamChunk.d.ts +0 -4
- package/dist/utils/streamChunk.js +0 -49
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/debug.d.ts
ADDED
package/dist/debug.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const ENABLED = typeof process !== 'undefined' && Boolean(process.env?.KURALLE_DEBUG);
|
|
2
|
+
/** Gated debug logger — a no-op unless KURALLE_DEBUG is set. Keeps library
|
|
3
|
+
* output off a consumer's stdout by default while preserving traces for debugging. */
|
|
4
|
+
export function debug(...args) {
|
|
5
|
+
if (ENABLED)
|
|
6
|
+
console.log(...args);
|
|
7
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { resolveInstructions } from './nodeBuilders.js';
|
|
2
|
+
import { isCollectNode, isDecideNode } from './nodeKinds.js';
|
|
3
|
+
function resolveCollectPrompt(instructions, state) {
|
|
4
|
+
const inst = instructions([], state);
|
|
5
|
+
if (typeof inst === 'string') {
|
|
6
|
+
return inst;
|
|
7
|
+
}
|
|
8
|
+
if (typeof inst === 'function') {
|
|
9
|
+
const result = inst({ state });
|
|
10
|
+
return typeof result === 'string' ? result : '';
|
|
11
|
+
}
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
function interactivePrompt(node, state) {
|
|
15
|
+
if (node.kind === 'decide') {
|
|
16
|
+
try {
|
|
17
|
+
return resolveInstructions(node.instructions, state);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!node.instructions) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return resolveCollectPrompt(node.instructions, state);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function emitInteractiveOnNodeEnter(node, state, emit) {
|
|
34
|
+
if (!(isCollectNode(node) || isDecideNode(node)) || !node.choices?.length) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
emit({
|
|
38
|
+
type: 'interactive',
|
|
39
|
+
nodeId: node.id,
|
|
40
|
+
options: node.choices,
|
|
41
|
+
prompt: interactivePrompt(node, state),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import type { CollectNode, FlowState } from '../types/flow.js';
|
|
2
2
|
import type { Tool } from '../types/effectTool.js';
|
|
3
|
-
export declare function collectDataKey(nodeId: string): string;
|
|
4
|
-
export declare function collectTurnsKey(nodeId: string): string;
|
|
5
3
|
export declare function getCollectData(state: FlowState, nodeId: string): Record<string, unknown>;
|
|
6
|
-
export declare function setCollectData(state: FlowState, nodeId: string, data: Record<string, unknown>): void;
|
|
7
|
-
export declare function getCollectTurns(state: FlowState, nodeId: string): number;
|
|
8
4
|
export declare function incrementCollectTurns(state: FlowState, nodeId: string): number;
|
|
9
5
|
export declare function computeMissingFields(node: CollectNode, data: Record<string, unknown>): string[];
|
|
10
6
|
export declare function schemaSatisfied(node: CollectNode, state: FlowState): boolean;
|
|
11
7
|
export declare function projectCollectData(node: CollectNode, state: FlowState): unknown;
|
|
12
8
|
export declare function mergeExtractionData(current: Record<string, unknown>, incoming: Record<string, unknown>): Record<string, unknown>;
|
|
13
|
-
export declare function isEmptySubmission(args: Record<string, unknown>): boolean;
|
|
14
9
|
export declare function createExtractionSubmitTool(node: CollectNode, missingFields: readonly string[], opts?: {
|
|
15
10
|
userMessage?: string;
|
|
16
11
|
retryNudge?: boolean;
|
|
17
12
|
}): Tool;
|
|
18
|
-
export declare function submitToolName(nodeId: string): string;
|
|
19
13
|
export declare function mergeTurnExtraction(node: CollectNode, state: FlowState, toolResults: Array<{
|
|
20
14
|
name: string;
|
|
21
15
|
result: unknown;
|
package/dist/flow/extraction.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineTool } from '../tools/effect/defineTool.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
|
|
3
|
+
function collectDataKey(nodeId) {
|
|
4
4
|
return `__collect_${nodeId}`;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
function collectTurnsKey(nodeId) {
|
|
7
7
|
return `__collectTurns_${nodeId}`;
|
|
8
8
|
}
|
|
9
9
|
export function getCollectData(state, nodeId) {
|
|
@@ -13,10 +13,10 @@ export function getCollectData(state, nodeId) {
|
|
|
13
13
|
}
|
|
14
14
|
return {};
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
function setCollectData(state, nodeId, data) {
|
|
17
17
|
state[collectDataKey(nodeId)] = data;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
function getCollectTurns(state, nodeId) {
|
|
20
20
|
const value = state[collectTurnsKey(nodeId)];
|
|
21
21
|
return typeof value === 'number' ? value : 0;
|
|
22
22
|
}
|
|
@@ -52,7 +52,7 @@ export function mergeExtractionData(current, incoming) {
|
|
|
52
52
|
}
|
|
53
53
|
return next;
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
function isEmptySubmission(args) {
|
|
56
56
|
for (const value of Object.values(args)) {
|
|
57
57
|
if (fieldPopulated(value)) {
|
|
58
58
|
return false;
|
|
@@ -82,7 +82,7 @@ export function createExtractionSubmitTool(node, missingFields, opts = {}) {
|
|
|
82
82
|
execute: async (args) => (isPlainRecord(args) ? args : {}),
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
function submitToolName(nodeId) {
|
|
86
86
|
return `submit_${slugify(nodeId)}_data`;
|
|
87
87
|
}
|
|
88
88
|
export function mergeTurnExtraction(node, state, toolResults) {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import type { ToolSet } from 'ai';
|
|
2
1
|
import type { Instructions } from '../types/agentConfig.js';
|
|
3
2
|
import type { FlowState, ReplyNode, CollectNode } from '../types/flow.js';
|
|
4
3
|
import type { ResolvedNode } from '../types/channel.js';
|
|
5
4
|
import type { Tool } from '../types/effectTool.js';
|
|
6
5
|
export declare function resolveInstructions(instructions: Instructions, state: FlowState): string;
|
|
7
6
|
export declare function buildNodePrompt(node: ReplyNode, state: FlowState): string;
|
|
8
|
-
export declare function buildNodeTools(node: ReplyNode, state: FlowState): ToolSet;
|
|
9
7
|
export declare function resolveReplyNode(node: ReplyNode, state: FlowState): ResolvedNode;
|
|
10
8
|
export declare function resolveCollectExtractionNode(collectNode: CollectNode, missing: string[], state: FlowState, submitTool: Tool): ResolvedNode;
|
|
@@ -15,7 +15,7 @@ export function resolveInstructions(instructions, state) {
|
|
|
15
15
|
export function buildNodePrompt(node, state) {
|
|
16
16
|
return resolveInstructions(node.instructions, state);
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
function buildNodeTools(node, state) {
|
|
19
19
|
if (!node.tools) {
|
|
20
20
|
return {};
|
|
21
21
|
}
|
|
@@ -17,5 +17,4 @@ export type NormalizedTransition = {
|
|
|
17
17
|
kind: 'stay';
|
|
18
18
|
};
|
|
19
19
|
export declare function resolveNodeRef(ref: FlowNode | (() => FlowNode)): FlowNode;
|
|
20
|
-
export declare function isFlowNode(value: unknown): value is FlowNode;
|
|
21
20
|
export declare function normalizeTransition(transition: Transition): NormalizedTransition;
|
|
@@ -2,7 +2,7 @@ const NODE_KINDS = new Set(['reply', 'collect', 'action', 'decide']);
|
|
|
2
2
|
export function resolveNodeRef(ref) {
|
|
3
3
|
return typeof ref === 'function' ? ref() : ref;
|
|
4
4
|
}
|
|
5
|
-
|
|
5
|
+
function isFlowNode(value) {
|
|
6
6
|
if (typeof value !== 'object' || value === null) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { applyContextStrategy, resolveContextStrategy } from './contextStrategy.js';
|
|
2
|
+
import { emitInteractiveOnNodeEnter } from './emitInteractive.js';
|
|
2
3
|
function resolveNodeContext(toNode, flow) {
|
|
3
4
|
if (toNode.kind === 'reply' && toNode.context) {
|
|
4
5
|
return toNode.context;
|
|
@@ -10,6 +11,7 @@ export async function reduceTransition(input) {
|
|
|
10
11
|
emit({ type: 'node-exit', nodeName: fromNodeId });
|
|
11
12
|
emit({ type: 'flow-transition', from: fromNodeId, to: toNode.id });
|
|
12
13
|
emit({ type: 'node-enter', nodeName: toNode.id });
|
|
14
|
+
emitInteractiveOnNodeEnter(toNode, run.state, emit);
|
|
13
15
|
await applyContextStrategy({
|
|
14
16
|
strategy: resolveNodeContext(toNode, flow),
|
|
15
17
|
run,
|
package/dist/flow/runFlow.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ChannelDriver } from '../types/channel.js';
|
|
2
|
-
import type { Flow
|
|
2
|
+
import type { Flow } from '../types/flow.js';
|
|
3
3
|
import type { RunContext } from '../types/run-context.js';
|
|
4
4
|
import type { RunState } from '../runtime/durable/types.js';
|
|
5
5
|
export type FlowResult = {
|
|
@@ -15,6 +15,4 @@ export type FlowResult = {
|
|
|
15
15
|
export declare class FlowOscillationError extends Error {
|
|
16
16
|
constructor(from: string, to: string);
|
|
17
17
|
}
|
|
18
|
-
export declare function buildNodeRegistry(flow: Flow): Map<string, FlowNode>;
|
|
19
|
-
export declare function resolveStartNode(flow: Flow): FlowNode;
|
|
20
18
|
export declare function runFlow(flow: Flow, run: RunState, driver: ChannelDriver, ctx: RunContext): Promise<FlowResult>;
|
package/dist/flow/runFlow.js
CHANGED
|
@@ -6,20 +6,21 @@ import { reduceTransition } from './reduceTransition.js';
|
|
|
6
6
|
import { resolveReplyNode } from './nodeBuilders.js';
|
|
7
7
|
import { runNodeVerify, VerifyBlockedError } from './verify.js';
|
|
8
8
|
import { loadRecordedSteps } from '../runtime/durable/replay.js';
|
|
9
|
+
import { emitInteractiveOnNodeEnter } from './emitInteractive.js';
|
|
9
10
|
export class FlowOscillationError extends Error {
|
|
10
11
|
constructor(from, to) {
|
|
11
12
|
super(`Flow oscillation blocked: ${from} -> ${to}`);
|
|
12
13
|
this.name = 'FlowOscillationError';
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
function buildNodeRegistry(flow) {
|
|
16
17
|
const registry = new Map();
|
|
17
18
|
for (const node of flow.nodes) {
|
|
18
19
|
registry.set(node.id, node);
|
|
19
20
|
}
|
|
20
21
|
return registry;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
function resolveStartNode(flow) {
|
|
23
24
|
return resolveNodeRef(flow.start);
|
|
24
25
|
}
|
|
25
26
|
function bumpOscillation(edgeCounts, from, to) {
|
|
@@ -97,6 +98,7 @@ export async function runFlow(flow, run, driver, ctx) {
|
|
|
97
98
|
run.activeFlow = flow.name;
|
|
98
99
|
ctx.emit({ type: 'flow-enter', flow: flow.name });
|
|
99
100
|
ctx.emit({ type: 'node-enter', nodeName: node.id });
|
|
101
|
+
emitInteractiveOnNodeEnter(node, run.state, ctx.emit);
|
|
100
102
|
}
|
|
101
103
|
const edgeCounts = new Map();
|
|
102
104
|
const maxOscillations = flow.maxOscillations ?? 2;
|
|
@@ -19,13 +19,6 @@ export declare function extractStructuredFields<TSchema extends ZodTypeAny>(opti
|
|
|
19
19
|
* fabricating placeholder values to satisfy required constraints.
|
|
20
20
|
*/
|
|
21
21
|
export declare function toExtractionSubmissionSchema(schema: ZodTypeAny): ZodTypeAny;
|
|
22
|
-
/**
|
|
23
|
-
* Build a nullable schema for extraction model calls.
|
|
24
|
-
*
|
|
25
|
-
* This matches the text extraction behavior: unknown fields should come back
|
|
26
|
-
* as null instead of being forced into placeholder strings.
|
|
27
|
-
*/
|
|
28
|
-
export declare function toNullableSchema(schema: ZodTypeAny): ZodTypeAny;
|
|
29
22
|
export declare function mergeExtractionData(current: Record<string, unknown>, extracted: Record<string, unknown> | null | undefined): Record<string, unknown>;
|
|
30
23
|
export declare function computeMissingFields(data: Record<string, unknown>, requiredFields: readonly string[]): string[];
|
|
31
24
|
export declare function buildMissingFieldsMessage(missingFields: readonly string[]): string;
|
package/dist/flows/extraction.js
CHANGED
|
@@ -35,22 +35,6 @@ export function toExtractionSubmissionSchema(schema) {
|
|
|
35
35
|
}
|
|
36
36
|
return schema.nullable().optional();
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Build a nullable schema for extraction model calls.
|
|
40
|
-
*
|
|
41
|
-
* This matches the text extraction behavior: unknown fields should come back
|
|
42
|
-
* as null instead of being forced into placeholder strings.
|
|
43
|
-
*/
|
|
44
|
-
export function toNullableSchema(schema) {
|
|
45
|
-
if (schema instanceof z.ZodObject) {
|
|
46
|
-
const nullableShape = {};
|
|
47
|
-
for (const [key, fieldSchema] of Object.entries(schema.shape)) {
|
|
48
|
-
nullableShape[key] = fieldSchema.nullable();
|
|
49
|
-
}
|
|
50
|
-
return z.object(nullableShape);
|
|
51
|
-
}
|
|
52
|
-
return schema;
|
|
53
|
-
}
|
|
54
38
|
export function mergeExtractionData(current, extracted) {
|
|
55
39
|
const next = { ...current };
|
|
56
40
|
if (!extracted)
|
package/dist/flows/template.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export type TemplateMissingBehavior = 'keep' | 'empty';
|
|
1
|
+
type TemplateMissingBehavior = 'keep' | 'empty';
|
|
3
2
|
export interface RenderTemplateOptions {
|
|
4
3
|
missing?: TemplateMissingBehavior;
|
|
5
4
|
}
|
|
@@ -8,5 +7,5 @@ export interface RenderTemplateOptions {
|
|
|
8
7
|
* Supports: {{key}} and {{nested.key}} from collectedData.
|
|
9
8
|
*/
|
|
10
9
|
export declare function renderFlowTemplate(text: string | undefined | null, data: Record<string, unknown>, options?: RenderTemplateOptions): string;
|
|
11
|
-
export declare function renderNodePrompt(prompt: string | undefined | null, ctx: FlowPromptContext): string;
|
|
12
10
|
export declare function compileSanitizePattern(pattern: string): RegExp;
|
|
11
|
+
export {};
|
package/dist/flows/template.js
CHANGED
|
@@ -53,9 +53,6 @@ export function renderFlowTemplate(text, data, options = {}) {
|
|
|
53
53
|
return formatValue(v);
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
export function renderNodePrompt(prompt, ctx) {
|
|
57
|
-
return renderFlowTemplate(prompt, ctx.collectedData, { missing: 'keep' });
|
|
58
|
-
}
|
|
59
56
|
function parseRegexLiteral(pattern) {
|
|
60
57
|
// Support "/foo/i" style literals from JSON config.
|
|
61
58
|
if (!pattern.startsWith('/') || pattern.lastIndexOf('/') === 0)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
interface FlowTransitionInlineNode {
|
|
2
2
|
id: string;
|
|
3
3
|
}
|
|
4
|
-
|
|
4
|
+
interface FlowTransitionSignal {
|
|
5
5
|
__flow_transition: true;
|
|
6
6
|
targetNode: string;
|
|
7
7
|
data?: Record<string, unknown>;
|
|
@@ -9,7 +9,7 @@ export interface FlowTransitionSignal {
|
|
|
9
9
|
/** Optional inline node definition for dynamic transitions (Pipecat-style). */
|
|
10
10
|
node?: FlowTransitionInlineNode;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
interface FlowUpdateSignal {
|
|
13
13
|
__flow_update: true;
|
|
14
14
|
data?: Record<string, unknown>;
|
|
15
15
|
message?: string;
|
|
@@ -20,32 +20,4 @@ export declare function createFlowTransitionWithNode(node: FlowTransitionInlineN
|
|
|
20
20
|
export declare function createFlowUpdate(data?: Record<string, unknown>, message?: string, missing?: string[]): FlowUpdateSignal;
|
|
21
21
|
export declare function isFlowTransition(result: unknown): result is FlowTransitionSignal;
|
|
22
22
|
export declare function isFlowUpdate(result: unknown): result is FlowUpdateSignal;
|
|
23
|
-
|
|
24
|
-
* Speech-friendly continuation marker that replaces a `FlowTransitionSignal`
|
|
25
|
-
* before the result reaches the language model. Internal control fields
|
|
26
|
-
* (`__flow_transition`, `targetNode`, `data`) MUST stay inside the runtime
|
|
27
|
-
* — both the realtime model (Gemini Live, OpenAI Realtime, …) and cascaded
|
|
28
|
-
* text models (Gemini Flash via AI-SDK) go silent post-transition when
|
|
29
|
-
* they receive the raw envelope (GH #28 / GH #29).
|
|
30
|
-
*
|
|
31
|
-
* Shape:
|
|
32
|
-
* { status: 'transition_complete', to: <targetNode>, message?: <line> }
|
|
33
|
-
*
|
|
34
|
-
* The optional `message` field is the user-supplied speech line from
|
|
35
|
-
* `createFlowTransition(target, data, message)` — when present it tells
|
|
36
|
-
* the model exactly what to say next, mirroring LiveKit's native
|
|
37
|
-
* `llm.handoff({ returns: '...' })` pattern.
|
|
38
|
-
*/
|
|
39
|
-
export interface FlowTransitionContinuation {
|
|
40
|
-
status: 'transition_complete';
|
|
41
|
-
to: string;
|
|
42
|
-
message?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Convert a tool-execute result into the value the language model should
|
|
46
|
-
* see. Pass-through for everything that is NOT a flow control signal;
|
|
47
|
-
* replace `FlowTransitionSignal` with a `FlowTransitionContinuation`.
|
|
48
|
-
*
|
|
49
|
-
* Used by the text and voice tool loops so flow control signals share one contract.
|
|
50
|
-
*/
|
|
51
|
-
export declare function sanitizeFlowControlSignal(raw: unknown): unknown;
|
|
23
|
+
export {};
|
|
@@ -35,23 +35,3 @@ export function isFlowUpdate(result) {
|
|
|
35
35
|
'__flow_update' in result &&
|
|
36
36
|
result.__flow_update === true);
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Convert a tool-execute result into the value the language model should
|
|
40
|
-
* see. Pass-through for everything that is NOT a flow control signal;
|
|
41
|
-
* replace `FlowTransitionSignal` with a `FlowTransitionContinuation`.
|
|
42
|
-
*
|
|
43
|
-
* Used by the text and voice tool loops so flow control signals share one contract.
|
|
44
|
-
*/
|
|
45
|
-
export function sanitizeFlowControlSignal(raw) {
|
|
46
|
-
if (isFlowTransition(raw)) {
|
|
47
|
-
const continuation = {
|
|
48
|
-
status: 'transition_complete',
|
|
49
|
-
to: raw.targetNode,
|
|
50
|
-
};
|
|
51
|
-
if (typeof raw.message === 'string' && raw.message.length > 0) {
|
|
52
|
-
continuation.message = raw.message;
|
|
53
|
-
}
|
|
54
|
-
return continuation;
|
|
55
|
-
}
|
|
56
|
-
return raw;
|
|
57
|
-
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { debug } from '../debug.js';
|
|
1
2
|
export class ToolEnforcer {
|
|
2
3
|
rules = [];
|
|
3
4
|
constructor(rules = []) {
|
|
@@ -34,11 +35,11 @@ export class ToolEnforcer {
|
|
|
34
35
|
}
|
|
35
36
|
const result = await Promise.resolve(rule.check(call, context));
|
|
36
37
|
if (!result.allowed) {
|
|
37
|
-
|
|
38
|
+
debug(`[Enforcement] Rule "${rule.name}" blocked ${call.toolName}: ${result.reason}`);
|
|
38
39
|
return result;
|
|
39
40
|
}
|
|
40
41
|
if (result.reminder) {
|
|
41
|
-
|
|
42
|
+
debug(`[Enforcement] Reminder for ${call.toolName}: ${result.reminder}`);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
return { allowed: true };
|
package/dist/index.d.ts
CHANGED
|
@@ -67,14 +67,15 @@ export type { Hooks } from './types/hooks.js';
|
|
|
67
67
|
export type { HarnessHooks } from './types/runtime.js';
|
|
68
68
|
export { defineAgent, defineFlow, reply, collect, action, decide, } from './authoring/index.js';
|
|
69
69
|
export { defineTool } from './types/effectTool.js';
|
|
70
|
-
export { buildToolSet, toolToAiSdk } from './tools/effect/index.js';
|
|
70
|
+
export { buildToolSet, toolToAiSdk, ToolApprovalDeniedError } from './tools/effect/index.js';
|
|
71
71
|
export type { Tool as EffectTool } from './types/effectTool.js';
|
|
72
72
|
export type { AgentRoute } from './types/processors.js';
|
|
73
73
|
export type { AgentConfig, Instructions } from './types/agentConfig.js';
|
|
74
|
-
export type { Flow, FlowNode, Transition } from './types/flow.js';
|
|
74
|
+
export type { Flow, FlowNode, Transition, CollectNode, DecideNode } from './types/flow.js';
|
|
75
75
|
export type { Route } from './types/route.js';
|
|
76
76
|
export type { TurnHandle } from './types/stream.js';
|
|
77
77
|
export type { HarnessStreamPart } from './types/stream.js';
|
|
78
|
+
export type { ChoiceOption, ResolvedSelection } from './types/selection.js';
|
|
78
79
|
export type { RunState, StepRecord } from './runtime/durable/types.js';
|
|
79
80
|
export type { RunStore } from './runtime/durable/RunStore.js';
|
|
80
81
|
export type { ChannelDriver, TextDriver, VoiceDriver } from './runtime/channels/index.js';
|
package/dist/index.js
CHANGED
|
@@ -38,5 +38,5 @@ export { CapabilityHost, TriageCapability, ExtractionCapability, HandoffCapabili
|
|
|
38
38
|
export { filterAuditEntries } from './audit/index.js';
|
|
39
39
|
export { defineAgent, defineFlow, reply, collect, action, decide, } from './authoring/index.js';
|
|
40
40
|
export { defineTool } from './types/effectTool.js';
|
|
41
|
-
export { buildToolSet, toolToAiSdk } from './tools/effect/index.js';
|
|
41
|
+
export { buildToolSet, toolToAiSdk, ToolApprovalDeniedError } from './tools/effect/index.js';
|
|
42
42
|
export { createRuntime, Runtime, } from './runtime/Runtime.js';
|
|
@@ -8,6 +8,7 @@ import type { Hooks } from '../types/hooks.js';
|
|
|
8
8
|
import type { AnyTool } from '../types/effectTool.js';
|
|
9
9
|
import type { TurnHandle } from '../types/stream.js';
|
|
10
10
|
import type { SignalDelivery } from './durable/types.js';
|
|
11
|
+
import type { ResolvedSelection } from '../types/selection.js';
|
|
11
12
|
import type { ConversationOutcome, ConversationOutcomeMarkedBy } from '../outcomes/types.js';
|
|
12
13
|
import type { selectHostTarget } from './select.js';
|
|
13
14
|
import type { KnowledgeProviderConfig } from '../types/voice.js';
|
|
@@ -18,6 +19,7 @@ export interface HarnessConfig {
|
|
|
18
19
|
sessionStore?: SessionStore;
|
|
19
20
|
defaultModel?: LanguageModel;
|
|
20
21
|
maxHandoffs?: number;
|
|
22
|
+
terminalHandoffTargets?: string[];
|
|
21
23
|
hooks?: Hooks;
|
|
22
24
|
voiceMode?: boolean;
|
|
23
25
|
hostSelect?: typeof selectHostTarget;
|
|
@@ -28,6 +30,7 @@ export interface HarnessConfig {
|
|
|
28
30
|
export interface RunOptions {
|
|
29
31
|
sessionId?: string;
|
|
30
32
|
input?: string;
|
|
33
|
+
selection?: ResolvedSelection;
|
|
31
34
|
userId?: string;
|
|
32
35
|
agentId?: string;
|
|
33
36
|
seedMessages?: ModelMessage[];
|
|
@@ -42,6 +45,7 @@ export declare class Runtime {
|
|
|
42
45
|
private readonly sessionStore;
|
|
43
46
|
private readonly defaultModel?;
|
|
44
47
|
private readonly maxHandoffs;
|
|
48
|
+
private readonly terminalHandoffTargets;
|
|
45
49
|
private readonly hooks?;
|
|
46
50
|
private readonly activeTurnAborts;
|
|
47
51
|
constructor(config: HarnessConfig);
|