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,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI SDK Integration for praisonai-ts
|
|
4
|
+
*
|
|
5
|
+
* This module provides integration with Vercel's AI SDK for multi-provider LLM support.
|
|
6
|
+
* All imports are lazy-loaded to avoid startup cost when AI SDK is not used.
|
|
7
|
+
*
|
|
8
|
+
* @example Basic usage
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createAISDKBackend, registerAISDKProviders } from 'praisonai';
|
|
11
|
+
*
|
|
12
|
+
* // Register AI SDK providers (one-time)
|
|
13
|
+
* registerAISDKProviders();
|
|
14
|
+
*
|
|
15
|
+
* // Create a backend for any supported provider
|
|
16
|
+
* const backend = createAISDKBackend('anthropic/claude-3-5-sonnet');
|
|
17
|
+
* const result = await backend.generateText({ messages: [...] });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.AISDKBackend = exports.redactSensitiveData = exports.createStandardMiddleware = exports.composeMiddleware = exports.createTimeoutMiddleware = exports.createLoggingMiddleware = exports.createAttributionMiddleware = exports.createSimplePrompt = exports.toAISDKToolChoice = exports.mapFinishReasonToProvider = exports.mapFinishReason = exports.fromAISDKStreamChunk = exports.fromAISDKResult = exports.toAISDKToolResult = exports.fromAISDKToolCall = exports.toAISDKTools = exports.toAISDKPrompt = exports.getMissingApiKeyMessage = exports.validateProviderApiKey = exports.createAISDKProvider = exports.getCustomProvider = exports.unregisterCustomProvider = exports.registerCustomProvider = exports.listSupportedProviders = exports.getProviderEnvKey = exports.getProviderPackage = exports.isProviderSupported = exports.resolveProviderAlias = exports.parseModelString = exports.PROVIDER_ALIASES = exports.AISDK_PROVIDERS = exports.SAFE_DEFAULTS = exports.AISDKError = void 0;
|
|
55
|
+
exports.getAISDKBackendClass = getAISDKBackendClass;
|
|
56
|
+
exports.createAISDKBackend = createAISDKBackend;
|
|
57
|
+
exports.registerAISDKProviders = registerAISDKProviders;
|
|
58
|
+
exports.isAISDKAvailable = isAISDKAvailable;
|
|
59
|
+
exports.getAISDKVersion = getAISDKVersion;
|
|
60
|
+
var types_1 = require("./types");
|
|
61
|
+
Object.defineProperty(exports, "AISDKError", { enumerable: true, get: function () { return types_1.AISDKError; } });
|
|
62
|
+
Object.defineProperty(exports, "SAFE_DEFAULTS", { enumerable: true, get: function () { return types_1.SAFE_DEFAULTS; } });
|
|
63
|
+
Object.defineProperty(exports, "AISDK_PROVIDERS", { enumerable: true, get: function () { return types_1.AISDK_PROVIDERS; } });
|
|
64
|
+
Object.defineProperty(exports, "PROVIDER_ALIASES", { enumerable: true, get: function () { return types_1.PROVIDER_ALIASES; } });
|
|
65
|
+
// Re-export provider map functions
|
|
66
|
+
var provider_map_1 = require("./provider-map");
|
|
67
|
+
Object.defineProperty(exports, "parseModelString", { enumerable: true, get: function () { return provider_map_1.parseModelString; } });
|
|
68
|
+
Object.defineProperty(exports, "resolveProviderAlias", { enumerable: true, get: function () { return provider_map_1.resolveProviderAlias; } });
|
|
69
|
+
Object.defineProperty(exports, "isProviderSupported", { enumerable: true, get: function () { return provider_map_1.isProviderSupported; } });
|
|
70
|
+
Object.defineProperty(exports, "getProviderPackage", { enumerable: true, get: function () { return provider_map_1.getProviderPackage; } });
|
|
71
|
+
Object.defineProperty(exports, "getProviderEnvKey", { enumerable: true, get: function () { return provider_map_1.getProviderEnvKey; } });
|
|
72
|
+
Object.defineProperty(exports, "listSupportedProviders", { enumerable: true, get: function () { return provider_map_1.listSupportedProviders; } });
|
|
73
|
+
Object.defineProperty(exports, "registerCustomProvider", { enumerable: true, get: function () { return provider_map_1.registerCustomProvider; } });
|
|
74
|
+
Object.defineProperty(exports, "unregisterCustomProvider", { enumerable: true, get: function () { return provider_map_1.unregisterCustomProvider; } });
|
|
75
|
+
Object.defineProperty(exports, "getCustomProvider", { enumerable: true, get: function () { return provider_map_1.getCustomProvider; } });
|
|
76
|
+
Object.defineProperty(exports, "createAISDKProvider", { enumerable: true, get: function () { return provider_map_1.createAISDKProvider; } });
|
|
77
|
+
Object.defineProperty(exports, "validateProviderApiKey", { enumerable: true, get: function () { return provider_map_1.validateProviderApiKey; } });
|
|
78
|
+
Object.defineProperty(exports, "getMissingApiKeyMessage", { enumerable: true, get: function () { return provider_map_1.getMissingApiKeyMessage; } });
|
|
79
|
+
// Re-export adapter functions
|
|
80
|
+
var adapter_1 = require("./adapter");
|
|
81
|
+
Object.defineProperty(exports, "toAISDKPrompt", { enumerable: true, get: function () { return adapter_1.toAISDKPrompt; } });
|
|
82
|
+
Object.defineProperty(exports, "toAISDKTools", { enumerable: true, get: function () { return adapter_1.toAISDKTools; } });
|
|
83
|
+
Object.defineProperty(exports, "fromAISDKToolCall", { enumerable: true, get: function () { return adapter_1.fromAISDKToolCall; } });
|
|
84
|
+
Object.defineProperty(exports, "toAISDKToolResult", { enumerable: true, get: function () { return adapter_1.toAISDKToolResult; } });
|
|
85
|
+
Object.defineProperty(exports, "fromAISDKResult", { enumerable: true, get: function () { return adapter_1.fromAISDKResult; } });
|
|
86
|
+
Object.defineProperty(exports, "fromAISDKStreamChunk", { enumerable: true, get: function () { return adapter_1.fromAISDKStreamChunk; } });
|
|
87
|
+
Object.defineProperty(exports, "mapFinishReason", { enumerable: true, get: function () { return adapter_1.mapFinishReason; } });
|
|
88
|
+
Object.defineProperty(exports, "mapFinishReasonToProvider", { enumerable: true, get: function () { return adapter_1.mapFinishReasonToProvider; } });
|
|
89
|
+
Object.defineProperty(exports, "toAISDKToolChoice", { enumerable: true, get: function () { return adapter_1.toAISDKToolChoice; } });
|
|
90
|
+
Object.defineProperty(exports, "createSimplePrompt", { enumerable: true, get: function () { return adapter_1.createSimplePrompt; } });
|
|
91
|
+
// Re-export middleware functions
|
|
92
|
+
var middleware_1 = require("./middleware");
|
|
93
|
+
Object.defineProperty(exports, "createAttributionMiddleware", { enumerable: true, get: function () { return middleware_1.createAttributionMiddleware; } });
|
|
94
|
+
Object.defineProperty(exports, "createLoggingMiddleware", { enumerable: true, get: function () { return middleware_1.createLoggingMiddleware; } });
|
|
95
|
+
Object.defineProperty(exports, "createTimeoutMiddleware", { enumerable: true, get: function () { return middleware_1.createTimeoutMiddleware; } });
|
|
96
|
+
Object.defineProperty(exports, "composeMiddleware", { enumerable: true, get: function () { return middleware_1.composeMiddleware; } });
|
|
97
|
+
Object.defineProperty(exports, "createStandardMiddleware", { enumerable: true, get: function () { return middleware_1.createStandardMiddleware; } });
|
|
98
|
+
Object.defineProperty(exports, "redactSensitiveData", { enumerable: true, get: function () { return middleware_1.redactSensitiveData; } });
|
|
99
|
+
// Lazy-loaded backend exports
|
|
100
|
+
// These use getters to avoid importing the backend module until needed
|
|
101
|
+
let _AISDKBackend = null;
|
|
102
|
+
let _createAISDKBackend = null;
|
|
103
|
+
/**
|
|
104
|
+
* Get the AISDKBackend class (lazy loaded)
|
|
105
|
+
*/
|
|
106
|
+
function getAISDKBackendClass() {
|
|
107
|
+
if (!_AISDKBackend) {
|
|
108
|
+
const backend = require('./backend');
|
|
109
|
+
_AISDKBackend = backend.AISDKBackend;
|
|
110
|
+
}
|
|
111
|
+
return _AISDKBackend;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create an AI SDK backend instance
|
|
115
|
+
*
|
|
116
|
+
* @param modelString - Model string in format "provider/model" or just "model"
|
|
117
|
+
* @param config - Optional configuration
|
|
118
|
+
* @returns AISDKBackend instance implementing LLMProvider
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const backend = createAISDKBackend('openai/gpt-4o');
|
|
123
|
+
* const backend = createAISDKBackend('anthropic/claude-3-5-sonnet');
|
|
124
|
+
* const backend = createAISDKBackend('google/gemini-2.0-flash');
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
function createAISDKBackend(modelString, config) {
|
|
128
|
+
if (!_createAISDKBackend) {
|
|
129
|
+
const backend = require('./backend');
|
|
130
|
+
_createAISDKBackend = backend.createAISDKBackend;
|
|
131
|
+
}
|
|
132
|
+
return _createAISDKBackend(modelString, config);
|
|
133
|
+
}
|
|
134
|
+
// Re-export the class for direct instantiation
|
|
135
|
+
var backend_1 = require("./backend");
|
|
136
|
+
Object.defineProperty(exports, "AISDKBackend", { enumerable: true, get: function () { return backend_1.AISDKBackend; } });
|
|
137
|
+
/**
|
|
138
|
+
* Register AI SDK providers with the praisonai-ts provider registry
|
|
139
|
+
* This allows using AI SDK providers via the standard createProvider() function
|
|
140
|
+
*
|
|
141
|
+
* @param customProviders - Optional map of custom provider factories
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { registerAISDKProviders, createProvider } from 'praisonai';
|
|
146
|
+
*
|
|
147
|
+
* // Register all AI SDK providers
|
|
148
|
+
* registerAISDKProviders();
|
|
149
|
+
*
|
|
150
|
+
* // Now you can use AI SDK providers via createProvider
|
|
151
|
+
* const provider = createProvider('aisdk:anthropic/claude-3-5-sonnet');
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function registerAISDKProviders(customProviders) {
|
|
155
|
+
// Register custom providers if provided
|
|
156
|
+
if (customProviders) {
|
|
157
|
+
const { registerCustomProvider } = require('./provider-map');
|
|
158
|
+
for (const [id, factory] of Object.entries(customProviders)) {
|
|
159
|
+
registerCustomProvider(id, factory);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Note: Integration with main provider registry is done in ../index.ts
|
|
163
|
+
// This function is mainly for registering custom AI SDK providers
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Check if AI SDK is available (installed)
|
|
167
|
+
*/
|
|
168
|
+
async function isAISDKAvailable() {
|
|
169
|
+
try {
|
|
170
|
+
// Use variable to prevent TypeScript from resolving at compile time
|
|
171
|
+
const moduleName = 'ai';
|
|
172
|
+
await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get AI SDK version if available
|
|
181
|
+
*/
|
|
182
|
+
async function getAISDKVersion() {
|
|
183
|
+
try {
|
|
184
|
+
// Use variable to prevent TypeScript from resolving at compile time
|
|
185
|
+
const moduleName = 'ai';
|
|
186
|
+
await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
187
|
+
// AI SDK doesn't export version directly, so we check package.json
|
|
188
|
+
try {
|
|
189
|
+
const pkgPath = 'ai/package.json';
|
|
190
|
+
const pkg = require(pkgPath);
|
|
191
|
+
return pkg.version;
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return 'installed';
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI SDK Middleware
|
|
3
|
+
*
|
|
4
|
+
* Provides middleware for injecting attribution context into AI SDK calls.
|
|
5
|
+
* Supports multi-agent safety with agent_id, run_id, trace_id, session_id.
|
|
6
|
+
*/
|
|
7
|
+
import type { AttributionContext, AISDKBackendConfig } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Middleware interface for AI SDK language models
|
|
10
|
+
* Compatible with AI SDK's LanguageModelMiddleware type
|
|
11
|
+
*/
|
|
12
|
+
export interface AISDKMiddleware {
|
|
13
|
+
transformParams?: (options: {
|
|
14
|
+
params: Record<string, unknown>;
|
|
15
|
+
type: 'generate' | 'stream';
|
|
16
|
+
model: unknown;
|
|
17
|
+
}) => Promise<Record<string, unknown>> | Record<string, unknown>;
|
|
18
|
+
wrapGenerate?: (options: {
|
|
19
|
+
doGenerate: () => Promise<unknown>;
|
|
20
|
+
doStream: () => Promise<unknown>;
|
|
21
|
+
params: Record<string, unknown>;
|
|
22
|
+
model: unknown;
|
|
23
|
+
}) => Promise<unknown>;
|
|
24
|
+
wrapStream?: (options: {
|
|
25
|
+
doGenerate: () => Promise<unknown>;
|
|
26
|
+
doStream: () => Promise<unknown>;
|
|
27
|
+
params: Record<string, unknown>;
|
|
28
|
+
model: unknown;
|
|
29
|
+
}) => Promise<unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create attribution middleware that injects agent context into requests
|
|
33
|
+
*
|
|
34
|
+
* Injects:
|
|
35
|
+
* - Headers: X-Agent-Id, X-Run-Id, X-Trace-Id, X-Session-Id
|
|
36
|
+
* - Provider options metadata where supported
|
|
37
|
+
*/
|
|
38
|
+
export declare function createAttributionMiddleware(ctx: AttributionContext): AISDKMiddleware;
|
|
39
|
+
/**
|
|
40
|
+
* Create logging middleware for debug purposes
|
|
41
|
+
* Only logs when debugLogging is enabled
|
|
42
|
+
*/
|
|
43
|
+
export declare function createLoggingMiddleware(config: AISDKBackendConfig): AISDKMiddleware;
|
|
44
|
+
/**
|
|
45
|
+
* Create timeout middleware that wraps requests with AbortController
|
|
46
|
+
*/
|
|
47
|
+
export declare function createTimeoutMiddleware(timeoutMs: number): AISDKMiddleware;
|
|
48
|
+
/**
|
|
49
|
+
* Compose multiple middlewares into one
|
|
50
|
+
* Middlewares are applied in order (first transforms first, last wraps innermost)
|
|
51
|
+
*/
|
|
52
|
+
export declare function composeMiddleware(...middlewares: AISDKMiddleware[]): AISDKMiddleware;
|
|
53
|
+
/**
|
|
54
|
+
* Redact sensitive data from objects for safe logging
|
|
55
|
+
*/
|
|
56
|
+
export declare function redactSensitiveData(obj: unknown): unknown;
|
|
57
|
+
/**
|
|
58
|
+
* Create all standard middlewares for the AI SDK backend
|
|
59
|
+
*/
|
|
60
|
+
export declare function createStandardMiddleware(config: AISDKBackendConfig, attribution?: AttributionContext): AISDKMiddleware;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AI SDK Middleware
|
|
4
|
+
*
|
|
5
|
+
* Provides middleware for injecting attribution context into AI SDK calls.
|
|
6
|
+
* Supports multi-agent safety with agent_id, run_id, trace_id, session_id.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createAttributionMiddleware = createAttributionMiddleware;
|
|
10
|
+
exports.createLoggingMiddleware = createLoggingMiddleware;
|
|
11
|
+
exports.createTimeoutMiddleware = createTimeoutMiddleware;
|
|
12
|
+
exports.composeMiddleware = composeMiddleware;
|
|
13
|
+
exports.redactSensitiveData = redactSensitiveData;
|
|
14
|
+
exports.createStandardMiddleware = createStandardMiddleware;
|
|
15
|
+
/**
|
|
16
|
+
* Create attribution middleware that injects agent context into requests
|
|
17
|
+
*
|
|
18
|
+
* Injects:
|
|
19
|
+
* - Headers: X-Agent-Id, X-Run-Id, X-Trace-Id, X-Session-Id
|
|
20
|
+
* - Provider options metadata where supported
|
|
21
|
+
*/
|
|
22
|
+
function createAttributionMiddleware(ctx) {
|
|
23
|
+
return {
|
|
24
|
+
transformParams: async ({ params }) => {
|
|
25
|
+
// Build attribution headers
|
|
26
|
+
const attributionHeaders = {};
|
|
27
|
+
if (ctx.agentId) {
|
|
28
|
+
attributionHeaders['X-Agent-Id'] = ctx.agentId;
|
|
29
|
+
}
|
|
30
|
+
if (ctx.runId) {
|
|
31
|
+
attributionHeaders['X-Run-Id'] = ctx.runId;
|
|
32
|
+
}
|
|
33
|
+
if (ctx.traceId) {
|
|
34
|
+
attributionHeaders['X-Trace-Id'] = ctx.traceId;
|
|
35
|
+
}
|
|
36
|
+
if (ctx.sessionId) {
|
|
37
|
+
attributionHeaders['X-Session-Id'] = ctx.sessionId;
|
|
38
|
+
}
|
|
39
|
+
if (ctx.parentSpanId) {
|
|
40
|
+
attributionHeaders['X-Parent-Span-Id'] = ctx.parentSpanId;
|
|
41
|
+
}
|
|
42
|
+
// Merge with existing headers
|
|
43
|
+
const existingHeaders = params.headers || {};
|
|
44
|
+
const mergedHeaders = {
|
|
45
|
+
...existingHeaders,
|
|
46
|
+
...attributionHeaders
|
|
47
|
+
};
|
|
48
|
+
// Build provider options metadata
|
|
49
|
+
const attributionMetadata = {};
|
|
50
|
+
if (ctx.agentId)
|
|
51
|
+
attributionMetadata.agentId = ctx.agentId;
|
|
52
|
+
if (ctx.runId)
|
|
53
|
+
attributionMetadata.runId = ctx.runId;
|
|
54
|
+
if (ctx.traceId)
|
|
55
|
+
attributionMetadata.traceId = ctx.traceId;
|
|
56
|
+
if (ctx.sessionId)
|
|
57
|
+
attributionMetadata.sessionId = ctx.sessionId;
|
|
58
|
+
// Merge with existing provider options
|
|
59
|
+
const existingProviderOptions = params.providerOptions || {};
|
|
60
|
+
const existingMetadata = existingProviderOptions.metadata || {};
|
|
61
|
+
const mergedProviderOptions = {
|
|
62
|
+
...existingProviderOptions,
|
|
63
|
+
metadata: {
|
|
64
|
+
...existingMetadata,
|
|
65
|
+
...attributionMetadata
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
...params,
|
|
70
|
+
headers: mergedHeaders,
|
|
71
|
+
providerOptions: mergedProviderOptions
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create logging middleware for debug purposes
|
|
78
|
+
* Only logs when debugLogging is enabled
|
|
79
|
+
*/
|
|
80
|
+
function createLoggingMiddleware(config) {
|
|
81
|
+
if (!config.debugLogging) {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
transformParams: async ({ params, type }) => {
|
|
86
|
+
const safeParams = config.redactLogs !== false
|
|
87
|
+
? redactSensitiveData(params)
|
|
88
|
+
: params;
|
|
89
|
+
console.log(`[AI SDK] ${type} request:`, JSON.stringify(safeParams, null, 2));
|
|
90
|
+
return params;
|
|
91
|
+
},
|
|
92
|
+
wrapGenerate: async ({ doGenerate, params }) => {
|
|
93
|
+
const startTime = Date.now();
|
|
94
|
+
try {
|
|
95
|
+
const result = await doGenerate();
|
|
96
|
+
const duration = Date.now() - startTime;
|
|
97
|
+
console.log(`[AI SDK] generate completed in ${duration}ms`);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
const duration = Date.now() - startTime;
|
|
102
|
+
console.error(`[AI SDK] generate failed after ${duration}ms:`, error);
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
wrapStream: async ({ doStream, params }) => {
|
|
107
|
+
const startTime = Date.now();
|
|
108
|
+
console.log(`[AI SDK] stream started`);
|
|
109
|
+
try {
|
|
110
|
+
const result = await doStream();
|
|
111
|
+
const duration = Date.now() - startTime;
|
|
112
|
+
console.log(`[AI SDK] stream setup completed in ${duration}ms`);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const duration = Date.now() - startTime;
|
|
117
|
+
console.error(`[AI SDK] stream failed after ${duration}ms:`, error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Create timeout middleware that wraps requests with AbortController
|
|
125
|
+
*/
|
|
126
|
+
function createTimeoutMiddleware(timeoutMs) {
|
|
127
|
+
return {
|
|
128
|
+
transformParams: async ({ params }) => {
|
|
129
|
+
// If there's already an abort signal, don't override it
|
|
130
|
+
if (params.abortSignal) {
|
|
131
|
+
return params;
|
|
132
|
+
}
|
|
133
|
+
const controller = new AbortController();
|
|
134
|
+
const timeoutId = setTimeout(() => {
|
|
135
|
+
controller.abort(new Error(`Request timed out after ${timeoutMs}ms`));
|
|
136
|
+
}, timeoutMs);
|
|
137
|
+
// Store timeout ID for cleanup (attached to signal)
|
|
138
|
+
controller.signal.__timeoutId = timeoutId;
|
|
139
|
+
return {
|
|
140
|
+
...params,
|
|
141
|
+
abortSignal: controller.signal
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Compose multiple middlewares into one
|
|
148
|
+
* Middlewares are applied in order (first transforms first, last wraps innermost)
|
|
149
|
+
*/
|
|
150
|
+
function composeMiddleware(...middlewares) {
|
|
151
|
+
const validMiddlewares = middlewares.filter(m => m && Object.keys(m).length > 0);
|
|
152
|
+
if (validMiddlewares.length === 0) {
|
|
153
|
+
return {};
|
|
154
|
+
}
|
|
155
|
+
if (validMiddlewares.length === 1) {
|
|
156
|
+
return validMiddlewares[0];
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
transformParams: async (options) => {
|
|
160
|
+
let params = options.params;
|
|
161
|
+
for (const middleware of validMiddlewares) {
|
|
162
|
+
if (middleware.transformParams) {
|
|
163
|
+
params = await middleware.transformParams({
|
|
164
|
+
...options,
|
|
165
|
+
params
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return params;
|
|
170
|
+
},
|
|
171
|
+
wrapGenerate: async (options) => {
|
|
172
|
+
// Build nested wrapper from inside out
|
|
173
|
+
let doGenerate = options.doGenerate;
|
|
174
|
+
for (let i = validMiddlewares.length - 1; i >= 0; i--) {
|
|
175
|
+
const middleware = validMiddlewares[i];
|
|
176
|
+
if (middleware.wrapGenerate) {
|
|
177
|
+
const currentDoGenerate = doGenerate;
|
|
178
|
+
const currentMiddleware = middleware;
|
|
179
|
+
doGenerate = () => currentMiddleware.wrapGenerate({
|
|
180
|
+
...options,
|
|
181
|
+
doGenerate: currentDoGenerate
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return doGenerate();
|
|
186
|
+
},
|
|
187
|
+
wrapStream: async (options) => {
|
|
188
|
+
// Build nested wrapper from inside out
|
|
189
|
+
let doStream = options.doStream;
|
|
190
|
+
for (let i = validMiddlewares.length - 1; i >= 0; i--) {
|
|
191
|
+
const middleware = validMiddlewares[i];
|
|
192
|
+
if (middleware.wrapStream) {
|
|
193
|
+
const currentDoStream = doStream;
|
|
194
|
+
const currentMiddleware = middleware;
|
|
195
|
+
doStream = () => currentMiddleware.wrapStream({
|
|
196
|
+
...options,
|
|
197
|
+
doStream: currentDoStream
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return doStream();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Redact sensitive data from objects for safe logging
|
|
207
|
+
*/
|
|
208
|
+
function redactSensitiveData(obj) {
|
|
209
|
+
if (obj === null || obj === undefined) {
|
|
210
|
+
return obj;
|
|
211
|
+
}
|
|
212
|
+
if (typeof obj !== 'object') {
|
|
213
|
+
return obj;
|
|
214
|
+
}
|
|
215
|
+
if (Array.isArray(obj)) {
|
|
216
|
+
return obj.map(redactSensitiveData);
|
|
217
|
+
}
|
|
218
|
+
const result = {};
|
|
219
|
+
const sensitiveKeys = [
|
|
220
|
+
'apiKey', 'api_key', 'apikey',
|
|
221
|
+
'token', 'secret', 'password',
|
|
222
|
+
'authorization', 'auth',
|
|
223
|
+
'key', 'credential', 'credentials'
|
|
224
|
+
];
|
|
225
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
226
|
+
const lowerKey = key.toLowerCase();
|
|
227
|
+
if (sensitiveKeys.some(sk => lowerKey.includes(sk))) {
|
|
228
|
+
if (typeof value === 'string' && value.length > 4) {
|
|
229
|
+
result[key] = value.slice(0, 4) + '****';
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
result[key] = '****';
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else if (typeof value === 'object') {
|
|
236
|
+
result[key] = redactSensitiveData(value);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
result[key] = value;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return result;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create all standard middlewares for the AI SDK backend
|
|
246
|
+
*/
|
|
247
|
+
function createStandardMiddleware(config, attribution) {
|
|
248
|
+
const middlewares = [];
|
|
249
|
+
// Attribution middleware (if context provided)
|
|
250
|
+
if (attribution && Object.keys(attribution).length > 0) {
|
|
251
|
+
middlewares.push(createAttributionMiddleware(attribution));
|
|
252
|
+
}
|
|
253
|
+
// Timeout middleware
|
|
254
|
+
if (config.timeout && config.timeout > 0) {
|
|
255
|
+
middlewares.push(createTimeoutMiddleware(config.timeout));
|
|
256
|
+
}
|
|
257
|
+
// Logging middleware (only if debug enabled)
|
|
258
|
+
if (config.debugLogging) {
|
|
259
|
+
middlewares.push(createLoggingMiddleware(config));
|
|
260
|
+
}
|
|
261
|
+
return composeMiddleware(...middlewares);
|
|
262
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI SDK Provider Map
|
|
3
|
+
*
|
|
4
|
+
* Maps model strings to AI SDK providers with lazy loading.
|
|
5
|
+
* Supports formats: "provider/model" or "model" (uses default provider)
|
|
6
|
+
*/
|
|
7
|
+
import { AISDKProviderOptions } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Parsed model string result
|
|
10
|
+
*/
|
|
11
|
+
export interface ParsedModel {
|
|
12
|
+
providerId: string;
|
|
13
|
+
modelId: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Provider factory function type
|
|
17
|
+
*/
|
|
18
|
+
export type ProviderFactory = (options?: AISDKProviderOptions) => unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Parse a model string into provider and model ID
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* parseModelString("openai/gpt-4o") // { providerId: "openai", modelId: "gpt-4o" }
|
|
24
|
+
* parseModelString("gpt-4o-mini") // { providerId: "openai", modelId: "gpt-4o-mini" }
|
|
25
|
+
* parseModelString("claude-3-5-sonnet") // { providerId: "anthropic", modelId: "claude-3-5-sonnet" }
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseModelString(model: string, defaultProvider?: string): ParsedModel;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve provider alias to canonical name
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveProviderAlias(providerId: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a provider is supported
|
|
34
|
+
*/
|
|
35
|
+
export declare function isProviderSupported(providerId: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Get the package name for a provider
|
|
38
|
+
*/
|
|
39
|
+
export declare function getProviderPackage(providerId: string): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Get the environment variable key for a provider's API key
|
|
42
|
+
*/
|
|
43
|
+
export declare function getProviderEnvKey(providerId: string): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* List all supported providers
|
|
46
|
+
*/
|
|
47
|
+
export declare function listSupportedProviders(): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Register a custom provider factory
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* registerCustomProvider('my-provider', (options) => createMyProvider(options));
|
|
53
|
+
*/
|
|
54
|
+
export declare function registerCustomProvider(providerId: string, factory: ProviderFactory): void;
|
|
55
|
+
/**
|
|
56
|
+
* Unregister a custom provider
|
|
57
|
+
*/
|
|
58
|
+
export declare function unregisterCustomProvider(providerId: string): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Get a custom provider factory
|
|
61
|
+
*/
|
|
62
|
+
export declare function getCustomProvider(providerId: string): ProviderFactory | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Dynamically import and create an AI SDK provider
|
|
65
|
+
* Uses lazy loading to avoid importing AI SDK packages until needed
|
|
66
|
+
*/
|
|
67
|
+
export declare function createAISDKProvider(providerId: string, options?: AISDKProviderOptions): Promise<unknown>;
|
|
68
|
+
/**
|
|
69
|
+
* Validate that a provider has the required API key
|
|
70
|
+
*/
|
|
71
|
+
export declare function validateProviderApiKey(providerId: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get missing API key message for a provider
|
|
74
|
+
*/
|
|
75
|
+
export declare function getMissingApiKeyMessage(providerId: string): string;
|