overai 1.4.0
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/README.md +248 -0
- package/dist/agent/context.d.ts +74 -0
- package/dist/agent/context.js +140 -0
- package/dist/agent/enhanced.d.ts +98 -0
- package/dist/agent/enhanced.js +293 -0
- package/dist/agent/handoff.d.ts +82 -0
- package/dist/agent/handoff.js +124 -0
- package/dist/agent/image.d.ts +57 -0
- package/dist/agent/image.js +116 -0
- package/dist/agent/index.d.ts +19 -0
- package/dist/agent/index.js +38 -0
- package/dist/agent/prompt-expander.d.ts +43 -0
- package/dist/agent/prompt-expander.js +99 -0
- package/dist/agent/proxy.d.ts +26 -0
- package/dist/agent/proxy.js +173 -0
- package/dist/agent/query-rewriter.d.ts +41 -0
- package/dist/agent/query-rewriter.js +94 -0
- package/dist/agent/research.d.ts +55 -0
- package/dist/agent/research.js +134 -0
- package/dist/agent/router.d.ts +141 -0
- package/dist/agent/router.js +209 -0
- package/dist/agent/simple.d.ts +289 -0
- package/dist/agent/simple.js +696 -0
- package/dist/agent/types.d.ts +56 -0
- package/dist/agent/types.js +165 -0
- package/dist/ai/agent-loop.d.ts +177 -0
- package/dist/ai/agent-loop.js +313 -0
- package/dist/ai/devtools.d.ts +74 -0
- package/dist/ai/devtools.js +216 -0
- package/dist/ai/embed.d.ts +71 -0
- package/dist/ai/embed.js +154 -0
- package/dist/ai/generate-image.d.ts +66 -0
- package/dist/ai/generate-image.js +138 -0
- package/dist/ai/generate-object.d.ts +132 -0
- package/dist/ai/generate-object.js +206 -0
- package/dist/ai/generate-text.d.ts +201 -0
- package/dist/ai/generate-text.js +253 -0
- package/dist/ai/index.d.ts +27 -0
- package/dist/ai/index.js +140 -0
- package/dist/ai/mcp.d.ts +181 -0
- package/dist/ai/mcp.js +234 -0
- package/dist/ai/middleware.d.ts +110 -0
- package/dist/ai/middleware.js +186 -0
- package/dist/ai/models.d.ts +67 -0
- package/dist/ai/models.js +249 -0
- package/dist/ai/multimodal.d.ts +125 -0
- package/dist/ai/multimodal.js +270 -0
- package/dist/ai/nextjs.d.ts +122 -0
- package/dist/ai/nextjs.js +218 -0
- package/dist/ai/server.d.ts +126 -0
- package/dist/ai/server.js +336 -0
- package/dist/ai/speech.d.ts +135 -0
- package/dist/ai/speech.js +296 -0
- package/dist/ai/telemetry.d.ts +162 -0
- package/dist/ai/telemetry.js +311 -0
- package/dist/ai/tool-approval.d.ts +225 -0
- package/dist/ai/tool-approval.js +407 -0
- package/dist/ai/tools.d.ts +93 -0
- package/dist/ai/tools.js +89 -0
- package/dist/ai/types.d.ts +47 -0
- package/dist/ai/types.js +5 -0
- package/dist/ai/ui-message.d.ts +218 -0
- package/dist/ai/ui-message.js +291 -0
- package/dist/auto/index.d.ts +62 -0
- package/dist/auto/index.js +163 -0
- package/dist/cache/index.d.ts +78 -0
- package/dist/cache/index.js +235 -0
- package/dist/cli/commands/agent.d.ts +30 -0
- package/dist/cli/commands/agent.js +151 -0
- package/dist/cli/commands/agents.d.ts +24 -0
- package/dist/cli/commands/agents.js +166 -0
- package/dist/cli/commands/approval.d.ts +10 -0
- package/dist/cli/commands/approval.js +253 -0
- package/dist/cli/commands/auto.d.ts +12 -0
- package/dist/cli/commands/auto.js +109 -0
- package/dist/cli/commands/autonomy.d.ts +5 -0
- package/dist/cli/commands/autonomy.js +152 -0
- package/dist/cli/commands/benchmark.d.ts +19 -0
- package/dist/cli/commands/benchmark.js +484 -0
- package/dist/cli/commands/cache.d.ts +9 -0
- package/dist/cli/commands/cache.js +143 -0
- package/dist/cli/commands/chat.d.ts +14 -0
- package/dist/cli/commands/chat.js +127 -0
- package/dist/cli/commands/checkpoints.d.ts +5 -0
- package/dist/cli/commands/checkpoints.js +236 -0
- package/dist/cli/commands/context.d.ts +11 -0
- package/dist/cli/commands/context.js +182 -0
- package/dist/cli/commands/cost.d.ts +5 -0
- package/dist/cli/commands/cost.js +146 -0
- package/dist/cli/commands/db.d.ts +9 -0
- package/dist/cli/commands/db.js +149 -0
- package/dist/cli/commands/embed.d.ts +20 -0
- package/dist/cli/commands/embed.js +375 -0
- package/dist/cli/commands/eval.d.ts +17 -0
- package/dist/cli/commands/eval.js +247 -0
- package/dist/cli/commands/external-agents.d.ts +5 -0
- package/dist/cli/commands/external-agents.js +170 -0
- package/dist/cli/commands/fast-context.d.ts +5 -0
- package/dist/cli/commands/fast-context.js +126 -0
- package/dist/cli/commands/flow.d.ts +5 -0
- package/dist/cli/commands/flow.js +141 -0
- package/dist/cli/commands/git.d.ts +5 -0
- package/dist/cli/commands/git.js +178 -0
- package/dist/cli/commands/graph-rag.d.ts +9 -0
- package/dist/cli/commands/graph-rag.js +131 -0
- package/dist/cli/commands/guardrail.d.ts +11 -0
- package/dist/cli/commands/guardrail.js +156 -0
- package/dist/cli/commands/handoff.d.ts +9 -0
- package/dist/cli/commands/handoff.js +133 -0
- package/dist/cli/commands/help.d.ts +8 -0
- package/dist/cli/commands/help.js +139 -0
- package/dist/cli/commands/image.d.ts +13 -0
- package/dist/cli/commands/image.js +192 -0
- package/dist/cli/commands/interactive.d.ts +6 -0
- package/dist/cli/commands/interactive.js +79 -0
- package/dist/cli/commands/jobs.d.ts +5 -0
- package/dist/cli/commands/jobs.js +282 -0
- package/dist/cli/commands/knowledge.d.ts +9 -0
- package/dist/cli/commands/knowledge.js +226 -0
- package/dist/cli/commands/llm.d.ts +21 -0
- package/dist/cli/commands/llm.js +748 -0
- package/dist/cli/commands/mcp.d.ts +9 -0
- package/dist/cli/commands/mcp.js +243 -0
- package/dist/cli/commands/memory.d.ts +10 -0
- package/dist/cli/commands/memory.js +198 -0
- package/dist/cli/commands/n8n.d.ts +5 -0
- package/dist/cli/commands/n8n.js +137 -0
- package/dist/cli/commands/observability.d.ts +16 -0
- package/dist/cli/commands/observability.js +335 -0
- package/dist/cli/commands/planning.d.ts +9 -0
- package/dist/cli/commands/planning.js +167 -0
- package/dist/cli/commands/prompt-expand.d.ts +11 -0
- package/dist/cli/commands/prompt-expand.js +100 -0
- package/dist/cli/commands/providers.d.ts +17 -0
- package/dist/cli/commands/providers.js +386 -0
- package/dist/cli/commands/query-rewrite.d.ts +12 -0
- package/dist/cli/commands/query-rewrite.js +102 -0
- package/dist/cli/commands/repo-map.d.ts +5 -0
- package/dist/cli/commands/repo-map.js +151 -0
- package/dist/cli/commands/reranker.d.ts +10 -0
- package/dist/cli/commands/reranker.js +144 -0
- package/dist/cli/commands/research.d.ts +12 -0
- package/dist/cli/commands/research.js +108 -0
- package/dist/cli/commands/router.d.ts +11 -0
- package/dist/cli/commands/router.js +142 -0
- package/dist/cli/commands/run.d.ts +14 -0
- package/dist/cli/commands/run.js +111 -0
- package/dist/cli/commands/sandbox.d.ts +5 -0
- package/dist/cli/commands/sandbox.js +135 -0
- package/dist/cli/commands/scheduler.d.ts +5 -0
- package/dist/cli/commands/scheduler.js +260 -0
- package/dist/cli/commands/session.d.ts +9 -0
- package/dist/cli/commands/session.js +238 -0
- package/dist/cli/commands/skills.d.ts +9 -0
- package/dist/cli/commands/skills.js +256 -0
- package/dist/cli/commands/telemetry.d.ts +9 -0
- package/dist/cli/commands/telemetry.js +146 -0
- package/dist/cli/commands/tools.d.ts +19 -0
- package/dist/cli/commands/tools.js +576 -0
- package/dist/cli/commands/vector.d.ts +10 -0
- package/dist/cli/commands/vector.js +171 -0
- package/dist/cli/commands/version.d.ts +8 -0
- package/dist/cli/commands/version.js +40 -0
- package/dist/cli/commands/voice.d.ts +10 -0
- package/dist/cli/commands/voice.js +162 -0
- package/dist/cli/commands/workflow.d.ts +13 -0
- package/dist/cli/commands/workflow.js +184 -0
- package/dist/cli/config/index.d.ts +6 -0
- package/dist/cli/config/index.js +22 -0
- package/dist/cli/config/load.d.ts +20 -0
- package/dist/cli/config/load.js +229 -0
- package/dist/cli/config/resolve.d.ts +28 -0
- package/dist/cli/config/resolve.js +70 -0
- package/dist/cli/config/schema.d.ts +15 -0
- package/dist/cli/config/schema.js +65 -0
- package/dist/cli/features/autonomy-mode.d.ts +98 -0
- package/dist/cli/features/autonomy-mode.js +266 -0
- package/dist/cli/features/background-jobs.d.ts +155 -0
- package/dist/cli/features/background-jobs.js +416 -0
- package/dist/cli/features/checkpoints.d.ts +126 -0
- package/dist/cli/features/checkpoints.js +288 -0
- package/dist/cli/features/cost-tracker.d.ts +101 -0
- package/dist/cli/features/cost-tracker.js +212 -0
- package/dist/cli/features/external-agents.d.ts +117 -0
- package/dist/cli/features/external-agents.js +296 -0
- package/dist/cli/features/fast-context.d.ts +126 -0
- package/dist/cli/features/fast-context.js +310 -0
- package/dist/cli/features/flow-display.d.ts +100 -0
- package/dist/cli/features/flow-display.js +254 -0
- package/dist/cli/features/git-integration.d.ts +138 -0
- package/dist/cli/features/git-integration.js +374 -0
- package/dist/cli/features/index.d.ts +17 -0
- package/dist/cli/features/index.js +102 -0
- package/dist/cli/features/interactive-tui.d.ts +114 -0
- package/dist/cli/features/interactive-tui.js +326 -0
- package/dist/cli/features/n8n-integration.d.ts +111 -0
- package/dist/cli/features/n8n-integration.js +299 -0
- package/dist/cli/features/repo-map.d.ts +101 -0
- package/dist/cli/features/repo-map.js +350 -0
- package/dist/cli/features/sandbox-executor.d.ts +89 -0
- package/dist/cli/features/sandbox-executor.js +314 -0
- package/dist/cli/features/scheduler.d.ts +111 -0
- package/dist/cli/features/scheduler.js +298 -0
- package/dist/cli/features/slash-commands.d.ts +77 -0
- package/dist/cli/features/slash-commands.js +316 -0
- package/dist/cli/index.d.ts +24 -0
- package/dist/cli/index.js +214 -0
- package/dist/cli/output/errors.d.ts +23 -0
- package/dist/cli/output/errors.js +36 -0
- package/dist/cli/output/json.d.ts +27 -0
- package/dist/cli/output/json.js +31 -0
- package/dist/cli/output/pretty.d.ts +13 -0
- package/dist/cli/output/pretty.js +31 -0
- package/dist/cli/runtime/env.d.ts +12 -0
- package/dist/cli/runtime/env.js +55 -0
- package/dist/cli/runtime/exit.d.ts +11 -0
- package/dist/cli/runtime/exit.js +49 -0
- package/dist/cli/runtime/index.d.ts +6 -0
- package/dist/cli/runtime/index.js +22 -0
- package/dist/cli/runtime/lazy.d.ts +18 -0
- package/dist/cli/runtime/lazy.js +85 -0
- package/dist/cli/spec/cli-spec.d.ts +87 -0
- package/dist/cli/spec/cli-spec.js +551 -0
- package/dist/cli/spec/index.d.ts +4 -0
- package/dist/cli/spec/index.js +20 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.js +75 -0
- package/dist/db/types.d.ts +42 -0
- package/dist/db/types.js +2 -0
- package/dist/eval/index.d.ts +61 -0
- package/dist/eval/index.js +157 -0
- package/dist/events/index.d.ts +84 -0
- package/dist/events/index.js +153 -0
- package/dist/guardrails/index.d.ts +82 -0
- package/dist/guardrails/index.js +202 -0
- package/dist/guardrails/llm-guardrail.d.ts +46 -0
- package/dist/guardrails/llm-guardrail.js +112 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +608 -0
- package/dist/integrations/computer-use.d.ts +182 -0
- package/dist/integrations/computer-use.js +356 -0
- package/dist/integrations/index.d.ts +7 -0
- package/dist/integrations/index.js +26 -0
- package/dist/integrations/observability/base.d.ts +123 -0
- package/dist/integrations/observability/base.js +183 -0
- package/dist/integrations/observability/index.d.ts +8 -0
- package/dist/integrations/observability/index.js +29 -0
- package/dist/integrations/observability/langfuse.d.ts +32 -0
- package/dist/integrations/observability/langfuse.js +174 -0
- package/dist/integrations/postgres.d.ts +162 -0
- package/dist/integrations/postgres.js +396 -0
- package/dist/integrations/slack.d.ts +145 -0
- package/dist/integrations/slack.js +270 -0
- package/dist/integrations/vector/base.d.ts +110 -0
- package/dist/integrations/vector/base.js +158 -0
- package/dist/integrations/vector/chroma.d.ts +25 -0
- package/dist/integrations/vector/chroma.js +143 -0
- package/dist/integrations/vector/index.d.ts +14 -0
- package/dist/integrations/vector/index.js +37 -0
- package/dist/integrations/vector/pinecone.d.ts +28 -0
- package/dist/integrations/vector/pinecone.js +172 -0
- package/dist/integrations/vector/qdrant.d.ts +25 -0
- package/dist/integrations/vector/qdrant.js +146 -0
- package/dist/integrations/vector/weaviate.d.ts +30 -0
- package/dist/integrations/vector/weaviate.js +206 -0
- package/dist/integrations/voice/base.d.ts +76 -0
- package/dist/integrations/voice/base.js +168 -0
- package/dist/integrations/voice/index.d.ts +6 -0
- package/dist/integrations/voice/index.js +26 -0
- package/dist/knowledge/chunking.d.ts +55 -0
- package/dist/knowledge/chunking.js +158 -0
- package/dist/knowledge/graph-rag.d.ts +125 -0
- package/dist/knowledge/graph-rag.js +289 -0
- package/dist/knowledge/index.d.ts +24 -0
- package/dist/knowledge/index.js +47 -0
- package/dist/knowledge/knowledge.d.ts +0 -0
- package/dist/knowledge/knowledge.js +1 -0
- package/dist/knowledge/rag.d.ts +80 -0
- package/dist/knowledge/rag.js +147 -0
- package/dist/knowledge/reranker.d.ts +86 -0
- package/dist/knowledge/reranker.js +196 -0
- package/dist/llm/backend-resolver.d.ts +77 -0
- package/dist/llm/backend-resolver.js +242 -0
- package/dist/llm/embeddings.d.ts +66 -0
- package/dist/llm/embeddings.js +294 -0
- package/dist/llm/index.d.ts +29 -0
- package/dist/llm/index.js +33 -0
- package/dist/llm/llm.d.ts +0 -0
- package/dist/llm/llm.js +1 -0
- package/dist/llm/openai.d.ts +39 -0
- package/dist/llm/openai.js +302 -0
- package/dist/llm/providers/ai-sdk/adapter.d.ts +121 -0
- package/dist/llm/providers/ai-sdk/adapter.js +399 -0
- package/dist/llm/providers/ai-sdk/backend.d.ts +49 -0
- package/dist/llm/providers/ai-sdk/backend.js +421 -0
- package/dist/llm/providers/ai-sdk/index.d.ts +69 -0
- package/dist/llm/providers/ai-sdk/index.js +200 -0
- package/dist/llm/providers/ai-sdk/middleware.d.ts +60 -0
- package/dist/llm/providers/ai-sdk/middleware.js +262 -0
- package/dist/llm/providers/ai-sdk/provider-map.d.ts +75 -0
- package/dist/llm/providers/ai-sdk/provider-map.js +258 -0
- package/dist/llm/providers/ai-sdk/types.d.ts +217 -0
- package/dist/llm/providers/ai-sdk/types.js +222 -0
- package/dist/llm/providers/anthropic.d.ts +33 -0
- package/dist/llm/providers/anthropic.js +291 -0
- package/dist/llm/providers/base.d.ts +25 -0
- package/dist/llm/providers/base.js +43 -0
- package/dist/llm/providers/google.d.ts +27 -0
- package/dist/llm/providers/google.js +275 -0
- package/dist/llm/providers/index.d.ts +107 -0
- package/dist/llm/providers/index.js +216 -0
- package/dist/llm/providers/openai.d.ts +18 -0
- package/dist/llm/providers/openai.js +203 -0
- package/dist/llm/providers/registry.d.ts +159 -0
- package/dist/llm/providers/registry.js +279 -0
- package/dist/llm/providers/types.d.ts +94 -0
- package/dist/llm/providers/types.js +5 -0
- package/dist/main.d.ts +0 -0
- package/dist/main.js +1 -0
- package/dist/memory/auto-memory.d.ts +136 -0
- package/dist/memory/auto-memory.js +301 -0
- package/dist/memory/file-memory.d.ts +88 -0
- package/dist/memory/file-memory.js +287 -0
- package/dist/memory/index.d.ts +26 -0
- package/dist/memory/index.js +41 -0
- package/dist/memory/memory.d.ts +92 -0
- package/dist/memory/memory.js +170 -0
- package/dist/observability/adapters/console.d.ts +33 -0
- package/dist/observability/adapters/console.js +71 -0
- package/dist/observability/adapters/external/arize.d.ts +20 -0
- package/dist/observability/adapters/external/arize.js +22 -0
- package/dist/observability/adapters/external/axiom.d.ts +20 -0
- package/dist/observability/adapters/external/axiom.js +22 -0
- package/dist/observability/adapters/external/braintrust.d.ts +20 -0
- package/dist/observability/adapters/external/braintrust.js +22 -0
- package/dist/observability/adapters/external/helicone.d.ts +20 -0
- package/dist/observability/adapters/external/helicone.js +22 -0
- package/dist/observability/adapters/external/laminar.d.ts +20 -0
- package/dist/observability/adapters/external/laminar.js +22 -0
- package/dist/observability/adapters/external/langfuse.d.ts +28 -0
- package/dist/observability/adapters/external/langfuse.js +186 -0
- package/dist/observability/adapters/external/langsmith.d.ts +21 -0
- package/dist/observability/adapters/external/langsmith.js +83 -0
- package/dist/observability/adapters/external/langwatch.d.ts +20 -0
- package/dist/observability/adapters/external/langwatch.js +22 -0
- package/dist/observability/adapters/external/maxim.d.ts +20 -0
- package/dist/observability/adapters/external/maxim.js +22 -0
- package/dist/observability/adapters/external/patronus.d.ts +20 -0
- package/dist/observability/adapters/external/patronus.js +22 -0
- package/dist/observability/adapters/external/scorecard.d.ts +20 -0
- package/dist/observability/adapters/external/scorecard.js +22 -0
- package/dist/observability/adapters/external/signoz.d.ts +20 -0
- package/dist/observability/adapters/external/signoz.js +22 -0
- package/dist/observability/adapters/external/traceloop.d.ts +20 -0
- package/dist/observability/adapters/external/traceloop.js +22 -0
- package/dist/observability/adapters/external/weave.d.ts +20 -0
- package/dist/observability/adapters/external/weave.js +22 -0
- package/dist/observability/adapters/index.d.ts +19 -0
- package/dist/observability/adapters/index.js +289 -0
- package/dist/observability/adapters/memory.d.ts +41 -0
- package/dist/observability/adapters/memory.js +190 -0
- package/dist/observability/adapters/noop.d.ts +25 -0
- package/dist/observability/adapters/noop.js +64 -0
- package/dist/observability/index.d.ts +47 -0
- package/dist/observability/index.js +115 -0
- package/dist/observability/types.d.ts +165 -0
- package/dist/observability/types.js +165 -0
- package/dist/planning/index.d.ts +253 -0
- package/dist/planning/index.js +475 -0
- package/dist/process/index.d.ts +25 -0
- package/dist/process/index.js +37 -0
- package/dist/process/process.d.ts +0 -0
- package/dist/process/process.js +1 -0
- package/dist/session/index.d.ts +111 -0
- package/dist/session/index.js +250 -0
- package/dist/skills/index.d.ts +70 -0
- package/dist/skills/index.js +233 -0
- package/dist/task/index.d.ts +25 -0
- package/dist/task/index.js +32 -0
- package/dist/task/task.d.ts +0 -0
- package/dist/task/task.js +1 -0
- package/dist/telemetry/index.d.ts +175 -0
- package/dist/telemetry/index.js +287 -0
- package/dist/tools/arxivTools.d.ts +32 -0
- package/dist/tools/arxivTools.js +81 -0
- package/dist/tools/base.d.ts +97 -0
- package/dist/tools/base.js +147 -0
- package/dist/tools/builtins/airweave.d.ts +32 -0
- package/dist/tools/builtins/airweave.js +119 -0
- package/dist/tools/builtins/bedrock-agentcore.d.ts +62 -0
- package/dist/tools/builtins/bedrock-agentcore.js +233 -0
- package/dist/tools/builtins/code-execution.d.ts +36 -0
- package/dist/tools/builtins/code-execution.js +136 -0
- package/dist/tools/builtins/code-mode.d.ts +54 -0
- package/dist/tools/builtins/code-mode.js +167 -0
- package/dist/tools/builtins/custom.d.ts +42 -0
- package/dist/tools/builtins/custom.js +195 -0
- package/dist/tools/builtins/exa.d.ts +53 -0
- package/dist/tools/builtins/exa.js +112 -0
- package/dist/tools/builtins/firecrawl.d.ts +56 -0
- package/dist/tools/builtins/firecrawl.js +158 -0
- package/dist/tools/builtins/index.d.ts +45 -0
- package/dist/tools/builtins/index.js +180 -0
- package/dist/tools/builtins/parallel.d.ts +30 -0
- package/dist/tools/builtins/parallel.js +113 -0
- package/dist/tools/builtins/perplexity.d.ts +32 -0
- package/dist/tools/builtins/perplexity.js +113 -0
- package/dist/tools/builtins/superagent.d.ts +66 -0
- package/dist/tools/builtins/superagent.js +187 -0
- package/dist/tools/builtins/tavily.d.ts +99 -0
- package/dist/tools/builtins/tavily.js +285 -0
- package/dist/tools/builtins/valyu.d.ts +65 -0
- package/dist/tools/builtins/valyu.js +193 -0
- package/dist/tools/decorator.d.ts +91 -0
- package/dist/tools/decorator.js +165 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.js +36 -0
- package/dist/tools/mcpSse.d.ts +43 -0
- package/dist/tools/mcpSse.js +110 -0
- package/dist/tools/registry/index.d.ts +9 -0
- package/dist/tools/registry/index.js +28 -0
- package/dist/tools/registry/middleware.d.ts +43 -0
- package/dist/tools/registry/middleware.js +220 -0
- package/dist/tools/registry/registry.d.ts +92 -0
- package/dist/tools/registry/registry.js +280 -0
- package/dist/tools/registry/types.d.ts +217 -0
- package/dist/tools/registry/types.js +49 -0
- package/dist/tools/test.d.ts +0 -0
- package/dist/tools/test.js +1 -0
- package/dist/tools/tools.d.ts +74 -0
- package/dist/tools/tools.js +133 -0
- package/dist/utils/logger.d.ts +25 -0
- package/dist/utils/logger.js +149 -0
- package/dist/utils/pretty-logger.d.ts +21 -0
- package/dist/utils/pretty-logger.js +248 -0
- package/dist/workflows/index.d.ts +118 -0
- package/dist/workflows/index.js +247 -0
- package/dist/workflows/loop.d.ts +0 -0
- package/dist/workflows/loop.js +1 -0
- package/dist/workflows/yaml-parser.d.ts +48 -0
- package/dist/workflows/yaml-parser.js +304 -0
- package/package.json +119 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI SDK Backend Types
|
|
4
|
+
*
|
|
5
|
+
* Type definitions for the AI SDK integration with praisonai-ts.
|
|
6
|
+
* These types define the configuration, errors, and stream chunk formats.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ADAPTERS = exports.COMMUNITY_PROVIDERS = exports.PROVIDER_ALIASES = exports.AISDK_PROVIDERS = exports.SAFE_DEFAULTS = exports.AISDKError = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Custom error class for AI SDK errors
|
|
12
|
+
*/
|
|
13
|
+
class AISDKError extends Error {
|
|
14
|
+
constructor(message, code, isRetryable, cause, statusCode) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'AISDKError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.isRetryable = isRetryable;
|
|
19
|
+
this.cause = cause;
|
|
20
|
+
this.statusCode = statusCode;
|
|
21
|
+
// Maintain proper stack trace in V8
|
|
22
|
+
if (Error.captureStackTrace) {
|
|
23
|
+
Error.captureStackTrace(this, AISDKError);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AISDKError = AISDKError;
|
|
28
|
+
/**
|
|
29
|
+
* Safe defaults for AI SDK backend
|
|
30
|
+
*/
|
|
31
|
+
exports.SAFE_DEFAULTS = {
|
|
32
|
+
timeout: 60000, // 60s request timeout
|
|
33
|
+
maxRetries: 2, // Retry on transient failures
|
|
34
|
+
maxOutputTokens: 4096, // Prevent runaway generation
|
|
35
|
+
redactLogs: true, // Never log API keys
|
|
36
|
+
debugLogging: false, // Opt-in verbose logging
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Default modalities for chat-only providers
|
|
40
|
+
*/
|
|
41
|
+
const CHAT_ONLY = {
|
|
42
|
+
text: true, chat: true, embeddings: false, image: false, audio: false, speech: false, tools: true
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Full modalities for providers with embeddings
|
|
46
|
+
*/
|
|
47
|
+
const CHAT_EMBED = {
|
|
48
|
+
text: true, chat: true, embeddings: true, image: false, audio: false, speech: false, tools: true
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Modalities for image generation providers
|
|
52
|
+
*/
|
|
53
|
+
const IMAGE_GEN = {
|
|
54
|
+
text: false, chat: false, embeddings: false, image: true, audio: false, speech: false, tools: false
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Modalities for audio/speech providers
|
|
58
|
+
*/
|
|
59
|
+
const AUDIO_SPEECH = {
|
|
60
|
+
text: false, chat: false, embeddings: false, image: false, audio: true, speech: true, tools: false
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Full multimodal support
|
|
64
|
+
*/
|
|
65
|
+
const MULTIMODAL = {
|
|
66
|
+
text: true, chat: true, embeddings: true, image: true, audio: true, speech: true, tools: true
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Supported AI SDK providers with their package names and capabilities
|
|
70
|
+
* Comprehensive list covering all AI SDK v6 providers
|
|
71
|
+
*/
|
|
72
|
+
exports.AISDK_PROVIDERS = {
|
|
73
|
+
// === Core Providers (Official AI SDK) ===
|
|
74
|
+
openai: { package: '@ai-sdk/openai', envKey: 'OPENAI_API_KEY', modalities: MULTIMODAL, description: 'OpenAI GPT models' },
|
|
75
|
+
anthropic: { package: '@ai-sdk/anthropic', envKey: 'ANTHROPIC_API_KEY', modalities: { ...CHAT_ONLY, image: true }, description: 'Anthropic Claude models' },
|
|
76
|
+
google: { package: '@ai-sdk/google', envKey: 'GOOGLE_API_KEY', modalities: MULTIMODAL, description: 'Google Generative AI (Gemini)' },
|
|
77
|
+
'google-vertex': { package: '@ai-sdk/google-vertex', envKey: 'GOOGLE_APPLICATION_CREDENTIALS', modalities: MULTIMODAL, description: 'Google Vertex AI' },
|
|
78
|
+
azure: { package: '@ai-sdk/azure', envKey: 'AZURE_API_KEY', modalities: MULTIMODAL, description: 'Azure OpenAI Service' },
|
|
79
|
+
'amazon-bedrock': { package: '@ai-sdk/amazon-bedrock', envKey: 'AWS_ACCESS_KEY_ID', modalities: CHAT_EMBED, description: 'Amazon Bedrock' },
|
|
80
|
+
// === xAI / Grok ===
|
|
81
|
+
xai: { package: '@ai-sdk/xai', envKey: 'XAI_API_KEY', modalities: { ...CHAT_ONLY, image: true }, description: 'xAI Grok models' },
|
|
82
|
+
// === Vercel ===
|
|
83
|
+
vercel: { package: '@ai-sdk/vercel', envKey: 'VERCEL_API_KEY', modalities: CHAT_ONLY, description: 'Vercel AI models' },
|
|
84
|
+
// === Inference Providers ===
|
|
85
|
+
groq: { package: '@ai-sdk/groq', envKey: 'GROQ_API_KEY', modalities: CHAT_ONLY, description: 'Groq inference' },
|
|
86
|
+
fireworks: { package: '@ai-sdk/fireworks', envKey: 'FIREWORKS_API_KEY', modalities: CHAT_EMBED, description: 'Fireworks AI' },
|
|
87
|
+
togetherai: { package: '@ai-sdk/togetherai', envKey: 'TOGETHER_API_KEY', modalities: CHAT_EMBED, description: 'Together.ai' },
|
|
88
|
+
deepinfra: { package: '@ai-sdk/deepinfra', envKey: 'DEEPINFRA_API_KEY', modalities: CHAT_EMBED, description: 'DeepInfra' },
|
|
89
|
+
replicate: { package: '@ai-sdk/replicate', envKey: 'REPLICATE_API_TOKEN', modalities: { ...CHAT_ONLY, image: true }, description: 'Replicate' },
|
|
90
|
+
baseten: { package: '@ai-sdk/baseten', envKey: 'BASETEN_API_KEY', modalities: CHAT_ONLY, description: 'Baseten' },
|
|
91
|
+
huggingface: { package: '@ai-sdk/huggingface', envKey: 'HUGGINGFACE_API_KEY', modalities: CHAT_EMBED, description: 'Hugging Face Inference' },
|
|
92
|
+
// === Model Providers ===
|
|
93
|
+
mistral: { package: '@ai-sdk/mistral', envKey: 'MISTRAL_API_KEY', modalities: CHAT_EMBED, description: 'Mistral AI' },
|
|
94
|
+
cohere: { package: '@ai-sdk/cohere', envKey: 'COHERE_API_KEY', modalities: CHAT_EMBED, description: 'Cohere' },
|
|
95
|
+
deepseek: { package: '@ai-sdk/deepseek', envKey: 'DEEPSEEK_API_KEY', modalities: CHAT_ONLY, description: 'DeepSeek' },
|
|
96
|
+
cerebras: { package: '@ai-sdk/cerebras', envKey: 'CEREBRAS_API_KEY', modalities: CHAT_ONLY, description: 'Cerebras' },
|
|
97
|
+
perplexity: { package: '@ai-sdk/perplexity', envKey: 'PERPLEXITY_API_KEY', modalities: CHAT_ONLY, description: 'Perplexity AI' },
|
|
98
|
+
// === Image Generation ===
|
|
99
|
+
fal: { package: '@ai-sdk/fal', envKey: 'FAL_KEY', modalities: IMAGE_GEN, description: 'Fal.ai image generation' },
|
|
100
|
+
'black-forest-labs': { package: '@ai-sdk/black-forest-labs', envKey: 'BFL_API_KEY', modalities: IMAGE_GEN, description: 'Black Forest Labs (FLUX)' },
|
|
101
|
+
luma: { package: '@ai-sdk/luma', envKey: 'LUMA_API_KEY', modalities: IMAGE_GEN, description: 'Luma AI video generation' },
|
|
102
|
+
// === Audio/Speech Providers ===
|
|
103
|
+
elevenlabs: { package: '@ai-sdk/elevenlabs', envKey: 'ELEVENLABS_API_KEY', modalities: AUDIO_SPEECH, description: 'ElevenLabs TTS' },
|
|
104
|
+
assemblyai: { package: '@ai-sdk/assemblyai', envKey: 'ASSEMBLYAI_API_KEY', modalities: AUDIO_SPEECH, description: 'AssemblyAI transcription' },
|
|
105
|
+
deepgram: { package: '@ai-sdk/deepgram', envKey: 'DEEPGRAM_API_KEY', modalities: AUDIO_SPEECH, description: 'Deepgram speech' },
|
|
106
|
+
gladia: { package: '@ai-sdk/gladia', envKey: 'GLADIA_API_KEY', modalities: AUDIO_SPEECH, description: 'Gladia transcription' },
|
|
107
|
+
lmnt: { package: '@ai-sdk/lmnt', envKey: 'LMNT_API_KEY', modalities: AUDIO_SPEECH, description: 'LMNT TTS' },
|
|
108
|
+
hume: { package: '@ai-sdk/hume', envKey: 'HUME_API_KEY', modalities: AUDIO_SPEECH, description: 'Hume AI emotion' },
|
|
109
|
+
revai: { package: '@ai-sdk/revai', envKey: 'REVAI_API_KEY', modalities: AUDIO_SPEECH, description: 'Rev.ai transcription' },
|
|
110
|
+
// === Gateway/Proxy Providers ===
|
|
111
|
+
'ai-gateway': { package: '@ai-sdk/gateway', envKey: 'AI_GATEWAY_API_KEY', modalities: CHAT_EMBED, description: 'AI Gateway' },
|
|
112
|
+
openrouter: { package: '@openrouter/ai-sdk-provider', envKey: 'OPENROUTER_API_KEY', modalities: CHAT_EMBED, description: 'OpenRouter' },
|
|
113
|
+
portkey: { package: '@portkey-ai/vercel-provider', envKey: 'PORTKEY_API_KEY', modalities: CHAT_EMBED, description: 'Portkey AI Gateway' },
|
|
114
|
+
helicone: { package: '@helicone/ai-sdk', envKey: 'HELICONE_API_KEY', modalities: CHAT_EMBED, description: 'Helicone proxy' },
|
|
115
|
+
// === Cloudflare ===
|
|
116
|
+
'cloudflare-workers-ai': { package: '@ai-sdk/cloudflare', envKey: 'CLOUDFLARE_API_TOKEN', modalities: CHAT_EMBED, description: 'Cloudflare Workers AI' },
|
|
117
|
+
'cloudflare-ai-gateway': { package: '@ai-sdk/cloudflare', envKey: 'CLOUDFLARE_API_TOKEN', modalities: CHAT_EMBED, description: 'Cloudflare AI Gateway' },
|
|
118
|
+
// === Local/Self-hosted ===
|
|
119
|
+
ollama: { package: 'ollama-ai-provider', envKey: 'OLLAMA_BASE_URL', modalities: CHAT_EMBED, description: 'Ollama local models' },
|
|
120
|
+
'lm-studio': { package: '@ai-sdk/openai-compatible', envKey: 'LM_STUDIO_BASE_URL', modalities: CHAT_ONLY, description: 'LM Studio' },
|
|
121
|
+
'nvidia-nim': { package: '@ai-sdk/openai-compatible', envKey: 'NVIDIA_API_KEY', modalities: CHAT_EMBED, description: 'NVIDIA NIM' },
|
|
122
|
+
// === OpenAI Compatible ===
|
|
123
|
+
'openai-compatible': { package: '@ai-sdk/openai-compatible', envKey: 'OPENAI_COMPATIBLE_API_KEY', modalities: CHAT_EMBED, description: 'OpenAI-compatible endpoints' },
|
|
124
|
+
// === Regional/Specialized Providers ===
|
|
125
|
+
qwen: { package: '@ai-sdk/qwen', envKey: 'DASHSCOPE_API_KEY', modalities: CHAT_EMBED, description: 'Alibaba Qwen' },
|
|
126
|
+
'zhipu-ai': { package: '@ai-sdk/zhipu', envKey: 'ZHIPU_API_KEY', modalities: CHAT_EMBED, description: 'Zhipu AI (GLM)' },
|
|
127
|
+
minimax: { package: '@ai-sdk/minimax', envKey: 'MINIMAX_API_KEY', modalities: CHAT_ONLY, description: 'MiniMax' },
|
|
128
|
+
spark: { package: '@ai-sdk/spark', envKey: 'SPARK_API_KEY', modalities: CHAT_ONLY, description: 'iFlytek Spark' },
|
|
129
|
+
sambanova: { package: '@ai-sdk/sambanova', envKey: 'SAMBANOVA_API_KEY', modalities: CHAT_ONLY, description: 'SambaNova' },
|
|
130
|
+
// === Embedding Specialists ===
|
|
131
|
+
'voyage-ai': { package: '@ai-sdk/voyage', envKey: 'VOYAGE_API_KEY', modalities: { ...CHAT_ONLY, embeddings: true, tools: false }, description: 'Voyage AI embeddings' },
|
|
132
|
+
'jina-ai': { package: '@ai-sdk/jina', envKey: 'JINA_API_KEY', modalities: { ...CHAT_ONLY, embeddings: true, tools: false }, description: 'Jina AI embeddings' },
|
|
133
|
+
mixedbread: { package: '@ai-sdk/mixedbread', envKey: 'MIXEDBREAD_API_KEY', modalities: { ...CHAT_ONLY, embeddings: true, tools: false }, description: 'Mixedbread embeddings' },
|
|
134
|
+
// === Memory/Agent Providers ===
|
|
135
|
+
mem0: { package: '@mem0ai/vercel-ai-provider', envKey: 'MEM0_API_KEY', modalities: CHAT_ONLY, description: 'Mem0 memory layer' },
|
|
136
|
+
letta: { package: '@letta-ai/vercel-ai-provider', envKey: 'LETTA_API_KEY', modalities: CHAT_ONLY, description: 'Letta agent memory' },
|
|
137
|
+
// === Enterprise/Cloud ===
|
|
138
|
+
'azure-ai': { package: '@ai-sdk/azure', envKey: 'AZURE_API_KEY', modalities: CHAT_EMBED, description: 'Azure AI Services' },
|
|
139
|
+
'sap-ai-core': { package: '@sap-ai-sdk/ai-core', envKey: 'SAP_AI_CORE_KEY', modalities: CHAT_ONLY, description: 'SAP AI Core' },
|
|
140
|
+
// === Other Providers ===
|
|
141
|
+
friendliai: { package: '@friendliai/ai-provider', envKey: 'FRIENDLI_TOKEN', modalities: CHAT_ONLY, description: 'FriendliAI' },
|
|
142
|
+
runpod: { package: '@runpod/ai-sdk', envKey: 'RUNPOD_API_KEY', modalities: CHAT_ONLY, description: 'RunPod serverless' },
|
|
143
|
+
clarifai: { package: '@clarifai/ai-sdk', envKey: 'CLARIFAI_PAT', modalities: { ...CHAT_ONLY, image: true }, description: 'Clarifai' },
|
|
144
|
+
'inflection-ai': { package: '@ai-sdk/inflection', envKey: 'INFLECTION_API_KEY', modalities: CHAT_ONLY, description: 'Inflection AI (Pi)' },
|
|
145
|
+
dify: { package: '@dify-ai/ai-sdk', envKey: 'DIFY_API_KEY', modalities: CHAT_ONLY, description: 'Dify platform' },
|
|
146
|
+
sarvam: { package: '@sarvam-ai/ai-sdk', envKey: 'SARVAM_API_KEY', modalities: CHAT_ONLY, description: 'Sarvam AI (Indic)' },
|
|
147
|
+
'aiml-api': { package: '@aimlapi/ai-sdk', envKey: 'AIML_API_KEY', modalities: CHAT_EMBED, description: 'AI/ML API' },
|
|
148
|
+
aihubmix: { package: '@aihubmix/ai-sdk', envKey: 'AIHUBMIX_API_KEY', modalities: CHAT_ONLY, description: 'AIHubMix' },
|
|
149
|
+
crosshatch: { package: '@crosshatch/ai-sdk', envKey: 'CROSSHATCH_API_KEY', modalities: CHAT_ONLY, description: 'Crosshatch' },
|
|
150
|
+
langdb: { package: '@langdb/ai-sdk', envKey: 'LANGDB_API_KEY', modalities: CHAT_ONLY, description: 'LangDB' },
|
|
151
|
+
requesty: { package: '@requesty/ai-sdk', envKey: 'REQUESTY_API_KEY', modalities: CHAT_ONLY, description: 'Requesty' },
|
|
152
|
+
// === Anthropic Vertex ===
|
|
153
|
+
'anthropic-vertex': { package: '@anthropic-ai/vertex-sdk', envKey: 'GOOGLE_APPLICATION_CREDENTIALS', modalities: { ...CHAT_ONLY, image: true }, description: 'Anthropic via Vertex AI' },
|
|
154
|
+
// === Heroku ===
|
|
155
|
+
heroku: { package: '@heroku/ai-sdk', envKey: 'HEROKU_API_KEY', modalities: CHAT_ONLY, description: 'Heroku AI' },
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Provider aliases for convenience
|
|
159
|
+
*/
|
|
160
|
+
exports.PROVIDER_ALIASES = {
|
|
161
|
+
// Core aliases
|
|
162
|
+
oai: 'openai',
|
|
163
|
+
claude: 'anthropic',
|
|
164
|
+
gemini: 'google',
|
|
165
|
+
gcp: 'google',
|
|
166
|
+
vertex: 'google-vertex',
|
|
167
|
+
'vertex-ai': 'google-vertex',
|
|
168
|
+
// Cloud aliases
|
|
169
|
+
aws: 'amazon-bedrock',
|
|
170
|
+
bedrock: 'amazon-bedrock',
|
|
171
|
+
'azure-openai': 'azure',
|
|
172
|
+
// Inference aliases
|
|
173
|
+
together: 'togetherai',
|
|
174
|
+
'together-ai': 'togetherai',
|
|
175
|
+
pplx: 'perplexity',
|
|
176
|
+
grok: 'xai',
|
|
177
|
+
// Image aliases
|
|
178
|
+
flux: 'black-forest-labs',
|
|
179
|
+
bfl: 'black-forest-labs',
|
|
180
|
+
// Audio aliases
|
|
181
|
+
'11labs': 'elevenlabs',
|
|
182
|
+
// Gateway aliases
|
|
183
|
+
'cf-ai': 'cloudflare-workers-ai',
|
|
184
|
+
'cf-gateway': 'cloudflare-ai-gateway',
|
|
185
|
+
cloudflare: 'cloudflare-workers-ai',
|
|
186
|
+
// Local aliases
|
|
187
|
+
local: 'ollama',
|
|
188
|
+
lmstudio: 'lm-studio',
|
|
189
|
+
nim: 'nvidia-nim',
|
|
190
|
+
nvidia: 'nvidia-nim',
|
|
191
|
+
// Regional aliases
|
|
192
|
+
alibaba: 'qwen',
|
|
193
|
+
dashscope: 'qwen',
|
|
194
|
+
glm: 'zhipu-ai',
|
|
195
|
+
zhipu: 'zhipu-ai',
|
|
196
|
+
iflytek: 'spark',
|
|
197
|
+
// Other aliases
|
|
198
|
+
voyage: 'voyage-ai',
|
|
199
|
+
jina: 'jina-ai',
|
|
200
|
+
'ai-ml': 'aiml-api',
|
|
201
|
+
inflection: 'inflection-ai',
|
|
202
|
+
pi: 'inflection-ai',
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Known community providers (not bundled, user must install)
|
|
206
|
+
*/
|
|
207
|
+
exports.COMMUNITY_PROVIDERS = [
|
|
208
|
+
{ name: 'a2a', package: '@anthropic/a2a-sdk', envKey: 'A2A_API_KEY', description: 'Anthropic A2A protocol' },
|
|
209
|
+
{ name: 'acp', package: '@acp/ai-sdk', envKey: 'ACP_API_KEY', description: 'Agent Client Protocol' },
|
|
210
|
+
{ name: 'firemoon', package: '@firemoon/ai-sdk', envKey: 'FIREMOON_API_KEY', description: 'Firemoon AI' },
|
|
211
|
+
{ name: 'supermemory', package: '@supermemory/ai-sdk', envKey: 'SUPERMEMORY_API_KEY', description: 'Supermemory' },
|
|
212
|
+
{ name: 'react-native-apple', package: '@react-native-ai/apple', envKey: '', description: 'React Native Apple AI' },
|
|
213
|
+
{ name: 'claude-code', package: '@anthropic/claude-code', envKey: 'ANTHROPIC_API_KEY', description: 'Claude Code CLI' },
|
|
214
|
+
{ name: 'gemini-cli', package: '@google/gemini-cli', envKey: 'GOOGLE_API_KEY', description: 'Gemini CLI' },
|
|
215
|
+
{ name: 'built-in-ai', package: '@anthropic/built-in-ai', envKey: '', description: 'Browser built-in AI' },
|
|
216
|
+
{ name: 'mcp-sampling', package: '@modelcontextprotocol/sampling', envKey: '', description: 'MCP Sampling Provider' },
|
|
217
|
+
{ name: 'automatic1111', package: '@a1111/ai-sdk', envKey: 'A1111_BASE_URL', description: 'Automatic1111 Stable Diffusion' },
|
|
218
|
+
];
|
|
219
|
+
exports.ADAPTERS = [
|
|
220
|
+
{ name: 'langchain', package: '@ai-sdk/langchain', description: 'LangChain adapter', type: 'langchain' },
|
|
221
|
+
{ name: 'llamaindex', package: '@ai-sdk/llamaindex', description: 'LlamaIndex adapter', type: 'llamaindex' },
|
|
222
|
+
];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Anthropic Provider - Implementation for Anthropic Claude API
|
|
3
|
+
*/
|
|
4
|
+
import { BaseProvider } from './base';
|
|
5
|
+
import type { ProviderConfig, GenerateTextOptions, GenerateTextResult, StreamTextOptions, StreamChunk, GenerateObjectOptions, GenerateObjectResult, Message, ToolDefinition } from './types';
|
|
6
|
+
interface AnthropicMessage {
|
|
7
|
+
role: 'user' | 'assistant';
|
|
8
|
+
content: string | Array<{
|
|
9
|
+
type: string;
|
|
10
|
+
text?: string;
|
|
11
|
+
tool_use_id?: string;
|
|
12
|
+
content?: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
interface AnthropicTool {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
input_schema: Record<string, any>;
|
|
19
|
+
}
|
|
20
|
+
export declare class AnthropicProvider extends BaseProvider {
|
|
21
|
+
readonly providerId = "anthropic";
|
|
22
|
+
private apiKey;
|
|
23
|
+
private baseUrl;
|
|
24
|
+
constructor(modelId: string, config?: ProviderConfig);
|
|
25
|
+
generateText(options: GenerateTextOptions): Promise<GenerateTextResult>;
|
|
26
|
+
streamText(options: StreamTextOptions): Promise<AsyncIterable<StreamChunk>>;
|
|
27
|
+
generateObject<T = any>(options: GenerateObjectOptions<T>): Promise<GenerateObjectResult<T>>;
|
|
28
|
+
private extractSystemPrompt;
|
|
29
|
+
protected formatMessages(messages: Message[]): AnthropicMessage[];
|
|
30
|
+
protected formatTools(tools: ToolDefinition[]): AnthropicTool[];
|
|
31
|
+
private mapStopReason;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic Provider - Implementation for Anthropic Claude API
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnthropicProvider = void 0;
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
class AnthropicProvider extends base_1.BaseProvider {
|
|
9
|
+
constructor(modelId, config = {}) {
|
|
10
|
+
super(modelId, config);
|
|
11
|
+
this.providerId = 'anthropic';
|
|
12
|
+
this.apiKey = config.apiKey || process.env.ANTHROPIC_API_KEY || '';
|
|
13
|
+
this.baseUrl = config.baseUrl || 'https://api.anthropic.com';
|
|
14
|
+
if (!this.apiKey) {
|
|
15
|
+
throw new Error('ANTHROPIC_API_KEY is required');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async generateText(options) {
|
|
19
|
+
return this.withRetry(async () => {
|
|
20
|
+
const { systemPrompt, messages } = this.extractSystemPrompt(options.messages);
|
|
21
|
+
const response = await fetch(`${this.baseUrl}/v1/messages`, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'x-api-key': this.apiKey,
|
|
26
|
+
'anthropic-version': '2023-06-01',
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify({
|
|
29
|
+
model: this.modelId,
|
|
30
|
+
max_tokens: options.maxTokens || 4096,
|
|
31
|
+
system: systemPrompt,
|
|
32
|
+
messages: this.formatMessages(messages),
|
|
33
|
+
temperature: options.temperature ?? 0.7,
|
|
34
|
+
tools: options.tools ? this.formatTools(options.tools) : undefined,
|
|
35
|
+
stop_sequences: options.stop,
|
|
36
|
+
top_p: options.topP,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const error = await response.json().catch(() => ({}));
|
|
41
|
+
throw Object.assign(new Error(error.error?.message || `Anthropic API error: ${response.status}`), {
|
|
42
|
+
status: response.status,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const data = await response.json();
|
|
46
|
+
let text = '';
|
|
47
|
+
const toolCalls = [];
|
|
48
|
+
for (const block of data.content || []) {
|
|
49
|
+
if (block.type === 'text') {
|
|
50
|
+
text += block.text;
|
|
51
|
+
}
|
|
52
|
+
else if (block.type === 'tool_use') {
|
|
53
|
+
toolCalls.push({
|
|
54
|
+
id: block.id,
|
|
55
|
+
type: 'function',
|
|
56
|
+
function: {
|
|
57
|
+
name: block.name,
|
|
58
|
+
arguments: JSON.stringify(block.input),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
text,
|
|
65
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
66
|
+
usage: {
|
|
67
|
+
promptTokens: data.usage?.input_tokens || 0,
|
|
68
|
+
completionTokens: data.usage?.output_tokens || 0,
|
|
69
|
+
totalTokens: (data.usage?.input_tokens || 0) + (data.usage?.output_tokens || 0),
|
|
70
|
+
},
|
|
71
|
+
finishReason: this.mapStopReason(data.stop_reason),
|
|
72
|
+
raw: data,
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async streamText(options) {
|
|
77
|
+
const self = this;
|
|
78
|
+
const { systemPrompt, messages } = this.extractSystemPrompt(options.messages);
|
|
79
|
+
return {
|
|
80
|
+
async *[Symbol.asyncIterator]() {
|
|
81
|
+
const response = await fetch(`${self.baseUrl}/v1/messages`, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: {
|
|
84
|
+
'Content-Type': 'application/json',
|
|
85
|
+
'x-api-key': self.apiKey,
|
|
86
|
+
'anthropic-version': '2023-06-01',
|
|
87
|
+
},
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
model: self.modelId,
|
|
90
|
+
max_tokens: options.maxTokens || 4096,
|
|
91
|
+
system: systemPrompt,
|
|
92
|
+
messages: self.formatMessages(messages),
|
|
93
|
+
temperature: options.temperature ?? 0.7,
|
|
94
|
+
tools: options.tools ? self.formatTools(options.tools) : undefined,
|
|
95
|
+
stream: true,
|
|
96
|
+
}),
|
|
97
|
+
});
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
const error = await response.json().catch(() => ({}));
|
|
100
|
+
throw new Error(error.error?.message || `Anthropic API error: ${response.status}`);
|
|
101
|
+
}
|
|
102
|
+
const reader = response.body?.getReader();
|
|
103
|
+
if (!reader)
|
|
104
|
+
throw new Error('No response body');
|
|
105
|
+
const decoder = new TextDecoder();
|
|
106
|
+
let buffer = '';
|
|
107
|
+
const toolCalls = [];
|
|
108
|
+
let currentToolCall = null;
|
|
109
|
+
while (true) {
|
|
110
|
+
const { done, value } = await reader.read();
|
|
111
|
+
if (done)
|
|
112
|
+
break;
|
|
113
|
+
buffer += decoder.decode(value, { stream: true });
|
|
114
|
+
const lines = buffer.split('\n');
|
|
115
|
+
buffer = lines.pop() || '';
|
|
116
|
+
for (const line of lines) {
|
|
117
|
+
if (!line.startsWith('data: '))
|
|
118
|
+
continue;
|
|
119
|
+
const data = line.slice(6);
|
|
120
|
+
if (data === '[DONE]')
|
|
121
|
+
continue;
|
|
122
|
+
try {
|
|
123
|
+
const event = JSON.parse(data);
|
|
124
|
+
if (event.type === 'content_block_delta') {
|
|
125
|
+
if (event.delta?.type === 'text_delta') {
|
|
126
|
+
const text = event.delta.text;
|
|
127
|
+
if (options.onToken)
|
|
128
|
+
options.onToken(text);
|
|
129
|
+
yield { text };
|
|
130
|
+
}
|
|
131
|
+
else if (event.delta?.type === 'input_json_delta') {
|
|
132
|
+
if (currentToolCall) {
|
|
133
|
+
currentToolCall.function.arguments += event.delta.partial_json;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (event.type === 'content_block_start') {
|
|
138
|
+
if (event.content_block?.type === 'tool_use') {
|
|
139
|
+
currentToolCall = {
|
|
140
|
+
id: event.content_block.id,
|
|
141
|
+
type: 'function',
|
|
142
|
+
function: {
|
|
143
|
+
name: event.content_block.name,
|
|
144
|
+
arguments: '',
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (event.type === 'content_block_stop') {
|
|
150
|
+
if (currentToolCall) {
|
|
151
|
+
toolCalls.push(currentToolCall);
|
|
152
|
+
currentToolCall = null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
else if (event.type === 'message_delta') {
|
|
156
|
+
yield {
|
|
157
|
+
finishReason: self.mapStopReason(event.delta?.stop_reason),
|
|
158
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
159
|
+
usage: event.usage ? {
|
|
160
|
+
promptTokens: 0,
|
|
161
|
+
completionTokens: event.usage.output_tokens,
|
|
162
|
+
totalTokens: event.usage.output_tokens,
|
|
163
|
+
} : undefined,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
// Skip malformed JSON
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
async generateObject(options) {
|
|
176
|
+
const { systemPrompt, messages } = this.extractSystemPrompt(options.messages);
|
|
177
|
+
// Add JSON instruction to system prompt
|
|
178
|
+
const jsonSystemPrompt = `${systemPrompt}\n\nYou must respond with valid JSON matching this schema:\n${JSON.stringify(options.schema, null, 2)}`;
|
|
179
|
+
return this.withRetry(async () => {
|
|
180
|
+
const response = await fetch(`${this.baseUrl}/v1/messages`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
headers: {
|
|
183
|
+
'Content-Type': 'application/json',
|
|
184
|
+
'x-api-key': this.apiKey,
|
|
185
|
+
'anthropic-version': '2023-06-01',
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify({
|
|
188
|
+
model: this.modelId,
|
|
189
|
+
max_tokens: options.maxTokens || 4096,
|
|
190
|
+
system: jsonSystemPrompt,
|
|
191
|
+
messages: this.formatMessages(messages),
|
|
192
|
+
temperature: options.temperature ?? 0.7,
|
|
193
|
+
}),
|
|
194
|
+
});
|
|
195
|
+
if (!response.ok) {
|
|
196
|
+
const error = await response.json().catch(() => ({}));
|
|
197
|
+
throw new Error(error.error?.message || `Anthropic API error: ${response.status}`);
|
|
198
|
+
}
|
|
199
|
+
const data = await response.json();
|
|
200
|
+
let text = '';
|
|
201
|
+
for (const block of data.content || []) {
|
|
202
|
+
if (block.type === 'text') {
|
|
203
|
+
text += block.text;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Extract JSON from response
|
|
207
|
+
const jsonMatch = text.match(/\{[\s\S]*\}/);
|
|
208
|
+
if (!jsonMatch) {
|
|
209
|
+
throw new Error(`No JSON found in response: ${text}`);
|
|
210
|
+
}
|
|
211
|
+
let parsed;
|
|
212
|
+
try {
|
|
213
|
+
parsed = JSON.parse(jsonMatch[0]);
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
throw new Error(`Failed to parse JSON: ${jsonMatch[0]}`);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
object: parsed,
|
|
220
|
+
usage: {
|
|
221
|
+
promptTokens: data.usage?.input_tokens || 0,
|
|
222
|
+
completionTokens: data.usage?.output_tokens || 0,
|
|
223
|
+
totalTokens: (data.usage?.input_tokens || 0) + (data.usage?.output_tokens || 0),
|
|
224
|
+
},
|
|
225
|
+
raw: data,
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
extractSystemPrompt(messages) {
|
|
230
|
+
const systemMessages = messages.filter(m => m.role === 'system');
|
|
231
|
+
const otherMessages = messages.filter(m => m.role !== 'system');
|
|
232
|
+
const systemPrompt = systemMessages.map(m => m.content).join('\n');
|
|
233
|
+
return { systemPrompt, messages: otherMessages };
|
|
234
|
+
}
|
|
235
|
+
formatMessages(messages) {
|
|
236
|
+
const result = [];
|
|
237
|
+
for (const msg of messages) {
|
|
238
|
+
if (msg.role === 'system')
|
|
239
|
+
continue; // Handled separately
|
|
240
|
+
if (msg.role === 'tool') {
|
|
241
|
+
// Tool results need to be part of user message in Anthropic
|
|
242
|
+
result.push({
|
|
243
|
+
role: 'user',
|
|
244
|
+
content: [{
|
|
245
|
+
type: 'tool_result',
|
|
246
|
+
tool_use_id: msg.tool_call_id || '',
|
|
247
|
+
content: msg.content || '',
|
|
248
|
+
}],
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
else if (msg.role === 'assistant' && msg.tool_calls) {
|
|
252
|
+
const content = [];
|
|
253
|
+
if (msg.content) {
|
|
254
|
+
content.push({ type: 'text', text: msg.content });
|
|
255
|
+
}
|
|
256
|
+
for (const tc of msg.tool_calls) {
|
|
257
|
+
content.push({
|
|
258
|
+
type: 'tool_use',
|
|
259
|
+
id: tc.id,
|
|
260
|
+
name: tc.function.name,
|
|
261
|
+
input: JSON.parse(tc.function.arguments),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
result.push({ role: 'assistant', content });
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
result.push({
|
|
268
|
+
role: msg.role,
|
|
269
|
+
content: msg.content || '',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
formatTools(tools) {
|
|
276
|
+
return tools.map(tool => ({
|
|
277
|
+
name: tool.name,
|
|
278
|
+
description: tool.description || `Function ${tool.name}`,
|
|
279
|
+
input_schema: tool.parameters || { type: 'object', properties: {} },
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
mapStopReason(reason) {
|
|
283
|
+
switch (reason) {
|
|
284
|
+
case 'end_turn': return 'stop';
|
|
285
|
+
case 'max_tokens': return 'length';
|
|
286
|
+
case 'tool_use': return 'tool_calls';
|
|
287
|
+
default: return 'stop';
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
exports.AnthropicProvider = AnthropicProvider;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Provider - Abstract base class for LLM providers
|
|
3
|
+
*/
|
|
4
|
+
import type { LLMProvider, ProviderConfig, GenerateTextOptions, GenerateTextResult, StreamTextOptions, StreamChunk, GenerateObjectOptions, GenerateObjectResult, Message, ToolDefinition } from './types';
|
|
5
|
+
export declare abstract class BaseProvider implements LLMProvider {
|
|
6
|
+
abstract readonly providerId: string;
|
|
7
|
+
readonly modelId: string;
|
|
8
|
+
protected config: ProviderConfig;
|
|
9
|
+
constructor(modelId: string, config?: ProviderConfig);
|
|
10
|
+
abstract generateText(options: GenerateTextOptions): Promise<GenerateTextResult>;
|
|
11
|
+
abstract streamText(options: StreamTextOptions): Promise<AsyncIterable<StreamChunk>>;
|
|
12
|
+
abstract generateObject<T = any>(options: GenerateObjectOptions<T>): Promise<GenerateObjectResult<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* Convert tool definitions to provider-specific format
|
|
15
|
+
*/
|
|
16
|
+
protected abstract formatTools(tools: ToolDefinition[]): any[];
|
|
17
|
+
/**
|
|
18
|
+
* Convert messages to provider-specific format
|
|
19
|
+
*/
|
|
20
|
+
protected abstract formatMessages(messages: Message[]): any[];
|
|
21
|
+
/**
|
|
22
|
+
* Retry logic with exponential backoff
|
|
23
|
+
*/
|
|
24
|
+
protected withRetry<T>(fn: () => Promise<T>, maxRetries?: number): Promise<T>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Base Provider - Abstract base class for LLM providers
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BaseProvider = void 0;
|
|
7
|
+
class BaseProvider {
|
|
8
|
+
constructor(modelId, config = {}) {
|
|
9
|
+
this.modelId = modelId;
|
|
10
|
+
this.config = {
|
|
11
|
+
maxRetries: 3,
|
|
12
|
+
timeout: 60000,
|
|
13
|
+
...config,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Retry logic with exponential backoff
|
|
18
|
+
*/
|
|
19
|
+
async withRetry(fn, maxRetries = this.config.maxRetries || 3) {
|
|
20
|
+
let lastError;
|
|
21
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
22
|
+
try {
|
|
23
|
+
return await fn();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
lastError = error;
|
|
27
|
+
// Check if error is retryable (rate limit, server error)
|
|
28
|
+
const isRetryable = error.status === 429 ||
|
|
29
|
+
error.status >= 500 ||
|
|
30
|
+
error.code === 'ECONNRESET' ||
|
|
31
|
+
error.code === 'ETIMEDOUT';
|
|
32
|
+
if (!isRetryable || attempt === maxRetries) {
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
// Exponential backoff
|
|
36
|
+
const delay = Math.min(1000 * Math.pow(2, attempt), 30000);
|
|
37
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw lastError;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.BaseProvider = BaseProvider;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Provider - Implementation for Google Gemini API
|
|
3
|
+
*/
|
|
4
|
+
import { BaseProvider } from './base';
|
|
5
|
+
import type { ProviderConfig, GenerateTextOptions, GenerateTextResult, StreamTextOptions, StreamChunk, GenerateObjectOptions, GenerateObjectResult, Message, ToolDefinition } from './types';
|
|
6
|
+
interface GeminiContent {
|
|
7
|
+
role: 'user' | 'model';
|
|
8
|
+
parts: Array<{
|
|
9
|
+
text?: string;
|
|
10
|
+
functionCall?: any;
|
|
11
|
+
functionResponse?: any;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export declare class GoogleProvider extends BaseProvider {
|
|
15
|
+
readonly providerId = "google";
|
|
16
|
+
private apiKey;
|
|
17
|
+
private baseUrl;
|
|
18
|
+
constructor(modelId: string, config?: ProviderConfig);
|
|
19
|
+
generateText(options: GenerateTextOptions): Promise<GenerateTextResult>;
|
|
20
|
+
streamText(options: StreamTextOptions): Promise<AsyncIterable<StreamChunk>>;
|
|
21
|
+
generateObject<T = any>(options: GenerateObjectOptions<T>): Promise<GenerateObjectResult<T>>;
|
|
22
|
+
private formatRequest;
|
|
23
|
+
protected formatMessages(messages: Message[]): GeminiContent[];
|
|
24
|
+
protected formatTools(tools: ToolDefinition[]): any[];
|
|
25
|
+
private mapFinishReason;
|
|
26
|
+
}
|
|
27
|
+
export {};
|