@workglow/anthropic 0.2.28
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/ai-provider/AnthropicProvider.d.ts +31 -0
- package/dist/ai-provider/AnthropicProvider.d.ts.map +1 -0
- package/dist/ai-provider/AnthropicQueuedProvider.d.ts +18 -0
- package/dist/ai-provider/AnthropicQueuedProvider.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_Chat.d.ts +10 -0
- package/dist/ai-provider/common/Anthropic_Chat.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_Client.d.ts +13 -0
- package/dist/ai-provider/common/Anthropic_Client.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_Constants.d.ts +7 -0
- package/dist/ai-provider/common/Anthropic_Constants.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_CountTokens.d.ts +10 -0
- package/dist/ai-provider/common/Anthropic_CountTokens.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_JobRunFns.d.ts +12 -0
- package/dist/ai-provider/common/Anthropic_JobRunFns.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_ModelInfo.d.ts +9 -0
- package/dist/ai-provider/common/Anthropic_ModelInfo.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_ModelSchema.d.ts +170 -0
- package/dist/ai-provider/common/Anthropic_ModelSchema.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_ModelSearch.d.ts +8 -0
- package/dist/ai-provider/common/Anthropic_ModelSearch.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_StructuredGeneration.d.ts +10 -0
- package/dist/ai-provider/common/Anthropic_StructuredGeneration.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_TextGeneration.d.ts +10 -0
- package/dist/ai-provider/common/Anthropic_TextGeneration.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_TextRewriter.d.ts +10 -0
- package/dist/ai-provider/common/Anthropic_TextRewriter.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_TextSummary.d.ts +10 -0
- package/dist/ai-provider/common/Anthropic_TextSummary.d.ts.map +1 -0
- package/dist/ai-provider/common/Anthropic_ToolCalling.d.ts +11 -0
- package/dist/ai-provider/common/Anthropic_ToolCalling.d.ts.map +1 -0
- package/dist/ai-provider/index.d.ts +10 -0
- package/dist/ai-provider/index.d.ts.map +1 -0
- package/dist/ai-provider/registerAnthropic.d.ts +10 -0
- package/dist/ai-provider/registerAnthropic.d.ts.map +1 -0
- package/dist/ai-provider/registerAnthropicInline.d.ts +8 -0
- package/dist/ai-provider/registerAnthropicInline.d.ts.map +1 -0
- package/dist/ai-provider/registerAnthropicWorker.d.ts +7 -0
- package/dist/ai-provider/registerAnthropicWorker.d.ts.map +1 -0
- package/dist/ai-provider/runtime.d.ts +16 -0
- package/dist/ai-provider/runtime.d.ts.map +1 -0
- package/dist/ai-provider-runtime.d.ts +7 -0
- package/dist/ai-provider-runtime.d.ts.map +1 -0
- package/dist/ai-provider-runtime.js +706 -0
- package/dist/ai-provider-runtime.js.map +25 -0
- package/dist/ai-provider.d.ts +7 -0
- package/dist/ai-provider.d.ts.map +1 -0
- package/dist/ai-provider.js +202 -0
- package/dist/ai-provider.js.map +15 -0
- package/package.json +60 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ai-provider/common/Anthropic_Client.ts", "../src/ai-provider/registerAnthropicInline.ts", "../src/ai-provider/AnthropicQueuedProvider.ts", "../src/ai-provider/common/Anthropic_Constants.ts", "../src/ai-provider/common/Anthropic_ModelSearch.ts", "../src/ai-provider/common/Anthropic_ToolCalling.ts", "../src/ai-provider/common/Anthropic_Chat.ts", "../src/ai-provider/common/Anthropic_CountTokens.ts", "../src/ai-provider/common/Anthropic_ModelInfo.ts", "../src/ai-provider/common/Anthropic_StructuredGeneration.ts", "../src/ai-provider/common/Anthropic_TextGeneration.ts", "../src/ai-provider/common/Anthropic_TextRewriter.ts", "../src/ai-provider/common/Anthropic_TextSummary.ts", "../src/ai-provider/common/Anthropic_JobRunFns.ts", "../src/ai-provider/registerAnthropicWorker.ts", "../src/ai-provider/AnthropicProvider.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nlet _sdk: typeof import(\"@anthropic-ai/sdk\") | undefined;\n\nexport async function loadAnthropicSDK() {\n if (!_sdk) {\n try {\n _sdk = await import(\"@anthropic-ai/sdk\");\n } catch {\n throw new Error(\n \"@anthropic-ai/sdk is required for Anthropic tasks. Install it with: bun add @anthropic-ai/sdk\"\n );\n }\n }\n return _sdk.default;\n}\n\ninterface ResolvedProviderConfig {\n readonly credential_key?: string;\n readonly api_key?: string;\n readonly model_name?: string;\n readonly base_url?: string;\n readonly max_tokens?: number;\n}\n\nexport async function getClient(model: AnthropicModelConfig | undefined) {\n const Anthropic = await loadAnthropicSDK();\n const config = model?.provider_config as ResolvedProviderConfig | undefined;\n const apiKey =\n config?.credential_key ||\n config?.api_key ||\n (typeof process !== \"undefined\" ? process.env?.ANTHROPIC_API_KEY : undefined);\n if (!apiKey) {\n throw new Error(\n \"Missing Anthropic API key: set provider_config.credential_key or the ANTHROPIC_API_KEY environment variable.\"\n );\n }\n try {\n return new Anthropic({\n apiKey,\n baseURL: config?.base_url || undefined,\n dangerouslyAllowBrowser:\n typeof globalThis.document !== \"undefined\" || \"WorkerGlobalScope\" in globalThis,\n });\n } catch (err) {\n throw new Error(\n `Failed to create Anthropic client: ${err instanceof Error ? err.message : \"unknown error\"}`\n );\n }\n}\n\nexport function getModelName(model: AnthropicModelConfig | undefined): string {\n const name = model?.provider_config?.model_name;\n if (!name) {\n throw new Error(\"Missing model name in provider_config.model_name.\");\n }\n return name;\n}\n\nexport function getMaxTokens(\n input: { maxTokens?: number },\n model: AnthropicModelConfig | undefined\n): number {\n return input.maxTokens ?? model?.provider_config?.max_tokens ?? 1024;\n}\n",
|
|
6
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AiProviderRegisterOptions } from \"@workglow/ai\";\nimport { registerProviderInline } from \"@workglow/ai-provider/common\";\nimport { AnthropicQueuedProvider } from \"./AnthropicQueuedProvider\";\nimport {\n ANTHROPIC_PREVIEW_TASKS,\n ANTHROPIC_STREAM_TASKS,\n ANTHROPIC_TASKS,\n} from \"./common/Anthropic_JobRunFns\";\n\nexport async function registerAnthropicInline(options?: AiProviderRegisterOptions): Promise<void> {\n await registerProviderInline(\n new AnthropicQueuedProvider(ANTHROPIC_TASKS, ANTHROPIC_STREAM_TASKS, ANTHROPIC_PREVIEW_TASKS),\n \"Anthropic\",\n options\n );\n}\n",
|
|
7
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { AiProvider } from \"@workglow/ai\";\nimport type { AiProviderPreviewRunFn, AiProviderRunFn, AiProviderStreamFn } from \"@workglow/ai\";\nimport { ANTHROPIC } from \"./common/Anthropic_Constants\";\nimport type { AnthropicModelConfig } from \"./common/Anthropic_ModelSchema\";\n\n/** Main-thread registration (inline or worker-backed). No queue — uses direct execution. */\nexport class AnthropicQueuedProvider extends AiProvider<AnthropicModelConfig> {\n readonly name = ANTHROPIC;\n readonly displayName = \"Anthropic\";\n readonly isLocal = false;\n readonly supportsBrowser = true;\n\n readonly taskTypes = [\n \"CountTokensTask\",\n \"ModelInfoTask\",\n \"TextGenerationTask\",\n \"TextRewriterTask\",\n \"TextSummaryTask\",\n \"StructuredGenerationTask\",\n \"ToolCallingTask\",\n \"ModelSearchTask\",\n ] as const;\n\n constructor(\n tasks?: Record<string, AiProviderRunFn<any, any, AnthropicModelConfig>>,\n streamTasks?: Record<string, AiProviderStreamFn<any, any, AnthropicModelConfig>>,\n previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, AnthropicModelConfig>>\n ) {\n super(tasks, streamTasks, previewTasks);\n }\n}\n",
|
|
8
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport const ANTHROPIC = \"ANTHROPIC\";\n",
|
|
9
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n ModelSearchResultItem,\n ModelSearchTaskInput,\n ModelSearchTaskOutput,\n} from \"@workglow/ai\";\nimport { filterLabeledModelsByQuery } from \"@workglow/ai-provider/common\";\nimport { getClient } from \"./Anthropic_Client\";\nimport { ANTHROPIC } from \"./Anthropic_Constants\";\n\nconst ANTHROPIC_FALLBACK: Array<{ label: string; value: string }> = [\n { label: \"claude-opus-4-7\", value: \"claude-opus-4-7\" },\n { label: \"claude-sonnet-4-6\", value: \"claude-sonnet-4-6\" },\n { label: \"claude-haiku-4-5-20251001\", value: \"claude-haiku-4-5-20251001\" },\n { label: \"claude-opus-4-6\", value: \"claude-opus-4-6\" },\n { label: \"claude-sonnet-4-5-20250929\", value: \"claude-sonnet-4-5-20250929\" },\n { label: \"claude-3-5-sonnet-20241022\", value: \"claude-3-5-sonnet-20241022\" },\n { label: \"claude-3-5-haiku-20241022\", value: \"claude-3-5-haiku-20241022\" },\n];\n\nasync function listAnthropicModels(\n credentialKey: string\n): Promise<Array<{ label: string; value: string }>> {\n const client = await getClient({\n provider: ANTHROPIC,\n provider_config: { model_name: \"\", credential_key: credentialKey },\n });\n const models: Array<{ label: string; value: string }> = [];\n for await (const m of client.beta.models.list()) {\n models.push({ label: `${m.id} ${m.display_name}`, value: m.id });\n }\n return models;\n}\n\nfunction mapModelList(models: Array<{ label: string; value: string }>): ModelSearchResultItem[] {\n return models.map((m) => ({\n id: m.value,\n label: m.label,\n description: \"\",\n record: {\n model_id: m.value,\n provider: ANTHROPIC,\n title: m.value,\n description: \"\",\n tasks: [],\n provider_config: { model_name: m.value },\n metadata: {},\n },\n raw: m,\n }));\n}\n\nexport const Anthropic_ModelSearch: AiProviderRunFn<\n ModelSearchTaskInput,\n ModelSearchTaskOutput\n> = async (input) => {\n let models: Array<{ label: string; value: string }>;\n if (!input.credential_key) {\n models = ANTHROPIC_FALLBACK;\n } else {\n models = await listAnthropicModels(input.credential_key);\n }\n models = filterLabeledModelsByQuery(models, input.query);\n return { results: mapModelList(models) };\n};\n",
|
|
10
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n AiProviderStreamFn,\n ChatMessage,\n ToolCall,\n ToolCallingTaskInput,\n ToolCallingTaskOutput,\n ToolCalls,\n ToolDefinition,\n} from \"@workglow/ai\";\nimport { buildToolDescription, filterValidToolCalls } from \"@workglow/ai/worker\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { parsePartialJson } from \"@workglow/util/worker\";\nimport { getClient, getMaxTokens, getModelName } from \"./Anthropic_Client\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nexport function buildAnthropicMessages(\n messages: ReadonlyArray<ChatMessage> | undefined,\n prompt: unknown\n): any[] {\n if (!messages || messages.length === 0) {\n return [{ role: \"user\", content: prompt }];\n }\n const out: any[] = [];\n for (const msg of messages) {\n if (msg.role === \"user\") {\n const blocks = msg.content.map((b) => {\n if (b.type === \"text\") return { type: \"text\", text: b.text };\n if (b.type === \"image\") {\n return {\n type: \"image\",\n source: { type: \"base64\", media_type: b.mimeType, data: b.data },\n };\n }\n return b;\n });\n out.push({ role: \"user\", content: blocks });\n } else if (msg.role === \"assistant\") {\n const blocks = msg.content.map((b) => {\n if (b.type === \"text\") return { type: \"text\", text: b.text };\n if (b.type === \"tool_use\") {\n return { type: \"tool_use\", id: b.id, name: b.name, input: b.input };\n }\n return b;\n });\n out.push({ role: \"assistant\", content: blocks });\n } else if (msg.role === \"tool\") {\n const blocks = msg.content\n .filter(\n (b): b is Extract<ChatMessage[\"content\"][number], { type: \"tool_result\" }> =>\n b.type === \"tool_result\"\n )\n .map((b) => {\n const content = b.content.map((inner) => {\n if (inner.type === \"text\") return { type: \"text\", text: inner.text };\n if (inner.type === \"image\") {\n return {\n type: \"image\",\n source: { type: \"base64\", media_type: inner.mimeType, data: inner.data },\n };\n }\n return inner;\n });\n return {\n type: \"tool_result\",\n tool_use_id: b.tool_use_id,\n content,\n ...(b.is_error ? { is_error: true } : {}),\n };\n });\n out.push({ role: \"user\", content: blocks });\n } else if (msg.role === \"system\") {\n // System prompts are handled separately via params.system; skip here.\n continue;\n }\n }\n return out;\n}\n\nfunction mapAnthropicToolChoice(\n toolChoice: string | undefined\n): { type: \"auto\" } | { type: \"any\" } | { type: \"tool\"; name: string } | undefined {\n if (!toolChoice || toolChoice === \"auto\") return { type: \"auto\" };\n if (toolChoice === \"none\") return undefined;\n if (toolChoice === \"required\") return { type: \"any\" };\n return { type: \"tool\", name: toolChoice };\n}\n\nexport const Anthropic_ToolCalling: AiProviderRunFn<\n ToolCallingTaskInput,\n ToolCallingTaskOutput,\n AnthropicModelConfig\n> = async (input, model, update_progress, signal, _outputSchema, sessionId) => {\n update_progress(0, \"Starting Anthropic tool calling\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const tools = input.tools.map((t: ToolDefinition) => ({\n name: t.name,\n description: buildToolDescription(t),\n input_schema: t.inputSchema as any,\n }));\n\n const toolChoice = mapAnthropicToolChoice(input.toolChoice);\n\n const messages = buildAnthropicMessages(input.messages, input.prompt);\n\n const params: any = {\n model: modelName,\n messages,\n max_tokens: getMaxTokens(input, model),\n temperature: input.temperature,\n };\n\n if (input.systemPrompt) {\n params.system = input.systemPrompt;\n }\n\n if (toolChoice !== undefined) {\n params.tools = tools;\n params.tool_choice = toolChoice;\n }\n\n if (sessionId) {\n // Add cache_control breakpoints for Anthropic prompt caching\n if (params.system) {\n params.system = [\n {\n type: \"text\",\n text: params.system,\n cache_control: { type: \"ephemeral\" },\n },\n ];\n }\n if (params.tools && params.tools.length > 0) {\n const lastIdx = params.tools.length - 1;\n params.tools[lastIdx] = {\n ...params.tools[lastIdx],\n cache_control: { type: \"ephemeral\" },\n };\n }\n }\n\n const response = await client.messages.create(params, { signal });\n\n const text = response.content\n .filter((b: any) => b.type === \"text\")\n .map((b: any) => b.text)\n .join(\"\");\n\n const toolCalls: ToolCalls = [];\n response.content\n .filter((b: any) => b.type === \"tool_use\")\n .forEach((b: any) => {\n toolCalls.push({\n id: b.id as string,\n name: b.name as string,\n input: (b.input as Record<string, unknown>) ?? {},\n });\n });\n\n update_progress(100, \"Completed Anthropic tool calling\");\n return { text, toolCalls: filterValidToolCalls(toolCalls, input.tools) };\n};\n\nexport const Anthropic_ToolCalling_Stream: AiProviderStreamFn<\n ToolCallingTaskInput,\n ToolCallingTaskOutput,\n AnthropicModelConfig\n> = async function* (\n input,\n model,\n signal,\n _outputSchema,\n sessionId\n): AsyncIterable<StreamEvent<ToolCallingTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const tools = input.tools.map((t: ToolDefinition) => ({\n name: t.name,\n description: buildToolDescription(t),\n input_schema: t.inputSchema as any,\n }));\n\n const toolChoice = mapAnthropicToolChoice(input.toolChoice);\n\n const messages = buildAnthropicMessages(input.messages, input.prompt);\n\n const params: any = {\n model: modelName,\n messages,\n max_tokens: getMaxTokens(input, model),\n temperature: input.temperature,\n };\n\n if (input.systemPrompt) {\n params.system = input.systemPrompt;\n }\n\n if (toolChoice !== undefined) {\n params.tools = tools;\n params.tool_choice = toolChoice;\n }\n\n if (sessionId) {\n // Add cache_control breakpoints for Anthropic prompt caching\n if (params.system) {\n params.system = [\n {\n type: \"text\",\n text: params.system,\n cache_control: { type: \"ephemeral\" },\n },\n ];\n }\n if (params.tools && params.tools.length > 0) {\n const lastIdx = params.tools.length - 1;\n params.tools[lastIdx] = {\n ...params.tools[lastIdx],\n cache_control: { type: \"ephemeral\" },\n };\n }\n }\n\n const stream = client.messages.stream(params, { signal });\n\n const blockMeta = new Map<number, { type: string; id?: string; name?: string; json: string }>();\n /** Keyed by Anthropic content block index — avoids collisions when `id` is missing during early deltas. */\n const toolCallsByBlockIndex = new Map<number, ToolCall>();\n\n const toolCallsInStreamOrder = (): ToolCall[] =>\n [...toolCallsByBlockIndex.entries()].sort((a, b) => a[0] - b[0]).map(([, tc]) => tc);\n\n for await (const event of stream) {\n if (event.type === \"content_block_start\") {\n const block = event.content_block;\n const index = event.index as number;\n if (block.type === \"tool_use\") {\n blockMeta.set(index, {\n type: \"tool_use\",\n id: block.id,\n name: block.name,\n json: \"\",\n });\n } else if (block.type === \"text\") {\n blockMeta.set(index, { type: \"text\", json: \"\" });\n }\n } else if (event.type === \"content_block_delta\") {\n const index = event.index as number;\n const delta = event.delta as any;\n if (delta.type === \"text_delta\") {\n yield { type: \"text-delta\", port: \"text\", textDelta: delta.text };\n } else if (delta.type === \"input_json_delta\") {\n const meta = blockMeta.get(index);\n if (meta) {\n meta.json += delta.partial_json;\n let parsedInput: Record<string, unknown>;\n try {\n parsedInput = JSON.parse(meta.json);\n } catch {\n const partial = parsePartialJson(meta.json);\n parsedInput = (partial as Record<string, unknown>) ?? {};\n }\n toolCallsByBlockIndex.set(index, {\n id: meta.id ?? \"\",\n name: meta.name ?? \"\",\n input: parsedInput,\n });\n yield {\n type: \"object-delta\",\n port: \"toolCalls\",\n objectDelta: toolCallsInStreamOrder(),\n };\n }\n }\n } else if (event.type === \"content_block_stop\") {\n const index = event.index as number;\n const meta = blockMeta.get(index);\n if (meta?.type === \"tool_use\") {\n let finalInput: Record<string, unknown>;\n try {\n finalInput = JSON.parse(meta.json);\n } catch {\n finalInput = (parsePartialJson(meta.json) as Record<string, unknown>) ?? {};\n }\n const id = meta.id ?? \"\";\n toolCallsByBlockIndex.set(index, { id, name: meta.name ?? \"\", input: finalInput });\n yield {\n type: \"object-delta\",\n port: \"toolCalls\",\n objectDelta: toolCallsInStreamOrder(),\n };\n }\n blockMeta.delete(index);\n }\n }\n\n yield { type: \"finish\", data: { text: \"\", toolCalls: [] } as ToolCallingTaskOutput };\n};\n",
|
|
11
|
+
"/**\n * @license\n * Copyright 2026 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiChatProviderInput,\n AiChatProviderOutput,\n AiProviderRunFn,\n AiProviderStreamFn,\n} from \"@workglow/ai\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { getClient, getMaxTokens, getModelName } from \"./Anthropic_Client\";\nimport { buildAnthropicMessages } from \"./Anthropic_ToolCalling\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nfunction buildParams(\n input: AiChatProviderInput,\n model: AnthropicModelConfig | undefined,\n sessionId: string | undefined\n): Record<string, unknown> {\n const messages = buildAnthropicMessages(input.messages, input.prompt);\n const params: Record<string, unknown> = {\n model: getModelName(model),\n messages,\n max_tokens: getMaxTokens({ maxTokens: input.maxTokens } as any, model),\n };\n if (input.temperature !== undefined) params.temperature = input.temperature;\n if (input.systemPrompt) {\n params.system = sessionId\n ? [\n {\n type: \"text\",\n text: input.systemPrompt,\n cache_control: { type: \"ephemeral\" },\n },\n ]\n : input.systemPrompt;\n }\n if (sessionId && messages.length > 0) {\n const last = messages[messages.length - 1] as { content: unknown };\n if (Array.isArray(last.content) && last.content.length > 0) {\n const blocks = last.content as Array<Record<string, unknown>>;\n blocks[blocks.length - 1] = {\n ...blocks[blocks.length - 1],\n cache_control: { type: \"ephemeral\" },\n };\n }\n }\n return params;\n}\n\nexport const Anthropic_Chat: AiProviderRunFn<\n AiChatProviderInput,\n AiChatProviderOutput,\n AnthropicModelConfig\n> = async (input, model, update_progress, signal, _outputSchema, sessionId) => {\n update_progress(0, \"Anthropic chat turn\");\n const client = await getClient(model);\n const params = buildParams(input, model, sessionId);\n const response = await (client.messages.create as any)(params, { signal });\n const text = ((response as any).content as Array<Record<string, unknown>>)\n .filter((b) => b.type === \"text\")\n .map((b) => b.text as string)\n .join(\"\");\n update_progress(100, \"Turn complete\");\n return { text };\n};\n\nexport const Anthropic_Chat_Stream: AiProviderStreamFn<\n AiChatProviderInput,\n AiChatProviderOutput,\n AnthropicModelConfig\n> = async function* (\n input,\n model,\n signal,\n _outputSchema,\n sessionId\n): AsyncIterable<StreamEvent<AiChatProviderOutput>> {\n const client = await getClient(model);\n const params = buildParams(input, model, sessionId);\n const stream = (client.messages.stream as any)(params, { signal });\n for await (const event of stream) {\n const e = event as { type: string; delta?: { type?: string; text?: string } };\n if (e.type === \"content_block_delta\" && e.delta?.type === \"text_delta\") {\n yield { type: \"text-delta\", port: \"text\", textDelta: e.delta.text ?? \"\" };\n }\n }\n yield { type: \"finish\", data: {} as AiChatProviderOutput };\n};\n",
|
|
12
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderPreviewRunFn,\n AiProviderRunFn,\n CountTokensTaskInput,\n CountTokensTaskOutput,\n} from \"@workglow/ai\";\nimport { getClient, getModelName } from \"./Anthropic_Client\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nexport const Anthropic_CountTokens: AiProviderRunFn<\n CountTokensTaskInput,\n CountTokensTaskOutput,\n AnthropicModelConfig\n> = async (input, model, onProgress, signal) => {\n const client = await getClient(model);\n const result = await client.messages.countTokens({\n model: getModelName(model),\n messages: [{ role: \"user\", content: input.text }],\n });\n return { count: result.input_tokens };\n};\n\nexport const Anthropic_CountTokens_Preview: AiProviderPreviewRunFn<\n CountTokensTaskInput,\n CountTokensTaskOutput,\n AnthropicModelConfig\n> = async (input, _model) => {\n return { count: Math.ceil(input.text.length / 4) };\n};\n",
|
|
13
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AiProviderRunFn, ModelInfoTaskInput, ModelInfoTaskOutput } from \"@workglow/ai\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nexport const Anthropic_ModelInfo: AiProviderRunFn<\n ModelInfoTaskInput,\n ModelInfoTaskOutput,\n AnthropicModelConfig\n> = async (input) => {\n if (input.detail === \"dimensions\") {\n return {\n model: input.model,\n is_local: false,\n is_remote: true,\n supports_browser: true,\n supports_node: true,\n is_cached: false,\n is_loaded: false,\n file_sizes: null,\n };\n }\n return {\n model: input.model,\n is_local: false,\n is_remote: true,\n supports_browser: true,\n supports_node: true,\n is_cached: false,\n is_loaded: false,\n file_sizes: null,\n };\n};\n",
|
|
14
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n AiProviderStreamFn,\n StructuredGenerationTaskInput,\n StructuredGenerationTaskOutput,\n} from \"@workglow/ai\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { parsePartialJson } from \"@workglow/util/worker\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\nimport { getClient, getMaxTokens, getModelName } from \"./Anthropic_Client\";\n\nexport const Anthropic_StructuredGeneration: AiProviderRunFn<\n StructuredGenerationTaskInput,\n StructuredGenerationTaskOutput,\n AnthropicModelConfig\n> = async (input, model, update_progress, signal, outputSchema) => {\n update_progress(0, \"Starting Anthropic structured generation\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const schema = input.outputSchema ?? outputSchema;\n\n const response = await client.messages.create(\n {\n model: modelName,\n messages: [{ role: \"user\", content: input.prompt as string }],\n tools: [\n {\n name: \"structured_output\",\n description: \"Output structured data conforming to the schema\",\n input_schema: schema as any,\n },\n ],\n tool_choice: { type: \"tool\" as const, name: \"structured_output\" },\n max_tokens: getMaxTokens(input, model),\n },\n { signal }\n );\n\n const toolBlock = response.content.find((b: any) => b.type === \"tool_use\") as any;\n const object = toolBlock?.input ?? {};\n\n update_progress(100, \"Completed Anthropic structured generation\");\n return { object };\n};\n\nexport const Anthropic_StructuredGeneration_Stream: AiProviderStreamFn<\n StructuredGenerationTaskInput,\n StructuredGenerationTaskOutput,\n AnthropicModelConfig\n> = async function* (\n input,\n model,\n signal,\n outputSchema\n): AsyncIterable<StreamEvent<StructuredGenerationTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const schema = input.outputSchema ?? outputSchema;\n\n const stream = client.messages.stream(\n {\n model: modelName,\n messages: [{ role: \"user\", content: input.prompt as string }],\n tools: [\n {\n name: \"structured_output\",\n description: \"Output structured data conforming to the schema\",\n input_schema: schema as any,\n },\n ],\n tool_choice: { type: \"tool\" as const, name: \"structured_output\" },\n max_tokens: getMaxTokens(input, model),\n },\n { signal }\n );\n\n let accumulatedJson = \"\";\n for await (const event of stream) {\n if (event.type === \"content_block_delta\" && event.delta.type === \"input_json_delta\") {\n accumulatedJson += event.delta.partial_json;\n const partial = parsePartialJson(accumulatedJson);\n if (partial !== undefined) {\n yield { type: \"object-delta\", port: \"object\", objectDelta: partial };\n }\n }\n }\n\n let finalObject: Record<string, unknown>;\n try {\n finalObject = JSON.parse(accumulatedJson);\n } catch {\n finalObject = parsePartialJson(accumulatedJson) ?? {};\n }\n yield { type: \"finish\", data: { object: finalObject } as StructuredGenerationTaskOutput };\n};\n",
|
|
15
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n AiProviderStreamFn,\n TextGenerationTaskInput,\n TextGenerationTaskOutput,\n} from \"@workglow/ai\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { getLogger } from \"@workglow/util/worker\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\nimport { getClient, getMaxTokens, getModelName } from \"./Anthropic_Client\";\n\nexport const Anthropic_TextGeneration: AiProviderRunFn<\n TextGenerationTaskInput,\n TextGenerationTaskOutput,\n AnthropicModelConfig\n> = async (input, model, update_progress, signal, _outputSchema, sessionId) => {\n const logger = getLogger();\n const timerLabel = `anthropic:TextGeneration:${model?.provider_config?.model_name}`;\n logger.time(timerLabel, { model: model?.provider_config?.model_name });\n\n update_progress(0, \"Starting Anthropic text generation\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const params: any = {\n model: modelName,\n messages: [{ role: \"user\", content: input.prompt }],\n max_tokens: getMaxTokens(input, model),\n temperature: input.temperature,\n top_p: input.topP,\n };\n\n // Cache annotation placeholder: TextGenerationTaskInput does not currently\n // include a systemPrompt field, so params.system is never set. When system\n // prompt support is added to TextGeneration, this block will activate.\n if (sessionId && params.system) {\n params.system = [\n {\n type: \"text\",\n text: params.system,\n cache_control: { type: \"ephemeral\" },\n },\n ];\n }\n\n const response = await client.messages.create(params, { signal });\n\n const text = response.content[0]?.type === \"text\" ? response.content[0].text : \"\";\n\n update_progress(100, \"Completed Anthropic text generation\");\n logger.timeEnd(timerLabel, { model: model?.provider_config?.model_name });\n return { text };\n};\n\nexport const Anthropic_TextGeneration_Stream: AiProviderStreamFn<\n TextGenerationTaskInput,\n TextGenerationTaskOutput,\n AnthropicModelConfig\n> = async function* (\n input,\n model,\n signal,\n _outputSchema,\n sessionId\n): AsyncIterable<StreamEvent<TextGenerationTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const params: any = {\n model: modelName,\n messages: [{ role: \"user\", content: input.prompt }],\n max_tokens: getMaxTokens(input, model),\n temperature: input.temperature,\n top_p: input.topP,\n };\n\n // Cache annotation placeholder: see comment in run function above.\n if (sessionId && params.system) {\n params.system = [\n {\n type: \"text\",\n text: params.system,\n cache_control: { type: \"ephemeral\" },\n },\n ];\n }\n\n const stream = client.messages.stream(params, { signal });\n\n for await (const event of stream) {\n if (event.type === \"content_block_delta\" && event.delta.type === \"text_delta\") {\n yield { type: \"text-delta\", port: \"text\", textDelta: event.delta.text };\n }\n }\n yield { type: \"finish\", data: {} as TextGenerationTaskOutput };\n};\n",
|
|
16
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n AiProviderStreamFn,\n TextRewriterTaskInput,\n TextRewriterTaskOutput,\n} from \"@workglow/ai\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { getClient, getMaxTokens, getModelName } from \"./Anthropic_Client\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nexport const Anthropic_TextRewriter: AiProviderRunFn<\n TextRewriterTaskInput,\n TextRewriterTaskOutput,\n AnthropicModelConfig\n> = async (input, model, update_progress, signal) => {\n update_progress(0, \"Starting Anthropic text rewriting\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const response = await client.messages.create(\n {\n model: modelName,\n system: input.prompt,\n messages: [{ role: \"user\", content: input.text }],\n max_tokens: getMaxTokens({}, model),\n },\n { signal }\n );\n\n const text = response.content[0]?.type === \"text\" ? response.content[0].text : \"\";\n\n update_progress(100, \"Completed Anthropic text rewriting\");\n return { text };\n};\n\nexport const Anthropic_TextRewriter_Stream: AiProviderStreamFn<\n TextRewriterTaskInput,\n TextRewriterTaskOutput,\n AnthropicModelConfig\n> = async function* (input, model, signal): AsyncIterable<StreamEvent<TextRewriterTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const stream = client.messages.stream(\n {\n model: modelName,\n system: input.prompt,\n messages: [{ role: \"user\", content: input.text }],\n max_tokens: getMaxTokens({}, model),\n },\n { signal }\n );\n\n for await (const event of stream) {\n if (event.type === \"content_block_delta\" && event.delta.type === \"text_delta\") {\n yield { type: \"text-delta\", port: \"text\", textDelta: event.delta.text };\n }\n }\n yield { type: \"finish\", data: {} as TextRewriterTaskOutput };\n};\n",
|
|
17
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n AiProviderStreamFn,\n TextSummaryTaskInput,\n TextSummaryTaskOutput,\n} from \"@workglow/ai\";\nimport type { StreamEvent } from \"@workglow/task-graph\";\nimport { getClient, getMaxTokens, getModelName } from \"./Anthropic_Client\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nexport const Anthropic_TextSummary: AiProviderRunFn<\n TextSummaryTaskInput,\n TextSummaryTaskOutput,\n AnthropicModelConfig\n> = async (input, model, update_progress, signal) => {\n update_progress(0, \"Starting Anthropic text summarization\");\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const response = await client.messages.create(\n {\n model: modelName,\n system: \"Summarize the following text concisely.\",\n messages: [{ role: \"user\", content: input.text }],\n max_tokens: getMaxTokens({}, model),\n },\n { signal }\n );\n\n const text = response.content[0]?.type === \"text\" ? response.content[0].text : \"\";\n\n update_progress(100, \"Completed Anthropic text summarization\");\n return { text };\n};\n\nexport const Anthropic_TextSummary_Stream: AiProviderStreamFn<\n TextSummaryTaskInput,\n TextSummaryTaskOutput,\n AnthropicModelConfig\n> = async function* (input, model, signal): AsyncIterable<StreamEvent<TextSummaryTaskOutput>> {\n const client = await getClient(model);\n const modelName = getModelName(model);\n\n const stream = client.messages.stream(\n {\n model: modelName,\n system: \"Summarize the following text concisely.\",\n messages: [{ role: \"user\", content: input.text }],\n max_tokens: getMaxTokens({}, model),\n },\n { signal }\n );\n\n for await (const event of stream) {\n if (event.type === \"content_block_delta\" && event.delta.type === \"text_delta\") {\n yield { type: \"text-delta\", port: \"text\", textDelta: event.delta.text };\n }\n }\n yield { type: \"finish\", data: {} as TextSummaryTaskOutput };\n};\n",
|
|
18
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AiProviderPreviewRunFn, AiProviderRunFn, AiProviderStreamFn } from \"@workglow/ai\";\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\nimport { Anthropic_ModelSearch } from \"./Anthropic_ModelSearch\";\n\nexport { getClient, getMaxTokens, getModelName, loadAnthropicSDK } from \"./Anthropic_Client\";\n\nimport { Anthropic_Chat, Anthropic_Chat_Stream } from \"./Anthropic_Chat\";\nimport { Anthropic_CountTokens, Anthropic_CountTokens_Preview } from \"./Anthropic_CountTokens\";\nimport { Anthropic_ModelInfo } from \"./Anthropic_ModelInfo\";\nimport {\n Anthropic_StructuredGeneration,\n Anthropic_StructuredGeneration_Stream,\n} from \"./Anthropic_StructuredGeneration\";\nimport {\n Anthropic_TextGeneration,\n Anthropic_TextGeneration_Stream,\n} from \"./Anthropic_TextGeneration\";\nimport { Anthropic_TextRewriter, Anthropic_TextRewriter_Stream } from \"./Anthropic_TextRewriter\";\nimport { Anthropic_TextSummary, Anthropic_TextSummary_Stream } from \"./Anthropic_TextSummary\";\nimport { Anthropic_ToolCalling, Anthropic_ToolCalling_Stream } from \"./Anthropic_ToolCalling\";\n\nexport const ANTHROPIC_TASKS: Record<string, AiProviderRunFn<any, any, AnthropicModelConfig>> = {\n AiChatTask: Anthropic_Chat,\n CountTokensTask: Anthropic_CountTokens,\n ModelInfoTask: Anthropic_ModelInfo,\n TextGenerationTask: Anthropic_TextGeneration,\n TextRewriterTask: Anthropic_TextRewriter,\n TextSummaryTask: Anthropic_TextSummary,\n StructuredGenerationTask: Anthropic_StructuredGeneration,\n ToolCallingTask: Anthropic_ToolCalling,\n ModelSearchTask: Anthropic_ModelSearch,\n};\n\nexport const ANTHROPIC_STREAM_TASKS: Record<\n string,\n AiProviderStreamFn<any, any, AnthropicModelConfig>\n> = {\n AiChatTask: Anthropic_Chat_Stream,\n TextGenerationTask: Anthropic_TextGeneration_Stream,\n TextRewriterTask: Anthropic_TextRewriter_Stream,\n TextSummaryTask: Anthropic_TextSummary_Stream,\n StructuredGenerationTask: Anthropic_StructuredGeneration_Stream,\n ToolCallingTask: Anthropic_ToolCalling_Stream,\n};\n\nexport const ANTHROPIC_PREVIEW_TASKS: Record<\n string,\n AiProviderPreviewRunFn<any, any, AnthropicModelConfig>\n> = {\n CountTokensTask: Anthropic_CountTokens_Preview,\n};\n",
|
|
19
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { registerProviderWorker } from \"@workglow/ai-provider/common\";\nimport {\n ANTHROPIC_PREVIEW_TASKS,\n ANTHROPIC_STREAM_TASKS,\n ANTHROPIC_TASKS,\n} from \"./common/Anthropic_JobRunFns\";\nimport { AnthropicProvider } from \"./AnthropicProvider\";\n\nexport async function registerAnthropicWorker(): Promise<void> {\n await registerProviderWorker(\n (ws) =>\n new AnthropicProvider(\n ANTHROPIC_TASKS,\n ANTHROPIC_STREAM_TASKS,\n ANTHROPIC_PREVIEW_TASKS\n ).registerOnWorkerServer(ws),\n \"Anthropic\"\n );\n}\n",
|
|
20
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { AiProvider } from \"@workglow/ai/worker\";\nimport type {\n AiProviderPreviewRunFn,\n AiProviderRunFn,\n AiProviderStreamFn,\n} from \"@workglow/ai/worker\";\nimport { ANTHROPIC } from \"./common/Anthropic_Constants\";\nimport type { AnthropicModelConfig } from \"./common/Anthropic_ModelSchema\";\n\n/**\n * AI provider for Anthropic cloud models.\n *\n * Supports text generation, text rewriting, and text summarization via the\n * Anthropic Messages API using the `@anthropic-ai/sdk` SDK.\n *\n * Note: Anthropic does not offer an embeddings API, so TextEmbeddingTask\n * is not supported by this provider.\n *\n * Task run functions are injected via the constructor so that the SDK\n * is only imported where actually needed (inline mode, worker server), not on\n * the main thread in worker mode.\n *\n */\nexport class AnthropicProvider extends AiProvider<AnthropicModelConfig> {\n readonly name = ANTHROPIC;\n readonly displayName = \"Anthropic\";\n readonly isLocal = false;\n readonly supportsBrowser = true;\n\n readonly taskTypes = [\n \"CountTokensTask\",\n \"ModelInfoTask\",\n \"TextGenerationTask\",\n \"TextRewriterTask\",\n \"TextSummaryTask\",\n \"StructuredGenerationTask\",\n \"ToolCallingTask\",\n \"ModelSearchTask\",\n ] as const;\n\n constructor(\n tasks?: Record<string, AiProviderRunFn<any, any, AnthropicModelConfig>>,\n streamTasks?: Record<string, AiProviderStreamFn<any, any, AnthropicModelConfig>>,\n previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, AnthropicModelConfig>>\n ) {\n super(tasks, streamTasks, previewTasks);\n }\n}\n"
|
|
21
|
+
],
|
|
22
|
+
"mappings": ";;;;;;;;;AAQA,IAAI;AAEJ,eAAsB,gBAAgB,GAAG;AAAA,EACvC,IAAI,CAAC,MAAM;AAAA,IACT,IAAI;AAAA,MACF,OAAO,MAAa;AAAA,MACpB,MAAM;AAAA,MACN,MAAM,IAAI,MACR,+FACF;AAAA;AAAA,EAEJ;AAAA,EACA,OAAO,KAAK;AAAA;AAWd,eAAsB,SAAS,CAAC,OAAyC;AAAA,EACvE,MAAM,YAAY,MAAM,iBAAiB;AAAA,EACzC,MAAM,SAAS,OAAO;AAAA,EACtB,MAAM,SACJ,QAAQ,kBACR,QAAQ,YACP,OAAO,YAAY,cAAc,QAAQ,KAAK,oBAAoB;AAAA,EACrE,IAAI,CAAC,QAAQ;AAAA,IACX,MAAM,IAAI,MACR,8GACF;AAAA,EACF;AAAA,EACA,IAAI;AAAA,IACF,OAAO,IAAI,UAAU;AAAA,MACnB;AAAA,MACA,SAAS,QAAQ,YAAY;AAAA,MAC7B,yBACE,OAAO,WAAW,aAAa,eAAe,uBAAuB;AAAA,IACzE,CAAC;AAAA,IACD,OAAO,KAAK;AAAA,IACZ,MAAM,IAAI,MACR,sCAAsC,eAAe,QAAQ,IAAI,UAAU,iBAC7E;AAAA;AAAA;AAIG,SAAS,YAAY,CAAC,OAAiD;AAAA,EAC5E,MAAM,OAAO,OAAO,iBAAiB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AAAA,EAEA,WAAW,CACT,OACA,aACA,cACA;AAAA,IACA,MAAM,OAAO,aAAa,YAAY;AAAA;AAE1C;;;ADvCA,eAAsB,uBAAuB,GAAkB;AAAA,EAC7D,MAAM,uBACJ,CAAC,OACC,IAAI,kBACF,iBACA,wBACA,uBACF,EAAE,uBAAuB,EAAE,GAC7B,WACF;AAAA;",
|
|
23
|
+
"debugId": "5CF7CD36576BBE7E64756E2164756E21",
|
|
24
|
+
"names": []
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-provider.d.ts","sourceRoot":"","sources":["../src/ai-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/ai-provider/common/Anthropic_Constants.ts
|
|
10
|
+
var ANTHROPIC = "ANTHROPIC";
|
|
11
|
+
|
|
12
|
+
// src/ai-provider/common/Anthropic_ModelSchema.ts
|
|
13
|
+
import { ModelConfigSchema, ModelRecordSchema } from "@workglow/ai/worker";
|
|
14
|
+
var AnthropicModelSchema = {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
provider: {
|
|
18
|
+
const: ANTHROPIC,
|
|
19
|
+
description: "Discriminator: Anthropic cloud provider."
|
|
20
|
+
},
|
|
21
|
+
provider_config: {
|
|
22
|
+
type: "object",
|
|
23
|
+
description: "Anthropic-specific configuration.",
|
|
24
|
+
properties: {
|
|
25
|
+
model_name: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "The Anthropic model identifier (e.g., 'claude-sonnet-4-20250514', 'claude-3-5-haiku-20241022')."
|
|
28
|
+
},
|
|
29
|
+
credential_key: {
|
|
30
|
+
type: "string",
|
|
31
|
+
format: "credential",
|
|
32
|
+
description: "Key to look up in the credential store for the API key.",
|
|
33
|
+
"x-ui-hidden": true
|
|
34
|
+
},
|
|
35
|
+
base_url: {
|
|
36
|
+
type: "string",
|
|
37
|
+
description: "Base URL for the Anthropic API (optional)."
|
|
38
|
+
},
|
|
39
|
+
max_tokens: {
|
|
40
|
+
type: "integer",
|
|
41
|
+
description: "Default max tokens for responses. Anthropic requires this parameter.",
|
|
42
|
+
default: 1024,
|
|
43
|
+
minimum: 1
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
required: ["model_name"],
|
|
47
|
+
additionalProperties: false
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
required: ["provider", "provider_config"],
|
|
51
|
+
additionalProperties: true
|
|
52
|
+
};
|
|
53
|
+
var AnthropicModelRecordSchema = {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
...ModelRecordSchema.properties,
|
|
57
|
+
...AnthropicModelSchema.properties
|
|
58
|
+
},
|
|
59
|
+
required: [...ModelRecordSchema.required, ...AnthropicModelSchema.required],
|
|
60
|
+
additionalProperties: false
|
|
61
|
+
};
|
|
62
|
+
var AnthropicModelConfigSchema = {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
...ModelConfigSchema.properties,
|
|
66
|
+
...AnthropicModelSchema.properties
|
|
67
|
+
},
|
|
68
|
+
required: [...ModelConfigSchema.required, ...AnthropicModelSchema.required],
|
|
69
|
+
additionalProperties: false
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/ai-provider/common/Anthropic_ModelSearch.ts
|
|
73
|
+
import { filterLabeledModelsByQuery } from "@workglow/ai-provider/common";
|
|
74
|
+
|
|
75
|
+
// src/ai-provider/common/Anthropic_Client.ts
|
|
76
|
+
var _sdk;
|
|
77
|
+
async function loadAnthropicSDK() {
|
|
78
|
+
if (!_sdk) {
|
|
79
|
+
try {
|
|
80
|
+
_sdk = await import("@anthropic-ai/sdk");
|
|
81
|
+
} catch {
|
|
82
|
+
throw new Error("@anthropic-ai/sdk is required for Anthropic tasks. Install it with: bun add @anthropic-ai/sdk");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return _sdk.default;
|
|
86
|
+
}
|
|
87
|
+
async function getClient(model) {
|
|
88
|
+
const Anthropic = await loadAnthropicSDK();
|
|
89
|
+
const config = model?.provider_config;
|
|
90
|
+
const apiKey = config?.credential_key || config?.api_key || (typeof process !== "undefined" ? process.env?.ANTHROPIC_API_KEY : undefined);
|
|
91
|
+
if (!apiKey) {
|
|
92
|
+
throw new Error("Missing Anthropic API key: set provider_config.credential_key or the ANTHROPIC_API_KEY environment variable.");
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
return new Anthropic({
|
|
96
|
+
apiKey,
|
|
97
|
+
baseURL: config?.base_url || undefined,
|
|
98
|
+
dangerouslyAllowBrowser: typeof globalThis.document !== "undefined" || "WorkerGlobalScope" in globalThis
|
|
99
|
+
});
|
|
100
|
+
} catch (err) {
|
|
101
|
+
throw new Error(`Failed to create Anthropic client: ${err instanceof Error ? err.message : "unknown error"}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function getModelName(model) {
|
|
105
|
+
const name = model?.provider_config?.model_name;
|
|
106
|
+
if (!name) {
|
|
107
|
+
throw new Error("Missing model name in provider_config.model_name.");
|
|
108
|
+
}
|
|
109
|
+
return name;
|
|
110
|
+
}
|
|
111
|
+
function getMaxTokens(input, model) {
|
|
112
|
+
return input.maxTokens ?? model?.provider_config?.max_tokens ?? 1024;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/ai-provider/common/Anthropic_ModelSearch.ts
|
|
116
|
+
var ANTHROPIC_FALLBACK = [
|
|
117
|
+
{ label: "claude-opus-4-7", value: "claude-opus-4-7" },
|
|
118
|
+
{ label: "claude-sonnet-4-6", value: "claude-sonnet-4-6" },
|
|
119
|
+
{ label: "claude-haiku-4-5-20251001", value: "claude-haiku-4-5-20251001" },
|
|
120
|
+
{ label: "claude-opus-4-6", value: "claude-opus-4-6" },
|
|
121
|
+
{ label: "claude-sonnet-4-5-20250929", value: "claude-sonnet-4-5-20250929" },
|
|
122
|
+
{ label: "claude-3-5-sonnet-20241022", value: "claude-3-5-sonnet-20241022" },
|
|
123
|
+
{ label: "claude-3-5-haiku-20241022", value: "claude-3-5-haiku-20241022" }
|
|
124
|
+
];
|
|
125
|
+
async function listAnthropicModels(credentialKey) {
|
|
126
|
+
const client = await getClient({
|
|
127
|
+
provider: ANTHROPIC,
|
|
128
|
+
provider_config: { model_name: "", credential_key: credentialKey }
|
|
129
|
+
});
|
|
130
|
+
const models = [];
|
|
131
|
+
for await (const m of client.beta.models.list()) {
|
|
132
|
+
models.push({ label: `${m.id} ${m.display_name}`, value: m.id });
|
|
133
|
+
}
|
|
134
|
+
return models;
|
|
135
|
+
}
|
|
136
|
+
function mapModelList(models) {
|
|
137
|
+
return models.map((m) => ({
|
|
138
|
+
id: m.value,
|
|
139
|
+
label: m.label,
|
|
140
|
+
description: "",
|
|
141
|
+
record: {
|
|
142
|
+
model_id: m.value,
|
|
143
|
+
provider: ANTHROPIC,
|
|
144
|
+
title: m.value,
|
|
145
|
+
description: "",
|
|
146
|
+
tasks: [],
|
|
147
|
+
provider_config: { model_name: m.value },
|
|
148
|
+
metadata: {}
|
|
149
|
+
},
|
|
150
|
+
raw: m
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
var Anthropic_ModelSearch = async (input) => {
|
|
154
|
+
let models;
|
|
155
|
+
if (!input.credential_key) {
|
|
156
|
+
models = ANTHROPIC_FALLBACK;
|
|
157
|
+
} else {
|
|
158
|
+
models = await listAnthropicModels(input.credential_key);
|
|
159
|
+
}
|
|
160
|
+
models = filterLabeledModelsByQuery(models, input.query);
|
|
161
|
+
return { results: mapModelList(models) };
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/ai-provider/registerAnthropic.ts
|
|
165
|
+
import { registerProviderWithWorker } from "@workglow/ai-provider/common";
|
|
166
|
+
|
|
167
|
+
// src/ai-provider/AnthropicQueuedProvider.ts
|
|
168
|
+
import { AiProvider } from "@workglow/ai";
|
|
169
|
+
class AnthropicQueuedProvider extends AiProvider {
|
|
170
|
+
name = ANTHROPIC;
|
|
171
|
+
displayName = "Anthropic";
|
|
172
|
+
isLocal = false;
|
|
173
|
+
supportsBrowser = true;
|
|
174
|
+
taskTypes = [
|
|
175
|
+
"CountTokensTask",
|
|
176
|
+
"ModelInfoTask",
|
|
177
|
+
"TextGenerationTask",
|
|
178
|
+
"TextRewriterTask",
|
|
179
|
+
"TextSummaryTask",
|
|
180
|
+
"StructuredGenerationTask",
|
|
181
|
+
"ToolCallingTask",
|
|
182
|
+
"ModelSearchTask"
|
|
183
|
+
];
|
|
184
|
+
constructor(tasks, streamTasks, previewTasks) {
|
|
185
|
+
super(tasks, streamTasks, previewTasks);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/ai-provider/registerAnthropic.ts
|
|
190
|
+
async function registerAnthropic(options) {
|
|
191
|
+
await registerProviderWithWorker(new AnthropicQueuedProvider, "Anthropic", options);
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
registerAnthropic,
|
|
195
|
+
Anthropic_ModelSearch,
|
|
196
|
+
AnthropicModelSchema,
|
|
197
|
+
AnthropicModelRecordSchema,
|
|
198
|
+
AnthropicModelConfigSchema,
|
|
199
|
+
ANTHROPIC
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
//# debugId=21EC05613F224B4764756E2164756E21
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ai-provider/common/Anthropic_Constants.ts", "../src/ai-provider/common/Anthropic_ModelSchema.ts", "../src/ai-provider/common/Anthropic_ModelSearch.ts", "../src/ai-provider/common/Anthropic_Client.ts", "../src/ai-provider/registerAnthropic.ts", "../src/ai-provider/AnthropicQueuedProvider.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport const ANTHROPIC = \"ANTHROPIC\";\n",
|
|
6
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ModelConfigSchema, ModelRecordSchema } from \"@workglow/ai/worker\";\nimport { DataPortSchemaObject, FromSchema } from \"@workglow/util/worker\";\nimport { ANTHROPIC } from \"./Anthropic_Constants\";\n\nexport const AnthropicModelSchema = {\n type: \"object\",\n properties: {\n provider: {\n const: ANTHROPIC,\n description: \"Discriminator: Anthropic cloud provider.\",\n },\n provider_config: {\n type: \"object\",\n description: \"Anthropic-specific configuration.\",\n properties: {\n model_name: {\n type: \"string\",\n description:\n \"The Anthropic model identifier (e.g., 'claude-sonnet-4-20250514', 'claude-3-5-haiku-20241022').\",\n },\n credential_key: {\n type: \"string\",\n format: \"credential\",\n description: \"Key to look up in the credential store for the API key.\",\n \"x-ui-hidden\": true,\n },\n base_url: {\n type: \"string\",\n description: \"Base URL for the Anthropic API (optional).\",\n },\n max_tokens: {\n type: \"integer\",\n description: \"Default max tokens for responses. Anthropic requires this parameter.\",\n default: 1024,\n minimum: 1,\n },\n },\n required: [\"model_name\"],\n additionalProperties: false,\n },\n },\n required: [\"provider\", \"provider_config\"],\n additionalProperties: true,\n} as const satisfies DataPortSchemaObject;\n\nexport const AnthropicModelRecordSchema = {\n type: \"object\",\n properties: {\n ...ModelRecordSchema.properties,\n ...AnthropicModelSchema.properties,\n },\n required: [...ModelRecordSchema.required, ...AnthropicModelSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type AnthropicModelRecord = FromSchema<typeof AnthropicModelRecordSchema>;\n\nexport const AnthropicModelConfigSchema = {\n type: \"object\",\n properties: {\n ...ModelConfigSchema.properties,\n ...AnthropicModelSchema.properties,\n },\n required: [...ModelConfigSchema.required, ...AnthropicModelSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type AnthropicModelConfig = FromSchema<typeof AnthropicModelConfigSchema>;\n",
|
|
7
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type {\n AiProviderRunFn,\n ModelSearchResultItem,\n ModelSearchTaskInput,\n ModelSearchTaskOutput,\n} from \"@workglow/ai\";\nimport { filterLabeledModelsByQuery } from \"@workglow/ai-provider/common\";\nimport { getClient } from \"./Anthropic_Client\";\nimport { ANTHROPIC } from \"./Anthropic_Constants\";\n\nconst ANTHROPIC_FALLBACK: Array<{ label: string; value: string }> = [\n { label: \"claude-opus-4-7\", value: \"claude-opus-4-7\" },\n { label: \"claude-sonnet-4-6\", value: \"claude-sonnet-4-6\" },\n { label: \"claude-haiku-4-5-20251001\", value: \"claude-haiku-4-5-20251001\" },\n { label: \"claude-opus-4-6\", value: \"claude-opus-4-6\" },\n { label: \"claude-sonnet-4-5-20250929\", value: \"claude-sonnet-4-5-20250929\" },\n { label: \"claude-3-5-sonnet-20241022\", value: \"claude-3-5-sonnet-20241022\" },\n { label: \"claude-3-5-haiku-20241022\", value: \"claude-3-5-haiku-20241022\" },\n];\n\nasync function listAnthropicModels(\n credentialKey: string\n): Promise<Array<{ label: string; value: string }>> {\n const client = await getClient({\n provider: ANTHROPIC,\n provider_config: { model_name: \"\", credential_key: credentialKey },\n });\n const models: Array<{ label: string; value: string }> = [];\n for await (const m of client.beta.models.list()) {\n models.push({ label: `${m.id} ${m.display_name}`, value: m.id });\n }\n return models;\n}\n\nfunction mapModelList(models: Array<{ label: string; value: string }>): ModelSearchResultItem[] {\n return models.map((m) => ({\n id: m.value,\n label: m.label,\n description: \"\",\n record: {\n model_id: m.value,\n provider: ANTHROPIC,\n title: m.value,\n description: \"\",\n tasks: [],\n provider_config: { model_name: m.value },\n metadata: {},\n },\n raw: m,\n }));\n}\n\nexport const Anthropic_ModelSearch: AiProviderRunFn<\n ModelSearchTaskInput,\n ModelSearchTaskOutput\n> = async (input) => {\n let models: Array<{ label: string; value: string }>;\n if (!input.credential_key) {\n models = ANTHROPIC_FALLBACK;\n } else {\n models = await listAnthropicModels(input.credential_key);\n }\n models = filterLabeledModelsByQuery(models, input.query);\n return { results: mapModelList(models) };\n};\n",
|
|
8
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnthropicModelConfig } from \"./Anthropic_ModelSchema\";\n\nlet _sdk: typeof import(\"@anthropic-ai/sdk\") | undefined;\n\nexport async function loadAnthropicSDK() {\n if (!_sdk) {\n try {\n _sdk = await import(\"@anthropic-ai/sdk\");\n } catch {\n throw new Error(\n \"@anthropic-ai/sdk is required for Anthropic tasks. Install it with: bun add @anthropic-ai/sdk\"\n );\n }\n }\n return _sdk.default;\n}\n\ninterface ResolvedProviderConfig {\n readonly credential_key?: string;\n readonly api_key?: string;\n readonly model_name?: string;\n readonly base_url?: string;\n readonly max_tokens?: number;\n}\n\nexport async function getClient(model: AnthropicModelConfig | undefined) {\n const Anthropic = await loadAnthropicSDK();\n const config = model?.provider_config as ResolvedProviderConfig | undefined;\n const apiKey =\n config?.credential_key ||\n config?.api_key ||\n (typeof process !== \"undefined\" ? process.env?.ANTHROPIC_API_KEY : undefined);\n if (!apiKey) {\n throw new Error(\n \"Missing Anthropic API key: set provider_config.credential_key or the ANTHROPIC_API_KEY environment variable.\"\n );\n }\n try {\n return new Anthropic({\n apiKey,\n baseURL: config?.base_url || undefined,\n dangerouslyAllowBrowser:\n typeof globalThis.document !== \"undefined\" || \"WorkerGlobalScope\" in globalThis,\n });\n } catch (err) {\n throw new Error(\n `Failed to create Anthropic client: ${err instanceof Error ? err.message : \"unknown error\"}`\n );\n }\n}\n\nexport function getModelName(model: AnthropicModelConfig | undefined): string {\n const name = model?.provider_config?.model_name;\n if (!name) {\n throw new Error(\"Missing model name in provider_config.model_name.\");\n }\n return name;\n}\n\nexport function getMaxTokens(\n input: { maxTokens?: number },\n model: AnthropicModelConfig | undefined\n): number {\n return input.maxTokens ?? model?.provider_config?.max_tokens ?? 1024;\n}\n",
|
|
9
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AiProviderRegisterOptions } from \"@workglow/ai\";\nimport { registerProviderWithWorker } from \"@workglow/ai-provider/common\";\nimport { AnthropicQueuedProvider } from \"./AnthropicQueuedProvider\";\n\nexport async function registerAnthropic(\n options: AiProviderRegisterOptions & {\n worker: Worker | (() => Worker);\n }\n): Promise<void> {\n await registerProviderWithWorker(new AnthropicQueuedProvider(), \"Anthropic\", options);\n}\n",
|
|
10
|
+
"/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { AiProvider } from \"@workglow/ai\";\nimport type { AiProviderPreviewRunFn, AiProviderRunFn, AiProviderStreamFn } from \"@workglow/ai\";\nimport { ANTHROPIC } from \"./common/Anthropic_Constants\";\nimport type { AnthropicModelConfig } from \"./common/Anthropic_ModelSchema\";\n\n/** Main-thread registration (inline or worker-backed). No queue — uses direct execution. */\nexport class AnthropicQueuedProvider extends AiProvider<AnthropicModelConfig> {\n readonly name = ANTHROPIC;\n readonly displayName = \"Anthropic\";\n readonly isLocal = false;\n readonly supportsBrowser = true;\n\n readonly taskTypes = [\n \"CountTokensTask\",\n \"ModelInfoTask\",\n \"TextGenerationTask\",\n \"TextRewriterTask\",\n \"TextSummaryTask\",\n \"StructuredGenerationTask\",\n \"ToolCallingTask\",\n \"ModelSearchTask\",\n ] as const;\n\n constructor(\n tasks?: Record<string, AiProviderRunFn<any, any, AnthropicModelConfig>>,\n streamTasks?: Record<string, AiProviderStreamFn<any, any, AnthropicModelConfig>>,\n previewTasks?: Record<string, AiProviderPreviewRunFn<any, any, AnthropicModelConfig>>\n ) {\n super(tasks, streamTasks, previewTasks);\n }\n}\n"
|
|
11
|
+
],
|
|
12
|
+
"mappings": ";;;;;;;;;AAMO,IAAM,YAAY;;;ACAzB;AAIO,IAAM,uBAAuB;AAAA,EAClC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,UAAU;AAAA,MACR,OAAO;AAAA,MACP,aAAa;AAAA,IACf;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,MACN,aAAa;AAAA,MACb,YAAY;AAAA,QACV,YAAY;AAAA,UACV,MAAM;AAAA,UACN,aACE;AAAA,QACJ;AAAA,QACA,gBAAgB;AAAA,UACd,MAAM;AAAA,UACN,QAAQ;AAAA,UACR,aAAa;AAAA,UACb,eAAe;AAAA,QACjB;AAAA,QACA,UAAU;AAAA,UACR,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,QACA,YAAY;AAAA,UACV,MAAM;AAAA,UACN,aAAa;AAAA,UACb,SAAS;AAAA,UACT,SAAS;AAAA,QACX;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAY;AAAA,MACvB,sBAAsB;AAAA,IACxB;AAAA,EACF;AAAA,EACA,UAAU,CAAC,YAAY,iBAAiB;AAAA,EACxC,sBAAsB;AACxB;AAEO,IAAM,6BAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,OACP,kBAAkB;AAAA,OAClB,qBAAqB;AAAA,EAC1B;AAAA,EACA,UAAU,CAAC,GAAG,kBAAkB,UAAU,GAAG,qBAAqB,QAAQ;AAAA,EAC1E,sBAAsB;AACxB;AAIO,IAAM,6BAA6B;AAAA,EACxC,MAAM;AAAA,EACN,YAAY;AAAA,OACP,kBAA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Q,MAAM,KAAK;AAAA,EACvD,OAAO,EAAE,SAAS,aAAa,MAAM,EAAE;AAAA;;;AE9DzC;;;ACDA;AAMO,MAAM,gCAAgC,WAAiC;AAAA,EACnE,OAAO;AAAA,EACP,cAAc;AAAA,EACd,UAAU;AAAA,EACV,kBAAkB;AAAA,EAElB,YAAY;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EAEA,WAAW,CACT,OACA,aACA,cACA;AAAA,IACA,MAAM,OAAO,aAAa,YAAY;AAAA;AAE1C;;;AD1BA,eAAsB,iBAAiB,CACrC,SAGe;AAAA,EACf,MAAM,2BAA2B,IAAI,yBAA2B,aAAa,OAAO;AAAA;",
|
|
13
|
+
"debugId": "21EC05613F224B4764756E2164756E21",
|
|
14
|
+
"names": []
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@workglow/anthropic",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"version": "0.2.28",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/workglow-dev/workglow.git",
|
|
9
|
+
"directory": "packages/anthropic"
|
|
10
|
+
},
|
|
11
|
+
"description": "Anthropic Claude provider for @workglow/ai-provider.",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"watch": "concurrently -c 'auto' 'bun:watch-*'",
|
|
14
|
+
"watch-code": "bun build --watch --no-clear-screen --sourcemap=external --packages=external --root ./src --outdir ./dist ./src/ai-provider.ts ./src/ai-provider-runtime.ts",
|
|
15
|
+
"watch-types": "tsc --watch --preserveWatchOutput",
|
|
16
|
+
"build-package": "concurrently -c 'auto' -n 'code,types' 'bun run build-code' 'bun run build-types'",
|
|
17
|
+
"build-js": "bun run build-code",
|
|
18
|
+
"build-clean": "rm -fr dist/* tsconfig.tsbuildinfo",
|
|
19
|
+
"build-code": "bun build --sourcemap=external --packages=external --root ./src --outdir ./dist ./src/ai-provider.ts ./src/ai-provider-runtime.ts",
|
|
20
|
+
"build-types": "rm -f tsconfig.tsbuildinfo && tsgo",
|
|
21
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
22
|
+
"test": "bun test"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
"./ai-provider": {
|
|
26
|
+
"types": "./dist/ai-provider.d.ts",
|
|
27
|
+
"import": "./dist/ai-provider.js"
|
|
28
|
+
},
|
|
29
|
+
"./ai-provider-runtime": {
|
|
30
|
+
"types": "./dist/ai-provider-runtime.d.ts",
|
|
31
|
+
"import": "./dist/ai-provider-runtime.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@anthropic-ai/sdk": "^0.92.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@workglow/ai": "0.2.28",
|
|
39
|
+
"@workglow/ai-provider": "0.2.28",
|
|
40
|
+
"@workglow/job-queue": "0.2.28",
|
|
41
|
+
"@workglow/storage": "0.2.28",
|
|
42
|
+
"@workglow/task-graph": "0.2.28",
|
|
43
|
+
"@workglow/util": "0.2.28"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@workglow/ai": "0.2.28",
|
|
47
|
+
"@workglow/ai-provider": "0.2.28",
|
|
48
|
+
"@workglow/job-queue": "0.2.28",
|
|
49
|
+
"@workglow/storage": "0.2.28",
|
|
50
|
+
"@workglow/task-graph": "0.2.28",
|
|
51
|
+
"@workglow/util": "0.2.28"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"src/**/*.md"
|
|
56
|
+
],
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|