@nexalab/agent-sdk 0.1.6 → 0.1.8
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/guided-flows/runtime.d.ts +55 -0
- package/dist/guided-flows/runtime.d.ts.map +1 -1
- package/dist/guided-flows/runtime.js +611 -92
- package/dist/guided-flows/runtime.js.map +1 -1
- package/dist/guided-flows/types.d.ts +23 -0
- package/dist/guided-flows/types.d.ts.map +1 -1
- package/dist/kernel.d.ts +6 -0
- package/dist/kernel.d.ts.map +1 -1
- package/dist/kernel.js +10 -2
- package/dist/kernel.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +16 -1
- package/dist/mcp.js.map +1 -1
- package/dist/sessions.d.ts +2 -0
- package/dist/sessions.d.ts.map +1 -1
- package/dist/sessions.js.map +1 -1
- package/dist/structured-output.d.ts +13 -1
- package/dist/structured-output.d.ts.map +1 -1
- package/dist/structured-output.js +24 -2
- package/dist/structured-output.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ import type { EventBus } from "../event-bus.js";
|
|
|
6
6
|
import type { SkillDefinition } from "../skills.js";
|
|
7
7
|
import { type TenantContext } from "../tenancy.js";
|
|
8
8
|
import type { JsonObject } from "../types.js";
|
|
9
|
+
import { type PublishFlowEventInput } from "./events.js";
|
|
9
10
|
import type { GuidedFlowStateStore } from "./persistence.js";
|
|
10
11
|
import type { FlowStatePatch, GuidedFlow, GuidedFlowRunMeta, GuidedFlowRunState } from "./types.js";
|
|
11
12
|
export type GuidedFlowRuntimeOptions = {
|
|
@@ -30,6 +31,33 @@ export type GuidedFlowTurnInput = {
|
|
|
30
31
|
sessionId: string;
|
|
31
32
|
tenant?: TenantContext;
|
|
32
33
|
explicitFlow?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Known facts to seed into `state` before this flow run's first turn —
|
|
36
|
+
* e.g. a `customerId` a WhatsApp gateway already resolved from the phone
|
|
37
|
+
* number, or a `locale` carried over from session context. Applied once,
|
|
38
|
+
* only while creating a brand-new flow run (`!existing` — an already
|
|
39
|
+
* in-progress flow ignores it; use `flows.patchState()` to update a
|
|
40
|
+
* running flow instead). Goes through the exact same
|
|
41
|
+
* `applyStatePatch`/`protectedFields` path as any other patch, with
|
|
42
|
+
* `source: "system"` — unknown keys are dropped, but (unlike a
|
|
43
|
+
* model-sourced patch) tool-reserved fields may be set, since this is the
|
|
44
|
+
* caller vouching for the value, not the model guessing it. Applied
|
|
45
|
+
* before step resolution and the extraction call, so both the active
|
|
46
|
+
* step and "Known so far" in the model's instructions already reflect it.
|
|
47
|
+
*/
|
|
48
|
+
initialState?: JsonObject;
|
|
49
|
+
/** Propagated to the extraction call and the tool-scoped reply pass so a caller (e.g. the Gateway) can cancel an in-flight turn. Additive — omitting it is byte-identical to previous behavior. */
|
|
50
|
+
signal?: AbortSignal;
|
|
51
|
+
/**
|
|
52
|
+
* Turn-scoped event sink, called synchronously alongside every existing
|
|
53
|
+
* `publishFlowEvent` call in this turn — same events, same payloads,
|
|
54
|
+
* just also delivered directly to this caller instead of only through
|
|
55
|
+
* the shared `EventBus`. This is what lets a caller stream a single
|
|
56
|
+
* turn's events without subscribing to (and filtering) the agent-wide
|
|
57
|
+
* bus. Purely additive: omitting it changes nothing about how this
|
|
58
|
+
* turn executes or what it returns.
|
|
59
|
+
*/
|
|
60
|
+
onEvent?: (event: PublishFlowEventInput) => void;
|
|
33
61
|
};
|
|
34
62
|
export type GuidedFlowTurnOutcome = {
|
|
35
63
|
handled: false;
|
|
@@ -54,6 +82,8 @@ export declare class GuidedFlowRuntime {
|
|
|
54
82
|
private requireFlow;
|
|
55
83
|
private soleFlow;
|
|
56
84
|
private key;
|
|
85
|
+
/** Publishes onto the shared EventBus (unchanged behavior) and, if this turn supplied one, also delivers the same event directly to the turn-scoped sink. */
|
|
86
|
+
private announce;
|
|
57
87
|
selectFlow(input: {
|
|
58
88
|
text: string;
|
|
59
89
|
sessionId: string;
|
|
@@ -62,6 +92,31 @@ export declare class GuidedFlowRuntime {
|
|
|
62
92
|
}): Promise<GuidedFlow | undefined>;
|
|
63
93
|
runTurn(input: GuidedFlowTurnInput): Promise<GuidedFlowTurnOutcome>;
|
|
64
94
|
private driveFlow;
|
|
95
|
+
/** The model-driven reply pass: composes text and may call the active step's tools. Only reached when a step has no `prompt`, or does but still has tools available (e.g. a validation step, which needs the model to react to a tool result/error dynamically). */
|
|
96
|
+
private runReplyPass;
|
|
97
|
+
/**
|
|
98
|
+
* Deterministically calls a step's single applicable tool when its arguments are fully
|
|
99
|
+
* resolvable without asking a model to decide anything. Covers two shapes:
|
|
100
|
+
*
|
|
101
|
+
* 1. A silent tool-only step (no `collect`, exactly one required tool) where every input
|
|
102
|
+
* property already resolves to a known value in `state` (matched by property name,
|
|
103
|
+
* case-insensitively — the generator's convention of lowercase-flattened field names makes
|
|
104
|
+
* this a reliable match in practice).
|
|
105
|
+
* 2. A `collect` step whose only useful action is resolving the user's free text against a
|
|
106
|
+
* dynamic list (an address, a product, a time slot): exactly one tool in `tools.allowed`
|
|
107
|
+
* has a `verbatimTextArg` mapping configured. Which tool to call isn't ambiguous and the
|
|
108
|
+
* argument that matters most — the user's own words — is already pinned to the raw turn
|
|
109
|
+
* text, so there's nothing left for a model to compose either. (Caught live: asked to do
|
|
110
|
+
* the exact same thing, a model sometimes narrates — "voy a consultar..." — instead of
|
|
111
|
+
* actually emitting the tool call, leaving the user with a blank reply.)
|
|
112
|
+
*
|
|
113
|
+
* Returns `undefined` — never partially constructed input — the moment any other required
|
|
114
|
+
* property can't be confidently resolved, so the caller falls back to the model-driven
|
|
115
|
+
* `runReplyPass` exactly as before. Bypasses the harness too: this never asks a model
|
|
116
|
+
* anything, so a custom `ModelHarness` has nothing to intercept here (same reasoning as the
|
|
117
|
+
* `step.prompt` verbatim path).
|
|
118
|
+
*/
|
|
119
|
+
private tryAutoInvokeRequiredTool;
|
|
65
120
|
private applyPatch;
|
|
66
121
|
private announceStepChange;
|
|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