@opencow-ai/opencow-agent-sdk 0.4.7 → 0.4.8
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/Tool.d.ts +1 -0
- package/dist/capabilities/SdkTool.d.ts +8 -0
- package/dist/capabilities/tools/ToolSearchTool/ToolSearchTool.d.ts +1 -1
- package/dist/cli.mjs +594 -485
- package/dist/client.js +543 -334
- package/dist/constants/envVars.d.ts +1 -0
- package/dist/controller/compact/autoCompact.d.ts +17 -1
- package/dist/controller/compact/reactiveCompact.d.ts +52 -0
- package/dist/controller/query/deps.d.ts +2 -1
- package/dist/controller/toolSearch.d.ts +20 -0
- package/dist/entrypoints/sdk/controlSchemas.d.ts +1 -0
- package/dist/entrypoints/sdk/coreSchemas.d.ts +2 -0
- package/dist/entrypoints/sdk/runtimeTypes.d.ts +19 -0
- package/dist/permissions/permissions.d.ts +15 -0
- package/dist/providers/codex/shim.d.ts +8 -0
- package/dist/providers/openai/shim.d.ts +17 -7
- package/dist/providers/shared/logging.d.ts +2 -2
- package/dist/providers/shared/model/providers.d.ts +5 -0
- package/dist/providers/shared/usage.d.ts +11 -0
- package/dist/query.d.ts +3 -0
- package/dist/sdk.js +543 -334
- package/dist/types/toolRuntime.d.ts +6 -0
- package/package.json +3 -3
|
@@ -106,6 +106,7 @@ export declare const ENV_VARS: {
|
|
|
106
106
|
readonly ENABLE_TASKS: EnvVarSpec;
|
|
107
107
|
readonly ENABLE_TELEMETRY: EnvVarSpec;
|
|
108
108
|
readonly ENABLE_TOKEN_USAGE_ATTACHMENT: EnvVarSpec;
|
|
109
|
+
readonly ENABLE_TOOL_SEARCH: EnvVarSpec;
|
|
109
110
|
readonly ENABLE_XAA: EnvVarSpec;
|
|
110
111
|
readonly ENHANCED_TELEMETRY_BETA: EnvVarSpec;
|
|
111
112
|
readonly ENTRYPOINT: EnvVarSpec;
|
|
@@ -2,7 +2,8 @@ import type { QuerySource } from '../../constants/querySource.js';
|
|
|
2
2
|
import type { ToolRuntimeContext } from '../../types/toolRuntime.js';
|
|
3
3
|
import type { Message } from '../../types/message.js';
|
|
4
4
|
import type { CacheSafeParams } from '../../session/forkedAgent.js';
|
|
5
|
-
import { type CompactionResult } from './compact.js';
|
|
5
|
+
import { type CompactionResult, compactConversation } from './compact.js';
|
|
6
|
+
import { trySessionMemoryCompaction } from './sessionMemoryCompact.js';
|
|
6
7
|
export declare function getEffectiveContextWindowSize(model: string, opts?: {
|
|
7
8
|
contextWindow?: number;
|
|
8
9
|
maxOutputTokens?: number;
|
|
@@ -41,3 +42,18 @@ export declare function autoCompactIfNeeded(messages: Message[], toolUseContext:
|
|
|
41
42
|
compactionResult?: CompactionResult;
|
|
42
43
|
consecutiveFailures?: number;
|
|
43
44
|
}>;
|
|
45
|
+
/**
|
|
46
|
+
* host 主动触发的手动压缩(用户的 `/compact`)。与 autoCompactIfNeeded 不同:
|
|
47
|
+
* 不看 token 阈值——总是立即压缩;并以非自动方式运行(isAutoCompact=false),
|
|
48
|
+
* 从而尊重自定义指令。其余策略与自动压缩一致:无指令时先试 session-memory 压缩
|
|
49
|
+
* (它不支持自定义指令),不可用再退回完整摘要压缩。
|
|
50
|
+
*
|
|
51
|
+
* deps 可注入,便于在不驱动真实摘要模型的前提下测试编排逻辑(沿用本仓 QueryDeps 思路)。
|
|
52
|
+
*/
|
|
53
|
+
export declare function manualCompact(messages: Message[], toolUseContext: ToolRuntimeContext, cacheSafeParams: CacheSafeParams, instructions?: string, deps?: {
|
|
54
|
+
compactConversation: typeof compactConversation;
|
|
55
|
+
trySessionMemoryCompaction: typeof trySessionMemoryCompaction;
|
|
56
|
+
}): Promise<{
|
|
57
|
+
wasCompacted: boolean;
|
|
58
|
+
compactionResult?: CompactionResult;
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reactive(撞墙后)上下文压缩 —— 413 "Prompt is too long" / 媒体过大的兜底。
|
|
3
|
+
*
|
|
4
|
+
* 主动压缩(autoCompact)在每轮开头按 token 阈值预判;但大 tool 输出能在同一 agent
|
|
5
|
+
* loop 内、两次检查之间把上下文顶爆 → 下一次 API 调用直接被上游拒(413/400
|
|
6
|
+
* "prompt is too long")。窗口估错(后端虚报 / openai 模型退回 200k 默认)时主动压缩
|
|
7
|
+
* 更是抓不住。本模块在 query loop 的流式阶段「withhold」住这类可恢复错误,turn 结束后由
|
|
8
|
+
* tryReactiveCompact 压缩 + 重试(单发防自旋:本 turn 试过一次就放弃,让错误浮现)。
|
|
9
|
+
*
|
|
10
|
+
* 复用 compactConversation(同主动压缩的摘要引擎,会 strip 图片 + 摘要旧消息),所以
|
|
11
|
+
* 媒体过大错误压缩后也能在重试时消失。query.ts 已接好 withhold/recovery/retry 状态机,
|
|
12
|
+
* 本模块只负责:判定可恢复 + 执行一次压缩。
|
|
13
|
+
*/
|
|
14
|
+
import type { AssistantMessage, Message } from '../../types/message.js';
|
|
15
|
+
import type { QuerySource } from '../../constants/querySource.js';
|
|
16
|
+
import type { CacheSafeParams } from '../../session/forkedAgent.js';
|
|
17
|
+
import { type CompactionResult, compactConversation } from './compact.js';
|
|
18
|
+
type WithholdableMessage = AssistantMessage | {
|
|
19
|
+
type?: string;
|
|
20
|
+
} | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Reactive 压缩是否启用。沿用用户的自动压缩开关:关掉自动压缩 = 连兜底也不做
|
|
23
|
+
* (尊重 DISABLE_AUTO_COMPACT / autoCompactEnabled=false 的「不要任何自动行为」语义)。
|
|
24
|
+
*/
|
|
25
|
+
export declare function isReactiveCompactEnabled(): boolean;
|
|
26
|
+
/** 流式阶段:这条消息是否是可兜底的 prompt-too-long(应 withhold 等待恢复)。 */
|
|
27
|
+
export declare function isWithheldPromptTooLong(message: WithholdableMessage): boolean;
|
|
28
|
+
/** 流式阶段:这条消息是否是可兜底的媒体过大错误(压缩 strip 图片后重试可恢复)。 */
|
|
29
|
+
export declare function isWithheldMediaSizeError(message: WithholdableMessage): boolean;
|
|
30
|
+
export interface TryReactiveCompactParams {
|
|
31
|
+
/** 本 turn 是否已经 reactive 压缩过一次(单发防自旋)。 */
|
|
32
|
+
hasAttempted: boolean;
|
|
33
|
+
querySource: QuerySource | undefined;
|
|
34
|
+
aborted: boolean;
|
|
35
|
+
messages: Message[];
|
|
36
|
+
cacheSafeParams: CacheSafeParams;
|
|
37
|
+
}
|
|
38
|
+
interface TryReactiveCompactDeps {
|
|
39
|
+
compactConversation: typeof compactConversation;
|
|
40
|
+
isReactiveCompactEnabled: typeof isReactiveCompactEnabled;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 撞墙后压缩一次并返回结果供 query loop 重试;不可恢复时返回 null(错误浮现)。
|
|
44
|
+
*
|
|
45
|
+
* 单发:hasAttempted=true(本 turn 已试过)或已 abort 直接 null,避免「压缩→仍超→
|
|
46
|
+
* 再压缩」死循环。复用 compactConversation:suppress 提问、无自定义指令、isAutoCompact
|
|
47
|
+
* 语义(它会 strip 图片 + 摘要旧消息,使 413/媒体过大在重试时消失)。
|
|
48
|
+
*
|
|
49
|
+
* deps 可注入,便于在不驱动真实摘要模型的前提下测试编排逻辑(沿用本仓 manualCompact 思路)。
|
|
50
|
+
*/
|
|
51
|
+
export declare function tryReactiveCompact(params: TryReactiveCompactParams, deps?: TryReactiveCompactDeps): Promise<CompactionResult | null>;
|
|
52
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { queryModelWithStreaming } from '../loop.js';
|
|
2
|
-
import { autoCompactIfNeeded } from '../compact/autoCompact.js';
|
|
2
|
+
import { autoCompactIfNeeded, manualCompact } from '../compact/autoCompact.js';
|
|
3
3
|
import { microcompactMessages } from '../compact/microCompact.js';
|
|
4
4
|
export type QueryDeps = {
|
|
5
5
|
callModel: typeof queryModelWithStreaming;
|
|
6
6
|
microcompact: typeof microcompactMessages;
|
|
7
7
|
autocompact: typeof autoCompactIfNeeded;
|
|
8
|
+
manualCompact: typeof manualCompact;
|
|
8
9
|
uuid: () => string;
|
|
9
10
|
};
|
|
10
11
|
export declare function productionDeps(): QueryDeps;
|
|
@@ -46,6 +46,17 @@ export declare function getToolSearchMode(): ToolSearchMode;
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function modelSupportsToolReference(model: string): boolean;
|
|
48
48
|
export declare function isToolSearchEnabledOptimistic(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the current request may use the NATIVE tool-search wire shapes:
|
|
51
|
+
* `tool_reference` content blocks + `defer_loading: true` on tool
|
|
52
|
+
* definitions + the tool-search beta header. These are Anthropic beta
|
|
53
|
+
* shapes — only the direct first-party Anthropic endpoint reliably
|
|
54
|
+
* accepts them. Proxies (custom ANTHROPIC_BASE_URL) and the OpenAI /
|
|
55
|
+
* Gemini families get the client-side EMULATION instead: ToolSearchTool
|
|
56
|
+
* results carry plain-text `<discovered-tool name="X" />` markers and
|
|
57
|
+
* discovered tools are sent with their FULL schema (no defer_loading).
|
|
58
|
+
*/
|
|
59
|
+
export declare function isNativeToolReferenceWire(): boolean;
|
|
49
60
|
/**
|
|
50
61
|
* Check if ToolSearchTool is available in the provided tools list.
|
|
51
62
|
* If ToolSearchTool is not available (e.g., disallowed via disallowedTools),
|
|
@@ -81,6 +92,15 @@ export declare function isToolSearchEnabled(model: string, tools: Tools, getTool
|
|
|
81
92
|
* tool_reference is a beta feature not in the SDK types, so we need runtime checks.
|
|
82
93
|
*/
|
|
83
94
|
export declare function isToolReferenceBlock(obj: unknown): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Marker emitted by ToolSearchTool under the emulation wire (non-native
|
|
97
|
+
* providers). One line per discovered tool. Kept attribute-style so a
|
|
98
|
+
* model quoting it verbatim in prose is unlikely to collide.
|
|
99
|
+
* Emitter lives in ToolSearchTool.ts (mapToolResultToToolResultBlockParam)
|
|
100
|
+
* — keep the two in sync. Has the `g` flag for matchAll — do NOT call
|
|
101
|
+
* .test()/.exec() on this export (stateful lastIndex).
|
|
102
|
+
*/
|
|
103
|
+
export declare const DISCOVERED_TOOL_MARKER_RE: RegExp;
|
|
84
104
|
/**
|
|
85
105
|
* Extract tool names from tool_reference blocks in message history.
|
|
86
106
|
*
|
|
@@ -4376,6 +4376,7 @@ export declare const StdoutMessageSchema: () => z.ZodUnion<readonly [z.ZodUnion<
|
|
|
4376
4376
|
auto: "auto";
|
|
4377
4377
|
}>;
|
|
4378
4378
|
pre_tokens: z.ZodNumber;
|
|
4379
|
+
post_tokens: z.ZodOptional<z.ZodNumber>;
|
|
4379
4380
|
preserved_segment: z.ZodOptional<z.ZodObject<{
|
|
4380
4381
|
head_uuid: z.ZodString;
|
|
4381
4382
|
anchor_uuid: z.ZodString;
|
|
@@ -2502,6 +2502,7 @@ export declare const SDKCompactBoundaryMessageSchema: () => z.ZodObject<{
|
|
|
2502
2502
|
auto: "auto";
|
|
2503
2503
|
}>;
|
|
2504
2504
|
pre_tokens: z.ZodNumber;
|
|
2505
|
+
post_tokens: z.ZodOptional<z.ZodNumber>;
|
|
2505
2506
|
preserved_segment: z.ZodOptional<z.ZodObject<{
|
|
2506
2507
|
head_uuid: z.ZodString;
|
|
2507
2508
|
anchor_uuid: z.ZodString;
|
|
@@ -2910,6 +2911,7 @@ export declare const SDKMessageSchema: () => z.ZodUnion<readonly [z.ZodObject<{
|
|
|
2910
2911
|
auto: "auto";
|
|
2911
2912
|
}>;
|
|
2912
2913
|
pre_tokens: z.ZodNumber;
|
|
2914
|
+
post_tokens: z.ZodOptional<z.ZodNumber>;
|
|
2913
2915
|
preserved_segment: z.ZodOptional<z.ZodObject<{
|
|
2914
2916
|
head_uuid: z.ZodString;
|
|
2915
2917
|
anchor_uuid: z.ZodString;
|
|
@@ -160,6 +160,14 @@ export type Options = {
|
|
|
160
160
|
* Values < 10_000 or > 5_000_000 are dropped + warn-logged (table fallback).
|
|
161
161
|
*/
|
|
162
162
|
contextWindow?: number;
|
|
163
|
+
/**
|
|
164
|
+
* 本回合手动压缩上下文(对应 host 的 /compact)。设置后 SDK 复用 auto-compact
|
|
165
|
+
* 机制(isAutoCompact=false + 这些指令)压缩当前消息、发出 system/compact_boundary,
|
|
166
|
+
* 随后结束本回合而不调用模型。单次信号——仅作用于携带它的那次 query()。
|
|
167
|
+
*/
|
|
168
|
+
compact?: {
|
|
169
|
+
instructions?: string;
|
|
170
|
+
};
|
|
163
171
|
includePartialMessages?: boolean;
|
|
164
172
|
replayUserMessages?: boolean;
|
|
165
173
|
permissionMode?: string;
|
|
@@ -228,6 +236,17 @@ export type Options = {
|
|
|
228
236
|
*/
|
|
229
237
|
agents?: readonly unknown[];
|
|
230
238
|
disallowedTools?: string[];
|
|
239
|
+
/**
|
|
240
|
+
* Tool names hidden from sub-agents (Agent/Task spawns) only — the main
|
|
241
|
+
* loop keeps them. Use this for MCP tools a sub-agent must not see (e.g. an
|
|
242
|
+
* interactive form/question capability): native UI tools like AskUserQuestion
|
|
243
|
+
* and EnterPlanMode are ALREADY excluded from every sub-agent, but MCP tools
|
|
244
|
+
* are not, so list them here. Matched with the same rules as `disallowedTools`,
|
|
245
|
+
* so MCP server-prefix (`mcp__server`) and wildcard (`mcp__server__*`) work.
|
|
246
|
+
* Unlike `disallowedTools` (a session-wide deny), this does NOT affect the
|
|
247
|
+
* main conversation.
|
|
248
|
+
*/
|
|
249
|
+
subagentDisallowedTools?: string[];
|
|
231
250
|
hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
|
|
232
251
|
/**
|
|
233
252
|
* Pre-execute lifecycle hook. Invoked SYNCHRONOUSLY (the SDK awaits the
|
|
@@ -19,6 +19,21 @@ export declare function getAllowRules(context: ToolPermissionContext): Permissio
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function createPermissionRequestMessage(toolName: string, decisionReason?: PermissionDecisionReason): string;
|
|
21
21
|
export declare function getDenyRules(context: ToolPermissionContext): PermissionRule[];
|
|
22
|
+
/**
|
|
23
|
+
* 把禁用工具名烘焙进权限上下文,作为 session 级 deny 规则。SDK 模式借此让
|
|
24
|
+
* Options.disallowedTools 经由共享的 deny 规则过滤,作用到每一处工具池组装——
|
|
25
|
+
* 主循环、子代理、fork。子代理会从它继承的权限上下文重建自己的工具池,所以仅在
|
|
26
|
+
* 主池上事后过滤的名字,否则会泄漏进子代理(并能通过 ToolSearch 被检索到)。
|
|
27
|
+
* 与 CLI 把 --disallowedTools 路由进 alwaysDenyRules 的做法一致。
|
|
28
|
+
*/
|
|
29
|
+
export declare function denySessionTools(context: ToolPermissionContext, toolNames: readonly string[] | undefined): ToolPermissionContext;
|
|
30
|
+
/**
|
|
31
|
+
* 过滤掉「仅对子代理隐藏」的工具(Options.subagentDisallowedTools)。复用与
|
|
32
|
+
* disallowedTools 同一套 deny 规则匹配,因此 MCP server 前缀('mcp__server')和
|
|
33
|
+
* 通配符('mcp__server__*')都能命中整组工具——不像裸 `Set.has(tool.name)` 只认精确全名。
|
|
34
|
+
* 在每个子代理工具池组装后调用(runAgent),主循环不调用,故对主循环无影响。
|
|
35
|
+
*/
|
|
36
|
+
export declare function filterSubagentDisallowedTools<T extends Pick<ToolRuntime, 'name' | 'mcpInfo'>>(tools: readonly T[], subagentDisallowedTools: readonly string[] | undefined): readonly T[];
|
|
22
37
|
export declare function getAskRules(context: ToolPermissionContext): PermissionRule[];
|
|
23
38
|
/**
|
|
24
39
|
* Check if the entire tool is listed in the always allow rules
|
|
@@ -125,6 +125,14 @@ export declare function performCodexRequest(options: {
|
|
|
125
125
|
/** Host-provided Responses-protocol-specific fields (merged into body). */
|
|
126
126
|
providerSpecific?: ResponsesProviderSpecific;
|
|
127
127
|
}): Promise<Response>;
|
|
128
|
+
/**
|
|
129
|
+
* 上游 `response.failed` 的错误若是「prompt 太长 / 上下文超限」,必须用非重试态 400 抛出。
|
|
130
|
+
* 否则 shouldRetry 把它当 5xx 服务端错误重试 MAX_RETRIES 次——同样超长的 prompt 原样重发
|
|
131
|
+
* 必然再失败,纯属浪费;且要等重试耗尽才轮到 query loop 的 reactive 压缩。400 让它即时浮现,
|
|
132
|
+
* 第一次就触发一次压缩重试(formatAPIError 仍按消息归一为 PROMPT_TOO_LONG_ERROR_MESSAGE,
|
|
133
|
+
* reactive 据此识别)。其余失败保持 500(可能是真·瞬时服务端错误,该重试)。
|
|
134
|
+
*/
|
|
135
|
+
export declare function codexFailureStatus(errorMessage: string): number;
|
|
128
136
|
export declare function collectCodexCompletedResponse(response: Response): Promise<Record<string, any>>;
|
|
129
137
|
export declare function codexStreamToAnthropic(response: Response, model: string): AsyncGenerator<AnthropicStreamEvent>;
|
|
130
138
|
export declare function convertCodexResponseToAnthropicMessage(data: Record<string, any>, model: string): Record<string, unknown>;
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* OPENAI_MODEL — optional; use github:copilot or openai/gpt-4.1 style IDs
|
|
22
22
|
*/
|
|
23
23
|
import type { ProviderOverride } from '../shared/routing.js';
|
|
24
|
-
import { type AnthropicStreamEvent, type ShimCreateParams } from '../../providers/codex/shim.js';
|
|
24
|
+
import { type AnthropicStreamEvent, type AnthropicUsage, type ShimCreateParams } from '../../providers/codex/shim.js';
|
|
25
25
|
interface OpenAIMessage {
|
|
26
26
|
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
27
27
|
content?: string | null | Array<{
|
|
@@ -68,6 +68,21 @@ export declare function convertTools(tools: Array<{
|
|
|
68
68
|
input_schema?: Record<string, unknown>;
|
|
69
69
|
}>, model?: string): OpenAITool[];
|
|
70
70
|
export declare function makeMessageId(): string;
|
|
71
|
+
/**
|
|
72
|
+
* 把 OpenAI(chat_completions)usage 折算成 Anthropic 语义的 usage。
|
|
73
|
+
*
|
|
74
|
+
* 关键:OpenAI 的 `prompt_tokens` 已包含缓存命中(`cached_tokens` 是它的子集);而
|
|
75
|
+
* Anthropic 语义里 input_tokens / cache_read / cache_creation 互不相交、三者之和才是
|
|
76
|
+
* 完整输入上下文。所以 input_tokens 必须取「非缓存」部分 = prompt_tokens − cached,否则
|
|
77
|
+
* 上层(messageMapper 占用环、成本核算)把 input + cache_read 求和会把缓存算两遍。
|
|
78
|
+
*/
|
|
79
|
+
export declare function openaiUsageToAnthropicUsage(usage: {
|
|
80
|
+
prompt_tokens?: number;
|
|
81
|
+
completion_tokens?: number;
|
|
82
|
+
prompt_tokens_details?: {
|
|
83
|
+
cached_tokens?: number;
|
|
84
|
+
};
|
|
85
|
+
} | undefined): AnthropicUsage;
|
|
71
86
|
/**
|
|
72
87
|
* Async generator that transforms an OpenAI SSE stream into
|
|
73
88
|
* Anthropic-format BetaRawMessageStreamEvent objects.
|
|
@@ -172,12 +187,7 @@ export declare function convertOpenAIResponseToAnthropic(data: {
|
|
|
172
187
|
model: string;
|
|
173
188
|
stop_reason: string;
|
|
174
189
|
stop_sequence: any;
|
|
175
|
-
usage:
|
|
176
|
-
input_tokens: number;
|
|
177
|
-
output_tokens: number;
|
|
178
|
-
cache_creation_input_tokens: number;
|
|
179
|
-
cache_read_input_tokens: number;
|
|
180
|
-
};
|
|
190
|
+
usage: AnthropicUsage;
|
|
181
191
|
};
|
|
182
192
|
/**
|
|
183
193
|
* @internal γ.6c
|
|
@@ -5,9 +5,9 @@ import type { EffortLevel } from 'src/lib/effort.js';
|
|
|
5
5
|
import type { PermissionMode } from 'src/permissions/PermissionMode.js';
|
|
6
6
|
import { type Span } from 'src/audit/telemetry/sessionTracing.js';
|
|
7
7
|
import type { NonNullableUsage } from '../../entrypoints/sdk/sdkUtilityTypes.js';
|
|
8
|
-
import { EMPTY_USAGE } from './usage.js';
|
|
8
|
+
import { EMPTY_USAGE, contextWindowTokens } from './usage.js';
|
|
9
9
|
export type { NonNullableUsage };
|
|
10
|
-
export { EMPTY_USAGE };
|
|
10
|
+
export { EMPTY_USAGE, contextWindowTokens };
|
|
11
11
|
export type GlobalCacheStrategy = 'tool_based' | 'system_prompt' | 'none';
|
|
12
12
|
export declare function logAPIQuery({ model, messagesLength, temperature, betas, permissionMode, querySource, queryTracking, thinkingType, effortValue, fastMode, previousRequestId, }: {
|
|
13
13
|
model: string;
|
|
@@ -19,5 +19,10 @@ export declare function getAPIProviderForStatsig(): AnalyticsMetadata_I_VERIFIED
|
|
|
19
19
|
* Check if ANTHROPIC_BASE_URL is a first-party Anthropic API URL.
|
|
20
20
|
* Returns true if not set (default API) or points to api.anthropic.com
|
|
21
21
|
* (or api-staging.anthropic.com for ant users).
|
|
22
|
+
*
|
|
23
|
+
* Reads the session-aware env (Options.env → process.env fallback): in-process
|
|
24
|
+
* hosts put the proxy base URL ONLY in createSession({env}), so a raw
|
|
25
|
+
* process.env read would misclassify their sessions as first-party and leak
|
|
26
|
+
* beta wire shapes (tool_reference / defer_loading) to the proxy.
|
|
22
27
|
*/
|
|
23
28
|
export declare function isFirstPartyAnthropicBaseUrl(): boolean;
|
|
@@ -5,3 +5,14 @@ import type { NonNullableUsage } from '../../entrypoints/sdk/sdkUtilityTypes.js'
|
|
|
5
5
|
* api/errors.ts → utils/messages.ts → BashTool.tsx → the world.
|
|
6
6
|
*/
|
|
7
7
|
export declare const EMPTY_USAGE: Readonly<NonNullableUsage>;
|
|
8
|
+
/**
|
|
9
|
+
* Tokens currently occupying the context window for a single API response.
|
|
10
|
+
*
|
|
11
|
+
* Context occupancy is a point-in-time snapshot = the input side of the most
|
|
12
|
+
* recent message: input_tokens + cache_read_input_tokens +
|
|
13
|
+
* cache_creation_input_tokens. output_tokens are excluded — they only enter
|
|
14
|
+
* the window on the *next* request. Callers must pass per-message usage, not a
|
|
15
|
+
* turn-cumulative total (summing every message's input over-counts the window
|
|
16
|
+
* because each tool round re-sends the growing context).
|
|
17
|
+
*/
|
|
18
|
+
export declare function contextWindowTokens(usage: NonNullableUsage): number;
|
package/dist/query.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export type QueryParams = {
|
|
|
24
24
|
taskBudget?: {
|
|
25
25
|
total: number;
|
|
26
26
|
};
|
|
27
|
+
compactRequest?: {
|
|
28
|
+
instructions?: string;
|
|
29
|
+
};
|
|
27
30
|
deps?: QueryDeps;
|
|
28
31
|
};
|
|
29
32
|
export declare function query(params: QueryParams): AsyncGenerator<StreamEvent | RequestStartEvent | Message | TombstoneMessage | ToolUseSummaryMessage, Terminal>;
|