@probelabs/probe 0.6.0-rc107 → 0.6.0-rc109

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/cjs/index.cjs CHANGED
@@ -1145,9 +1145,10 @@ function parseXmlToolCall(xmlString, validTools = DEFAULT_VALID_TOOLS) {
1145
1145
  if (openIndex === -1) {
1146
1146
  continue;
1147
1147
  }
1148
- const closeIndex = xmlString.indexOf(closeTag, openIndex + openTag.length);
1148
+ let closeIndex = xmlString.indexOf(closeTag, openIndex + openTag.length);
1149
+ let hasClosingTag = closeIndex !== -1;
1149
1150
  if (closeIndex === -1) {
1150
- continue;
1151
+ closeIndex = xmlString.length;
1151
1152
  }
1152
1153
  const innerContent = xmlString.substring(
1153
1154
  openIndex + openTag.length,
@@ -1189,9 +1190,17 @@ function parseXmlToolCall(xmlString, validTools = DEFAULT_VALID_TOOLS) {
1189
1190
  if (paramOpenIndex === -1) {
1190
1191
  continue;
1191
1192
  }
1192
- const paramCloseIndex = innerContent.indexOf(paramCloseTag, paramOpenIndex + paramOpenTag.length);
1193
+ let paramCloseIndex = innerContent.indexOf(paramCloseTag, paramOpenIndex + paramOpenTag.length);
1193
1194
  if (paramCloseIndex === -1) {
1194
- continue;
1195
+ let nextTagIndex = innerContent.length;
1196
+ for (const nextParam of commonParams3) {
1197
+ const nextOpenTag = `<${nextParam}>`;
1198
+ const nextIndex = innerContent.indexOf(nextOpenTag, paramOpenIndex + paramOpenTag.length);
1199
+ if (nextIndex !== -1 && nextIndex < nextTagIndex) {
1200
+ nextTagIndex = nextIndex;
1201
+ }
1202
+ }
1203
+ paramCloseIndex = nextTagIndex;
1195
1204
  }
1196
1205
  let paramValue = innerContent.substring(
1197
1206
  paramOpenIndex + paramOpenTag.length,
@@ -13753,9 +13762,10 @@ var init_ProtocolLib = __esm({
13753
13762
  return { errorSchema, errorMetadata };
13754
13763
  } catch (e3) {
13755
13764
  dataObject.message = dataObject.message ?? dataObject.Message ?? "UnknownError";
13756
- const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
13765
+ const synthetic = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace);
13766
+ const baseExceptionSchema = synthetic.getBaseException();
13757
13767
  if (baseExceptionSchema) {
13758
- const ErrorCtor = baseExceptionSchema.ctor;
13768
+ const ErrorCtor = synthetic.getErrorCtor(baseExceptionSchema) ?? Error;
13759
13769
  throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
13760
13770
  }
13761
13771
  throw Object.assign(new Error(errorName), errorMetadata, dataObject);
@@ -13822,7 +13832,8 @@ var init_AwsSmithyRpcV2CborProtocol = __esm({
13822
13832
  const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorName, this.options.defaultNamespace, response, dataObject, metadata);
13823
13833
  const ns = NormalizedSchema.of(errorSchema);
13824
13834
  const message = dataObject.message ?? dataObject.Message ?? "Unknown";
13825
- const exception = new errorSchema.ctor(message);
13835
+ const ErrorCtor = TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
13836
+ const exception = new ErrorCtor(message);
13826
13837
  const output = {};
13827
13838
  for (const [name14, member] of ns.structIterator()) {
13828
13839
  output[name14] = this.deserializer.readValue(member, dataObject[name14]);
@@ -15364,7 +15375,8 @@ var init_AwsJsonRpcProtocol = __esm({
15364
15375
  const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
15365
15376
  const ns = NormalizedSchema.of(errorSchema);
15366
15377
  const message = dataObject.message ?? dataObject.Message ?? "Unknown";
15367
- const exception = new errorSchema.ctor(message);
15378
+ const ErrorCtor = TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
15379
+ const exception = new ErrorCtor(message);
15368
15380
  const output = {};
15369
15381
  for (const [name14, member] of ns.structIterator()) {
15370
15382
  const target = member.getMergedTraits().jsonName ?? name14;
@@ -15493,7 +15505,8 @@ var init_AwsRestJsonProtocol = __esm({
15493
15505
  const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
15494
15506
  const ns = NormalizedSchema.of(errorSchema);
15495
15507
  const message = dataObject.message ?? dataObject.Message ?? "Unknown";
15496
- const exception = new errorSchema.ctor(message);
15508
+ const ErrorCtor = TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
15509
+ const exception = new ErrorCtor(message);
15497
15510
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
15498
15511
  const output = {};
15499
15512
  for (const [name14, member] of ns.structIterator()) {
@@ -16905,7 +16918,8 @@ var init_AwsQueryProtocol = __esm({
16905
16918
  };
16906
16919
  const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, (registry, errorName) => registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName));
16907
16920
  const ns = NormalizedSchema.of(errorSchema);
16908
- const exception = new errorSchema.ctor(message);
16921
+ const ErrorCtor = TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
16922
+ const exception = new ErrorCtor(message);
16909
16923
  const output = {
16910
16924
  Error: errorData.Error
16911
16925
  };
@@ -17367,7 +17381,8 @@ var init_AwsRestXmlProtocol = __esm({
17367
17381
  const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
17368
17382
  const ns = NormalizedSchema.of(errorSchema);
17369
17383
  const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
17370
- const exception = new errorSchema.ctor(message);
17384
+ const ErrorCtor = TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
17385
+ const exception = new ErrorCtor(message);
17371
17386
  await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
17372
17387
  const output = {};
17373
17388
  for (const [name14, member] of ns.structIterator()) {
@@ -21318,7 +21333,7 @@ var require_package = __commonJS({
21318
21333
  module2.exports = {
21319
21334
  name: "@aws-sdk/client-bedrock-runtime",
21320
21335
  description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
21321
- version: "3.896.0",
21336
+ version: "3.899.0",
21322
21337
  scripts: {
21323
21338
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
21324
21339
  "build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
@@ -21337,23 +21352,23 @@ var require_package = __commonJS({
21337
21352
  dependencies: {
21338
21353
  "@aws-crypto/sha256-browser": "5.2.0",
21339
21354
  "@aws-crypto/sha256-js": "5.2.0",
21340
- "@aws-sdk/core": "3.896.0",
21341
- "@aws-sdk/credential-provider-node": "3.896.0",
21355
+ "@aws-sdk/core": "3.899.0",
21356
+ "@aws-sdk/credential-provider-node": "3.899.0",
21342
21357
  "@aws-sdk/eventstream-handler-node": "3.893.0",
21343
21358
  "@aws-sdk/middleware-eventstream": "3.893.0",
21344
21359
  "@aws-sdk/middleware-host-header": "3.893.0",
21345
21360
  "@aws-sdk/middleware-logger": "3.893.0",
21346
21361
  "@aws-sdk/middleware-recursion-detection": "3.893.0",
21347
- "@aws-sdk/middleware-user-agent": "3.896.0",
21362
+ "@aws-sdk/middleware-user-agent": "3.899.0",
21348
21363
  "@aws-sdk/middleware-websocket": "3.893.0",
21349
21364
  "@aws-sdk/region-config-resolver": "3.893.0",
21350
- "@aws-sdk/token-providers": "3.896.0",
21365
+ "@aws-sdk/token-providers": "3.899.0",
21351
21366
  "@aws-sdk/types": "3.893.0",
21352
21367
  "@aws-sdk/util-endpoints": "3.895.0",
21353
21368
  "@aws-sdk/util-user-agent-browser": "3.893.0",
21354
- "@aws-sdk/util-user-agent-node": "3.896.0",
21369
+ "@aws-sdk/util-user-agent-node": "3.899.0",
21355
21370
  "@smithy/config-resolver": "^4.2.2",
21356
- "@smithy/core": "^3.12.0",
21371
+ "@smithy/core": "^3.13.0",
21357
21372
  "@smithy/eventstream-serde-browser": "^4.1.1",
21358
21373
  "@smithy/eventstream-serde-config-resolver": "^4.2.1",
21359
21374
  "@smithy/eventstream-serde-node": "^4.1.1",
@@ -21361,21 +21376,21 @@ var require_package = __commonJS({
21361
21376
  "@smithy/hash-node": "^4.1.1",
21362
21377
  "@smithy/invalid-dependency": "^4.1.1",
21363
21378
  "@smithy/middleware-content-length": "^4.1.1",
21364
- "@smithy/middleware-endpoint": "^4.2.4",
21365
- "@smithy/middleware-retry": "^4.3.0",
21379
+ "@smithy/middleware-endpoint": "^4.2.5",
21380
+ "@smithy/middleware-retry": "^4.3.1",
21366
21381
  "@smithy/middleware-serde": "^4.1.1",
21367
21382
  "@smithy/middleware-stack": "^4.1.1",
21368
21383
  "@smithy/node-config-provider": "^4.2.2",
21369
21384
  "@smithy/node-http-handler": "^4.2.1",
21370
21385
  "@smithy/protocol-http": "^5.2.1",
21371
- "@smithy/smithy-client": "^4.6.4",
21386
+ "@smithy/smithy-client": "^4.6.5",
21372
21387
  "@smithy/types": "^4.5.0",
21373
21388
  "@smithy/url-parser": "^4.1.1",
21374
21389
  "@smithy/util-base64": "^4.1.0",
21375
21390
  "@smithy/util-body-length-browser": "^4.1.0",
21376
21391
  "@smithy/util-body-length-node": "^4.1.0",
21377
- "@smithy/util-defaults-mode-browser": "^4.1.4",
21378
- "@smithy/util-defaults-mode-node": "^4.1.4",
21392
+ "@smithy/util-defaults-mode-browser": "^4.1.5",
21393
+ "@smithy/util-defaults-mode-node": "^4.1.5",
21379
21394
  "@smithy/util-endpoints": "^3.1.2",
21380
21395
  "@smithy/util-middleware": "^4.1.1",
21381
21396
  "@smithy/util-retry": "^4.1.2",
@@ -22167,7 +22182,7 @@ var require_package2 = __commonJS({
22167
22182
  module2.exports = {
22168
22183
  name: "@aws-sdk/client-sso",
22169
22184
  description: "AWS SDK for JavaScript Sso Client for Node.js, Browser and React Native",
22170
- version: "3.896.0",
22185
+ version: "3.899.0",
22171
22186
  scripts: {
22172
22187
  build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
22173
22188
  "build:cjs": "node ../../scripts/compilation/inline client-sso",
@@ -22186,37 +22201,37 @@ var require_package2 = __commonJS({
22186
22201
  dependencies: {
22187
22202
  "@aws-crypto/sha256-browser": "5.2.0",
22188
22203
  "@aws-crypto/sha256-js": "5.2.0",
22189
- "@aws-sdk/core": "3.896.0",
22204
+ "@aws-sdk/core": "3.899.0",
22190
22205
  "@aws-sdk/middleware-host-header": "3.893.0",
22191
22206
  "@aws-sdk/middleware-logger": "3.893.0",
22192
22207
  "@aws-sdk/middleware-recursion-detection": "3.893.0",
22193
- "@aws-sdk/middleware-user-agent": "3.896.0",
22208
+ "@aws-sdk/middleware-user-agent": "3.899.0",
22194
22209
  "@aws-sdk/region-config-resolver": "3.893.0",
22195
22210
  "@aws-sdk/types": "3.893.0",
22196
22211
  "@aws-sdk/util-endpoints": "3.895.0",
22197
22212
  "@aws-sdk/util-user-agent-browser": "3.893.0",
22198
- "@aws-sdk/util-user-agent-node": "3.896.0",
22213
+ "@aws-sdk/util-user-agent-node": "3.899.0",
22199
22214
  "@smithy/config-resolver": "^4.2.2",
22200
- "@smithy/core": "^3.12.0",
22215
+ "@smithy/core": "^3.13.0",
22201
22216
  "@smithy/fetch-http-handler": "^5.2.1",
22202
22217
  "@smithy/hash-node": "^4.1.1",
22203
22218
  "@smithy/invalid-dependency": "^4.1.1",
22204
22219
  "@smithy/middleware-content-length": "^4.1.1",
22205
- "@smithy/middleware-endpoint": "^4.2.4",
22206
- "@smithy/middleware-retry": "^4.3.0",
22220
+ "@smithy/middleware-endpoint": "^4.2.5",
22221
+ "@smithy/middleware-retry": "^4.3.1",
22207
22222
  "@smithy/middleware-serde": "^4.1.1",
22208
22223
  "@smithy/middleware-stack": "^4.1.1",
22209
22224
  "@smithy/node-config-provider": "^4.2.2",
22210
22225
  "@smithy/node-http-handler": "^4.2.1",
22211
22226
  "@smithy/protocol-http": "^5.2.1",
22212
- "@smithy/smithy-client": "^4.6.4",
22227
+ "@smithy/smithy-client": "^4.6.5",
22213
22228
  "@smithy/types": "^4.5.0",
22214
22229
  "@smithy/url-parser": "^4.1.1",
22215
22230
  "@smithy/util-base64": "^4.1.0",
22216
22231
  "@smithy/util-body-length-browser": "^4.1.0",
22217
22232
  "@smithy/util-body-length-node": "^4.1.0",
22218
- "@smithy/util-defaults-mode-browser": "^4.1.4",
22219
- "@smithy/util-defaults-mode-node": "^4.1.4",
22233
+ "@smithy/util-defaults-mode-browser": "^4.1.5",
22234
+ "@smithy/util-defaults-mode-node": "^4.1.5",
22220
22235
  "@smithy/util-endpoints": "^3.1.2",
22221
22236
  "@smithy/util-middleware": "^4.1.1",
22222
22237
  "@smithy/util-retry": "^4.1.2",
@@ -23448,7 +23463,7 @@ var init_package = __esm({
23448
23463
  "node_modules/@aws-sdk/nested-clients/package.json"() {
23449
23464
  package_default = {
23450
23465
  name: "@aws-sdk/nested-clients",
23451
- version: "3.896.0",
23466
+ version: "3.899.0",
23452
23467
  description: "Nested clients for AWS SDK packages.",
23453
23468
  main: "./dist-cjs/index.js",
23454
23469
  module: "./dist-es/index.js",
@@ -23477,37 +23492,37 @@ var init_package = __esm({
23477
23492
  dependencies: {
23478
23493
  "@aws-crypto/sha256-browser": "5.2.0",
23479
23494
  "@aws-crypto/sha256-js": "5.2.0",
23480
- "@aws-sdk/core": "3.896.0",
23495
+ "@aws-sdk/core": "3.899.0",
23481
23496
  "@aws-sdk/middleware-host-header": "3.893.0",
23482
23497
  "@aws-sdk/middleware-logger": "3.893.0",
23483
23498
  "@aws-sdk/middleware-recursion-detection": "3.893.0",
23484
- "@aws-sdk/middleware-user-agent": "3.896.0",
23499
+ "@aws-sdk/middleware-user-agent": "3.899.0",
23485
23500
  "@aws-sdk/region-config-resolver": "3.893.0",
23486
23501
  "@aws-sdk/types": "3.893.0",
23487
23502
  "@aws-sdk/util-endpoints": "3.895.0",
23488
23503
  "@aws-sdk/util-user-agent-browser": "3.893.0",
23489
- "@aws-sdk/util-user-agent-node": "3.896.0",
23504
+ "@aws-sdk/util-user-agent-node": "3.899.0",
23490
23505
  "@smithy/config-resolver": "^4.2.2",
23491
- "@smithy/core": "^3.12.0",
23506
+ "@smithy/core": "^3.13.0",
23492
23507
  "@smithy/fetch-http-handler": "^5.2.1",
23493
23508
  "@smithy/hash-node": "^4.1.1",
23494
23509
  "@smithy/invalid-dependency": "^4.1.1",
23495
23510
  "@smithy/middleware-content-length": "^4.1.1",
23496
- "@smithy/middleware-endpoint": "^4.2.4",
23497
- "@smithy/middleware-retry": "^4.3.0",
23511
+ "@smithy/middleware-endpoint": "^4.2.5",
23512
+ "@smithy/middleware-retry": "^4.3.1",
23498
23513
  "@smithy/middleware-serde": "^4.1.1",
23499
23514
  "@smithy/middleware-stack": "^4.1.1",
23500
23515
  "@smithy/node-config-provider": "^4.2.2",
23501
23516
  "@smithy/node-http-handler": "^4.2.1",
23502
23517
  "@smithy/protocol-http": "^5.2.1",
23503
- "@smithy/smithy-client": "^4.6.4",
23518
+ "@smithy/smithy-client": "^4.6.5",
23504
23519
  "@smithy/types": "^4.5.0",
23505
23520
  "@smithy/url-parser": "^4.1.1",
23506
23521
  "@smithy/util-base64": "^4.1.0",
23507
23522
  "@smithy/util-body-length-browser": "^4.1.0",
23508
23523
  "@smithy/util-body-length-node": "^4.1.0",
23509
- "@smithy/util-defaults-mode-browser": "^4.1.4",
23510
- "@smithy/util-defaults-mode-node": "^4.1.4",
23524
+ "@smithy/util-defaults-mode-browser": "^4.1.5",
23525
+ "@smithy/util-defaults-mode-node": "^4.1.5",
23511
23526
  "@smithy/util-endpoints": "^3.1.2",
23512
23527
  "@smithy/util-middleware": "^4.1.1",
23513
23528
  "@smithy/util-retry": "^4.1.2",
@@ -27977,6 +27992,7 @@ var require_dist_cjs65 = __commonJS({
27977
27992
  END_TURN: "end_turn",
27978
27993
  GUARDRAIL_INTERVENED: "guardrail_intervened",
27979
27994
  MAX_TOKENS: "max_tokens",
27995
+ MODEL_CONTEXT_WINDOW_EXCEEDED: "model_context_window_exceeded",
27980
27996
  STOP_SEQUENCE: "stop_sequence",
27981
27997
  TOOL_USE: "tool_use"
27982
27998
  };
@@ -28906,6 +28922,9 @@ var require_dist_cjs65 = __commonJS({
28906
28922
  case "ServiceQuotaExceededException":
28907
28923
  case "com.amazonaws.bedrockruntime#ServiceQuotaExceededException":
28908
28924
  throw await de_ServiceQuotaExceededExceptionRes(parsedOutput, context);
28925
+ case "ServiceUnavailableException":
28926
+ case "com.amazonaws.bedrockruntime#ServiceUnavailableException":
28927
+ throw await de_ServiceUnavailableExceptionRes(parsedOutput, context);
28909
28928
  case "ThrottlingException":
28910
28929
  case "com.amazonaws.bedrockruntime#ThrottlingException":
28911
28930
  throw await de_ThrottlingExceptionRes(parsedOutput, context);
@@ -28921,9 +28940,6 @@ var require_dist_cjs65 = __commonJS({
28921
28940
  case "ModelTimeoutException":
28922
28941
  case "com.amazonaws.bedrockruntime#ModelTimeoutException":
28923
28942
  throw await de_ModelTimeoutExceptionRes(parsedOutput, context);
28924
- case "ServiceUnavailableException":
28925
- case "com.amazonaws.bedrockruntime#ServiceUnavailableException":
28926
- throw await de_ServiceUnavailableExceptionRes(parsedOutput, context);
28927
28943
  case "ModelStreamErrorException":
28928
28944
  case "com.amazonaws.bedrockruntime#ModelStreamErrorException":
28929
28945
  throw await de_ModelStreamErrorExceptionRes(parsedOutput, context);
@@ -31270,13 +31286,42 @@ var init_tokenCounter = __esm({
31270
31286
 
31271
31287
  // src/agent/xmlParsingUtils.js
31272
31288
  function removeThinkingTags(xmlString) {
31273
- return xmlString.replace(/<thinking>[\s\S]*?<\/thinking>/g, "").trim();
31289
+ let result = xmlString;
31290
+ result = result.replace(/<thinking>[\s\S]*?<\/thinking>/g, "");
31291
+ const thinkingIndex = result.indexOf("<thinking>");
31292
+ if (thinkingIndex !== -1) {
31293
+ const afterThinking = result.substring(thinkingIndex + "<thinking>".length);
31294
+ const toolPattern = /<(search|query|extract|listFiles|searchFiles|implement|attempt_completion|attempt_complete)>/;
31295
+ const toolMatch = afterThinking.match(toolPattern);
31296
+ if (toolMatch) {
31297
+ const toolStart = thinkingIndex + "<thinking>".length + toolMatch.index;
31298
+ result = result.substring(0, thinkingIndex) + result.substring(toolStart);
31299
+ } else {
31300
+ result = result.substring(0, thinkingIndex);
31301
+ }
31302
+ }
31303
+ return result.trim();
31274
31304
  }
31275
31305
  function extractThinkingContent(xmlString) {
31276
31306
  const thinkingMatch = xmlString.match(/<thinking>([\s\S]*?)<\/thinking>/);
31277
31307
  return thinkingMatch ? thinkingMatch[1].trim() : null;
31278
31308
  }
31279
31309
  function checkAttemptCompleteRecovery(cleanedXmlString, validTools = []) {
31310
+ const attemptCompletionMatch = cleanedXmlString.match(/<attempt_completion>([\s\S]*?)(?:<\/attempt_completion>|$)/);
31311
+ if (attemptCompletionMatch) {
31312
+ const content = attemptCompletionMatch[1].trim();
31313
+ const hasClosingTag = cleanedXmlString.includes("</attempt_completion>");
31314
+ if (content) {
31315
+ return {
31316
+ toolName: "attempt_completion",
31317
+ params: { result: content }
31318
+ };
31319
+ }
31320
+ return {
31321
+ toolName: "attempt_completion",
31322
+ params: { result: hasClosingTag ? "" : "__PREVIOUS_RESPONSE__" }
31323
+ };
31324
+ }
31280
31325
  const attemptCompletePatterns = [
31281
31326
  // Standard shorthand with optional whitespace
31282
31327
  /^<attempt_complete>\s*$/,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc107",
3
+ "version": "0.6.0-rc109",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -72,8 +72,6 @@
72
72
  "@ai-sdk/anthropic": "^2.0.8",
73
73
  "@ai-sdk/google": "^2.0.14",
74
74
  "@ai-sdk/openai": "^2.0.10",
75
- "@mermaid-js/mermaid-cli": "^11.12.0",
76
- "@mermaid-js/parser": "^0.6.2",
77
75
  "@modelcontextprotocol/sdk": "^1.0.0",
78
76
  "@opentelemetry/api": "^1.9.0",
79
77
  "@opentelemetry/core": "^1.30.1",
@@ -84,14 +82,8 @@
84
82
  "@opentelemetry/semantic-conventions": "^1.36.0",
85
83
  "ai": "^5.0.0",
86
84
  "axios": "^1.8.3",
87
- "chalk": "^5.6.2",
88
- "dompurify": "^3.2.7",
89
- "dotenv": "^16.4.7",
90
85
  "fs-extra": "^11.1.1",
91
86
  "glob": "^10.3.10",
92
- "isomorphic-dompurify": "^2.28.0",
93
- "jsdom": "^27.0.0",
94
- "mermaid": "^11.12.0",
95
87
  "tar": "^6.2.0",
96
88
  "tiktoken": "^1.0.20",
97
89
  "zod": "^3.24.2"
@@ -5,11 +5,39 @@
5
5
 
6
6
  /**
7
7
  * Remove thinking tags and their content from XML string
8
+ * Handles both closed and unclosed thinking tags
8
9
  * @param {string} xmlString - The XML string to clean
9
10
  * @returns {string} - Cleaned XML string without thinking tags
10
11
  */
11
12
  export function removeThinkingTags(xmlString) {
12
- return xmlString.replace(/<thinking>[\s\S]*?<\/thinking>/g, '').trim();
13
+ let result = xmlString;
14
+
15
+ // Remove all properly closed thinking tags first
16
+ result = result.replace(/<thinking>[\s\S]*?<\/thinking>/g, '');
17
+
18
+ // Handle unclosed thinking tags
19
+ // Find any remaining <thinking> tag (which means it's unclosed)
20
+ const thinkingIndex = result.indexOf('<thinking>');
21
+ if (thinkingIndex !== -1) {
22
+ // Check if there's a tool tag after the thinking tag
23
+ // We want to preserve tool tags even if they're after unclosed thinking
24
+ const afterThinking = result.substring(thinkingIndex + '<thinking>'.length);
25
+
26
+ // Look for any tool tags in the remaining content
27
+ const toolPattern = /<(search|query|extract|listFiles|searchFiles|implement|attempt_completion|attempt_complete)>/;
28
+ const toolMatch = afterThinking.match(toolPattern);
29
+
30
+ if (toolMatch) {
31
+ // Found a tool tag - remove thinking tag and its content up to the tool tag
32
+ const toolStart = thinkingIndex + '<thinking>'.length + toolMatch.index;
33
+ result = result.substring(0, thinkingIndex) + result.substring(toolStart);
34
+ } else {
35
+ // No tool tag found - remove everything from <thinking> onwards
36
+ result = result.substring(0, thinkingIndex);
37
+ }
38
+ }
39
+
40
+ return result.trim();
13
41
  }
14
42
 
15
43
  /**
@@ -29,6 +57,30 @@ export function extractThinkingContent(xmlString) {
29
57
  * @returns {Object|null} - Standardized attempt_completion result or null
30
58
  */
31
59
  export function checkAttemptCompleteRecovery(cleanedXmlString, validTools = []) {
60
+ // Check for <attempt_completion> with content (with or without closing tag)
61
+ // This handles: "<attempt_completion>content" or "<attempt_completion>content</attempt_completion>"
62
+ const attemptCompletionMatch = cleanedXmlString.match(/<attempt_completion>([\s\S]*?)(?:<\/attempt_completion>|$)/);
63
+ if (attemptCompletionMatch) {
64
+ const content = attemptCompletionMatch[1].trim();
65
+ const hasClosingTag = cleanedXmlString.includes('</attempt_completion>');
66
+
67
+ if (content) {
68
+ // If there's content after the tag, use it as the result
69
+ return {
70
+ toolName: 'attempt_completion',
71
+ params: { result: content }
72
+ };
73
+ }
74
+
75
+ // If the tag exists but is empty:
76
+ // - With closing tag (e.g., "<attempt_completion></attempt_completion>"): use empty string
77
+ // - Without closing tag (e.g., "<attempt_completion>"): use previous response
78
+ return {
79
+ toolName: 'attempt_completion',
80
+ params: { result: hasClosingTag ? '' : '__PREVIOUS_RESPONSE__' }
81
+ };
82
+ }
83
+
32
84
  // Enhanced recovery logic for attempt_complete shorthand
33
85
  const attemptCompletePatterns = [
34
86
  // Standard shorthand with optional whitespace
@@ -61,7 +113,7 @@ export function checkAttemptCompleteRecovery(cleanedXmlString, validTools = [])
61
113
  if (cleanedXmlString.includes('<attempt_complete') && !hasOtherToolTags(cleanedXmlString, validTools)) {
62
114
  // This handles malformed cases where attempt_complete appears but is broken
63
115
  return {
64
- toolName: 'attempt_completion',
116
+ toolName: 'attempt_completion',
65
117
  params: { result: '__PREVIOUS_RESPONSE__' }
66
118
  };
67
119
  }
@@ -364,47 +364,62 @@ export function parseXmlToolCall(xmlString, validTools = DEFAULT_VALID_TOOLS) {
364
364
  for (const toolName of validTools) {
365
365
  const openTag = `<${toolName}>`;
366
366
  const closeTag = `</${toolName}>`;
367
-
367
+
368
368
  const openIndex = xmlString.indexOf(openTag);
369
369
  if (openIndex === -1) {
370
370
  continue; // Tool not found, try next tool
371
371
  }
372
-
373
- const closeIndex = xmlString.indexOf(closeTag, openIndex + openTag.length);
372
+
373
+ let closeIndex = xmlString.indexOf(closeTag, openIndex + openTag.length);
374
+ let hasClosingTag = closeIndex !== -1;
375
+
376
+ // If no closing tag found, use content until end of string
377
+ // This makes the parser more resilient to AI formatting errors
374
378
  if (closeIndex === -1) {
375
- continue; // No closing tag found, try next tool
379
+ closeIndex = xmlString.length;
376
380
  }
377
-
378
- // Extract the content between tags
381
+
382
+ // Extract the content between tags (or until end if no closing tag)
379
383
  const innerContent = xmlString.substring(
380
- openIndex + openTag.length,
384
+ openIndex + openTag.length,
381
385
  closeIndex
382
386
  );
383
-
387
+
384
388
  const params = {};
385
389
 
386
390
  // Parse parameters using string-based approach for better safety
387
391
  // Common parameter names to look for (can be extended as needed)
388
392
  // Note: includes both camelCase and underscore_case variants to handle inconsistencies
389
- const commonParams = ['query', 'file_path', 'line', 'end_line', 'path', 'recursive', 'includeHidden',
393
+ const commonParams = ['query', 'file_path', 'line', 'end_line', 'path', 'recursive', 'includeHidden',
390
394
  'max_results', 'maxResults', 'result', 'command', 'description', 'task', 'param', 'pattern',
391
395
  'allow_tests', 'exact', 'maxTokens', 'language', 'input_content',
392
396
  'context_lines', 'format', 'directory', 'autoCommits', 'files', 'targets'];
393
-
397
+
394
398
  for (const paramName of commonParams) {
395
399
  const paramOpenTag = `<${paramName}>`;
396
400
  const paramCloseTag = `</${paramName}>`;
397
-
401
+
398
402
  const paramOpenIndex = innerContent.indexOf(paramOpenTag);
399
403
  if (paramOpenIndex === -1) {
400
404
  continue; // Parameter not found
401
405
  }
402
-
403
- const paramCloseIndex = innerContent.indexOf(paramCloseTag, paramOpenIndex + paramOpenTag.length);
406
+
407
+ let paramCloseIndex = innerContent.indexOf(paramCloseTag, paramOpenIndex + paramOpenTag.length);
408
+
409
+ // Handle unclosed parameter tags - use content until next tag or end of content
404
410
  if (paramCloseIndex === -1) {
405
- continue; // No closing tag found
411
+ // Find the next opening tag after this parameter
412
+ let nextTagIndex = innerContent.length;
413
+ for (const nextParam of commonParams) {
414
+ const nextOpenTag = `<${nextParam}>`;
415
+ const nextIndex = innerContent.indexOf(nextOpenTag, paramOpenIndex + paramOpenTag.length);
416
+ if (nextIndex !== -1 && nextIndex < nextTagIndex) {
417
+ nextTagIndex = nextIndex;
418
+ }
419
+ }
420
+ paramCloseIndex = nextTagIndex;
406
421
  }
407
-
422
+
408
423
  let paramValue = innerContent.substring(
409
424
  paramOpenIndex + paramOpenTag.length,
410
425
  paramCloseIndex