@opencow-ai/opencow-agent-sdk 0.4.6 → 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/mcp/types.d.ts +1 -1
- package/dist/capabilities/tools/AgentTool/agentMerge.d.ts +8 -0
- package/dist/capabilities/tools/AgentTool/builtInAgents.d.ts +15 -0
- package/dist/capabilities/tools/AgentTool/runAgent.d.ts +13 -2
- package/dist/capabilities/tools/ToolSearchTool/ToolSearchTool.d.ts +1 -1
- package/dist/cli.mjs +914 -567
- package/dist/client.d.ts +10 -0
- package/dist/client.js +863 -399
- package/dist/constants/envVars.d.ts +1 -0
- package/dist/constants/tools.d.ts +1 -1
- package/dist/controller/compact/autoCompact.d.ts +17 -1
- package/dist/controller/compact/reactiveCompact.d.ts +52 -0
- package/dist/controller/hooks.d.ts +17 -2
- package/dist/controller/loop.d.ts +2 -5
- package/dist/controller/query/deps.d.ts +2 -1
- package/dist/controller/toolSearch.d.ts +20 -0
- package/dist/entrypoints/sdk/controlSchemas.d.ts +74 -1
- package/dist/entrypoints/sdk/coreSchemas.d.ts +19 -1
- package/dist/entrypoints/sdk/runtimeTypes.d.ts +41 -0
- package/dist/lib/envDynamic.d.ts +1 -1
- package/dist/permissions/permissions.d.ts +15 -0
- package/dist/providers/anthropic/teleport/api.d.ts +1 -1
- package/dist/providers/codex/shim.d.ts +8 -0
- package/dist/providers/openai/shim.d.ts +19 -12
- package/dist/providers/provider.d.ts +2 -5
- package/dist/providers/shared/clientFactory.d.ts +2 -5
- package/dist/providers/shared/logging.d.ts +2 -2
- package/dist/providers/shared/model/providers.d.ts +5 -0
- package/dist/providers/shared/routing.d.ts +37 -6
- package/dist/providers/shared/usage.d.ts +11 -0
- package/dist/query.d.ts +3 -0
- package/dist/sdk.js +863 -399
- package/dist/session/backgroundAbortRegistry.d.ts +23 -0
- package/dist/types/toolRuntime.d.ts +14 -5
- package/package.json +3 -3
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
* GITHUB_TOKEN or GH_TOKEN — PAT with models access (mapped to Bearer auth)
|
|
21
21
|
* OPENAI_MODEL — optional; use github:copilot or openai/gpt-4.1 style IDs
|
|
22
22
|
*/
|
|
23
|
-
import
|
|
23
|
+
import type { ProviderOverride } from '../shared/routing.js';
|
|
24
|
+
import { type AnthropicStreamEvent, type AnthropicUsage, type ShimCreateParams } from '../../providers/codex/shim.js';
|
|
24
25
|
interface OpenAIMessage {
|
|
25
26
|
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
26
27
|
content?: string | null | Array<{
|
|
@@ -67,6 +68,21 @@ export declare function convertTools(tools: Array<{
|
|
|
67
68
|
input_schema?: Record<string, unknown>;
|
|
68
69
|
}>, model?: string): OpenAITool[];
|
|
69
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;
|
|
70
86
|
/**
|
|
71
87
|
* Async generator that transforms an OpenAI SSE stream into
|
|
72
88
|
* Anthropic-format BetaRawMessageStreamEvent objects.
|
|
@@ -171,12 +187,7 @@ export declare function convertOpenAIResponseToAnthropic(data: {
|
|
|
171
187
|
model: string;
|
|
172
188
|
stop_reason: string;
|
|
173
189
|
stop_sequence: any;
|
|
174
|
-
usage:
|
|
175
|
-
input_tokens: number;
|
|
176
|
-
output_tokens: number;
|
|
177
|
-
cache_creation_input_tokens: number;
|
|
178
|
-
cache_read_input_tokens: number;
|
|
179
|
-
};
|
|
190
|
+
usage: AnthropicUsage;
|
|
180
191
|
};
|
|
181
192
|
/**
|
|
182
193
|
* @internal γ.6c
|
|
@@ -199,10 +210,6 @@ export declare function createOpenAIShimClient(options: {
|
|
|
199
210
|
maxRetries?: number;
|
|
200
211
|
timeout?: number;
|
|
201
212
|
reasoningEffort?: 'low' | 'medium' | 'high' | 'xhigh';
|
|
202
|
-
providerOverride?:
|
|
203
|
-
model: string;
|
|
204
|
-
baseURL: string;
|
|
205
|
-
apiKey: string;
|
|
206
|
-
};
|
|
213
|
+
providerOverride?: ProviderOverride;
|
|
207
214
|
}): unknown;
|
|
208
215
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ProviderOverride } from './shared/routing.js';
|
|
2
3
|
import type { ClientOptions } from '@anthropic-ai/sdk';
|
|
3
4
|
import type { ModelOutputTokenCap, NormalizedRequest, NormalizedResponse, ProviderError, ProviderFeature, ProviderId, ProviderProtocol, StreamEvent } from './types.js';
|
|
4
5
|
/**
|
|
@@ -19,11 +20,7 @@ export interface CreateClientOptions {
|
|
|
19
20
|
* without forcing hosts to rebuild a whole Provider object when
|
|
20
21
|
* the swap is temporary.
|
|
21
22
|
*/
|
|
22
|
-
readonly providerOverride?:
|
|
23
|
-
readonly model: string;
|
|
24
|
-
readonly baseURL: string;
|
|
25
|
-
readonly apiKey: string;
|
|
26
|
-
};
|
|
23
|
+
readonly providerOverride?: ProviderOverride;
|
|
27
24
|
}
|
|
28
25
|
export interface Provider {
|
|
29
26
|
/** Stable id for logs / telemetry / per-session pinning. Not used for dispatch. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Anthropic, { type ClientOptions } from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ProviderOverride } from './routing.js';
|
|
2
3
|
/**
|
|
3
4
|
* @internal γ.6c
|
|
4
5
|
*
|
|
@@ -22,10 +23,6 @@ export declare function getNormalizedClient({ apiKey, maxRetries, model, fetchOv
|
|
|
22
23
|
model?: string;
|
|
23
24
|
fetchOverride?: ClientOptions['fetch'];
|
|
24
25
|
source?: string;
|
|
25
|
-
providerOverride?:
|
|
26
|
-
model: string;
|
|
27
|
-
baseURL: string;
|
|
28
|
-
apiKey: string;
|
|
29
|
-
};
|
|
26
|
+
providerOverride?: ProviderOverride;
|
|
30
27
|
}): Promise<Anthropic>;
|
|
31
28
|
export declare const CLIENT_REQUEST_ID_HEADER = "x-client-request-id";
|
|
@@ -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;
|
|
@@ -1,16 +1,47 @@
|
|
|
1
1
|
import type { SettingsJson } from '../../session/settings/types.js';
|
|
2
|
+
import type { ProviderTransport } from './config.js';
|
|
2
3
|
/**
|
|
3
|
-
* Provider override resolved
|
|
4
|
-
* When present, the API client
|
|
4
|
+
* Provider override resolved for a specific agent/model.
|
|
5
|
+
* When present, the API client uses these instead of the session-global
|
|
6
|
+
* env-derived provider config (baseURL/key/transport).
|
|
5
7
|
*/
|
|
6
8
|
export interface ProviderOverride {
|
|
7
9
|
/** Model name to send to the API (e.g. "deepseek-chat", "gpt-4o") */
|
|
8
10
|
model: string;
|
|
9
|
-
/**
|
|
10
|
-
baseURL
|
|
11
|
-
/** API key
|
|
12
|
-
apiKey
|
|
11
|
+
/** Base URL. Optional — falls back to the session's OPENAI_BASE_URL env. */
|
|
12
|
+
baseURL?: string;
|
|
13
|
+
/** API key. Optional — falls back to the session's env credential chain. */
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Wire transport for this override. Without it the session-level
|
|
17
|
+
* transport/sniff applies — which is exactly the cross-protocol subagent
|
|
18
|
+
* bug: a tier model living on a different wire (e.g. openai_responses)
|
|
19
|
+
* than the main session (chat_completions) hits the wrong endpoint and
|
|
20
|
+
* 404s. 'anthropic' routes to the native Anthropic client instead of the
|
|
21
|
+
* OpenAI shim.
|
|
22
|
+
*/
|
|
23
|
+
transport?: ProviderTransport | 'anthropic';
|
|
24
|
+
/** Per-wire extras (e.g. openai-responses reasoning summary config). */
|
|
25
|
+
providerSpecific?: {
|
|
26
|
+
openaiResponses?: Record<string, unknown>;
|
|
27
|
+
};
|
|
13
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Host-supplied model → provider-route catalog (`Options.modelProviders`).
|
|
31
|
+
* Key is the model id as it appears after subagent model resolution (tier
|
|
32
|
+
* env values / Agent tool `model` param). The host owns the model catalog
|
|
33
|
+
* (which channel/protocol each model lives on); the SDK consults this AFTER
|
|
34
|
+
* resolving a subagent's model so any resolution path — tier alias, explicit
|
|
35
|
+
* model param, inherit — lands on the right wire.
|
|
36
|
+
*/
|
|
37
|
+
export type ModelProviderConfig = Omit<ProviderOverride, 'model'>;
|
|
38
|
+
export type ModelProviders = Record<string, ModelProviderConfig>;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve a model's provider route from the host catalog. Returns null when
|
|
41
|
+
* the catalog has no entry — the model is served by the session's default
|
|
42
|
+
* provider config (the common case: same wire as the main session).
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveModelProvider(model: string, modelProviders: ModelProviders | undefined): ProviderOverride | null;
|
|
14
45
|
/**
|
|
15
46
|
* Look up agent.routing by name or subagent_type, then resolve via agent.models.
|
|
16
47
|
*
|
|
@@ -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>;
|