mcp-agent-foundry 1.0.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/LICENSE +21 -0
- package/README.md +477 -0
- package/dist/cli/install-skills.d.ts +11 -0
- package/dist/cli/install-skills.d.ts.map +1 -0
- package/dist/cli/install-skills.js +143 -0
- package/dist/cli/install-skills.js.map +1 -0
- package/dist/cli/recovery-commands.d.ts +41 -0
- package/dist/cli/recovery-commands.d.ts.map +1 -0
- package/dist/cli/recovery-commands.js +241 -0
- package/dist/cli/recovery-commands.js.map +1 -0
- package/dist/cli/setup-wizard.d.ts +25 -0
- package/dist/cli/setup-wizard.d.ts.map +1 -0
- package/dist/cli/setup-wizard.js +1417 -0
- package/dist/cli/setup-wizard.js.map +1 -0
- package/dist/cli/test-connection.d.ts +45 -0
- package/dist/cli/test-connection.d.ts.map +1 -0
- package/dist/cli/test-connection.js +317 -0
- package/dist/cli/test-connection.js.map +1 -0
- package/dist/cli.d.ts +75 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +704 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/defaults.d.ts +57 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +99 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/index.d.ts +14 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +22 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/manager.d.ts +184 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +347 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/merger.d.ts +76 -0
- package/dist/config/merger.d.ts.map +1 -0
- package/dist/config/merger.js +189 -0
- package/dist/config/merger.js.map +1 -0
- package/dist/config/schema.d.ts +20 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +20 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/validator.d.ts +254 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +363 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/config/worktree-defaults.d.ts +23 -0
- package/dist/config/worktree-defaults.d.ts.map +1 -0
- package/dist/config/worktree-defaults.js +78 -0
- package/dist/config/worktree-defaults.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/tools/compare-agents.d.ts +25 -0
- package/dist/mcp/tools/compare-agents.d.ts.map +1 -0
- package/dist/mcp/tools/compare-agents.js +177 -0
- package/dist/mcp/tools/compare-agents.js.map +1 -0
- package/dist/mcp/tools/critique-plan.d.ts +26 -0
- package/dist/mcp/tools/critique-plan.d.ts.map +1 -0
- package/dist/mcp/tools/critique-plan.js +162 -0
- package/dist/mcp/tools/critique-plan.js.map +1 -0
- package/dist/mcp/tools/design-feedback.d.ts +26 -0
- package/dist/mcp/tools/design-feedback.d.ts.map +1 -0
- package/dist/mcp/tools/design-feedback.js +216 -0
- package/dist/mcp/tools/design-feedback.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +50 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +191 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/invoke-agent.d.ts +25 -0
- package/dist/mcp/tools/invoke-agent.d.ts.map +1 -0
- package/dist/mcp/tools/invoke-agent.js +141 -0
- package/dist/mcp/tools/invoke-agent.js.map +1 -0
- package/dist/mcp/tools/review-code.d.ts +25 -0
- package/dist/mcp/tools/review-code.d.ts.map +1 -0
- package/dist/mcp/tools/review-code.js +170 -0
- package/dist/mcp/tools/review-code.js.map +1 -0
- package/dist/mcp/tools/tasks/claim-next-task.d.ts +22 -0
- package/dist/mcp/tools/tasks/claim-next-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/claim-next-task.js +203 -0
- package/dist/mcp/tools/tasks/claim-next-task.js.map +1 -0
- package/dist/mcp/tools/tasks/create-routed-task.d.ts +17 -0
- package/dist/mcp/tools/tasks/create-routed-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/create-routed-task.js +178 -0
- package/dist/mcp/tools/tasks/create-routed-task.js.map +1 -0
- package/dist/mcp/tools/tasks/execute-pipeline.d.ts +22 -0
- package/dist/mcp/tools/tasks/execute-pipeline.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/execute-pipeline.js +401 -0
- package/dist/mcp/tools/tasks/execute-pipeline.js.map +1 -0
- package/dist/mcp/tools/tasks/execute-task.d.ts +32 -0
- package/dist/mcp/tools/tasks/execute-task.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/execute-task.js +284 -0
- package/dist/mcp/tools/tasks/execute-task.js.map +1 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.d.ts +26 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.js +460 -0
- package/dist/mcp/tools/tasks/get-pipeline-status.js.map +1 -0
- package/dist/mcp/tools/tasks/index.d.ts +36 -0
- package/dist/mcp/tools/tasks/index.d.ts.map +1 -0
- package/dist/mcp/tools/tasks/index.js +66 -0
- package/dist/mcp/tools/tasks/index.js.map +1 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.d.ts +17 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.js +147 -0
- package/dist/mcp/tools/worktree/cleanup-worktrees.js.map +1 -0
- package/dist/mcp/tools/worktree/get-worktree-status.d.ts +17 -0
- package/dist/mcp/tools/worktree/get-worktree-status.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/get-worktree-status.js +123 -0
- package/dist/mcp/tools/worktree/get-worktree-status.js.map +1 -0
- package/dist/mcp/tools/worktree/index.d.ts +41 -0
- package/dist/mcp/tools/worktree/index.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/index.js +69 -0
- package/dist/mcp/tools/worktree/index.js.map +1 -0
- package/dist/mcp/tools/worktree/list-worktrees.d.ts +17 -0
- package/dist/mcp/tools/worktree/list-worktrees.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/list-worktrees.js +136 -0
- package/dist/mcp/tools/worktree/list-worktrees.js.map +1 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.d.ts +19 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.d.ts.map +1 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.js +228 -0
- package/dist/mcp/tools/worktree/resolve-conflicts.js.map +1 -0
- package/dist/mcp/transport/stdio.d.ts +13 -0
- package/dist/mcp/transport/stdio.d.ts.map +1 -0
- package/dist/mcp/transport/stdio.js +15 -0
- package/dist/mcp/transport/stdio.js.map +1 -0
- package/dist/observability/logger.d.ts +137 -0
- package/dist/observability/logger.d.ts.map +1 -0
- package/dist/observability/logger.js +235 -0
- package/dist/observability/logger.js.map +1 -0
- package/dist/observability/metrics.d.ts +250 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +364 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/persistence/index.d.ts +9 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +9 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/state-schema.d.ts +116 -0
- package/dist/persistence/state-schema.d.ts.map +1 -0
- package/dist/persistence/state-schema.js +28 -0
- package/dist/persistence/state-schema.js.map +1 -0
- package/dist/persistence/state-store.d.ts +111 -0
- package/dist/persistence/state-store.d.ts.map +1 -0
- package/dist/persistence/state-store.js +291 -0
- package/dist/persistence/state-store.js.map +1 -0
- package/dist/providers/anthropic.d.ts +164 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +500 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +151 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +227 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/gemini.d.ts +85 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +414 -0
- package/dist/providers/gemini.js.map +1 -0
- package/dist/providers/kimi.d.ts +19 -0
- package/dist/providers/kimi.d.ts.map +1 -0
- package/dist/providers/kimi.js +20 -0
- package/dist/providers/kimi.js.map +1 -0
- package/dist/providers/manager.d.ts +160 -0
- package/dist/providers/manager.d.ts.map +1 -0
- package/dist/providers/manager.js +264 -0
- package/dist/providers/manager.js.map +1 -0
- package/dist/providers/ollama.d.ts +83 -0
- package/dist/providers/ollama.d.ts.map +1 -0
- package/dist/providers/ollama.js +453 -0
- package/dist/providers/ollama.js.map +1 -0
- package/dist/providers/openai.d.ts +96 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +457 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/zai.d.ts +19 -0
- package/dist/providers/zai.d.ts.map +1 -0
- package/dist/providers/zai.js +20 -0
- package/dist/providers/zai.js.map +1 -0
- package/dist/router/context-manager.d.ts +2 -0
- package/dist/router/context-manager.d.ts.map +1 -0
- package/dist/router/context-manager.js +3 -0
- package/dist/router/context-manager.js.map +1 -0
- package/dist/router/engine.d.ts +169 -0
- package/dist/router/engine.d.ts.map +1 -0
- package/dist/router/engine.js +435 -0
- package/dist/router/engine.js.map +1 -0
- package/dist/router/pattern-executor.d.ts +317 -0
- package/dist/router/pattern-executor.d.ts.map +1 -0
- package/dist/router/pattern-executor.js +571 -0
- package/dist/router/pattern-executor.js.map +1 -0
- package/dist/router/role-resolver.d.ts +59 -0
- package/dist/router/role-resolver.d.ts.map +1 -0
- package/dist/router/role-resolver.js +95 -0
- package/dist/router/role-resolver.js.map +1 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +223 -0
- package/dist/server.js.map +1 -0
- package/dist/startup.d.ts +78 -0
- package/dist/startup.d.ts.map +1 -0
- package/dist/startup.js +107 -0
- package/dist/startup.js.map +1 -0
- package/dist/tasks/coordinator.d.ts +141 -0
- package/dist/tasks/coordinator.d.ts.map +1 -0
- package/dist/tasks/coordinator.js +331 -0
- package/dist/tasks/coordinator.js.map +1 -0
- package/dist/tasks/index.d.ts +13 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +13 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/tasks/persistent-state-coordinator.d.ts +89 -0
- package/dist/tasks/persistent-state-coordinator.d.ts.map +1 -0
- package/dist/tasks/persistent-state-coordinator.js +371 -0
- package/dist/tasks/persistent-state-coordinator.js.map +1 -0
- package/dist/tasks/pipeline-manager.d.ts +103 -0
- package/dist/tasks/pipeline-manager.d.ts.map +1 -0
- package/dist/tasks/pipeline-manager.js +358 -0
- package/dist/tasks/pipeline-manager.js.map +1 -0
- package/dist/tasks/state-coordinator.d.ts +79 -0
- package/dist/tasks/state-coordinator.d.ts.map +1 -0
- package/dist/tasks/state-coordinator.js +200 -0
- package/dist/tasks/state-coordinator.js.map +1 -0
- package/dist/tasks/worker-mode.d.ts +65 -0
- package/dist/tasks/worker-mode.d.ts.map +1 -0
- package/dist/tasks/worker-mode.js +208 -0
- package/dist/tasks/worker-mode.js.map +1 -0
- package/dist/translation/errors.d.ts +203 -0
- package/dist/translation/errors.d.ts.map +1 -0
- package/dist/translation/errors.js +477 -0
- package/dist/translation/errors.js.map +1 -0
- package/dist/translation/index.d.ts +12 -0
- package/dist/translation/index.d.ts.map +1 -0
- package/dist/translation/index.js +32 -0
- package/dist/translation/index.js.map +1 -0
- package/dist/translation/messages.d.ts +295 -0
- package/dist/translation/messages.d.ts.map +1 -0
- package/dist/translation/messages.js +557 -0
- package/dist/translation/messages.js.map +1 -0
- package/dist/translation/streaming.d.ts +226 -0
- package/dist/translation/streaming.d.ts.map +1 -0
- package/dist/translation/streaming.js +520 -0
- package/dist/translation/streaming.js.map +1 -0
- package/dist/translation/tools.d.ts +209 -0
- package/dist/translation/tools.d.ts.map +1 -0
- package/dist/translation/tools.js +331 -0
- package/dist/translation/tools.js.map +1 -0
- package/dist/types.d.ts +747 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +86 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +175 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +315 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/env.d.ts +2 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +3 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/git.d.ts +58 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +197 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/merge-ordering.d.ts +45 -0
- package/dist/utils/merge-ordering.d.ts.map +1 -0
- package/dist/utils/merge-ordering.js +128 -0
- package/dist/utils/merge-ordering.js.map +1 -0
- package/dist/utils/retry.d.ts +106 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +188 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/worktrees/branch-manager.d.ts +55 -0
- package/dist/worktrees/branch-manager.d.ts.map +1 -0
- package/dist/worktrees/branch-manager.js +129 -0
- package/dist/worktrees/branch-manager.js.map +1 -0
- package/dist/worktrees/conflict-handler.d.ts +72 -0
- package/dist/worktrees/conflict-handler.d.ts.map +1 -0
- package/dist/worktrees/conflict-handler.js +287 -0
- package/dist/worktrees/conflict-handler.js.map +1 -0
- package/dist/worktrees/conflict-parser.d.ts +28 -0
- package/dist/worktrees/conflict-parser.d.ts.map +1 -0
- package/dist/worktrees/conflict-parser.js +140 -0
- package/dist/worktrees/conflict-parser.js.map +1 -0
- package/dist/worktrees/index.d.ts +20 -0
- package/dist/worktrees/index.d.ts.map +1 -0
- package/dist/worktrees/index.js +20 -0
- package/dist/worktrees/index.js.map +1 -0
- package/dist/worktrees/instructions.d.ts +20 -0
- package/dist/worktrees/instructions.d.ts.map +1 -0
- package/dist/worktrees/instructions.js +84 -0
- package/dist/worktrees/instructions.js.map +1 -0
- package/dist/worktrees/manager.d.ts +76 -0
- package/dist/worktrees/manager.d.ts.map +1 -0
- package/dist/worktrees/manager.js +277 -0
- package/dist/worktrees/manager.js.map +1 -0
- package/dist/worktrees/pipeline-merge-orchestrator.d.ts +55 -0
- package/dist/worktrees/pipeline-merge-orchestrator.d.ts.map +1 -0
- package/dist/worktrees/pipeline-merge-orchestrator.js +221 -0
- package/dist/worktrees/pipeline-merge-orchestrator.js.map +1 -0
- package/dist/worktrees/pool.d.ts +95 -0
- package/dist/worktrees/pool.d.ts.map +1 -0
- package/dist/worktrees/pool.js +271 -0
- package/dist/worktrees/pool.js.map +1 -0
- package/dist/worktrees/recovery.d.ts +94 -0
- package/dist/worktrees/recovery.d.ts.map +1 -0
- package/dist/worktrees/recovery.js +371 -0
- package/dist/worktrees/recovery.js.map +1 -0
- package/dist/worktrees/resource-manager.d.ts +74 -0
- package/dist/worktrees/resource-manager.d.ts.map +1 -0
- package/dist/worktrees/resource-manager.js +228 -0
- package/dist/worktrees/resource-manager.js.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ollama Provider Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements the Provider interface for Ollama's OpenAI-compatible API.
|
|
5
|
+
* Ollama provides local LLM inference with an API that mirrors OpenAI's format.
|
|
6
|
+
*
|
|
7
|
+
* Key characteristics:
|
|
8
|
+
* - Local server running at http://localhost:11434
|
|
9
|
+
* - No authentication required (local)
|
|
10
|
+
* - Uses OpenAI-compatible /v1/chat/completions endpoint
|
|
11
|
+
* - May not support all features (especially function calling)
|
|
12
|
+
* - Server may be slower than cloud providers
|
|
13
|
+
*/
|
|
14
|
+
import { ProviderError, } from '../types.js';
|
|
15
|
+
import { BaseProvider } from './base.js';
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Ollama Provider Implementation
|
|
18
|
+
// ============================================================================
|
|
19
|
+
/**
|
|
20
|
+
* Ollama provider adapter for local LLM inference.
|
|
21
|
+
*
|
|
22
|
+
* Ollama provides an OpenAI-compatible API for running local models.
|
|
23
|
+
* This provider translates AgentRouter requests to the Ollama format
|
|
24
|
+
* and handles the specific characteristics of local inference.
|
|
25
|
+
*
|
|
26
|
+
* Features:
|
|
27
|
+
* - No authentication required (local server)
|
|
28
|
+
* - Supports streaming responses
|
|
29
|
+
* - Limited function calling support (depends on model)
|
|
30
|
+
* - Graceful connection error handling
|
|
31
|
+
*/
|
|
32
|
+
export class OllamaProvider extends BaseProvider {
|
|
33
|
+
name = 'ollama';
|
|
34
|
+
static DEFAULT_BASE_URL = 'http://localhost:11434';
|
|
35
|
+
/**
|
|
36
|
+
* Build headers for Ollama API requests.
|
|
37
|
+
* No authentication required for local server.
|
|
38
|
+
*/
|
|
39
|
+
buildHeaders() {
|
|
40
|
+
const headers = {
|
|
41
|
+
'Content-Type': 'application/json',
|
|
42
|
+
};
|
|
43
|
+
// Add any custom headers from config (but skip Authorization since it's local)
|
|
44
|
+
if (this.config.headers) {
|
|
45
|
+
Object.assign(headers, this.config.headers);
|
|
46
|
+
}
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Execute a completion request and return the full response.
|
|
51
|
+
*/
|
|
52
|
+
async complete(request) {
|
|
53
|
+
const baseUrl = this.getBaseUrl(OllamaProvider.DEFAULT_BASE_URL);
|
|
54
|
+
const url = `${baseUrl}/v1/chat/completions`;
|
|
55
|
+
const ollamaRequest = this.translateRequest(request);
|
|
56
|
+
try {
|
|
57
|
+
const response = await this.makeRequest({
|
|
58
|
+
method: 'POST',
|
|
59
|
+
url,
|
|
60
|
+
headers: this.buildHeaders(),
|
|
61
|
+
body: ollamaRequest,
|
|
62
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
63
|
+
});
|
|
64
|
+
return this.translateResponse(response);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// Provide more helpful error messages for Ollama-specific issues
|
|
68
|
+
this.handleOllamaError(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Execute a streaming completion request.
|
|
73
|
+
*/
|
|
74
|
+
async *completeStream(request) {
|
|
75
|
+
const baseUrl = this.getBaseUrl(OllamaProvider.DEFAULT_BASE_URL);
|
|
76
|
+
const url = `${baseUrl}/v1/chat/completions`;
|
|
77
|
+
const ollamaRequest = this.translateRequest({ ...request, stream: true });
|
|
78
|
+
let response;
|
|
79
|
+
try {
|
|
80
|
+
response = await this.makeStreamingRequest({
|
|
81
|
+
method: 'POST',
|
|
82
|
+
url,
|
|
83
|
+
headers: this.buildHeaders(),
|
|
84
|
+
body: ollamaRequest,
|
|
85
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
86
|
+
stream: true,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
this.handleOllamaError(error);
|
|
91
|
+
}
|
|
92
|
+
if (!response.body) {
|
|
93
|
+
throw new ProviderError('No response body for streaming request', this.name);
|
|
94
|
+
}
|
|
95
|
+
// Track tool calls being built across chunks
|
|
96
|
+
const toolCallsInProgress = new Map();
|
|
97
|
+
let hasStartedContent = false;
|
|
98
|
+
const reader = response.body.getReader();
|
|
99
|
+
const decoder = new TextDecoder();
|
|
100
|
+
let buffer = '';
|
|
101
|
+
try {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
103
|
+
while (true) {
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
105
|
+
const { done, value } = await reader.read();
|
|
106
|
+
if (done) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
110
|
+
buffer += decoder.decode(value, { stream: true });
|
|
111
|
+
// Process complete SSE events
|
|
112
|
+
const lines = buffer.split('\n');
|
|
113
|
+
buffer = lines.pop() ?? '';
|
|
114
|
+
for (const line of lines) {
|
|
115
|
+
const trimmed = line.trim();
|
|
116
|
+
if (trimmed === '' || trimmed === 'data: [DONE]') {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (trimmed.startsWith('data: ')) {
|
|
120
|
+
const jsonStr = trimmed.slice(6);
|
|
121
|
+
try {
|
|
122
|
+
const chunk = JSON.parse(jsonStr);
|
|
123
|
+
const chunks = this.translateStreamChunk(chunk, toolCallsInProgress, hasStartedContent);
|
|
124
|
+
for (const streamChunk of chunks) {
|
|
125
|
+
// Track state for content block management
|
|
126
|
+
if (streamChunk.type === 'content_block_start' &&
|
|
127
|
+
streamChunk.content_block?.type === 'text') {
|
|
128
|
+
hasStartedContent = true;
|
|
129
|
+
}
|
|
130
|
+
yield streamChunk;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Skip malformed JSON chunks
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
reader.releaseLock();
|
|
142
|
+
}
|
|
143
|
+
// Emit message_stop at the end
|
|
144
|
+
yield { type: 'message_stop' };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Check if the Ollama server is running and available.
|
|
148
|
+
* Uses the native Ollama tags API to list available models.
|
|
149
|
+
*/
|
|
150
|
+
async healthCheck() {
|
|
151
|
+
const baseUrl = this.getBaseUrl(OllamaProvider.DEFAULT_BASE_URL);
|
|
152
|
+
const url = `${baseUrl}/api/tags`;
|
|
153
|
+
try {
|
|
154
|
+
await this.makeRequest({
|
|
155
|
+
method: 'GET',
|
|
156
|
+
url,
|
|
157
|
+
headers: this.buildHeaders(),
|
|
158
|
+
timeoutMs: 10000,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
// Provide helpful error message for common Ollama issues
|
|
163
|
+
if (error instanceof Error) {
|
|
164
|
+
if (error.message.includes('ECONNREFUSED') || error.message.includes('fetch failed')) {
|
|
165
|
+
throw new ProviderError('Ollama server is not running. Start it with: ollama serve', this.name, undefined, error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// ==========================================================================
|
|
172
|
+
// Error Handling
|
|
173
|
+
// ==========================================================================
|
|
174
|
+
/**
|
|
175
|
+
* Handle Ollama-specific errors with helpful messages.
|
|
176
|
+
*/
|
|
177
|
+
handleOllamaError(error) {
|
|
178
|
+
if (error instanceof Error) {
|
|
179
|
+
// Connection refused - server not running
|
|
180
|
+
if (error.message.includes('ECONNREFUSED') || error.message.includes('fetch failed')) {
|
|
181
|
+
throw new ProviderError('Ollama server is not running. Start it with: ollama serve', this.name, undefined, error);
|
|
182
|
+
}
|
|
183
|
+
// Model not found
|
|
184
|
+
if (error.message.includes('model') && error.message.includes('not found')) {
|
|
185
|
+
throw new ProviderError(`Ollama model not found. Pull it with: ollama pull <model-name>`, this.name, 404, error);
|
|
186
|
+
}
|
|
187
|
+
// Re-throw if it's already a ProviderError
|
|
188
|
+
if (error instanceof ProviderError) {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
// Wrap other errors
|
|
192
|
+
throw new ProviderError(error.message, this.name, undefined, error);
|
|
193
|
+
}
|
|
194
|
+
throw new ProviderError(String(error), this.name);
|
|
195
|
+
}
|
|
196
|
+
// ==========================================================================
|
|
197
|
+
// Translation Methods
|
|
198
|
+
// ==========================================================================
|
|
199
|
+
/**
|
|
200
|
+
* Translate AgentRouter request to Ollama format.
|
|
201
|
+
*/
|
|
202
|
+
translateRequest(request) {
|
|
203
|
+
const messages = this.translateMessages(request.messages);
|
|
204
|
+
const tools = request.tools ? this.translateTools(request.tools) : undefined;
|
|
205
|
+
return {
|
|
206
|
+
model: request.model,
|
|
207
|
+
messages,
|
|
208
|
+
temperature: request.temperature,
|
|
209
|
+
max_tokens: request.max_tokens,
|
|
210
|
+
tools: tools && tools.length > 0 ? tools : undefined,
|
|
211
|
+
stream: request.stream,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Translate messages from AgentRouter format to Ollama format.
|
|
216
|
+
*
|
|
217
|
+
* Key translations:
|
|
218
|
+
* - Content blocks are flattened to strings
|
|
219
|
+
* - tool_use blocks become tool_calls array on assistant messages
|
|
220
|
+
* - tool_result blocks become separate role: "tool" messages
|
|
221
|
+
*/
|
|
222
|
+
translateMessages(messages) {
|
|
223
|
+
const ollamaMessages = [];
|
|
224
|
+
for (const message of messages) {
|
|
225
|
+
if (typeof message.content === 'string') {
|
|
226
|
+
// Simple string content
|
|
227
|
+
ollamaMessages.push({
|
|
228
|
+
role: message.role,
|
|
229
|
+
content: message.content,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Content blocks - need to process differently based on type
|
|
234
|
+
const textParts = [];
|
|
235
|
+
const toolCalls = [];
|
|
236
|
+
const toolResults = [];
|
|
237
|
+
for (const block of message.content) {
|
|
238
|
+
switch (block.type) {
|
|
239
|
+
case 'text':
|
|
240
|
+
if (block.text !== undefined && block.text !== '') {
|
|
241
|
+
textParts.push(block.text);
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
244
|
+
case 'tool_use':
|
|
245
|
+
if (block.id !== undefined && block.id !== '' && block.name !== undefined && block.name !== '') {
|
|
246
|
+
toolCalls.push({
|
|
247
|
+
id: block.id,
|
|
248
|
+
type: 'function',
|
|
249
|
+
function: {
|
|
250
|
+
name: block.name,
|
|
251
|
+
arguments: JSON.stringify(block.input ?? {}),
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
case 'tool_result':
|
|
257
|
+
if (block.tool_use_id !== undefined && block.tool_use_id !== '' && block.content !== undefined && block.content !== '') {
|
|
258
|
+
toolResults.push({
|
|
259
|
+
tool_call_id: block.tool_use_id,
|
|
260
|
+
content: block.content,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Handle assistant messages with tool calls
|
|
267
|
+
if (message.role === 'assistant') {
|
|
268
|
+
const assistantMessage = {
|
|
269
|
+
role: 'assistant',
|
|
270
|
+
content: textParts.length > 0 ? textParts.join('\n') : null,
|
|
271
|
+
};
|
|
272
|
+
if (toolCalls.length > 0) {
|
|
273
|
+
assistantMessage.tool_calls = toolCalls;
|
|
274
|
+
}
|
|
275
|
+
ollamaMessages.push(assistantMessage);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
// User messages
|
|
279
|
+
if (textParts.length > 0) {
|
|
280
|
+
ollamaMessages.push({
|
|
281
|
+
role: 'user',
|
|
282
|
+
content: textParts.join('\n'),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
// Add tool results as separate messages
|
|
286
|
+
for (const result of toolResults) {
|
|
287
|
+
ollamaMessages.push({
|
|
288
|
+
role: 'tool',
|
|
289
|
+
content: result.content,
|
|
290
|
+
tool_call_id: result.tool_call_id,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return ollamaMessages;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Translate tools from AgentRouter format to Ollama format.
|
|
300
|
+
*/
|
|
301
|
+
translateTools(tools) {
|
|
302
|
+
return tools.map((tool) => ({
|
|
303
|
+
type: 'function',
|
|
304
|
+
function: {
|
|
305
|
+
name: tool.name,
|
|
306
|
+
description: tool.description,
|
|
307
|
+
parameters: tool.input_schema,
|
|
308
|
+
},
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Translate Ollama response to AgentRouter format.
|
|
313
|
+
*/
|
|
314
|
+
translateResponse(response) {
|
|
315
|
+
const choice = response.choices[0];
|
|
316
|
+
if (!choice) {
|
|
317
|
+
throw new ProviderError('No choices in Ollama response', this.name);
|
|
318
|
+
}
|
|
319
|
+
const content = [];
|
|
320
|
+
// Add text content if present
|
|
321
|
+
if (choice.message.content !== null && choice.message.content !== '') {
|
|
322
|
+
content.push({
|
|
323
|
+
type: 'text',
|
|
324
|
+
text: choice.message.content,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
// Add tool calls if present
|
|
328
|
+
if (choice.message.tool_calls) {
|
|
329
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
330
|
+
content.push({
|
|
331
|
+
type: 'tool_use',
|
|
332
|
+
id: toolCall.id,
|
|
333
|
+
name: toolCall.function.name,
|
|
334
|
+
input: JSON.parse(toolCall.function.arguments),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Map finish_reason to stop_reason
|
|
339
|
+
let stopReason = 'end_turn';
|
|
340
|
+
switch (choice.finish_reason) {
|
|
341
|
+
case 'stop':
|
|
342
|
+
stopReason = 'end_turn';
|
|
343
|
+
break;
|
|
344
|
+
case 'length':
|
|
345
|
+
stopReason = 'max_tokens';
|
|
346
|
+
break;
|
|
347
|
+
case 'tool_calls':
|
|
348
|
+
stopReason = 'tool_use';
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
const result = {
|
|
352
|
+
id: response.id,
|
|
353
|
+
content,
|
|
354
|
+
model: response.model,
|
|
355
|
+
stop_reason: stopReason,
|
|
356
|
+
};
|
|
357
|
+
if (response.usage) {
|
|
358
|
+
result.usage = {
|
|
359
|
+
input_tokens: response.usage.prompt_tokens,
|
|
360
|
+
output_tokens: response.usage.completion_tokens,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Translate Ollama streaming chunk to AgentRouter StreamChunk format.
|
|
367
|
+
*
|
|
368
|
+
* Ollama streams deltas that need to be accumulated for tool calls.
|
|
369
|
+
* Text content can be yielded immediately.
|
|
370
|
+
*/
|
|
371
|
+
translateStreamChunk(chunk, toolCallsInProgress, hasStartedContent) {
|
|
372
|
+
const chunks = [];
|
|
373
|
+
const choice = chunk.choices[0];
|
|
374
|
+
if (!choice) {
|
|
375
|
+
return chunks;
|
|
376
|
+
}
|
|
377
|
+
const delta = choice.delta;
|
|
378
|
+
// Handle text content
|
|
379
|
+
if (delta.content !== undefined && delta.content !== null) {
|
|
380
|
+
// Emit content_block_start if this is the first content
|
|
381
|
+
if (!hasStartedContent) {
|
|
382
|
+
chunks.push({
|
|
383
|
+
type: 'content_block_start',
|
|
384
|
+
index: 0,
|
|
385
|
+
content_block: {
|
|
386
|
+
type: 'text',
|
|
387
|
+
text: '',
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
// Emit content delta
|
|
392
|
+
chunks.push({
|
|
393
|
+
type: 'content_block_delta',
|
|
394
|
+
index: 0,
|
|
395
|
+
delta: {
|
|
396
|
+
type: 'text_delta',
|
|
397
|
+
text: delta.content,
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
// Handle tool calls
|
|
402
|
+
if (delta.tool_calls) {
|
|
403
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
404
|
+
const index = toolCallDelta.index;
|
|
405
|
+
// Initialize tool call tracking if new
|
|
406
|
+
if (!toolCallsInProgress.has(index)) {
|
|
407
|
+
toolCallsInProgress.set(index, {
|
|
408
|
+
id: toolCallDelta.id ?? '',
|
|
409
|
+
name: toolCallDelta.function?.name ?? '',
|
|
410
|
+
arguments: '',
|
|
411
|
+
});
|
|
412
|
+
// Emit content_block_start for tool use
|
|
413
|
+
if (toolCallDelta.id !== undefined && toolCallDelta.id !== '' && toolCallDelta.function?.name !== undefined && toolCallDelta.function.name !== '') {
|
|
414
|
+
chunks.push({
|
|
415
|
+
type: 'content_block_start',
|
|
416
|
+
index: index + 1, // Offset by 1 since text is at index 0
|
|
417
|
+
content_block: {
|
|
418
|
+
type: 'tool_use',
|
|
419
|
+
id: toolCallDelta.id,
|
|
420
|
+
name: toolCallDelta.function.name,
|
|
421
|
+
input: {},
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// Update tool call data
|
|
427
|
+
const toolCall = toolCallsInProgress.get(index);
|
|
428
|
+
if (toolCall) {
|
|
429
|
+
if (toolCallDelta.id !== undefined && toolCallDelta.id !== '') {
|
|
430
|
+
toolCall.id = toolCallDelta.id;
|
|
431
|
+
}
|
|
432
|
+
if (toolCallDelta.function?.name !== undefined && toolCallDelta.function.name !== '') {
|
|
433
|
+
toolCall.name = toolCallDelta.function.name;
|
|
434
|
+
}
|
|
435
|
+
if (toolCallDelta.function?.arguments !== undefined && toolCallDelta.function.arguments !== '') {
|
|
436
|
+
toolCall.arguments += toolCallDelta.function.arguments;
|
|
437
|
+
// Emit delta for argument chunks
|
|
438
|
+
chunks.push({
|
|
439
|
+
type: 'content_block_delta',
|
|
440
|
+
index: index + 1,
|
|
441
|
+
delta: {
|
|
442
|
+
type: 'input_json_delta',
|
|
443
|
+
text: toolCallDelta.function.arguments,
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return chunks;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
//# sourceMappingURL=ollama.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../src/providers/ollama.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,aAAa,GAOd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,MAA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format translation between AgentRouter's internal format
|
|
6
|
+
* (which uses Anthropic-style messages) and OpenAI's format.
|
|
7
|
+
*
|
|
8
|
+
* Key differences from Anthropic format:
|
|
9
|
+
* - System prompt goes in messages array as role: "system"
|
|
10
|
+
* - Tool schemas use "parameters" instead of "input_schema"
|
|
11
|
+
* - Tool calls are in a separate "tool_calls" array, not content blocks
|
|
12
|
+
* - Tool results use role: "tool" messages, not tool_result content blocks
|
|
13
|
+
*/
|
|
14
|
+
import { BaseProvider } from './base.js';
|
|
15
|
+
import type { CompletionRequest, CompletionResponse, StreamChunk, ProviderConfig } from '../types.js';
|
|
16
|
+
/**
|
|
17
|
+
* OpenAI provider adapter.
|
|
18
|
+
*
|
|
19
|
+
* Translates between AgentRouter's internal message format and OpenAI's
|
|
20
|
+
* Chat Completions API format. Supports both streaming and non-streaming
|
|
21
|
+
* completion requests.
|
|
22
|
+
*/
|
|
23
|
+
export declare class OpenAIProvider extends BaseProvider {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
private static readonly DEFAULT_BASE_URL;
|
|
26
|
+
constructor(config: ProviderConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Build headers for OpenAI API requests.
|
|
29
|
+
* Adds organization header if configured.
|
|
30
|
+
*/
|
|
31
|
+
protected buildHeaders(): Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Execute a completion request and return the full response.
|
|
34
|
+
*/
|
|
35
|
+
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Execute a streaming completion request.
|
|
38
|
+
*/
|
|
39
|
+
completeStream(request: CompletionRequest): AsyncIterable<StreamChunk>;
|
|
40
|
+
/**
|
|
41
|
+
* Check if the provider is available and configured correctly.
|
|
42
|
+
*/
|
|
43
|
+
healthCheck(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Translate AgentRouter request to OpenAI format.
|
|
46
|
+
*
|
|
47
|
+
* Note: Newer OpenAI models (gpt-4o, gpt-4-turbo, o1, etc.) require
|
|
48
|
+
* max_completion_tokens instead of max_tokens. We detect model type
|
|
49
|
+
* and use the appropriate parameter.
|
|
50
|
+
*/
|
|
51
|
+
private translateRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Check if we're using the actual OpenAI API (not a compatible third-party API).
|
|
54
|
+
* Third-party OpenAI-compatible APIs (Z.AI, DeepSeek, local LLMs, etc.) typically
|
|
55
|
+
* use the standard max_tokens parameter, not max_completion_tokens.
|
|
56
|
+
*/
|
|
57
|
+
private isActualOpenAIAPI;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a model requires max_completion_tokens instead of max_tokens.
|
|
60
|
+
* Newer OpenAI models (gpt-4o, gpt-4-turbo, gpt-5.x, o1, o3, etc.) use the new parameter.
|
|
61
|
+
*
|
|
62
|
+
* IMPORTANT: This only applies to the actual OpenAI API. Third-party OpenAI-compatible
|
|
63
|
+
* APIs (Z.AI, DeepSeek, Ollama, etc.) use the standard max_tokens parameter.
|
|
64
|
+
*
|
|
65
|
+
* As of late 2024, most new OpenAI models require max_completion_tokens.
|
|
66
|
+
* We default to using max_completion_tokens for any model that:
|
|
67
|
+
* - Contains 'gpt-4o', 'gpt-4-turbo', 'gpt-5', 'o1', 'o3', or 'chatgpt'
|
|
68
|
+
* - OR is NOT a legacy model (gpt-3.5, gpt-4-0314, gpt-4-0613)
|
|
69
|
+
*/
|
|
70
|
+
private modelRequiresMaxCompletionTokens;
|
|
71
|
+
/**
|
|
72
|
+
* Translate messages from AgentRouter format to OpenAI format.
|
|
73
|
+
*
|
|
74
|
+
* Key translations:
|
|
75
|
+
* - Content blocks are flattened to strings
|
|
76
|
+
* - tool_use blocks become tool_calls array on assistant messages
|
|
77
|
+
* - tool_result blocks become separate role: "tool" messages
|
|
78
|
+
*/
|
|
79
|
+
private translateMessages;
|
|
80
|
+
/**
|
|
81
|
+
* Translate tools from AgentRouter format to OpenAI format.
|
|
82
|
+
*/
|
|
83
|
+
private translateTools;
|
|
84
|
+
/**
|
|
85
|
+
* Translate OpenAI response to AgentRouter format.
|
|
86
|
+
*/
|
|
87
|
+
private translateResponse;
|
|
88
|
+
/**
|
|
89
|
+
* Translate OpenAI streaming chunk to AgentRouter StreamChunk format.
|
|
90
|
+
*
|
|
91
|
+
* OpenAI streams deltas that need to be accumulated for tool calls.
|
|
92
|
+
* Text content can be yielded immediately.
|
|
93
|
+
*/
|
|
94
|
+
private translateStreamChunk;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EAIX,cAAc,EACf,MAAM,aAAa,CAAC;AAiHrB;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,SAAgB,IAAI,EAAE,MAAM,CAAY;IAExC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAA+B;gBAE3D,MAAM,EAAE,cAAc;IAIlC;;;OAGG;cACgB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWzD;;OAEG;IACU,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAe9E;;OAEG;IACW,cAAc,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa,CAAC,WAAW,CAAC;IAiFpF;;OAEG;IACU,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAezC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAgCxB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,gCAAgC;IA4BxC;;;;;;;OAOG;IACH,OAAO,CAAC,iBAAiB;IAoFzB;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA8DzB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;CA6F7B"}
|