agent-afk 5.97.8 → 5.99.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/agent/fast-mode.d.ts +24 -0
- package/dist/agent/providers/anthropic-direct/auth.d.ts +1 -1
- package/dist/agent/providers/anthropic-direct/beta-headers.d.ts +10 -0
- package/dist/agent/providers/anthropic-direct/index.d.ts +3 -49
- package/dist/agent/providers/anthropic-direct/loop/round-request.d.ts +2 -1
- package/dist/agent/providers/anthropic-direct/pricing.d.ts +6 -1
- package/dist/agent/providers/anthropic-direct/provider-context.d.ts +31 -0
- package/dist/agent/providers/anthropic-direct/provider-grants.d.ts +16 -0
- package/dist/agent/providers/anthropic-direct/provider-options.d.ts +2 -0
- package/dist/agent/providers/anthropic-direct/provider-query-build.d.ts +4 -0
- package/dist/agent/providers/anthropic-direct/provider-query-setup.d.ts +26 -0
- package/dist/agent/providers/anthropic-direct/provider-runtime.d.ts +46 -0
- package/dist/agent/providers/anthropic-direct/provider-schemas.d.ts +3 -0
- package/dist/agent/providers/anthropic-direct/query/auth-retry-tier.d.ts +5 -0
- package/dist/agent/providers/anthropic-direct/query/overload-pause-tier.d.ts +4 -0
- package/dist/agent/providers/anthropic-direct/query/retry-constants.d.ts +6 -0
- package/dist/agent/providers/anthropic-direct/query/retry-context.d.ts +20 -0
- package/dist/agent/providers/anthropic-direct/query/retry-layer.d.ts +4 -8
- package/dist/agent/providers/anthropic-direct/query/turn-request.d.ts +31 -0
- package/dist/agent/providers/anthropic-direct/query/usage-limit-pause.d.ts +5 -0
- package/dist/agent/providers/anthropic-direct/query/usage-limit-tier.d.ts +4 -0
- package/dist/agent/providers/anthropic-direct/query-capabilities.d.ts +6 -0
- package/dist/agent/providers/anthropic-direct/query-events.d.ts +2 -0
- package/dist/agent/providers/anthropic-direct/query-live-updates.d.ts +21 -0
- package/dist/agent/providers/anthropic-direct/query-maintenance.d.ts +13 -0
- package/dist/agent/providers/anthropic-direct/query-options.d.ts +42 -0
- package/dist/agent/providers/anthropic-direct/query-runtime.d.ts +53 -0
- package/dist/agent/providers/anthropic-direct/query-system.d.ts +7 -0
- package/dist/agent/providers/anthropic-direct/query-turn-driver.d.ts +30 -0
- package/dist/agent/providers/anthropic-direct/query.d.ts +2 -88
- package/dist/agent/providers/anthropic-direct/request-types.d.ts +56 -0
- package/dist/agent/providers/anthropic-direct/types.d.ts +6 -58
- package/dist/agent/providers/anthropic-direct/usage.d.ts +4 -0
- package/dist/cli/commands/interactive/bootstrap-providers.d.ts +2 -0
- package/dist/cli/commands/interactive/bootstrap-slash-context.d.ts +5 -0
- package/dist/cli/provider-parser.d.ts +12 -0
- package/dist/cli/shared-helpers.d.ts +3 -18
- package/dist/cli/slash/commands/fast.d.ts +2 -0
- package/dist/cli/slash/types.d.ts +3 -0
- package/dist/cli/system-prompt.d.ts +8 -0
- package/dist/cli.mjs +702 -702
- package/dist/index.mjs +319 -319
- package/dist/telegram.mjs +276 -276
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type FastModePreference = 'on' | 'off';
|
|
2
|
+
export type FastExecutionPath = 'top-level' | 'child' | 'subagent' | 'skill' | 'compaction' | 'summarization' | 'one-shot' | 'auxiliary';
|
|
3
|
+
export type FastModeInactiveReason = 'preference-off' | 'unsupported-provider' | 'custom-endpoint' | 'excluded-execution-path' | 'unsupported-model';
|
|
4
|
+
export interface FastModeContext {
|
|
5
|
+
resolvedModelId: string;
|
|
6
|
+
providerFamily: string;
|
|
7
|
+
hasCustomEndpoint: boolean;
|
|
8
|
+
executionPath: FastExecutionPath;
|
|
9
|
+
}
|
|
10
|
+
export type FastModeStatus = Readonly<{
|
|
11
|
+
preference: FastModePreference;
|
|
12
|
+
effective: boolean;
|
|
13
|
+
reason?: FastModeInactiveReason;
|
|
14
|
+
}>;
|
|
15
|
+
export type FastTurnDecision = FastModeStatus;
|
|
16
|
+
export declare function resolveFastModeStatus(preference: FastModePreference, context: FastModeContext): FastModeStatus;
|
|
17
|
+
export declare class FastModeController {
|
|
18
|
+
private preference;
|
|
19
|
+
constructor(initial?: FastModePreference);
|
|
20
|
+
getPreference(): FastModePreference;
|
|
21
|
+
setPreference(preference: FastModePreference): void;
|
|
22
|
+
resolveStatus(context: FastModeContext): FastModeStatus;
|
|
23
|
+
snapshotTurn(context: FastModeContext): FastTurnDecision;
|
|
24
|
+
}
|
|
@@ -14,5 +14,5 @@ export declare function buildClientOptions(token: string, mode: AuthMode, baseUr
|
|
|
14
14
|
baseURL?: string;
|
|
15
15
|
fetch?: typeof fetch;
|
|
16
16
|
};
|
|
17
|
-
export declare function buildRequestHeaders(mode: AuthMode, sessionId: string, requestId: string, withEffort?: boolean, extendedCacheTtl?: boolean): Record<string, string>;
|
|
17
|
+
export declare function buildRequestHeaders(mode: AuthMode, sessionId: string, requestId: string, withEffort?: boolean, extendedCacheTtl?: boolean, withFast?: boolean): Record<string, string>;
|
|
18
18
|
export declare function buildSystemPrefix(mode: AuthMode): ContentBlockParam[] | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const FAST_MODE_BETA = "fast-mode-2026-02-01";
|
|
2
|
+
export interface BetaHeaderOptions {
|
|
3
|
+
oauthEntries?: readonly string[];
|
|
4
|
+
effort?: boolean;
|
|
5
|
+
extendedCacheTtl?: boolean;
|
|
6
|
+
fast?: boolean;
|
|
7
|
+
effortEntry: string;
|
|
8
|
+
extendedCacheEntry: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function composeBetaHeader(options: BetaHeaderOptions): string | undefined;
|
|
@@ -1,49 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
export { __setAnthropicClientFactory, type AnthropicClientFactory, type AnthropicDirectProviderOptions, } from './provider-options.js';
|
|
5
|
-
export declare class AnthropicDirectProvider implements ModelProvider {
|
|
6
|
-
readonly name = "anthropic-direct";
|
|
7
|
-
private readonly externalTools;
|
|
8
|
-
private readonly memoryStore;
|
|
9
|
-
private readonly providerFactory?;
|
|
10
|
-
private readonly skillExecutor?;
|
|
11
|
-
private readonly schemas;
|
|
12
|
-
private readonly hookRegistry;
|
|
13
|
-
private readonly permissions;
|
|
14
|
-
private readonly canUseTool;
|
|
15
|
-
private readonly subagentExecutor;
|
|
16
|
-
private readonly composeExecutor;
|
|
17
|
-
private readonly surface;
|
|
18
|
-
private readonly declaredSurface;
|
|
19
|
-
private readonly readOnlyMemory;
|
|
20
|
-
private readonly readOnlyBash;
|
|
21
|
-
private readonly mcpManager;
|
|
22
|
-
private readonly customTools;
|
|
23
|
-
private _sharedReadRoots;
|
|
24
|
-
private _sharedWriteRoots;
|
|
25
|
-
private _currentPermissionMode;
|
|
26
|
-
private _initialResolveBase;
|
|
27
|
-
private _currentCwd;
|
|
28
|
-
private _mcpToolsCache;
|
|
29
|
-
private _mcpHandlersCache;
|
|
30
|
-
private _presenceSessionId;
|
|
31
|
-
private _mintedSessionId;
|
|
32
|
-
constructor(opts?: AnthropicDirectProviderOptions);
|
|
33
|
-
private buildDispatcher;
|
|
34
|
-
close(): void;
|
|
35
|
-
complete(args: ProviderCompleteArgs): Promise<string>;
|
|
36
|
-
private ensureSharedRoots;
|
|
37
|
-
private readonly grantManager;
|
|
38
|
-
addReadRoot(absPath: string, source?: 'slash' | 'tool', sessionId?: string): void;
|
|
39
|
-
addWriteRoot(absPath: string, source?: 'slash' | 'tool', sessionId?: string): void;
|
|
40
|
-
revokeRoot(absPath: string, source?: 'slash' | 'tool', sessionId?: string): void;
|
|
41
|
-
getGrants(): {
|
|
42
|
-
resolveBase: string | undefined;
|
|
43
|
-
readRoots: string[];
|
|
44
|
-
writeRoots: string[];
|
|
45
|
-
allowAll: boolean;
|
|
46
|
-
};
|
|
47
|
-
query(args: ProviderQueryArgs): ProviderQuery;
|
|
48
|
-
}
|
|
49
|
-
export declare const anthropicDirectProvider: ModelProvider;
|
|
1
|
+
export { AnthropicDirectProvider, anthropicDirectProvider, resolveEffort, resolveMaxTokens, resolveThinkingParam, __setAnthropicClientFactory, } from './provider-runtime.js';
|
|
2
|
+
export { AnthropicDirectQuery } from './query-runtime.js';
|
|
3
|
+
export type { AnthropicClientFactory, AnthropicDirectProviderOptions, } from './provider-runtime.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProviderEvent } from '../../../provider.js';
|
|
2
|
-
import type { AnthropicToolDef, RunTurnInput, WireToolDef } from '../types.js';
|
|
2
|
+
import type { AnthropicMessagesCreateParams, AnthropicToolDef, RunTurnInput, WireToolDef } from '../types.js';
|
|
3
3
|
import { type FirstByteTimeoutHandle } from '../../shared/first-byte-timeout.js';
|
|
4
4
|
import { type StreamStallHandle } from '../../shared/stream-stall-timeout.js';
|
|
5
5
|
import { type RoundRetryBudget } from './retry-budget.js';
|
|
@@ -25,4 +25,5 @@ export interface OpenRoundContext {
|
|
|
25
25
|
ttfbTimeoutMs: number;
|
|
26
26
|
stallTimeoutMs: number;
|
|
27
27
|
}
|
|
28
|
+
export declare function buildRoundParams(input: Pick<RunTurnInput, 'model' | 'maxTokens' | 'messages' | 'system' | 'tools' | 'thinking' | 'effort' | 'fastMode'>): AnthropicMessagesCreateParams;
|
|
28
29
|
export declare function openRound({ input, turn, retry, ttfbTimeoutMs, stallTimeoutMs, }: OpenRoundContext): AsyncGenerator<ProviderEvent, OpenRoundResult, void>;
|
|
@@ -10,4 +10,9 @@ export interface CacheWriteSplit {
|
|
|
10
10
|
ephemeral5m: number;
|
|
11
11
|
ephemeral1h: number;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export type AnthropicSpeed = 'standard' | 'fast';
|
|
14
|
+
export interface SpeedPricingContext {
|
|
15
|
+
requestSpeed?: AnthropicSpeed;
|
|
16
|
+
responseSpeed?: AnthropicSpeed;
|
|
17
|
+
}
|
|
18
|
+
export declare function deriveCallCostUsd(model: string, inputTokens: number, outputTokens: number, cachedInputTokens: number, cacheCreationTokens: number, cacheWriteSplit?: CacheWriteSplit, speed?: SpeedPricingContext): number | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CanUseTool } from '../../types/sdk-types.js';
|
|
2
|
+
import type { SessionToolDispatcher } from '../../tools/dispatcher.js';
|
|
3
|
+
import type { ToolDispatcher } from './tool-dispatcher.js';
|
|
4
|
+
import type { SkillExecutor } from '../../tools/skill-executor.js';
|
|
5
|
+
import type { AnthropicClientFactory } from './provider-options.js';
|
|
6
|
+
import type { BuildDispatcherOptions } from './build-dispatcher.js';
|
|
7
|
+
export interface ProviderQueryContext {
|
|
8
|
+
readonly externalTools: ToolDispatcher | undefined;
|
|
9
|
+
readonly providerFactory: AnthropicClientFactory | undefined;
|
|
10
|
+
readonly skillExecutor: SkillExecutor | undefined;
|
|
11
|
+
readonly subagentExecutor: import('../../tools/subagent-executor.js').SubagentExecutor | undefined;
|
|
12
|
+
readonly composeExecutor: import('../../tools/compose-executor.js').ComposeExecutor | undefined;
|
|
13
|
+
readonly canUseTool: CanUseTool | undefined;
|
|
14
|
+
readonly surface: string;
|
|
15
|
+
readonly declaredSurface: string | undefined;
|
|
16
|
+
readonly readOnlyMemory: boolean;
|
|
17
|
+
readonly mcpManager: import('../../mcp/index.js').McpManager | undefined;
|
|
18
|
+
readonly fastModeController: import('../../fast-mode.js').FastModeController | undefined;
|
|
19
|
+
getSharedReadRoots(): string[] | undefined;
|
|
20
|
+
getSharedWriteRoots(): string[] | undefined;
|
|
21
|
+
getCurrentCwd(): string | undefined;
|
|
22
|
+
setCurrentCwd(cwd: string | undefined): void;
|
|
23
|
+
getCurrentPermissionMode(): string;
|
|
24
|
+
setCurrentPermissionMode(mode: string): void;
|
|
25
|
+
getMintedSessionId(): string | null;
|
|
26
|
+
setMintedSessionId(v: string | null): void;
|
|
27
|
+
getPresenceSessionId(): string | null;
|
|
28
|
+
setPresenceSessionId(v: string | null): void;
|
|
29
|
+
ensureSharedRoots(cwd?: string): void;
|
|
30
|
+
buildDispatcher(permissionMode: string, opts?: BuildDispatcherOptions): SessionToolDispatcher;
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PathGrantManager } from '../../tools/grant-manager.js';
|
|
2
|
+
export declare class ProviderGrantState {
|
|
3
|
+
private _readRoots;
|
|
4
|
+
private _writeRoots;
|
|
5
|
+
private _initialResolveBase;
|
|
6
|
+
private _currentCwd;
|
|
7
|
+
private _permissionMode;
|
|
8
|
+
readonly manager: PathGrantManager;
|
|
9
|
+
get readRoots(): string[] | undefined;
|
|
10
|
+
get writeRoots(): string[] | undefined;
|
|
11
|
+
get currentCwd(): string | undefined;
|
|
12
|
+
set currentCwd(cwd: string | undefined);
|
|
13
|
+
get permissionMode(): string;
|
|
14
|
+
set permissionMode(mode: string);
|
|
15
|
+
ensureInitialized(cwd?: string): void;
|
|
16
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { SkillExecutor } from '../../tools/skill-executor.js';
|
|
|
7
7
|
import type { ComposeExecutor } from '../../tools/compose-executor.js';
|
|
8
8
|
import type { ToolPermissionConfig } from '../../tools/permissions.js';
|
|
9
9
|
import type { ToolDispatcher } from './tool-dispatcher.js';
|
|
10
|
+
import type { FastModeController } from '../../fast-mode.js';
|
|
10
11
|
export type AnthropicClientFactory = (opts: ({
|
|
11
12
|
authToken: string;
|
|
12
13
|
} | {
|
|
@@ -18,6 +19,7 @@ export type AnthropicClientFactory = (opts: ({
|
|
|
18
19
|
export declare function __setAnthropicClientFactory(factory: AnthropicClientFactory | null): void;
|
|
19
20
|
export declare function getClientFactory(): AnthropicClientFactory | null;
|
|
20
21
|
export interface AnthropicDirectProviderOptions {
|
|
22
|
+
fastModeController?: FastModeController;
|
|
21
23
|
tools?: ToolDispatcher;
|
|
22
24
|
hookRegistry?: HookRegistry;
|
|
23
25
|
permissions?: ToolPermissionConfig;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProviderQuery, ProviderQueryArgs } from '../../provider.js';
|
|
2
|
+
import type { ProviderQueryContext } from './provider-context.js';
|
|
3
|
+
import type { QuerySetupResult } from './provider-query-setup.js';
|
|
4
|
+
export declare function buildProviderQuery(ctx: ProviderQueryContext, args: ProviderQueryArgs, setup: QuerySetupResult): ProviderQuery;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { AgentConfig } from '../../types/config-types.js';
|
|
3
|
+
import type { ProviderQueryArgs } from '../../provider.js';
|
|
4
|
+
import { setUpQueryClient } from './query/client-setup.js';
|
|
5
|
+
import { wireQueryDispatcher } from './query/dispatcher-wiring.js';
|
|
6
|
+
import { assembleQueryPrompt } from './query/prompt-assembly.js';
|
|
7
|
+
import type { ProviderQueryContext } from './provider-context.js';
|
|
8
|
+
export interface QuerySetupResult {
|
|
9
|
+
client: Anthropic;
|
|
10
|
+
authMode: import('./types.js').AuthMode;
|
|
11
|
+
localMode: boolean;
|
|
12
|
+
model: string;
|
|
13
|
+
maxTokens: number;
|
|
14
|
+
cwd: string;
|
|
15
|
+
systemPrefix: Awaited<ReturnType<typeof setUpQueryClient>>['systemPrefix'];
|
|
16
|
+
throttleQueue: ReturnType<typeof setUpQueryClient>['throttleQueue'];
|
|
17
|
+
tokenRefresher: ReturnType<typeof setUpQueryClient>['tokenRefresher'];
|
|
18
|
+
queryDispatcher: ReturnType<typeof wireQueryDispatcher>['queryDispatcher'];
|
|
19
|
+
runtimeStateSource: ReturnType<typeof wireQueryDispatcher>['runtimeStateSource'];
|
|
20
|
+
toolDefs: ReturnType<typeof wireQueryDispatcher>['toolDefs'];
|
|
21
|
+
resolvedSessionId: ReturnType<typeof wireQueryDispatcher>['resolvedSessionId'];
|
|
22
|
+
stableSystemPrefix: ReturnType<typeof assembleQueryPrompt>['stableSystemPrefix'];
|
|
23
|
+
toolSystemAppend: ReturnType<typeof assembleQueryPrompt>['toolSystemAppend'];
|
|
24
|
+
}
|
|
25
|
+
export declare function resolveUserSystem(sp: AgentConfig['systemPrompt']): string | null;
|
|
26
|
+
export declare function setUpQuerySession(ctx: ProviderQueryContext, args: ProviderQueryArgs, providerName: string, defaultModel: string): QuerySetupResult;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ModelProvider, ProviderQuery, ProviderQueryArgs, ProviderCompleteArgs } from '../../provider.js';
|
|
2
|
+
export { resolveEffort, resolveMaxTokens, resolveThinkingParam } from './resolve-params.js';
|
|
3
|
+
import { type AnthropicDirectProviderOptions } from './provider-options.js';
|
|
4
|
+
export { __setAnthropicClientFactory, type AnthropicClientFactory, type AnthropicDirectProviderOptions, } from './provider-options.js';
|
|
5
|
+
export { resolveUserSystem } from './provider-query-setup.js';
|
|
6
|
+
export declare class AnthropicDirectProvider implements ModelProvider {
|
|
7
|
+
readonly name = "anthropic-direct";
|
|
8
|
+
private readonly externalTools;
|
|
9
|
+
private readonly memoryStore;
|
|
10
|
+
private readonly providerFactory?;
|
|
11
|
+
private readonly skillExecutor?;
|
|
12
|
+
private readonly schemas;
|
|
13
|
+
private readonly hookRegistry;
|
|
14
|
+
private readonly permissions;
|
|
15
|
+
private readonly canUseTool;
|
|
16
|
+
private readonly subagentExecutor;
|
|
17
|
+
private readonly composeExecutor;
|
|
18
|
+
private readonly surface;
|
|
19
|
+
private readonly declaredSurface;
|
|
20
|
+
private readonly readOnlyMemory;
|
|
21
|
+
private readonly readOnlyBash;
|
|
22
|
+
private readonly mcpManager;
|
|
23
|
+
private readonly customTools;
|
|
24
|
+
private readonly fastModeController?;
|
|
25
|
+
private readonly grants;
|
|
26
|
+
private _mcpToolsCache;
|
|
27
|
+
private _mcpHandlersCache;
|
|
28
|
+
private _presenceSessionId;
|
|
29
|
+
private _mintedSessionId;
|
|
30
|
+
constructor(opts?: AnthropicDirectProviderOptions);
|
|
31
|
+
private buildDispatcher;
|
|
32
|
+
close(): void;
|
|
33
|
+
complete(args: ProviderCompleteArgs): Promise<string>;
|
|
34
|
+
addReadRoot(absPath: string, source?: 'slash' | 'tool', sessionId?: string): void;
|
|
35
|
+
addWriteRoot(absPath: string, source?: 'slash' | 'tool', sessionId?: string): void;
|
|
36
|
+
revokeRoot(absPath: string, source?: 'slash' | 'tool', sessionId?: string): void;
|
|
37
|
+
getGrants(): {
|
|
38
|
+
resolveBase: string | undefined;
|
|
39
|
+
readRoots: string[];
|
|
40
|
+
writeRoots: string[];
|
|
41
|
+
allowAll: boolean;
|
|
42
|
+
};
|
|
43
|
+
private queryContext;
|
|
44
|
+
query(args: ProviderQueryArgs): ProviderQuery;
|
|
45
|
+
}
|
|
46
|
+
export declare const anthropicDirectProvider: ModelProvider;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProviderEvent } from '../../../provider.js';
|
|
2
|
+
import type { RunTurnInput } from '../types.js';
|
|
3
|
+
import type { RetryTierContext } from './retry-context.js';
|
|
4
|
+
export declare function isRetryableAuth(ctx: RetryTierContext, error: Error): boolean;
|
|
5
|
+
export declare function turnWithAuthRetry(ctx: RetryTierContext, runInput: RunTurnInput, isClosed: () => boolean): AsyncGenerator<ProviderEvent, void, void>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProviderEvent } from '../../../provider.js';
|
|
2
|
+
import type { RunTurnInput } from '../types.js';
|
|
3
|
+
import type { RetryTierContext, TierGenerator } from './retry-context.js';
|
|
4
|
+
export declare function turnWithOverloadPause(ctx: RetryTierContext, runInput: RunTurnInput, isClosed: () => boolean, next: TierGenerator): AsyncGenerator<ProviderEvent, void, void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const TWO_HOURS_MS: number;
|
|
2
|
+
export declare const RATE_LIMIT_TRANSIENT_MAX_RETRIES = 3;
|
|
3
|
+
export declare const RATE_LIMIT_RETRY_MAX_WAIT_MS = 120000;
|
|
4
|
+
export declare const RATE_LIMIT_RETRY_DEFAULT_WAIT_MS = 5000;
|
|
5
|
+
export declare const RATE_LIMIT_RETRY_JITTER_MS = 1000;
|
|
6
|
+
export declare const NO_TS_RETRY_INTERVAL_MS: number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ProviderEvent } from '../../../provider.js';
|
|
3
|
+
import type { AuthMode, RunTurnInput } from '../types.js';
|
|
4
|
+
export type UsageLimitWaitResult = 'aborted' | 'timer' | 'hot-swap';
|
|
5
|
+
export type TierGenerator = (ctx: RetryTierContext, runInput: RunTurnInput, isClosed: () => boolean) => AsyncGenerator<ProviderEvent, void, void>;
|
|
6
|
+
export interface RetryTierContext {
|
|
7
|
+
readonly authMode: AuthMode;
|
|
8
|
+
readonly surface: string | undefined;
|
|
9
|
+
readonly autoResumeOnUsageLimit: boolean;
|
|
10
|
+
readonly tokenRefresher: (() => Promise<Anthropic | null>) | undefined;
|
|
11
|
+
getClient(): Anthropic;
|
|
12
|
+
rotateHeaders(runInput: Pick<RunTurnInput, 'effort' | 'fastMode'>): Record<string, string>;
|
|
13
|
+
forceClientRefresh(): Promise<{
|
|
14
|
+
accountId: string;
|
|
15
|
+
swapped: boolean;
|
|
16
|
+
} | null>;
|
|
17
|
+
getUsageLimitWait(): Promise<UsageLimitWaitResult> | null;
|
|
18
|
+
setUsageLimitWait(p: Promise<UsageLimitWaitResult> | null): void;
|
|
19
|
+
markCredentialSnapshotStale(): void;
|
|
20
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
2
|
import type { ProviderEvent } from '../../../provider.js';
|
|
3
3
|
import type { AuthMode, RunTurnInput } from '../types.js';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export declare const RATE_LIMIT_RETRY_MAX_WAIT_MS = 120000;
|
|
4
|
+
export { TWO_HOURS_MS, RATE_LIMIT_TRANSIENT_MAX_RETRIES, RATE_LIMIT_RETRY_MAX_WAIT_MS, } from './retry-constants.js';
|
|
5
|
+
export type { RetryTierContext, UsageLimitWaitResult } from './retry-context.js';
|
|
7
6
|
export interface RetryLayerOptions {
|
|
8
7
|
client: Anthropic;
|
|
9
8
|
authMode: AuthMode;
|
|
@@ -26,15 +25,12 @@ export declare class RetryLayer {
|
|
|
26
25
|
private credentialSnapshotStale;
|
|
27
26
|
constructor(opts: RetryLayerOptions);
|
|
28
27
|
get client(): Anthropic;
|
|
29
|
-
private rotateHeaders;
|
|
30
28
|
get authMode(): AuthMode;
|
|
29
|
+
private rotateHeaders;
|
|
30
|
+
private tierContext;
|
|
31
31
|
forceClientRefresh(): Promise<{
|
|
32
32
|
accountId: string;
|
|
33
33
|
swapped: boolean;
|
|
34
34
|
} | null>;
|
|
35
35
|
turnWithRetries(runInput: RunTurnInput, isClosed: () => boolean): AsyncGenerator<ProviderEvent, void, void>;
|
|
36
|
-
private turnWithOverloadPause;
|
|
37
|
-
private turnWithUsageLimitRetry;
|
|
38
|
-
private turnWithAuthRetry;
|
|
39
|
-
private isRetryableAuth;
|
|
40
36
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources';
|
|
2
|
+
import type { FastModeController, FastTurnDecision } from '../../../fast-mode.js';
|
|
3
|
+
import type { AnthropicClientLike, AnthropicToolDef, RunTurnInput, ToolDispatcherLike } from '../types.js';
|
|
4
|
+
export interface TurnRequestInput {
|
|
5
|
+
client: AnthropicClientLike;
|
|
6
|
+
messages: RunTurnInput['messages'];
|
|
7
|
+
system: ContentBlockParam[] | string | null;
|
|
8
|
+
tools: AnthropicToolDef[] | null;
|
|
9
|
+
toolDispatcher: ToolDispatcherLike;
|
|
10
|
+
model: string;
|
|
11
|
+
maxTokens: number;
|
|
12
|
+
signal: AbortSignal;
|
|
13
|
+
authMode: import('../types.js').AuthMode;
|
|
14
|
+
sessionId: string;
|
|
15
|
+
requestId: string;
|
|
16
|
+
fastModeController?: FastModeController;
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
thinking?: RunTurnInput['thinking'];
|
|
19
|
+
effort?: RunTurnInput['effort'];
|
|
20
|
+
maxToolUseIterations?: number;
|
|
21
|
+
traceWriter?: RunTurnInput['traceWriter'];
|
|
22
|
+
subagentId?: string;
|
|
23
|
+
throttleQueue?: RunTurnInput['throttleQueue'];
|
|
24
|
+
onUsageProgress?: RunTurnInput['onUsageProgress'];
|
|
25
|
+
}
|
|
26
|
+
export declare function prepareTurnRequest(input: TurnRequestInput): {
|
|
27
|
+
decision: FastTurnDecision | undefined;
|
|
28
|
+
runInput: RunTurnInput;
|
|
29
|
+
};
|
|
30
|
+
export declare const FAST_ERROR_PREFIX = "[Fast mode requested; no standard-mode fallback will be attempted]";
|
|
31
|
+
export declare function annotateFastError(error: unknown, fast: boolean): Error;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProviderEvent } from '../../../provider.js';
|
|
2
|
+
import type { RunTurnInput } from '../types.js';
|
|
3
|
+
import type { RetryTierContext, TierGenerator } from './retry-context.js';
|
|
4
|
+
export declare function usageLimitNoTimestampPause(ctx: RetryTierContext, runInput: RunTurnInput, isClosed: () => boolean, next: TierGenerator, pendingErrorEvent: ProviderEvent): AsyncGenerator<ProviderEvent, void, void>;
|
|
5
|
+
export declare function usageLimitResetPause(ctx: RetryTierContext, runInput: RunTurnInput, isClosed: () => boolean, next: TierGenerator, pendingErrorEvent: ProviderEvent, resetsAt: Date): AsyncGenerator<ProviderEvent, void, void>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProviderEvent } from '../../../provider.js';
|
|
2
|
+
import type { RunTurnInput } from '../types.js';
|
|
3
|
+
import type { RetryTierContext, TierGenerator } from './retry-context.js';
|
|
4
|
+
export declare function turnWithUsageLimitRetry(ctx: RetryTierContext, runInput: RunTurnInput, isClosed: () => boolean, next: TierGenerator): AsyncGenerator<ProviderEvent, void, void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProviderAccountInfo, ProviderContextUsage, ProviderMcpServerStatus } from '../../provider.js';
|
|
2
|
+
import type { SessionState } from './query/session-state.js';
|
|
3
|
+
import type { AuthMode } from './types.js';
|
|
4
|
+
export declare function computeContextUsage(state: SessionState): ProviderContextUsage;
|
|
5
|
+
export declare function mcpServerStatusList(mcpManager: import('../../mcp/index.js').McpManager | undefined): ProviderMcpServerStatus[];
|
|
6
|
+
export declare function accountInfoFor(authMode: AuthMode): ProviderAccountInfo;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ToolDispatcher } from './tool-dispatcher.js';
|
|
2
|
+
import type { SessionState } from './query/session-state.js';
|
|
3
|
+
export declare function setLiveModel(state: SessionState, model?: string): void;
|
|
4
|
+
export declare function setLivePermissionMode(options: {
|
|
5
|
+
state: SessionState;
|
|
6
|
+
mode: string;
|
|
7
|
+
onPermissionMode?: (mode: string) => void;
|
|
8
|
+
}): void;
|
|
9
|
+
export declare function setLiveCwd(options: {
|
|
10
|
+
state: SessionState;
|
|
11
|
+
cwd: string;
|
|
12
|
+
cwdDependentsFactory?: (cwd: string) => {
|
|
13
|
+
userSystem: string;
|
|
14
|
+
dispatcher: ToolDispatcher;
|
|
15
|
+
};
|
|
16
|
+
}): void;
|
|
17
|
+
export declare function setLiveSystemPrompt(options: {
|
|
18
|
+
state: SessionState;
|
|
19
|
+
basePrompt: string | undefined;
|
|
20
|
+
systemPromptRebuildFactory?: (basePrompt: string | undefined) => string;
|
|
21
|
+
}): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ProviderCompactResult, ProviderRewindConversationResult, RewindTarget } from '../../provider.js';
|
|
2
|
+
import type { AbortCoordinator } from '../shared/abort-coordinator.js';
|
|
3
|
+
import type { RetryLayer } from './query/retry-layer.js';
|
|
4
|
+
import type { SessionState } from './query/session-state.js';
|
|
5
|
+
export declare function compactQueryHistory(options: {
|
|
6
|
+
state: SessionState;
|
|
7
|
+
abort: AbortCoordinator;
|
|
8
|
+
retry: RetryLayer;
|
|
9
|
+
initSessionId: string;
|
|
10
|
+
traceWriter?: import('../../trace/index.js').TraceWriter;
|
|
11
|
+
}): Promise<ProviderCompactResult>;
|
|
12
|
+
export declare function queryRewindTargets(state: SessionState): RewindTarget[];
|
|
13
|
+
export declare function rewindQueryConversation(state: SessionState, abort: AbortCoordinator, turnIndex: number): ProviderRewindConversationResult;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ContentBlockParam, MessageParam } from '@anthropic-ai/sdk/resources';
|
|
3
|
+
import type { ProviderModelInfo, ProviderUserTurn } from '../../provider.js';
|
|
4
|
+
import type { ToolDispatcher } from './tool-dispatcher.js';
|
|
5
|
+
import type { AnthropicToolDef, AuthMode } from './types.js';
|
|
6
|
+
import type { HookRegistry } from '../../hooks.js';
|
|
7
|
+
export interface AnthropicDirectQueryOptions {
|
|
8
|
+
client: Anthropic;
|
|
9
|
+
authMode: AuthMode;
|
|
10
|
+
promptStream: AsyncIterable<ProviderUserTurn>;
|
|
11
|
+
toolDispatcher: ToolDispatcher;
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
initialMessages?: MessageParam[];
|
|
14
|
+
model: string;
|
|
15
|
+
requestedModel?: string;
|
|
16
|
+
permissionMode?: string;
|
|
17
|
+
maxTokens: number;
|
|
18
|
+
tools: AnthropicToolDef[] | null;
|
|
19
|
+
userSystem: string | null;
|
|
20
|
+
systemPrefix: ContentBlockParam[] | null;
|
|
21
|
+
tokenRefresher?: () => Promise<Anthropic | null>;
|
|
22
|
+
thinking?: import('@anthropic-ai/sdk/resources').ThinkingConfigParam;
|
|
23
|
+
effort?: import('../../types/sdk-types.js').EffortLevel;
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
maxToolUseIterations?: number;
|
|
26
|
+
traceWriter?: import('../../trace/index.js').TraceWriter;
|
|
27
|
+
subagentId?: string;
|
|
28
|
+
autoResumeOnUsageLimit?: boolean;
|
|
29
|
+
surface?: string;
|
|
30
|
+
cwdDependentsFactory?: (cwd: string) => {
|
|
31
|
+
userSystem: string;
|
|
32
|
+
dispatcher: ToolDispatcher;
|
|
33
|
+
};
|
|
34
|
+
systemPromptRebuildFactory?: (basePrompt: string | undefined) => string;
|
|
35
|
+
onPermissionMode?: (mode: string) => void;
|
|
36
|
+
mcpManager?: import('../../mcp/index.js').McpManager;
|
|
37
|
+
autoCompactThreshold?: number;
|
|
38
|
+
hookRegistry?: HookRegistry;
|
|
39
|
+
throttleQueue?: import('./throttle-queue.js').ThrottleQueue;
|
|
40
|
+
fastModeController?: import('../../fast-mode.js').FastModeController;
|
|
41
|
+
}
|
|
42
|
+
export declare function starterModels(): ProviderModelInfo[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ProviderAccountInfo, ProviderAgentInfo, ProviderCommandInfo, ProviderCompactResult, ProviderContextUsage, ProviderEvent, ProviderMcpServerStatus, ProviderModelInfo, ProviderQuery, ProviderRewindConversationResult, ProviderRewindResult, RewindTarget } from '../../provider.js';
|
|
2
|
+
import type { AnthropicDirectQueryOptions } from './query-options.js';
|
|
3
|
+
export type { AnthropicDirectQueryOptions } from './query-options.js';
|
|
4
|
+
export declare class AnthropicDirectQuery implements ProviderQuery {
|
|
5
|
+
private readonly initSessionId;
|
|
6
|
+
private readonly promptStream;
|
|
7
|
+
private readonly maxTokens;
|
|
8
|
+
private readonly tools;
|
|
9
|
+
private readonly systemPrefix;
|
|
10
|
+
private readonly thinking?;
|
|
11
|
+
private readonly effort?;
|
|
12
|
+
private readonly baseUrl?;
|
|
13
|
+
private readonly maxToolUseIterations?;
|
|
14
|
+
private readonly traceWriter?;
|
|
15
|
+
private readonly subagentId?;
|
|
16
|
+
private readonly state;
|
|
17
|
+
private readonly abort;
|
|
18
|
+
private readonly retry;
|
|
19
|
+
private readonly cwdDependentsFactory?;
|
|
20
|
+
private readonly systemPromptRebuildFactory?;
|
|
21
|
+
private readonly onPermissionMode?;
|
|
22
|
+
private readonly mcpManager?;
|
|
23
|
+
private readonly hookRegistry?;
|
|
24
|
+
private readonly throttleQueue?;
|
|
25
|
+
private readonly fastModeController?;
|
|
26
|
+
constructor(opts: AnthropicDirectQueryOptions);
|
|
27
|
+
private turnDriverContext;
|
|
28
|
+
[Symbol.asyncIterator](): AsyncIterator<ProviderEvent>;
|
|
29
|
+
private composeSystem;
|
|
30
|
+
interrupt(reason?: import('../../abort-reason.js').ProviderAbortReason): Promise<void>;
|
|
31
|
+
private makeInterruptedTurnEvent;
|
|
32
|
+
setModel(model?: string): Promise<void>;
|
|
33
|
+
setPermissionMode(mode: string): Promise<void>;
|
|
34
|
+
setCwd(cwd: string): void;
|
|
35
|
+
setSystemPrompt(basePrompt: string | undefined): boolean;
|
|
36
|
+
supportedCommands(): Promise<ProviderCommandInfo[]>;
|
|
37
|
+
supportedModels(): Promise<ProviderModelInfo[]>;
|
|
38
|
+
supportedAgents(): Promise<ProviderAgentInfo[]>;
|
|
39
|
+
getContextUsage(): Promise<ProviderContextUsage>;
|
|
40
|
+
mcpServerStatus(): Promise<ProviderMcpServerStatus[]>;
|
|
41
|
+
accountInfo(): Promise<ProviderAccountInfo>;
|
|
42
|
+
reauth(): Promise<{
|
|
43
|
+
accountId: string;
|
|
44
|
+
swapped: boolean;
|
|
45
|
+
} | null>;
|
|
46
|
+
rewindFiles(_userMessageId: string, _options?: {
|
|
47
|
+
dryRun?: boolean;
|
|
48
|
+
}): Promise<ProviderRewindResult>;
|
|
49
|
+
compact(): Promise<ProviderCompactResult>;
|
|
50
|
+
listRewindTargets(): RewindTarget[];
|
|
51
|
+
rewindConversation(turnIndex: number): Promise<ProviderRewindConversationResult>;
|
|
52
|
+
close(): void;
|
|
53
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources';
|
|
2
|
+
import type { SessionState } from './query/session-state.js';
|
|
3
|
+
export declare function composeQuerySystem(options: {
|
|
4
|
+
state: SessionState;
|
|
5
|
+
systemPrefix: ContentBlockParam[] | null;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
}): ContentBlockParam[] | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ContentBlockParam } from '@anthropic-ai/sdk/resources';
|
|
2
|
+
import type { ProviderCompactResult, ProviderEvent, ProviderUserTurn } from '../../provider.js';
|
|
3
|
+
import type { AnthropicToolDef } from './types.js';
|
|
4
|
+
import type { SessionState } from './query/session-state.js';
|
|
5
|
+
import type { AbortCoordinator } from '../shared/abort-coordinator.js';
|
|
6
|
+
import type { RetryLayer } from './query/retry-layer.js';
|
|
7
|
+
import type { HookRegistry } from '../../hooks.js';
|
|
8
|
+
export interface TurnDriverContext {
|
|
9
|
+
readonly initSessionId: string;
|
|
10
|
+
readonly promptStream: AsyncIterable<ProviderUserTurn>;
|
|
11
|
+
readonly state: SessionState;
|
|
12
|
+
readonly abort: AbortCoordinator;
|
|
13
|
+
readonly retry: RetryLayer;
|
|
14
|
+
readonly maxTokens: number;
|
|
15
|
+
readonly tools: AnthropicToolDef[] | null;
|
|
16
|
+
readonly thinking: import('@anthropic-ai/sdk/resources').ThinkingConfigParam | undefined;
|
|
17
|
+
readonly effort: import('../../types/sdk-types.js').EffortLevel | undefined;
|
|
18
|
+
readonly baseUrl: string | undefined;
|
|
19
|
+
readonly maxToolUseIterations: number | undefined;
|
|
20
|
+
readonly traceWriter: import('../../trace/index.js').TraceWriter | undefined;
|
|
21
|
+
readonly subagentId: string | undefined;
|
|
22
|
+
readonly mcpManager: import('../../mcp/index.js').McpManager | undefined;
|
|
23
|
+
readonly hookRegistry: HookRegistry | undefined;
|
|
24
|
+
readonly throttleQueue: import('./throttle-queue.js').ThrottleQueue | undefined;
|
|
25
|
+
readonly fastModeController: import('../../fast-mode.js').FastModeController | undefined;
|
|
26
|
+
composeSystem(): ContentBlockParam[] | null;
|
|
27
|
+
makeInterruptedTurnEvent(): ProviderEvent;
|
|
28
|
+
compact(): Promise<ProviderCompactResult>;
|
|
29
|
+
}
|
|
30
|
+
export declare function driveTurns(ctx: TurnDriverContext): AsyncGenerator<ProviderEvent, void, void>;
|