@pencil-agent/nano-pencil 2.0.0-beta.2 → 2.0.0-beta.4
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/build-meta.json +3 -3
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-continuations.js +60 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-stream-events.js +55 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-results.js +137 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop-tool-summaries.js +64 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +913 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.d.ts +9 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent-run-result.js +32 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.d.ts +215 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/agent.js +522 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/errors.js +146 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/index.js +19 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.d.ts +91 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/proxy.js +279 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.d.ts +15 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +625 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-streaming-tool-executor.js +189 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-tool-orchestration.js +319 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.d.ts +417 -0
- package/dist/node_modules/@pencil-agent/agent-core/dist/types.js +13 -0
- package/dist/node_modules/@pencil-agent/agent-core/package.json +28 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/api-registry.js +152 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.d.ts +2 -0
- package/dist/node_modules/@pencil-agent/ai/dist/cli.js +121 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.d.ts +1 -0
- package/dist/node_modules/@pencil-agent/ai/dist/config-path.js +17 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.d.ts +94 -0
- package/dist/node_modules/@pencil-agent/ai/dist/debug-logger.js +218 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env-api-keys.js +107 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/env.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/events.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/ai/dist/index.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/json.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.d.ts +15159 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.generated.js +14928 -0
- package/dist/node_modules/@pencil-agent/ai/dist/models.js +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.d.ts +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/overflow.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/amazon-bedrock.js +606 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/anthropic.js +737 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.d.ts +21 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/azure-openai-responses.js +193 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/github-copilot-headers.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.d.ts +79 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-gemini-cli.js +753 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.d.ts +70 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-shared.js +311 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google-vertex.js +380 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/google.js +360 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-codex-responses.js +704 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.d.ts +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-completions.js +870 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses-shared.js +432 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.d.ts +19 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/openai-responses.js +207 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/register-builtins.js +86 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/simple-options.js +40 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/providers/transform-messages.js +175 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.d.ts +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/registry.js +8 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.d.ts +10 -0
- package/dist/node_modules/@pencil-agent/ai/dist/schema.js +9 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.d.ts +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/stream.js +324 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.d.ts +306 -0
- package/dist/node_modules/@pencil-agent/ai/dist/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream-types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/event-stream.js +98 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.d.ts +13 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/http-proxy.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.d.ts +14 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/json-parse.js +34 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/anthropic.js +109 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.d.ts +12 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/decode-credential.js +25 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.d.ts +35 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/github-copilot.js +286 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-antigravity.js +378 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.d.ts +31 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/google-gemini-cli.js +483 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.d.ts +60 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/index.js +131 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.d.ts +39 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/openai-codex.js +385 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/pkce.js +36 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.d.ts +52 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/oauth/types.js +7 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.d.ts +57 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/overflow.js +120 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.d.ts +16 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/sanitize-unicode.js +20 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/typebox-helpers.js +26 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.d.ts +23 -0
- package/dist/node_modules/@pencil-agent/ai/dist/utils/validation.js +78 -0
- package/dist/node_modules/@pencil-agent/ai/package.json +106 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.d.ts +62 -0
- package/dist/node_modules/@pencil-agent/tui/dist/autocomplete.js +624 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/box.js +109 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.d.ts +27 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/cancellable-loader.js +40 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.d.ts +218 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/editor.js +1697 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/image.js +74 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.d.ts +42 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/input.js +438 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.d.ts +26 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/loader.js +54 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.d.ts +100 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/markdown.js +634 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.d.ts +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/select-list.js +157 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.d.ts +55 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/settings-list.js +190 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.d.ts +17 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/spacer.js +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.d.ts +24 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/text.js +94 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.d.ts +18 -0
- package/dist/node_modules/@pencil-agent/tui/dist/components/truncated-text.js +56 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.d.ts +51 -0
- package/dist/node_modules/@pencil-agent/tui/dist/editor-component.js +7 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.d.ts +32 -0
- package/dist/node_modules/@pencil-agent/tui/dist/fuzzy.js +152 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.d.ts +28 -0
- package/dist/node_modules/@pencil-agent/tui/dist/index.js +37 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.d.ts +44 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keybindings.js +119 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.d.ts +149 -0
- package/dist/node_modules/@pencil-agent/tui/dist/keys.js +948 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.d.ts +33 -0
- package/dist/node_modules/@pencil-agent/tui/dist/kill-ring.js +49 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.d.ts +38 -0
- package/dist/node_modules/@pencil-agent/tui/dist/stdin-buffer.js +307 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.d.ts +73 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal-image.js +287 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.d.ts +86 -0
- package/dist/node_modules/@pencil-agent/tui/dist/terminal.js +266 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.d.ts +219 -0
- package/dist/node_modules/@pencil-agent/tui/dist/tui.js +1001 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.d.ts +22 -0
- package/dist/node_modules/@pencil-agent/tui/dist/undo-stack.js +30 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.d.ts +83 -0
- package/dist/node_modules/@pencil-agent/tui/dist/utils.js +811 -0
- package/dist/node_modules/@pencil-agent/tui/package.json +37 -0
- package/package.json +3 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [WHO]: Provides resolveAgentRunLoopFramework(), buildAgentRunPolicy()
|
|
3
|
+
* [FROM]: Depends on AgentLoopConfig, AgentRunPolicy, normalizeAgentLoopFramework
|
|
4
|
+
* [TO]: Consumed by standard and structured-adaptive agent loops
|
|
5
|
+
* [HERE]: core/lib/agent-core/src/agent-run-result.ts - shared result telemetry helpers
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentLoopConfig, AgentLoopFramework, AgentRunPolicy } from "./types.js";
|
|
8
|
+
export declare function resolveAgentRunLoopFramework(config: AgentLoopConfig): AgentLoopFramework;
|
|
9
|
+
export declare function buildAgentRunPolicy(config: AgentLoopConfig): AgentRunPolicy;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { normalizeAgentLoopFramework } from "./types.js";
|
|
2
|
+
export function resolveAgentRunLoopFramework(config) {
|
|
3
|
+
return normalizeAgentLoopFramework(config.loopFramework) ?? "standard";
|
|
4
|
+
}
|
|
5
|
+
export function buildAgentRunPolicy(config) {
|
|
6
|
+
const policy = {};
|
|
7
|
+
if (config.maxModelErrorRecoveryAttempts !== undefined) {
|
|
8
|
+
policy.maxModelErrorRecoveryAttempts = config.maxModelErrorRecoveryAttempts;
|
|
9
|
+
}
|
|
10
|
+
if (config.maxOutputTokenRecoveryAttempts !== undefined) {
|
|
11
|
+
policy.maxOutputTokenRecoveryAttempts = config.maxOutputTokenRecoveryAttempts;
|
|
12
|
+
}
|
|
13
|
+
if (config.outputTokenBudget !== undefined) {
|
|
14
|
+
policy.outputTokenBudget = { ...config.outputTokenBudget };
|
|
15
|
+
}
|
|
16
|
+
if (config.maxStopHookContinuations !== undefined) {
|
|
17
|
+
policy.maxStopHookContinuations = config.maxStopHookContinuations;
|
|
18
|
+
}
|
|
19
|
+
if (config.maxToolConcurrency !== undefined) {
|
|
20
|
+
policy.maxToolConcurrency = config.maxToolConcurrency;
|
|
21
|
+
}
|
|
22
|
+
if (config.maxToolResultBatchSizeChars !== undefined) {
|
|
23
|
+
policy.maxToolResultBatchSizeChars = config.maxToolResultBatchSizeChars;
|
|
24
|
+
}
|
|
25
|
+
if (config.maxTurnsPerPrompt !== undefined) {
|
|
26
|
+
policy.maxTurnsPerPrompt = config.maxTurnsPerPrompt;
|
|
27
|
+
}
|
|
28
|
+
if (config.maxToolCallsPerPrompt !== undefined) {
|
|
29
|
+
policy.maxToolCallsPerPrompt = config.maxToolCallsPerPrompt;
|
|
30
|
+
}
|
|
31
|
+
return policy;
|
|
32
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent class that uses the agent-loop directly.
|
|
3
|
+
* No transport abstraction - calls streamSimple via the loop.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* [WHO]: AgentOptions, Agent, and loop policy option plumbing
|
|
7
|
+
* [FROM]: Depends on ./agent-loop.js and ./structured-adaptive-agent-loop.js
|
|
8
|
+
* [TO]: Consumed by core/lib/agent-core/src/index.ts
|
|
9
|
+
* [HERE]: core/lib/agent-core/src/agent.ts -
|
|
10
|
+
*/
|
|
11
|
+
import { type ImageContent, type Message, type Model, type ThinkingBudgets, type Transport } from "@pencil-agent/ai/types";
|
|
12
|
+
import type { AgentEvent, AgentLoopFramework, AgentLoopFrameworkInput, AgentLoopConfig, AgentMessage, AgentState, AgentTool, StreamFn, ThinkingLevel } from "./types.js";
|
|
13
|
+
export interface AgentOptions {
|
|
14
|
+
initialState?: Partial<AgentState>;
|
|
15
|
+
/**
|
|
16
|
+
* Converts AgentMessage[] to LLM-compatible Message[] before each LLM call.
|
|
17
|
+
* Default filters to user/assistant/toolResult and converts attachments.
|
|
18
|
+
*/
|
|
19
|
+
convertToLlm?: (messages: AgentMessage[]) => Message[] | Promise<Message[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Optional transform applied to context before convertToLlm.
|
|
22
|
+
* Use for context pruning, injecting external context, etc.
|
|
23
|
+
*/
|
|
24
|
+
transformContext?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<AgentMessage[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Steering mode: "all" = send all steering messages at once, "one-at-a-time" = one per turn
|
|
27
|
+
*/
|
|
28
|
+
steeringMode?: "all" | "one-at-a-time";
|
|
29
|
+
/**
|
|
30
|
+
* Follow-up mode: "all" = send all follow-up messages at once, "one-at-a-time" = one per turn
|
|
31
|
+
*/
|
|
32
|
+
followUpMode?: "all" | "one-at-a-time";
|
|
33
|
+
/**
|
|
34
|
+
* Custom stream function (for proxy backends, etc.). Default uses streamSimple.
|
|
35
|
+
*/
|
|
36
|
+
streamFn?: StreamFn;
|
|
37
|
+
/**
|
|
38
|
+
* Optional session identifier forwarded to LLM providers.
|
|
39
|
+
* Used by providers that support session-based caching (e.g., OpenAI Codex).
|
|
40
|
+
*/
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Resolves an API key dynamically for each LLM call.
|
|
44
|
+
* Useful for expiring tokens (e.g., GitHub Copilot OAuth).
|
|
45
|
+
*/
|
|
46
|
+
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Custom token budgets for thinking levels (token-based providers only).
|
|
49
|
+
*/
|
|
50
|
+
thinkingBudgets?: ThinkingBudgets;
|
|
51
|
+
/**
|
|
52
|
+
* Preferred transport for providers that support multiple transports.
|
|
53
|
+
*/
|
|
54
|
+
transport?: Transport;
|
|
55
|
+
/**
|
|
56
|
+
* Maximum delay in milliseconds to wait for a retry when the server requests a long wait.
|
|
57
|
+
* If the server's requested delay exceeds this value, the request fails immediately,
|
|
58
|
+
* allowing higher-level retry logic to handle it with user visibility.
|
|
59
|
+
* Default: 60000 (60 seconds). Set to 0 to disable the cap.
|
|
60
|
+
*/
|
|
61
|
+
maxRetryDelayMs?: number;
|
|
62
|
+
/**
|
|
63
|
+
* Force a loop framework for all models in this Agent.
|
|
64
|
+
* When omitted, the current model's `agentLoopFramework` setting is used.
|
|
65
|
+
*/
|
|
66
|
+
agentLoopFramework?: AgentLoopFrameworkInput;
|
|
67
|
+
/**
|
|
68
|
+
* Optional tool permission gate used by loop execution.
|
|
69
|
+
*/
|
|
70
|
+
canUseTool?: AgentLoopConfig["canUseTool"];
|
|
71
|
+
/**
|
|
72
|
+
* Optional aggregate tool-result batch budget used by loop execution.
|
|
73
|
+
*/
|
|
74
|
+
maxToolResultBatchSizeChars?: AgentLoopConfig["maxToolResultBatchSizeChars"];
|
|
75
|
+
/**
|
|
76
|
+
* Optional in-loop model error recovery hook used by loop execution.
|
|
77
|
+
*/
|
|
78
|
+
recoverModelError?: AgentLoopConfig["recoverModelError"];
|
|
79
|
+
/** Maximum in-loop model error recoveries per prompt. */
|
|
80
|
+
maxModelErrorRecoveryAttempts?: number;
|
|
81
|
+
/** Maximum automatic output-token recovery turns per prompt. */
|
|
82
|
+
maxOutputTokenRecoveryAttempts?: number;
|
|
83
|
+
/** Optional target for automatic continuation when output is under-complete. */
|
|
84
|
+
outputTokenBudget?: AgentLoopConfig["outputTokenBudget"];
|
|
85
|
+
/** Optional stop hook for validation/correction continuation turns. */
|
|
86
|
+
runStopHooks?: AgentLoopConfig["runStopHooks"];
|
|
87
|
+
/** Maximum stop-hook continuation turns per prompt. */
|
|
88
|
+
maxStopHookContinuations?: number;
|
|
89
|
+
/** Optional non-blocking summary hook for completed tool batches. */
|
|
90
|
+
createToolUseSummary?: AgentLoopConfig["createToolUseSummary"];
|
|
91
|
+
/** Maximum concurrency for concurrency-safe tool batches. */
|
|
92
|
+
maxToolConcurrency?: number;
|
|
93
|
+
/** Maximum assistant turns allowed for one prompt/continue loop. */
|
|
94
|
+
maxTurnsPerPrompt?: number;
|
|
95
|
+
/** Maximum tool calls allowed for one prompt/continue loop. */
|
|
96
|
+
maxToolCallsPerPrompt?: number;
|
|
97
|
+
}
|
|
98
|
+
export type AgentLoopPolicyOptions = Pick<AgentOptions, "canUseTool" | "maxToolResultBatchSizeChars" | "recoverModelError" | "maxModelErrorRecoveryAttempts" | "maxOutputTokenRecoveryAttempts" | "outputTokenBudget" | "runStopHooks" | "maxStopHookContinuations" | "createToolUseSummary" | "maxToolConcurrency" | "maxTurnsPerPrompt" | "maxToolCallsPerPrompt">;
|
|
99
|
+
export declare class Agent {
|
|
100
|
+
private _state;
|
|
101
|
+
private listeners;
|
|
102
|
+
private abortController?;
|
|
103
|
+
private convertToLlm;
|
|
104
|
+
private transformContext?;
|
|
105
|
+
private steeringQueue;
|
|
106
|
+
private followUpQueue;
|
|
107
|
+
private steeringMode;
|
|
108
|
+
private followUpMode;
|
|
109
|
+
streamFn: StreamFn;
|
|
110
|
+
private _sessionId?;
|
|
111
|
+
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
112
|
+
private runningPrompt?;
|
|
113
|
+
private resolveRunningPrompt?;
|
|
114
|
+
private _thinkingBudgets?;
|
|
115
|
+
private _transport;
|
|
116
|
+
private _maxRetryDelayMs?;
|
|
117
|
+
private _agentLoopFramework?;
|
|
118
|
+
private canUseTool?;
|
|
119
|
+
private maxToolResultBatchSizeChars?;
|
|
120
|
+
private recoverModelError?;
|
|
121
|
+
private maxModelErrorRecoveryAttempts?;
|
|
122
|
+
private maxOutputTokenRecoveryAttempts?;
|
|
123
|
+
private outputTokenBudget?;
|
|
124
|
+
private runStopHooks?;
|
|
125
|
+
private maxStopHookContinuations?;
|
|
126
|
+
private createToolUseSummary?;
|
|
127
|
+
private maxToolConcurrency?;
|
|
128
|
+
private maxTurnsPerPrompt?;
|
|
129
|
+
private maxToolCallsPerPrompt?;
|
|
130
|
+
constructor(opts?: AgentOptions);
|
|
131
|
+
/**
|
|
132
|
+
* Get the current session ID used for provider caching.
|
|
133
|
+
*/
|
|
134
|
+
get sessionId(): string | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Set the session ID for provider caching.
|
|
137
|
+
* Call this when switching sessions (new session, branch, resume).
|
|
138
|
+
*/
|
|
139
|
+
set sessionId(value: string | undefined);
|
|
140
|
+
/**
|
|
141
|
+
* Get the current thinking budgets.
|
|
142
|
+
*/
|
|
143
|
+
get thinkingBudgets(): ThinkingBudgets | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Set custom thinking budgets for token-based providers.
|
|
146
|
+
*/
|
|
147
|
+
set thinkingBudgets(value: ThinkingBudgets | undefined);
|
|
148
|
+
/**
|
|
149
|
+
* Get the current preferred transport.
|
|
150
|
+
*/
|
|
151
|
+
get transport(): Transport;
|
|
152
|
+
/**
|
|
153
|
+
* Set the preferred transport.
|
|
154
|
+
*/
|
|
155
|
+
setTransport(value: Transport): void;
|
|
156
|
+
/**
|
|
157
|
+
* Get the current max retry delay in milliseconds.
|
|
158
|
+
*/
|
|
159
|
+
get maxRetryDelayMs(): number | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Set the maximum delay to wait for server-requested retries.
|
|
162
|
+
* Set to 0 to disable the cap.
|
|
163
|
+
*/
|
|
164
|
+
set maxRetryDelayMs(value: number | undefined);
|
|
165
|
+
get agentLoopFramework(): AgentLoopFramework;
|
|
166
|
+
setAgentLoopFramework(value: AgentLoopFrameworkInput | undefined): void;
|
|
167
|
+
get state(): AgentState;
|
|
168
|
+
subscribe(fn: (e: AgentEvent) => void): () => void;
|
|
169
|
+
setSystemPrompt(v: string): void;
|
|
170
|
+
setModel(m: Model<any>): void;
|
|
171
|
+
setThinkingLevel(l: ThinkingLevel): void;
|
|
172
|
+
setSteeringMode(mode: "all" | "one-at-a-time"): void;
|
|
173
|
+
getSteeringMode(): "all" | "one-at-a-time";
|
|
174
|
+
setFollowUpMode(mode: "all" | "one-at-a-time"): void;
|
|
175
|
+
getFollowUpMode(): "all" | "one-at-a-time";
|
|
176
|
+
setTools(t: AgentTool<any>[]): void;
|
|
177
|
+
setLoopPolicy(options: Partial<AgentLoopPolicyOptions>): void;
|
|
178
|
+
setModelErrorRecovery(recoverModelError: AgentLoopConfig["recoverModelError"] | undefined): void;
|
|
179
|
+
replaceMessages(ms: AgentMessage[]): void;
|
|
180
|
+
appendMessage(m: AgentMessage): void;
|
|
181
|
+
/**
|
|
182
|
+
* Queue a steering message to interrupt the agent mid-run.
|
|
183
|
+
* Delivered after current tool execution, skips remaining tools.
|
|
184
|
+
*/
|
|
185
|
+
steer(m: AgentMessage): void;
|
|
186
|
+
/**
|
|
187
|
+
* Queue a follow-up message to be processed after the agent finishes.
|
|
188
|
+
* Delivered only when agent has no more tool calls or steering messages.
|
|
189
|
+
*/
|
|
190
|
+
followUp(m: AgentMessage): void;
|
|
191
|
+
clearSteeringQueue(): void;
|
|
192
|
+
clearFollowUpQueue(): void;
|
|
193
|
+
clearAllQueues(): void;
|
|
194
|
+
hasQueuedMessages(): boolean;
|
|
195
|
+
private dequeueSteeringMessages;
|
|
196
|
+
private dequeueFollowUpMessages;
|
|
197
|
+
clearMessages(): void;
|
|
198
|
+
abort(): void;
|
|
199
|
+
waitForIdle(): Promise<void>;
|
|
200
|
+
reset(): void;
|
|
201
|
+
/** Send a prompt with an AgentMessage */
|
|
202
|
+
prompt(message: AgentMessage | AgentMessage[]): Promise<void>;
|
|
203
|
+
prompt(input: string, images?: ImageContent[]): Promise<void>;
|
|
204
|
+
/**
|
|
205
|
+
* Continue from current context (used for retries and resuming queued messages).
|
|
206
|
+
*/
|
|
207
|
+
continue(): Promise<void>;
|
|
208
|
+
/**
|
|
209
|
+
* Run the agent loop.
|
|
210
|
+
* If messages are provided, starts a new conversation turn with those messages.
|
|
211
|
+
* Otherwise, continues from existing context.
|
|
212
|
+
*/
|
|
213
|
+
private _runLoop;
|
|
214
|
+
private emit;
|
|
215
|
+
}
|