@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
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared, url-aware normalization for canonical image sources.
|
|
3
|
+
*
|
|
4
|
+
* Canonical image blocks carry a discriminated `source` union
|
|
5
|
+
* (`CanonicalImageSource`: base64 | url). Every wire adapter that has to
|
|
6
|
+
* render an image — OpenAI Chat Completions, OpenAI Responses, and the
|
|
7
|
+
* tool_result fan-out on both — needs the same "is this base64 or a url"
|
|
8
|
+
* decision. This module owns that single decision so the providers stay in
|
|
9
|
+
* lock-step (truthiness checks, the `image/png` fallback, and "drop unknown
|
|
10
|
+
* sources silently" all live here, not duplicated four times).
|
|
11
|
+
*/
|
|
12
|
+
/** Result of normalizing a raw image `source` into a wire-agnostic shape. */
|
|
13
|
+
export type NormalizedImageSource = {
|
|
14
|
+
kind: 'base64';
|
|
15
|
+
mediaType: string;
|
|
16
|
+
data: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'url';
|
|
19
|
+
url: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Reduce a raw (untrusted) image `source` to a normalized base64/url shape,
|
|
23
|
+
* or `null` when it is neither. Callers treat `null` as "drop this image"
|
|
24
|
+
* — silently, to avoid smuggling a misleading placeholder into the model's
|
|
25
|
+
* context.
|
|
26
|
+
*
|
|
27
|
+
* Takes `unknown` because the source arrives off a loosely-typed message
|
|
28
|
+
* payload (history replay, MCP tool output) where the discriminant is not
|
|
29
|
+
* statically guaranteed.
|
|
30
|
+
*/
|
|
31
|
+
export declare function normalizeCanonicalImageSource(source: unknown): NormalizedImageSource | null;
|
|
32
|
+
/**
|
|
33
|
+
* Render a normalized image as a single string usable wherever a wire format
|
|
34
|
+
* wants one field: a `data:` URI for base64, or the url verbatim. Used by the
|
|
35
|
+
* OpenAI `image_url` and Responses `input_image` parts.
|
|
36
|
+
*/
|
|
37
|
+
export declare function imageSourceToDataUri(img: NormalizedImageSource): string;
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
* future refactors (e.g. splitting types/runtime validators/brands) do
|
|
6
6
|
* not ripple through consumer imports.
|
|
7
7
|
*/
|
|
8
|
-
export { CANONICAL_VERSION, CanonicalAPIError, CanonicalUserAbortError, type CanonicalBase64ImageSource, type CanonicalContentBlock, type CanonicalContentBlockParam, type CanonicalImageBlockParam, type CanonicalMessage, type CanonicalMessageParam, type CanonicalStreamEvent, type CanonicalTextBlock, type CanonicalTextBlockParam, type CanonicalRedactedThinkingBlock, type CanonicalRedactedThinkingBlockParam, type CanonicalThinkingBlock, type CanonicalThinkingBlockParam, type CanonicalToolResultBlockParam, type CanonicalToolUnion, type CanonicalToolUseBlock, type CanonicalToolUseBlockParam, type CanonicalUsage, type CanonicalVersion, } from './types.js';
|
|
8
|
+
export { CANONICAL_VERSION, CanonicalAPIError, CanonicalUserAbortError, type CanonicalBase64ImageSource, type CanonicalURLImageSource, type CanonicalImageSource, type CanonicalContentBlock, type CanonicalContentBlockParam, type CanonicalImageBlockParam, type CanonicalMessage, type CanonicalMessageParam, type CanonicalStreamEvent, type CanonicalTextBlock, type CanonicalTextBlockParam, type CanonicalRedactedThinkingBlock, type CanonicalRedactedThinkingBlockParam, type CanonicalThinkingBlock, type CanonicalThinkingBlockParam, type CanonicalToolResultBlockParam, type CanonicalToolUnion, type CanonicalToolUseBlock, type CanonicalToolUseBlockParam, type CanonicalUsage, type CanonicalVersion, } from './types.js';
|
|
9
|
+
export { imageSourceToDataUri, normalizeCanonicalImageSource, type NormalizedImageSource, } from './imageSource.js';
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* `src/session/canonical/index.js`.
|
|
46
46
|
*/
|
|
47
47
|
import { APIError, APIUserAbortError } from '@anthropic-ai/sdk';
|
|
48
|
-
import type { BetaBase64ImageSource, BetaContentBlock, BetaContentBlockParam, BetaImageBlockParam, BetaMessage, BetaMessageParam, BetaRawMessageStreamEvent, BetaRedactedThinkingBlock, BetaRedactedThinkingBlockParam, BetaTextBlock, BetaTextBlockParam, BetaThinkingBlock, BetaThinkingBlockParam, BetaToolResultBlockParam, BetaToolUnion, BetaToolUseBlock, BetaToolUseBlockParam, BetaUsage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
|
|
48
|
+
import type { BetaBase64ImageSource, BetaURLImageSource, BetaContentBlock, BetaContentBlockParam, BetaImageBlockParam, BetaMessage, BetaMessageParam, BetaRawMessageStreamEvent, BetaRedactedThinkingBlock, BetaRedactedThinkingBlockParam, BetaTextBlock, BetaTextBlockParam, BetaThinkingBlock, BetaThinkingBlockParam, BetaToolResultBlockParam, BetaToolUnion, BetaToolUseBlock, BetaToolUseBlockParam, BetaUsage } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs';
|
|
49
49
|
export type CanonicalVersion = 'v1';
|
|
50
50
|
/**
|
|
51
51
|
* Current canonical schema version. Consumers that persist canonical
|
|
@@ -98,6 +98,10 @@ export type CanonicalStreamEvent = BetaRawMessageStreamEvent;
|
|
|
98
98
|
export type CanonicalImageBlockParam = BetaImageBlockParam;
|
|
99
99
|
/** Base64-encoded image source inside an image block. */
|
|
100
100
|
export type CanonicalBase64ImageSource = BetaBase64ImageSource;
|
|
101
|
+
/** External-URL image source inside an image block. */
|
|
102
|
+
export type CanonicalURLImageSource = BetaURLImageSource;
|
|
103
|
+
/** Discriminated union of every image-source variant carried by an image block. */
|
|
104
|
+
export type CanonicalImageSource = CanonicalBase64ImageSource | CanonicalURLImageSource;
|
|
101
105
|
/** Token-usage metadata carried on assistant messages and deltas. */
|
|
102
106
|
export type CanonicalUsage = BetaUsage;
|
|
103
107
|
/**
|
|
@@ -48,6 +48,22 @@ export type ValidationResult = {
|
|
|
48
48
|
message: string;
|
|
49
49
|
errorCode: number;
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Host-supplied media uploader (see `Options.uploadMedia`). Given media
|
|
53
|
+
* bytes + media type, returns a fetchable URL the model side can render,
|
|
54
|
+
* or `null` when upload is unavailable. Media-neutral: serves any binary a
|
|
55
|
+
* tool produces (image / PDF / extracted page image, ...), driven by
|
|
56
|
+
* `mediaType`. The SDK passes the **compressed** buffer (post token-budget),
|
|
57
|
+
* so the materialized bytes stay bounded.
|
|
58
|
+
*
|
|
59
|
+
* Returning `null` or throwing means "uploader unavailable" — callers fall
|
|
60
|
+
* back to inline base64. Pure port: no SDK/CLI behavior depends on it being
|
|
61
|
+
* set, so standalone runs are unaffected.
|
|
62
|
+
*/
|
|
63
|
+
export type UploadMediaFn = (input: {
|
|
64
|
+
bytes: Uint8Array;
|
|
65
|
+
mediaType: string;
|
|
66
|
+
}) => Promise<string | null>;
|
|
51
67
|
export type ToolPermissionContext = DeepImmutable<{
|
|
52
68
|
mode: PermissionMode;
|
|
53
69
|
additionalWorkingDirectories: Map<string, AdditionalWorkingDirectory>;
|
|
@@ -96,6 +112,7 @@ export type ToolRuntimeContext = {
|
|
|
96
112
|
agentDefinitions: AgentDefinitionsResult;
|
|
97
113
|
maxBudgetUsd?: number;
|
|
98
114
|
maxOutputTokens?: number;
|
|
115
|
+
maxOutputTokensLimit?: number;
|
|
99
116
|
contextWindow?: number;
|
|
100
117
|
customSystemPrompt?: string;
|
|
101
118
|
appendSystemPrompt?: string;
|
|
@@ -143,6 +160,13 @@ export type ToolRuntimeContext = {
|
|
|
143
160
|
toolInput: Record<string, unknown>;
|
|
144
161
|
toolUseId: string;
|
|
145
162
|
}) => void | Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Host-injected media uploader (see `Options.uploadMedia`). When present,
|
|
165
|
+
* media-producing tools (FileReadTool) upload the compressed bytes and
|
|
166
|
+
* carry a URL instead of inline base64. Absent → base64 (zero-config
|
|
167
|
+
* standalone behavior).
|
|
168
|
+
*/
|
|
169
|
+
uploadMedia?: UploadMediaFn;
|
|
146
170
|
updateFileHistoryState: (updater: (prev: FileHistoryState) => FileHistoryState) => void;
|
|
147
171
|
updateAttributionState: (updater: (prev: AttributionState) => AttributionState) => void;
|
|
148
172
|
setConversationId?: (id: UUID) => void;
|
package/package.json
CHANGED