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,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Reranker - Rerank search results for improved relevance
|
|
4
|
+
* Inspired by mastra's rerank module
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LLMReranker = exports.CrossEncoderReranker = exports.CohereReranker = exports.BaseReranker = void 0;
|
|
8
|
+
exports.createCohereReranker = createCohereReranker;
|
|
9
|
+
exports.createCrossEncoderReranker = createCrossEncoderReranker;
|
|
10
|
+
exports.createLLMReranker = createLLMReranker;
|
|
11
|
+
/**
|
|
12
|
+
* Abstract base class for rerankers
|
|
13
|
+
*/
|
|
14
|
+
class BaseReranker {
|
|
15
|
+
constructor(name) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.BaseReranker = BaseReranker;
|
|
20
|
+
/**
|
|
21
|
+
* Cohere Reranker - Uses Cohere's rerank API
|
|
22
|
+
*/
|
|
23
|
+
class CohereReranker extends BaseReranker {
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
super('CohereReranker');
|
|
26
|
+
this.apiKey = config.apiKey || process.env.COHERE_API_KEY || '';
|
|
27
|
+
this.model = config.model || 'rerank-english-v3.0';
|
|
28
|
+
}
|
|
29
|
+
async rerank(query, documents, config) {
|
|
30
|
+
if (!this.apiKey) {
|
|
31
|
+
throw new Error('Cohere API key required for reranking');
|
|
32
|
+
}
|
|
33
|
+
const response = await fetch('https://api.cohere.ai/v1/rerank', {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: {
|
|
36
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
37
|
+
'Content-Type': 'application/json'
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
model: config?.model || this.model,
|
|
41
|
+
query,
|
|
42
|
+
documents: documents.map(d => d.content),
|
|
43
|
+
top_n: config?.topK || documents.length,
|
|
44
|
+
return_documents: true
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const error = await response.text();
|
|
49
|
+
throw new Error(`Cohere rerank error: ${response.status} - ${error}`);
|
|
50
|
+
}
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
const threshold = config?.threshold || 0;
|
|
53
|
+
return (data.results || [])
|
|
54
|
+
.filter((r) => r.relevance_score >= threshold)
|
|
55
|
+
.map((r, newRank) => ({
|
|
56
|
+
id: documents[r.index].id,
|
|
57
|
+
score: r.relevance_score,
|
|
58
|
+
content: documents[r.index].content,
|
|
59
|
+
metadata: documents[r.index].metadata,
|
|
60
|
+
originalRank: r.index,
|
|
61
|
+
newRank
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.CohereReranker = CohereReranker;
|
|
66
|
+
/**
|
|
67
|
+
* Cross-Encoder Reranker - Uses sentence similarity for reranking
|
|
68
|
+
* This is a simple implementation using cosine similarity
|
|
69
|
+
*/
|
|
70
|
+
class CrossEncoderReranker extends BaseReranker {
|
|
71
|
+
constructor(config = {}) {
|
|
72
|
+
super('CrossEncoderReranker');
|
|
73
|
+
this.embedFn = config.embedFn;
|
|
74
|
+
}
|
|
75
|
+
async rerank(query, documents, config) {
|
|
76
|
+
if (!this.embedFn) {
|
|
77
|
+
// Fallback to simple keyword matching
|
|
78
|
+
return this.keywordRerank(query, documents, config);
|
|
79
|
+
}
|
|
80
|
+
// Get embeddings for query and all documents
|
|
81
|
+
const texts = [query, ...documents.map(d => d.content)];
|
|
82
|
+
const embeddings = await this.embedFn(texts);
|
|
83
|
+
const queryEmbedding = embeddings[0];
|
|
84
|
+
const docEmbeddings = embeddings.slice(1);
|
|
85
|
+
// Calculate similarity scores
|
|
86
|
+
const scores = docEmbeddings.map((docEmb, i) => ({
|
|
87
|
+
index: i,
|
|
88
|
+
score: this.cosineSimilarity(queryEmbedding, docEmb)
|
|
89
|
+
}));
|
|
90
|
+
// Sort by score descending
|
|
91
|
+
scores.sort((a, b) => b.score - a.score);
|
|
92
|
+
const threshold = config?.threshold || 0;
|
|
93
|
+
const topK = config?.topK || documents.length;
|
|
94
|
+
return scores
|
|
95
|
+
.filter(s => s.score >= threshold)
|
|
96
|
+
.slice(0, topK)
|
|
97
|
+
.map((s, newRank) => ({
|
|
98
|
+
id: documents[s.index].id,
|
|
99
|
+
score: s.score,
|
|
100
|
+
content: documents[s.index].content,
|
|
101
|
+
metadata: documents[s.index].metadata,
|
|
102
|
+
originalRank: s.index,
|
|
103
|
+
newRank
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
keywordRerank(query, documents, config) {
|
|
107
|
+
const queryTerms = query.toLowerCase().split(/\s+/);
|
|
108
|
+
const scores = documents.map((doc, i) => {
|
|
109
|
+
const content = doc.content.toLowerCase();
|
|
110
|
+
let score = 0;
|
|
111
|
+
for (const term of queryTerms) {
|
|
112
|
+
if (content.includes(term)) {
|
|
113
|
+
score += 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Normalize by query length
|
|
117
|
+
score = score / queryTerms.length;
|
|
118
|
+
return { index: i, score };
|
|
119
|
+
});
|
|
120
|
+
scores.sort((a, b) => b.score - a.score);
|
|
121
|
+
const threshold = config?.threshold || 0;
|
|
122
|
+
const topK = config?.topK || documents.length;
|
|
123
|
+
return scores
|
|
124
|
+
.filter(s => s.score >= threshold)
|
|
125
|
+
.slice(0, topK)
|
|
126
|
+
.map((s, newRank) => ({
|
|
127
|
+
id: documents[s.index].id,
|
|
128
|
+
score: s.score,
|
|
129
|
+
content: documents[s.index].content,
|
|
130
|
+
metadata: documents[s.index].metadata,
|
|
131
|
+
originalRank: s.index,
|
|
132
|
+
newRank
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
cosineSimilarity(a, b) {
|
|
136
|
+
const dot = a.reduce((sum, x, i) => sum + x * b[i], 0);
|
|
137
|
+
const normA = Math.sqrt(a.reduce((sum, x) => sum + x * x, 0));
|
|
138
|
+
const normB = Math.sqrt(b.reduce((sum, x) => sum + x * x, 0));
|
|
139
|
+
return dot / (normA * normB);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.CrossEncoderReranker = CrossEncoderReranker;
|
|
143
|
+
/**
|
|
144
|
+
* LLM Reranker - Uses an LLM to score relevance
|
|
145
|
+
*/
|
|
146
|
+
class LLMReranker extends BaseReranker {
|
|
147
|
+
constructor(config) {
|
|
148
|
+
super('LLMReranker');
|
|
149
|
+
this.generateFn = config.generateFn;
|
|
150
|
+
}
|
|
151
|
+
async rerank(query, documents, config) {
|
|
152
|
+
const scores = [];
|
|
153
|
+
// Score each document
|
|
154
|
+
for (let i = 0; i < documents.length; i++) {
|
|
155
|
+
const doc = documents[i];
|
|
156
|
+
const prompt = `Rate the relevance of the following document to the query on a scale of 0 to 10.
|
|
157
|
+
Query: ${query}
|
|
158
|
+
Document: ${doc.content.slice(0, 500)}
|
|
159
|
+
|
|
160
|
+
Respond with only a number between 0 and 10.`;
|
|
161
|
+
try {
|
|
162
|
+
const response = await this.generateFn(prompt);
|
|
163
|
+
const score = parseFloat(response.trim()) / 10;
|
|
164
|
+
scores.push({ index: i, score: isNaN(score) ? 0 : Math.min(1, Math.max(0, score)) });
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
scores.push({ index: i, score: 0 });
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
scores.sort((a, b) => b.score - a.score);
|
|
171
|
+
const threshold = config?.threshold || 0;
|
|
172
|
+
const topK = config?.topK || documents.length;
|
|
173
|
+
return scores
|
|
174
|
+
.filter(s => s.score >= threshold)
|
|
175
|
+
.slice(0, topK)
|
|
176
|
+
.map((s, newRank) => ({
|
|
177
|
+
id: documents[s.index].id,
|
|
178
|
+
score: s.score,
|
|
179
|
+
content: documents[s.index].content,
|
|
180
|
+
metadata: documents[s.index].metadata,
|
|
181
|
+
originalRank: s.index,
|
|
182
|
+
newRank
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.LLMReranker = LLMReranker;
|
|
187
|
+
// Factory functions
|
|
188
|
+
function createCohereReranker(config) {
|
|
189
|
+
return new CohereReranker(config);
|
|
190
|
+
}
|
|
191
|
+
function createCrossEncoderReranker(config) {
|
|
192
|
+
return new CrossEncoderReranker(config);
|
|
193
|
+
}
|
|
194
|
+
function createLLMReranker(config) {
|
|
195
|
+
return new LLMReranker(config);
|
|
196
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend Resolver - Unified LLM backend resolution with AI SDK preference
|
|
3
|
+
*
|
|
4
|
+
* Resolution order:
|
|
5
|
+
* 1. AI SDK backend (if installed and enabled)
|
|
6
|
+
* 2. Native provider registry (OpenAI, Anthropic, Google)
|
|
7
|
+
* 3. Error with actionable guidance
|
|
8
|
+
*
|
|
9
|
+
* Environment variables:
|
|
10
|
+
* - PRAISONAI_BACKEND: 'ai-sdk' | 'native' | 'auto' (default: 'auto')
|
|
11
|
+
*/
|
|
12
|
+
import type { LLMProvider, ProviderConfig } from './providers/types';
|
|
13
|
+
export type BackendSource = 'ai-sdk' | 'native' | 'custom' | 'legacy';
|
|
14
|
+
export interface BackendResolutionResult {
|
|
15
|
+
provider: LLMProvider;
|
|
16
|
+
source: BackendSource;
|
|
17
|
+
providerId: string;
|
|
18
|
+
modelId: string;
|
|
19
|
+
warnings?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface ResolveBackendOptions {
|
|
22
|
+
/** Force a specific backend: 'ai-sdk' | 'native' | 'auto' (default: 'auto') */
|
|
23
|
+
backend?: 'ai-sdk' | 'native' | 'auto';
|
|
24
|
+
/** Provider configuration (API keys, timeouts, etc.) */
|
|
25
|
+
config?: ProviderConfig;
|
|
26
|
+
/** Attribution context for multi-agent tracing */
|
|
27
|
+
attribution?: {
|
|
28
|
+
agentId?: string;
|
|
29
|
+
runId?: string;
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if AI SDK is available (installed)
|
|
35
|
+
* Result is cached after first check
|
|
36
|
+
*/
|
|
37
|
+
export declare function isAISDKAvailable(): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Reset the AI SDK availability cache (for testing)
|
|
40
|
+
*/
|
|
41
|
+
export declare function resetAISDKAvailabilityCache(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get the preferred backend from environment
|
|
44
|
+
*/
|
|
45
|
+
export declare function getPreferredBackend(): 'ai-sdk' | 'native' | 'auto';
|
|
46
|
+
/**
|
|
47
|
+
* Parse model string into provider and model ID
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseModelString(model: string): {
|
|
50
|
+
providerId: string;
|
|
51
|
+
modelId: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the best available backend for a model
|
|
55
|
+
*
|
|
56
|
+
* @param modelString - Model string in format "provider/model" or just "model"
|
|
57
|
+
* @param options - Resolution options
|
|
58
|
+
* @returns Backend resolution result with provider instance
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const { provider, source } = await resolveBackend('openai/gpt-4o-mini');
|
|
63
|
+
* const result = await provider.generateText({ messages: [...] });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveBackend(modelString: string, options?: ResolveBackendOptions): Promise<BackendResolutionResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Resolve backend synchronously using cached availability
|
|
69
|
+
* Only works if isAISDKAvailable() has been called before
|
|
70
|
+
* Falls back to native if cache is not populated
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveBackendSync(modelString: string, options?: ResolveBackendOptions): BackendResolutionResult;
|
|
73
|
+
/**
|
|
74
|
+
* Get default model string
|
|
75
|
+
*/
|
|
76
|
+
export declare function getDefaultModel(): string;
|
|
77
|
+
export type { LLMProvider, ProviderConfig };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Backend Resolver - Unified LLM backend resolution with AI SDK preference
|
|
4
|
+
*
|
|
5
|
+
* Resolution order:
|
|
6
|
+
* 1. AI SDK backend (if installed and enabled)
|
|
7
|
+
* 2. Native provider registry (OpenAI, Anthropic, Google)
|
|
8
|
+
* 3. Error with actionable guidance
|
|
9
|
+
*
|
|
10
|
+
* Environment variables:
|
|
11
|
+
* - PRAISONAI_BACKEND: 'ai-sdk' | 'native' | 'auto' (default: 'auto')
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.isAISDKAvailable = isAISDKAvailable;
|
|
48
|
+
exports.resetAISDKAvailabilityCache = resetAISDKAvailabilityCache;
|
|
49
|
+
exports.getPreferredBackend = getPreferredBackend;
|
|
50
|
+
exports.parseModelString = parseModelString;
|
|
51
|
+
exports.resolveBackend = resolveBackend;
|
|
52
|
+
exports.resolveBackendSync = resolveBackendSync;
|
|
53
|
+
exports.getDefaultModel = getDefaultModel;
|
|
54
|
+
// Cached availability check
|
|
55
|
+
let _aiSdkAvailable = null;
|
|
56
|
+
let _aiSdkCheckPromise = null;
|
|
57
|
+
/**
|
|
58
|
+
* Check if AI SDK is available (installed)
|
|
59
|
+
* Result is cached after first check
|
|
60
|
+
*/
|
|
61
|
+
async function isAISDKAvailable() {
|
|
62
|
+
if (_aiSdkAvailable !== null) {
|
|
63
|
+
return _aiSdkAvailable;
|
|
64
|
+
}
|
|
65
|
+
if (_aiSdkCheckPromise) {
|
|
66
|
+
return _aiSdkCheckPromise;
|
|
67
|
+
}
|
|
68
|
+
_aiSdkCheckPromise = (async () => {
|
|
69
|
+
try {
|
|
70
|
+
// Dynamic import to avoid loading if not needed
|
|
71
|
+
const moduleName = 'ai';
|
|
72
|
+
await Promise.resolve(`${moduleName}`).then(s => __importStar(require(s)));
|
|
73
|
+
_aiSdkAvailable = true;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
_aiSdkAvailable = false;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
})();
|
|
81
|
+
return _aiSdkCheckPromise;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Reset the AI SDK availability cache (for testing)
|
|
85
|
+
*/
|
|
86
|
+
function resetAISDKAvailabilityCache() {
|
|
87
|
+
_aiSdkAvailable = null;
|
|
88
|
+
_aiSdkCheckPromise = null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Get the preferred backend from environment
|
|
92
|
+
*/
|
|
93
|
+
function getPreferredBackend() {
|
|
94
|
+
const env = process.env.PRAISONAI_BACKEND?.toLowerCase();
|
|
95
|
+
if (env === 'ai-sdk' || env === 'aisdk')
|
|
96
|
+
return 'ai-sdk';
|
|
97
|
+
if (env === 'native' || env === 'legacy')
|
|
98
|
+
return 'native';
|
|
99
|
+
return 'auto';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Parse model string into provider and model ID
|
|
103
|
+
*/
|
|
104
|
+
function parseModelString(model) {
|
|
105
|
+
if (model.includes('/')) {
|
|
106
|
+
const [providerId, ...rest] = model.split('/');
|
|
107
|
+
return { providerId: providerId.toLowerCase(), modelId: rest.join('/') };
|
|
108
|
+
}
|
|
109
|
+
// Default to OpenAI for common model prefixes
|
|
110
|
+
if (model.startsWith('gpt-') || model.startsWith('o1') || model.startsWith('o3')) {
|
|
111
|
+
return { providerId: 'openai', modelId: model };
|
|
112
|
+
}
|
|
113
|
+
if (model.startsWith('claude-')) {
|
|
114
|
+
return { providerId: 'anthropic', modelId: model };
|
|
115
|
+
}
|
|
116
|
+
if (model.startsWith('gemini-')) {
|
|
117
|
+
return { providerId: 'google', modelId: model };
|
|
118
|
+
}
|
|
119
|
+
// Default to OpenAI
|
|
120
|
+
return { providerId: 'openai', modelId: model };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resolve the best available backend for a model
|
|
124
|
+
*
|
|
125
|
+
* @param modelString - Model string in format "provider/model" or just "model"
|
|
126
|
+
* @param options - Resolution options
|
|
127
|
+
* @returns Backend resolution result with provider instance
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const { provider, source } = await resolveBackend('openai/gpt-4o-mini');
|
|
132
|
+
* const result = await provider.generateText({ messages: [...] });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
async function resolveBackend(modelString, options = {}) {
|
|
136
|
+
const { providerId, modelId } = parseModelString(modelString);
|
|
137
|
+
const preferredBackend = options.backend || getPreferredBackend();
|
|
138
|
+
const warnings = [];
|
|
139
|
+
// Try AI SDK first if preferred or auto
|
|
140
|
+
if (preferredBackend === 'ai-sdk' || preferredBackend === 'auto') {
|
|
141
|
+
const aiSdkAvailable = await isAISDKAvailable();
|
|
142
|
+
if (aiSdkAvailable) {
|
|
143
|
+
try {
|
|
144
|
+
// Lazy import AI SDK backend
|
|
145
|
+
const { createAISDKBackend } = await Promise.resolve().then(() => __importStar(require('./providers/ai-sdk')));
|
|
146
|
+
const backend = createAISDKBackend(modelString, {
|
|
147
|
+
...options.config,
|
|
148
|
+
attribution: options.attribution ? {
|
|
149
|
+
agentId: options.attribution.agentId,
|
|
150
|
+
runId: options.attribution.runId,
|
|
151
|
+
sessionId: options.attribution.sessionId,
|
|
152
|
+
} : undefined,
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
provider: backend,
|
|
156
|
+
source: 'ai-sdk',
|
|
157
|
+
providerId,
|
|
158
|
+
modelId,
|
|
159
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (preferredBackend === 'ai-sdk') {
|
|
164
|
+
// User explicitly requested AI SDK, throw error
|
|
165
|
+
throw new Error(`AI SDK backend failed for '${modelString}': ${error.message}. ` +
|
|
166
|
+
`Set PRAISONAI_BACKEND=native to use native providers.`);
|
|
167
|
+
}
|
|
168
|
+
// Auto mode: fall through to native
|
|
169
|
+
warnings.push(`AI SDK failed: ${error.message}, falling back to native provider`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (preferredBackend === 'ai-sdk') {
|
|
173
|
+
throw new Error(`AI SDK is not installed but PRAISONAI_BACKEND=ai-sdk is set. ` +
|
|
174
|
+
`Install with: npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Try native provider registry
|
|
178
|
+
try {
|
|
179
|
+
const { createProvider } = await Promise.resolve().then(() => __importStar(require('./providers')));
|
|
180
|
+
const provider = createProvider(modelString, options.config);
|
|
181
|
+
return {
|
|
182
|
+
provider,
|
|
183
|
+
source: 'native',
|
|
184
|
+
providerId,
|
|
185
|
+
modelId,
|
|
186
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
throw new Error(`Cannot resolve backend for '${modelString}'. ` +
|
|
191
|
+
`Neither AI SDK nor native provider available. ` +
|
|
192
|
+
`Install AI SDK: npm install ai @ai-sdk/${providerId} ` +
|
|
193
|
+
`or check your provider configuration. ` +
|
|
194
|
+
`Original error: ${error.message}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Resolve backend synchronously using cached availability
|
|
199
|
+
* Only works if isAISDKAvailable() has been called before
|
|
200
|
+
* Falls back to native if cache is not populated
|
|
201
|
+
*/
|
|
202
|
+
function resolveBackendSync(modelString, options = {}) {
|
|
203
|
+
const { providerId, modelId } = parseModelString(modelString);
|
|
204
|
+
const preferredBackend = options.backend || getPreferredBackend();
|
|
205
|
+
// If AI SDK availability is cached and available, try it first
|
|
206
|
+
if (_aiSdkAvailable === true && (preferredBackend === 'ai-sdk' || preferredBackend === 'auto')) {
|
|
207
|
+
try {
|
|
208
|
+
// This will throw if AI SDK module is not already loaded
|
|
209
|
+
const aiSdk = require('./providers/ai-sdk');
|
|
210
|
+
const backend = aiSdk.createAISDKBackend(modelString, {
|
|
211
|
+
...options.config,
|
|
212
|
+
attribution: options.attribution,
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
provider: backend,
|
|
216
|
+
source: 'ai-sdk',
|
|
217
|
+
providerId,
|
|
218
|
+
modelId,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// Fall through to native
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Use native provider
|
|
226
|
+
const { createProvider } = require('./providers');
|
|
227
|
+
const provider = createProvider(modelString, options.config);
|
|
228
|
+
return {
|
|
229
|
+
provider,
|
|
230
|
+
source: 'native',
|
|
231
|
+
providerId,
|
|
232
|
+
modelId,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Get default model string
|
|
237
|
+
*/
|
|
238
|
+
function getDefaultModel() {
|
|
239
|
+
return process.env.OPENAI_MODEL_NAME ||
|
|
240
|
+
process.env.PRAISONAI_MODEL ||
|
|
241
|
+
'openai/gpt-4o-mini';
|
|
242
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embeddings - AI SDK-backed embedding utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides embedding functionality with AI SDK preference and native fallback.
|
|
5
|
+
* Integrates with existing EmbeddingProvider interface in knowledge/rag.ts and memory/memory.ts
|
|
6
|
+
*/
|
|
7
|
+
import type { EmbeddingProvider } from '../knowledge/rag';
|
|
8
|
+
export interface EmbeddingOptions {
|
|
9
|
+
/** Model to use for embeddings (default: text-embedding-3-small) */
|
|
10
|
+
model?: string;
|
|
11
|
+
/** Provider to use (default: openai) */
|
|
12
|
+
provider?: string;
|
|
13
|
+
/** Maximum retries (default: 2) */
|
|
14
|
+
maxRetries?: number;
|
|
15
|
+
/** Abort signal for cancellation */
|
|
16
|
+
abortSignal?: AbortSignal;
|
|
17
|
+
/** Additional headers */
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
/** Force specific backend: 'ai-sdk' | 'native' | 'auto' */
|
|
20
|
+
backend?: 'ai-sdk' | 'native' | 'auto';
|
|
21
|
+
}
|
|
22
|
+
export interface EmbeddingResult {
|
|
23
|
+
embedding: number[];
|
|
24
|
+
usage?: {
|
|
25
|
+
tokens: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface EmbeddingBatchResult {
|
|
29
|
+
embeddings: number[][];
|
|
30
|
+
usage?: {
|
|
31
|
+
tokens: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the default embedding model for a provider
|
|
36
|
+
*/
|
|
37
|
+
export declare function getDefaultEmbeddingModel(provider?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Parse embedding model string into provider and model
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseEmbeddingModel(model: string): {
|
|
42
|
+
provider: string;
|
|
43
|
+
model: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Embed a single text using AI SDK (preferred) or native provider
|
|
47
|
+
*/
|
|
48
|
+
export declare function embed(text: string, options?: EmbeddingOptions): Promise<EmbeddingResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Embed multiple texts using AI SDK (preferred) or native provider
|
|
51
|
+
*/
|
|
52
|
+
export declare function embedMany(texts: string[], options?: EmbeddingOptions): Promise<EmbeddingBatchResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Create an EmbeddingProvider that uses AI SDK
|
|
55
|
+
* Compatible with KnowledgeBase and Memory interfaces
|
|
56
|
+
*/
|
|
57
|
+
export declare function createEmbeddingProvider(options?: EmbeddingOptions): EmbeddingProvider;
|
|
58
|
+
/**
|
|
59
|
+
* Cosine similarity between two vectors
|
|
60
|
+
*/
|
|
61
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
62
|
+
/**
|
|
63
|
+
* Euclidean distance between two vectors
|
|
64
|
+
*/
|
|
65
|
+
export declare function euclideanDistance(a: number[], b: number[]): number;
|
|
66
|
+
export type { EmbeddingProvider };
|