@statelyai/agent 2.0.0-alpha.25 → 2.0.0-alpha.27
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/ai-sdk.cjs +4 -4
- package/dist/ai-sdk.d.cts +6 -6
- package/dist/ai-sdk.d.mts +6 -6
- package/dist/ai-sdk.mjs +4 -4
- package/dist/{decision-CM9CYZ6t.cjs → decision-CmM8-HHz.cjs} +10 -9
- package/dist/{decision-DzSv1NpD.mjs → decision-RQ0iv0oZ.mjs} +10 -9
- package/dist/{event-log-store-Ba2fsc4E.mjs → event-log-store-2pAFiWuc.mjs} +1 -1
- package/dist/{event-log-store-DvOcs10J.d.cts → event-log-store-2xzFmgr2.d.cts} +1 -1
- package/dist/{event-log-store-DxyVgnas.d.mts → event-log-store-BIPOz-di.d.mts} +1 -1
- package/dist/{event-log-store-DQmImLYk.cjs → event-log-store-C-COhIXP.cjs} +1 -1
- package/dist/index.cjs +13 -195
- package/dist/index.d.cts +25 -105
- package/dist/index.d.mts +25 -105
- package/dist/index.mjs +12 -189
- package/dist/log.cjs +1 -1
- package/dist/log.d.cts +1 -1
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +1 -1
- package/dist/machines.cjs +4 -7
- package/dist/machines.d.cts +5 -7
- package/dist/machines.d.mts +5 -7
- package/dist/machines.mjs +4 -7
- package/dist/openai.cjs +3 -3
- package/dist/openai.d.cts +5 -5
- package/dist/openai.d.mts +5 -5
- package/dist/openai.mjs +3 -3
- package/dist/otel.cjs +2 -2
- package/dist/otel.d.cts +3 -3
- package/dist/otel.d.mts +3 -3
- package/dist/otel.mjs +2 -2
- package/dist/{run-agent-CG343kFs.d.mts → run-agent-ByO-Bxyd.d.cts} +184 -179
- package/dist/{run-agent-BOfoJg5B.d.cts → run-agent-COXXc0RW.d.mts} +184 -179
- package/dist/{run-agent-Cb1-LS5P.cjs → run-agent-Dmf8GV2d.cjs} +539 -737
- package/dist/{run-agent-DvDQd4If.mjs → run-agent-xNTxpt82.mjs} +537 -705
- package/dist/{setup-agent-CFW-jPI8.mjs → setup-agent-BuanDXeh.mjs} +6 -28
- package/dist/{setup-agent-CPf7MxnG.cjs → setup-agent-DV4cTou-.cjs} +6 -28
- package/dist/testing.cjs +285 -170
- package/dist/testing.d.cts +39 -22
- package/dist/testing.d.mts +39 -22
- package/dist/testing.mjs +270 -155
- package/dist/{text-logic-Bl_ZRxDi.mjs → text-logic-CIqHAmBi.mjs} +10 -26
- package/dist/{text-logic-BFEOxyxv.d.cts → text-logic-D-czVPYp.d.mts} +27 -28
- package/dist/{text-logic-hZSiRUo1.d.mts → text-logic-IjfYy9DP.d.cts} +27 -28
- package/dist/{text-logic-C8xyr6Ag.cjs → text-logic-f5F5sCdc.cjs} +9 -43
- package/dist/{types-B1Qs2q3q.d.cts → types-BgNbNKnJ.d.mts} +3 -3
- package/dist/{types-tA3SdczG.d.mts → types-hR5f5YXa.d.cts} +3 -3
- package/dist/{utils-C1p37X_c.d.mts → utils-_q7F-AZu.d.mts} +3 -103
- package/dist/{utils-RalRn9sk.d.cts → utils-o4YRdHJX.d.cts} +3 -103
- package/dist/validate.cjs +0 -8
- package/dist/validate.mjs +0 -8
- package/package.json +5 -4
- package/readme.md +8 -4
- package/schemas/agent-workflow.json +0 -8
package/dist/testing.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { u as ChosenEvent } from "./types-
|
|
2
|
-
import { Z as AgentError, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-
|
|
3
|
-
import { d as
|
|
4
|
-
import {
|
|
1
|
+
import { u as ChosenEvent } from "./types-hR5f5YXa.cjs";
|
|
2
|
+
import { Z as AgentError, c as AgentRequestExecutorInfo, f as AgentTextRequest, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-IjfYy9DP.cjs";
|
|
3
|
+
import { c as AgentRunResult, d as AgentRuntimeOptions, o as AgentRunInit } from "./run-agent-ByO-Bxyd.cjs";
|
|
4
|
+
import { t as MetaOfSnapshot } from "./utils-o4YRdHJX.cjs";
|
|
5
5
|
import { AnyMachineSnapshot, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
|
|
7
7
|
//#region src/verify.d.ts
|
|
@@ -415,11 +415,13 @@ interface TrajectoryMatch {
|
|
|
415
415
|
* @example Trajectory assertions in a test
|
|
416
416
|
* ```ts
|
|
417
417
|
* const statePath: unknown[] = [];
|
|
418
|
-
* const result = await
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
418
|
+
* const result = await runToQuiescence(
|
|
419
|
+
* createAgentRuntime(machine, {
|
|
420
|
+
* executors,
|
|
421
|
+
* onTransition: (snapshot) => statePath.push(snapshot.value),
|
|
422
|
+
* }),
|
|
423
|
+
* { input },
|
|
424
|
+
* );
|
|
423
425
|
*
|
|
424
426
|
* const path = matchesTrajectory(statePath, ['prompting', 'drafting', 'sent']);
|
|
425
427
|
* expect(path.matched, JSON.stringify(path.firstMiss)).toBe(true);
|
|
@@ -435,6 +437,20 @@ interface TrajectoryMatch {
|
|
|
435
437
|
declare function matchesTrajectory(actual: readonly unknown[], expected: readonly TrajectoryItem[], options?: MatchTrajectoryOptions): TrajectoryMatch;
|
|
436
438
|
//#endregion
|
|
437
439
|
//#region src/seam.d.ts
|
|
440
|
+
/**
|
|
441
|
+
* One scripted answer in a {@link RunSeamOptions.scripts} queue: the request's
|
|
442
|
+
* output value (a string, or the object a structured request declares), or a
|
|
443
|
+
* function of the {@link AgentTextRequest} returning one.
|
|
444
|
+
*
|
|
445
|
+
* An entry is taken as the executor result (instead of the value itself)
|
|
446
|
+
* only when its OWN keys are a `result` plus, optionally, `messages`/`usage`/
|
|
447
|
+
* `raw` — that is how an entry reports token `usage`. Anything else, including
|
|
448
|
+
* an object that merely happens to have a `result` key alongside its own data
|
|
449
|
+
* (`{ result: 'draft', confidence: 0.9 }`), is the output value. For a
|
|
450
|
+
* structured request whose declared output is exactly `{ result }` (or
|
|
451
|
+
* `{ result, usage }`), wrap it once more: `{ result: { result: '…' } }`.
|
|
452
|
+
*/
|
|
453
|
+
type SeamScriptEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
438
454
|
/**
|
|
439
455
|
* Which model call is under test: the Nth call with this request `name` (the
|
|
440
456
|
* `setupAgent({ requests })` key, or `createTextLogic({ name })`). Name the
|
|
@@ -466,7 +482,7 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
|
|
|
466
482
|
/** 0-based index of this pause within the run. */
|
|
467
483
|
turn: number;
|
|
468
484
|
/** The `idle` result that produced the pause. */
|
|
469
|
-
result:
|
|
485
|
+
result: AgentRunResult<TMachine>;
|
|
470
486
|
}
|
|
471
487
|
/**
|
|
472
488
|
* One text call in a {@link runSeam} run's ledger, in call order — the receipt
|
|
@@ -497,7 +513,7 @@ interface SeamSlice {
|
|
|
497
513
|
}
|
|
498
514
|
/** Options for {@link runSeam}. */
|
|
499
515
|
interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
500
|
-
/** Machine input, passed straight through to `
|
|
516
|
+
/** Machine input, passed straight through to `runToQuiescence`. */
|
|
501
517
|
input?: InputFrom<TMachine>;
|
|
502
518
|
/**
|
|
503
519
|
* The call plan: scripted answers per key, consumed in order. A key is a
|
|
@@ -505,12 +521,12 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
505
521
|
* machine whose requests are named routes by name and an unnamed one routes
|
|
506
522
|
* by model.
|
|
507
523
|
*
|
|
508
|
-
* Entries follow {@link
|
|
524
|
+
* Entries follow {@link SeamScriptEntry} conventions (a value, an
|
|
509
525
|
* `{ result, usage? }` object, or a function of the request). A queue that
|
|
510
526
|
* runs dry throws; set {@link RunSeamOptions.repeatLast} to replay its last
|
|
511
527
|
* entry instead.
|
|
512
528
|
*/
|
|
513
|
-
scripts?: Record<string,
|
|
529
|
+
scripts?: Record<string, SeamScriptEntry[]>;
|
|
514
530
|
/**
|
|
515
531
|
* Replay the LAST entry of a queue once it is exhausted, so a live seam that
|
|
516
532
|
* sends the run down a longer branch still finds an answer. Off by default:
|
|
@@ -534,20 +550,21 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
534
550
|
/** Maximum idle pauses to answer before stopping. Default `12`. */
|
|
535
551
|
maxTurns?: number;
|
|
536
552
|
/**
|
|
537
|
-
* Base executors merged UNDER the seam routing — supply `decide` (
|
|
538
|
-
*
|
|
553
|
+
* Base executors merged UNDER the seam routing — supply `decide` (a plain
|
|
554
|
+
* function of the decision request, or `createAiSdkExecutors` over a mock
|
|
555
|
+
* model) for a machine that also decides.
|
|
539
556
|
* Text slots are always owned by the routing.
|
|
540
557
|
*/
|
|
541
558
|
executors?: Partial<AgentRequestExecutors>;
|
|
542
|
-
/** Passed through to `
|
|
543
|
-
actors?:
|
|
559
|
+
/** Passed through to `createAgentRuntime`: actor implementations merged onto the machine. */
|
|
560
|
+
actors?: (AgentRuntimeOptions<TMachine> & AgentRunInit<TMachine>)["actors"];
|
|
544
561
|
}
|
|
545
562
|
/** What {@link runSeam} returns: the seam's own answer, plus the run it caused. */
|
|
546
563
|
interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
547
564
|
/**
|
|
548
|
-
* The final `
|
|
565
|
+
* The final `runToQuiescence` result. `usage` accounts for the last leg.
|
|
549
566
|
*/
|
|
550
|
-
result:
|
|
567
|
+
result: AgentRunResult<TMachine>;
|
|
551
568
|
/** What the seam call returned, or `undefined` when the run never reached it. */
|
|
552
569
|
seamOutput: unknown;
|
|
553
570
|
/**
|
|
@@ -583,8 +600,8 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
583
600
|
* @example No API key: the seam is scripted too, so the whole thing runs offline.
|
|
584
601
|
* ```ts
|
|
585
602
|
* const run = await runSeam(emailDrafter, {
|
|
586
|
-
* scripts: {
|
|
587
|
-
* seam: { request: '
|
|
603
|
+
* scripts: { writeFollowUps: [followUps], emailDrafter: [draft] },
|
|
604
|
+
* seam: { request: 'writeFollowUps' },
|
|
588
605
|
* respond: ({ state }) => (state === 'prompting' ? { type: 'PROMPT_SUBMITTED', prompt } : null),
|
|
589
606
|
* });
|
|
590
607
|
*
|
|
@@ -599,4 +616,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
599
616
|
*/
|
|
600
617
|
declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
|
|
601
618
|
//#endregion
|
|
602
|
-
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type
|
|
619
|
+
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type SeamCall, type SeamRef, type SeamScriptEntry, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, assertAgentMachine, canReach, explorePaths, lintAgentMachine, matchesTrajectory, runSeam, simulateAgent };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { u as ChosenEvent } from "./types-
|
|
2
|
-
import { Z as AgentError, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-
|
|
3
|
-
import { d as
|
|
4
|
-
import {
|
|
1
|
+
import { u as ChosenEvent } from "./types-BgNbNKnJ.mjs";
|
|
2
|
+
import { Z as AgentError, c as AgentRequestExecutorInfo, f as AgentTextRequest, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-D-czVPYp.mjs";
|
|
3
|
+
import { c as AgentRunResult, d as AgentRuntimeOptions, o as AgentRunInit } from "./run-agent-COXXc0RW.mjs";
|
|
4
|
+
import { t as MetaOfSnapshot } from "./utils-_q7F-AZu.mjs";
|
|
5
5
|
import { AnyMachineSnapshot, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
|
|
7
7
|
//#region src/verify.d.ts
|
|
@@ -415,11 +415,13 @@ interface TrajectoryMatch {
|
|
|
415
415
|
* @example Trajectory assertions in a test
|
|
416
416
|
* ```ts
|
|
417
417
|
* const statePath: unknown[] = [];
|
|
418
|
-
* const result = await
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
418
|
+
* const result = await runToQuiescence(
|
|
419
|
+
* createAgentRuntime(machine, {
|
|
420
|
+
* executors,
|
|
421
|
+
* onTransition: (snapshot) => statePath.push(snapshot.value),
|
|
422
|
+
* }),
|
|
423
|
+
* { input },
|
|
424
|
+
* );
|
|
423
425
|
*
|
|
424
426
|
* const path = matchesTrajectory(statePath, ['prompting', 'drafting', 'sent']);
|
|
425
427
|
* expect(path.matched, JSON.stringify(path.firstMiss)).toBe(true);
|
|
@@ -435,6 +437,20 @@ interface TrajectoryMatch {
|
|
|
435
437
|
declare function matchesTrajectory(actual: readonly unknown[], expected: readonly TrajectoryItem[], options?: MatchTrajectoryOptions): TrajectoryMatch;
|
|
436
438
|
//#endregion
|
|
437
439
|
//#region src/seam.d.ts
|
|
440
|
+
/**
|
|
441
|
+
* One scripted answer in a {@link RunSeamOptions.scripts} queue: the request's
|
|
442
|
+
* output value (a string, or the object a structured request declares), or a
|
|
443
|
+
* function of the {@link AgentTextRequest} returning one.
|
|
444
|
+
*
|
|
445
|
+
* An entry is taken as the executor result (instead of the value itself)
|
|
446
|
+
* only when its OWN keys are a `result` plus, optionally, `messages`/`usage`/
|
|
447
|
+
* `raw` — that is how an entry reports token `usage`. Anything else, including
|
|
448
|
+
* an object that merely happens to have a `result` key alongside its own data
|
|
449
|
+
* (`{ result: 'draft', confidence: 0.9 }`), is the output value. For a
|
|
450
|
+
* structured request whose declared output is exactly `{ result }` (or
|
|
451
|
+
* `{ result, usage }`), wrap it once more: `{ result: { result: '…' } }`.
|
|
452
|
+
*/
|
|
453
|
+
type SeamScriptEntry = ((request: AgentTextRequest, info?: AgentRequestExecutorInfo) => unknown) | string | number | boolean | null | object;
|
|
438
454
|
/**
|
|
439
455
|
* Which model call is under test: the Nth call with this request `name` (the
|
|
440
456
|
* `setupAgent({ requests })` key, or `createTextLogic({ name })`). Name the
|
|
@@ -466,7 +482,7 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
|
|
|
466
482
|
/** 0-based index of this pause within the run. */
|
|
467
483
|
turn: number;
|
|
468
484
|
/** The `idle` result that produced the pause. */
|
|
469
|
-
result:
|
|
485
|
+
result: AgentRunResult<TMachine>;
|
|
470
486
|
}
|
|
471
487
|
/**
|
|
472
488
|
* One text call in a {@link runSeam} run's ledger, in call order — the receipt
|
|
@@ -497,7 +513,7 @@ interface SeamSlice {
|
|
|
497
513
|
}
|
|
498
514
|
/** Options for {@link runSeam}. */
|
|
499
515
|
interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
500
|
-
/** Machine input, passed straight through to `
|
|
516
|
+
/** Machine input, passed straight through to `runToQuiescence`. */
|
|
501
517
|
input?: InputFrom<TMachine>;
|
|
502
518
|
/**
|
|
503
519
|
* The call plan: scripted answers per key, consumed in order. A key is a
|
|
@@ -505,12 +521,12 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
505
521
|
* machine whose requests are named routes by name and an unnamed one routes
|
|
506
522
|
* by model.
|
|
507
523
|
*
|
|
508
|
-
* Entries follow {@link
|
|
524
|
+
* Entries follow {@link SeamScriptEntry} conventions (a value, an
|
|
509
525
|
* `{ result, usage? }` object, or a function of the request). A queue that
|
|
510
526
|
* runs dry throws; set {@link RunSeamOptions.repeatLast} to replay its last
|
|
511
527
|
* entry instead.
|
|
512
528
|
*/
|
|
513
|
-
scripts?: Record<string,
|
|
529
|
+
scripts?: Record<string, SeamScriptEntry[]>;
|
|
514
530
|
/**
|
|
515
531
|
* Replay the LAST entry of a queue once it is exhausted, so a live seam that
|
|
516
532
|
* sends the run down a longer branch still finds an answer. Off by default:
|
|
@@ -534,20 +550,21 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
534
550
|
/** Maximum idle pauses to answer before stopping. Default `12`. */
|
|
535
551
|
maxTurns?: number;
|
|
536
552
|
/**
|
|
537
|
-
* Base executors merged UNDER the seam routing — supply `decide` (
|
|
538
|
-
*
|
|
553
|
+
* Base executors merged UNDER the seam routing — supply `decide` (a plain
|
|
554
|
+
* function of the decision request, or `createAiSdkExecutors` over a mock
|
|
555
|
+
* model) for a machine that also decides.
|
|
539
556
|
* Text slots are always owned by the routing.
|
|
540
557
|
*/
|
|
541
558
|
executors?: Partial<AgentRequestExecutors>;
|
|
542
|
-
/** Passed through to `
|
|
543
|
-
actors?:
|
|
559
|
+
/** Passed through to `createAgentRuntime`: actor implementations merged onto the machine. */
|
|
560
|
+
actors?: (AgentRuntimeOptions<TMachine> & AgentRunInit<TMachine>)["actors"];
|
|
544
561
|
}
|
|
545
562
|
/** What {@link runSeam} returns: the seam's own answer, plus the run it caused. */
|
|
546
563
|
interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
547
564
|
/**
|
|
548
|
-
* The final `
|
|
565
|
+
* The final `runToQuiescence` result. `usage` accounts for the last leg.
|
|
549
566
|
*/
|
|
550
|
-
result:
|
|
567
|
+
result: AgentRunResult<TMachine>;
|
|
551
568
|
/** What the seam call returned, or `undefined` when the run never reached it. */
|
|
552
569
|
seamOutput: unknown;
|
|
553
570
|
/**
|
|
@@ -583,8 +600,8 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
583
600
|
* @example No API key: the seam is scripted too, so the whole thing runs offline.
|
|
584
601
|
* ```ts
|
|
585
602
|
* const run = await runSeam(emailDrafter, {
|
|
586
|
-
* scripts: {
|
|
587
|
-
* seam: { request: '
|
|
603
|
+
* scripts: { writeFollowUps: [followUps], emailDrafter: [draft] },
|
|
604
|
+
* seam: { request: 'writeFollowUps' },
|
|
588
605
|
* respond: ({ state }) => (state === 'prompting' ? { type: 'PROMPT_SUBMITTED', prompt } : null),
|
|
589
606
|
* });
|
|
590
607
|
*
|
|
@@ -599,4 +616,4 @@ interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
|
599
616
|
*/
|
|
600
617
|
declare function runSeam<TMachine extends AnyStateMachine>(machine: TMachine, options: RunSeamOptions<TMachine>): Promise<RunSeamResult<TMachine>>;
|
|
601
618
|
//#endregion
|
|
602
|
-
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type
|
|
619
|
+
export { type AgentLintDiagnostic, AgentLintError, type AgentLintSeverity, type AgentPathReport, type AgentPathTerminal, AgentUnknownStateError, type AssertAgentMachineOptions, type CanReachResult, type ExplorePathsOptions, type LintAgentMachineOptions, type MatchTrajectoryOptions, type RunSeamOptions, type RunSeamResult, type SeamCall, type SeamRef, type SeamScriptEntry, type SeamSlice, type SeamTurn, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, type TrajectoryEvent, type TrajectoryItem, type TrajectoryMatch, type TrajectoryMiss, assertAgentMachine, canReach, explorePaths, lintAgentMachine, matchesTrajectory, runSeam, simulateAgent };
|