anyclaude-sdk 0.4.8 → 0.4.9
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/llm/index.d.ts +1 -0
- package/dist/llm/openai.d.ts +24 -1
- package/dist/llm/openai.js +22 -3
- package/package.json +1 -1
package/dist/llm/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export * from './openai.js';
|
|
|
2
2
|
export * from './anthropic.js';
|
|
3
3
|
export * from './responses.js';
|
|
4
4
|
export { hasInlineToolCalls, parseInlineToolCalls } from './inlineTools.js';
|
|
5
|
+
export type { LLMClient, ChatMsg, StreamResult, ToolCall, ToolDef, StopReason, Usage, ContentBlockParam, } from '../types/index.js';
|
package/dist/llm/openai.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LLMClient } from '../types/index.js';
|
|
1
|
+
import type { ChatMsg, ContentBlockParam, LLMClient } from '../types/index.js';
|
|
2
2
|
export interface OpenAIClientOptions {
|
|
3
3
|
/** API key, or a function returning one per request (for round-robin key pools). */
|
|
4
4
|
apiKey?: string | (() => string | undefined);
|
|
@@ -25,5 +25,28 @@ export interface OpenAIClientOptions {
|
|
|
25
25
|
* from streamed deltas) via the returned StreamResult and the `onTool` hook.
|
|
26
26
|
*/
|
|
27
27
|
export declare function createOpenAIClient(options?: OpenAIClientOptions): LLMClient;
|
|
28
|
+
/** A single message in OpenAI `/chat/completions` wire shape. */
|
|
29
|
+
export type OpenAIChatMessage = Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Convert the SDK's provider-neutral `ChatMsg[]` into OpenAI `/chat/completions`
|
|
32
|
+
* `messages`. Exported so custom `LLMClient` authors who bring their own
|
|
33
|
+
* transport (proxy, encryption, alternate URL) can reuse the SDK's canonical
|
|
34
|
+
* wire conversion instead of forking it — keeping content-block mapping
|
|
35
|
+
* (text / image / PDF `document` / `tool_result`) in lockstep with the
|
|
36
|
+
* built-in `createOpenAIClient`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function toOpenAIMessages(messages: ChatMsg[]): OpenAIChatMessage[];
|
|
39
|
+
/** Convert our provider-neutral ChatMsg into an OpenAI chat message. */
|
|
40
|
+
export declare function toOpenAIMessage(msg: ChatMsg): OpenAIChatMessage;
|
|
41
|
+
/**
|
|
42
|
+
* Map content blocks to OpenAI multimodal `content` parts
|
|
43
|
+
* (`text` / `image_url` / `file`). Exported for custom `LLMClient` authors.
|
|
44
|
+
*/
|
|
45
|
+
export declare function blocksToOpenAIContent(blocks: ContentBlockParam[]): unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Flatten `text` + nested `tool_result` content blocks to a plain string
|
|
48
|
+
* (used for `assistant`/`tool` roles). Exported for custom `LLMClient` authors.
|
|
49
|
+
*/
|
|
50
|
+
export declare function blocksToText(blocks: ContentBlockParam[]): string;
|
|
28
51
|
/** Read an SSE response body, invoking `onData` for each `data:` payload. */
|
|
29
52
|
export declare function consumeSSE(body: ReadableStream<Uint8Array>, onData: (data: string) => void): Promise<void>;
|
package/dist/llm/openai.js
CHANGED
|
@@ -131,8 +131,19 @@ function mapFinishReason(reason) {
|
|
|
131
131
|
return reason ? 'end_turn' : null;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Convert the SDK's provider-neutral `ChatMsg[]` into OpenAI `/chat/completions`
|
|
136
|
+
* `messages`. Exported so custom `LLMClient` authors who bring their own
|
|
137
|
+
* transport (proxy, encryption, alternate URL) can reuse the SDK's canonical
|
|
138
|
+
* wire conversion instead of forking it — keeping content-block mapping
|
|
139
|
+
* (text / image / PDF `document` / `tool_result`) in lockstep with the
|
|
140
|
+
* built-in `createOpenAIClient`.
|
|
141
|
+
*/
|
|
142
|
+
export function toOpenAIMessages(messages) {
|
|
143
|
+
return messages.map(toOpenAIMessage);
|
|
144
|
+
}
|
|
134
145
|
/** Convert our provider-neutral ChatMsg into an OpenAI chat message. */
|
|
135
|
-
function toOpenAIMessage(msg) {
|
|
146
|
+
export function toOpenAIMessage(msg) {
|
|
136
147
|
if (msg.role === 'tool') {
|
|
137
148
|
return {
|
|
138
149
|
role: 'tool',
|
|
@@ -155,7 +166,11 @@ function toOpenAIMessage(msg) {
|
|
|
155
166
|
}
|
|
156
167
|
return { role: msg.role, content: blocksToOpenAIContent(msg.content) };
|
|
157
168
|
}
|
|
158
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Map content blocks to OpenAI multimodal `content` parts
|
|
171
|
+
* (`text` / `image_url` / `file`). Exported for custom `LLMClient` authors.
|
|
172
|
+
*/
|
|
173
|
+
export function blocksToOpenAIContent(blocks) {
|
|
159
174
|
const parts = [];
|
|
160
175
|
for (const b of blocks) {
|
|
161
176
|
if (b.type === 'text')
|
|
@@ -186,7 +201,11 @@ function blocksToOpenAIContent(blocks) {
|
|
|
186
201
|
}
|
|
187
202
|
return parts.length ? parts : '';
|
|
188
203
|
}
|
|
189
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Flatten `text` + nested `tool_result` content blocks to a plain string
|
|
206
|
+
* (used for `assistant`/`tool` roles). Exported for custom `LLMClient` authors.
|
|
207
|
+
*/
|
|
208
|
+
export function blocksToText(blocks) {
|
|
190
209
|
return blocks
|
|
191
210
|
.map((b) => {
|
|
192
211
|
if (b.type === 'text')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anyclaude-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "Standalone, browser-compatible SDK providing Claude Code agent capabilities (tools, tool loop, multi-turn, MCP, sub-agents, sessions) against any OpenAI/Anthropic-compatible LLM endpoint. Runs in the browser (WebContainer), Node, and Bun — no backend required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|