@opencow-ai/opencow-agent-sdk 0.4.11 → 0.4.13
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/capabilities/adapters/callToolResultAdapter.d.ts +8 -0
- package/dist/capabilities/tools/FileReadTool/FileReadTool.d.ts +8 -0
- package/dist/cli.mjs +197 -128
- package/dist/client.js +198 -121
- package/dist/controller/compact/autoCompact.d.ts +4 -0
- package/dist/controller/loop.d.ts +1 -0
- package/dist/entrypoints/sdk/runtimeTypes.d.ts +41 -4
- package/dist/providers/codex/shim.d.ts +3 -3
- package/dist/providers/openai/shim.d.ts +8 -19
- package/dist/providers/shared/config.d.ts +4 -3
- package/dist/providers/shared/model/maxTokens.d.ts +1 -0
- package/dist/providers/shared/routing.d.ts +3 -1
- package/dist/query.d.ts +1 -0
- package/dist/sdk.js +198 -121
- package/dist/session/canonical/imageSource.d.ts +37 -0
- package/dist/session/canonical/index.d.ts +2 -1
- package/dist/session/canonical/types.d.ts +5 -1
- package/dist/types/toolRuntime.d.ts +24 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ import { trySessionMemoryCompaction } from './sessionMemoryCompact.js';
|
|
|
7
7
|
export declare function getEffectiveContextWindowSize(model: string, opts?: {
|
|
8
8
|
contextWindow?: number;
|
|
9
9
|
maxOutputTokens?: number;
|
|
10
|
+
maxOutputTokensLimit?: number;
|
|
10
11
|
}): number;
|
|
11
12
|
export type AutoCompactTrackingState = {
|
|
12
13
|
compacted: boolean;
|
|
@@ -21,10 +22,12 @@ export declare const MANUAL_COMPACT_BUFFER_TOKENS = 3000;
|
|
|
21
22
|
export declare function getAutoCompactThreshold(model: string, opts?: {
|
|
22
23
|
contextWindow?: number;
|
|
23
24
|
maxOutputTokens?: number;
|
|
25
|
+
maxOutputTokensLimit?: number;
|
|
24
26
|
}): number;
|
|
25
27
|
export declare function calculateTokenWarningState(tokenUsage: number, model: string, opts?: {
|
|
26
28
|
contextWindow?: number;
|
|
27
29
|
maxOutputTokens?: number;
|
|
30
|
+
maxOutputTokensLimit?: number;
|
|
28
31
|
}): {
|
|
29
32
|
percentLeft: number;
|
|
30
33
|
isAboveWarningThreshold: boolean;
|
|
@@ -36,6 +39,7 @@ export declare function isAutoCompactEnabled(): boolean;
|
|
|
36
39
|
export declare function shouldAutoCompact(messages: Message[], model: string, querySource?: QuerySource, snipTokensFreed?: number, opts?: {
|
|
37
40
|
contextWindow?: number;
|
|
38
41
|
maxOutputTokens?: number;
|
|
42
|
+
maxOutputTokensLimit?: number;
|
|
39
43
|
}): Promise<boolean>;
|
|
40
44
|
export declare function autoCompactIfNeeded(messages: Message[], toolUseContext: ToolRuntimeContext, cacheSafeParams: CacheSafeParams, querySource?: QuerySource, tracking?: AutoCompactTrackingState, snipTokensFreed?: number): Promise<{
|
|
41
45
|
wasCompacted: boolean;
|
|
@@ -32,6 +32,7 @@ export type Options = {
|
|
|
32
32
|
isNonInteractiveSession: boolean;
|
|
33
33
|
extraToolSchemas?: BetaToolUnion[];
|
|
34
34
|
maxOutputTokensOverride?: number;
|
|
35
|
+
maxOutputTokensLimitOverride?: number;
|
|
35
36
|
fallbackModel?: string;
|
|
36
37
|
onStreamingFallback?: () => void;
|
|
37
38
|
querySource: QuerySource;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
2
|
import type { ModelProviders } from '../../providers/shared/routing.js';
|
|
3
|
+
import type { UploadMediaFn } from '../../types/toolRuntime.js';
|
|
3
4
|
export type { ModelProviders, ModelProviderConfig } from '../../providers/shared/routing.js';
|
|
4
5
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
6
|
import type { CallToolResult, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
|
|
@@ -124,7 +125,7 @@ export type SettingSource = 'user' | 'project' | 'local';
|
|
|
124
125
|
import type { SdkTool } from '../../capabilities/SdkTool.js';
|
|
125
126
|
import type { LayoutProfile } from '../../session/layout/LayoutProfile.js';
|
|
126
127
|
import type { SdkRule } from '../../session/rules/SdkRule.js';
|
|
127
|
-
import type { ProviderTransport, DeprecatedProviderTransportName } from '../../providers/shared/config.js';
|
|
128
|
+
import type { ProviderTransport, DeprecatedProviderTransportName, ReasoningEffort } from '../../providers/shared/config.js';
|
|
128
129
|
import type { FileHistoryChangeListener, FileHistoryState } from '../../session/fileHistory.js';
|
|
129
130
|
export type Options = {
|
|
130
131
|
cwd?: string;
|
|
@@ -147,6 +148,13 @@ export type Options = {
|
|
|
147
148
|
* values are clamped + warn-logged, never thrown.
|
|
148
149
|
*/
|
|
149
150
|
maxOutputTokens?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Optional host-authoritative upper bound for `maxOutputTokens`. Use this
|
|
153
|
+
* when the selected model is a custom gateway/deployment id whose native
|
|
154
|
+
* output cap is known by the host model catalog but not by the SDK's built-in
|
|
155
|
+
* model table. When unset, SDK built-in per-model limits are used.
|
|
156
|
+
*/
|
|
157
|
+
maxOutputTokensLimit?: number;
|
|
150
158
|
/**
|
|
151
159
|
* Per-session context window override (input tokens). Used by autoCompact
|
|
152
160
|
* threshold computation and any other code path that calls
|
|
@@ -160,6 +168,20 @@ export type Options = {
|
|
|
160
168
|
* Values < 10_000 or > 5_000_000 are dropped + warn-logged (table fallback).
|
|
161
169
|
*/
|
|
162
170
|
contextWindow?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Host-provided default reasoning effort for the selected model. This is
|
|
173
|
+
* protocol-neutral: OpenAI Chat Completions serializes it as
|
|
174
|
+
* `reasoning_effort`, while OpenAI Responses serializes it as
|
|
175
|
+
* `reasoning.effort` and can still merge protocol-specific fields such as
|
|
176
|
+
* `reasoning.summary`.
|
|
177
|
+
*
|
|
178
|
+
* Leave unset to preserve SDK/model defaults. Pass `null` on a per-turn
|
|
179
|
+
* override to clear inherited or descriptor defaults. Hosts with an
|
|
180
|
+
* authoritative model catalog should pass that model's default here, and
|
|
181
|
+
* user-selected effort can override the catalog default before it reaches
|
|
182
|
+
* the SDK.
|
|
183
|
+
*/
|
|
184
|
+
reasoningEffort?: ReasoningEffort | null;
|
|
163
185
|
/**
|
|
164
186
|
* 本回合手动压缩上下文(对应 host 的 /compact)。设置后 SDK 复用 auto-compact
|
|
165
187
|
* 机制(isAutoCompact=false + 这些指令)压缩当前消息、发出 system/compact_boundary,
|
|
@@ -278,6 +300,21 @@ export type Options = {
|
|
|
278
300
|
toolInput: Record<string, unknown>;
|
|
279
301
|
toolUseId: string;
|
|
280
302
|
}) => void | Promise<void>;
|
|
303
|
+
/**
|
|
304
|
+
* Host-injected media uploader. When supplied, media-producing built-in
|
|
305
|
+
* tools (FileReadTool reading an image) upload the **compressed** bytes
|
|
306
|
+
* (post token-budget) and emit `{type:'image', source:{type:'url', url}}`
|
|
307
|
+
* in the tool_result instead of inline base64 — keeping the bytes out of
|
|
308
|
+
* every subsequent turn's request and letting the host materialize them.
|
|
309
|
+
* Media-neutral: the same port serves image / PDF / page-image tool output,
|
|
310
|
+
* driven by `mediaType`.
|
|
311
|
+
*
|
|
312
|
+
* Returns a fetchable URL, or `null` when upload is unavailable; the SDK
|
|
313
|
+
* also treats a thrown error as "unavailable". Either way it falls back to
|
|
314
|
+
* inline base64, so standalone SDK/CLI runs (no uploader) are byte-for-byte
|
|
315
|
+
* unchanged.
|
|
316
|
+
*/
|
|
317
|
+
uploadMedia?: UploadMediaFn;
|
|
281
318
|
jsonSchema?: Record<string, unknown>;
|
|
282
319
|
betas?: string[];
|
|
283
320
|
settingSources?: SettingSource[];
|
|
@@ -325,8 +362,8 @@ export type Options = {
|
|
|
325
362
|
* - `metadata` — string-keyed map attached to the request
|
|
326
363
|
* - `responseFormat` — JSON schema enforcement
|
|
327
364
|
* - `reasoning` — reasoning configuration override. `effort` controls
|
|
328
|
-
* how hard the model thinks (minimal/low/medium/high;
|
|
329
|
-
* specific). `summary` controls whether human-readable reasoning
|
|
365
|
+
* how hard the model thinks (none/minimal/low/medium/high/xhigh;
|
|
366
|
+
* default model-specific). `summary` controls whether human-readable reasoning
|
|
330
367
|
* summary is returned in the SSE stream ('auto'/'concise'/'detailed';
|
|
331
368
|
* when unset, upstream returns only encrypted reasoning items —
|
|
332
369
|
* useful for state preservation but invisible in UI). Merges with
|
|
@@ -341,7 +378,7 @@ export type Options = {
|
|
|
341
378
|
metadata?: Record<string, string>;
|
|
342
379
|
responseFormat?: unknown;
|
|
343
380
|
reasoning?: {
|
|
344
|
-
effort?:
|
|
381
|
+
effort?: ReasoningEffort;
|
|
345
382
|
summary?: 'auto' | 'concise' | 'detailed' | null;
|
|
346
383
|
};
|
|
347
384
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedCodexCredentials, ResolvedProviderRequest } from '../../providers/shared/config.js';
|
|
1
|
+
import type { ResolvedCodexCredentials, ResolvedProviderRequest, ReasoningEffort } from '../../providers/shared/config.js';
|
|
2
2
|
export interface AnthropicUsage {
|
|
3
3
|
input_tokens: number;
|
|
4
4
|
output_tokens: number;
|
|
@@ -53,7 +53,7 @@ export interface ResponsesProviderSpecific {
|
|
|
53
53
|
* reasoning (Codex aliases or `?reasoning=high` model suffix) per-key.
|
|
54
54
|
*
|
|
55
55
|
* - `effort`: how hard the model thinks. Without it, model-specific
|
|
56
|
-
* default applies
|
|
56
|
+
* default applies.
|
|
57
57
|
* - `summary`: whether human-readable reasoning summary is streamed via
|
|
58
58
|
* `response.reasoning_summary_text.delta` events. WITHOUT this set,
|
|
59
59
|
* the upstream returns only encrypted_content reasoning items —
|
|
@@ -62,7 +62,7 @@ export interface ResponsesProviderSpecific {
|
|
|
62
62
|
* chain-of-thought text.
|
|
63
63
|
*/
|
|
64
64
|
reasoning?: {
|
|
65
|
-
effort?:
|
|
65
|
+
effort?: ReasoningEffort;
|
|
66
66
|
summary?: 'auto' | 'concise' | 'detailed' | null;
|
|
67
67
|
};
|
|
68
68
|
}
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import type { ProviderOverride } from '../shared/routing.js';
|
|
24
24
|
import { type AnthropicStreamEvent, type AnthropicUsage, type ShimCreateParams } from '../../providers/codex/shim.js';
|
|
25
|
+
import { type ReasoningEffort } from '../../providers/shared/config.js';
|
|
25
26
|
interface OpenAIMessage {
|
|
26
27
|
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
27
28
|
content?: string | null | Array<{
|
|
@@ -98,24 +99,12 @@ export declare function openaiUsageToAnthropicUsage(usage: {
|
|
|
98
99
|
* responsibilities.
|
|
99
100
|
*/
|
|
100
101
|
/**
|
|
101
|
-
* Convert an SDK
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* - SDK vocab: `'low' | 'medium' | 'high' | 'xhigh'`
|
|
106
|
-
* (`'xhigh'` is the SDK-internal "Max" tier,
|
|
107
|
-
* surfaced as "max" in the CLI — see
|
|
108
|
-
* `lib/effort.ts`.)
|
|
109
|
-
* - OpenAI chat wire vocab: `'low' | 'medium' | 'high'`
|
|
110
|
-
* (Spec: platform.openai.com/docs/api-reference/chat/create)
|
|
111
|
-
*
|
|
112
|
-
* `'xhigh'` is clamped down to `'high'` rather than rejected: the SDK
|
|
113
|
-
* semantic is "as much reasoning as the provider will give" and `'high'`
|
|
114
|
-
* is the upper bound on this wire. Sending `'xhigh'` raw would 400 on
|
|
115
|
-
* strict proxies. The Responses API (codex) has its own serialisation
|
|
116
|
-
* and does NOT go through this function — see `codex/shim.ts`.
|
|
102
|
+
* Convert an SDK reasoning-effort tier to the value accepted by OpenAI Chat
|
|
103
|
+
* Completions `reasoning_effort`. The current OpenAI wire accepts the same
|
|
104
|
+
* vocabulary as the SDK; model-specific legality is enforced by the host
|
|
105
|
+
* catalog / upstream provider, not by this transport boundary.
|
|
117
106
|
*/
|
|
118
|
-
export declare function toOpenAIChatReasoningEffort(effort:
|
|
107
|
+
export declare function toOpenAIChatReasoningEffort(effort: ReasoningEffort): ReasoningEffort;
|
|
119
108
|
export declare function buildOpenAIRequestBody(params: ShimCreateParams, ctx: {
|
|
120
109
|
resolvedModel: string;
|
|
121
110
|
baseUrl: string;
|
|
@@ -133,7 +122,7 @@ export declare function buildOpenAIRequestBody(params: ShimCreateParams, ctx: {
|
|
|
133
122
|
* transports serialise differently on the wire.
|
|
134
123
|
*/
|
|
135
124
|
reasoning?: {
|
|
136
|
-
effort:
|
|
125
|
+
effort: ReasoningEffort;
|
|
137
126
|
};
|
|
138
127
|
}): Record<string, unknown>;
|
|
139
128
|
export declare function openaiStreamToAnthropic(response: Response, model: string): AsyncGenerator<AnthropicStreamEvent>;
|
|
@@ -209,7 +198,7 @@ export declare function createOpenAIShimClient(options: {
|
|
|
209
198
|
defaultHeaders?: Record<string, string>;
|
|
210
199
|
maxRetries?: number;
|
|
211
200
|
timeout?: number;
|
|
212
|
-
reasoningEffort?:
|
|
201
|
+
reasoningEffort?: ReasoningEffort;
|
|
213
202
|
providerOverride?: ProviderOverride;
|
|
214
203
|
}): unknown;
|
|
215
204
|
export {};
|
|
@@ -2,7 +2,7 @@ export declare const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
|
|
2
2
|
export declare const DEFAULT_CODEX_BASE_URL = "https://chatgpt.com/backend-api/codex";
|
|
3
3
|
/** Default GitHub Models API model when user selects copilot / github:copilot */
|
|
4
4
|
export declare const DEFAULT_GITHUB_MODELS_API_MODEL = "openai/gpt-4.1";
|
|
5
|
-
type ReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh';
|
|
5
|
+
export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
6
6
|
/**
|
|
7
7
|
* Wire-level transport selected by `resolveProviderTransport`.
|
|
8
8
|
*
|
|
@@ -45,6 +45,8 @@ export type DeprecatedProviderTransportName = 'codex_responses';
|
|
|
45
45
|
* CLAUDE_CODE_USE_GITHUB, OPENCOW_DEBUG_REASONING).
|
|
46
46
|
*/
|
|
47
47
|
export declare const QUERY_ENV_KEY_TRANSPORT_OVERRIDE = "__OPENCOW_TRANSPORT_OVERRIDE";
|
|
48
|
+
export declare const QUERY_ENV_KEY_REASONING_EFFORT_OVERRIDE = "__OPENCOW_REASONING_EFFORT_OVERRIDE";
|
|
49
|
+
export declare const QUERY_ENV_VALUE_REASONING_EFFORT_CLEAR = "__OPENCOW_CLEAR_REASONING_EFFORT__";
|
|
48
50
|
export declare const QUERY_ENV_KEY_PROVIDER_SPECIFIC_OPENAI_RESPONSES = "__OPENCOW_PROVIDER_SPECIFIC_OPENAI_RESPONSES";
|
|
49
51
|
export type ResolvedProviderRequest = {
|
|
50
52
|
transport: ProviderTransport;
|
|
@@ -139,7 +141,7 @@ export declare function resolveProviderRequest(options?: {
|
|
|
139
141
|
model?: string;
|
|
140
142
|
baseUrl?: string;
|
|
141
143
|
fallbackModel?: string;
|
|
142
|
-
reasoningEffortOverride?: ReasoningEffort;
|
|
144
|
+
reasoningEffortOverride?: ReasoningEffort | null;
|
|
143
145
|
/**
|
|
144
146
|
* Optional explicit transport override forwarded to
|
|
145
147
|
* `resolveProviderTransport`. When unset, callers can still rely on the
|
|
@@ -181,4 +183,3 @@ export declare function parseChatgptAccountId(token: string | undefined): string
|
|
|
181
183
|
export declare function resolveOpenAIResponsesCredentials(): ResolvedCodexCredentials;
|
|
182
184
|
export declare function resolveCodexApiCredentials(env?: NodeJS.ProcessEnv): ResolvedCodexCredentials;
|
|
183
185
|
export declare function getReasoningEffortForModel(model: string): ReasoningEffort | undefined;
|
|
184
|
-
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SettingsJson } from '../../session/settings/types.js';
|
|
2
|
-
import type { ProviderTransport } from './config.js';
|
|
2
|
+
import type { ProviderTransport, ReasoningEffort } from './config.js';
|
|
3
3
|
/**
|
|
4
4
|
* Provider override resolved for a specific agent/model.
|
|
5
5
|
* When present, the API client uses these instead of the session-global
|
|
@@ -21,6 +21,8 @@ export interface ProviderOverride {
|
|
|
21
21
|
* OpenAI shim.
|
|
22
22
|
*/
|
|
23
23
|
transport?: ProviderTransport | 'anthropic';
|
|
24
|
+
/** Default reasoning effort for this model route; null clears session default. */
|
|
25
|
+
reasoningEffort?: ReasoningEffort | null;
|
|
24
26
|
/** Per-wire extras (e.g. openai-responses reasoning summary config). */
|
|
25
27
|
providerSpecific?: {
|
|
26
28
|
openaiResponses?: Record<string, unknown>;
|
package/dist/query.d.ts
CHANGED