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,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI Provider - Implementation for OpenAI API
|
|
4
|
+
*/
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.OpenAIProvider = void 0;
|
|
10
|
+
const openai_1 = __importDefault(require("openai"));
|
|
11
|
+
const base_1 = require("./base");
|
|
12
|
+
class OpenAIProvider extends base_1.BaseProvider {
|
|
13
|
+
constructor(modelId, config = {}) {
|
|
14
|
+
super(modelId, config);
|
|
15
|
+
this.providerId = 'openai';
|
|
16
|
+
this.client = new openai_1.default({
|
|
17
|
+
apiKey: config.apiKey || process.env.OPENAI_API_KEY,
|
|
18
|
+
baseURL: config.baseUrl,
|
|
19
|
+
timeout: config.timeout || 60000,
|
|
20
|
+
maxRetries: 0, // We handle retries ourselves
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async generateText(options) {
|
|
24
|
+
return this.withRetry(async () => {
|
|
25
|
+
const response = await this.client.chat.completions.create({
|
|
26
|
+
model: this.modelId,
|
|
27
|
+
messages: this.formatMessages(options.messages),
|
|
28
|
+
temperature: options.temperature ?? 0.7,
|
|
29
|
+
max_tokens: options.maxTokens,
|
|
30
|
+
tools: options.tools ? this.formatTools(options.tools) : undefined,
|
|
31
|
+
tool_choice: options.toolChoice,
|
|
32
|
+
stop: options.stop,
|
|
33
|
+
top_p: options.topP,
|
|
34
|
+
frequency_penalty: options.frequencyPenalty,
|
|
35
|
+
presence_penalty: options.presencePenalty,
|
|
36
|
+
});
|
|
37
|
+
const choice = response.choices[0];
|
|
38
|
+
const message = choice.message;
|
|
39
|
+
return {
|
|
40
|
+
text: message.content || '',
|
|
41
|
+
toolCalls: message.tool_calls?.map(tc => ({
|
|
42
|
+
id: tc.id,
|
|
43
|
+
type: 'function',
|
|
44
|
+
function: {
|
|
45
|
+
name: tc.function.name,
|
|
46
|
+
arguments: tc.function.arguments,
|
|
47
|
+
},
|
|
48
|
+
})),
|
|
49
|
+
usage: {
|
|
50
|
+
promptTokens: response.usage?.prompt_tokens || 0,
|
|
51
|
+
completionTokens: response.usage?.completion_tokens || 0,
|
|
52
|
+
totalTokens: response.usage?.total_tokens || 0,
|
|
53
|
+
},
|
|
54
|
+
finishReason: this.mapFinishReason(choice.finish_reason),
|
|
55
|
+
raw: response,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async streamText(options) {
|
|
60
|
+
const self = this;
|
|
61
|
+
return {
|
|
62
|
+
async *[Symbol.asyncIterator]() {
|
|
63
|
+
const stream = await self.client.chat.completions.create({
|
|
64
|
+
model: self.modelId,
|
|
65
|
+
messages: self.formatMessages(options.messages),
|
|
66
|
+
temperature: options.temperature ?? 0.7,
|
|
67
|
+
max_tokens: options.maxTokens,
|
|
68
|
+
tools: options.tools ? self.formatTools(options.tools) : undefined,
|
|
69
|
+
tool_choice: options.toolChoice,
|
|
70
|
+
stop: options.stop,
|
|
71
|
+
stream: true,
|
|
72
|
+
});
|
|
73
|
+
let toolCalls = [];
|
|
74
|
+
for await (const chunk of stream) {
|
|
75
|
+
const delta = chunk.choices[0]?.delta;
|
|
76
|
+
if (delta?.content) {
|
|
77
|
+
if (options.onToken) {
|
|
78
|
+
options.onToken(delta.content);
|
|
79
|
+
}
|
|
80
|
+
yield { text: delta.content };
|
|
81
|
+
}
|
|
82
|
+
if (delta?.tool_calls) {
|
|
83
|
+
for (const tc of delta.tool_calls) {
|
|
84
|
+
if (tc.index !== undefined) {
|
|
85
|
+
if (!toolCalls[tc.index]) {
|
|
86
|
+
toolCalls[tc.index] = {
|
|
87
|
+
id: tc.id || '',
|
|
88
|
+
type: 'function',
|
|
89
|
+
function: { name: '', arguments: '' },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (tc.id)
|
|
93
|
+
toolCalls[tc.index].id = tc.id;
|
|
94
|
+
if (tc.function?.name)
|
|
95
|
+
toolCalls[tc.index].function.name = tc.function.name;
|
|
96
|
+
if (tc.function?.arguments)
|
|
97
|
+
toolCalls[tc.index].function.arguments += tc.function.arguments;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (chunk.choices[0]?.finish_reason) {
|
|
102
|
+
yield {
|
|
103
|
+
finishReason: chunk.choices[0].finish_reason,
|
|
104
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
105
|
+
usage: chunk.usage ? {
|
|
106
|
+
promptTokens: chunk.usage.prompt_tokens,
|
|
107
|
+
completionTokens: chunk.usage.completion_tokens,
|
|
108
|
+
totalTokens: chunk.usage.total_tokens,
|
|
109
|
+
} : undefined,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async generateObject(options) {
|
|
117
|
+
return this.withRetry(async () => {
|
|
118
|
+
const response = await this.client.chat.completions.create({
|
|
119
|
+
model: this.modelId,
|
|
120
|
+
messages: this.formatMessages(options.messages),
|
|
121
|
+
temperature: options.temperature ?? 0.7,
|
|
122
|
+
max_tokens: options.maxTokens,
|
|
123
|
+
response_format: {
|
|
124
|
+
type: 'json_schema',
|
|
125
|
+
json_schema: {
|
|
126
|
+
name: 'response',
|
|
127
|
+
schema: this.normalizeSchema(options.schema),
|
|
128
|
+
strict: true,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const choice = response.choices[0];
|
|
133
|
+
const content = choice.message.content || '{}';
|
|
134
|
+
let parsed;
|
|
135
|
+
try {
|
|
136
|
+
parsed = JSON.parse(content);
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
throw new Error(`Failed to parse JSON response: ${content}`);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
object: parsed,
|
|
143
|
+
usage: {
|
|
144
|
+
promptTokens: response.usage?.prompt_tokens || 0,
|
|
145
|
+
completionTokens: response.usage?.completion_tokens || 0,
|
|
146
|
+
totalTokens: response.usage?.total_tokens || 0,
|
|
147
|
+
},
|
|
148
|
+
raw: response,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
formatMessages(messages) {
|
|
153
|
+
return messages.map(msg => {
|
|
154
|
+
if (msg.role === 'tool') {
|
|
155
|
+
return {
|
|
156
|
+
role: 'tool',
|
|
157
|
+
content: msg.content || '',
|
|
158
|
+
tool_call_id: msg.tool_call_id || '',
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (msg.role === 'assistant' && msg.tool_calls) {
|
|
162
|
+
return {
|
|
163
|
+
role: 'assistant',
|
|
164
|
+
content: msg.content,
|
|
165
|
+
tool_calls: msg.tool_calls,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
role: msg.role,
|
|
170
|
+
content: msg.content || '',
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
formatTools(tools) {
|
|
175
|
+
return tools.map(tool => ({
|
|
176
|
+
type: 'function',
|
|
177
|
+
function: {
|
|
178
|
+
name: tool.name,
|
|
179
|
+
description: tool.description || `Function ${tool.name}`,
|
|
180
|
+
parameters: tool.parameters || { type: 'object', properties: {} },
|
|
181
|
+
},
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
mapFinishReason(reason) {
|
|
185
|
+
switch (reason) {
|
|
186
|
+
case 'stop': return 'stop';
|
|
187
|
+
case 'length': return 'length';
|
|
188
|
+
case 'tool_calls': return 'tool_calls';
|
|
189
|
+
case 'content_filter': return 'content_filter';
|
|
190
|
+
default: return 'stop';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
normalizeSchema(schema) {
|
|
194
|
+
// If it's a Zod schema, convert to JSON schema
|
|
195
|
+
if (schema && typeof schema.parse === 'function' && typeof schema._def === 'object') {
|
|
196
|
+
// This is a Zod schema - we need zod-to-json-schema
|
|
197
|
+
// For now, throw an error suggesting to use JSON schema directly
|
|
198
|
+
throw new Error('Zod schemas require zod-to-json-schema. Please use JSON schema directly or install zod-to-json-schema.');
|
|
199
|
+
}
|
|
200
|
+
return schema;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.OpenAIProvider = OpenAIProvider;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider Registry - Extensible provider registration system
|
|
3
|
+
*
|
|
4
|
+
* Fixes Issue #1095: Allows users to register custom providers
|
|
5
|
+
* that can be resolved by name via createProvider().
|
|
6
|
+
*/
|
|
7
|
+
import type { LLMProvider, ProviderConfig } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Provider constructor type
|
|
10
|
+
*/
|
|
11
|
+
export type ProviderConstructor = new (modelId: string, config?: ProviderConfig) => LLMProvider;
|
|
12
|
+
/**
|
|
13
|
+
* Lazy loader function that returns a provider constructor
|
|
14
|
+
* Used for tree-shaking and lazy loading of provider implementations
|
|
15
|
+
*/
|
|
16
|
+
export type ProviderLoader = () => ProviderConstructor;
|
|
17
|
+
/**
|
|
18
|
+
* Options for registering a provider
|
|
19
|
+
*/
|
|
20
|
+
export interface RegisterOptions {
|
|
21
|
+
/** Allow overwriting an existing registration */
|
|
22
|
+
override?: boolean;
|
|
23
|
+
/** Additional names that resolve to this provider */
|
|
24
|
+
aliases?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Provider Registry Interface
|
|
28
|
+
*/
|
|
29
|
+
export interface IProviderRegistry {
|
|
30
|
+
register(name: string, provider: ProviderConstructor | ProviderLoader, options?: RegisterOptions): void;
|
|
31
|
+
unregister(name: string): boolean;
|
|
32
|
+
has(name: string): boolean;
|
|
33
|
+
list(): string[];
|
|
34
|
+
resolve(name: string, modelId: string, config?: ProviderConfig): LLMProvider;
|
|
35
|
+
get(name: string): ProviderConstructor | ProviderLoader | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Provider Registry Implementation
|
|
39
|
+
*
|
|
40
|
+
* Manages registration and resolution of LLM providers by name.
|
|
41
|
+
* Supports lazy loading, aliases, and isolated instances.
|
|
42
|
+
*/
|
|
43
|
+
export declare class ProviderRegistry implements IProviderRegistry {
|
|
44
|
+
private entries;
|
|
45
|
+
private aliases;
|
|
46
|
+
/**
|
|
47
|
+
* Register a provider by name
|
|
48
|
+
*
|
|
49
|
+
* @param name - Provider name (e.g., 'cloudflare', 'ollama')
|
|
50
|
+
* @param provider - Provider constructor or lazy loader function
|
|
51
|
+
* @param options - Registration options
|
|
52
|
+
* @throws Error if name is already registered (unless override: true)
|
|
53
|
+
*/
|
|
54
|
+
register(name: string, provider: ProviderConstructor | ProviderLoader, options?: RegisterOptions): void;
|
|
55
|
+
/**
|
|
56
|
+
* Unregister a provider by name
|
|
57
|
+
*
|
|
58
|
+
* @param name - Provider name to unregister
|
|
59
|
+
* @returns true if provider was unregistered, false if not found
|
|
60
|
+
*/
|
|
61
|
+
unregister(name: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Check if a provider is registered
|
|
64
|
+
*
|
|
65
|
+
* @param name - Provider name to check
|
|
66
|
+
* @returns true if provider is registered
|
|
67
|
+
*/
|
|
68
|
+
has(name: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* List all registered provider names (canonical names only)
|
|
71
|
+
*
|
|
72
|
+
* @returns Array of provider names
|
|
73
|
+
*/
|
|
74
|
+
list(): string[];
|
|
75
|
+
/**
|
|
76
|
+
* List all names including aliases
|
|
77
|
+
*
|
|
78
|
+
* @returns Array of all registered names and aliases
|
|
79
|
+
*/
|
|
80
|
+
listAll(): string[];
|
|
81
|
+
/**
|
|
82
|
+
* Resolve a provider by name, creating an instance
|
|
83
|
+
*
|
|
84
|
+
* @param name - Provider name
|
|
85
|
+
* @param modelId - Model ID to pass to constructor
|
|
86
|
+
* @param config - Optional provider config
|
|
87
|
+
* @returns Provider instance
|
|
88
|
+
* @throws Error if provider not found
|
|
89
|
+
*/
|
|
90
|
+
resolve(name: string, modelId: string, config?: ProviderConfig): LLMProvider;
|
|
91
|
+
/**
|
|
92
|
+
* Get the provider constructor/loader without instantiating
|
|
93
|
+
*
|
|
94
|
+
* @param name - Provider name
|
|
95
|
+
* @returns Provider constructor/loader or undefined
|
|
96
|
+
*/
|
|
97
|
+
get(name: string): ProviderConstructor | ProviderLoader | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Get the resolved constructor for an entry
|
|
100
|
+
*/
|
|
101
|
+
private getConstructor;
|
|
102
|
+
/**
|
|
103
|
+
* Determine if a value is a loader function vs a constructor
|
|
104
|
+
* Loaders are arrow functions or regular functions that return a class
|
|
105
|
+
* Constructors have a prototype with constructor
|
|
106
|
+
*/
|
|
107
|
+
private isLoaderFunction;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the default global provider registry
|
|
111
|
+
*
|
|
112
|
+
* This is the registry used by createProvider() when no custom registry is specified.
|
|
113
|
+
* Built-in providers (OpenAI, Anthropic, Google) are registered here.
|
|
114
|
+
*/
|
|
115
|
+
export declare function getDefaultRegistry(): ProviderRegistry;
|
|
116
|
+
/**
|
|
117
|
+
* Create a new isolated provider registry
|
|
118
|
+
*
|
|
119
|
+
* Use this when you need a separate registry that doesn't share
|
|
120
|
+
* registrations with the default global registry.
|
|
121
|
+
*/
|
|
122
|
+
export declare function createProviderRegistry(): ProviderRegistry;
|
|
123
|
+
/**
|
|
124
|
+
* Register a provider to the default global registry
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { registerProvider } from 'praisonai';
|
|
129
|
+
* import { CloudflareProvider } from './my-cloudflare-provider';
|
|
130
|
+
*
|
|
131
|
+
* registerProvider('cloudflare', CloudflareProvider);
|
|
132
|
+
*
|
|
133
|
+
* // Now works:
|
|
134
|
+
* const agent = new Agent({ llm: 'cloudflare/workers-ai' });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function registerProvider(name: string, provider: ProviderConstructor | ProviderLoader, options?: RegisterOptions): void;
|
|
138
|
+
/**
|
|
139
|
+
* Unregister a provider from the default global registry
|
|
140
|
+
*/
|
|
141
|
+
export declare function unregisterProvider(name: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if a provider is registered in the default registry
|
|
144
|
+
*/
|
|
145
|
+
export declare function hasProvider(name: string): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* List all providers in the default registry
|
|
148
|
+
*/
|
|
149
|
+
export declare function listProviders(): string[];
|
|
150
|
+
/**
|
|
151
|
+
* Register built-in providers to a registry
|
|
152
|
+
* Uses lazy loaders to avoid importing all providers at module load time
|
|
153
|
+
*/
|
|
154
|
+
export declare function registerBuiltinProviders(registry: ProviderRegistry): void;
|
|
155
|
+
/**
|
|
156
|
+
* Reset the default registry (mainly for testing)
|
|
157
|
+
* @internal
|
|
158
|
+
*/
|
|
159
|
+
export declare function _resetDefaultRegistry(): void;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Provider Registry - Extensible provider registration system
|
|
4
|
+
*
|
|
5
|
+
* Fixes Issue #1095: Allows users to register custom providers
|
|
6
|
+
* that can be resolved by name via createProvider().
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ProviderRegistry = void 0;
|
|
10
|
+
exports.getDefaultRegistry = getDefaultRegistry;
|
|
11
|
+
exports.createProviderRegistry = createProviderRegistry;
|
|
12
|
+
exports.registerProvider = registerProvider;
|
|
13
|
+
exports.unregisterProvider = unregisterProvider;
|
|
14
|
+
exports.hasProvider = hasProvider;
|
|
15
|
+
exports.listProviders = listProviders;
|
|
16
|
+
exports.registerBuiltinProviders = registerBuiltinProviders;
|
|
17
|
+
exports._resetDefaultRegistry = _resetDefaultRegistry;
|
|
18
|
+
/**
|
|
19
|
+
* Provider Registry Implementation
|
|
20
|
+
*
|
|
21
|
+
* Manages registration and resolution of LLM providers by name.
|
|
22
|
+
* Supports lazy loading, aliases, and isolated instances.
|
|
23
|
+
*/
|
|
24
|
+
class ProviderRegistry {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.entries = new Map();
|
|
27
|
+
this.aliases = new Map(); // alias -> canonical name
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Register a provider by name
|
|
31
|
+
*
|
|
32
|
+
* @param name - Provider name (e.g., 'cloudflare', 'ollama')
|
|
33
|
+
* @param provider - Provider constructor or lazy loader function
|
|
34
|
+
* @param options - Registration options
|
|
35
|
+
* @throws Error if name is already registered (unless override: true)
|
|
36
|
+
*/
|
|
37
|
+
register(name, provider, options = {}) {
|
|
38
|
+
const normalizedName = name.toLowerCase();
|
|
39
|
+
// Check for existing registration
|
|
40
|
+
if (this.entries.has(normalizedName) && !options.override) {
|
|
41
|
+
throw new Error(`Provider '${name}' is already registered. ` +
|
|
42
|
+
`Use { override: true } to replace it.`);
|
|
43
|
+
}
|
|
44
|
+
// Determine if this is a loader function or direct constructor
|
|
45
|
+
const isLoader = this.isLoaderFunction(provider);
|
|
46
|
+
const entry = {
|
|
47
|
+
provider,
|
|
48
|
+
isLoader,
|
|
49
|
+
canonicalName: normalizedName,
|
|
50
|
+
};
|
|
51
|
+
this.entries.set(normalizedName, entry);
|
|
52
|
+
// Register aliases
|
|
53
|
+
if (options.aliases) {
|
|
54
|
+
for (const alias of options.aliases) {
|
|
55
|
+
const normalizedAlias = alias.toLowerCase();
|
|
56
|
+
if (this.entries.has(normalizedAlias) && !options.override) {
|
|
57
|
+
throw new Error(`Alias '${alias}' conflicts with existing provider. ` +
|
|
58
|
+
`Use { override: true } to replace it.`);
|
|
59
|
+
}
|
|
60
|
+
this.aliases.set(normalizedAlias, normalizedName);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Unregister a provider by name
|
|
66
|
+
*
|
|
67
|
+
* @param name - Provider name to unregister
|
|
68
|
+
* @returns true if provider was unregistered, false if not found
|
|
69
|
+
*/
|
|
70
|
+
unregister(name) {
|
|
71
|
+
const normalizedName = name.toLowerCase();
|
|
72
|
+
// Check if it's an alias
|
|
73
|
+
if (this.aliases.has(normalizedName)) {
|
|
74
|
+
this.aliases.delete(normalizedName);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
// Check if it's a canonical name
|
|
78
|
+
if (this.entries.has(normalizedName)) {
|
|
79
|
+
// Remove all aliases pointing to this provider
|
|
80
|
+
for (const [alias, canonical] of this.aliases.entries()) {
|
|
81
|
+
if (canonical === normalizedName) {
|
|
82
|
+
this.aliases.delete(alias);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this.entries.delete(normalizedName);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if a provider is registered
|
|
92
|
+
*
|
|
93
|
+
* @param name - Provider name to check
|
|
94
|
+
* @returns true if provider is registered
|
|
95
|
+
*/
|
|
96
|
+
has(name) {
|
|
97
|
+
const normalizedName = name.toLowerCase();
|
|
98
|
+
return this.entries.has(normalizedName) || this.aliases.has(normalizedName);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* List all registered provider names (canonical names only)
|
|
102
|
+
*
|
|
103
|
+
* @returns Array of provider names
|
|
104
|
+
*/
|
|
105
|
+
list() {
|
|
106
|
+
return Array.from(this.entries.keys());
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* List all names including aliases
|
|
110
|
+
*
|
|
111
|
+
* @returns Array of all registered names and aliases
|
|
112
|
+
*/
|
|
113
|
+
listAll() {
|
|
114
|
+
return [...this.entries.keys(), ...this.aliases.keys()];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolve a provider by name, creating an instance
|
|
118
|
+
*
|
|
119
|
+
* @param name - Provider name
|
|
120
|
+
* @param modelId - Model ID to pass to constructor
|
|
121
|
+
* @param config - Optional provider config
|
|
122
|
+
* @returns Provider instance
|
|
123
|
+
* @throws Error if provider not found
|
|
124
|
+
*/
|
|
125
|
+
resolve(name, modelId, config) {
|
|
126
|
+
const normalizedName = name.toLowerCase();
|
|
127
|
+
// Resolve alias to canonical name
|
|
128
|
+
const canonicalName = this.aliases.get(normalizedName) || normalizedName;
|
|
129
|
+
const entry = this.entries.get(canonicalName);
|
|
130
|
+
if (!entry) {
|
|
131
|
+
const available = this.list();
|
|
132
|
+
throw new Error(`Unknown provider: '${name}'. ` +
|
|
133
|
+
`Available providers: ${available.length > 0 ? available.join(', ') : 'none'}. ` +
|
|
134
|
+
`Register a custom provider with registerProvider('${name}', YourProviderClass).`);
|
|
135
|
+
}
|
|
136
|
+
// Get constructor (resolve loader if needed)
|
|
137
|
+
const Constructor = this.getConstructor(entry);
|
|
138
|
+
return new Constructor(modelId, config);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Get the provider constructor/loader without instantiating
|
|
142
|
+
*
|
|
143
|
+
* @param name - Provider name
|
|
144
|
+
* @returns Provider constructor/loader or undefined
|
|
145
|
+
*/
|
|
146
|
+
get(name) {
|
|
147
|
+
const normalizedName = name.toLowerCase();
|
|
148
|
+
const canonicalName = this.aliases.get(normalizedName) || normalizedName;
|
|
149
|
+
return this.entries.get(canonicalName)?.provider;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the resolved constructor for an entry
|
|
153
|
+
*/
|
|
154
|
+
getConstructor(entry) {
|
|
155
|
+
if (!entry.isLoader) {
|
|
156
|
+
return entry.provider;
|
|
157
|
+
}
|
|
158
|
+
// Lazy load and cache
|
|
159
|
+
if (!entry.cachedConstructor) {
|
|
160
|
+
const loader = entry.provider;
|
|
161
|
+
entry.cachedConstructor = loader();
|
|
162
|
+
}
|
|
163
|
+
return entry.cachedConstructor;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Determine if a value is a loader function vs a constructor
|
|
167
|
+
* Loaders are arrow functions or regular functions that return a class
|
|
168
|
+
* Constructors have a prototype with constructor
|
|
169
|
+
*/
|
|
170
|
+
isLoaderFunction(value) {
|
|
171
|
+
// If it has a prototype with more than just constructor, it's likely a class
|
|
172
|
+
if (value.prototype && Object.getOwnPropertyNames(value.prototype).length > 1) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
// Check if it looks like a class (has 'prototype' that is an object with constructor)
|
|
176
|
+
if (value.prototype && value.prototype.constructor === value) {
|
|
177
|
+
// Additional check: classes typically have a name and their toString starts with 'class'
|
|
178
|
+
const str = value.toString();
|
|
179
|
+
if (str.startsWith('class ') || str.includes('function ')) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Arrow functions and simple functions are loaders
|
|
184
|
+
return typeof value === 'function' && !value.prototype?.constructor;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.ProviderRegistry = ProviderRegistry;
|
|
188
|
+
// ============================================================================
|
|
189
|
+
// Default Registry Singleton
|
|
190
|
+
// ============================================================================
|
|
191
|
+
let defaultRegistry = null;
|
|
192
|
+
/**
|
|
193
|
+
* Get the default global provider registry
|
|
194
|
+
*
|
|
195
|
+
* This is the registry used by createProvider() when no custom registry is specified.
|
|
196
|
+
* Built-in providers (OpenAI, Anthropic, Google) are registered here.
|
|
197
|
+
*/
|
|
198
|
+
function getDefaultRegistry() {
|
|
199
|
+
if (!defaultRegistry) {
|
|
200
|
+
defaultRegistry = new ProviderRegistry();
|
|
201
|
+
registerBuiltinProviders(defaultRegistry);
|
|
202
|
+
}
|
|
203
|
+
return defaultRegistry;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Create a new isolated provider registry
|
|
207
|
+
*
|
|
208
|
+
* Use this when you need a separate registry that doesn't share
|
|
209
|
+
* registrations with the default global registry.
|
|
210
|
+
*/
|
|
211
|
+
function createProviderRegistry() {
|
|
212
|
+
return new ProviderRegistry();
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Register a provider to the default global registry
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* import { registerProvider } from 'praisonai';
|
|
220
|
+
* import { CloudflareProvider } from './my-cloudflare-provider';
|
|
221
|
+
*
|
|
222
|
+
* registerProvider('cloudflare', CloudflareProvider);
|
|
223
|
+
*
|
|
224
|
+
* // Now works:
|
|
225
|
+
* const agent = new Agent({ llm: 'cloudflare/workers-ai' });
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
function registerProvider(name, provider, options) {
|
|
229
|
+
getDefaultRegistry().register(name, provider, options);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Unregister a provider from the default global registry
|
|
233
|
+
*/
|
|
234
|
+
function unregisterProvider(name) {
|
|
235
|
+
return getDefaultRegistry().unregister(name);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Check if a provider is registered in the default registry
|
|
239
|
+
*/
|
|
240
|
+
function hasProvider(name) {
|
|
241
|
+
return getDefaultRegistry().has(name);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* List all providers in the default registry
|
|
245
|
+
*/
|
|
246
|
+
function listProviders() {
|
|
247
|
+
return getDefaultRegistry().list();
|
|
248
|
+
}
|
|
249
|
+
// ============================================================================
|
|
250
|
+
// Built-in Provider Registration
|
|
251
|
+
// ============================================================================
|
|
252
|
+
/**
|
|
253
|
+
* Register built-in providers to a registry
|
|
254
|
+
* Uses lazy loaders to avoid importing all providers at module load time
|
|
255
|
+
*/
|
|
256
|
+
function registerBuiltinProviders(registry) {
|
|
257
|
+
// OpenAI - lazy loaded
|
|
258
|
+
registry.register('openai', () => {
|
|
259
|
+
const { OpenAIProvider } = require('./openai');
|
|
260
|
+
return OpenAIProvider;
|
|
261
|
+
}, { aliases: ['oai'] });
|
|
262
|
+
// Anthropic - lazy loaded
|
|
263
|
+
registry.register('anthropic', () => {
|
|
264
|
+
const { AnthropicProvider } = require('./anthropic');
|
|
265
|
+
return AnthropicProvider;
|
|
266
|
+
}, { aliases: ['claude'] });
|
|
267
|
+
// Google - lazy loaded
|
|
268
|
+
registry.register('google', () => {
|
|
269
|
+
const { GoogleProvider } = require('./google');
|
|
270
|
+
return GoogleProvider;
|
|
271
|
+
}, { aliases: ['gemini'] });
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Reset the default registry (mainly for testing)
|
|
275
|
+
* @internal
|
|
276
|
+
*/
|
|
277
|
+
function _resetDefaultRegistry() {
|
|
278
|
+
defaultRegistry = null;
|
|
279
|
+
}
|