@probelabs/probe 0.6.0-rc167 → 0.6.0-rc169
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/build/agent/ProbeAgent.d.ts +7 -1
- package/build/agent/ProbeAgent.js +353 -32
- package/build/agent/engines/codex.js +347 -0
- package/build/agent/engines/enhanced-claude-code.js +3 -42
- package/build/agent/index.js +1036 -81
- package/build/agent/mcp/built-in-server.js +334 -8
- package/build/agent/shared/Session.js +53 -0
- package/build/agent/shared/prompts.js +129 -0
- package/build/agent/tools.js +26 -9
- package/cjs/agent/ProbeAgent.cjs +1074 -92
- package/cjs/index.cjs +1083 -101
- package/index.d.ts +7 -1
- package/package.json +1 -1
- package/src/agent/ProbeAgent.d.ts +7 -1
- package/src/agent/ProbeAgent.js +353 -32
- package/src/agent/engines/codex.js +347 -0
- package/src/agent/engines/enhanced-claude-code.js +3 -42
- package/src/agent/mcp/built-in-server.js +334 -8
- package/src/agent/shared/Session.js +53 -0
- package/src/agent/shared/prompts.js +129 -0
- package/src/agent/tools.js +26 -9
package/cjs/agent/ProbeAgent.cjs
CHANGED
|
@@ -5308,11 +5308,11 @@ var require_randomUUID = __commonJS({
|
|
|
5308
5308
|
var require_dist_cjs19 = __commonJS({
|
|
5309
5309
|
"node_modules/@smithy/uuid/dist-cjs/index.js"(exports2) {
|
|
5310
5310
|
"use strict";
|
|
5311
|
-
var
|
|
5311
|
+
var randomUUID6 = require_randomUUID();
|
|
5312
5312
|
var decimalToHex = Array.from({ length: 256 }, (_, i4) => i4.toString(16).padStart(2, "0"));
|
|
5313
5313
|
var v4 = () => {
|
|
5314
|
-
if (
|
|
5315
|
-
return
|
|
5314
|
+
if (randomUUID6.randomUUID) {
|
|
5315
|
+
return randomUUID6.randomUUID();
|
|
5316
5316
|
}
|
|
5317
5317
|
const rnds = new Uint8Array(16);
|
|
5318
5318
|
crypto.getRandomValues(rnds);
|
|
@@ -17003,7 +17003,7 @@ var require_package2 = __commonJS({
|
|
|
17003
17003
|
module2.exports = {
|
|
17004
17004
|
name: "@aws-sdk/client-bedrock-runtime",
|
|
17005
17005
|
description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
|
|
17006
|
-
version: "3.
|
|
17006
|
+
version: "3.938.0",
|
|
17007
17007
|
scripts: {
|
|
17008
17008
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
17009
17009
|
"build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
|
|
@@ -23276,6 +23276,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
23276
23276
|
var _A2 = "Accept";
|
|
23277
23277
|
var _ADE3 = "AccessDeniedException";
|
|
23278
23278
|
var _AG = "ApplyGuardrail";
|
|
23279
|
+
var _AGD = "AppliedGuardrailDetails";
|
|
23279
23280
|
var _AGR = "ApplyGuardrailRequest";
|
|
23280
23281
|
var _AGRp = "ApplyGuardrailResponse";
|
|
23281
23282
|
var _AIM = "AsyncInvokeMessage";
|
|
@@ -23491,6 +23492,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
23491
23492
|
var _XABST = "X-Amzn-Bedrock-Service-Tier";
|
|
23492
23493
|
var _XABT = "X-Amzn-Bedrock-Trace";
|
|
23493
23494
|
var _a16 = "action";
|
|
23495
|
+
var _aGD = "appliedGuardrailDetails";
|
|
23494
23496
|
var _aIS = "asyncInvokeSummaries";
|
|
23495
23497
|
var _aMRF = "additionalModelRequestFields";
|
|
23496
23498
|
var _aMRFP = "additionalModelResponseFieldPaths";
|
|
@@ -23554,10 +23556,14 @@ var require_dist_cjs66 = __commonJS({
|
|
|
23554
23556
|
var _fi = "findings";
|
|
23555
23557
|
var _fil = "filters";
|
|
23556
23558
|
var _g = "guardrail";
|
|
23559
|
+
var _gA = "guardrailArn";
|
|
23557
23560
|
var _gC = "guardrailCoverage";
|
|
23558
23561
|
var _gCu = "guardrailConfig";
|
|
23559
23562
|
var _gCua = "guardContent";
|
|
23560
|
-
var _gI = "
|
|
23563
|
+
var _gI = "guardrailId";
|
|
23564
|
+
var _gIu = "guardrailIdentifier";
|
|
23565
|
+
var _gO = "guardrailOrigin";
|
|
23566
|
+
var _gOu = "guardrailOwnership";
|
|
23561
23567
|
var _gPL = "guardrailProcessingLatency";
|
|
23562
23568
|
var _gV = "guardrailVersion";
|
|
23563
23569
|
var _gu = "guarded";
|
|
@@ -23728,12 +23734,20 @@ var require_dist_cjs66 = __commonJS({
|
|
|
23728
23734
|
];
|
|
23729
23735
|
schema.TypeRegistry.for(n04).registerError(AccessDeniedException5, AccessDeniedException$1);
|
|
23730
23736
|
var AnyToolChoice = [3, n04, _ATC, 0, [], []];
|
|
23737
|
+
var AppliedGuardrailDetails = [
|
|
23738
|
+
3,
|
|
23739
|
+
n04,
|
|
23740
|
+
_AGD,
|
|
23741
|
+
0,
|
|
23742
|
+
[_gI, _gV, _gA, _gO, _gOu],
|
|
23743
|
+
[0, 0, 0, 64 | 0, 0]
|
|
23744
|
+
];
|
|
23731
23745
|
var ApplyGuardrailRequest = [
|
|
23732
23746
|
3,
|
|
23733
23747
|
n04,
|
|
23734
23748
|
_AGR,
|
|
23735
23749
|
0,
|
|
23736
|
-
[
|
|
23750
|
+
[_gIu, _gV, _s4, _co3, _oS],
|
|
23737
23751
|
[[0, 1], [0, 1], 0, [() => GuardrailContentBlockList, 0], 0]
|
|
23738
23752
|
];
|
|
23739
23753
|
var ApplyGuardrailResponse = [
|
|
@@ -23963,7 +23977,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
23963
23977
|
n04,
|
|
23964
23978
|
_GA,
|
|
23965
23979
|
0,
|
|
23966
|
-
[_tP, _cP, _wP, _sIP, _cGP, _aRP, _iM],
|
|
23980
|
+
[_tP, _cP, _wP, _sIP, _cGP, _aRP, _iM, _aGD],
|
|
23967
23981
|
[
|
|
23968
23982
|
() => GuardrailTopicPolicyAssessment,
|
|
23969
23983
|
() => GuardrailContentPolicyAssessment,
|
|
@@ -23971,7 +23985,8 @@ var require_dist_cjs66 = __commonJS({
|
|
|
23971
23985
|
() => GuardrailSensitiveInformationPolicyAssessment,
|
|
23972
23986
|
() => GuardrailContextualGroundingPolicyAssessment,
|
|
23973
23987
|
[() => GuardrailAutomatedReasoningPolicyAssessment, 0],
|
|
23974
|
-
() => GuardrailInvocationMetrics
|
|
23988
|
+
() => GuardrailInvocationMetrics,
|
|
23989
|
+
() => AppliedGuardrailDetails
|
|
23975
23990
|
]
|
|
23976
23991
|
];
|
|
23977
23992
|
var GuardrailAutomatedReasoningImpossibleFinding = [
|
|
@@ -24103,7 +24118,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
24103
24118
|
[() => GuardrailAutomatedReasoningLogicWarning, 0]
|
|
24104
24119
|
]
|
|
24105
24120
|
];
|
|
24106
|
-
var GuardrailConfiguration = [3, n04, _GC, 0, [
|
|
24121
|
+
var GuardrailConfiguration = [3, n04, _GC, 0, [_gIu, _gV, _tr], [0, 0, 0]];
|
|
24107
24122
|
var GuardrailContentFilter = [3, n04, _GCF, 0, [_t, _conf, _fS, _a16, _de], [0, 0, 0, 0, 2]];
|
|
24108
24123
|
var GuardrailContentPolicyAssessment = [
|
|
24109
24124
|
3,
|
|
@@ -24176,7 +24191,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
24176
24191
|
[_pE, _re],
|
|
24177
24192
|
[() => GuardrailPiiEntityFilterList, () => GuardrailRegexFilterList]
|
|
24178
24193
|
];
|
|
24179
|
-
var GuardrailStreamConfiguration = [3, n04, _GSC, 0, [
|
|
24194
|
+
var GuardrailStreamConfiguration = [3, n04, _GSC, 0, [_gIu, _gV, _tr, _sPM], [0, 0, 0, 0]];
|
|
24180
24195
|
var GuardrailTextBlock = [3, n04, _GTB, 0, [_te, _q], [0, 64 | 0]];
|
|
24181
24196
|
var GuardrailTextCharactersCoverage = [3, n04, _GTCC, 0, [_gu, _to], [1, 1]];
|
|
24182
24197
|
var GuardrailTopic = [3, n04, _GT, 0, [_n, _t, _a16, _de], [0, 0, 0, 2]];
|
|
@@ -24231,7 +24246,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
24231
24246
|
n04,
|
|
24232
24247
|
_IMR,
|
|
24233
24248
|
0,
|
|
24234
|
-
[_bo, _cT, _ac, _mI, _tr,
|
|
24249
|
+
[_bo, _cT, _ac, _mI, _tr, _gIu, _gV, _pCL, _sTe],
|
|
24235
24250
|
[
|
|
24236
24251
|
[() => Body, 16],
|
|
24237
24252
|
[
|
|
@@ -24332,7 +24347,7 @@ var require_dist_cjs66 = __commonJS({
|
|
|
24332
24347
|
n04,
|
|
24333
24348
|
_IMWRSR,
|
|
24334
24349
|
0,
|
|
24335
|
-
[_bo, _cT, _ac, _mI, _tr,
|
|
24350
|
+
[_bo, _cT, _ac, _mI, _tr, _gIu, _gV, _pCL, _sTe],
|
|
24336
24351
|
[
|
|
24337
24352
|
[() => Body, 16],
|
|
24338
24353
|
[
|
|
@@ -25151,6 +25166,15 @@ var require_dist_cjs66 = __commonJS({
|
|
|
25151
25166
|
GUARDRAIL_INTERVENED: "GUARDRAIL_INTERVENED",
|
|
25152
25167
|
NONE: "NONE"
|
|
25153
25168
|
};
|
|
25169
|
+
var GuardrailOrigin = {
|
|
25170
|
+
ACCOUNT_ENFORCED: "ACCOUNT_ENFORCED",
|
|
25171
|
+
ORGANIZATION_ENFORCED: "ORGANIZATION_ENFORCED",
|
|
25172
|
+
REQUEST: "REQUEST"
|
|
25173
|
+
};
|
|
25174
|
+
var GuardrailOwnership = {
|
|
25175
|
+
CROSS_ACCOUNT: "CROSS_ACCOUNT",
|
|
25176
|
+
SELF: "SELF"
|
|
25177
|
+
};
|
|
25154
25178
|
var GuardrailAutomatedReasoningLogicWarningType = {
|
|
25155
25179
|
ALWAYS_FALSE: "ALWAYS_FALSE",
|
|
25156
25180
|
ALWAYS_TRUE: "ALWAYS_TRUE"
|
|
@@ -25362,7 +25386,9 @@ var require_dist_cjs66 = __commonJS({
|
|
|
25362
25386
|
exports2.GuardrailConverseImageFormat = GuardrailConverseImageFormat;
|
|
25363
25387
|
exports2.GuardrailImageFormat = GuardrailImageFormat;
|
|
25364
25388
|
exports2.GuardrailManagedWordType = GuardrailManagedWordType;
|
|
25389
|
+
exports2.GuardrailOrigin = GuardrailOrigin;
|
|
25365
25390
|
exports2.GuardrailOutputScope = GuardrailOutputScope;
|
|
25391
|
+
exports2.GuardrailOwnership = GuardrailOwnership;
|
|
25366
25392
|
exports2.GuardrailPiiEntityType = GuardrailPiiEntityType;
|
|
25367
25393
|
exports2.GuardrailSensitiveInformationPolicyAction = GuardrailSensitiveInformationPolicyAction;
|
|
25368
25394
|
exports2.GuardrailStreamProcessingMode = GuardrailStreamProcessingMode;
|
|
@@ -34323,8 +34349,8 @@ var init_vercel = __esm({
|
|
|
34323
34349
|
const { writeFileSync: writeFileSync2, unlinkSync } = await import("fs");
|
|
34324
34350
|
const { join: join3 } = await import("path");
|
|
34325
34351
|
const { tmpdir } = await import("os");
|
|
34326
|
-
const { randomUUID:
|
|
34327
|
-
tempFilePath = join3(tmpdir(), `probe-extract-${
|
|
34352
|
+
const { randomUUID: randomUUID6 } = await import("crypto");
|
|
34353
|
+
tempFilePath = join3(tmpdir(), `probe-extract-${randomUUID6()}.txt`);
|
|
34328
34354
|
writeFileSync2(tempFilePath, input_content);
|
|
34329
34355
|
if (debug) {
|
|
34330
34356
|
console.error(`Created temporary file for input content: ${tempFilePath}`);
|
|
@@ -43363,17 +43389,30 @@ var init_xmlParsingUtils = __esm({
|
|
|
43363
43389
|
|
|
43364
43390
|
// src/agent/tools.js
|
|
43365
43391
|
function createTools(configOptions) {
|
|
43366
|
-
const tools2 = {
|
|
43367
|
-
|
|
43368
|
-
|
|
43369
|
-
|
|
43370
|
-
|
|
43371
|
-
|
|
43372
|
-
|
|
43392
|
+
const tools2 = {};
|
|
43393
|
+
const isToolAllowed = configOptions.isToolAllowed || ((toolName) => {
|
|
43394
|
+
if (!configOptions.allowedTools) return true;
|
|
43395
|
+
return configOptions.allowedTools.isEnabled(toolName);
|
|
43396
|
+
});
|
|
43397
|
+
if (isToolAllowed("search")) {
|
|
43398
|
+
tools2.searchTool = searchTool(configOptions);
|
|
43399
|
+
}
|
|
43400
|
+
if (isToolAllowed("query")) {
|
|
43401
|
+
tools2.queryTool = queryTool(configOptions);
|
|
43402
|
+
}
|
|
43403
|
+
if (isToolAllowed("extract")) {
|
|
43404
|
+
tools2.extractTool = extractTool(configOptions);
|
|
43405
|
+
}
|
|
43406
|
+
if (configOptions.enableDelegate && isToolAllowed("delegate")) {
|
|
43407
|
+
tools2.delegateTool = delegateTool(configOptions);
|
|
43408
|
+
}
|
|
43409
|
+
if (configOptions.enableBash && isToolAllowed("bash")) {
|
|
43373
43410
|
tools2.bashTool = bashTool(configOptions);
|
|
43374
43411
|
}
|
|
43375
|
-
if (configOptions.allowEdit) {
|
|
43412
|
+
if (configOptions.allowEdit && isToolAllowed("edit")) {
|
|
43376
43413
|
tools2.editTool = editTool(configOptions);
|
|
43414
|
+
}
|
|
43415
|
+
if (configOptions.allowEdit && isToolAllowed("create")) {
|
|
43377
43416
|
tools2.createTool = createTool(configOptions);
|
|
43378
43417
|
}
|
|
43379
43418
|
return tools2;
|
|
@@ -81658,6 +81697,126 @@ Provide only the corrected Mermaid diagram within a mermaid code block. Do not a
|
|
|
81658
81697
|
}
|
|
81659
81698
|
});
|
|
81660
81699
|
|
|
81700
|
+
// src/agent/shared/prompts.js
|
|
81701
|
+
var predefinedPrompts;
|
|
81702
|
+
var init_prompts = __esm({
|
|
81703
|
+
"src/agent/shared/prompts.js"() {
|
|
81704
|
+
"use strict";
|
|
81705
|
+
predefinedPrompts = {
|
|
81706
|
+
"code-explorer": `You are ProbeChat Code Explorer - an AI assistant focused on reading and explaining code using Probe's semantic search capabilities.
|
|
81707
|
+
|
|
81708
|
+
Your primary role is to explore codebases, understand code structure, and provide clear explanations. You should:
|
|
81709
|
+
|
|
81710
|
+
1. Use the 'search' tool to find relevant code snippets across the codebase
|
|
81711
|
+
2. Use the 'query' tool to locate specific symbols, functions, or classes
|
|
81712
|
+
3. Use the 'extract' tool to get full context for files or specific code blocks
|
|
81713
|
+
4. Explain code behavior, architecture patterns, and relationships between components
|
|
81714
|
+
5. Provide concise summaries with key insights highlighted
|
|
81715
|
+
|
|
81716
|
+
When exploring code:
|
|
81717
|
+
- Start with targeted searches to find relevant areas
|
|
81718
|
+
- Extract full context when you need to understand implementation details
|
|
81719
|
+
- Trace function calls and data flow to understand how components interact
|
|
81720
|
+
- Focus on "why" and "how" rather than just describing what the code does
|
|
81721
|
+
|
|
81722
|
+
You should NOT:
|
|
81723
|
+
- Make changes to the codebase (read-only access)
|
|
81724
|
+
- Execute or run code
|
|
81725
|
+
- Make assumptions without verifying through search/query/extract`,
|
|
81726
|
+
"architect": `You are ProbeChat Architect - a senior software architect specialized in analyzing and designing software systems.
|
|
81727
|
+
|
|
81728
|
+
Your role is to:
|
|
81729
|
+
|
|
81730
|
+
1. Analyze existing codebases to understand architecture patterns and design decisions
|
|
81731
|
+
2. Identify architectural issues, technical debt, and improvement opportunities
|
|
81732
|
+
3. Propose refactoring strategies and architectural changes
|
|
81733
|
+
4. Design new features that fit well with existing architecture
|
|
81734
|
+
5. Create high-level architecture diagrams and documentation
|
|
81735
|
+
|
|
81736
|
+
When analyzing architecture:
|
|
81737
|
+
- Use search/query/extract to understand component boundaries and dependencies
|
|
81738
|
+
- Identify layers, modules, and their responsibilities
|
|
81739
|
+
- Look for patterns like MVC, microservices, event-driven, etc.
|
|
81740
|
+
- Assess coupling, cohesion, and separation of concerns
|
|
81741
|
+
- Consider scalability, maintainability, and testability
|
|
81742
|
+
|
|
81743
|
+
When proposing changes:
|
|
81744
|
+
- Provide clear rationale backed by architectural principles
|
|
81745
|
+
- Consider migration paths and backwards compatibility
|
|
81746
|
+
- Identify risks and tradeoffs
|
|
81747
|
+
- Suggest incremental implementation steps`,
|
|
81748
|
+
"code-review": `You are ProbeChat Code Reviewer - a meticulous code reviewer focused on quality, best practices, and maintainability.
|
|
81749
|
+
|
|
81750
|
+
Your role is to:
|
|
81751
|
+
|
|
81752
|
+
1. Review code changes for correctness, clarity, and best practices
|
|
81753
|
+
2. Identify bugs, security issues, and performance problems
|
|
81754
|
+
3. Suggest improvements for readability and maintainability
|
|
81755
|
+
4. Ensure consistency with project conventions and patterns
|
|
81756
|
+
5. Verify test coverage and edge case handling
|
|
81757
|
+
|
|
81758
|
+
When reviewing code:
|
|
81759
|
+
- Use search to find similar patterns in the codebase for consistency
|
|
81760
|
+
- Look for common issues: null checks, error handling, resource leaks
|
|
81761
|
+
- Check for security vulnerabilities: injection, XSS, etc.
|
|
81762
|
+
- Assess complexity and suggest simplifications
|
|
81763
|
+
- Verify naming conventions and code organization
|
|
81764
|
+
|
|
81765
|
+
Provide constructive feedback:
|
|
81766
|
+
- Start with what's good about the code
|
|
81767
|
+
- Be specific about issues with examples
|
|
81768
|
+
- Suggest concrete improvements with code snippets
|
|
81769
|
+
- Prioritize critical issues over style preferences
|
|
81770
|
+
- Explain the "why" behind your suggestions`,
|
|
81771
|
+
"engineer": `You are a senior engineer who helps implement features and fix bugs.
|
|
81772
|
+
|
|
81773
|
+
Your role is to:
|
|
81774
|
+
|
|
81775
|
+
1. Implement new features following project conventions
|
|
81776
|
+
2. Fix bugs by understanding root causes
|
|
81777
|
+
3. Refactor code to improve quality
|
|
81778
|
+
4. Write clear, maintainable code
|
|
81779
|
+
5. Add appropriate tests and documentation
|
|
81780
|
+
|
|
81781
|
+
When implementing:
|
|
81782
|
+
- Use search/query to understand existing patterns
|
|
81783
|
+
- Follow the project's coding style and conventions
|
|
81784
|
+
- Consider edge cases and error handling
|
|
81785
|
+
- Write self-documenting code with clear names
|
|
81786
|
+
- Add comments for complex logic
|
|
81787
|
+
|
|
81788
|
+
You have access to:
|
|
81789
|
+
- search: Find relevant code patterns
|
|
81790
|
+
- query: Locate specific symbols/functions
|
|
81791
|
+
- extract: Get full file context
|
|
81792
|
+
- implement: Create or modify files (use carefully)
|
|
81793
|
+
- delegate: Break down complex tasks`,
|
|
81794
|
+
"support": `You are ProbeChat Support - a helpful assistant focused on answering questions about codebases.
|
|
81795
|
+
|
|
81796
|
+
Your role is to:
|
|
81797
|
+
|
|
81798
|
+
1. Answer questions about how code works
|
|
81799
|
+
2. Help users locate specific functionality
|
|
81800
|
+
3. Explain error messages and debugging approaches
|
|
81801
|
+
4. Guide users to relevant documentation
|
|
81802
|
+
5. Provide examples and usage patterns
|
|
81803
|
+
|
|
81804
|
+
When helping users:
|
|
81805
|
+
- Ask clarifying questions if the request is ambiguous
|
|
81806
|
+
- Use search/query to find relevant code quickly
|
|
81807
|
+
- Provide clear, step-by-step explanations
|
|
81808
|
+
- Include code examples when helpful
|
|
81809
|
+
- Point to relevant files and line numbers
|
|
81810
|
+
|
|
81811
|
+
You should be:
|
|
81812
|
+
- Patient and encouraging
|
|
81813
|
+
- Clear and concise
|
|
81814
|
+
- Thorough but not overwhelming
|
|
81815
|
+
- Honest about limitations (say "I don't know" when appropriate)`
|
|
81816
|
+
};
|
|
81817
|
+
}
|
|
81818
|
+
});
|
|
81819
|
+
|
|
81661
81820
|
// src/agent/mcp/config.js
|
|
81662
81821
|
function loadMCPConfigurationFromPath(configPath) {
|
|
81663
81822
|
if (!configPath) {
|
|
@@ -83195,14 +83354,58 @@ var init_contextCompactor = __esm({
|
|
|
83195
83354
|
});
|
|
83196
83355
|
|
|
83197
83356
|
// src/agent/mcp/built-in-server.js
|
|
83198
|
-
var import_http, import_events2, import_server, import_types3, BuiltInMCPServer;
|
|
83357
|
+
var import_http, import_events2, import_crypto5, import_server, import_sse2, import_streamableHttp, import_types3, InMemoryEventStore, BuiltInMCPServer;
|
|
83199
83358
|
var init_built_in_server = __esm({
|
|
83200
83359
|
"src/agent/mcp/built-in-server.js"() {
|
|
83201
83360
|
"use strict";
|
|
83202
83361
|
import_http = require("http");
|
|
83203
83362
|
import_events2 = require("events");
|
|
83363
|
+
import_crypto5 = require("crypto");
|
|
83204
83364
|
import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
83365
|
+
import_sse2 = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
83366
|
+
import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
83205
83367
|
import_types3 = require("@modelcontextprotocol/sdk/types.js");
|
|
83368
|
+
InMemoryEventStore = class {
|
|
83369
|
+
constructor() {
|
|
83370
|
+
this.events = /* @__PURE__ */ new Map();
|
|
83371
|
+
}
|
|
83372
|
+
generateEventId(streamId) {
|
|
83373
|
+
return `${streamId}_${Date.now()}_${Math.random().toString(36).substring(2, 10)}`;
|
|
83374
|
+
}
|
|
83375
|
+
getStreamIdFromEventId(eventId) {
|
|
83376
|
+
const parts = eventId.split("_");
|
|
83377
|
+
return parts.length > 0 ? parts[0] : "";
|
|
83378
|
+
}
|
|
83379
|
+
async storeEvent(streamId, message) {
|
|
83380
|
+
const eventId = this.generateEventId(streamId);
|
|
83381
|
+
this.events.set(eventId, { streamId, message });
|
|
83382
|
+
return eventId;
|
|
83383
|
+
}
|
|
83384
|
+
async replayEventsAfter(lastEventId, { send }) {
|
|
83385
|
+
if (!lastEventId || !this.events.has(lastEventId)) {
|
|
83386
|
+
return "";
|
|
83387
|
+
}
|
|
83388
|
+
const streamId = this.getStreamIdFromEventId(lastEventId);
|
|
83389
|
+
if (!streamId) {
|
|
83390
|
+
return "";
|
|
83391
|
+
}
|
|
83392
|
+
let foundLastEvent = false;
|
|
83393
|
+
const sortedEvents = [...this.events.entries()].sort((a4, b4) => a4[0].localeCompare(b4[0]));
|
|
83394
|
+
for (const [eventId, { streamId: eventStreamId, message }] of sortedEvents) {
|
|
83395
|
+
if (eventStreamId !== streamId) {
|
|
83396
|
+
continue;
|
|
83397
|
+
}
|
|
83398
|
+
if (eventId === lastEventId) {
|
|
83399
|
+
foundLastEvent = true;
|
|
83400
|
+
continue;
|
|
83401
|
+
}
|
|
83402
|
+
if (foundLastEvent) {
|
|
83403
|
+
await send(eventId, message);
|
|
83404
|
+
}
|
|
83405
|
+
}
|
|
83406
|
+
return streamId;
|
|
83407
|
+
}
|
|
83408
|
+
};
|
|
83206
83409
|
BuiltInMCPServer = class extends import_events2.EventEmitter {
|
|
83207
83410
|
constructor(agent, options = {}) {
|
|
83208
83411
|
super();
|
|
@@ -83211,6 +83414,8 @@ var init_built_in_server = __esm({
|
|
|
83211
83414
|
this.host = options.host || "127.0.0.1";
|
|
83212
83415
|
this.httpServer = null;
|
|
83213
83416
|
this.mcpServer = null;
|
|
83417
|
+
this.sseTransports = /* @__PURE__ */ new Map();
|
|
83418
|
+
this.streamableTransports = /* @__PURE__ */ new Map();
|
|
83214
83419
|
this.connections = /* @__PURE__ */ new Set();
|
|
83215
83420
|
this.debug = options.debug || false;
|
|
83216
83421
|
}
|
|
@@ -83232,11 +83437,13 @@ var init_built_in_server = __esm({
|
|
|
83232
83437
|
});
|
|
83233
83438
|
this.registerHandlers();
|
|
83234
83439
|
return new Promise((resolve5, reject2) => {
|
|
83235
|
-
this.httpServer.listen(this.port, this.host, () => {
|
|
83440
|
+
this.httpServer.listen(this.port, this.host, async () => {
|
|
83236
83441
|
const address = this.httpServer.address();
|
|
83237
83442
|
this.port = address.port;
|
|
83238
83443
|
if (this.debug) {
|
|
83239
83444
|
console.log(`[MCP] Built-in server started at http://${this.host}:${this.port}`);
|
|
83445
|
+
console.log(`[MCP] SSE endpoint: http://${this.host}:${this.port}/sse`);
|
|
83446
|
+
console.log(`[MCP] Messages endpoint: http://${this.host}:${this.port}/messages`);
|
|
83240
83447
|
}
|
|
83241
83448
|
this.emit("ready", { host: this.host, port: this.port });
|
|
83242
83449
|
resolve5({ host: this.host, port: this.port });
|
|
@@ -83249,6 +83456,9 @@ var init_built_in_server = __esm({
|
|
|
83249
83456
|
*/
|
|
83250
83457
|
handleRequest(req, res) {
|
|
83251
83458
|
const { method, url } = req;
|
|
83459
|
+
if (this.debug) {
|
|
83460
|
+
console.log(`[MCP] Request: ${method} ${url}`);
|
|
83461
|
+
}
|
|
83252
83462
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
83253
83463
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
83254
83464
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
@@ -83258,15 +83468,22 @@ var init_built_in_server = __esm({
|
|
|
83258
83468
|
return;
|
|
83259
83469
|
}
|
|
83260
83470
|
if (url === "/sse" && method === "GET") {
|
|
83261
|
-
this.
|
|
83471
|
+
if (this.debug) {
|
|
83472
|
+
console.log("[MCP] Routing to handleSSEConnection");
|
|
83473
|
+
}
|
|
83474
|
+
this.handleSSEConnection(req, res);
|
|
83475
|
+
return;
|
|
83476
|
+
}
|
|
83477
|
+
if (url.startsWith("/messages") && method === "POST") {
|
|
83478
|
+
this.handleSSEMessage(req, res);
|
|
83262
83479
|
return;
|
|
83263
83480
|
}
|
|
83264
83481
|
if (url === "/rpc" && method === "POST") {
|
|
83265
83482
|
this.handleJSONRPC(req, res);
|
|
83266
83483
|
return;
|
|
83267
83484
|
}
|
|
83268
|
-
if (url === "/mcp"
|
|
83269
|
-
this.
|
|
83485
|
+
if (url === "/mcp") {
|
|
83486
|
+
this.handleStreamableHTTP(req, res);
|
|
83270
83487
|
return;
|
|
83271
83488
|
}
|
|
83272
83489
|
if (url === "/health") {
|
|
@@ -83282,7 +83499,190 @@ var init_built_in_server = __esm({
|
|
|
83282
83499
|
res.end("Not Found");
|
|
83283
83500
|
}
|
|
83284
83501
|
/**
|
|
83285
|
-
* Handle
|
|
83502
|
+
* Handle SSE connection (GET /sse) - creates new transport
|
|
83503
|
+
*/
|
|
83504
|
+
async handleSSEConnection(req, res) {
|
|
83505
|
+
if (this.debug) {
|
|
83506
|
+
console.log("[MCP] New SSE connection request");
|
|
83507
|
+
}
|
|
83508
|
+
const transport = new import_sse2.SSEServerTransport("/messages", res);
|
|
83509
|
+
this.sseTransports.set(transport.sessionId, transport);
|
|
83510
|
+
res.on("close", () => {
|
|
83511
|
+
if (this.debug) {
|
|
83512
|
+
console.log("[MCP] SSE connection closed, sessionId:", transport.sessionId);
|
|
83513
|
+
}
|
|
83514
|
+
this.sseTransports.delete(transport.sessionId);
|
|
83515
|
+
});
|
|
83516
|
+
try {
|
|
83517
|
+
await this.mcpServer.connect(transport);
|
|
83518
|
+
if (this.debug) {
|
|
83519
|
+
console.log("[MCP] MCP server connected to SSE transport, sessionId:", transport.sessionId);
|
|
83520
|
+
}
|
|
83521
|
+
} catch (error2) {
|
|
83522
|
+
if (this.debug) {
|
|
83523
|
+
console.error("[MCP] Error connecting MCP server to transport:", error2);
|
|
83524
|
+
}
|
|
83525
|
+
this.sseTransports.delete(transport.sessionId);
|
|
83526
|
+
}
|
|
83527
|
+
}
|
|
83528
|
+
/**
|
|
83529
|
+
* Handle SSE message (POST /messages?sessionId=...) - routes to existing transport
|
|
83530
|
+
*/
|
|
83531
|
+
async handleSSEMessage(req, res) {
|
|
83532
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
83533
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
83534
|
+
if (!sessionId) {
|
|
83535
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
83536
|
+
res.end(JSON.stringify({
|
|
83537
|
+
jsonrpc: "2.0",
|
|
83538
|
+
error: {
|
|
83539
|
+
code: -32e3,
|
|
83540
|
+
message: "Bad Request: sessionId query parameter is required"
|
|
83541
|
+
},
|
|
83542
|
+
id: null
|
|
83543
|
+
}));
|
|
83544
|
+
return;
|
|
83545
|
+
}
|
|
83546
|
+
const transport = this.sseTransports.get(sessionId);
|
|
83547
|
+
if (!transport) {
|
|
83548
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
83549
|
+
res.end(JSON.stringify({
|
|
83550
|
+
jsonrpc: "2.0",
|
|
83551
|
+
error: {
|
|
83552
|
+
code: -32e3,
|
|
83553
|
+
message: `Bad Request: No transport found for sessionId: ${sessionId}`
|
|
83554
|
+
},
|
|
83555
|
+
id: null
|
|
83556
|
+
}));
|
|
83557
|
+
return;
|
|
83558
|
+
}
|
|
83559
|
+
let body = "";
|
|
83560
|
+
req.on("data", (chunk) => {
|
|
83561
|
+
body += chunk.toString();
|
|
83562
|
+
});
|
|
83563
|
+
req.on("end", async () => {
|
|
83564
|
+
try {
|
|
83565
|
+
const message = JSON.parse(body);
|
|
83566
|
+
await transport.handlePostMessage(req, res, message);
|
|
83567
|
+
} catch (error2) {
|
|
83568
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
83569
|
+
res.end(JSON.stringify({
|
|
83570
|
+
jsonrpc: "2.0",
|
|
83571
|
+
error: {
|
|
83572
|
+
code: -32603,
|
|
83573
|
+
message: "Internal error",
|
|
83574
|
+
data: error2.message
|
|
83575
|
+
},
|
|
83576
|
+
id: null
|
|
83577
|
+
}));
|
|
83578
|
+
}
|
|
83579
|
+
});
|
|
83580
|
+
}
|
|
83581
|
+
/**
|
|
83582
|
+
* Handle Streamable HTTP protocol (GET/POST/DELETE on /mcp)
|
|
83583
|
+
*/
|
|
83584
|
+
async handleStreamableHTTP(req, res) {
|
|
83585
|
+
const { method } = req;
|
|
83586
|
+
if (this.debug) {
|
|
83587
|
+
console.log(`[MCP] Streamable HTTP ${method} request`);
|
|
83588
|
+
}
|
|
83589
|
+
try {
|
|
83590
|
+
let body = null;
|
|
83591
|
+
if (method === "POST") {
|
|
83592
|
+
body = await this.parseRequestBody(req);
|
|
83593
|
+
}
|
|
83594
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
83595
|
+
let transport;
|
|
83596
|
+
if (sessionId && this.streamableTransports.has(sessionId)) {
|
|
83597
|
+
transport = this.streamableTransports.get(sessionId);
|
|
83598
|
+
if (this.debug) {
|
|
83599
|
+
console.log(`[MCP] Reusing existing transport for session: ${sessionId}`);
|
|
83600
|
+
}
|
|
83601
|
+
} else if (!sessionId && method === "POST" && body && (0, import_types3.isInitializeRequest)(body)) {
|
|
83602
|
+
if (this.debug) {
|
|
83603
|
+
console.log("[MCP] Creating new Streamable HTTP transport for initialization");
|
|
83604
|
+
}
|
|
83605
|
+
const eventStore = new InMemoryEventStore();
|
|
83606
|
+
transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
83607
|
+
sessionIdGenerator: () => (0, import_crypto5.randomUUID)(),
|
|
83608
|
+
eventStore,
|
|
83609
|
+
// Enable resumability
|
|
83610
|
+
onsessioninitialized: (newSessionId) => {
|
|
83611
|
+
if (this.debug) {
|
|
83612
|
+
console.log(`[MCP] Streamable HTTP session initialized: ${newSessionId}`);
|
|
83613
|
+
}
|
|
83614
|
+
this.streamableTransports.set(newSessionId, transport);
|
|
83615
|
+
},
|
|
83616
|
+
onsessionclosed: (closedSessionId) => {
|
|
83617
|
+
if (this.debug) {
|
|
83618
|
+
console.log(`[MCP] Streamable HTTP session closed: ${closedSessionId}`);
|
|
83619
|
+
}
|
|
83620
|
+
this.streamableTransports.delete(closedSessionId);
|
|
83621
|
+
}
|
|
83622
|
+
});
|
|
83623
|
+
transport.onclose = () => {
|
|
83624
|
+
const sid = transport.sessionId;
|
|
83625
|
+
if (sid && this.streamableTransports.has(sid)) {
|
|
83626
|
+
if (this.debug) {
|
|
83627
|
+
console.log(`[MCP] Transport closed for session ${sid}`);
|
|
83628
|
+
}
|
|
83629
|
+
this.streamableTransports.delete(sid);
|
|
83630
|
+
}
|
|
83631
|
+
};
|
|
83632
|
+
await this.mcpServer.connect(transport);
|
|
83633
|
+
} else {
|
|
83634
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
83635
|
+
res.end(JSON.stringify({
|
|
83636
|
+
jsonrpc: "2.0",
|
|
83637
|
+
error: {
|
|
83638
|
+
code: -32e3,
|
|
83639
|
+
message: "Bad Request: No valid session ID provided or not an initialization request"
|
|
83640
|
+
},
|
|
83641
|
+
id: null
|
|
83642
|
+
}));
|
|
83643
|
+
return;
|
|
83644
|
+
}
|
|
83645
|
+
await transport.handleRequest(req, res, body);
|
|
83646
|
+
} catch (error2) {
|
|
83647
|
+
if (this.debug) {
|
|
83648
|
+
console.error("[MCP] Error handling Streamable HTTP request:", error2);
|
|
83649
|
+
}
|
|
83650
|
+
if (!res.headersSent) {
|
|
83651
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
83652
|
+
res.end(JSON.stringify({
|
|
83653
|
+
jsonrpc: "2.0",
|
|
83654
|
+
error: {
|
|
83655
|
+
code: -32603,
|
|
83656
|
+
message: "Internal server error",
|
|
83657
|
+
data: error2.message
|
|
83658
|
+
},
|
|
83659
|
+
id: null
|
|
83660
|
+
}));
|
|
83661
|
+
}
|
|
83662
|
+
}
|
|
83663
|
+
}
|
|
83664
|
+
/**
|
|
83665
|
+
* Parse request body as JSON
|
|
83666
|
+
*/
|
|
83667
|
+
async parseRequestBody(req) {
|
|
83668
|
+
return new Promise((resolve5, reject2) => {
|
|
83669
|
+
let body = "";
|
|
83670
|
+
req.on("data", (chunk) => {
|
|
83671
|
+
body += chunk.toString();
|
|
83672
|
+
});
|
|
83673
|
+
req.on("end", () => {
|
|
83674
|
+
try {
|
|
83675
|
+
const parsed = body ? JSON.parse(body) : null;
|
|
83676
|
+
resolve5(parsed);
|
|
83677
|
+
} catch (error2) {
|
|
83678
|
+
reject2(error2);
|
|
83679
|
+
}
|
|
83680
|
+
});
|
|
83681
|
+
req.on("error", reject2);
|
|
83682
|
+
});
|
|
83683
|
+
}
|
|
83684
|
+
/**
|
|
83685
|
+
* Handle Server-Sent Events connection (DEPRECATED - use handleSSEConnection instead)
|
|
83286
83686
|
*/
|
|
83287
83687
|
handleSSE(req, res) {
|
|
83288
83688
|
res.writeHead(200, {
|
|
@@ -83549,6 +83949,32 @@ data: ${JSON.stringify(data2)}
|
|
|
83549
83949
|
* Stop the server
|
|
83550
83950
|
*/
|
|
83551
83951
|
async stop() {
|
|
83952
|
+
for (const [sessionId, transport] of this.streamableTransports.entries()) {
|
|
83953
|
+
try {
|
|
83954
|
+
await transport.close();
|
|
83955
|
+
if (this.debug) {
|
|
83956
|
+
console.log(`[MCP] Closed Streamable HTTP transport for session: ${sessionId}`);
|
|
83957
|
+
}
|
|
83958
|
+
} catch (error2) {
|
|
83959
|
+
if (this.debug) {
|
|
83960
|
+
console.error(`[MCP] Error closing Streamable HTTP transport ${sessionId}:`, error2);
|
|
83961
|
+
}
|
|
83962
|
+
}
|
|
83963
|
+
}
|
|
83964
|
+
this.streamableTransports.clear();
|
|
83965
|
+
for (const [sessionId, transport] of this.sseTransports.entries()) {
|
|
83966
|
+
try {
|
|
83967
|
+
await transport.close();
|
|
83968
|
+
if (this.debug) {
|
|
83969
|
+
console.log(`[MCP] Closed SSE transport for session: ${sessionId}`);
|
|
83970
|
+
}
|
|
83971
|
+
} catch (error2) {
|
|
83972
|
+
if (this.debug) {
|
|
83973
|
+
console.error(`[MCP] Error closing SSE transport ${sessionId}:`, error2);
|
|
83974
|
+
}
|
|
83975
|
+
}
|
|
83976
|
+
}
|
|
83977
|
+
this.sseTransports.clear();
|
|
83552
83978
|
for (const connection of this.connections) {
|
|
83553
83979
|
connection.end();
|
|
83554
83980
|
}
|
|
@@ -83580,6 +84006,59 @@ data: ${JSON.stringify(data2)}
|
|
|
83580
84006
|
}
|
|
83581
84007
|
});
|
|
83582
84008
|
|
|
84009
|
+
// src/agent/shared/Session.js
|
|
84010
|
+
var Session;
|
|
84011
|
+
var init_Session = __esm({
|
|
84012
|
+
"src/agent/shared/Session.js"() {
|
|
84013
|
+
"use strict";
|
|
84014
|
+
Session = class {
|
|
84015
|
+
constructor(id, debug = false) {
|
|
84016
|
+
this.id = id;
|
|
84017
|
+
this.conversationId = null;
|
|
84018
|
+
this.messageCount = 0;
|
|
84019
|
+
this.debug = debug;
|
|
84020
|
+
}
|
|
84021
|
+
/**
|
|
84022
|
+
* Set the conversation ID for session resumption
|
|
84023
|
+
* @param {string} conversationId - Provider's conversation/thread ID
|
|
84024
|
+
*/
|
|
84025
|
+
setConversationId(conversationId) {
|
|
84026
|
+
this.conversationId = conversationId;
|
|
84027
|
+
if (this.debug) {
|
|
84028
|
+
console.log(`[Session ${this.id}] Conversation ID: ${conversationId}`);
|
|
84029
|
+
}
|
|
84030
|
+
}
|
|
84031
|
+
/**
|
|
84032
|
+
* Increment the message count
|
|
84033
|
+
*/
|
|
84034
|
+
incrementMessageCount() {
|
|
84035
|
+
this.messageCount++;
|
|
84036
|
+
}
|
|
84037
|
+
/**
|
|
84038
|
+
* Get session info as plain object
|
|
84039
|
+
* @returns {Object} Session information
|
|
84040
|
+
*/
|
|
84041
|
+
getInfo() {
|
|
84042
|
+
return {
|
|
84043
|
+
id: this.id,
|
|
84044
|
+
conversationId: this.conversationId,
|
|
84045
|
+
messageCount: this.messageCount
|
|
84046
|
+
};
|
|
84047
|
+
}
|
|
84048
|
+
/**
|
|
84049
|
+
* Get resume arguments for CLI commands (used by Claude Code)
|
|
84050
|
+
* @returns {Array<string>} CLI arguments for resuming conversation
|
|
84051
|
+
*/
|
|
84052
|
+
getResumeArgs() {
|
|
84053
|
+
if (this.conversationId && this.messageCount > 0) {
|
|
84054
|
+
return ["--resume", this.conversationId];
|
|
84055
|
+
}
|
|
84056
|
+
return [];
|
|
84057
|
+
}
|
|
84058
|
+
};
|
|
84059
|
+
}
|
|
84060
|
+
});
|
|
84061
|
+
|
|
83583
84062
|
// src/agent/engines/enhanced-claude-code.js
|
|
83584
84063
|
var enhanced_claude_code_exports = {};
|
|
83585
84064
|
__export(enhanced_claude_code_exports, {
|
|
@@ -83587,8 +84066,8 @@ __export(enhanced_claude_code_exports, {
|
|
|
83587
84066
|
});
|
|
83588
84067
|
async function createEnhancedClaudeCLIEngine(options = {}) {
|
|
83589
84068
|
const { agent, systemPrompt, customPrompt, debug, sessionId, allowedTools } = options;
|
|
83590
|
-
const session = new
|
|
83591
|
-
sessionId || (0,
|
|
84069
|
+
const session = new Session(
|
|
84070
|
+
sessionId || (0, import_crypto6.randomBytes)(8).toString("hex"),
|
|
83592
84071
|
debug
|
|
83593
84072
|
);
|
|
83594
84073
|
let mcpServer = null;
|
|
@@ -83798,11 +84277,7 @@ ${opts.schema}`;
|
|
|
83798
84277
|
* Get session info
|
|
83799
84278
|
*/
|
|
83800
84279
|
getSession() {
|
|
83801
|
-
return
|
|
83802
|
-
id: session.id,
|
|
83803
|
-
conversationId: session.conversationId,
|
|
83804
|
-
messageCount: session.messageCount
|
|
83805
|
-
};
|
|
84280
|
+
return session.getInfo();
|
|
83806
84281
|
},
|
|
83807
84282
|
/**
|
|
83808
84283
|
* Clean up - MUST be called to stop MCP server and clean resources
|
|
@@ -83983,46 +84458,293 @@ function combinePrompts(systemPrompt, customPrompt, agent) {
|
|
|
83983
84458
|
}
|
|
83984
84459
|
return systemPrompt || "";
|
|
83985
84460
|
}
|
|
83986
|
-
var import_child_process9,
|
|
84461
|
+
var import_child_process9, import_crypto6, import_promises2, import_path11, import_os4, import_events3;
|
|
83987
84462
|
var init_enhanced_claude_code = __esm({
|
|
83988
84463
|
"src/agent/engines/enhanced-claude-code.js"() {
|
|
83989
84464
|
"use strict";
|
|
83990
84465
|
import_child_process9 = require("child_process");
|
|
83991
|
-
|
|
84466
|
+
import_crypto6 = require("crypto");
|
|
83992
84467
|
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
83993
84468
|
import_path11 = __toESM(require("path"), 1);
|
|
83994
84469
|
import_os4 = __toESM(require("os"), 1);
|
|
83995
84470
|
import_events3 = require("events");
|
|
83996
84471
|
init_built_in_server();
|
|
83997
|
-
|
|
83998
|
-
|
|
83999
|
-
|
|
84000
|
-
|
|
84001
|
-
|
|
84002
|
-
|
|
84472
|
+
init_Session();
|
|
84473
|
+
}
|
|
84474
|
+
});
|
|
84475
|
+
|
|
84476
|
+
// src/agent/engines/codex.js
|
|
84477
|
+
var codex_exports = {};
|
|
84478
|
+
__export(codex_exports, {
|
|
84479
|
+
createCodexEngine: () => createCodexEngine
|
|
84480
|
+
});
|
|
84481
|
+
async function createCodexEngine(options = {}) {
|
|
84482
|
+
const { agent, systemPrompt, customPrompt, debug, sessionId, allowedTools, model } = options;
|
|
84483
|
+
const session = new Session(
|
|
84484
|
+
sessionId || (0, import_crypto7.randomBytes)(8).toString("hex"),
|
|
84485
|
+
debug
|
|
84486
|
+
);
|
|
84487
|
+
let mcpServer = null;
|
|
84488
|
+
let mcpServerUrl = null;
|
|
84489
|
+
let mcpServerName = null;
|
|
84490
|
+
if (agent) {
|
|
84491
|
+
mcpServer = new BuiltInMCPServer(agent, {
|
|
84492
|
+
port: 0,
|
|
84493
|
+
host: "127.0.0.1",
|
|
84494
|
+
debug
|
|
84495
|
+
});
|
|
84496
|
+
const { host, port } = await mcpServer.start();
|
|
84497
|
+
mcpServerUrl = `http://${host}:${port}/mcp`;
|
|
84498
|
+
mcpServerName = `probe_${session.id}`;
|
|
84499
|
+
if (debug) {
|
|
84500
|
+
console.log("[DEBUG] Built-in Probe MCP server started");
|
|
84501
|
+
console.log("[DEBUG] Probe MCP URL:", mcpServerUrl);
|
|
84502
|
+
}
|
|
84503
|
+
}
|
|
84504
|
+
if (debug) {
|
|
84505
|
+
console.log("[DEBUG] Starting Codex MCP server...");
|
|
84506
|
+
}
|
|
84507
|
+
const codexProcess = (0, import_child_process10.spawn)("codex", ["mcp-server"], {
|
|
84508
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
84509
|
+
});
|
|
84510
|
+
let requestId = 0;
|
|
84511
|
+
const pendingRequests = /* @__PURE__ */ new Map();
|
|
84512
|
+
const eventHandlers = /* @__PURE__ */ new Map();
|
|
84513
|
+
const stdoutReader = (0, import_readline.createInterface)({
|
|
84514
|
+
input: codexProcess.stdout,
|
|
84515
|
+
crlfDelay: Infinity
|
|
84516
|
+
});
|
|
84517
|
+
stdoutReader.on("line", (line) => {
|
|
84518
|
+
try {
|
|
84519
|
+
const message = JSON.parse(line);
|
|
84520
|
+
if (debug) {
|
|
84521
|
+
if (message.method === "codex/event") {
|
|
84522
|
+
console.log(`[DEBUG] Codex event: ${message.params?.msg?.type}`);
|
|
84523
|
+
}
|
|
84003
84524
|
}
|
|
84004
|
-
|
|
84005
|
-
|
|
84006
|
-
|
|
84007
|
-
|
|
84008
|
-
|
|
84009
|
-
|
|
84010
|
-
|
|
84525
|
+
if (message.id !== void 0 && pendingRequests.has(message.id)) {
|
|
84526
|
+
const { resolve: resolve5, reject: reject2 } = pendingRequests.get(message.id);
|
|
84527
|
+
pendingRequests.delete(message.id);
|
|
84528
|
+
if (message.error) {
|
|
84529
|
+
reject2(new Error(message.error.message || JSON.stringify(message.error)));
|
|
84530
|
+
} else {
|
|
84531
|
+
resolve5(message.result);
|
|
84011
84532
|
}
|
|
84012
84533
|
}
|
|
84013
|
-
|
|
84014
|
-
|
|
84015
|
-
|
|
84016
|
-
|
|
84017
|
-
if (this.conversationId && this.messageCount > 0) {
|
|
84018
|
-
return ["--resume", this.conversationId];
|
|
84534
|
+
if (message.method === "codex/event" && message.params) {
|
|
84535
|
+
const requestId2 = message.params._meta?.requestId;
|
|
84536
|
+
if (requestId2 !== void 0 && eventHandlers.has(requestId2)) {
|
|
84537
|
+
eventHandlers.get(requestId2)(message.params);
|
|
84019
84538
|
}
|
|
84020
|
-
return [];
|
|
84021
84539
|
}
|
|
84022
|
-
|
|
84023
|
-
|
|
84540
|
+
} catch (e4) {
|
|
84541
|
+
if (debug) {
|
|
84542
|
+
console.error("[DEBUG] Failed to parse message:", line);
|
|
84024
84543
|
}
|
|
84025
|
-
}
|
|
84544
|
+
}
|
|
84545
|
+
});
|
|
84546
|
+
if (debug) {
|
|
84547
|
+
codexProcess.stderr.on("data", (data2) => {
|
|
84548
|
+
console.error("[CODEX STDERR]", data2.toString());
|
|
84549
|
+
});
|
|
84550
|
+
}
|
|
84551
|
+
function sendRequest(method, params = {}) {
|
|
84552
|
+
return new Promise((resolve5, reject2) => {
|
|
84553
|
+
const id = ++requestId;
|
|
84554
|
+
const request = {
|
|
84555
|
+
jsonrpc: "2.0",
|
|
84556
|
+
id,
|
|
84557
|
+
method,
|
|
84558
|
+
params
|
|
84559
|
+
};
|
|
84560
|
+
pendingRequests.set(id, { resolve: resolve5, reject: reject2 });
|
|
84561
|
+
setTimeout(() => {
|
|
84562
|
+
if (pendingRequests.has(id)) {
|
|
84563
|
+
pendingRequests.delete(id);
|
|
84564
|
+
reject2(new Error(`Request ${method} timed out after 10 minutes`));
|
|
84565
|
+
}
|
|
84566
|
+
}, 6e5);
|
|
84567
|
+
codexProcess.stdin.write(JSON.stringify(request) + "\n");
|
|
84568
|
+
});
|
|
84569
|
+
}
|
|
84570
|
+
await sendRequest("initialize", {
|
|
84571
|
+
protocolVersion: "2024-11-05",
|
|
84572
|
+
capabilities: { tools: {} },
|
|
84573
|
+
clientInfo: {
|
|
84574
|
+
name: "probe-codex-client",
|
|
84575
|
+
version: "1.0.0"
|
|
84576
|
+
}
|
|
84577
|
+
});
|
|
84578
|
+
if (debug) {
|
|
84579
|
+
console.log("[DEBUG] Connected to Codex MCP server");
|
|
84580
|
+
console.log("[DEBUG] Session:", session.id);
|
|
84581
|
+
}
|
|
84582
|
+
const fullPrompt = combinePrompts2(systemPrompt, customPrompt, agent);
|
|
84583
|
+
return {
|
|
84584
|
+
sessionId: session.id,
|
|
84585
|
+
session,
|
|
84586
|
+
/**
|
|
84587
|
+
* Query Codex via MCP protocol with event streaming
|
|
84588
|
+
*/
|
|
84589
|
+
async *query(prompt, opts = {}) {
|
|
84590
|
+
let finalPrompt = prompt;
|
|
84591
|
+
if (!session.conversationId && fullPrompt) {
|
|
84592
|
+
finalPrompt = `${fullPrompt}
|
|
84593
|
+
|
|
84594
|
+
${prompt}`;
|
|
84595
|
+
}
|
|
84596
|
+
const isFollowUp = session.conversationId !== null;
|
|
84597
|
+
const toolName = isFollowUp ? "codex-reply" : "codex";
|
|
84598
|
+
const toolArgs = { prompt: finalPrompt };
|
|
84599
|
+
if (isFollowUp) {
|
|
84600
|
+
toolArgs.conversationId = session.conversationId;
|
|
84601
|
+
if (debug) {
|
|
84602
|
+
console.log(`[DEBUG] Follow-up with conversationId: ${session.conversationId}`);
|
|
84603
|
+
}
|
|
84604
|
+
} else {
|
|
84605
|
+
if (model) {
|
|
84606
|
+
toolArgs.model = model;
|
|
84607
|
+
}
|
|
84608
|
+
if (mcpServerUrl && mcpServerName) {
|
|
84609
|
+
toolArgs.config = {
|
|
84610
|
+
mcp_servers: {
|
|
84611
|
+
[mcpServerName]: { url: mcpServerUrl }
|
|
84612
|
+
}
|
|
84613
|
+
};
|
|
84614
|
+
}
|
|
84615
|
+
if (debug) {
|
|
84616
|
+
console.log(`[DEBUG] Initial query with tool: ${toolName}`);
|
|
84617
|
+
}
|
|
84618
|
+
}
|
|
84619
|
+
try {
|
|
84620
|
+
const reqId = requestId + 1;
|
|
84621
|
+
let fullResponse = "";
|
|
84622
|
+
let gotSessionId = false;
|
|
84623
|
+
const eventPromise = new Promise((resolve5) => {
|
|
84624
|
+
eventHandlers.set(reqId, (eventParams) => {
|
|
84625
|
+
const msg = eventParams.msg;
|
|
84626
|
+
if (msg.type === "session_configured" && msg.session_id && !gotSessionId) {
|
|
84627
|
+
session.setConversationId(msg.session_id);
|
|
84628
|
+
gotSessionId = true;
|
|
84629
|
+
}
|
|
84630
|
+
if (msg.type === "raw_response_item" && msg.item?.role === "assistant") {
|
|
84631
|
+
const content = msg.item.content;
|
|
84632
|
+
if (Array.isArray(content)) {
|
|
84633
|
+
for (const part of content) {
|
|
84634
|
+
if (part.type === "text" && part.text) {
|
|
84635
|
+
fullResponse += part.text;
|
|
84636
|
+
}
|
|
84637
|
+
}
|
|
84638
|
+
}
|
|
84639
|
+
}
|
|
84640
|
+
});
|
|
84641
|
+
setTimeout(() => {
|
|
84642
|
+
eventHandlers.delete(reqId);
|
|
84643
|
+
resolve5();
|
|
84644
|
+
}, 6e5);
|
|
84645
|
+
});
|
|
84646
|
+
const resultPromise = sendRequest("tools/call", {
|
|
84647
|
+
name: toolName,
|
|
84648
|
+
arguments: toolArgs
|
|
84649
|
+
});
|
|
84650
|
+
const result = await resultPromise;
|
|
84651
|
+
eventHandlers.delete(reqId);
|
|
84652
|
+
if (result && result.content && Array.isArray(result.content)) {
|
|
84653
|
+
for (const item of result.content) {
|
|
84654
|
+
if (item.type === "text" && item.text) {
|
|
84655
|
+
yield {
|
|
84656
|
+
type: "text",
|
|
84657
|
+
content: item.text
|
|
84658
|
+
};
|
|
84659
|
+
fullResponse = item.text;
|
|
84660
|
+
}
|
|
84661
|
+
}
|
|
84662
|
+
}
|
|
84663
|
+
if (fullResponse && (!result.content || result.content.length === 0)) {
|
|
84664
|
+
yield {
|
|
84665
|
+
type: "text",
|
|
84666
|
+
content: fullResponse
|
|
84667
|
+
};
|
|
84668
|
+
}
|
|
84669
|
+
session.incrementMessageCount();
|
|
84670
|
+
yield {
|
|
84671
|
+
type: "metadata",
|
|
84672
|
+
data: {
|
|
84673
|
+
sessionId: session.id,
|
|
84674
|
+
conversationId: session.conversationId,
|
|
84675
|
+
messageCount: session.messageCount
|
|
84676
|
+
}
|
|
84677
|
+
};
|
|
84678
|
+
} catch (error2) {
|
|
84679
|
+
if (debug) {
|
|
84680
|
+
console.error("[DEBUG] Codex query error:", error2);
|
|
84681
|
+
}
|
|
84682
|
+
yield {
|
|
84683
|
+
type: "error",
|
|
84684
|
+
error: error2
|
|
84685
|
+
};
|
|
84686
|
+
}
|
|
84687
|
+
},
|
|
84688
|
+
/**
|
|
84689
|
+
* Get session info
|
|
84690
|
+
*/
|
|
84691
|
+
getSession() {
|
|
84692
|
+
return session.getInfo();
|
|
84693
|
+
},
|
|
84694
|
+
/**
|
|
84695
|
+
* Clean up resources
|
|
84696
|
+
*/
|
|
84697
|
+
async close() {
|
|
84698
|
+
try {
|
|
84699
|
+
if (stdoutReader) {
|
|
84700
|
+
stdoutReader.close();
|
|
84701
|
+
if (debug) {
|
|
84702
|
+
console.log("[DEBUG] Closed stdout reader");
|
|
84703
|
+
}
|
|
84704
|
+
}
|
|
84705
|
+
pendingRequests.clear();
|
|
84706
|
+
eventHandlers.clear();
|
|
84707
|
+
if (codexProcess && !codexProcess.killed) {
|
|
84708
|
+
codexProcess.kill();
|
|
84709
|
+
if (debug) {
|
|
84710
|
+
console.log("[DEBUG] Killed Codex MCP server process");
|
|
84711
|
+
}
|
|
84712
|
+
}
|
|
84713
|
+
if (mcpServer) {
|
|
84714
|
+
await mcpServer.stop();
|
|
84715
|
+
if (debug) {
|
|
84716
|
+
console.log("[DEBUG] Stopped Probe MCP server");
|
|
84717
|
+
}
|
|
84718
|
+
}
|
|
84719
|
+
if (debug) {
|
|
84720
|
+
console.log("[DEBUG] Engine closed, session:", session.id);
|
|
84721
|
+
}
|
|
84722
|
+
} catch (error2) {
|
|
84723
|
+
if (debug) {
|
|
84724
|
+
console.error("[DEBUG] Error during cleanup:", error2.message);
|
|
84725
|
+
}
|
|
84726
|
+
}
|
|
84727
|
+
}
|
|
84728
|
+
};
|
|
84729
|
+
}
|
|
84730
|
+
function combinePrompts2(systemPrompt, customPrompt, agent) {
|
|
84731
|
+
if (!systemPrompt && customPrompt) {
|
|
84732
|
+
return customPrompt;
|
|
84733
|
+
}
|
|
84734
|
+
if (systemPrompt && customPrompt) {
|
|
84735
|
+
return systemPrompt + "\n\n## Additional Instructions\n" + customPrompt;
|
|
84736
|
+
}
|
|
84737
|
+
return systemPrompt || "";
|
|
84738
|
+
}
|
|
84739
|
+
var import_child_process10, import_crypto7, import_readline;
|
|
84740
|
+
var init_codex = __esm({
|
|
84741
|
+
"src/agent/engines/codex.js"() {
|
|
84742
|
+
"use strict";
|
|
84743
|
+
import_child_process10 = require("child_process");
|
|
84744
|
+
import_crypto7 = require("crypto");
|
|
84745
|
+
import_readline = require("readline");
|
|
84746
|
+
init_built_in_server();
|
|
84747
|
+
init_Session();
|
|
84026
84748
|
}
|
|
84027
84749
|
});
|
|
84028
84750
|
|
|
@@ -84101,7 +84823,7 @@ __export(ProbeAgent_exports, {
|
|
|
84101
84823
|
ProbeAgent: () => ProbeAgent
|
|
84102
84824
|
});
|
|
84103
84825
|
module.exports = __toCommonJS(ProbeAgent_exports);
|
|
84104
|
-
var import_dotenv2, import_anthropic2, import_openai2, import_google2, import_ai5,
|
|
84826
|
+
var import_dotenv2, import_anthropic2, import_openai2, import_google2, import_ai5, import_crypto8, import_events4, import_fs10, import_promises3, import_path12, MAX_TOOL_ITERATIONS, MAX_HISTORY_MESSAGES, MAX_IMAGE_FILE_SIZE, ProbeAgent;
|
|
84105
84827
|
var init_ProbeAgent = __esm({
|
|
84106
84828
|
"src/agent/ProbeAgent.js"() {
|
|
84107
84829
|
import_dotenv2 = __toESM(require_main(), 1);
|
|
@@ -84110,7 +84832,7 @@ var init_ProbeAgent = __esm({
|
|
|
84110
84832
|
import_google2 = require("@ai-sdk/google");
|
|
84111
84833
|
init_dist3();
|
|
84112
84834
|
import_ai5 = require("ai");
|
|
84113
|
-
|
|
84835
|
+
import_crypto8 = require("crypto");
|
|
84114
84836
|
import_events4 = require("events");
|
|
84115
84837
|
import_fs10 = require("fs");
|
|
84116
84838
|
import_promises3 = require("fs/promises");
|
|
@@ -84126,6 +84848,7 @@ var init_ProbeAgent = __esm({
|
|
|
84126
84848
|
init_index();
|
|
84127
84849
|
init_schemaUtils();
|
|
84128
84850
|
init_xmlParsingUtils();
|
|
84851
|
+
init_prompts();
|
|
84129
84852
|
init_mcp();
|
|
84130
84853
|
init_RetryManager();
|
|
84131
84854
|
init_FallbackManager();
|
|
@@ -84147,6 +84870,7 @@ var init_ProbeAgent = __esm({
|
|
|
84147
84870
|
* @param {Object} options - Configuration options
|
|
84148
84871
|
* @param {string} [options.sessionId] - Optional session ID
|
|
84149
84872
|
* @param {string} [options.customPrompt] - Custom prompt to replace the default system message
|
|
84873
|
+
* @param {string} [options.systemPrompt] - Alias for customPrompt; takes precedence when both are provided
|
|
84150
84874
|
* @param {string} [options.promptType] - Predefined prompt type (architect, code-review, support)
|
|
84151
84875
|
* @param {boolean} [options.allowEdit=false] - Allow the use of the 'implement' tool
|
|
84152
84876
|
* @param {boolean} [options.enableDelegate=false] - Enable the delegate tool for task distribution to subagents
|
|
@@ -84181,8 +84905,8 @@ var init_ProbeAgent = __esm({
|
|
|
84181
84905
|
* @param {number} [options.fallback.maxTotalAttempts=10] - Maximum total attempts across all providers
|
|
84182
84906
|
*/
|
|
84183
84907
|
constructor(options = {}) {
|
|
84184
|
-
this.sessionId = options.sessionId || (0,
|
|
84185
|
-
this.customPrompt = options.customPrompt || null;
|
|
84908
|
+
this.sessionId = options.sessionId || (0, import_crypto8.randomUUID)();
|
|
84909
|
+
this.customPrompt = options.systemPrompt || options.customPrompt || null;
|
|
84186
84910
|
this.promptType = options.promptType || "code-explorer";
|
|
84187
84911
|
this.allowEdit = !!options.allowEdit;
|
|
84188
84912
|
this.enableDelegate = !!options.enableDelegate;
|
|
@@ -84306,9 +85030,10 @@ var init_ProbeAgent = __esm({
|
|
|
84306
85030
|
* This method initializes MCP and merges MCP tools into the tool list, and loads history from storage
|
|
84307
85031
|
*/
|
|
84308
85032
|
async initialize() {
|
|
84309
|
-
if (!this.provider && !this.clientApiProvider && this.apiType !== "claude-code") {
|
|
85033
|
+
if (!this.provider && !this.clientApiProvider && this.apiType !== "claude-code" && this.apiType !== "codex") {
|
|
84310
85034
|
if (this.apiType === "uninitialized") {
|
|
84311
85035
|
const claudeAvailable = await this.isClaudeCommandAvailable();
|
|
85036
|
+
const codexAvailable = await this.isCodexCommandAvailable();
|
|
84312
85037
|
if (claudeAvailable) {
|
|
84313
85038
|
if (this.debug) {
|
|
84314
85039
|
console.log("[DEBUG] No API keys found, but claude command detected");
|
|
@@ -84318,8 +85043,17 @@ var init_ProbeAgent = __esm({
|
|
|
84318
85043
|
this.provider = null;
|
|
84319
85044
|
this.model = this.clientApiModel || "claude-3-5-sonnet-20241022";
|
|
84320
85045
|
this.apiType = "claude-code";
|
|
85046
|
+
} else if (codexAvailable) {
|
|
85047
|
+
if (this.debug) {
|
|
85048
|
+
console.log("[DEBUG] No API keys found, but codex command detected");
|
|
85049
|
+
console.log("[DEBUG] Auto-switching to codex provider");
|
|
85050
|
+
}
|
|
85051
|
+
this.clientApiProvider = "codex";
|
|
85052
|
+
this.provider = null;
|
|
85053
|
+
this.model = this.clientApiModel || "gpt-4o";
|
|
85054
|
+
this.apiType = "codex";
|
|
84321
85055
|
} else {
|
|
84322
|
-
throw new Error("No API key provided and claude command
|
|
85056
|
+
throw new Error("No API key provided and neither claude nor codex command found. Please either:\n1. Set an API key: ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, or AWS credentials\n2. Install claude command from https://docs.claude.com/en/docs/claude-code\n3. Install codex command from https://openai.com/codex");
|
|
84323
85057
|
}
|
|
84324
85058
|
}
|
|
84325
85059
|
}
|
|
@@ -84382,25 +85116,43 @@ var init_ProbeAgent = __esm({
|
|
|
84382
85116
|
* Initialize tools with configuration
|
|
84383
85117
|
*/
|
|
84384
85118
|
initializeTools() {
|
|
85119
|
+
const isToolAllowed = (toolName) => this.allowedTools.isEnabled(toolName);
|
|
84385
85120
|
const configOptions = {
|
|
84386
85121
|
sessionId: this.sessionId,
|
|
84387
85122
|
debug: this.debug,
|
|
84388
85123
|
defaultPath: this.allowedFolders.length > 0 ? this.allowedFolders[0] : process.cwd(),
|
|
84389
85124
|
allowedFolders: this.allowedFolders,
|
|
84390
85125
|
outline: this.outline,
|
|
85126
|
+
allowEdit: this.allowEdit,
|
|
85127
|
+
enableDelegate: this.enableDelegate,
|
|
84391
85128
|
enableBash: this.enableBash,
|
|
84392
|
-
bashConfig: this.bashConfig
|
|
85129
|
+
bashConfig: this.bashConfig,
|
|
85130
|
+
allowedTools: this.allowedTools,
|
|
85131
|
+
isToolAllowed
|
|
84393
85132
|
};
|
|
84394
85133
|
const baseTools = createTools(configOptions);
|
|
84395
85134
|
const wrappedTools = createWrappedTools(baseTools);
|
|
84396
|
-
this.toolImplementations = {
|
|
84397
|
-
|
|
84398
|
-
|
|
84399
|
-
|
|
84400
|
-
|
|
84401
|
-
|
|
84402
|
-
|
|
84403
|
-
|
|
85135
|
+
this.toolImplementations = {};
|
|
85136
|
+
if (wrappedTools.searchToolInstance && isToolAllowed("search")) {
|
|
85137
|
+
this.toolImplementations.search = wrappedTools.searchToolInstance;
|
|
85138
|
+
}
|
|
85139
|
+
if (wrappedTools.queryToolInstance && isToolAllowed("query")) {
|
|
85140
|
+
this.toolImplementations.query = wrappedTools.queryToolInstance;
|
|
85141
|
+
}
|
|
85142
|
+
if (wrappedTools.extractToolInstance && isToolAllowed("extract")) {
|
|
85143
|
+
this.toolImplementations.extract = wrappedTools.extractToolInstance;
|
|
85144
|
+
}
|
|
85145
|
+
if (this.enableDelegate && wrappedTools.delegateToolInstance && isToolAllowed("delegate")) {
|
|
85146
|
+
this.toolImplementations.delegate = wrappedTools.delegateToolInstance;
|
|
85147
|
+
}
|
|
85148
|
+
if (isToolAllowed("listFiles")) {
|
|
85149
|
+
this.toolImplementations.listFiles = listFilesToolInstance;
|
|
85150
|
+
}
|
|
85151
|
+
if (isToolAllowed("searchFiles")) {
|
|
85152
|
+
this.toolImplementations.searchFiles = searchFilesToolInstance;
|
|
85153
|
+
}
|
|
85154
|
+
if (isToolAllowed("readImage")) {
|
|
85155
|
+
this.toolImplementations.readImage = {
|
|
84404
85156
|
execute: async (params) => {
|
|
84405
85157
|
const imagePath = params.path;
|
|
84406
85158
|
if (!imagePath) {
|
|
@@ -84412,16 +85164,16 @@ var init_ProbeAgent = __esm({
|
|
|
84412
85164
|
}
|
|
84413
85165
|
return `Image loaded successfully: ${imagePath}. The image is now available for analysis in the conversation.`;
|
|
84414
85166
|
}
|
|
84415
|
-
}
|
|
84416
|
-
}
|
|
84417
|
-
if (this.enableBash && wrappedTools.bashToolInstance) {
|
|
85167
|
+
};
|
|
85168
|
+
}
|
|
85169
|
+
if (this.enableBash && wrappedTools.bashToolInstance && isToolAllowed("bash")) {
|
|
84418
85170
|
this.toolImplementations.bash = wrappedTools.bashToolInstance;
|
|
84419
85171
|
}
|
|
84420
85172
|
if (this.allowEdit) {
|
|
84421
|
-
if (wrappedTools.editToolInstance) {
|
|
85173
|
+
if (wrappedTools.editToolInstance && isToolAllowed("edit")) {
|
|
84422
85174
|
this.toolImplementations.edit = wrappedTools.editToolInstance;
|
|
84423
85175
|
}
|
|
84424
|
-
if (wrappedTools.createToolInstance) {
|
|
85176
|
+
if (wrappedTools.createToolInstance && isToolAllowed("create")) {
|
|
84425
85177
|
this.toolImplementations.create = wrappedTools.createToolInstance;
|
|
84426
85178
|
}
|
|
84427
85179
|
}
|
|
@@ -84441,13 +85193,33 @@ var init_ProbeAgent = __esm({
|
|
|
84441
85193
|
}
|
|
84442
85194
|
/**
|
|
84443
85195
|
* Check if claude command is available on the system
|
|
85196
|
+
* Uses execFile instead of exec to avoid shell injection risks
|
|
84444
85197
|
* @returns {Promise<boolean>} True if claude command is available
|
|
84445
85198
|
* @private
|
|
84446
85199
|
*/
|
|
84447
85200
|
async isClaudeCommandAvailable() {
|
|
84448
85201
|
try {
|
|
84449
|
-
const {
|
|
84450
|
-
|
|
85202
|
+
const { execFile: execFile3 } = await import("child_process");
|
|
85203
|
+
const { promisify: promisify8 } = await import("util");
|
|
85204
|
+
const execFileAsync3 = promisify8(execFile3);
|
|
85205
|
+
await execFileAsync3("claude", ["--version"], { timeout: 5e3 });
|
|
85206
|
+
return true;
|
|
85207
|
+
} catch (error2) {
|
|
85208
|
+
return false;
|
|
85209
|
+
}
|
|
85210
|
+
}
|
|
85211
|
+
/**
|
|
85212
|
+
* Check if codex command is available on the system
|
|
85213
|
+
* Uses execFile instead of exec to avoid shell injection risks
|
|
85214
|
+
* @returns {Promise<boolean>} True if codex command is available
|
|
85215
|
+
* @private
|
|
85216
|
+
*/
|
|
85217
|
+
async isCodexCommandAvailable() {
|
|
85218
|
+
try {
|
|
85219
|
+
const { execFile: execFile3 } = await import("child_process");
|
|
85220
|
+
const { promisify: promisify8 } = await import("util");
|
|
85221
|
+
const execFileAsync3 = promisify8(execFile3);
|
|
85222
|
+
await execFileAsync3("codex", ["--version"], { timeout: 5e3 });
|
|
84451
85223
|
return true;
|
|
84452
85224
|
} catch (error2) {
|
|
84453
85225
|
return false;
|
|
@@ -84471,6 +85243,20 @@ var init_ProbeAgent = __esm({
|
|
|
84471
85243
|
}
|
|
84472
85244
|
return;
|
|
84473
85245
|
}
|
|
85246
|
+
if (this.clientApiProvider === "codex" || process.env.USE_CODEX === "true") {
|
|
85247
|
+
this.provider = null;
|
|
85248
|
+
this.model = modelName || null;
|
|
85249
|
+
this.apiType = "codex";
|
|
85250
|
+
if (this.debug) {
|
|
85251
|
+
console.log("[DEBUG] Codex CLI engine selected - will use built-in access if available");
|
|
85252
|
+
if (this.model) {
|
|
85253
|
+
console.log(`[DEBUG] Using model: ${this.model}`);
|
|
85254
|
+
} else {
|
|
85255
|
+
console.log("[DEBUG] Using Codex account default model");
|
|
85256
|
+
}
|
|
85257
|
+
}
|
|
85258
|
+
return;
|
|
85259
|
+
}
|
|
84474
85260
|
const anthropicApiKey = process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
84475
85261
|
const openaiApiKey = process.env.OPENAI_API_KEY;
|
|
84476
85262
|
const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY;
|
|
@@ -84632,6 +85418,44 @@ var init_ProbeAgent = __esm({
|
|
|
84632
85418
|
}
|
|
84633
85419
|
}
|
|
84634
85420
|
}
|
|
85421
|
+
if (this.clientApiProvider === "codex" || process.env.USE_CODEX === "true") {
|
|
85422
|
+
try {
|
|
85423
|
+
const engine = await this.getEngine();
|
|
85424
|
+
if (engine && engine.query) {
|
|
85425
|
+
const userMessages = options.messages.filter(
|
|
85426
|
+
(m4) => m4.role === "user" && !m4.content.includes("WARNING: You have reached the maximum tool iterations limit")
|
|
85427
|
+
);
|
|
85428
|
+
const lastUserMessage = userMessages[userMessages.length - 1];
|
|
85429
|
+
const prompt = lastUserMessage ? lastUserMessage.content : "";
|
|
85430
|
+
const engineOptions = {
|
|
85431
|
+
maxTokens: options.maxTokens,
|
|
85432
|
+
temperature: options.temperature,
|
|
85433
|
+
messages: options.messages,
|
|
85434
|
+
systemPrompt: options.messages.find((m4) => m4.role === "system")?.content
|
|
85435
|
+
};
|
|
85436
|
+
const engineStream = engine.query(prompt, engineOptions);
|
|
85437
|
+
async function* createTextStream() {
|
|
85438
|
+
for await (const message of engineStream) {
|
|
85439
|
+
if (message.type === "text" && message.content) {
|
|
85440
|
+
yield message.content;
|
|
85441
|
+
} else if (typeof message === "string") {
|
|
85442
|
+
yield message;
|
|
85443
|
+
}
|
|
85444
|
+
}
|
|
85445
|
+
}
|
|
85446
|
+
return {
|
|
85447
|
+
textStream: createTextStream(),
|
|
85448
|
+
usage: Promise.resolve({})
|
|
85449
|
+
// Engine should handle its own usage tracking
|
|
85450
|
+
// Add other streamText-compatible properties as needed
|
|
85451
|
+
};
|
|
85452
|
+
}
|
|
85453
|
+
} catch (error2) {
|
|
85454
|
+
if (this.debug) {
|
|
85455
|
+
console.log(`[DEBUG] Failed to use Codex engine, falling back to Vercel:`, error2.message);
|
|
85456
|
+
}
|
|
85457
|
+
}
|
|
85458
|
+
}
|
|
84635
85459
|
if (!this.retryManager) {
|
|
84636
85460
|
this.retryManager = new RetryManager({
|
|
84637
85461
|
maxRetries: this.retryConfig.maxRetries ?? 3,
|
|
@@ -84784,6 +85608,35 @@ var init_ProbeAgent = __esm({
|
|
|
84784
85608
|
this.clientApiProvider = null;
|
|
84785
85609
|
}
|
|
84786
85610
|
}
|
|
85611
|
+
if (this.clientApiProvider === "codex" || process.env.USE_CODEX === "true") {
|
|
85612
|
+
try {
|
|
85613
|
+
const { createCodexEngine: createCodexEngine2 } = await Promise.resolve().then(() => (init_codex(), codex_exports));
|
|
85614
|
+
const systemPrompt = this.customPrompt || this.getCodexNativeSystemPrompt();
|
|
85615
|
+
this.engine = await createCodexEngine2({
|
|
85616
|
+
agent: this,
|
|
85617
|
+
// Pass reference to ProbeAgent for tool access
|
|
85618
|
+
systemPrompt,
|
|
85619
|
+
customPrompt: this.customPrompt,
|
|
85620
|
+
sessionId: this.options?.sessionId,
|
|
85621
|
+
debug: this.debug,
|
|
85622
|
+
allowedTools: this.allowedTools,
|
|
85623
|
+
// Pass tool filtering configuration
|
|
85624
|
+
model: this.model
|
|
85625
|
+
// Pass model name (e.g., gpt-4o, o3, etc.)
|
|
85626
|
+
});
|
|
85627
|
+
if (this.debug) {
|
|
85628
|
+
console.log("[DEBUG] Using Codex CLI engine with Probe tools");
|
|
85629
|
+
if (this.customPrompt) {
|
|
85630
|
+
console.log("[DEBUG] Using custom prompt/persona");
|
|
85631
|
+
}
|
|
85632
|
+
}
|
|
85633
|
+
return this.engine;
|
|
85634
|
+
} catch (error2) {
|
|
85635
|
+
console.warn("[WARNING] Failed to load Codex CLI engine:", error2.message);
|
|
85636
|
+
console.warn("[WARNING] Falling back to Vercel AI SDK");
|
|
85637
|
+
this.clientApiProvider = null;
|
|
85638
|
+
}
|
|
85639
|
+
}
|
|
84787
85640
|
const { createEnhancedVercelEngine: createEnhancedVercelEngine2 } = await Promise.resolve().then(() => (init_enhanced_vercel(), enhanced_vercel_exports));
|
|
84788
85641
|
this.engine = createEnhancedVercelEngine2(this);
|
|
84789
85642
|
if (this.debug) {
|
|
@@ -84791,6 +85644,32 @@ var init_ProbeAgent = __esm({
|
|
|
84791
85644
|
}
|
|
84792
85645
|
return this.engine;
|
|
84793
85646
|
}
|
|
85647
|
+
/**
|
|
85648
|
+
* Get session information including thread ID for resumability
|
|
85649
|
+
* @returns {Object} Session info with sessionId, threadId, messageCount
|
|
85650
|
+
*/
|
|
85651
|
+
getSessionInfo() {
|
|
85652
|
+
if (this.engine && this.engine.getSession) {
|
|
85653
|
+
return this.engine.getSession();
|
|
85654
|
+
}
|
|
85655
|
+
return {
|
|
85656
|
+
id: this.sessionId,
|
|
85657
|
+
threadId: null,
|
|
85658
|
+
messageCount: 0
|
|
85659
|
+
};
|
|
85660
|
+
}
|
|
85661
|
+
/**
|
|
85662
|
+
* Close the agent and clean up resources (e.g., MCP servers)
|
|
85663
|
+
* @returns {Promise<void>}
|
|
85664
|
+
*/
|
|
85665
|
+
async close() {
|
|
85666
|
+
if (this.engine && this.engine.close) {
|
|
85667
|
+
await this.engine.close();
|
|
85668
|
+
}
|
|
85669
|
+
if (this.mcpBridge) {
|
|
85670
|
+
this.mcpBridge = null;
|
|
85671
|
+
}
|
|
85672
|
+
}
|
|
84794
85673
|
/**
|
|
84795
85674
|
* Process assistant response content and detect/load image references
|
|
84796
85675
|
* @param {string} content - The assistant's response content
|
|
@@ -85083,11 +85962,61 @@ var init_ProbeAgent = __esm({
|
|
|
85083
85962
|
*/
|
|
85084
85963
|
getClaudeNativeSystemPrompt() {
|
|
85085
85964
|
let systemPrompt = "";
|
|
85086
|
-
if (this.
|
|
85087
|
-
|
|
85088
|
-
|
|
85089
|
-
|
|
85090
|
-
|
|
85965
|
+
if (this.customPrompt) {
|
|
85966
|
+
systemPrompt += this.customPrompt + "\n\n";
|
|
85967
|
+
} else if (this.promptType && predefinedPrompts[this.promptType]) {
|
|
85968
|
+
systemPrompt += predefinedPrompts[this.promptType] + "\n\n";
|
|
85969
|
+
} else {
|
|
85970
|
+
systemPrompt += predefinedPrompts["code-explorer"] + "\n\n";
|
|
85971
|
+
}
|
|
85972
|
+
systemPrompt += `You have access to powerful code search and analysis tools through MCP:
|
|
85973
|
+
- search: Find code patterns using semantic search
|
|
85974
|
+
- extract: Extract specific code sections with context
|
|
85975
|
+
- query: Use AST patterns for structural code matching
|
|
85976
|
+
- listFiles: Browse directory contents
|
|
85977
|
+
- searchFiles: Find files by name patterns`;
|
|
85978
|
+
if (this.enableBash) {
|
|
85979
|
+
systemPrompt += `
|
|
85980
|
+
- bash: Execute bash commands for system operations`;
|
|
85981
|
+
}
|
|
85982
|
+
systemPrompt += `
|
|
85983
|
+
|
|
85984
|
+
When exploring code:
|
|
85985
|
+
1. Start with search to find relevant code patterns
|
|
85986
|
+
2. Use extract to get detailed context when needed
|
|
85987
|
+
3. Prefer focused, specific searches over broad queries
|
|
85988
|
+
4. Combine multiple tools to build complete understanding`;
|
|
85989
|
+
if (this.allowedFolders && this.allowedFolders.length > 0) {
|
|
85990
|
+
systemPrompt += `
|
|
85991
|
+
|
|
85992
|
+
Workspace: ${this.allowedFolders.join(", ")}`;
|
|
85993
|
+
}
|
|
85994
|
+
if (this.fileList) {
|
|
85995
|
+
systemPrompt += `
|
|
85996
|
+
|
|
85997
|
+
# Repository Structure
|
|
85998
|
+
`;
|
|
85999
|
+
systemPrompt += `You are working with a repository located at: ${this.allowedFolders[0]}
|
|
86000
|
+
|
|
86001
|
+
`;
|
|
86002
|
+
systemPrompt += `Here's an overview of the repository structure (showing up to 100 most relevant files):
|
|
86003
|
+
|
|
86004
|
+
`;
|
|
86005
|
+
systemPrompt += "```\n" + this.fileList + "\n```\n";
|
|
86006
|
+
}
|
|
86007
|
+
return systemPrompt;
|
|
86008
|
+
}
|
|
86009
|
+
/**
|
|
86010
|
+
* Get system prompt for Codex CLI (similar to Claude but optimized for Codex)
|
|
86011
|
+
*/
|
|
86012
|
+
getCodexNativeSystemPrompt() {
|
|
86013
|
+
let systemPrompt = "";
|
|
86014
|
+
if (this.customPrompt) {
|
|
86015
|
+
systemPrompt += this.customPrompt + "\n\n";
|
|
86016
|
+
} else if (this.promptType && predefinedPrompts[this.promptType]) {
|
|
86017
|
+
systemPrompt += predefinedPrompts[this.promptType] + "\n\n";
|
|
86018
|
+
} else {
|
|
86019
|
+
systemPrompt += predefinedPrompts["code-explorer"] + "\n\n";
|
|
85091
86020
|
}
|
|
85092
86021
|
systemPrompt += `You have access to powerful code search and analysis tools through MCP:
|
|
85093
86022
|
- search: Find code patterns using semantic search
|
|
@@ -85283,7 +86212,7 @@ Follow these instructions carefully:
|
|
|
85283
86212
|
- Use 'create' for new files or complete file rewrites` : ""}
|
|
85284
86213
|
</instructions>
|
|
85285
86214
|
`;
|
|
85286
|
-
const
|
|
86215
|
+
const predefinedPrompts2 = {
|
|
85287
86216
|
"code-explorer": `You are ProbeChat Code Explorer, a specialized AI assistant focused on helping developers, product managers, and QAs understand and navigate codebases. Your primary function is to answer questions based on code, explain how systems work, and provide insights into code functionality using the provided code analysis tools.
|
|
85288
86217
|
|
|
85289
86218
|
When exploring code:
|
|
@@ -85339,14 +86268,14 @@ When troubleshooting:
|
|
|
85339
86268
|
if (this.debug) {
|
|
85340
86269
|
console.log(`[DEBUG] Using custom prompt`);
|
|
85341
86270
|
}
|
|
85342
|
-
} else if (this.promptType &&
|
|
85343
|
-
systemMessage = "<role>" +
|
|
86271
|
+
} else if (this.promptType && predefinedPrompts2[this.promptType]) {
|
|
86272
|
+
systemMessage = "<role>" + predefinedPrompts2[this.promptType] + "</role>";
|
|
85344
86273
|
if (this.debug) {
|
|
85345
86274
|
console.log(`[DEBUG] Using predefined prompt: ${this.promptType}`);
|
|
85346
86275
|
}
|
|
85347
86276
|
systemMessage += commonInstructions;
|
|
85348
86277
|
} else {
|
|
85349
|
-
systemMessage = "<role>" +
|
|
86278
|
+
systemMessage = "<role>" + predefinedPrompts2["code-explorer"] + "</role>";
|
|
85350
86279
|
if (this.debug) {
|
|
85351
86280
|
console.log(`[DEBUG] Using default prompt: code explorer`);
|
|
85352
86281
|
}
|
|
@@ -85487,6 +86416,7 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
85487
86416
|
const baseMaxIterations = this.maxIterations || MAX_TOOL_ITERATIONS;
|
|
85488
86417
|
const maxIterations = options.schema ? baseMaxIterations + 4 : baseMaxIterations;
|
|
85489
86418
|
const isClaudeCode = this.clientApiProvider === "claude-code" || process.env.USE_CLAUDE_CODE === "true";
|
|
86419
|
+
const isCodex = this.clientApiProvider === "codex" || process.env.USE_CODEX === "true";
|
|
85490
86420
|
if (isClaudeCode) {
|
|
85491
86421
|
if (this.debug) {
|
|
85492
86422
|
console.log(`[DEBUG] Using Claude Code engine - bypassing tool loop (black box mode)`);
|
|
@@ -85539,6 +86469,58 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
85539
86469
|
throw error2;
|
|
85540
86470
|
}
|
|
85541
86471
|
}
|
|
86472
|
+
if (isCodex) {
|
|
86473
|
+
if (this.debug) {
|
|
86474
|
+
console.log(`[DEBUG] Using Codex engine - bypassing tool loop (black box mode)`);
|
|
86475
|
+
console.log(`[DEBUG] Sending question directly to Codex: ${message.substring(0, 100)}...`);
|
|
86476
|
+
}
|
|
86477
|
+
try {
|
|
86478
|
+
const engine = await this.getEngine();
|
|
86479
|
+
if (engine && engine.query) {
|
|
86480
|
+
let assistantResponseContent = "";
|
|
86481
|
+
let toolBatch = null;
|
|
86482
|
+
for await (const chunk of engine.query(message, options)) {
|
|
86483
|
+
if (chunk.type === "text" && chunk.content) {
|
|
86484
|
+
assistantResponseContent += chunk.content;
|
|
86485
|
+
if (options.onStream) {
|
|
86486
|
+
options.onStream(chunk.content);
|
|
86487
|
+
}
|
|
86488
|
+
} else if (chunk.type === "toolBatch" && chunk.tools) {
|
|
86489
|
+
toolBatch = chunk.tools;
|
|
86490
|
+
if (this.debug) {
|
|
86491
|
+
console.log(`[DEBUG] Received batch of ${chunk.tools.length} tool events from Codex`);
|
|
86492
|
+
}
|
|
86493
|
+
} else if (chunk.type === "error") {
|
|
86494
|
+
throw chunk.error;
|
|
86495
|
+
}
|
|
86496
|
+
}
|
|
86497
|
+
if (toolBatch && toolBatch.length > 0 && this.events) {
|
|
86498
|
+
if (this.debug) {
|
|
86499
|
+
console.log(`[DEBUG] Emitting ${toolBatch.length} tool events from Codex batch`);
|
|
86500
|
+
}
|
|
86501
|
+
for (const toolEvent of toolBatch) {
|
|
86502
|
+
this.events.emit("toolCall", toolEvent);
|
|
86503
|
+
}
|
|
86504
|
+
}
|
|
86505
|
+
this.history.push(userMessage);
|
|
86506
|
+
this.history.push({
|
|
86507
|
+
role: "assistant",
|
|
86508
|
+
content: assistantResponseContent
|
|
86509
|
+
});
|
|
86510
|
+
await this.hooks.emit(HOOK_TYPES.COMPLETION, {
|
|
86511
|
+
sessionId: this.sessionId,
|
|
86512
|
+
prompt: message,
|
|
86513
|
+
response: assistantResponseContent
|
|
86514
|
+
});
|
|
86515
|
+
return assistantResponseContent;
|
|
86516
|
+
}
|
|
86517
|
+
} catch (error2) {
|
|
86518
|
+
if (this.debug) {
|
|
86519
|
+
console.error("[DEBUG] Codex error:", error2);
|
|
86520
|
+
}
|
|
86521
|
+
throw error2;
|
|
86522
|
+
}
|
|
86523
|
+
}
|
|
85542
86524
|
if (this.debug) {
|
|
85543
86525
|
console.log(`[DEBUG] Starting agentic flow for question: ${message.substring(0, 100)}...`);
|
|
85544
86526
|
if (options.schema) {
|
|
@@ -86419,7 +87401,7 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
86419
87401
|
*/
|
|
86420
87402
|
clone(options = {}) {
|
|
86421
87403
|
const {
|
|
86422
|
-
sessionId = (0,
|
|
87404
|
+
sessionId = (0, import_crypto8.randomUUID)(),
|
|
86423
87405
|
stripInternalMessages = true,
|
|
86424
87406
|
keepSystemMessage = true,
|
|
86425
87407
|
deepCopy = true,
|