qlogicagent 0.5.2 → 0.6.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/README.md +403 -402
- package/dist/agent.js +18 -0
- package/dist/cli.js +384 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +383 -0
- package/dist/orchestration.js +34 -0
- package/dist/types/agent/agent.d.ts +43 -0
- package/dist/types/agent/constants.d.ts +47 -0
- package/dist/types/agent/tool-access.d.ts +30 -0
- package/dist/types/agent/tool-loop.d.ts +94 -0
- package/dist/types/agent/types.d.ts +238 -0
- package/dist/types/cli/main.d.ts +11 -0
- package/dist/types/cli/stdio-server.d.ts +78 -0
- package/dist/types/cli/tool-bootstrap.d.ts +40 -0
- package/dist/types/cli/transport.d.ts +40 -0
- package/dist/types/config/config.d.ts +17 -0
- package/dist/types/contracts/hooks.d.ts +175 -0
- package/dist/types/contracts/index.d.ts +9 -0
- package/dist/types/contracts/planner.d.ts +35 -0
- package/dist/types/contracts/todo.d.ts +23 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/llm/builtin-providers.d.ts +10 -0
- package/dist/types/llm/debug-transport.d.ts +12 -0
- package/dist/types/llm/index.d.ts +16 -0
- package/dist/types/llm/llm-client.d.ts +43 -0
- package/dist/types/llm/model-catalog.d.ts +53 -0
- package/dist/types/llm/provider-def.d.ts +59 -0
- package/dist/types/llm/provider-registry.d.ts +54 -0
- package/dist/types/llm/transport.d.ts +62 -0
- package/dist/types/llm/transports/anthropic-messages.d.ts +31 -0
- package/dist/types/llm/transports/openai-chat.d.ts +36 -0
- package/dist/types/orchestration/context/context-collapse.d.ts +58 -0
- package/dist/types/orchestration/context/context-compression.d.ts +301 -0
- package/dist/types/orchestration/context/reactive-compact.d.ts +73 -0
- package/dist/types/orchestration/context/turn-loop-guard.d.ts +86 -0
- package/dist/types/orchestration/error-handling/error-classification.d.ts +12 -0
- package/dist/types/orchestration/error-handling/failover-classification.d.ts +8 -0
- package/dist/types/orchestration/error-handling/failover-error.d.ts +33 -0
- package/dist/types/orchestration/error-handling/retry-loop.d.ts +69 -0
- package/dist/types/orchestration/index.d.ts +15 -0
- package/dist/types/orchestration/skill-improvement.d.ts +59 -0
- package/dist/types/orchestration/subagent/agent-registry.d.ts +46 -0
- package/dist/types/orchestration/subagent/fork-subagent.d.ts +98 -0
- package/dist/types/orchestration/subagent/task-types.d.ts +142 -0
- package/dist/types/orchestration/tool-loop/conversation-repair.d.ts +61 -0
- package/dist/types/orchestration/tool-loop/tool-choice-policy.d.ts +54 -0
- package/dist/types/orchestration/tool-loop/tool-loop-state.d.ts +50 -0
- package/dist/types/orchestration/tool-loop/tool-schema.d.ts +39 -0
- package/dist/types/runtime/execution/dream-agent.d.ts +199 -0
- package/dist/types/runtime/execution/forked-agent.d.ts +109 -0
- package/dist/types/runtime/execution/index.d.ts +6 -0
- package/dist/types/runtime/execution/progress-tracker.d.ts +78 -0
- package/dist/types/runtime/execution/remote-agent.d.ts +63 -0
- package/dist/types/runtime/execution/streaming-tool-executor.d.ts +100 -0
- package/dist/types/runtime/execution/tool-eligibility.d.ts +59 -0
- package/dist/types/runtime/execution/tool-result-storage.d.ts +87 -0
- package/dist/types/runtime/hooks/context-compression.d.ts +61 -0
- package/dist/types/runtime/hooks/hook-registry.d.ts +12 -0
- package/dist/types/runtime/hooks/index.d.ts +3 -0
- package/dist/types/runtime/hooks/memory-hooks.d.ts +49 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/infra/agent-paths.d.ts +57 -0
- package/dist/types/runtime/infra/checkpoint-backend.d.ts +8 -0
- package/dist/types/runtime/infra/cleanup-registry.d.ts +23 -0
- package/dist/types/runtime/infra/disk-storage.d.ts +36 -0
- package/dist/types/runtime/infra/file-watcher.d.ts +72 -0
- package/dist/types/runtime/infra/index.d.ts +8 -0
- package/dist/types/runtime/infra/secure-storage.d.ts +81 -0
- package/dist/types/runtime/infra/task-runtime.d.ts +108 -0
- package/dist/types/runtime/infra/token-budget.d.ts +92 -0
- package/dist/types/runtime/infra/worktree-backend.d.ts +85 -0
- package/dist/types/runtime/prompt/environment-context.d.ts +23 -0
- package/dist/types/runtime/prompt/index.d.ts +3 -0
- package/dist/types/runtime/prompt/instruction-loader.d.ts +64 -0
- package/dist/types/runtime/prompt/system-prompt-sections.d.ts +63 -0
- package/dist/types/runtime/session/index.d.ts +2 -0
- package/dist/types/runtime/session/session-memory.d.ts +90 -0
- package/dist/types/runtime/session/session-persistence.d.ts +94 -0
- package/dist/types/runtime/session/session-state.d.ts +117 -0
- package/dist/types/skills/index.d.ts +119 -0
- package/dist/types/skills/mcp/index.d.ts +3 -0
- package/dist/types/skills/mcp/mcp-http-client.d.ts +66 -0
- package/dist/types/skills/mcp/mcp-manager.d.ts +83 -0
- package/dist/types/skills/mcp/mcp-stdio-client.d.ts +84 -0
- package/dist/types/skills/memory/memory-extractor.d.ts +64 -0
- package/dist/types/skills/memory/memory-store.d.ts +86 -0
- package/dist/types/skills/memory/memory-tool.d.ts +87 -0
- package/dist/types/skills/memory/qmemory-adapter.d.ts +42 -0
- package/dist/types/skills/permissions/bash-classifier.d.ts +30 -0
- package/dist/types/skills/permissions/classifier-cache.d.ts +51 -0
- package/dist/types/skills/permissions/denial-tracking.d.ts +42 -0
- package/dist/types/skills/permissions/hook-runner.d.ts +85 -0
- package/dist/types/skills/permissions/index.d.ts +12 -0
- package/dist/types/skills/permissions/permission-classifier.d.ts +41 -0
- package/dist/types/skills/permissions/rule-engine.d.ts +41 -0
- package/dist/types/skills/permissions/settings-watcher.d.ts +46 -0
- package/dist/types/skills/permissions/types.d.ts +113 -0
- package/dist/types/skills/plugins/index.d.ts +2 -0
- package/dist/types/skills/plugins/plugin-api.d.ts +38 -0
- package/dist/types/skills/plugins/plugin-loader.d.ts +42 -0
- package/dist/types/skills/plugins/plugin-marketplace.d.ts +61 -0
- package/dist/types/skills/portable-tool.d.ts +104 -0
- package/dist/types/skills/skill-system/skill-frontmatter.d.ts +19 -0
- package/dist/types/skills/skill-system/skill-guard.d.ts +23 -0
- package/dist/types/skills/skill-system/skill-loader.d.ts +16 -0
- package/dist/types/skills/skill-system/skill-source.d.ts +119 -0
- package/dist/types/skills/skill-system/skill-types.d.ts +199 -0
- package/dist/types/skills/think-tool.d.ts +16 -0
- package/dist/types/skills/todo-tool.d.ts +72 -0
- package/dist/types/skills/tools/agent-tool.d.ts +91 -0
- package/dist/types/skills/tools/apply-patch-tool.d.ts +29 -0
- package/dist/types/skills/tools/ask-user-tool.d.ts +80 -0
- package/dist/types/skills/tools/brief-tool.d.ts +74 -0
- package/dist/types/skills/tools/browser-tool.d.ts +114 -0
- package/dist/types/skills/tools/checkpoint-tool.d.ts +66 -0
- package/dist/types/skills/tools/config-tool.d.ts +63 -0
- package/dist/types/skills/tools/cron-tool.d.ts +116 -0
- package/dist/types/skills/tools/edit-tool.d.ts +43 -0
- package/dist/types/skills/tools/exec-tool.d.ts +97 -0
- package/dist/types/skills/tools/image-generate-tool.d.ts +62 -0
- package/dist/types/skills/tools/instructions-tool.d.ts +65 -0
- package/dist/types/skills/tools/lsp-tool.d.ts +153 -0
- package/dist/types/skills/tools/mcp-client-types.d.ts +269 -0
- package/dist/types/skills/tools/mcp-resource-tools.d.ts +14 -0
- package/dist/types/skills/tools/mcp-tool.d.ts +249 -0
- package/dist/types/skills/tools/monitor-tool.d.ts +113 -0
- package/dist/types/skills/tools/music-generate-tool.d.ts +55 -0
- package/dist/types/skills/tools/notebook-edit-tool.d.ts +15 -0
- package/dist/types/skills/tools/notify-tool.d.ts +53 -0
- package/dist/types/skills/tools/patch-tool.d.ts +45 -0
- package/dist/types/skills/tools/plan-mode-tool.d.ts +98 -0
- package/dist/types/skills/tools/read-tool.d.ts +51 -0
- package/dist/types/skills/tools/repl-tool.d.ts +70 -0
- package/dist/types/skills/tools/search-tool.d.ts +112 -0
- package/dist/types/skills/tools/send-message-tool.d.ts +51 -0
- package/dist/types/skills/tools/shell/bash-provider.d.ts +26 -0
- package/dist/types/skills/tools/shell/command-classification.d.ts +44 -0
- package/dist/types/skills/tools/shell/command-semantics.d.ts +14 -0
- package/dist/types/skills/tools/shell/destructive-command-warning.d.ts +10 -0
- package/dist/types/skills/tools/shell/exec-permissions.d.ts +52 -0
- package/dist/types/skills/tools/shell/index.d.ts +17 -0
- package/dist/types/skills/tools/shell/powershell-provider.d.ts +15 -0
- package/dist/types/skills/tools/shell/shell-command.d.ts +54 -0
- package/dist/types/skills/tools/shell/shell-exec.d.ts +33 -0
- package/dist/types/skills/tools/shell/shell-provider.d.ts +85 -0
- package/dist/types/skills/tools/shell/task-output.d.ts +45 -0
- package/dist/types/skills/tools/skill-invoke-tool.d.ts +46 -0
- package/dist/types/skills/tools/skill-list-tool.d.ts +33 -0
- package/dist/types/skills/tools/skill-manage-tool.d.ts +73 -0
- package/dist/types/skills/tools/skill-view-tool.d.ts +37 -0
- package/dist/types/skills/tools/sleep-tool.d.ts +49 -0
- package/dist/types/skills/tools/structured-output-tool.d.ts +116 -0
- package/dist/types/skills/tools/task-tool.d.ts +104 -0
- package/dist/types/skills/tools/team-tool.d.ts +89 -0
- package/dist/types/skills/tools/tool-search-tool.d.ts +51 -0
- package/dist/types/skills/tools/tts-tool.d.ts +38 -0
- package/dist/types/skills/tools/video-edit-tool.d.ts +69 -0
- package/dist/types/skills/tools/video-generate-tool.d.ts +62 -0
- package/dist/types/skills/tools/video-merge-tool.d.ts +105 -0
- package/dist/types/skills/tools/video-upscale-tool.d.ts +45 -0
- package/dist/types/skills/tools/web-fetch-tool.d.ts +78 -0
- package/dist/types/skills/tools/web-search-tool.d.ts +57 -0
- package/dist/types/skills/tools/workflow-tool.d.ts +44 -0
- package/dist/types/skills/tools/worktree-tool.d.ts +69 -0
- package/dist/types/skills/tools/write-tool.d.ts +45 -0
- package/dist/types/skills/tools.d.ts +65 -0
- package/package.json +4 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn Loop Guard — Abort signal + token budget warning for preventive termination.
|
|
3
|
+
*
|
|
4
|
+
* Aligned with Claude Code's multi-condition termination:
|
|
5
|
+
* 1. AbortSignal from user cancellation
|
|
6
|
+
* 2. Token budget pre-check (don't send API call if over budget)
|
|
7
|
+
* 3. max_output_tokens escalation on truncation
|
|
8
|
+
* 4. Prompt-too-long reactive compact trigger
|
|
9
|
+
*/
|
|
10
|
+
export interface TurnLoopGuardConfig {
|
|
11
|
+
/** Context window size in tokens. */
|
|
12
|
+
contextWindowTokens: number;
|
|
13
|
+
/** Buffer reserved for response (default: 13000). */
|
|
14
|
+
responseBufferTokens: number;
|
|
15
|
+
/** Max output tokens for current model. */
|
|
16
|
+
maxOutputTokens: number;
|
|
17
|
+
/** Abort signal for user cancellation. */
|
|
18
|
+
abortSignal?: AbortSignal;
|
|
19
|
+
/** Whether reactive compact is available. */
|
|
20
|
+
reactiveCompactEnabled: boolean;
|
|
21
|
+
/** Whether max_output_tokens escalation is allowed. */
|
|
22
|
+
outputEscalationEnabled: boolean;
|
|
23
|
+
}
|
|
24
|
+
export type TokenWarningState = {
|
|
25
|
+
level: "ok";
|
|
26
|
+
} | {
|
|
27
|
+
level: "warning";
|
|
28
|
+
usagePercent: number;
|
|
29
|
+
remainingTokens: number;
|
|
30
|
+
} | {
|
|
31
|
+
level: "blocking";
|
|
32
|
+
usagePercent: number;
|
|
33
|
+
reason: "prompt_too_long" | "budget_exhausted";
|
|
34
|
+
};
|
|
35
|
+
export interface TurnLoopGuardState {
|
|
36
|
+
/** Current accumulated prompt tokens. */
|
|
37
|
+
promptTokens: number;
|
|
38
|
+
/** Whether reactive compact has already been attempted this turn. */
|
|
39
|
+
hasAttemptedReactiveCompact: boolean;
|
|
40
|
+
/** Current max_output_tokens (may escalate). */
|
|
41
|
+
currentMaxOutputTokens: number;
|
|
42
|
+
/** Number of consecutive max_tokens truncations. */
|
|
43
|
+
consecutiveTruncations: number;
|
|
44
|
+
/** Whether the turn has been aborted. */
|
|
45
|
+
aborted: boolean;
|
|
46
|
+
}
|
|
47
|
+
/** Initial guard state. */
|
|
48
|
+
export declare function createTurnLoopGuardState(config: TurnLoopGuardConfig): TurnLoopGuardState;
|
|
49
|
+
/**
|
|
50
|
+
* Calculate token warning state before making an API call.
|
|
51
|
+
* If level is "blocking", do NOT send the API call.
|
|
52
|
+
*/
|
|
53
|
+
export declare function calculateTokenWarningState(state: TurnLoopGuardState, config: TurnLoopGuardConfig): TokenWarningState;
|
|
54
|
+
/**
|
|
55
|
+
* Handle API error and determine recovery action.
|
|
56
|
+
*/
|
|
57
|
+
export type ApiErrorRecovery = {
|
|
58
|
+
action: "reactive_compact";
|
|
59
|
+
} | {
|
|
60
|
+
action: "escalate_output_tokens";
|
|
61
|
+
newMax: number;
|
|
62
|
+
} | {
|
|
63
|
+
action: "retry";
|
|
64
|
+
reason: string;
|
|
65
|
+
} | {
|
|
66
|
+
action: "abort";
|
|
67
|
+
reason: string;
|
|
68
|
+
};
|
|
69
|
+
export declare function resolveApiErrorRecovery(error: {
|
|
70
|
+
type?: string;
|
|
71
|
+
status?: number;
|
|
72
|
+
message?: string;
|
|
73
|
+
}, state: TurnLoopGuardState, config: TurnLoopGuardConfig): ApiErrorRecovery;
|
|
74
|
+
/**
|
|
75
|
+
* Handle finish_reason === "max_tokens" — escalate max_output_tokens.
|
|
76
|
+
*
|
|
77
|
+
* CC pattern: double the output token budget up to model max.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveOutputTokenEscalation(state: TurnLoopGuardState, config: TurnLoopGuardConfig, modelMaxOutput: number): {
|
|
80
|
+
shouldEscalate: boolean;
|
|
81
|
+
newMax: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Check if the turn should be aborted (user cancellation).
|
|
85
|
+
*/
|
|
86
|
+
export declare function shouldAbortTurn(state: TurnLoopGuardState, config: TurnLoopGuardConfig): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FailoverReason } from "./failover-classification.js";
|
|
2
|
+
export type ErrorCategory = "RETRYABLE_TRANSIENT" | "RETRYABLE_DEGRADED" | "NON_RETRYABLE_AUTH" | "NON_RETRYABLE_CONTENT" | "NON_RETRYABLE_QUOTA" | "TOOL_EXECUTION_FAILED";
|
|
3
|
+
export interface RetryStrategy {
|
|
4
|
+
retryable: boolean;
|
|
5
|
+
maxRetries: number;
|
|
6
|
+
baseDelayMs: number;
|
|
7
|
+
backoffMultiplier: number;
|
|
8
|
+
switchProvider: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function classifyError(status: number | undefined, message?: string): ErrorCategory;
|
|
11
|
+
export declare function classifyErrorFromReason(reason: FailoverReason): ErrorCategory;
|
|
12
|
+
export declare function getRetryStrategy(category: ErrorCategory): RetryStrategy;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type FailoverReason = "auth" | "auth_permanent" | "format" | "rate_limit" | "overloaded" | "billing" | "timeout" | "model_not_found" | "session_expired" | "unknown";
|
|
2
|
+
export declare function isTimeoutErrorMessage(raw: string): boolean;
|
|
3
|
+
export declare function isCloudflareOrHtmlErrorPage(raw: string): boolean;
|
|
4
|
+
export declare function isTransientHttpError(raw: string): boolean;
|
|
5
|
+
export declare function classifyFailoverReasonFromHttpStatus(status: number | undefined, message?: string): FailoverReason | null;
|
|
6
|
+
export declare function isModelNotFoundErrorMessage(raw: string): boolean;
|
|
7
|
+
export declare function classifyFailoverReason(raw: string): FailoverReason | null;
|
|
8
|
+
export declare function isFailoverErrorMessage(raw: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type FailoverReason } from "./failover-classification.js";
|
|
2
|
+
export declare class FailoverError extends Error {
|
|
3
|
+
readonly reason: FailoverReason;
|
|
4
|
+
readonly provider?: string;
|
|
5
|
+
readonly model?: string;
|
|
6
|
+
readonly profileId?: string;
|
|
7
|
+
readonly status?: number;
|
|
8
|
+
readonly code?: string;
|
|
9
|
+
constructor(message: string, params: {
|
|
10
|
+
reason: FailoverReason;
|
|
11
|
+
provider?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
profileId?: string;
|
|
14
|
+
status?: number;
|
|
15
|
+
code?: string;
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare function isFailoverError(err: unknown): err is FailoverError;
|
|
20
|
+
export declare function resolveFailoverStatus(reason: FailoverReason): number | undefined;
|
|
21
|
+
export declare function isTimeoutError(err: unknown): boolean;
|
|
22
|
+
export declare function resolveFailoverReasonFromError(err: unknown): FailoverReason | null;
|
|
23
|
+
export declare function describeFailoverError(err: unknown): {
|
|
24
|
+
message: string;
|
|
25
|
+
reason?: FailoverReason;
|
|
26
|
+
status?: number;
|
|
27
|
+
code?: string;
|
|
28
|
+
};
|
|
29
|
+
export declare function coerceToFailoverError(err: unknown, context?: {
|
|
30
|
+
provider?: string;
|
|
31
|
+
model?: string;
|
|
32
|
+
profileId?: string;
|
|
33
|
+
}): FailoverError | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare function executeBoundedRetryLoop<TResult>(params: {
|
|
2
|
+
maxIterations: number;
|
|
3
|
+
onRetryLimit: (params: {
|
|
4
|
+
iterations: number;
|
|
5
|
+
maxIterations: number;
|
|
6
|
+
}) => Promise<TResult> | TResult;
|
|
7
|
+
executeIteration: (params: {
|
|
8
|
+
iteration: number;
|
|
9
|
+
}) => Promise<{
|
|
10
|
+
kind: "continue";
|
|
11
|
+
} | {
|
|
12
|
+
kind: "return";
|
|
13
|
+
result: TResult;
|
|
14
|
+
}>;
|
|
15
|
+
}): Promise<TResult>;
|
|
16
|
+
export declare function resolveScaledRetryIterations(params: {
|
|
17
|
+
candidateCount: number;
|
|
18
|
+
baseIterations?: number;
|
|
19
|
+
perCandidateIterations?: number;
|
|
20
|
+
minIterations?: number;
|
|
21
|
+
maxIterations?: number;
|
|
22
|
+
}): number;
|
|
23
|
+
export declare function isForegroundSource(source: string | undefined): boolean;
|
|
24
|
+
/** Is this a transient capacity error (429 or 529/overloaded)? */
|
|
25
|
+
export declare function isTransientCapacityError(status: number | undefined): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Compute exponential backoff delay with jitter.
|
|
28
|
+
* CC parity: withRetry.ts — BASE_DELAY_MS=500, 2^n backoff, capped.
|
|
29
|
+
*/
|
|
30
|
+
export declare function computeRetryBackoff(attempt: number, baseDelayMs?: number, maxDelayMs?: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* Persistent retry mode — for unattended sessions.
|
|
33
|
+
* Retries 429/529 indefinitely with higher backoff.
|
|
34
|
+
* Yields heartbeat events periodically so the host doesn't mark us idle.
|
|
35
|
+
*
|
|
36
|
+
* CC parity: withRetry.ts CLAUDE_CODE_UNATTENDED_RETRY
|
|
37
|
+
*/
|
|
38
|
+
export interface PersistentRetryConfig {
|
|
39
|
+
/** Max backoff interval (CC: 5 min). */
|
|
40
|
+
maxBackoffMs: number;
|
|
41
|
+
/** Total cap before giving up (CC: 6 hours). */
|
|
42
|
+
resetCapMs: number;
|
|
43
|
+
/** Heartbeat interval during waits (CC: 30 seconds). */
|
|
44
|
+
heartbeatIntervalMs: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const DEFAULT_PERSISTENT_RETRY_CONFIG: PersistentRetryConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Check if persistent retry is enabled via environment variable.
|
|
49
|
+
* CC parity: CLAUDE_CODE_UNATTENDED_RETRY
|
|
50
|
+
*/
|
|
51
|
+
export declare function isPersistentRetryEnabled(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Error class for triggering model fallback after repeated 529s.
|
|
54
|
+
* CC parity: FallbackTriggeredError
|
|
55
|
+
*/
|
|
56
|
+
export declare class FallbackTriggeredError extends Error {
|
|
57
|
+
readonly originalModel: string;
|
|
58
|
+
readonly fallbackModel: string;
|
|
59
|
+
constructor(originalModel: string, fallbackModel: string);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Error class for when retries are exhausted and cannot continue.
|
|
63
|
+
* CC parity: CannotRetryError
|
|
64
|
+
*/
|
|
65
|
+
export declare class CannotRetryError extends Error {
|
|
66
|
+
readonly originalError: unknown;
|
|
67
|
+
readonly model: string;
|
|
68
|
+
constructor(originalError: unknown, model: string);
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { buildAssistantToolCallMessage, buildToolResultMessage, type FunctionToolDefinition, } from "./tool-loop/tool-schema.js";
|
|
2
|
+
export { classifyError, getRetryStrategy, type ErrorCategory, type RetryStrategy, } from "./error-handling/error-classification.js";
|
|
3
|
+
export { composeStrategies, composeAsyncStrategies, SlidingWindowStrategy, SummarizeOldStrategy, ToolResultTrimStrategy, HeadTailProtectedStrategy, IncrementalCompactStrategy, CacheAwareCompressionStrategy, CompressionMetricsCollector, ContextEngineRegistry, MicroCompactStrategy, postCompactFileRecovery, type PostCompactRecoveryConfig, buildStructuredSummaryPrompt, computeAdaptiveBudget, isAsyncCompressionStrategy, selectCompressionTier, DEFAULT_ADAPTIVE_BUDGET_CONFIG, type AdaptiveBudgetConfig, type AsyncCompressionStrategy, type CacheAwareCompressionConfig, type CompressibleMessage, type CompressionEvent, type CompressionMetrics, type CompressionMetricsSnapshot, type CompressionResult, type CompressionStrategy, type CompressionTier, type ContextEngine, type HeadTailProtectionConfig, type IncrementalCompactConfig, type SummarizeFn, } from "./context/context-compression.js";
|
|
4
|
+
export { snipCompactIfNeeded, type SnipResult, } from "./context/context-compression.js";
|
|
5
|
+
export { applyCollapsesIfNeeded as applyContextCollapsesIfNeeded, recoverFromOverflow as recoverContextCollapseFromOverflow, createCollapseStore, type CollapseStore, type CollapseStage, } from "./context/context-collapse.js";
|
|
6
|
+
export { buildSkillInstruction, type SkillCreateInstruction, type SkillImproveInstruction, type SkillInstruction, type SkillTurnResult, } from "./skill-improvement.js";
|
|
7
|
+
export { applyToolChoicePolicy, type ApplyToolChoicePolicyInput, type ApplyToolChoicePolicyResult, } from "./tool-loop/tool-choice-policy.js";
|
|
8
|
+
export { repairOpenAiChatConversation, type ConversationRepairOptions, type OpenAiChatMessageLike, type OpenAiToolCall, } from "./tool-loop/conversation-repair.js";
|
|
9
|
+
export { advanceToolLoopState, recoverToolLoopStateFromChatConversation, recoverToolLoopStateFromResponsesItems, settleToolLoopState, type RepairToolLoopStateResult, type ToolLoopRepairAction, type ToolLoopState, } from "./tool-loop/tool-loop-state.js";
|
|
10
|
+
export { isForegroundSource, isTransientCapacityError, computeRetryBackoff, isPersistentRetryEnabled, FallbackTriggeredError, type PersistentRetryConfig, } from "./error-handling/retry-loop.js";
|
|
11
|
+
export { canForkAtDepth, buildForkedMessages, buildForkPlaceholderResults, FORK_PLACEHOLDER_RESULT, FORK_SENTINEL_TAG, generateForkChildAgentId, isInForkChild, MAX_FORK_DEPTH, resolveForkChildTools, type ForkChildConfig, type ForkChildMessage, type ForkContext, type ForkResult, } from "./subagent/fork-subagent.js";
|
|
12
|
+
export { getBuiltInAgent, getBuiltInAgents, isBuiltInAgent, resolveAgentToolSet, type AgentDefinition, } from "./subagent/agent-registry.js";
|
|
13
|
+
export { createTaskState, filterToolsByRole, type IsolationMode, type PermissionRole, type TaskType, type TaskLifecycle, type TaskState, type TaskStateBase, type LocalBashTaskState, type LocalAgentTaskState, type RemoteAgentTaskState, type InProcessTeammateTaskState, type DreamTaskState, type DreamTurn, type DreamPhase, } from "./subagent/task-types.js";
|
|
14
|
+
export { calculateTokenWarningState, createTurnLoopGuardState, resolveApiErrorRecovery, resolveOutputTokenEscalation, shouldAbortTurn, type ApiErrorRecovery, type TokenWarningState, type TurnLoopGuardConfig, type TurnLoopGuardState, } from "./context/turn-loop-guard.js";
|
|
15
|
+
export { buildPostCompactRestorationMessage, createReactiveCompactState, shouldAttemptReactiveCompact, type ReactiveCompactConfig, type ReactiveCompactState, } from "./context/reactive-compact.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill self-learning: decides whether a completed turn should
|
|
3
|
+
* trigger skill creation or improvement instructions.
|
|
4
|
+
*/
|
|
5
|
+
export interface SkillTurnResult {
|
|
6
|
+
ok: boolean;
|
|
7
|
+
/** Number of tool invocations in this turn */
|
|
8
|
+
toolCallCount: number;
|
|
9
|
+
/** Number of distinct tool names used */
|
|
10
|
+
distinctToolCount: number;
|
|
11
|
+
/** Was a multi-step orchestration (≥2 rounds) used? */
|
|
12
|
+
multiStep: boolean;
|
|
13
|
+
/** Did the turn involve a sub-agent fork? */
|
|
14
|
+
hasSubAgent: boolean;
|
|
15
|
+
/** Optional user feedback signal (positive/negative/none) */
|
|
16
|
+
feedback?: "positive" | "negative" | null;
|
|
17
|
+
/** Skill name if an existing skill was used */
|
|
18
|
+
existingSkillName?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface SkillCreateInstruction {
|
|
21
|
+
type: "skill.create";
|
|
22
|
+
/** Suggested skill name derived from tool usage pattern */
|
|
23
|
+
suggestedName: string;
|
|
24
|
+
/** Short description of what the skill does */
|
|
25
|
+
description: string;
|
|
26
|
+
/** Tool names involved */
|
|
27
|
+
tools: string[];
|
|
28
|
+
/** Number of orchestration steps */
|
|
29
|
+
stepCount: number;
|
|
30
|
+
}
|
|
31
|
+
export interface SkillImproveInstruction {
|
|
32
|
+
type: "skill.improve";
|
|
33
|
+
/** Existing skill to improve */
|
|
34
|
+
skillName: string;
|
|
35
|
+
/** Reason for improvement */
|
|
36
|
+
reason: string;
|
|
37
|
+
}
|
|
38
|
+
export type SkillInstruction = SkillCreateInstruction | SkillImproveInstruction;
|
|
39
|
+
/**
|
|
40
|
+
* Determine whether a completed turn should produce a skill instruction.
|
|
41
|
+
*
|
|
42
|
+
* A new skill is suggested when:
|
|
43
|
+
* - The turn succeeded
|
|
44
|
+
* - It involved multi-step orchestration
|
|
45
|
+
* - It used ≥3 tool calls across ≥2 distinct tools
|
|
46
|
+
* - No existing skill was already applied
|
|
47
|
+
*
|
|
48
|
+
* An improvement is suggested when:
|
|
49
|
+
* - The turn used an existing skill but got negative feedback
|
|
50
|
+
*/
|
|
51
|
+
export declare function shouldCreateSkill(result: SkillTurnResult): boolean;
|
|
52
|
+
export declare function shouldImproveSkill(result: SkillTurnResult): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Build a skill instruction from a turn result, or null if none is warranted.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildSkillInstruction(result: SkillTurnResult, context: {
|
|
57
|
+
tools: string[];
|
|
58
|
+
suggestedName?: string;
|
|
59
|
+
}): SkillInstruction | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in Agent Registry — CC-aligned agent definitions for fork/subagent.
|
|
3
|
+
*
|
|
4
|
+
* Each built-in agent defines a role with constrained tools, system prompt,
|
|
5
|
+
* and execution budget. The LLM can invoke these via the AgentTool.
|
|
6
|
+
*/
|
|
7
|
+
import type { PermissionRole, IsolationMode } from "./task-types.js";
|
|
8
|
+
export interface AgentDefinition {
|
|
9
|
+
/** Unique identifier for the agent (kebab-case). */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Human-readable label. */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Short description (appears in tool_search / LLM prompt). */
|
|
14
|
+
description: string;
|
|
15
|
+
/** Maximum turns this agent can execute before forced stop. */
|
|
16
|
+
maxTurns: number;
|
|
17
|
+
/** Tool access mode. */
|
|
18
|
+
toolAccessMode: "full" | "read-only" | "none";
|
|
19
|
+
/** Explicit allowed tool names (if empty, uses toolAccessMode filter). */
|
|
20
|
+
allowedTools?: string[];
|
|
21
|
+
/** Whether this agent can fork sub-agents itself. */
|
|
22
|
+
canFork: boolean;
|
|
23
|
+
/** System prompt override for this agent. */
|
|
24
|
+
systemPromptSuffix?: string;
|
|
25
|
+
/** Permission role context (CC: interactive/coordinator/worker). Default: "worker". */
|
|
26
|
+
permissionRole?: PermissionRole;
|
|
27
|
+
/** Isolation mode (CC: shared/worktree/container). Default: "shared". */
|
|
28
|
+
isolation?: IsolationMode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the full list of built-in agent definitions.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getBuiltInAgents(): AgentDefinition[];
|
|
34
|
+
/**
|
|
35
|
+
* Look up a built-in agent by name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function getBuiltInAgent(name: string): AgentDefinition | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a given agent name is a built-in agent.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isBuiltInAgent(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Resolve tool access for an agent definition.
|
|
44
|
+
* Returns the set of tool names the agent is allowed to use.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveAgentToolSet(agent: AgentDefinition, availableTools: string[]): string[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fork Sub-Agent — CC-aligned fork mechanism for spawning child agents.
|
|
3
|
+
*
|
|
4
|
+
* Core design principles (aligned with Claude Code):
|
|
5
|
+
* 1. Child agent shares parent's message prefix (prompt cache hit)
|
|
6
|
+
* 2. Fork uses placeholder results to ensure byte-identical prefix across children
|
|
7
|
+
* 3. Child has independent tool context (doesn't pollute parent state)
|
|
8
|
+
* 4. Results flow back via AsyncGenerator (streaming backflow)
|
|
9
|
+
* 5. Depth control via in-memory counter (not DB-based)
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentDefinition } from "./agent-registry.js";
|
|
12
|
+
/** Sentinel tag injected into fork children to prevent recursive forking. */
|
|
13
|
+
export declare const FORK_SENTINEL_TAG = "<fork-child-context>";
|
|
14
|
+
/** Placeholder text used for all tool_results in shared prefix (ensures byte-identical prefix). */
|
|
15
|
+
export declare const FORK_PLACEHOLDER_RESULT = "Fork started \u2014 processing in background";
|
|
16
|
+
/** Maximum fork depth for in-memory agents (CC: MAX_FORK_DEPTH). */
|
|
17
|
+
export declare const MAX_FORK_DEPTH = 4;
|
|
18
|
+
export interface ForkContext {
|
|
19
|
+
/** Parent's full message history (becomes shared prefix for cache). */
|
|
20
|
+
parentMessages: unknown[];
|
|
21
|
+
/** Parent's rendered system prompt (byte-exact for cache hit). */
|
|
22
|
+
systemPrompt: string;
|
|
23
|
+
/** Parent's full tool pool (useExactTools=true pattern). */
|
|
24
|
+
parentTools: string[];
|
|
25
|
+
/** Current fork depth (0 = root). */
|
|
26
|
+
depth: number;
|
|
27
|
+
/** Abort signal from parent. */
|
|
28
|
+
abortSignal?: AbortSignal;
|
|
29
|
+
/** Parent's agent ID for lineage tracking. */
|
|
30
|
+
parentAgentId: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ForkChildConfig {
|
|
33
|
+
/** The agent definition to run. */
|
|
34
|
+
agent: AgentDefinition;
|
|
35
|
+
/** Task-specific prompt for this child (the unique part after shared prefix). */
|
|
36
|
+
taskPrompt: string;
|
|
37
|
+
/** Optional override for max turns. */
|
|
38
|
+
maxTurns?: number;
|
|
39
|
+
/** Whether to run in background (async). */
|
|
40
|
+
isAsync?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface ForkChildMessage {
|
|
43
|
+
role: "assistant" | "user" | "system";
|
|
44
|
+
content: unknown;
|
|
45
|
+
toolCalls?: unknown[];
|
|
46
|
+
}
|
|
47
|
+
export interface ForkResult {
|
|
48
|
+
/** Whether the fork completed successfully. */
|
|
49
|
+
ok: boolean;
|
|
50
|
+
/** Child's final output text (summary). */
|
|
51
|
+
output: string;
|
|
52
|
+
/** Messages produced by the child (for result backflow). */
|
|
53
|
+
messages: ForkChildMessage[];
|
|
54
|
+
/** Total tokens consumed by the child. */
|
|
55
|
+
tokensUsed: number;
|
|
56
|
+
/** Whether the child hit its turn limit. */
|
|
57
|
+
maxTurnsReached: boolean;
|
|
58
|
+
/** Child's agent ID. */
|
|
59
|
+
childAgentId: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if current context is inside a fork child (prevents recursive forking).
|
|
63
|
+
*/
|
|
64
|
+
export declare function isInForkChild(messages: unknown[]): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Check if fork depth allows spawning another child.
|
|
67
|
+
*/
|
|
68
|
+
export declare function canForkAtDepth(currentDepth: number): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Build forked messages that ensure byte-identical prefix across all fork children.
|
|
71
|
+
*
|
|
72
|
+
* Strategy (aligned with CC's buildForkedMessages):
|
|
73
|
+
* 1. Keep full parent message history (all tool_use blocks, thinking, text)
|
|
74
|
+
* 2. Replace all pending tool_results with FORK_PLACEHOLDER_RESULT
|
|
75
|
+
* 3. Append a single user message with the child-specific directive
|
|
76
|
+
* → All children share the same prefix up to the directive → maximum cache hits.
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildForkedMessages(context: ForkContext, childConfig: ForkChildConfig): unknown[];
|
|
79
|
+
/**
|
|
80
|
+
* Build placeholder tool results for the shared prefix.
|
|
81
|
+
* When parent has pending tool_calls, replace them all with identical placeholder text
|
|
82
|
+
* so all fork children produce byte-identical API request prefix.
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildForkPlaceholderResults(pendingToolCallIds: string[]): Array<{
|
|
85
|
+
role: "tool";
|
|
86
|
+
tool_call_id: string;
|
|
87
|
+
content: string;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the effective tool set for a fork child.
|
|
91
|
+
* CC pattern: useExactTools=true → child gets parent's full tool pool,
|
|
92
|
+
* then filtered by agent definition.
|
|
93
|
+
*/
|
|
94
|
+
export declare function resolveForkChildTools(parentTools: string[], agent: AgentDefinition): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Generate a unique agent ID for a fork child.
|
|
97
|
+
*/
|
|
98
|
+
export declare function generateForkChildAgentId(parentAgentId: string, agentName: string, depth: number): string;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Type Taxonomy — CC-aligned sub-agent task state system.
|
|
3
|
+
*
|
|
4
|
+
* CC defines 7 task types for sub-agent dispatch. Each type has different:
|
|
5
|
+
* - Execution model (in-process, subprocess, remote)
|
|
6
|
+
* - Isolation level (shared, worktree, container)
|
|
7
|
+
* - Permission handling (interactive, coordinator, worker)
|
|
8
|
+
* - Tool access (full, restricted, read-only)
|
|
9
|
+
*
|
|
10
|
+
* Reference: claude-code src/tasks/types.ts
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The 7 task types from CC's sub-agent architecture.
|
|
14
|
+
*
|
|
15
|
+
* - local_bash: Subprocess shell execution (bash/powershell)
|
|
16
|
+
* - local_agent: Background forked Node process with its own tool loop
|
|
17
|
+
* - remote_agent: Cloud environment (polling-based, e.g., CCR sandbox)
|
|
18
|
+
* - in_process_teammate: Same process, AsyncLocalStorage-isolated agent
|
|
19
|
+
* - local_workflow: DAG/pipeline execution (planned)
|
|
20
|
+
* - monitor_mcp: MCP server monitoring agent (planned)
|
|
21
|
+
* - dream: Background memory consolidation agent
|
|
22
|
+
*/
|
|
23
|
+
export type TaskType = "local_bash" | "local_agent" | "remote_agent" | "in_process_teammate" | "local_workflow" | "monitor_mcp" | "dream";
|
|
24
|
+
/**
|
|
25
|
+
* How a sub-agent is isolated from the parent execution.
|
|
26
|
+
*
|
|
27
|
+
* - shared: Same working directory, same filesystem (default fork)
|
|
28
|
+
* - worktree: Git worktree checkout — separate branch, merges back
|
|
29
|
+
* - container: Container sandbox (docker/remote)
|
|
30
|
+
*/
|
|
31
|
+
export type IsolationMode = "shared" | "worktree" | "container";
|
|
32
|
+
/**
|
|
33
|
+
* Permission context for sub-agent execution.
|
|
34
|
+
* Determines which PermissionChecker variant is used.
|
|
35
|
+
*
|
|
36
|
+
* CC reference: 3 permission handler variants
|
|
37
|
+
* - interactive: User-facing agent, prompts for approval
|
|
38
|
+
* - coordinator: Orchestrator agent, auto-approves most non-destructive ops
|
|
39
|
+
* - worker: Headless worker, classifier-only (no user prompts)
|
|
40
|
+
*/
|
|
41
|
+
export type PermissionRole = "interactive" | "coordinator" | "worker";
|
|
42
|
+
/** Common state fields shared by all task types. */
|
|
43
|
+
export interface TaskStateBase {
|
|
44
|
+
/** Unique task ID. */
|
|
45
|
+
taskId: string;
|
|
46
|
+
/** Task type discriminant. */
|
|
47
|
+
type: TaskType;
|
|
48
|
+
/** Human-readable label. */
|
|
49
|
+
label: string;
|
|
50
|
+
/** The permission role for this task's agent. */
|
|
51
|
+
permissionRole: PermissionRole;
|
|
52
|
+
/** Isolation mode. */
|
|
53
|
+
isolation: IsolationMode;
|
|
54
|
+
/** Current lifecycle state. */
|
|
55
|
+
lifecycle: TaskLifecycle;
|
|
56
|
+
/** Parent task ID (for nested sub-agents). */
|
|
57
|
+
parentTaskId?: string;
|
|
58
|
+
/** Execution depth (0 = root). */
|
|
59
|
+
depth: number;
|
|
60
|
+
/** Maximum turns before forced stop. */
|
|
61
|
+
maxTurns: number;
|
|
62
|
+
/** Token budget for this task. */
|
|
63
|
+
tokenBudget: number;
|
|
64
|
+
/** Start timestamp (ms). */
|
|
65
|
+
startedAt: number;
|
|
66
|
+
/** End timestamp (ms), set when completed/failed. */
|
|
67
|
+
endedAt?: number;
|
|
68
|
+
}
|
|
69
|
+
export type TaskLifecycle = "pending" | "running" | "completed" | "failed" | "cancelled" | "timeout";
|
|
70
|
+
/** Local bash task — subprocess shell execution. */
|
|
71
|
+
export interface LocalBashTaskState extends TaskStateBase {
|
|
72
|
+
type: "local_bash";
|
|
73
|
+
command: string;
|
|
74
|
+
cwd: string;
|
|
75
|
+
pid?: number;
|
|
76
|
+
}
|
|
77
|
+
/** Local agent task — forked agent with its own tool loop. */
|
|
78
|
+
export interface LocalAgentTaskState extends TaskStateBase {
|
|
79
|
+
type: "local_agent";
|
|
80
|
+
agentName: string;
|
|
81
|
+
systemPrompt: string;
|
|
82
|
+
/** Restricted tool set (empty = inherit parent). */
|
|
83
|
+
allowedTools: string[];
|
|
84
|
+
/** Worktree branch name (if isolation === "worktree"). */
|
|
85
|
+
worktreeBranch?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Remote agent task — cloud sandbox execution. */
|
|
88
|
+
export interface RemoteAgentTaskState extends TaskStateBase {
|
|
89
|
+
type: "remote_agent";
|
|
90
|
+
/** Remote session/environment ID. */
|
|
91
|
+
remoteSessionId: string;
|
|
92
|
+
/** Polling endpoint for status checks. */
|
|
93
|
+
pollEndpoint?: string;
|
|
94
|
+
}
|
|
95
|
+
/** In-process teammate — AsyncLocalStorage-isolated, same process. */
|
|
96
|
+
export interface InProcessTeammateTaskState extends TaskStateBase {
|
|
97
|
+
type: "in_process_teammate";
|
|
98
|
+
teamName: string;
|
|
99
|
+
agentName: string;
|
|
100
|
+
/** Teammate's independent permission mode. */
|
|
101
|
+
permissionMode: string;
|
|
102
|
+
/** Async mailbox for coordinator ↔ worker communication. */
|
|
103
|
+
mailboxId?: string;
|
|
104
|
+
}
|
|
105
|
+
/** A single dream agent turn — text output + tool use count. */
|
|
106
|
+
export interface DreamTurn {
|
|
107
|
+
text: string;
|
|
108
|
+
toolUseCount: number;
|
|
109
|
+
}
|
|
110
|
+
/** Dream phase lifecycle — CC alignment. */
|
|
111
|
+
export type DreamPhase = "starting" | "updating" | "completed" | "failed";
|
|
112
|
+
/** Dream task — background memory consolidation agent (CC autoDream parity). */
|
|
113
|
+
export interface DreamTaskState extends TaskStateBase {
|
|
114
|
+
type: "dream";
|
|
115
|
+
sessionId: string;
|
|
116
|
+
/** Current dream phase. */
|
|
117
|
+
phase: DreamPhase;
|
|
118
|
+
/** Number of sessions being reviewed. */
|
|
119
|
+
sessionsReviewing: number;
|
|
120
|
+
/** Memory files touched by the dream agent. */
|
|
121
|
+
filesTouched: string[];
|
|
122
|
+
/** Dream agent turn history (capped). */
|
|
123
|
+
turns: DreamTurn[];
|
|
124
|
+
/** Stashed lock mtime for rollback on failure. */
|
|
125
|
+
priorLockMtime: number;
|
|
126
|
+
}
|
|
127
|
+
/** Placeholder for planned task types. */
|
|
128
|
+
export interface PlannedTaskState extends TaskStateBase {
|
|
129
|
+
type: "local_workflow" | "monitor_mcp";
|
|
130
|
+
}
|
|
131
|
+
/** Union of all concrete task states. */
|
|
132
|
+
export type TaskState = LocalBashTaskState | LocalAgentTaskState | RemoteAgentTaskState | InProcessTeammateTaskState | DreamTaskState | PlannedTaskState;
|
|
133
|
+
/**
|
|
134
|
+
* Filter available tools by permission role.
|
|
135
|
+
*
|
|
136
|
+
* @param role - The agent's permission role
|
|
137
|
+
* @param availableTools - Full set of tool names
|
|
138
|
+
* @returns Filtered tool names appropriate for the role
|
|
139
|
+
*/
|
|
140
|
+
export declare function filterToolsByRole(role: PermissionRole, availableTools: string[]): string[];
|
|
141
|
+
/** Create a new task state with defaults populated. */
|
|
142
|
+
export declare function createTaskState(overrides: Pick<TaskStateBase, "taskId" | "type" | "label"> & Partial<TaskStateBase>): TaskStateBase;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface OpenAiToolCall {
|
|
2
|
+
id: string;
|
|
3
|
+
type: "function";
|
|
4
|
+
function: {
|
|
5
|
+
name: string;
|
|
6
|
+
arguments: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface OpenAiChatToolCallRef {
|
|
10
|
+
id?: string;
|
|
11
|
+
function?: {
|
|
12
|
+
name?: string;
|
|
13
|
+
arguments?: string;
|
|
14
|
+
};
|
|
15
|
+
name?: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface OpenAiChatMessageLike {
|
|
19
|
+
role: string;
|
|
20
|
+
content?: unknown;
|
|
21
|
+
tool_calls?: OpenAiChatToolCallRef[];
|
|
22
|
+
tool_call_id?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface OpenAiResponsesItemLike {
|
|
26
|
+
type: string;
|
|
27
|
+
id?: string;
|
|
28
|
+
call_id?: string;
|
|
29
|
+
role?: string;
|
|
30
|
+
content?: unknown;
|
|
31
|
+
status?: string;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface ConversationRepairOptions {
|
|
35
|
+
stopReason?: string;
|
|
36
|
+
placeholderToolResult?: string;
|
|
37
|
+
placeholderFunctionCallOutput?: string;
|
|
38
|
+
forcedStopReasons?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
type ContentPart = {
|
|
41
|
+
type: string;
|
|
42
|
+
text?: string;
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
};
|
|
45
|
+
export type { ContentPart };
|
|
46
|
+
export declare function sanitizeOpenAiChatMessages<T extends OpenAiChatMessageLike>(messages: readonly T[]): T[];
|
|
47
|
+
export declare function ensureAssistantReasoningContent<T extends Record<string, unknown>>(messages: readonly T[], defaultValue?: string): T[];
|
|
48
|
+
export declare function stripForcedStopAssistantToolMetadata<T extends OpenAiChatMessageLike>(messages: readonly T[], options?: ConversationRepairOptions): T[];
|
|
49
|
+
export declare function injectDanglingToolCallPlaceholders<T extends OpenAiChatMessageLike>(messages: readonly T[], options?: ConversationRepairOptions): T[];
|
|
50
|
+
export declare function repairOpenAiChatConversation<T extends OpenAiChatMessageLike>(messages: readonly T[], options?: ConversationRepairOptions): T[];
|
|
51
|
+
export declare function downgradeOpenAiFunctionCallReasoningPairs<T extends {
|
|
52
|
+
role?: unknown;
|
|
53
|
+
content?: unknown;
|
|
54
|
+
toolCallId?: unknown;
|
|
55
|
+
toolUseId?: unknown;
|
|
56
|
+
}>(messages: readonly T[]): T[];
|
|
57
|
+
export declare function downgradeOpenAiReasoningBlocks<T extends {
|
|
58
|
+
role?: unknown;
|
|
59
|
+
content?: unknown;
|
|
60
|
+
}>(messages: readonly T[]): T[];
|
|
61
|
+
export declare function repairOpenAiResponsesItems<T extends OpenAiResponsesItemLike>(items: readonly T[], options?: ConversationRepairOptions): T[];
|