@kuralle-agents/core 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring/index.d.ts +1 -1
- package/dist/authoring/index.js +1 -1
- package/dist/authoring/nodes.d.ts +1 -1
- package/dist/authoring/nodes.js +1 -1
- package/dist/flow/confirmParse.d.ts +2 -0
- package/dist/flow/confirmParse.js +170 -0
- package/dist/flow/runFlow.js +39 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/types/flow.d.ts +17 -3
- package/dist/types/flow.js +13 -0
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { reply, collect, action, decide, defineFlow } from './nodes.js';
|
|
1
|
+
export { reply, collect, action, decide, confirmGate, defineFlow } from './nodes.js';
|
|
2
2
|
export { defineAgent, type AgentConfig, type Instructions } from './defineAgent.js';
|
package/dist/authoring/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { reply, collect, action, decide, defineFlow } from './nodes.js';
|
|
1
|
+
export { reply, collect, action, decide, confirmGate, defineFlow } from './nodes.js';
|
|
2
2
|
export { defineAgent } from './defineAgent.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { reply, collect, action, decide, defineFlow } from '../types/flow.js';
|
|
1
|
+
export { reply, collect, action, decide, confirmGate, defineFlow } from '../types/flow.js';
|
package/dist/authoring/nodes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { reply, collect, action, decide, defineFlow } from '../types/flow.js';
|
|
1
|
+
export { reply, collect, action, decide, confirmGate, defineFlow } from '../types/flow.js';
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
const AFFIRM_TOKENS = new Set([
|
|
2
|
+
'yes',
|
|
3
|
+
'yeah',
|
|
4
|
+
'yep',
|
|
5
|
+
'yup',
|
|
6
|
+
'ya',
|
|
7
|
+
'sure',
|
|
8
|
+
'ok',
|
|
9
|
+
'okay',
|
|
10
|
+
'okey',
|
|
11
|
+
'k',
|
|
12
|
+
'confirm',
|
|
13
|
+
'confirmed',
|
|
14
|
+
'correct',
|
|
15
|
+
'right',
|
|
16
|
+
'proceed',
|
|
17
|
+
'do',
|
|
18
|
+
'done',
|
|
19
|
+
'yessir',
|
|
20
|
+
'affirmative',
|
|
21
|
+
'ow',
|
|
22
|
+
'ova',
|
|
23
|
+
'hari',
|
|
24
|
+
'hariyata',
|
|
25
|
+
'ehenam',
|
|
26
|
+
'aam',
|
|
27
|
+
'aama',
|
|
28
|
+
'sari',
|
|
29
|
+
'seri',
|
|
30
|
+
]);
|
|
31
|
+
const AFFIRM_PHRASES = [
|
|
32
|
+
'go ahead',
|
|
33
|
+
'do it',
|
|
34
|
+
'book it',
|
|
35
|
+
'place it',
|
|
36
|
+
'place the order',
|
|
37
|
+
'place my order',
|
|
38
|
+
'sounds good',
|
|
39
|
+
"that's right",
|
|
40
|
+
'thats right',
|
|
41
|
+
'that is correct',
|
|
42
|
+
'please do',
|
|
43
|
+
"let's do it",
|
|
44
|
+
'lets do it',
|
|
45
|
+
'go for it',
|
|
46
|
+
'confirm the order',
|
|
47
|
+
'yes please',
|
|
48
|
+
];
|
|
49
|
+
const AFFIRM_SCRIPT = ['ඔව්', 'හරි', 'හා', 'හරියට', 'ஆம்', 'சரி', 'ஆமா'];
|
|
50
|
+
const DECLINE_TOKENS = new Set([
|
|
51
|
+
'no',
|
|
52
|
+
'nope',
|
|
53
|
+
'nah',
|
|
54
|
+
'na',
|
|
55
|
+
'not',
|
|
56
|
+
'dont',
|
|
57
|
+
"don't",
|
|
58
|
+
'stop',
|
|
59
|
+
'cancel',
|
|
60
|
+
'wait',
|
|
61
|
+
'hold',
|
|
62
|
+
'change',
|
|
63
|
+
'edit',
|
|
64
|
+
'incorrect',
|
|
65
|
+
'wrong',
|
|
66
|
+
'nevermind',
|
|
67
|
+
'never',
|
|
68
|
+
'naha',
|
|
69
|
+
'nae',
|
|
70
|
+
'epa',
|
|
71
|
+
'epaa',
|
|
72
|
+
'wenas',
|
|
73
|
+
'illa',
|
|
74
|
+
'illai',
|
|
75
|
+
'vendam',
|
|
76
|
+
'vendaam',
|
|
77
|
+
'vena',
|
|
78
|
+
]);
|
|
79
|
+
const DECLINE_PHRASES = [
|
|
80
|
+
'not yet',
|
|
81
|
+
'hold on',
|
|
82
|
+
'no thanks',
|
|
83
|
+
'no thank you',
|
|
84
|
+
"don't",
|
|
85
|
+
'do not',
|
|
86
|
+
'change it',
|
|
87
|
+
'change the',
|
|
88
|
+
'let me change',
|
|
89
|
+
'something else',
|
|
90
|
+
'go back',
|
|
91
|
+
];
|
|
92
|
+
const DECLINE_SCRIPT = ['නැහැ', 'නෑ', 'එපා', 'වෙනස්', 'இல்லை', 'வேண்டாம்', 'வேற'];
|
|
93
|
+
const INTERROGATIVE_WORDS = [
|
|
94
|
+
'what',
|
|
95
|
+
'how',
|
|
96
|
+
'when',
|
|
97
|
+
'where',
|
|
98
|
+
'why',
|
|
99
|
+
'which',
|
|
100
|
+
'who',
|
|
101
|
+
'do you',
|
|
102
|
+
'can you',
|
|
103
|
+
'could you',
|
|
104
|
+
'is there',
|
|
105
|
+
'tell me',
|
|
106
|
+
'show me',
|
|
107
|
+
];
|
|
108
|
+
function normalize(raw) {
|
|
109
|
+
return raw.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
110
|
+
}
|
|
111
|
+
function stripTokenPunctuation(token) {
|
|
112
|
+
return token.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, '');
|
|
113
|
+
}
|
|
114
|
+
function tokenize(normalized) {
|
|
115
|
+
return normalized
|
|
116
|
+
.split(/\s+/)
|
|
117
|
+
.map(stripTokenPunctuation)
|
|
118
|
+
.filter((token) => token.length > 0);
|
|
119
|
+
}
|
|
120
|
+
function hasDeclineToken(tokens) {
|
|
121
|
+
return tokens.some((token) => DECLINE_TOKENS.has(token));
|
|
122
|
+
}
|
|
123
|
+
function hasDeclinePhrase(normalized) {
|
|
124
|
+
return DECLINE_PHRASES.some((phrase) => normalized.includes(phrase));
|
|
125
|
+
}
|
|
126
|
+
function hasDeclineScript(normalized, raw) {
|
|
127
|
+
return DECLINE_SCRIPT.some((fragment) => normalized.includes(fragment) || raw.includes(fragment));
|
|
128
|
+
}
|
|
129
|
+
function hasDecline(normalized, tokens, raw) {
|
|
130
|
+
return hasDeclineToken(tokens) || hasDeclinePhrase(normalized) || hasDeclineScript(normalized, raw);
|
|
131
|
+
}
|
|
132
|
+
function hasInterrogative(normalized) {
|
|
133
|
+
if (normalized.includes('?')) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
return INTERROGATIVE_WORDS.some((word) => {
|
|
137
|
+
const pattern = new RegExp(`(?:^|\\s)${word.replace(/\s+/g, '\\s+')}(?:\\s|$|[?.!,])`, 'i');
|
|
138
|
+
return pattern.test(normalized);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function hasAffirmScript(normalized, raw) {
|
|
142
|
+
return AFFIRM_SCRIPT.some((fragment) => normalized.includes(fragment) || raw.includes(fragment));
|
|
143
|
+
}
|
|
144
|
+
function hasAffirmPhrase(normalized) {
|
|
145
|
+
return AFFIRM_PHRASES.some((phrase) => normalized.startsWith(phrase));
|
|
146
|
+
}
|
|
147
|
+
function hasAffirmToken(tokens) {
|
|
148
|
+
const head = tokens.slice(0, 3);
|
|
149
|
+
if (head.some((token) => AFFIRM_TOKENS.has(token))) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
return tokens.length === 1 && tokens[0] === 'y';
|
|
153
|
+
}
|
|
154
|
+
function hasAffirm(normalized, tokens, raw) {
|
|
155
|
+
return hasAffirmScript(normalized, raw) || hasAffirmPhrase(normalized) || hasAffirmToken(tokens);
|
|
156
|
+
}
|
|
157
|
+
export function parseConfirmation(raw) {
|
|
158
|
+
const normalized = normalize(raw);
|
|
159
|
+
const tokens = tokenize(normalized);
|
|
160
|
+
if (hasDecline(normalized, tokens, raw)) {
|
|
161
|
+
return 'decline';
|
|
162
|
+
}
|
|
163
|
+
if (hasInterrogative(normalized)) {
|
|
164
|
+
return 'ambiguous';
|
|
165
|
+
}
|
|
166
|
+
if (hasAffirm(normalized, tokens, raw)) {
|
|
167
|
+
return 'affirm';
|
|
168
|
+
}
|
|
169
|
+
return 'ambiguous';
|
|
170
|
+
}
|
package/dist/flow/runFlow.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseConfirmation } from './confirmParse.js';
|
|
1
2
|
import { hasPendingUserInput } from '../runtime/channels/inputBuffer.js';
|
|
2
3
|
import { collectUntilComplete } from './collectUntilComplete.js';
|
|
3
4
|
import { isActionNode, isCollectNode, isDecideNode, isReplyNode, } from './nodeKinds.js';
|
|
@@ -46,6 +47,38 @@ function appendUserMessage(run, input) {
|
|
|
46
47
|
const message = { role: 'user', content: input };
|
|
47
48
|
run.messages = [...run.messages, message];
|
|
48
49
|
}
|
|
50
|
+
function latestUserText(run) {
|
|
51
|
+
for (let i = run.messages.length - 1; i >= 0; i -= 1) {
|
|
52
|
+
const message = run.messages[i];
|
|
53
|
+
if (message?.role === 'user' && typeof message.content === 'string') {
|
|
54
|
+
return message.content;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
async function dispatchConfirmGate(node, run, driver, ctx) {
|
|
60
|
+
const gate = node.confirmGate;
|
|
61
|
+
if (!hasPendingUserInput(ctx.session) && ctx.turnInputConsumed) {
|
|
62
|
+
return { kind: 'stay' };
|
|
63
|
+
}
|
|
64
|
+
let input = '';
|
|
65
|
+
if (hasPendingUserInput(ctx.session)) {
|
|
66
|
+
const signal = await driver.awaitUser(ctx);
|
|
67
|
+
input = signal.input;
|
|
68
|
+
appendUserMessage(run, signal.input);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
input = latestUserText(run);
|
|
72
|
+
}
|
|
73
|
+
ctx.turnInputConsumed = true;
|
|
74
|
+
const verdict = parseConfirmation(input);
|
|
75
|
+
const branch = verdict === 'affirm'
|
|
76
|
+
? gate.onConfirm
|
|
77
|
+
: verdict === 'decline'
|
|
78
|
+
? gate.onDecline
|
|
79
|
+
: (gate.onAmbiguous ?? 'stay');
|
|
80
|
+
return normalizeTransition(branch);
|
|
81
|
+
}
|
|
49
82
|
function appendAssistantMessage(run, text) {
|
|
50
83
|
if (!text.trim()) {
|
|
51
84
|
return;
|
|
@@ -61,9 +94,15 @@ async function dispatchNode(node, run, driver, ctx) {
|
|
|
61
94
|
return collectUntilComplete(node, run, driver, ctx);
|
|
62
95
|
}
|
|
63
96
|
if (isDecideNode(node)) {
|
|
97
|
+
if (node.confirmGate) {
|
|
98
|
+
return dispatchConfirmGate(node, run, driver, ctx);
|
|
99
|
+
}
|
|
64
100
|
if (!driver.runStructured) {
|
|
65
101
|
throw new Error('ChannelDriver.runStructured is required for decide nodes');
|
|
66
102
|
}
|
|
103
|
+
if (!node.schema || !node.decide) {
|
|
104
|
+
throw new Error(`decide node "${node.id}" requires schema and decide`);
|
|
105
|
+
}
|
|
67
106
|
// An interactive choice node (withChoices) reached when the turn's input was
|
|
68
107
|
// already consumed by a prior node: its choices were presented on node-enter,
|
|
69
108
|
// so wait for the user to actually pick rather than auto-deciding on stale
|
package/dist/index.d.ts
CHANGED
|
@@ -65,13 +65,15 @@ export type { AuditConfig, AuditEntryBase, AuditEntryType, AuditListOptions, Aud
|
|
|
65
65
|
export type { RealtimeAudioClient, RealtimeSessionConfig, RealtimeAudioConfig, RealtimeToolResponse, RealtimeEventMap, RealtimeSessionHandle, } from './realtime/index.js';
|
|
66
66
|
export type { Hooks } from './types/hooks.js';
|
|
67
67
|
export type { HarnessHooks } from './types/runtime.js';
|
|
68
|
-
export { defineAgent, defineFlow, reply, collect, action, decide, } from './authoring/index.js';
|
|
68
|
+
export { defineAgent, defineFlow, reply, collect, action, decide, confirmGate, } from './authoring/index.js';
|
|
69
69
|
export { defineTool } from './types/effectTool.js';
|
|
70
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, CollectNode, DecideNode } from './types/flow.js';
|
|
74
|
+
export type { Flow, FlowNode, Transition, CollectNode, DecideNode, ConfirmGate } from './types/flow.js';
|
|
75
|
+
export { parseConfirmation } from './flow/confirmParse.js';
|
|
76
|
+
export type { ConfirmVerdict } from './flow/confirmParse.js';
|
|
75
77
|
export type { Route } from './types/route.js';
|
|
76
78
|
export type { TurnHandle } from './types/stream.js';
|
|
77
79
|
export type { HarnessStreamPart } from './types/stream.js';
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,8 @@ export { handoffFilters, removeToolHistory, keepRecentMessages, removeKeys, comp
|
|
|
36
36
|
export { DefaultToolExecutor, DefaultConversationState, DefaultConversationEventLog, DefaultAgentStateController, createFoundation, } from './foundation/index.js';
|
|
37
37
|
export { CapabilityHost, TriageCapability, ExtractionCapability, HandoffCapability, GuardrailCapability, AutoRetrieveCapability, PassThroughRefinement, PassThroughValidation, toGeminiDeclarations, toAISDKTools, } from './capabilities/index.js';
|
|
38
38
|
export { filterAuditEntries } from './audit/index.js';
|
|
39
|
-
export { defineAgent, defineFlow, reply, collect, action, decide, } from './authoring/index.js';
|
|
39
|
+
export { defineAgent, defineFlow, reply, collect, action, decide, confirmGate, } from './authoring/index.js';
|
|
40
40
|
export { defineTool } from './types/effectTool.js';
|
|
41
41
|
export { buildToolSet, toolToAiSdk, ToolApprovalDeniedError } from './tools/effect/index.js';
|
|
42
|
+
export { parseConfirmation } from './flow/confirmParse.js';
|
|
42
43
|
export { createRuntime, Runtime, } from './runtime/Runtime.js';
|
package/dist/types/flow.d.ts
CHANGED
|
@@ -61,16 +61,30 @@ export interface ActionNode {
|
|
|
61
61
|
outputSchema?: StandardSchemaV1;
|
|
62
62
|
run: (state: FlowState, ctx: ActionContext) => Transition | Promise<Transition>;
|
|
63
63
|
}
|
|
64
|
+
export interface ConfirmGate {
|
|
65
|
+
onConfirm: Transition;
|
|
66
|
+
onDecline: Transition;
|
|
67
|
+
onAmbiguous?: Transition;
|
|
68
|
+
}
|
|
64
69
|
export interface DecideNode {
|
|
65
70
|
kind: 'decide';
|
|
66
71
|
id: string;
|
|
67
72
|
instructions: Instructions;
|
|
68
|
-
schema
|
|
73
|
+
schema?: StandardSchemaV1;
|
|
69
74
|
choices?: ChoiceOption[];
|
|
70
|
-
|
|
75
|
+
confirmGate?: ConfirmGate;
|
|
76
|
+
decide?: (data: unknown, state: FlowState) => Transition | Promise<Transition>;
|
|
71
77
|
}
|
|
72
78
|
export declare function reply(node: Omit<ReplyNode, 'kind'>): ReplyNode;
|
|
73
79
|
export declare function collect(node: Omit<CollectNode, 'kind'>): CollectNode;
|
|
74
80
|
export declare function action(node: Omit<ActionNode, 'kind'>): ActionNode;
|
|
75
|
-
export declare function decide(node: Omit<DecideNode, 'kind'>): DecideNode;
|
|
81
|
+
export declare function decide(node: Omit<DecideNode, 'kind' | 'confirmGate'> & Required<Pick<DecideNode, 'schema' | 'decide'>>): DecideNode;
|
|
82
|
+
export declare function confirmGate(node: {
|
|
83
|
+
id: string;
|
|
84
|
+
instructions: Instructions;
|
|
85
|
+
onConfirm: Transition;
|
|
86
|
+
onDecline: Transition;
|
|
87
|
+
onAmbiguous?: Transition;
|
|
88
|
+
choices?: ChoiceOption[];
|
|
89
|
+
}): DecideNode;
|
|
76
90
|
export declare function defineFlow(flow: Flow): Flow;
|
package/dist/types/flow.js
CHANGED
|
@@ -10,6 +10,19 @@ export function action(node) {
|
|
|
10
10
|
export function decide(node) {
|
|
11
11
|
return { kind: 'decide', ...node };
|
|
12
12
|
}
|
|
13
|
+
export function confirmGate(node) {
|
|
14
|
+
return {
|
|
15
|
+
kind: 'decide',
|
|
16
|
+
id: node.id,
|
|
17
|
+
instructions: node.instructions,
|
|
18
|
+
choices: node.choices,
|
|
19
|
+
confirmGate: {
|
|
20
|
+
onConfirm: node.onConfirm,
|
|
21
|
+
onDecline: node.onDecline,
|
|
22
|
+
onAmbiguous: node.onAmbiguous,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
13
26
|
export function defineFlow(flow) {
|
|
14
27
|
return flow;
|
|
15
28
|
}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "git+https://github.com/kuralle/kuralle-agents.git",
|
|
7
7
|
"directory": "packages/kuralle-core"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.9",
|
|
10
10
|
"description": "A framework for structured conversational AI agents",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"dotenv": "^16.4.0",
|
|
98
98
|
"typescript": "^5.3.0",
|
|
99
99
|
"zod": "^3.23.0",
|
|
100
|
-
"@kuralle-agents/realtime-audio": "0.3.
|
|
100
|
+
"@kuralle-agents/realtime-audio": "0.3.9"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"chrono-node": "^2.6.0",
|