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,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Provider Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements the Provider interface for OpenAI's Chat Completions API.
|
|
5
|
+
* Handles message 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
|
+
// ============================================================================
|
|
16
|
+
// OpenAI Provider Implementation
|
|
17
|
+
// ============================================================================
|
|
18
|
+
/**
|
|
19
|
+
* OpenAI provider adapter.
|
|
20
|
+
*
|
|
21
|
+
* Translates between AgentRouter's internal message format and OpenAI's
|
|
22
|
+
* Chat Completions API format. Supports both streaming and non-streaming
|
|
23
|
+
* completion requests.
|
|
24
|
+
*/
|
|
25
|
+
export class OpenAIProvider extends BaseProvider {
|
|
26
|
+
name = 'openai';
|
|
27
|
+
static DEFAULT_BASE_URL = 'https://api.openai.com/v1';
|
|
28
|
+
constructor(config) {
|
|
29
|
+
super(config);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build headers for OpenAI API requests.
|
|
33
|
+
* Adds organization header if configured.
|
|
34
|
+
*/
|
|
35
|
+
buildHeaders() {
|
|
36
|
+
const headers = super.buildHeaders();
|
|
37
|
+
// Add organization header if configured
|
|
38
|
+
if (this.config.organization) {
|
|
39
|
+
headers['OpenAI-Organization'] = this.config.organization;
|
|
40
|
+
}
|
|
41
|
+
return headers;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute a completion request and return the full response.
|
|
45
|
+
*/
|
|
46
|
+
async complete(request) {
|
|
47
|
+
const url = `${this.getBaseUrl(OpenAIProvider.DEFAULT_BASE_URL)}/chat/completions`;
|
|
48
|
+
const openAIRequest = this.translateRequest(request);
|
|
49
|
+
const response = await this.makeRequest({
|
|
50
|
+
method: 'POST',
|
|
51
|
+
url,
|
|
52
|
+
headers: this.buildHeaders(),
|
|
53
|
+
body: openAIRequest,
|
|
54
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
55
|
+
});
|
|
56
|
+
return this.translateResponse(response);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Execute a streaming completion request.
|
|
60
|
+
*/
|
|
61
|
+
async *completeStream(request) {
|
|
62
|
+
const url = `${this.getBaseUrl(OpenAIProvider.DEFAULT_BASE_URL)}/chat/completions`;
|
|
63
|
+
const openAIRequest = this.translateRequest({ ...request, stream: true });
|
|
64
|
+
const response = await this.makeStreamingRequest({
|
|
65
|
+
method: 'POST',
|
|
66
|
+
url,
|
|
67
|
+
headers: this.buildHeaders(),
|
|
68
|
+
body: openAIRequest,
|
|
69
|
+
timeoutMs: request.timeout_ms ?? this.defaultTimeoutMs,
|
|
70
|
+
stream: true,
|
|
71
|
+
});
|
|
72
|
+
if (!response.body) {
|
|
73
|
+
throw new Error('No response body for streaming request');
|
|
74
|
+
}
|
|
75
|
+
// Track tool calls being built across chunks
|
|
76
|
+
const toolCallsInProgress = new Map();
|
|
77
|
+
let hasStartedContent = false;
|
|
78
|
+
const reader = response.body.getReader();
|
|
79
|
+
const decoder = new TextDecoder();
|
|
80
|
+
let buffer = '';
|
|
81
|
+
try {
|
|
82
|
+
while (true) {
|
|
83
|
+
const { done, value } = await reader.read();
|
|
84
|
+
if (done) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
buffer += decoder.decode(value, { stream: true });
|
|
88
|
+
// Process complete SSE events
|
|
89
|
+
const lines = buffer.split('\n');
|
|
90
|
+
buffer = lines.pop() || '';
|
|
91
|
+
for (const line of lines) {
|
|
92
|
+
const trimmed = line.trim();
|
|
93
|
+
if (!trimmed || trimmed === 'data: [DONE]') {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (trimmed.startsWith('data: ')) {
|
|
97
|
+
const jsonStr = trimmed.slice(6);
|
|
98
|
+
try {
|
|
99
|
+
const chunk = JSON.parse(jsonStr);
|
|
100
|
+
const chunks = this.translateStreamChunk(chunk, toolCallsInProgress, hasStartedContent);
|
|
101
|
+
for (const streamChunk of chunks) {
|
|
102
|
+
// Track state for content block management
|
|
103
|
+
if (streamChunk.type === 'content_block_start' &&
|
|
104
|
+
streamChunk.content_block?.type === 'text') {
|
|
105
|
+
hasStartedContent = true;
|
|
106
|
+
}
|
|
107
|
+
yield streamChunk;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// Skip malformed JSON chunks
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
reader.releaseLock();
|
|
119
|
+
}
|
|
120
|
+
// Emit message_stop at the end
|
|
121
|
+
yield { type: 'message_stop' };
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if the provider is available and configured correctly.
|
|
125
|
+
*/
|
|
126
|
+
async healthCheck() {
|
|
127
|
+
const url = `${this.getBaseUrl(OpenAIProvider.DEFAULT_BASE_URL)}/models`;
|
|
128
|
+
await this.makeRequest({
|
|
129
|
+
method: 'GET',
|
|
130
|
+
url,
|
|
131
|
+
headers: this.buildHeaders(),
|
|
132
|
+
timeoutMs: 10000,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// ==========================================================================
|
|
136
|
+
// Translation Methods
|
|
137
|
+
// ==========================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Translate AgentRouter request to OpenAI format.
|
|
140
|
+
*
|
|
141
|
+
* Note: Newer OpenAI models (gpt-4o, gpt-4-turbo, o1, etc.) require
|
|
142
|
+
* max_completion_tokens instead of max_tokens. We detect model type
|
|
143
|
+
* and use the appropriate parameter.
|
|
144
|
+
*/
|
|
145
|
+
translateRequest(request) {
|
|
146
|
+
const messages = this.translateMessages(request.messages);
|
|
147
|
+
const tools = request.tools ? this.translateTools(request.tools) : undefined;
|
|
148
|
+
// Newer models require max_completion_tokens instead of max_tokens
|
|
149
|
+
const usesNewTokenParam = this.modelRequiresMaxCompletionTokens(request.model);
|
|
150
|
+
// Debug logging
|
|
151
|
+
console.log(`[OpenAI] Model: ${request.model}, usesNewTokenParam: ${usesNewTokenParam}, max_tokens: ${request.max_tokens}`);
|
|
152
|
+
const result = {
|
|
153
|
+
model: request.model,
|
|
154
|
+
messages,
|
|
155
|
+
temperature: request.temperature,
|
|
156
|
+
tools: tools && tools.length > 0 ? tools : undefined,
|
|
157
|
+
stream: request.stream,
|
|
158
|
+
};
|
|
159
|
+
// Add the appropriate token limit parameter
|
|
160
|
+
if (request.max_tokens !== undefined) {
|
|
161
|
+
if (usesNewTokenParam) {
|
|
162
|
+
result.max_completion_tokens = request.max_tokens;
|
|
163
|
+
console.log(`[OpenAI] Using max_completion_tokens: ${request.max_tokens}`);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
result.max_tokens = request.max_tokens;
|
|
167
|
+
console.log(`[OpenAI] Using max_tokens: ${request.max_tokens}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Check if we're using the actual OpenAI API (not a compatible third-party API).
|
|
174
|
+
* Third-party OpenAI-compatible APIs (Z.AI, DeepSeek, local LLMs, etc.) typically
|
|
175
|
+
* use the standard max_tokens parameter, not max_completion_tokens.
|
|
176
|
+
*/
|
|
177
|
+
isActualOpenAIAPI() {
|
|
178
|
+
const baseUrl = this.getBaseUrl(OpenAIProvider.DEFAULT_BASE_URL);
|
|
179
|
+
// Check if the base URL is OpenAI's official API
|
|
180
|
+
return baseUrl.startsWith('https://api.openai.com');
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Check if a model requires max_completion_tokens instead of max_tokens.
|
|
184
|
+
* Newer OpenAI models (gpt-4o, gpt-4-turbo, gpt-5.x, o1, o3, etc.) use the new parameter.
|
|
185
|
+
*
|
|
186
|
+
* IMPORTANT: This only applies to the actual OpenAI API. Third-party OpenAI-compatible
|
|
187
|
+
* APIs (Z.AI, DeepSeek, Ollama, etc.) use the standard max_tokens parameter.
|
|
188
|
+
*
|
|
189
|
+
* As of late 2024, most new OpenAI models require max_completion_tokens.
|
|
190
|
+
* We default to using max_completion_tokens for any model that:
|
|
191
|
+
* - Contains 'gpt-4o', 'gpt-4-turbo', 'gpt-5', 'o1', 'o3', or 'chatgpt'
|
|
192
|
+
* - OR is NOT a legacy model (gpt-3.5, gpt-4-0314, gpt-4-0613)
|
|
193
|
+
*/
|
|
194
|
+
modelRequiresMaxCompletionTokens(model) {
|
|
195
|
+
// If we're not talking to the actual OpenAI API, always use max_tokens
|
|
196
|
+
// Third-party OpenAI-compatible APIs (Z.AI, DeepSeek, local LLMs, etc.)
|
|
197
|
+
// typically use the standard max_tokens parameter
|
|
198
|
+
if (!this.isActualOpenAIAPI()) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const lowerModel = model.toLowerCase();
|
|
202
|
+
// Legacy models that use max_tokens (the old parameter)
|
|
203
|
+
const legacyModels = [
|
|
204
|
+
'gpt-3.5',
|
|
205
|
+
'gpt-4-0314',
|
|
206
|
+
'gpt-4-0613',
|
|
207
|
+
'gpt-4-32k',
|
|
208
|
+
];
|
|
209
|
+
// If it's a known legacy model, use old parameter
|
|
210
|
+
if (legacyModels.some(m => lowerModel.includes(m))) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
// For all other models (gpt-4o, gpt-4-turbo, gpt-5.x, o1, o3, etc.), use new parameter
|
|
214
|
+
// This is safer as OpenAI is moving toward max_completion_tokens
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Translate messages from AgentRouter format to OpenAI format.
|
|
219
|
+
*
|
|
220
|
+
* Key translations:
|
|
221
|
+
* - Content blocks are flattened to strings
|
|
222
|
+
* - tool_use blocks become tool_calls array on assistant messages
|
|
223
|
+
* - tool_result blocks become separate role: "tool" messages
|
|
224
|
+
*/
|
|
225
|
+
translateMessages(messages) {
|
|
226
|
+
const openAIMessages = [];
|
|
227
|
+
for (const message of messages) {
|
|
228
|
+
if (typeof message.content === 'string') {
|
|
229
|
+
// Simple string content
|
|
230
|
+
openAIMessages.push({
|
|
231
|
+
role: message.role,
|
|
232
|
+
content: message.content,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Content blocks - need to process differently based on type
|
|
237
|
+
const textParts = [];
|
|
238
|
+
const toolCalls = [];
|
|
239
|
+
const toolResults = [];
|
|
240
|
+
for (const block of message.content) {
|
|
241
|
+
switch (block.type) {
|
|
242
|
+
case 'text':
|
|
243
|
+
if (block.text) {
|
|
244
|
+
textParts.push(block.text);
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case 'tool_use':
|
|
248
|
+
if (block.id && block.name) {
|
|
249
|
+
toolCalls.push({
|
|
250
|
+
id: block.id,
|
|
251
|
+
type: 'function',
|
|
252
|
+
function: {
|
|
253
|
+
name: block.name,
|
|
254
|
+
arguments: JSON.stringify(block.input || {}),
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case 'tool_result':
|
|
260
|
+
if (block.tool_use_id && block.content) {
|
|
261
|
+
toolResults.push({
|
|
262
|
+
tool_call_id: block.tool_use_id,
|
|
263
|
+
content: block.content,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Handle assistant messages with tool calls
|
|
270
|
+
if (message.role === 'assistant') {
|
|
271
|
+
const assistantMessage = {
|
|
272
|
+
role: 'assistant',
|
|
273
|
+
content: textParts.length > 0 ? textParts.join('\n') : null,
|
|
274
|
+
};
|
|
275
|
+
if (toolCalls.length > 0) {
|
|
276
|
+
assistantMessage.tool_calls = toolCalls;
|
|
277
|
+
}
|
|
278
|
+
openAIMessages.push(assistantMessage);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
// User messages
|
|
282
|
+
if (textParts.length > 0) {
|
|
283
|
+
openAIMessages.push({
|
|
284
|
+
role: 'user',
|
|
285
|
+
content: textParts.join('\n'),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
// Add tool results as separate messages
|
|
289
|
+
for (const result of toolResults) {
|
|
290
|
+
openAIMessages.push({
|
|
291
|
+
role: 'tool',
|
|
292
|
+
content: result.content,
|
|
293
|
+
tool_call_id: result.tool_call_id,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return openAIMessages;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Translate tools from AgentRouter format to OpenAI format.
|
|
303
|
+
*/
|
|
304
|
+
translateTools(tools) {
|
|
305
|
+
return tools.map((tool) => ({
|
|
306
|
+
type: 'function',
|
|
307
|
+
function: {
|
|
308
|
+
name: tool.name,
|
|
309
|
+
description: tool.description,
|
|
310
|
+
parameters: tool.input_schema,
|
|
311
|
+
},
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Translate OpenAI response to AgentRouter format.
|
|
316
|
+
*/
|
|
317
|
+
translateResponse(response) {
|
|
318
|
+
const choice = response.choices[0];
|
|
319
|
+
if (!choice) {
|
|
320
|
+
throw new Error('No choices in OpenAI response');
|
|
321
|
+
}
|
|
322
|
+
const content = [];
|
|
323
|
+
// Add text content if present
|
|
324
|
+
if (choice.message.content) {
|
|
325
|
+
content.push({
|
|
326
|
+
type: 'text',
|
|
327
|
+
text: choice.message.content,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
// Add tool calls if present
|
|
331
|
+
if (choice.message.tool_calls) {
|
|
332
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
333
|
+
content.push({
|
|
334
|
+
type: 'tool_use',
|
|
335
|
+
id: toolCall.id,
|
|
336
|
+
name: toolCall.function.name,
|
|
337
|
+
input: JSON.parse(toolCall.function.arguments),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
// Map finish_reason to stop_reason
|
|
342
|
+
let stopReason = 'end_turn';
|
|
343
|
+
switch (choice.finish_reason) {
|
|
344
|
+
case 'stop':
|
|
345
|
+
stopReason = 'end_turn';
|
|
346
|
+
break;
|
|
347
|
+
case 'length':
|
|
348
|
+
stopReason = 'max_tokens';
|
|
349
|
+
break;
|
|
350
|
+
case 'tool_calls':
|
|
351
|
+
stopReason = 'tool_use';
|
|
352
|
+
break;
|
|
353
|
+
case 'content_filter':
|
|
354
|
+
stopReason = 'content_filter';
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
const result = {
|
|
358
|
+
id: response.id,
|
|
359
|
+
content,
|
|
360
|
+
model: response.model,
|
|
361
|
+
stop_reason: stopReason,
|
|
362
|
+
};
|
|
363
|
+
if (response.usage) {
|
|
364
|
+
result.usage = {
|
|
365
|
+
input_tokens: response.usage.prompt_tokens,
|
|
366
|
+
output_tokens: response.usage.completion_tokens,
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Translate OpenAI streaming chunk to AgentRouter StreamChunk format.
|
|
373
|
+
*
|
|
374
|
+
* OpenAI streams deltas that need to be accumulated for tool calls.
|
|
375
|
+
* Text content can be yielded immediately.
|
|
376
|
+
*/
|
|
377
|
+
translateStreamChunk(chunk, toolCallsInProgress, hasStartedContent) {
|
|
378
|
+
const chunks = [];
|
|
379
|
+
const choice = chunk.choices[0];
|
|
380
|
+
if (!choice) {
|
|
381
|
+
return chunks;
|
|
382
|
+
}
|
|
383
|
+
const delta = choice.delta;
|
|
384
|
+
// Handle text content
|
|
385
|
+
if (delta.content !== undefined && delta.content !== null) {
|
|
386
|
+
// Emit content_block_start if this is the first content
|
|
387
|
+
if (!hasStartedContent) {
|
|
388
|
+
chunks.push({
|
|
389
|
+
type: 'content_block_start',
|
|
390
|
+
index: 0,
|
|
391
|
+
content_block: {
|
|
392
|
+
type: 'text',
|
|
393
|
+
text: '',
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
// Emit content delta
|
|
398
|
+
chunks.push({
|
|
399
|
+
type: 'content_block_delta',
|
|
400
|
+
index: 0,
|
|
401
|
+
delta: {
|
|
402
|
+
type: 'text_delta',
|
|
403
|
+
text: delta.content,
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
// Handle tool calls
|
|
408
|
+
if (delta.tool_calls) {
|
|
409
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
410
|
+
const index = toolCallDelta.index;
|
|
411
|
+
// Initialize tool call tracking if new
|
|
412
|
+
if (!toolCallsInProgress.has(index)) {
|
|
413
|
+
toolCallsInProgress.set(index, {
|
|
414
|
+
id: toolCallDelta.id || '',
|
|
415
|
+
name: toolCallDelta.function?.name || '',
|
|
416
|
+
arguments: '',
|
|
417
|
+
});
|
|
418
|
+
// Emit content_block_start for tool use
|
|
419
|
+
if (toolCallDelta.id && toolCallDelta.function?.name) {
|
|
420
|
+
chunks.push({
|
|
421
|
+
type: 'content_block_start',
|
|
422
|
+
index: index + 1, // Offset by 1 since text is at index 0
|
|
423
|
+
content_block: {
|
|
424
|
+
type: 'tool_use',
|
|
425
|
+
id: toolCallDelta.id,
|
|
426
|
+
name: toolCallDelta.function.name,
|
|
427
|
+
input: {},
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// Update tool call data
|
|
433
|
+
const toolCall = toolCallsInProgress.get(index);
|
|
434
|
+
if (toolCallDelta.id) {
|
|
435
|
+
toolCall.id = toolCallDelta.id;
|
|
436
|
+
}
|
|
437
|
+
if (toolCallDelta.function?.name) {
|
|
438
|
+
toolCall.name = toolCallDelta.function.name;
|
|
439
|
+
}
|
|
440
|
+
if (toolCallDelta.function?.arguments) {
|
|
441
|
+
toolCall.arguments += toolCallDelta.function.arguments;
|
|
442
|
+
// Emit delta for argument chunks
|
|
443
|
+
chunks.push({
|
|
444
|
+
type: 'content_block_delta',
|
|
445
|
+
index: index + 1,
|
|
446
|
+
delta: {
|
|
447
|
+
type: 'input_json_delta',
|
|
448
|
+
text: toolCallDelta.function.arguments,
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return chunks;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAuHzC,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IAC9B,IAAI,GAAW,QAAQ,CAAC;IAEhC,MAAM,CAAU,gBAAgB,GAAG,2BAA2B,CAAC;IAEvE,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;OAGG;IACgB,YAAY;QAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,YAAY,EAAE,CAAC;QAErC,wCAAwC;QACxC,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YAC7B,OAAO,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;QAC5D,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,QAAQ,CAAC,OAA0B;QAC9C,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,gBAAgB,CAAC,mBAAmB,CAAC;QACnF,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAErD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAiB;YACtD,MAAM,EAAE,MAAM;YACd,GAAG;YACH,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE;YAC5B,IAAI,EAAE,a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C;gBAC9C,CAAC;gBACD,IAAI,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC;oBACtC,QAAQ,CAAC,SAAS,IAAI,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAEvD,iCAAiC;oBACjC,MAAM,CAAC,IAAI,CAAC;wBACV,IAAI,EAAE,qBAAqB;wBAC3B,KAAK,EAAE,KAAK,GAAG,CAAC;wBAChB,KAAK,EAAE;4BACL,IAAI,EAAE,kBAAkB;4BACxB,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,SAAS;yBACvC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z.AI Provider Implementation
|
|
3
|
+
*
|
|
4
|
+
* Z.AI (GLM models) uses an OpenAI-compatible API format.
|
|
5
|
+
* This provider extends OpenAIProvider with the correct name identifier.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIProvider } from './openai.js';
|
|
8
|
+
import type { ProviderConfig } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Z.AI (GLM) API provider adapter.
|
|
11
|
+
*
|
|
12
|
+
* Uses OpenAI-compatible API format but with Z.AI endpoints.
|
|
13
|
+
* Default base URL: https://api.z.ai/api/paas/v4
|
|
14
|
+
*/
|
|
15
|
+
export declare class ZAIProvider extends OpenAIProvider {
|
|
16
|
+
readonly name = "zai";
|
|
17
|
+
constructor(config: ProviderConfig);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=zai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zai.d.ts","sourceRoot":"","sources":["../../src/providers/zai.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,cAAc;IAC7C,SAAyB,IAAI,SAAS;gBAE1B,MAAM,EAAE,cAAc;CAGnC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Z.AI Provider Implementation
|
|
3
|
+
*
|
|
4
|
+
* Z.AI (GLM models) uses an OpenAI-compatible API format.
|
|
5
|
+
* This provider extends OpenAIProvider with the correct name identifier.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAIProvider } from './openai.js';
|
|
8
|
+
/**
|
|
9
|
+
* Z.AI (GLM) API provider adapter.
|
|
10
|
+
*
|
|
11
|
+
* Uses OpenAI-compatible API format but with Z.AI endpoints.
|
|
12
|
+
* Default base URL: https://api.z.ai/api/paas/v4
|
|
13
|
+
*/
|
|
14
|
+
export class ZAIProvider extends OpenAIProvider {
|
|
15
|
+
name = 'zai';
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super(config);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=zai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zai.js","sourceRoot":"","sources":["../../src/providers/zai.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,cAAc;IACpB,IAAI,GAAG,KAAK,CAAC;IAEtC,YAAY,MAAsB;QAChC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.d.ts","sourceRoot":"","sources":["../../src/router/context-manager.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/router/context-manager.ts"],"names":[],"mappings":";AAAA,kBAAkB"}
|