@falai/agent 2.2.0 → 2.2.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/dist/cjs/core/BranchEvaluator.d.ts +2 -2
- package/dist/cjs/core/BranchEvaluator.js +2 -2
- package/dist/cjs/core/BranchEvaluator.js.map +1 -1
- package/dist/cjs/core/Flow.d.ts +2 -1
- package/dist/cjs/core/Flow.d.ts.map +1 -1
- package/dist/cjs/core/Flow.js +2 -1
- package/dist/cjs/core/Flow.js.map +1 -1
- package/dist/cjs/core/FlowRouter.js +2 -2
- package/dist/cjs/core/FlowRouter.js.map +1 -1
- package/dist/cjs/core/PromptComposer.d.ts.map +1 -1
- package/dist/cjs/core/PromptComposer.js +8 -20
- package/dist/cjs/core/PromptComposer.js.map +1 -1
- package/dist/cjs/core/Step.d.ts +2 -1
- package/dist/cjs/core/Step.d.ts.map +1 -1
- package/dist/cjs/core/Step.js +2 -1
- package/dist/cjs/core/Step.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/DeepSeekProvider.d.ts +61 -0
- package/dist/cjs/providers/DeepSeekProvider.d.ts.map +1 -0
- package/dist/cjs/providers/DeepSeekProvider.js +450 -0
- package/dist/cjs/providers/DeepSeekProvider.js.map +1 -0
- package/dist/cjs/providers/index.d.ts +2 -0
- package/dist/cjs/providers/index.d.ts.map +1 -1
- package/dist/cjs/providers/index.js +3 -1
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +5 -3
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/flow.d.ts +4 -4
- package/dist/core/BranchEvaluator.d.ts +2 -2
- package/dist/core/BranchEvaluator.js +2 -2
- package/dist/core/BranchEvaluator.js.map +1 -1
- package/dist/core/Flow.d.ts +2 -1
- package/dist/core/Flow.d.ts.map +1 -1
- package/dist/core/Flow.js +2 -1
- package/dist/core/Flow.js.map +1 -1
- package/dist/core/FlowRouter.js +2 -2
- package/dist/core/FlowRouter.js.map +1 -1
- package/dist/core/PromptComposer.d.ts.map +1 -1
- package/dist/core/PromptComposer.js +8 -20
- package/dist/core/PromptComposer.js.map +1 -1
- package/dist/core/Step.d.ts +2 -1
- package/dist/core/Step.d.ts.map +1 -1
- package/dist/core/Step.js +2 -1
- package/dist/core/Step.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/DeepSeekProvider.d.ts +61 -0
- package/dist/providers/DeepSeekProvider.d.ts.map +1 -0
- package/dist/providers/DeepSeekProvider.js +443 -0
- package/dist/providers/DeepSeekProvider.js.map +1 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/types/agent.d.ts +5 -3
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/flow.d.ts +4 -4
- package/docs/guides/branching.md +3 -1
- package/docs/guides/conditions.md +9 -8
- package/docs/guides/instructions.md +7 -7
- package/docs/reference/branches.md +2 -2
- package/docs/reference/flow.md +1 -1
- package/docs/reference/instruction.md +7 -5
- package/docs/reference/providers.md +48 -2
- package/docs/reference/step.md +2 -2
- package/package.json +11 -11
- package/src/core/BranchEvaluator.ts +4 -4
- package/src/core/Flow.ts +2 -1
- package/src/core/FlowRouter.ts +2 -2
- package/src/core/PromptComposer.ts +9 -20
- package/src/core/Step.ts +2 -1
- package/src/index.ts +2 -0
- package/src/providers/DeepSeekProvider.ts +666 -0
- package/src/providers/index.ts +3 -0
- package/src/types/agent.ts +5 -3
- package/src/types/flow.ts +4 -4
|
@@ -10,4 +10,6 @@ export { OpenAIProvider } from "./OpenAIProvider";
|
|
|
10
10
|
export type { OpenAIProviderOptions } from "./OpenAIProvider";
|
|
11
11
|
export { OpenRouterProvider } from "./OpenRouterProvider";
|
|
12
12
|
export type { OpenRouterProviderOptions } from "./OpenRouterProvider";
|
|
13
|
+
export { DeepSeekProvider } from "./DeepSeekProvider";
|
|
14
|
+
export type { DeepSeekProviderOptions } from "./DeepSeekProvider";
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/providers/index.js
CHANGED
|
@@ -6,4 +6,5 @@ export { AnthropicProvider } from "./AnthropicProvider";
|
|
|
6
6
|
export { GeminiProvider } from "./GeminiProvider";
|
|
7
7
|
export { OpenAIProvider } from "./OpenAIProvider";
|
|
8
8
|
export { OpenRouterProvider } from "./OpenRouterProvider";
|
|
9
|
+
export { DeepSeekProvider } from "./DeepSeekProvider";
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -245,7 +245,7 @@ export interface Instruction<TContext = unknown, TData = unknown> {
|
|
|
245
245
|
*/
|
|
246
246
|
kind?: 'must' | 'never' | 'should';
|
|
247
247
|
/**
|
|
248
|
-
* AI-evaluated activation condition. String or array of strings (
|
|
248
|
+
* AI-evaluated activation condition. String or array of strings (OR semantics).
|
|
249
249
|
* Undefined = always active. Functions are NOT allowed here — use `if`.
|
|
250
250
|
*/
|
|
251
251
|
when?: ConditionWhen;
|
|
@@ -289,7 +289,8 @@ export interface ScopedInstructions<TContext = unknown, TData = unknown> {
|
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
|
-
* Observability record for an instruction that was
|
|
292
|
+
* Observability record for an instruction that was rendered into a turn's prompt.
|
|
293
|
+
* Textual `when` conditions are included in the prompt for the AI to evaluate.
|
|
293
294
|
* Deterministic — derived from rendering, not from LLM self-report.
|
|
294
295
|
*/
|
|
295
296
|
export interface AppliedInstruction {
|
|
@@ -313,7 +314,8 @@ export interface AgentResponse<TData = Record<string, unknown>> {
|
|
|
313
314
|
/** Why execution stopped (for multi-step execution) */
|
|
314
315
|
stoppedReason?: StoppedReason;
|
|
315
316
|
/**
|
|
316
|
-
* Instructions
|
|
317
|
+
* Instructions rendered into this turn's prompt after code-evaluated gates passed.
|
|
318
|
+
* Textual `when` conditions remain in the prompt for the AI to evaluate.
|
|
317
319
|
* Deterministic — derived from rendering, not from LLM self-report.
|
|
318
320
|
*/
|
|
319
321
|
appliedInstructions?: AppliedInstruction[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/types/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACv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AC3C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;CACnD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B"}
|
package/dist/types/flow.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type ConditionPredicate<TContext = unknown, TData = unknown> = (ctx: {
|
|
|
20
20
|
*/
|
|
21
21
|
export type ConditionIf<TContext = unknown, TData = unknown> = ConditionPredicate<TContext, TData> | ConditionPredicate<TContext, TData>[];
|
|
22
22
|
/**
|
|
23
|
-
* The `when` field shape: a single AI-evaluated string or array of strings (
|
|
23
|
+
* The `when` field shape: a single AI-evaluated string or array of strings (OR semantics).
|
|
24
24
|
* Functions are NOT allowed on `when` — they belong on `if` only.
|
|
25
25
|
*/
|
|
26
26
|
export type ConditionWhen = string | string[];
|
|
@@ -176,7 +176,7 @@ export type BranchPredicate<TContext = unknown, TData = unknown> = (ctx: BranchP
|
|
|
176
176
|
*/
|
|
177
177
|
export interface BranchEntry<TContext = unknown, TData = unknown> {
|
|
178
178
|
/**
|
|
179
|
-
* AI-evaluated condition. String or array of strings (
|
|
179
|
+
* AI-evaluated condition. String or array of strings (OR semantics).
|
|
180
180
|
* Costs LLM tokens. Reuses the same machinery as `step.when`.
|
|
181
181
|
* Only evaluated if `if` passes (or is absent) — code-first short-circuit.
|
|
182
182
|
*/
|
|
@@ -272,7 +272,7 @@ export interface FlowOptions<TContext = unknown, TData = unknown> {
|
|
|
272
272
|
/** Description of what this flow accomplishes */
|
|
273
273
|
description?: string;
|
|
274
274
|
/**
|
|
275
|
-
* AI-evaluated activation condition(s). String or array of strings (
|
|
275
|
+
* AI-evaluated activation condition(s). String or array of strings (OR semantics).
|
|
276
276
|
* Costs LLM tokens. Functions are NOT allowed here — use `if` for code predicates.
|
|
277
277
|
*/
|
|
278
278
|
when?: ConditionWhen;
|
|
@@ -423,7 +423,7 @@ export interface StepOptions<TContext = unknown, TData = unknown> {
|
|
|
423
423
|
*/
|
|
424
424
|
requires?: (keyof TData)[];
|
|
425
425
|
/**
|
|
426
|
-
* AI-evaluated activation condition(s). String or array of strings (
|
|
426
|
+
* AI-evaluated activation condition(s). String or array of strings (OR semantics).
|
|
427
427
|
* Costs LLM tokens. Functions are NOT allowed here — use `if` for code predicates.
|
|
428
428
|
*/
|
|
429
429
|
when?: ConditionWhen;
|
package/docs/guides/branching.md
CHANGED
|
@@ -19,7 +19,7 @@ By the end of this page you will have written four branch points: a pure-code fo
|
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
21
|
interface BranchEntry<TContext, TData> {
|
|
22
|
-
/** AI-evaluated condition. String or array of strings (
|
|
22
|
+
/** AI-evaluated condition. String or array of strings (OR). */
|
|
23
23
|
when?: string | string[];
|
|
24
24
|
|
|
25
25
|
/** Code predicate. Function or array of functions (AND). */
|
|
@@ -101,6 +101,8 @@ flow({
|
|
|
101
101
|
|
|
102
102
|
`when` strings reuse the same machinery as `step.when`. One LLM call evaluates each entry's condition in declaration order; the first match wins. Conditions are written from the agent's perspective — `"user wants to cancel"` reads naturally and matches the prompts the model already speaks. Don't try to compress them into keywords; the AI is doing classification, not pattern matching.
|
|
103
103
|
|
|
104
|
+
When one branch has several alternative phrasings, use an array. The entries use OR semantics: any one match activates the branch.
|
|
105
|
+
|
|
104
106
|
The fallback at the end is doing real work too. When the model can't classify the message into any of the three buckets — say the user typed "hi" — `general_help` catches it instead of dropping the user into AI step selection.
|
|
105
107
|
|
|
106
108
|
## Combining `if` and `when`
|
|
@@ -7,7 +7,7 @@ order: 1
|
|
|
7
7
|
|
|
8
8
|
# When and if
|
|
9
9
|
|
|
10
|
-
Conditions decide whether a flow activates, a step runs, an instruction
|
|
10
|
+
Conditions decide whether a flow activates, a step runs, an instruction applies, or a branch fires. v2 splits them into two distinct fields with different evaluators:
|
|
11
11
|
|
|
12
12
|
- `when` — strings the LLM evaluates against intent and the conversation. Costs tokens.
|
|
13
13
|
- `if` — TypeScript predicates the engine evaluates locally. Free.
|
|
@@ -38,19 +38,19 @@ If the answer lives in `data`, `context`, or `session`, it's `if`. If the answer
|
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Multiple strings combine with **
|
|
41
|
+
Multiple strings combine with **OR** semantics — any clause may pass for the condition to match. Use the array form for alternative natural-language expressions of the same intent:
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
44
|
{
|
|
45
|
-
title: "
|
|
45
|
+
title: "Address",
|
|
46
46
|
when: [
|
|
47
|
-
"the user
|
|
48
|
-
"the user
|
|
47
|
+
"the user asked about the address",
|
|
48
|
+
"the user asked where we are located",
|
|
49
49
|
],
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
The strings are sent to the LLM as part of the routing or activation prompt. Keep
|
|
53
|
+
The strings are sent to the LLM as part of the routing or activation prompt. For instructions, the string is appended to the instruction bullet so the response model can apply the instruction conditionally. Keep conditions short, intent-shaped, and free of code-style boolean expressions — `"the user wants to cancel"` lands; `"data.cancelRequested === true"` does not.
|
|
54
54
|
|
|
55
55
|
## `if` — code predicates
|
|
56
56
|
|
|
@@ -120,7 +120,7 @@ The same `when` / `if` shape attaches to four primitives. Semantics are identica
|
|
|
120
120
|
| --------------- | ----------------------- | -------------------------------------------------- |
|
|
121
121
|
| Flow | `FlowOptions.when/if` | Whether the router selects this flow this turn |
|
|
122
122
|
| Step | `StepOptions.when/if` | Whether the step is reachable in the current flow |
|
|
123
|
-
| Instruction | `Instruction.when/if` | Whether the instruction
|
|
123
|
+
| Instruction | `Instruction.when/if` | Whether the instruction applies to the response |
|
|
124
124
|
| BranchEntry | `BranchEntry.when/if` | Whether this branch entry matches inside `step.branches` |
|
|
125
125
|
|
|
126
126
|
```typescript
|
|
@@ -160,7 +160,8 @@ A short checklist before shipping a condition:
|
|
|
160
160
|
|
|
161
161
|
- Does it read a field, flag, or context value? Use `if`.
|
|
162
162
|
- Does it interpret natural language? Use `when`.
|
|
163
|
-
- Multiple
|
|
163
|
+
- Multiple natural-language alternatives where any may match? Put them in `when` — arrays use OR.
|
|
164
|
+
- Multiple code predicates that must all pass? Put them in `if` — arrays use AND.
|
|
164
165
|
- Need to skip when a value is already collected? `step.skip` (OR semantics).
|
|
165
166
|
- Both fields set? `if` runs first, free; `when` only fires if `if` passes.
|
|
166
167
|
|
|
@@ -62,7 +62,7 @@ createAgent({
|
|
|
62
62
|
});
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
Reach narrows as you nest. Agent-scope instructions render on every turn for every flow. Flow-scope instructions render only while that flow is active. Step-scope instructions render only while that step is current. Conditions on
|
|
65
|
+
Reach narrows as you nest. Agent-scope instructions render on every turn for every flow. Flow-scope instructions render only while that flow is active. Step-scope instructions render only while that step is current. Conditions apply on top: `if` removes an instruction locally when its predicate fails, while `when` is rendered with the instruction so the model can decide whether the natural-language condition applies.
|
|
66
66
|
|
|
67
67
|
The composer renders the resolved set under a single `## Instructions` heading and tags each line with a scope caption so the model can read both *what* and *where from* in one pass:
|
|
68
68
|
|
|
@@ -74,28 +74,28 @@ The composer renders the resolved set under a single `## Instructions` heading a
|
|
|
74
74
|
|
|
75
75
|
## Rendering format
|
|
76
76
|
|
|
77
|
-
Each
|
|
77
|
+
Each eligible instruction lands in the prompt as a single bullet:
|
|
78
78
|
|
|
79
79
|
```
|
|
80
|
-
- [<kind>] [<scope>] <prompt>
|
|
80
|
+
- [<kind>] [<scope>] <prompt> (apply only when: <when-clause> OR <when-clause>)
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
-
A composed block looks like this:
|
|
83
|
+
The condition suffix is omitted when `when` is not set. A composed block looks like this:
|
|
84
84
|
|
|
85
85
|
```
|
|
86
86
|
## Instructions
|
|
87
87
|
|
|
88
88
|
- [must] [Always] Validate dates are in the future before booking.
|
|
89
89
|
- [never] [Always] Promise rates you have not looked up.
|
|
90
|
-
- [should] [In: Booking] Offer to compare two options before committing.
|
|
90
|
+
- [should] [In: Booking] Offer to compare two options before committing. (apply only when: the user is comparing hotel options)
|
|
91
91
|
- [must] [Step: payment] If the card is declined, never retry without confirmation.
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
The format is fixed. The kind prefix is always present (defaulting to `[should]`), the scope caption is always present, and the prompt text follows verbatim.
|
|
94
|
+
The format is fixed. The kind prefix is always present (defaulting to `[should]`), the scope caption is always present, and the prompt text follows verbatim. When present, `when` clauses are joined with `OR` and appended for the model to evaluate.
|
|
95
95
|
|
|
96
96
|
## `appliedInstructions` on the response
|
|
97
97
|
|
|
98
|
-
Every `respond()` call returns an `appliedInstructions` array listing exactly which instructions were rendered into that turn's prompt. The set is deterministic — it comes from the prompt composer, not the model — so you can use it for observability, audits, and tests:
|
|
98
|
+
Every `respond()` call returns an `appliedInstructions` array listing exactly which instructions were rendered into that turn's prompt. The set is deterministic — it comes from the prompt composer, not the model — so you can use it for observability, audits, and tests. For an instruction with `when`, inclusion means the conditional instruction reached the model; it does not claim that the model judged the condition true:
|
|
99
99
|
|
|
100
100
|
```typescript
|
|
101
101
|
const response = await agent.respond("I want to book a room.");
|
|
@@ -19,7 +19,7 @@ Branches resolve **after** the step's post-LLM phase (tool execution, `finalize`
|
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
21
|
interface BranchEntry<TContext = unknown, TData = unknown> {
|
|
22
|
-
/** AI-evaluated condition. String or array of strings (
|
|
22
|
+
/** AI-evaluated condition. String or array of strings (OR semantics). */
|
|
23
23
|
when?: string | string[];
|
|
24
24
|
|
|
25
25
|
/** Code predicate. Function or array of functions (AND semantics). */
|
|
@@ -64,7 +64,7 @@ interface BranchPredicateContext<TContext = unknown, TData = unknown> {
|
|
|
64
64
|
|
|
65
65
|
| Field | Type | Required | Default | Notes |
|
|
66
66
|
|-------|------|----------|---------|-------|
|
|
67
|
-
| `when` | `string \| string[]` | no | — | AI-evaluated condition. Reuses the same machinery as `step.when`. Only evaluated if `if` passes (or is absent). Costs LLM tokens. |
|
|
67
|
+
| `when` | `string \| string[]` | no | — | AI-evaluated condition. Arrays use OR semantics. Reuses the same machinery as `step.when`. Only evaluated if `if` passes (or is absent). Costs LLM tokens. |
|
|
68
68
|
| `if` | `BranchPredicate \| BranchPredicate[]` | no | — | Code predicate. Free to evaluate. When both `when` and `if` are set, `if` runs first; `when` is only evaluated if all `if` predicates pass. |
|
|
69
69
|
| `then` | `string \| Directive` | yes | — | Target. See [Resolution of `then`](#resolution-of-then) below. |
|
|
70
70
|
| `label` | `string` | no | — | Optional label surfaced in event traces and flow visualization. |
|
package/docs/reference/flow.md
CHANGED
|
@@ -77,7 +77,7 @@ class Flow<TContext = unknown, TData = unknown> {
|
|
|
77
77
|
| `id` | `string` | no | derived from `title` | Stable identifier. Auto-generated deterministically from the title when omitted. |
|
|
78
78
|
| `title` | `string` | yes | — | Human-readable name. Shown to the router and used as the default flow id. |
|
|
79
79
|
| `description` | `string` | no | — | One-line summary surfaced to the router prompt. |
|
|
80
|
-
| `when` | `string \| string[]` | no | — | AI-evaluated activation condition(s). Strings only — functions belong on `if`. Multiple strings combine with
|
|
80
|
+
| `when` | `string \| string[]` | no | — | AI-evaluated activation condition(s). Strings only — functions belong on `if`. Multiple strings combine with OR semantics. |
|
|
81
81
|
| `if` | `(ctx) => boolean \| Promise<boolean>` or array | no | — | Code-evaluated activation condition(s). Free to evaluate. When both are set, `if` runs first; `when` only evaluates if `if` passes. |
|
|
82
82
|
| `instructions` | `Instruction<TContext, TData>[]` | no | `[]` | Flow-scoped instructions. Apply only while this flow is active. See [Instruction](./instruction.md). |
|
|
83
83
|
| `tools` | `(string \| Tool)[]` | no | `[]` | Tool ids (resolved via the agent's tool registry) or inline `Tool` objects. Available only while this flow is active. |
|
|
@@ -11,7 +11,7 @@ order: 5
|
|
|
11
11
|
|
|
12
12
|
An `Instruction` is a single statement of behavior the agent should follow. v2 collapses three v1 types into one — every instruction now carries a `kind` discriminator (`'must'`, `'never'`, or `'should'`) and a `prompt` that is rendered into the system prompt with a scope caption. The same shape works at agent, flow, and step scope; only its position in the configuration changes.
|
|
13
13
|
|
|
14
|
-
The set of instructions actually rendered into a given turn's prompt is reported back on the response as `appliedInstructions` — observability is deterministic, derived from rendering, not self-reported by the model.
|
|
14
|
+
The set of instructions actually rendered into a given turn's prompt is reported back on the response as `appliedInstructions` — observability is deterministic, derived from rendering, not self-reported by the model. For instructions with a textual `when`, this means the condition was presented to the model, not that the model reported a match.
|
|
15
15
|
|
|
16
16
|
## Signature
|
|
17
17
|
|
|
@@ -19,7 +19,7 @@ The set of instructions actually rendered into a given turn's prompt is reported
|
|
|
19
19
|
interface Instruction<TContext = unknown, TData = unknown> {
|
|
20
20
|
id?: string;
|
|
21
21
|
kind?: 'must' | 'never' | 'should'; // default: 'should'
|
|
22
|
-
when?: ConditionWhen; // AI-evaluated string(s),
|
|
22
|
+
when?: ConditionWhen; // AI-evaluated string(s), OR semantics
|
|
23
23
|
if?: ConditionIf<TContext, TData>; // code-evaluated function(s), AND semantics
|
|
24
24
|
prompt: Template<TContext, TData>;
|
|
25
25
|
enabled?: boolean; // default: true
|
|
@@ -48,7 +48,7 @@ interface AppliedInstruction {
|
|
|
48
48
|
|-------|------|----------|---------|-------|
|
|
49
49
|
| `prompt` | `Template<TContext, TData>` | yes | — | Behavioral text rendered into the prompt under the `## Instructions` section. |
|
|
50
50
|
| `kind` | `'must' \| 'never' \| 'should'` | no | `'should'` | Severity. `'must'` = absolute do, `'never'` = absolute don't, `'should'` = conditional nudge. |
|
|
51
|
-
| `when` | `ConditionWhen` | no | — | AI-evaluated activation string (or array,
|
|
51
|
+
| `when` | `ConditionWhen` | no | — | AI-evaluated activation string (or array, OR semantics). Functions are not allowed here; use `if`. |
|
|
52
52
|
| `if` | `ConditionIf<TContext, TData>` | no | — | Code-evaluated activation function (or array). Free to evaluate. When both `when` and `if` are set, `if` runs first; `when` is only evaluated if `if` passes. |
|
|
53
53
|
| `id` | `string` | no | auto | Stable identifier used in `AppliedInstruction.id`. Auto-generated when omitted. |
|
|
54
54
|
| `enabled` | `boolean` | no | `true` | Set `false` to skip the instruction without removing it from configuration. |
|
|
@@ -71,12 +71,14 @@ The same `Instruction` shape attaches at three positions:
|
|
|
71
71
|
- **Flow:** `FlowOptions.instructions` — considered when the active flow matches.
|
|
72
72
|
- **Step:** `StepOptions.instructions` — considered when the active step matches.
|
|
73
73
|
|
|
74
|
-
At prompt-build time the composer renders each
|
|
74
|
+
At prompt-build time the composer renders each eligible instruction as a single bullet:
|
|
75
75
|
|
|
76
76
|
```
|
|
77
|
-
- [<kind>] [<scope-caption>] <prompt>
|
|
77
|
+
- [<kind>] [<scope-caption>] <prompt> (apply only when: <when-clause> OR <when-clause>)
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
The parenthesized condition is omitted when `when` is not set. Code-evaluated `if` predicates run first; a failing predicate removes the entire bullet before the prompt reaches the model.
|
|
81
|
+
|
|
80
82
|
Scope captions are fixed by where the instruction was declared:
|
|
81
83
|
|
|
82
84
|
| Scope | Caption |
|
|
@@ -11,7 +11,7 @@ order: 10
|
|
|
11
11
|
|
|
12
12
|
Providers are the strategy plug between an `Agent` and a model vendor. Every provider implements the same `AiProvider` interface, so the Agent itself stays vendor-agnostic. Pass an instance to `createAgent({ provider })` and the agent talks to that vendor for every turn (and for compaction, if you wire it in).
|
|
13
13
|
|
|
14
|
-
`@falai/agent` ships
|
|
14
|
+
`@falai/agent` ships five built-in providers. All five accept an `apiKey` and a required `model`, support `backupModels` for automatic failover on overload or 5xx, and accept a vendor-typed `config` object that flows through to the underlying SDK.
|
|
15
15
|
|
|
16
16
|
| Provider | Class | Options | SDK |
|
|
17
17
|
|----------|-------|---------|-----|
|
|
@@ -19,6 +19,7 @@ Providers are the strategy plug between an `Agent` and a model vendor. Every pro
|
|
|
19
19
|
| OpenAI | `OpenAIProvider` | `OpenAIProviderOptions` | `openai` |
|
|
20
20
|
| Anthropic Claude | `AnthropicProvider` | `AnthropicProviderOptions` | `@anthropic-ai/sdk` |
|
|
21
21
|
| OpenRouter | `OpenRouterProvider` | `OpenRouterProviderOptions` | `openai` (compat) |
|
|
22
|
+
| DeepSeek | `DeepSeekProvider` | `DeepSeekProviderOptions` | `openai` (compat) |
|
|
22
23
|
|
|
23
24
|
## Use with createAgent
|
|
24
25
|
|
|
@@ -31,6 +32,7 @@ import {
|
|
|
31
32
|
OpenAIProvider,
|
|
32
33
|
AnthropicProvider,
|
|
33
34
|
OpenRouterProvider,
|
|
35
|
+
DeepSeekProvider,
|
|
34
36
|
} from "@falai/agent";
|
|
35
37
|
|
|
36
38
|
const provider =
|
|
@@ -40,6 +42,8 @@ const provider =
|
|
|
40
42
|
? new AnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY!, model: "claude-sonnet-4-6" })
|
|
41
43
|
: process.env.PROVIDER === "openrouter"
|
|
42
44
|
? new OpenRouterProvider({ apiKey: process.env.OPENROUTER_API_KEY!, model: "anthropic/claude-sonnet-4.6" })
|
|
45
|
+
: process.env.PROVIDER === "deepseek"
|
|
46
|
+
? new DeepSeekProvider({ apiKey: process.env.DEEPSEEK_API_KEY!, model: "deepseek-chat" })
|
|
43
47
|
: new GeminiProvider({ apiKey: process.env.GEMINI_API_KEY!, model: "gemini-3.1-pro-preview" });
|
|
44
48
|
|
|
45
49
|
const agent = createAgent({ provider, schema, flows });
|
|
@@ -204,9 +208,51 @@ const openrouter = new OpenRouterProvider({
|
|
|
204
208
|
});
|
|
205
209
|
```
|
|
206
210
|
|
|
211
|
+
## DeepSeekProvider
|
|
212
|
+
|
|
213
|
+
DeepSeek is OpenAI-compatible and offers powerful reasoning models. The `deepseek-reasoner` model streams thinking/reasoning content via `reasoning_content` on the delta, which is logged at debug level.
|
|
214
|
+
|
|
215
|
+
### Signature
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
new DeepSeekProvider(options: DeepSeekProviderOptions)
|
|
219
|
+
|
|
220
|
+
interface DeepSeekProviderOptions {
|
|
221
|
+
apiKey: string;
|
|
222
|
+
model: string;
|
|
223
|
+
backupModels?: string[];
|
|
224
|
+
baseURL?: string;
|
|
225
|
+
config?: Partial<Omit<ChatCompletionCreateParamsNonStreaming, "model" | "messages">>;
|
|
226
|
+
retryConfig?: { timeout?: number; retries?: number };
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Fields
|
|
231
|
+
|
|
232
|
+
| Field | Type | Required | Default | Notes |
|
|
233
|
+
|-------|------|----------|---------|-------|
|
|
234
|
+
| `apiKey` | `string` | yes | — | Throws if empty. |
|
|
235
|
+
| `model` | `string` | yes | — | e.g. `"deepseek-chat"`, `"deepseek-reasoner"`. |
|
|
236
|
+
| `backupModels` | `string[]` | no | `[]` | Tried in order on overload/rate-limit errors. |
|
|
237
|
+
| `baseURL` | `string` | no | `"https://api.deepseek.com"` | Custom endpoint for self-hosted or proxy deployments. |
|
|
238
|
+
| `config` | OpenAI params | no | — | OpenAI-shaped defaults (forwarded to DeepSeek). |
|
|
239
|
+
| `retryConfig.timeout` | `number` | no | `60000` | Per-attempt timeout in ms. |
|
|
240
|
+
| `retryConfig.retries` | `number` | no | `3` | Total attempts. |
|
|
241
|
+
|
|
242
|
+
### Example
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
const deepseek = new DeepSeekProvider({
|
|
246
|
+
apiKey: process.env.DEEPSEEK_API_KEY!,
|
|
247
|
+
model: "deepseek-chat",
|
|
248
|
+
backupModels: ["deepseek-reasoner"],
|
|
249
|
+
config: { temperature: 0.3 },
|
|
250
|
+
});
|
|
251
|
+
```
|
|
252
|
+
|
|
207
253
|
## Errors
|
|
208
254
|
|
|
209
|
-
All
|
|
255
|
+
All five providers share the same construction-time guards and runtime failure modes.
|
|
210
256
|
|
|
211
257
|
| When | Error | Why |
|
|
212
258
|
|------|-------|-----|
|
package/docs/reference/step.md
CHANGED
|
@@ -96,7 +96,7 @@ interface StepLifecycleHooks<TContext = unknown, TData = unknown> {
|
|
|
96
96
|
| `auto` | `boolean` | no | `false` | When `true`, the step runs without an LLM call — only `onEnter`, `prepare`, and `branches` execute. Cannot coexist with `prompt`, `collect`, `tools`, or `finalize`. Counts against `maxAutoStepsPerTurn`. |
|
|
97
97
|
| `collect` | `(keyof TData)[]` | no | `[]` | Schema field keys this step is responsible for extracting from the user message. Every key must exist in the agent's `schema`. The engine skips the step automatically when every listed key is already present in `session.data` (pre-extraction). |
|
|
98
98
|
| `requires` | `(keyof TData)[]` | no | `[]` | Prerequisite field keys. The engine refuses to enter the step until every key is present in `session.data`. When fields covered by `requires` are read inside `branches[].if` predicates, they are guaranteed to be defined. |
|
|
99
|
-
| `when` | `string \| string[]` | no | — | AI-evaluated activation strings (
|
|
99
|
+
| `when` | `string \| string[]` | no | — | AI-evaluated activation strings (OR semantics). Evaluated by the LLM at routing time. Functions are not allowed here — the constructor throws `FlowConfigurationError` if a function is found. |
|
|
100
100
|
| `if` | `(ctx) => boolean \| Promise<boolean>` or array | no | — | Code-evaluated activation predicates (AND semantics). Evaluated locally — no LLM cost. When both `when` and `if` are set, `if` runs first; `when` is only evaluated if every `if` predicate passes. |
|
|
101
101
|
| `skip` | `(ctx) => boolean \| Promise<boolean>` or array | no | — | Code-evaluated skip predicates (OR semantics). When any predicate returns `true`, the step is bypassed. Only code predicates — no AI strings. |
|
|
102
102
|
| `tools` | `(string \| Tool<TContext, TData>)[]` | no | `[]` | Tools available during this step. Strings are resolved against the agent's tool registry; objects are inline tools. Stacked on top of agent and flow scopes. |
|
|
@@ -130,7 +130,7 @@ or the full `Directive` surface (`appendPrompt`,
|
|
|
130
130
|
|
|
131
131
|
For one step, the engine walks this sequence per turn:
|
|
132
132
|
|
|
133
|
-
1. Evaluate `if` (code, AND) and `when` (AI,
|
|
133
|
+
1. Evaluate `if` (code, AND) and `when` (AI, OR) — fails skip the step entirely.
|
|
134
134
|
2. Evaluate `skip` (code, OR) — true means bypass and fall through.
|
|
135
135
|
3. Check `requires` — refuse entry if any required field is missing.
|
|
136
136
|
4. Run `onEnter`, then `prepare` / `hooks.prepare`. May emit a `Directive` (pre-LLM fields honored).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falai/agent",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Conversational state engine for TypeScript where the AI understands, but the code is in control",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://falai.dev",
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
41
|
+
"build": "bun run build:esm && bun run build:cjs && bun run fix:cjs",
|
|
42
42
|
"build:esm": "tsc",
|
|
43
43
|
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
44
44
|
"fix:cjs": "echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
@@ -48,15 +48,14 @@
|
|
|
48
48
|
"lint": "eslint src/**/*.ts",
|
|
49
49
|
"lint:fix": "eslint src/**/*.ts --fix",
|
|
50
50
|
"clean": "rm -rf dist",
|
|
51
|
-
"prebuild": "
|
|
52
|
-
"prepublishOnly": "
|
|
53
|
-
"release:patch": "
|
|
54
|
-
"release:minor": "
|
|
55
|
-
"release:major": "
|
|
56
|
-
"release:alpha": "
|
|
57
|
-
"release": "
|
|
58
|
-
"test": "bun test tests/*.test.ts"
|
|
59
|
-
"preinstall": "node preinstall.js"
|
|
51
|
+
"prebuild": "bun run clean",
|
|
52
|
+
"prepublishOnly": "bun run lint && bun run typecheck && bun run build && bun run test",
|
|
53
|
+
"release:patch": "bun pm version patch && bun publish",
|
|
54
|
+
"release:minor": "bun pm version minor && bun publish",
|
|
55
|
+
"release:major": "bun pm version major && bun publish",
|
|
56
|
+
"release:alpha": "bun publish --tag alpha",
|
|
57
|
+
"release": "bun publish",
|
|
58
|
+
"test": "bun test tests/*.test.ts"
|
|
60
59
|
},
|
|
61
60
|
"keywords": [
|
|
62
61
|
"ai",
|
|
@@ -67,6 +66,7 @@
|
|
|
67
66
|
"gemini",
|
|
68
67
|
"openai",
|
|
69
68
|
"anthropic",
|
|
69
|
+
"deepseek",
|
|
70
70
|
"llm",
|
|
71
71
|
"chatbot",
|
|
72
72
|
"framework",
|
|
@@ -20,8 +20,8 @@ import { eventsToHistory, logger } from "../utils";
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* The AI condition evaluator function signature.
|
|
23
|
-
* Accepts an array of condition strings (
|
|
24
|
-
* whether
|
|
23
|
+
* Accepts an array of condition strings (OR semantics) and returns
|
|
24
|
+
* whether any condition is satisfied.
|
|
25
25
|
*
|
|
26
26
|
* This is the same evaluation mechanism used by `step.when` — condition
|
|
27
27
|
* strings are evaluated by the AI provider against the conversation context.
|
|
@@ -65,7 +65,7 @@ export function createAiConditionEvaluator<TContext = unknown>(
|
|
|
65
65
|
"Condition(s):",
|
|
66
66
|
conditionText,
|
|
67
67
|
"",
|
|
68
|
-
"Return JSON with a single boolean field `result`: true if
|
|
68
|
+
"Return JSON with a single boolean field `result`: true if ANY condition is satisfied, false otherwise.",
|
|
69
69
|
].join("\n");
|
|
70
70
|
|
|
71
71
|
const result = await provider.generateMessage<TContext, { result: boolean }>({
|
|
@@ -78,7 +78,7 @@ export function createAiConditionEvaluator<TContext = unknown>(
|
|
|
78
78
|
properties: {
|
|
79
79
|
result: {
|
|
80
80
|
type: "boolean",
|
|
81
|
-
description: "Whether
|
|
81
|
+
description: "Whether any condition is met based on the conversation context",
|
|
82
82
|
},
|
|
83
83
|
},
|
|
84
84
|
required: ["result"],
|
package/src/core/Flow.ts
CHANGED
|
@@ -246,7 +246,8 @@ export class Flow<TContext = unknown, TData = unknown> {
|
|
|
246
246
|
/**
|
|
247
247
|
* Evaluate when/if conditions using the v2 split logic.
|
|
248
248
|
* `if` (code predicate) evaluates first (free); `when` (AI) evaluates only when `if` passes.
|
|
249
|
-
*
|
|
249
|
+
* `if` predicates use AND semantics. `when` strings use OR semantics.
|
|
250
|
+
* When both fields are set, the passing `if` gate and AI match are combined with AND.
|
|
250
251
|
*/
|
|
251
252
|
async evaluateWhen(
|
|
252
253
|
templateContext: TemplateContext<TContext, TData>
|
package/src/core/FlowRouter.ts
CHANGED
|
@@ -1151,7 +1151,7 @@ export class FlowRouter<TContext = unknown, TData = unknown> {
|
|
|
1151
1151
|
if (candidate.step.when) {
|
|
1152
1152
|
const whenResult = await candidate.step.evaluateWhen(templateContext);
|
|
1153
1153
|
if (whenResult.aiContextStrings.length > 0) {
|
|
1154
|
-
parts.push(` When
|
|
1154
|
+
parts.push(` When any condition matches: ${whenResult.aiContextStrings.join(" OR ")}`);
|
|
1155
1155
|
} else if (typeof candidate.step.when === 'string') {
|
|
1156
1156
|
parts.push(` When this step should be completed: ${candidate.step.when}`);
|
|
1157
1157
|
}
|
|
@@ -1436,7 +1436,7 @@ export class FlowRouter<TContext = unknown, TData = unknown> {
|
|
|
1436
1436
|
if (step.when) {
|
|
1437
1437
|
const whenResult = await step.evaluateWhen(templateContext);
|
|
1438
1438
|
if (whenResult.aiContextStrings.length > 0) {
|
|
1439
|
-
stepInfo.push(` When
|
|
1439
|
+
stepInfo.push(` When any condition matches: ${whenResult.aiContextStrings.join(" OR ")}`);
|
|
1440
1440
|
activeStepConditionContext.push(...whenResult.aiContextStrings);
|
|
1441
1441
|
} else if (typeof step.when === 'string') {
|
|
1442
1442
|
stepInfo.push(` When this step should be completed: ${step.when}`);
|
|
@@ -2,7 +2,6 @@ import type { Event, Term, Instruction, AgentOptions, ScopedInstructions, Applie
|
|
|
2
2
|
import type { Flow } from "./Flow";
|
|
3
3
|
import { render, renderMany, formatKnowledgeBase, createTemplateContext } from "../utils/template";
|
|
4
4
|
import { TemplateContext } from "../types/template";
|
|
5
|
-
import { ConditionEvaluator } from "../utils/condition";
|
|
6
5
|
import { PromptSectionCache } from "./PromptSectionCache";
|
|
7
6
|
import { logger } from "../utils";
|
|
8
7
|
|
|
@@ -155,8 +154,6 @@ export class PromptComposer<TContext = unknown, TData = unknown> {
|
|
|
155
154
|
// Reset the per-turn applied set
|
|
156
155
|
this.lastAppliedInstructions = [];
|
|
157
156
|
|
|
158
|
-
const evaluator = new ConditionEvaluator(this.renderContext);
|
|
159
|
-
|
|
160
157
|
/**
|
|
161
158
|
* Evaluate a single instruction's `if` code predicate(s).
|
|
162
159
|
* Returns true if all predicates pass (AND semantics).
|
|
@@ -182,17 +179,6 @@ export class PromptComposer<TContext = unknown, TData = unknown> {
|
|
|
182
179
|
return true;
|
|
183
180
|
};
|
|
184
181
|
|
|
185
|
-
/**
|
|
186
|
-
* Evaluate a single instruction's `when` condition.
|
|
187
|
-
* Returns true if the instruction should be active.
|
|
188
|
-
*/
|
|
189
|
-
const evaluateWhen = async (when: Instruction<TContext, TData>['when']): Promise<boolean> => {
|
|
190
|
-
if (when === undefined) return true;
|
|
191
|
-
const evaluation = await evaluator.evaluateCondition(when, 'AND');
|
|
192
|
-
if (!evaluation.hasProgrammaticConditions) return true;
|
|
193
|
-
return evaluation.programmaticResult;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
182
|
/**
|
|
197
183
|
* Resolve the kind prefix for rendering.
|
|
198
184
|
* Default kind is 'should'.
|
|
@@ -203,7 +189,7 @@ export class PromptComposer<TContext = unknown, TData = unknown> {
|
|
|
203
189
|
};
|
|
204
190
|
|
|
205
191
|
/**
|
|
206
|
-
* Process a scope bucket: filter enabled,
|
|
192
|
+
* Process a scope bucket: filter enabled, gate by `if`, render `when`, and collect applied records.
|
|
207
193
|
*/
|
|
208
194
|
const processScope = async (
|
|
209
195
|
items: Instruction<TContext, TData>[],
|
|
@@ -219,14 +205,17 @@ export class PromptComposer<TContext = unknown, TData = unknown> {
|
|
|
219
205
|
const ifPassed = await evaluateIf(g.if);
|
|
220
206
|
if (!ifPassed) continue;
|
|
221
207
|
|
|
222
|
-
// Evaluate `when` (AI condition) only when `if` passed
|
|
223
|
-
const active = await evaluateWhen(g.when);
|
|
224
|
-
if (!active) continue;
|
|
225
|
-
|
|
226
208
|
const text = await render(g.prompt, this.renderContext);
|
|
227
209
|
if (!text) continue;
|
|
228
210
|
|
|
229
|
-
|
|
211
|
+
const whenContextStrings = g.when
|
|
212
|
+
? (Array.isArray(g.when) ? g.when : [g.when])
|
|
213
|
+
: [];
|
|
214
|
+
const condition = whenContextStrings.length > 0
|
|
215
|
+
? ` (apply only when: ${whenContextStrings.join(" OR ")})`
|
|
216
|
+
: "";
|
|
217
|
+
|
|
218
|
+
lines.push(`- ${kindPrefix(g.kind)} ${caption} ${text}${condition}`);
|
|
230
219
|
this.lastAppliedInstructions.push({
|
|
231
220
|
id: g.id || '',
|
|
232
221
|
scope,
|
package/src/core/Step.ts
CHANGED
|
@@ -448,7 +448,8 @@ export class Step<TContext = unknown, TData = unknown> {
|
|
|
448
448
|
/**
|
|
449
449
|
* Evaluate when/if conditions using the v2 split logic.
|
|
450
450
|
* `if` (code predicate) evaluates first (free); `when` (AI) evaluates only when `if` passes.
|
|
451
|
-
*
|
|
451
|
+
* `if` predicates use AND semantics. `when` strings use OR semantics.
|
|
452
|
+
* When both fields are set, the passing `if` gate and AI match are combined with AND.
|
|
452
453
|
*/
|
|
453
454
|
async evaluateWhen(
|
|
454
455
|
templateContext: TemplateContext<TContext, TData>
|
package/src/index.ts
CHANGED
|
@@ -31,6 +31,8 @@ export { OpenRouterProvider } from "./providers/OpenRouterProvider";
|
|
|
31
31
|
export type { OpenRouterProviderOptions } from "./providers/OpenRouterProvider";
|
|
32
32
|
export { AnthropicProvider } from "./providers/AnthropicProvider";
|
|
33
33
|
export type { AnthropicProviderOptions } from "./providers/AnthropicProvider";
|
|
34
|
+
export { DeepSeekProvider } from "./providers/DeepSeekProvider";
|
|
35
|
+
export type { DeepSeekProviderOptions } from "./providers/DeepSeekProvider";
|
|
34
36
|
|
|
35
37
|
// Adapters
|
|
36
38
|
export { PrismaAdapter } from "./adapters/PrismaAdapter";
|