@agntk/core 0.3.3 → 1.0.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/dist/advanced/index.d.ts +13 -22
- package/dist/advanced/index.d.ts.map +1 -1
- package/dist/advanced/index.js +10 -55
- package/dist/advanced/index.js.map +1 -1
- package/dist/agent.d.ts +2 -35
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +113 -111
- package/dist/agent.js.map +1 -1
- package/dist/config/defaults.d.ts +1 -5
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +1 -11
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/index.d.ts +5 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +7 -7
- package/dist/config/index.js.map +1 -1
- package/dist/config/loader.d.ts +0 -40
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +3 -80
- package/dist/config/loader.js.map +1 -1
- package/dist/config/schema.d.ts +117 -788
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +52 -63
- package/dist/config/schema.js.map +1 -1
- package/dist/constants.d.ts +0 -11
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +0 -17
- package/dist/constants.js.map +1 -1
- package/dist/evals/assertions.d.ts +0 -35
- package/dist/evals/assertions.d.ts.map +1 -1
- package/dist/evals/assertions.js +0 -51
- package/dist/evals/assertions.js.map +1 -1
- package/dist/evals/index.d.ts +0 -5
- package/dist/evals/index.d.ts.map +1 -1
- package/dist/evals/index.js +0 -5
- package/dist/evals/index.js.map +1 -1
- package/dist/evals/runner.d.ts +0 -27
- package/dist/evals/runner.d.ts.map +1 -1
- package/dist/evals/runner.js +3 -45
- package/dist/evals/runner.js.map +1 -1
- package/dist/evals/types.d.ts +0 -14
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/evals/types.js +0 -3
- package/dist/evals/types.js.map +1 -1
- package/dist/guardrails/built-ins.d.ts +0 -28
- package/dist/guardrails/built-ins.d.ts.map +1 -1
- package/dist/guardrails/built-ins.js +21 -47
- package/dist/guardrails/built-ins.js.map +1 -1
- package/dist/guardrails/index.d.ts +1 -4
- package/dist/guardrails/index.d.ts.map +1 -1
- package/dist/guardrails/index.js +1 -4
- package/dist/guardrails/index.js.map +1 -1
- package/dist/guardrails/runner.d.ts +0 -30
- package/dist/guardrails/runner.d.ts.map +1 -1
- package/dist/guardrails/runner.js +1 -46
- package/dist/guardrails/runner.js.map +1 -1
- package/dist/guardrails/types.d.ts +0 -35
- package/dist/guardrails/types.d.ts.map +1 -1
- package/dist/guardrails/types.js +4 -7
- package/dist/guardrails/types.js.map +1 -1
- package/dist/index.d.ts +4 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -31
- package/dist/index.js.map +1 -1
- package/dist/memory/loader.d.ts +0 -17
- package/dist/memory/loader.d.ts.map +1 -1
- package/dist/memory/loader.js +5 -27
- package/dist/memory/loader.js.map +1 -1
- package/dist/memory/store.d.ts +8 -16
- package/dist/memory/store.d.ts.map +1 -1
- package/dist/memory/store.js +101 -32
- package/dist/memory/store.js.map +1 -1
- package/dist/memory/types.d.ts +10 -30
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/memory/types.js +0 -6
- package/dist/memory/types.js.map +1 -1
- package/dist/models.d.ts +9 -32
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +25 -68
- package/dist/models.js.map +1 -1
- package/dist/observability/index.d.ts +0 -3
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +0 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/langfuse.d.ts +0 -38
- package/dist/observability/langfuse.d.ts.map +1 -1
- package/dist/observability/langfuse.js +6 -55
- package/dist/observability/langfuse.js.map +1 -1
- package/dist/observability/types.d.ts +0 -21
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/observability/types.js +0 -3
- package/dist/observability/types.js.map +1 -1
- package/dist/presets/tool-preset-registry.d.ts +0 -21
- package/dist/presets/tool-preset-registry.d.ts.map +1 -1
- package/dist/presets/tool-preset-registry.js +15 -34
- package/dist/presets/tool-preset-registry.js.map +1 -1
- package/dist/presets/tools.d.ts +41 -39
- package/dist/presets/tools.d.ts.map +1 -1
- package/dist/presets/tools.js +46 -40
- package/dist/presets/tools.js.map +1 -1
- package/dist/prompts/context.d.ts +0 -4
- package/dist/prompts/context.d.ts.map +1 -1
- package/dist/prompts/context.js +21 -33
- package/dist/prompts/context.js.map +1 -1
- package/dist/prompts/template.d.ts +0 -11
- package/dist/prompts/template.d.ts.map +1 -1
- package/dist/prompts/template.js +4 -14
- package/dist/prompts/template.js.map +1 -1
- package/dist/provider-resolver.d.ts +0 -29
- package/dist/provider-resolver.d.ts.map +1 -1
- package/dist/provider-resolver.js +17 -61
- package/dist/provider-resolver.js.map +1 -1
- package/dist/reflection.d.ts +0 -34
- package/dist/reflection.d.ts.map +1 -1
- package/dist/reflection.js +0 -40
- package/dist/reflection.js.map +1 -1
- package/dist/skills/index.d.ts +0 -3
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +0 -3
- package/dist/skills/index.js.map +1 -1
- package/dist/skills/loader.d.ts +0 -69
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +38 -130
- package/dist/skills/loader.js.map +1 -1
- package/dist/skills/types.d.ts +0 -36
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/skills/types.js +0 -4
- package/dist/skills/types.js.map +1 -1
- package/dist/system-detect.d.ts +0 -57
- package/dist/system-detect.d.ts.map +1 -1
- package/dist/system-detect.js +9 -114
- package/dist/system-detect.js.map +1 -1
- package/dist/tools/approval.d.ts +0 -47
- package/dist/tools/approval.d.ts.map +1 -1
- package/dist/tools/approval.js +0 -46
- package/dist/tools/approval.js.map +1 -1
- package/dist/tools/ast-grep/cli.d.ts.map +1 -1
- package/dist/tools/ast-grep/cli.js +10 -4
- package/dist/tools/ast-grep/cli.js.map +1 -1
- package/dist/tools/ast-grep/constants.d.ts.map +1 -1
- package/dist/tools/ast-grep/constants.js +7 -14
- package/dist/tools/ast-grep/constants.js.map +1 -1
- package/dist/tools/ast-grep/downloader.d.ts.map +1 -1
- package/dist/tools/ast-grep/downloader.js +1 -4
- package/dist/tools/ast-grep/downloader.js.map +1 -1
- package/dist/tools/ast-grep/index.d.ts +2 -2
- package/dist/tools/ast-grep/index.d.ts.map +1 -1
- package/dist/tools/ast-grep/index.js +1 -1
- package/dist/tools/ast-grep/index.js.map +1 -1
- package/dist/tools/ast-grep/tools.d.ts +4 -4
- package/dist/tools/ast-grep/tools.d.ts.map +1 -1
- package/dist/tools/ast-grep/tools.js +2 -8
- package/dist/tools/ast-grep/tools.js.map +1 -1
- package/dist/tools/browser/index.d.ts +4 -4
- package/dist/tools/browser/index.d.ts.map +1 -1
- package/dist/tools/browser/index.js +2 -3
- package/dist/tools/browser/index.js.map +1 -1
- package/dist/tools/browser/stream.d.ts +0 -32
- package/dist/tools/browser/stream.d.ts.map +1 -1
- package/dist/tools/browser/stream.js +0 -53
- package/dist/tools/browser/stream.js.map +1 -1
- package/dist/tools/browser/tool.d.ts +10 -15
- package/dist/tools/browser/tool.d.ts.map +1 -1
- package/dist/tools/browser/tool.js +2 -26
- package/dist/tools/browser/tool.js.map +1 -1
- package/dist/tools/browser/types.d.ts +31 -156
- package/dist/tools/browser/types.d.ts.map +1 -1
- package/dist/tools/browser/types.js +22 -17
- package/dist/tools/browser/types.js.map +1 -1
- package/dist/tools/deep-reasoning/constants.d.ts +0 -6
- package/dist/tools/deep-reasoning/constants.d.ts.map +1 -1
- package/dist/tools/deep-reasoning/constants.js +0 -6
- package/dist/tools/deep-reasoning/constants.js.map +1 -1
- package/dist/tools/deep-reasoning/engine.d.ts.map +1 -1
- package/dist/tools/deep-reasoning/engine.js +0 -1
- package/dist/tools/deep-reasoning/engine.js.map +1 -1
- package/dist/tools/deep-reasoning/index.d.ts +4 -0
- package/dist/tools/deep-reasoning/index.d.ts.map +1 -1
- package/dist/tools/deep-reasoning/index.js +4 -3
- package/dist/tools/deep-reasoning/index.js.map +1 -1
- package/dist/tools/deep-reasoning/tools.d.ts.map +1 -1
- package/dist/tools/deep-reasoning/tools.js +8 -1
- package/dist/tools/deep-reasoning/tools.js.map +1 -1
- package/dist/tools/deep-reasoning/types.d.ts +5 -30
- package/dist/tools/deep-reasoning/types.d.ts.map +1 -1
- package/dist/tools/deep-reasoning/types.js +10 -1
- package/dist/tools/deep-reasoning/types.js.map +1 -1
- package/dist/tools/file/index.d.ts +3 -5
- package/dist/tools/file/index.d.ts.map +1 -1
- package/dist/tools/file/index.js +2 -4
- package/dist/tools/file/index.js.map +1 -1
- package/dist/tools/file/tools.d.ts +8 -11
- package/dist/tools/file/tools.d.ts.map +1 -1
- package/dist/tools/file/tools.js +45 -59
- package/dist/tools/file/tools.js.map +1 -1
- package/dist/tools/glob/cli.d.ts.map +1 -1
- package/dist/tools/glob/cli.js +8 -6
- package/dist/tools/glob/cli.js.map +1 -1
- package/dist/tools/glob/tools.d.ts.map +1 -1
- package/dist/tools/glob/tools.js +7 -10
- package/dist/tools/glob/tools.js.map +1 -1
- package/dist/tools/grep/cli.d.ts.map +1 -1
- package/dist/tools/grep/cli.js +0 -2
- package/dist/tools/grep/cli.js.map +1 -1
- package/dist/tools/grep/constants.d.ts.map +1 -1
- package/dist/tools/grep/constants.js +3 -5
- package/dist/tools/grep/constants.js.map +1 -1
- package/dist/tools/grep/downloader.d.ts.map +1 -1
- package/dist/tools/grep/downloader.js +3 -3
- package/dist/tools/grep/downloader.js.map +1 -1
- package/dist/tools/grep/tools.d.ts +2 -2
- package/dist/tools/grep/tools.d.ts.map +1 -1
- package/dist/tools/grep/tools.js +8 -14
- package/dist/tools/grep/tools.js.map +1 -1
- package/dist/tools/index.d.ts +10 -11
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +9 -22
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/model-retry.d.ts +0 -40
- package/dist/tools/model-retry.d.ts.map +1 -1
- package/dist/tools/model-retry.js +1 -49
- package/dist/tools/model-retry.js.map +1 -1
- package/dist/tools/plan/constants.d.ts +0 -6
- package/dist/tools/plan/constants.d.ts.map +1 -1
- package/dist/tools/plan/constants.js +9 -6
- package/dist/tools/plan/constants.js.map +1 -1
- package/dist/tools/plan/index.d.ts +1 -1
- package/dist/tools/plan/index.d.ts.map +1 -1
- package/dist/tools/plan/index.js +1 -4
- package/dist/tools/plan/index.js.map +1 -1
- package/dist/tools/plan/tools.d.ts +2 -2
- package/dist/tools/plan/tools.d.ts.map +1 -1
- package/dist/tools/plan/tools.js +10 -11
- package/dist/tools/plan/tools.js.map +1 -1
- package/dist/tools/plan/types.d.ts +22 -32
- package/dist/tools/plan/types.d.ts.map +1 -1
- package/dist/tools/plan/types.js +11 -3
- package/dist/tools/plan/types.js.map +1 -1
- package/dist/tools/progress/index.d.ts +3 -22
- package/dist/tools/progress/index.d.ts.map +1 -1
- package/dist/tools/progress/index.js +19 -34
- package/dist/tools/progress/index.js.map +1 -1
- package/dist/tools/search-skills.d.ts +0 -23
- package/dist/tools/search-skills.d.ts.map +1 -1
- package/dist/tools/search-skills.js +3 -32
- package/dist/tools/search-skills.js.map +1 -1
- package/dist/tools/shell/background.d.ts +2 -18
- package/dist/tools/shell/background.d.ts.map +1 -1
- package/dist/tools/shell/background.js +45 -48
- package/dist/tools/shell/background.js.map +1 -1
- package/dist/tools/shell/constants.d.ts +0 -3
- package/dist/tools/shell/constants.d.ts.map +1 -1
- package/dist/tools/shell/constants.js +16 -6
- package/dist/tools/shell/constants.js.map +1 -1
- package/dist/tools/shell/index.d.ts +1 -1
- package/dist/tools/shell/index.d.ts.map +1 -1
- package/dist/tools/shell/index.js +1 -1
- package/dist/tools/shell/index.js.map +1 -1
- package/dist/tools/shell/tools.d.ts +3 -3
- package/dist/tools/shell/tools.d.ts.map +1 -1
- package/dist/tools/shell/tools.js +0 -2
- package/dist/tools/shell/tools.js.map +1 -1
- package/dist/tools/shell/types.d.ts +5 -13
- package/dist/tools/shell/types.d.ts.map +1 -1
- package/dist/tools/shell/types.js +10 -1
- package/dist/tools/shell/types.js.map +1 -1
- package/dist/tools/spawn-agent/check-agent.d.ts +45 -0
- package/dist/tools/spawn-agent/check-agent.d.ts.map +1 -0
- package/dist/tools/spawn-agent/check-agent.js +84 -0
- package/dist/tools/spawn-agent/check-agent.js.map +1 -0
- package/dist/tools/spawn-agent/index.d.ts +44 -51
- package/dist/tools/spawn-agent/index.d.ts.map +1 -1
- package/dist/tools/spawn-agent/index.js +196 -84
- package/dist/tools/spawn-agent/index.js.map +1 -1
- package/dist/tools/spawn-agent/registry.d.ts +36 -0
- package/dist/tools/spawn-agent/registry.d.ts.map +1 -0
- package/dist/tools/spawn-agent/registry.js +88 -0
- package/dist/tools/spawn-agent/registry.js.map +1 -0
- package/dist/tools/utils/errors.d.ts +2 -1
- package/dist/tools/utils/errors.d.ts.map +1 -1
- package/dist/tools/utils/errors.js +2 -1
- package/dist/tools/utils/errors.js.map +1 -1
- package/dist/tools/utils/shell.d.ts +0 -11
- package/dist/tools/utils/shell.d.ts.map +1 -1
- package/dist/tools/utils/shell.js +10 -78
- package/dist/tools/utils/shell.js.map +1 -1
- package/dist/tools/utils/tool-result.d.ts +0 -3
- package/dist/tools/utils/tool-result.d.ts.map +1 -1
- package/dist/tools/utils/tool-result.js +4 -4
- package/dist/tools/utils/tool-result.js.map +1 -1
- package/dist/tools/web-search/index.d.ts +4 -0
- package/dist/tools/web-search/index.d.ts.map +1 -0
- package/dist/tools/web-search/index.js +3 -0
- package/dist/tools/web-search/index.js.map +1 -0
- package/dist/tools/web-search/tools.d.ts +17 -0
- package/dist/tools/web-search/tools.d.ts.map +1 -0
- package/dist/tools/web-search/tools.js +81 -0
- package/dist/tools/web-search/tools.js.map +1 -0
- package/dist/tools/web-search/types.d.ts +16 -0
- package/dist/tools/web-search/types.d.ts.map +1 -0
- package/dist/tools/web-search/types.js +29 -0
- package/dist/tools/web-search/types.js.map +1 -0
- package/dist/tools/workspace-middleware.d.ts +14 -0
- package/dist/tools/workspace-middleware.d.ts.map +1 -0
- package/dist/tools/workspace-middleware.js +97 -0
- package/dist/tools/workspace-middleware.js.map +1 -0
- package/dist/types/agent.d.ts +1 -66
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +0 -6
- package/dist/types/agent.js.map +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/lifecycle.d.ts +0 -141
- package/dist/types/lifecycle.d.ts.map +1 -1
- package/dist/types/lifecycle.js +4 -54
- package/dist/types/lifecycle.js.map +1 -1
- package/dist/types/streaming.d.ts +0 -4
- package/dist/types/streaming.d.ts.map +1 -1
- package/dist/types/streaming.js +0 -4
- package/dist/types/streaming.js.map +1 -1
- package/dist/usage-limits.d.ts +0 -37
- package/dist/usage-limits.d.ts.map +1 -1
- package/dist/usage-limits.js +1 -40
- package/dist/usage-limits.js.map +1 -1
- package/dist/workflow/durable-tool.d.ts +0 -84
- package/dist/workflow/durable-tool.d.ts.map +1 -1
- package/dist/workflow/durable-tool.js +2 -104
- package/dist/workflow/durable-tool.js.map +1 -1
- package/dist/workflow/hooks.d.ts +0 -215
- package/dist/workflow/hooks.d.ts.map +1 -1
- package/dist/workflow/hooks.js +15 -221
- package/dist/workflow/hooks.js.map +1 -1
- package/dist/workflow/index.d.ts +0 -9
- package/dist/workflow/index.d.ts.map +1 -1
- package/dist/workflow/index.js +0 -12
- package/dist/workflow/index.js.map +1 -1
- package/dist/workflow/utils.d.ts +0 -24
- package/dist/workflow/utils.d.ts.map +1 -1
- package/dist/workflow/utils.js +1 -32
- package/dist/workflow/utils.js.map +1 -1
- package/dist/wrappers/best-of-n.d.ts +0 -35
- package/dist/wrappers/best-of-n.d.ts.map +1 -1
- package/dist/wrappers/best-of-n.js +4 -53
- package/dist/wrappers/best-of-n.js.map +1 -1
- package/dist/wrappers/refine-loop.d.ts +36 -0
- package/dist/wrappers/refine-loop.d.ts.map +1 -0
- package/dist/wrappers/refine-loop.js +135 -0
- package/dist/wrappers/refine-loop.js.map +1 -0
- package/package.json +14 -8
package/dist/usage-limits.d.ts
CHANGED
|
@@ -1,45 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @agntk/core - Usage Limits
|
|
3
|
-
*
|
|
4
|
-
* Token and request caps for agents. Prevents runaway loops from
|
|
5
|
-
* burning API budget by enforcing maxRequests, maxInputTokens,
|
|
6
|
-
* maxOutputTokens, and maxTotalTokens.
|
|
7
|
-
*/
|
|
8
1
|
import type { ToolSet, StepResult } from 'ai';
|
|
9
|
-
/** Usage limits for an agent run. All fields are optional — only set limits are enforced. */
|
|
10
2
|
export interface UsageLimits {
|
|
11
|
-
/** Maximum number of LLM round-trips (steps). */
|
|
12
3
|
maxRequests?: number;
|
|
13
|
-
/** Maximum cumulative input tokens across all steps. */
|
|
14
4
|
maxInputTokens?: number;
|
|
15
|
-
/** Maximum cumulative output tokens across all steps. */
|
|
16
5
|
maxOutputTokens?: number;
|
|
17
|
-
/** Maximum cumulative total tokens (input + output) across all steps. */
|
|
18
6
|
maxTotalTokens?: number;
|
|
19
7
|
}
|
|
20
|
-
/** Which limit was exceeded. */
|
|
21
8
|
export type UsageLimitType = 'maxRequests' | 'maxInputTokens' | 'maxOutputTokens' | 'maxTotalTokens';
|
|
22
|
-
/** Current usage snapshot at the time a limit was exceeded. */
|
|
23
9
|
export interface UsageSnapshot {
|
|
24
10
|
requests: number;
|
|
25
11
|
inputTokens: number;
|
|
26
12
|
outputTokens: number;
|
|
27
13
|
totalTokens: number;
|
|
28
14
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Thrown when an agent exceeds a configured usage limit.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* try {
|
|
35
|
-
* const result = await agent.stream({ prompt: 'do something' });
|
|
36
|
-
* } catch (error) {
|
|
37
|
-
* if (error instanceof UsageLimitExceeded) {
|
|
38
|
-
* console.log(`Hit ${error.limitType}: ${error.currentValue}/${error.limitValue}`);
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
15
|
export declare class UsageLimitExceeded extends Error {
|
|
44
16
|
readonly name = "UsageLimitExceeded";
|
|
45
17
|
readonly limitType: UsageLimitType;
|
|
@@ -48,15 +20,6 @@ export declare class UsageLimitExceeded extends Error {
|
|
|
48
20
|
readonly usage: UsageSnapshot;
|
|
49
21
|
constructor(limitType: UsageLimitType, limitValue: number, currentValue: number, usage: UsageSnapshot);
|
|
50
22
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Create a StopCondition that checks usage limits after each step.
|
|
53
|
-
*
|
|
54
|
-
* Compatible with AI SDK's `stopWhen` array — combine with `stepCountIs()`.
|
|
55
|
-
*
|
|
56
|
-
* When a limit is exceeded, the condition throws `UsageLimitExceeded`
|
|
57
|
-
* rather than returning `true`, because returning `true` would silently
|
|
58
|
-
* stop the agent. Throwing gives the caller a clear signal with details.
|
|
59
|
-
*/
|
|
60
23
|
export declare function usageLimitStop<TOOLS extends ToolSet>(limits: UsageLimits): (options: {
|
|
61
24
|
steps: Array<StepResult<TOOLS>>;
|
|
62
25
|
}) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-limits.d.ts","sourceRoot":"","sources":["../src/usage-limits.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"usage-limits.d.ts","sourceRoot":"","sources":["../src/usage-limits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,gBAAgB,GAChB,iBAAiB,GACjB,gBAAgB,CAAC;AAErB,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,SAAkB,IAAI,wBAAwB;IAC9C,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;gBAG5B,SAAS,EAAE,cAAc,EACzB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,aAAa;CAQvB;AAED,wBAAgB,cAAc,CAAC,KAAK,SAAS,OAAO,EAClD,MAAM,EAAE,WAAW,GAClB,CAAC,OAAO,EAAE;IAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;CAAE,KAAK,OAAO,CAqC3D"}
|
package/dist/usage-limits.js
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @agntk/core - Usage Limits
|
|
3
|
-
*
|
|
4
|
-
* Token and request caps for agents. Prevents runaway loops from
|
|
5
|
-
* burning API budget by enforcing maxRequests, maxInputTokens,
|
|
6
|
-
* maxOutputTokens, and maxTotalTokens.
|
|
7
|
-
*/
|
|
8
|
-
// ============================================================================
|
|
9
|
-
// Error
|
|
10
|
-
// ============================================================================
|
|
11
|
-
/**
|
|
12
|
-
* Thrown when an agent exceeds a configured usage limit.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* try {
|
|
17
|
-
* const result = await agent.stream({ prompt: 'do something' });
|
|
18
|
-
* } catch (error) {
|
|
19
|
-
* if (error instanceof UsageLimitExceeded) {
|
|
20
|
-
* console.log(`Hit ${error.limitType}: ${error.currentValue}/${error.limitValue}`);
|
|
21
|
-
* }
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
1
|
export class UsageLimitExceeded extends Error {
|
|
26
2
|
name = 'UsageLimitExceeded';
|
|
27
3
|
limitType;
|
|
@@ -36,18 +12,6 @@ export class UsageLimitExceeded extends Error {
|
|
|
36
12
|
this.usage = usage;
|
|
37
13
|
}
|
|
38
14
|
}
|
|
39
|
-
// ============================================================================
|
|
40
|
-
// Stop Condition Factory
|
|
41
|
-
// ============================================================================
|
|
42
|
-
/**
|
|
43
|
-
* Create a StopCondition that checks usage limits after each step.
|
|
44
|
-
*
|
|
45
|
-
* Compatible with AI SDK's `stopWhen` array — combine with `stepCountIs()`.
|
|
46
|
-
*
|
|
47
|
-
* When a limit is exceeded, the condition throws `UsageLimitExceeded`
|
|
48
|
-
* rather than returning `true`, because returning `true` would silently
|
|
49
|
-
* stop the agent. Throwing gives the caller a clear signal with details.
|
|
50
|
-
*/
|
|
51
15
|
export function usageLimitStop(limits) {
|
|
52
16
|
return ({ steps }) => {
|
|
53
17
|
const usage = computeUsage(steps);
|
|
@@ -63,12 +27,9 @@ export function usageLimitStop(limits) {
|
|
|
63
27
|
if (limits.maxTotalTokens !== undefined && usage.totalTokens > limits.maxTotalTokens) {
|
|
64
28
|
throw new UsageLimitExceeded('maxTotalTokens', limits.maxTotalTokens, usage.totalTokens, usage);
|
|
65
29
|
}
|
|
66
|
-
return false;
|
|
30
|
+
return false;
|
|
67
31
|
};
|
|
68
32
|
}
|
|
69
|
-
// ============================================================================
|
|
70
|
-
// Helpers
|
|
71
|
-
// ============================================================================
|
|
72
33
|
function computeUsage(steps) {
|
|
73
34
|
let inputTokens = 0;
|
|
74
35
|
let outputTokens = 0;
|
package/dist/usage-limits.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-limits.js","sourceRoot":"","sources":["../src/usage-limits.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usage-limits.js","sourceRoot":"","sources":["../src/usage-limits.ts"],"names":[],"mappings":"AAyBA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACzB,IAAI,GAAG,oBAAoB,CAAC;IACrC,SAAS,CAAiB;IAC1B,UAAU,CAAS;IACnB,YAAY,CAAS;IACrB,KAAK,CAAgB;IAE9B,YACE,SAAyB,EACzB,UAAkB,EAClB,YAAoB,EACpB,KAAoB;QAEpB,KAAK,CAAC,yBAAyB,SAAS,MAAM,YAAY,YAAY,UAAU,GAAG,CAAC,CAAC;QACrF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAC5B,MAAmB;IAEnB,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAElC,IAAI,MAAM,CAAC,WAAW,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YAC5E,MAAM,IAAI,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QACzF,CAAC;QAED,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;YACrF,MAAM,IAAI,kBAAkB,CAC1B,gBAAgB,EAChB,MAAM,CAAC,cAAc,EACrB,KAAK,CAAC,WAAW,EACjB,KAAK,CACN,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,IAAI,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;YACxF,MAAM,IAAI,kBAAkB,CAC1B,iBAAiB,EACjB,MAAM,CAAC,eAAe,EACtB,KAAK,CAAC,YAAY,EAClB,KAAK,CACN,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;YACrF,MAAM,IAAI,kBAAkB,CAC1B,gBAAgB,EAChB,MAAM,CAAC,cAAc,EACrB,KAAK,CAAC,WAAW,EACjB,KAAK,CACN,CAAC;QACJ,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAwB,KAA+B;IAC1E,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE,WAAW,IAAI,CAAC,CAAC;QAC5C,YAAY,IAAI,IAAI,CAAC,KAAK,EAAE,YAAY,IAAI,CAAC,CAAC;QAC9C,WAAW,IAAI,IAAI,CAAC,KAAK,EAAE,WAAW,IAAI,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,MAAM;QACtB,WAAW;QACX,YAAY;QACZ,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
|
@@ -1,103 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @agntk/core - Durable Tool Wrapper
|
|
3
|
-
*
|
|
4
|
-
* Wraps tools with durability directives for crash recovery.
|
|
5
|
-
* Uses the Workflow DevKit's "use step" directive to checkpoint tool executions.
|
|
6
|
-
* Each tool step gets a descriptive name for observability in the workflow inspector.
|
|
7
|
-
*
|
|
8
|
-
* @see https://useworkflow.dev
|
|
9
|
-
*/
|
|
10
1
|
import type { Tool } from 'ai';
|
|
11
2
|
type ToolSet = Record<string, Tool>;
|
|
12
3
|
export interface DurabilityConfig {
|
|
13
|
-
/** Enable durability for this tool. Default: true */
|
|
14
4
|
enabled?: boolean;
|
|
15
|
-
/** Whether this tool can run independently in parallel. Default: false */
|
|
16
5
|
independent?: boolean;
|
|
17
|
-
/** Number of retry attempts on failure. Default: 3 */
|
|
18
6
|
retryCount?: number;
|
|
19
|
-
/** Timeout duration string (e.g., "30s", "5m"). Default: "5m" */
|
|
20
7
|
timeout?: string;
|
|
21
|
-
/** Custom step name for the workflow inspector. Default: "tool-exec-{toolName}" */
|
|
22
8
|
stepName?: string;
|
|
23
9
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Wrap a single tool with durability directives.
|
|
26
|
-
*
|
|
27
|
-
* When wrapped, the tool's execute function uses the "use step" directive
|
|
28
|
-
* to create a checkpoint. If the process crashes, the workflow runtime
|
|
29
|
-
* resumes from the last checkpoint.
|
|
30
|
-
*
|
|
31
|
-
* Each wrapped tool gets a descriptive step name for the workflow inspector:
|
|
32
|
-
* - Default: "tool-exec-{toolName}"
|
|
33
|
-
* - Custom via `config.stepName`
|
|
34
|
-
*
|
|
35
|
-
* @param tool - The tool to wrap
|
|
36
|
-
* @param config - Durability configuration
|
|
37
|
-
* @param toolName - Name of the tool (used for step naming)
|
|
38
|
-
* @returns Wrapped tool with durability enabled
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const durableReadFile = wrapToolAsDurableStep(readFileTool, {
|
|
43
|
-
* retryCount: 3,
|
|
44
|
-
* timeout: '30s',
|
|
45
|
-
* }, 'read_file');
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
10
|
export declare function wrapToolAsDurableStep(tool: Tool, config?: DurabilityConfig, toolName?: string): Tool;
|
|
49
|
-
/**
|
|
50
|
-
* Wrap all tools in a set with durability directives.
|
|
51
|
-
* Each tool gets a step name based on its key in the record.
|
|
52
|
-
*
|
|
53
|
-
* @param tools - Record of tools to wrap
|
|
54
|
-
* @param config - Durability configuration applied to all tools
|
|
55
|
-
* @returns Record of wrapped tools
|
|
56
|
-
*
|
|
57
|
-
* @example
|
|
58
|
-
* ```typescript
|
|
59
|
-
* const durableTools = wrapToolsAsDurable(myTools, {
|
|
60
|
-
* retryCount: 3,
|
|
61
|
-
* timeout: '5m',
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
11
|
export declare function wrapToolsAsDurable(tools: ToolSet, config?: DurabilityConfig): ToolSet;
|
|
66
|
-
/**
|
|
67
|
-
* Wrap only specified tools with durability, leaving others unchanged.
|
|
68
|
-
*
|
|
69
|
-
* @param tools - All tools
|
|
70
|
-
* @param toolNames - Names of tools to wrap
|
|
71
|
-
* @param config - Durability configuration
|
|
72
|
-
* @returns Tools with selective durability applied
|
|
73
|
-
*/
|
|
74
12
|
export declare function wrapSelectedToolsAsDurable(tools: ToolSet, toolNames: string[], config?: DurabilityConfig): ToolSet;
|
|
75
|
-
/**
|
|
76
|
-
* Wrap a tool as an independent durable step.
|
|
77
|
-
*
|
|
78
|
-
* Independent steps can be executed in parallel with other independent steps.
|
|
79
|
-
* The workflow runtime optimizes by running these concurrently.
|
|
80
|
-
*
|
|
81
|
-
* @param tool - The tool to wrap
|
|
82
|
-
* @param toolName - Name of the tool (used for step naming)
|
|
83
|
-
* @returns Wrapped tool marked as independent
|
|
84
|
-
*/
|
|
85
13
|
export declare function wrapToolAsIndependentStep(tool: Tool, toolName?: string): Tool;
|
|
86
|
-
/**
|
|
87
|
-
* Symbol for storing durability metadata on tools.
|
|
88
|
-
*/
|
|
89
14
|
export declare const DURABILITY_CONFIG: unique symbol;
|
|
90
|
-
/**
|
|
91
|
-
* Get durability configuration from a tool (if set).
|
|
92
|
-
*/
|
|
93
15
|
export declare function getDurabilityConfig(tool: Tool): DurabilityConfig | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Set durability configuration on a tool.
|
|
96
|
-
*/
|
|
97
16
|
export declare function setDurabilityConfig(tool: Tool, config: DurabilityConfig): Tool;
|
|
98
|
-
/**
|
|
99
|
-
* Get the step name assigned to a durable tool.
|
|
100
|
-
*/
|
|
101
17
|
export declare function getStepName(tool: Tool): string | undefined;
|
|
102
18
|
export {};
|
|
103
19
|
//# sourceMappingURL=durable-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-tool.d.ts","sourceRoot":"","sources":["../../src/workflow/durable-tool.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"durable-tool.d.ts","sourceRoot":"","sources":["../../src/workflow/durable-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAK/B,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAEpC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,IAAI,EACV,MAAM,GAAE,gBAAqB,EAC7B,QAAQ,CAAC,EAAE,MAAM,GAChB,IAAI,CA4CN;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,GAAE,gBAAqB,GAAG,OAAO,CAMzF;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,GAAE,gBAAqB,GAC5B,OAAO,CAaT;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAE7E;AAED,eAAO,MAAM,iBAAiB,eAA6B,CAAC;AAE5D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,gBAAgB,GAAG,SAAS,CAG5E;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAI9E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAE1D"}
|
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @agntk/core - Durable Tool Wrapper
|
|
3
|
-
*
|
|
4
|
-
* Wraps tools with durability directives for crash recovery.
|
|
5
|
-
* Uses the Workflow DevKit's "use step" directive to checkpoint tool executions.
|
|
6
|
-
* Each tool step gets a descriptive name for observability in the workflow inspector.
|
|
7
|
-
*
|
|
8
|
-
* @see https://useworkflow.dev
|
|
9
|
-
*/
|
|
10
1
|
import { createLogger } from '@agntk/logger';
|
|
11
2
|
const log = createLogger('@agntk/core:workflow:tool');
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// Single Tool Wrapper
|
|
14
|
-
// ============================================================================
|
|
15
|
-
/**
|
|
16
|
-
* Wrap a single tool with durability directives.
|
|
17
|
-
*
|
|
18
|
-
* When wrapped, the tool's execute function uses the "use step" directive
|
|
19
|
-
* to create a checkpoint. If the process crashes, the workflow runtime
|
|
20
|
-
* resumes from the last checkpoint.
|
|
21
|
-
*
|
|
22
|
-
* Each wrapped tool gets a descriptive step name for the workflow inspector:
|
|
23
|
-
* - Default: "tool-exec-{toolName}"
|
|
24
|
-
* - Custom via `config.stepName`
|
|
25
|
-
*
|
|
26
|
-
* @param tool - The tool to wrap
|
|
27
|
-
* @param config - Durability configuration
|
|
28
|
-
* @param toolName - Name of the tool (used for step naming)
|
|
29
|
-
* @returns Wrapped tool with durability enabled
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const durableReadFile = wrapToolAsDurableStep(readFileTool, {
|
|
34
|
-
* retryCount: 3,
|
|
35
|
-
* timeout: '30s',
|
|
36
|
-
* }, 'read_file');
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
3
|
export function wrapToolAsDurableStep(tool, config = {}, toolName) {
|
|
40
4
|
const { enabled = true } = config;
|
|
41
5
|
if (!enabled) {
|
|
@@ -51,10 +15,7 @@ export function wrapToolAsDurableStep(tool, config = {}, toolName) {
|
|
|
51
15
|
...tool,
|
|
52
16
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
17
|
execute: async (input, options) => {
|
|
54
|
-
|
|
55
|
-
// When the workflow resumes after a crash, it skips to this point
|
|
56
|
-
// and returns the cached result instead of re-executing.
|
|
57
|
-
"use step";
|
|
18
|
+
'use step';
|
|
58
19
|
log.debug(`Executing durable step: ${stepName}`, {
|
|
59
20
|
stepName,
|
|
60
21
|
retryCount: config.retryCount,
|
|
@@ -69,52 +30,17 @@ export function wrapToolAsDurableStep(tool, config = {}, toolName) {
|
|
|
69
30
|
log.error(`Durable step failed: ${stepName}`, {
|
|
70
31
|
error: error instanceof Error ? error.message : String(error),
|
|
71
32
|
});
|
|
72
|
-
// Re-throw to let the workflow runtime handle retries
|
|
73
33
|
throw error;
|
|
74
34
|
}
|
|
75
35
|
},
|
|
76
36
|
};
|
|
77
|
-
// Store step name and config as metadata
|
|
78
37
|
setDurabilityConfig(wrappedTool, { ...config, stepName });
|
|
79
38
|
return wrappedTool;
|
|
80
39
|
}
|
|
81
|
-
// ============================================================================
|
|
82
|
-
// Batch Tool Wrapper
|
|
83
|
-
// ============================================================================
|
|
84
|
-
/**
|
|
85
|
-
* Wrap all tools in a set with durability directives.
|
|
86
|
-
* Each tool gets a step name based on its key in the record.
|
|
87
|
-
*
|
|
88
|
-
* @param tools - Record of tools to wrap
|
|
89
|
-
* @param config - Durability configuration applied to all tools
|
|
90
|
-
* @returns Record of wrapped tools
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* const durableTools = wrapToolsAsDurable(myTools, {
|
|
95
|
-
* retryCount: 3,
|
|
96
|
-
* timeout: '5m',
|
|
97
|
-
* });
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
40
|
export function wrapToolsAsDurable(tools, config = {}) {
|
|
101
41
|
log.debug('Wrapping all tools as durable', { count: Object.keys(tools).length });
|
|
102
|
-
return Object.fromEntries(Object.entries(tools).map(([name, tool]) => [
|
|
103
|
-
name,
|
|
104
|
-
wrapToolAsDurableStep(tool, config, name),
|
|
105
|
-
]));
|
|
42
|
+
return Object.fromEntries(Object.entries(tools).map(([name, tool]) => [name, wrapToolAsDurableStep(tool, config, name)]));
|
|
106
43
|
}
|
|
107
|
-
// ============================================================================
|
|
108
|
-
// Selective Wrapping
|
|
109
|
-
// ============================================================================
|
|
110
|
-
/**
|
|
111
|
-
* Wrap only specified tools with durability, leaving others unchanged.
|
|
112
|
-
*
|
|
113
|
-
* @param tools - All tools
|
|
114
|
-
* @param toolNames - Names of tools to wrap
|
|
115
|
-
* @param config - Durability configuration
|
|
116
|
-
* @returns Tools with selective durability applied
|
|
117
|
-
*/
|
|
118
44
|
export function wrapSelectedToolsAsDurable(tools, toolNames, config = {}) {
|
|
119
45
|
const nameSet = new Set(toolNames);
|
|
120
46
|
log.debug('Selectively wrapping tools as durable', {
|
|
@@ -126,47 +52,19 @@ export function wrapSelectedToolsAsDurable(tools, toolNames, config = {}) {
|
|
|
126
52
|
nameSet.has(name) ? wrapToolAsDurableStep(tool, config, name) : tool,
|
|
127
53
|
]));
|
|
128
54
|
}
|
|
129
|
-
// ============================================================================
|
|
130
|
-
// Independent Step Wrapper
|
|
131
|
-
// ============================================================================
|
|
132
|
-
/**
|
|
133
|
-
* Wrap a tool as an independent durable step.
|
|
134
|
-
*
|
|
135
|
-
* Independent steps can be executed in parallel with other independent steps.
|
|
136
|
-
* The workflow runtime optimizes by running these concurrently.
|
|
137
|
-
*
|
|
138
|
-
* @param tool - The tool to wrap
|
|
139
|
-
* @param toolName - Name of the tool (used for step naming)
|
|
140
|
-
* @returns Wrapped tool marked as independent
|
|
141
|
-
*/
|
|
142
55
|
export function wrapToolAsIndependentStep(tool, toolName) {
|
|
143
56
|
return wrapToolAsDurableStep(tool, { independent: true }, toolName);
|
|
144
57
|
}
|
|
145
|
-
// ============================================================================
|
|
146
|
-
// Durability Metadata
|
|
147
|
-
// ============================================================================
|
|
148
|
-
/**
|
|
149
|
-
* Symbol for storing durability metadata on tools.
|
|
150
|
-
*/
|
|
151
58
|
export const DURABILITY_CONFIG = Symbol('durabilityConfig');
|
|
152
|
-
/**
|
|
153
|
-
* Get durability configuration from a tool (if set).
|
|
154
|
-
*/
|
|
155
59
|
export function getDurabilityConfig(tool) {
|
|
156
60
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
61
|
return tool[DURABILITY_CONFIG];
|
|
158
62
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Set durability configuration on a tool.
|
|
161
|
-
*/
|
|
162
63
|
export function setDurabilityConfig(tool, config) {
|
|
163
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
164
65
|
tool[DURABILITY_CONFIG] = config;
|
|
165
66
|
return tool;
|
|
166
67
|
}
|
|
167
|
-
/**
|
|
168
|
-
* Get the step name assigned to a durable tool.
|
|
169
|
-
*/
|
|
170
68
|
export function getStepName(tool) {
|
|
171
69
|
return getDurabilityConfig(tool)?.stepName;
|
|
172
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-tool.js","sourceRoot":"","sources":["../../src/workflow/durable-tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"durable-tool.js","sourceRoot":"","sources":["../../src/workflow/durable-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,GAAG,GAA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