@caupulican/pi-ai 0.85.3 → 0.85.4

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.
Files changed (36) hide show
  1. package/dist/bedrock-provider.d.ts +1 -0
  2. package/dist/bedrock-provider.d.ts.map +1 -1
  3. package/dist/bedrock-provider.js +1 -0
  4. package/dist/bedrock-provider.js.map +1 -1
  5. package/dist/bedrock-scope.d.ts +35 -0
  6. package/dist/bedrock-scope.d.ts.map +1 -0
  7. package/dist/bedrock-scope.js +141 -0
  8. package/dist/bedrock-scope.js.map +1 -0
  9. package/dist/env-api-keys.d.ts.map +1 -1
  10. package/dist/env-api-keys.js +4 -1
  11. package/dist/env-api-keys.js.map +1 -1
  12. package/dist/image-models.generated.js +1 -1
  13. package/dist/image-models.generated.js.map +1 -1
  14. package/dist/models.generated.d.ts +217 -30
  15. package/dist/models.generated.d.ts.map +1 -1
  16. package/dist/models.generated.js +225 -80
  17. package/dist/models.generated.js.map +1 -1
  18. package/dist/stream.d.ts.map +1 -1
  19. package/dist/stream.js +193 -87
  20. package/dist/stream.js.map +1 -1
  21. package/dist/utils/tool-repair/registry.d.ts +21 -0
  22. package/dist/utils/tool-repair/registry.d.ts.map +1 -1
  23. package/dist/utils/tool-repair/registry.js +27 -0
  24. package/dist/utils/tool-repair/registry.js.map +1 -1
  25. package/dist/utils/tool-repair/text-protocol-history.d.ts.map +1 -1
  26. package/dist/utils/tool-repair/text-protocol-history.js +4 -1
  27. package/dist/utils/tool-repair/text-protocol-history.js.map +1 -1
  28. package/dist/utils/tool-repair/text-protocol-live-filter.d.ts +5 -0
  29. package/dist/utils/tool-repair/text-protocol-live-filter.d.ts.map +1 -1
  30. package/dist/utils/tool-repair/text-protocol-live-filter.js +11 -0
  31. package/dist/utils/tool-repair/text-protocol-live-filter.js.map +1 -1
  32. package/dist/utils/tool-repair/text-protocol.d.ts +5 -1
  33. package/dist/utils/tool-repair/text-protocol.d.ts.map +1 -1
  34. package/dist/utils/tool-repair/text-protocol.js +49 -27
  35. package/dist/utils/tool-repair/text-protocol.js.map +1 -1
  36. package/package.json +3 -1
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/registry.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,kBAAkB;IAClB,oBAAoB;IACpB,iBAAiB;IACjB,2BAA2B;IAC3B,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,uBAAuB;IACvB,qBAAqB;IACrB,0BAA0B;IAC1B,qBAAqB;IACrB,mBAAmB;CACV,CAAC;AAWX,MAAM,CAAC,MAAM,oBAAoB,GAAuC;IACvE;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,2DAA2D;QACzE,YAAY,EAAE,+CAA+C;KAC7D;IACD;QACC,IAAI,EAAE,oBAAoB;QAC1B,YAAY,EAAE,8DAA8D;QAC5E,YAAY,EAAE,6EAA6E;KAC3F;IACD;QACC,IAAI,EAAE,iBAAiB;QACvB,YAAY,EAAE,uEAAuE;QACrF,YAAY,EACX,+GAA+G;KAChH;IACD;QACC,IAAI,EAAE,2BAA2B;QACjC,YAAY,EACX,6GAA6G;QAC9G,YAAY,EACX,uHAAuH;KACxH;IACD;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,+DAA+D;QAC7E,YAAY,EAAE,kEAAkE;KAChF;IACD;QACC,IAAI,EAAE,gBAAgB;QACtB,YAAY,EAAE,mEAAmE;QACjF,YAAY,EAAE,kEAAkE;KAChF;IACD;QACC,IAAI,EAAE,wBAAwB;QAC9B,YAAY,EAAE,kEAAkE;QAChF,YAAY,EAAE,oEAAoE;KAClF;IACD;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,wDAAwD;QACtE,YAAY,EAAE,6EAA6E;KAC3F;IACD;QACC,IAAI,EAAE,gBAAgB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KAAK,EAAE,aAAa,IAAI,QAAQ,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,YAAoB;IACjE,OAAO,2BAA2B,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC;AAC5D,CAAC","sourcesContent":["export const TOOL_REPAIR_MODE_NAMES = [\n\t\"nullOptionalDrop\",\n\t\"nullRequiredBounce\",\n\t\"jsonStringParse\",\n\t\"jsonObjectPropertySalvage\",\n\t\"singleObjectWrap\",\n\t\"bareScalarWrap\",\n\t\"emptyObjectPlaceholder\",\n\t\"numberFromString\",\n\t\"boolFromString\",\n\t\"enumCaseNormalize\",\n\t\"propertyCaseNormalize\",\n\t\"singleElementUnwrap\",\n\t\"stringifiedNumberInArray\",\n\t\"bashCommandArgvJoin\",\n\t\"bashCommandUnwrap\",\n] as const;\n\nexport type ToolRepairModeName = (typeof TOOL_REPAIR_MODE_NAMES)[number];\nexport type ToolRepairFailureModeName = ToolRepairModeName | \"other\";\n\nexport interface ToolRepairRegistryEntry {\n\tname: ToolRepairModeName;\n\tnoteTemplate: string;\n\tstandingRule: string;\n}\n\nexport const TOOL_REPAIR_REGISTRY: readonly ToolRepairRegistryEntry[] = [\n\t{\n\t\tname: \"nullOptionalDrop\",\n\t\tnoteTemplate: \"sent null for optional `{path}` -> omit the field instead\",\n\t\tstandingRule: \"Omit optional fields instead of sending null.\",\n\t},\n\t{\n\t\tname: \"nullRequiredBounce\",\n\t\tnoteTemplate: \"`{path}` is required and cannot be null -> send a real value\",\n\t\tstandingRule: \"Send real values for required fields; never send null for a required field.\",\n\t},\n\t{\n\t\tname: \"jsonStringParse\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted JSON string -> send a raw JSON array/object\",\n\t\tstandingRule:\n\t\t\t\"Send raw JSON arrays/objects where the tool schema expects arrays/objects; do not quote them as JSON strings.\",\n\t},\n\t{\n\t\tname: \"jsonObjectPropertySalvage\",\n\t\tnoteTemplate:\n\t\t\t\"sent `{path}` as malformed JSON with recoverable declared properties -> keep the schema-declared properties\",\n\t\tstandingRule:\n\t\t\t\"When sending JSON objects, use strict JSON syntax with commas between properties and no extra text inside the object.\",\n\t},\n\t{\n\t\tname: \"singleObjectWrap\",\n\t\tnoteTemplate: \"sent one object where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single object in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"bareScalarWrap\",\n\t\tnoteTemplate: \"sent a single value where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single scalar in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"emptyObjectPlaceholder\",\n\t\tnoteTemplate: \"sent `{}` as a placeholder -> omit `{path}`; its default applies\",\n\t\tstandingRule: \"Omit defaulted object fields instead of sending `{}` placeholders.\",\n\t},\n\t{\n\t\tname: \"numberFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted number -> send a bare number\",\n\t\tstandingRule: \"Send bare numbers where the tool schema expects numbers; do not quote them.\",\n\t},\n\t{\n\t\tname: \"boolFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted boolean -> send bare true/false\",\n\t\tstandingRule: \"Send bare true/false where the tool schema expects booleans; do not quote them.\",\n\t},\n\t{\n\t\tname: \"enumCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` matched a declared enum value after case/space normalization\",\n\t\tstandingRule: \"Use enum values exactly as declared, preserving case and spacing.\",\n\t},\n\t{\n\t\tname: \"propertyCaseNormalize\",\n\t\tnoteTemplate: \"sent `{path}` with different property-key casing -> use the schema key casing\",\n\t\tstandingRule: \"Use tool argument property names exactly as declared in the schema, preserving case.\",\n\t},\n\t{\n\t\tname: \"singleElementUnwrap\",\n\t\tnoteTemplate: \"sent `{path}` as a 1-item list where a single value was expected -> send the value\",\n\t\tstandingRule:\n\t\t\t\"Send a single value directly when the tool schema expects a single value; do not wrap it in a one-item list.\",\n\t},\n\t{\n\t\tname: \"stringifiedNumberInArray\",\n\t\tnoteTemplate: \"list `{path}` holds quoted numbers -> send bare numbers\",\n\t\tstandingRule: \"Use bare numbers inside number arrays; do not quote them.\",\n\t},\n\t{\n\t\tname: \"bashCommandArgvJoin\",\n\t\tnoteTemplate: \"bash takes one command string, not an argv list -> joined the argv values\",\n\t\tstandingRule: \"For bash, send one command string rather than an argv array.\",\n\t},\n\t{\n\t\tname: \"bashCommandUnwrap\",\n\t\tnoteTemplate: \"bash `command` is a string -> unwrapped the command object\",\n\t\tstandingRule: \"For bash, send `command` as a string rather than an object wrapper.\",\n\t},\n] as const;\n\nconst registryByName = new Map(TOOL_REPAIR_REGISTRY.map((entry) => [entry.name, entry]));\n\nexport function getToolRepairRegistryEntry(name: ToolRepairModeName): ToolRepairRegistryEntry {\n\tconst entry = registryByName.get(name);\n\tif (!entry) throw new Error(`Unknown tool repair mode: ${name}`);\n\treturn entry;\n}\n\nexport function formatToolRepairNote(name: ToolRepairModeName, path: string): string {\n\treturn getToolRepairRegistryEntry(name).noteTemplate.replaceAll(\"{path}\", path);\n}\n\nexport function formatToolRepairStandingRule(name: ToolRepairModeName): string {\n\treturn getToolRepairRegistryEntry(name).standingRule;\n}\n\nexport type ToolExecutionAttemptMemory = \"retain\" | \"discard\";\nexport type ToolFailurePhase =\n\t| \"validation\"\n\t| \"policy\"\n\t| \"preflight\"\n\t| \"execution\"\n\t| \"timeout\"\n\t| \"cancelled\"\n\t| \"provisioning\";\n\ninterface ToolExecutionErrorCatalogueEntry {\n\tname: string;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory?: ToolExecutionAttemptMemory;\n\tretainDiagnostic?: boolean;\n\tmatches(message: string): boolean;\n}\n\nexport const TOOL_EXECUTION_ERROR_CATALOGUE = [\n\t{\n\t\tname: \"provisioningFailed\",\n\t\tphase: \"provisioning\",\n\t\tfailureCode: \"provisioning_failed\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Provisioning failed; use the exact diagnostic, repair that cause, and retry only after the environment changes.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_TOOL_PROVISIONING_FAILED\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"commandNotFound\",\n\t\tphase: \"provisioning\",\n\t\tguidance: \"Command was not found; check the command name or available tools before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /^spawn \\S+ ENOENT\\b/i.test(message) || /(?:^|\\n|:)\\s*command not found\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"encodingCorruption\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"encoding_corruption\",\n\t\tattemptMemory: \"discard\",\n\t\tguidance:\n\t\t\t\"Change approach: exact UTF-8 text replacement is unsafe for this file. Use an encoding-aware or byte-safe tool/workflow instead; do not replay the text edit.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_ENCODING_CORRUPTION\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"fileNotFound\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Path was not found; list the parent directory or re-read the path before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bENOENT\\b/i.test(message) || /no such file or directory/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"editOldTextNotFound\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Re-read the target file and use the exact current text before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /(?:oldText|old text|exact text).*(?:not found|no match|failed to match|must match)/is.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"pathOutsideCwd\",\n\t\tphase: \"policy\",\n\t\tguidance: \"Choose a path inside the current working directory, or ask before changing scope.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /outside (?:the )?(?:current working directory|cwd|workspace|root)/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"permissionDenied\",\n\t\tphase: \"policy\",\n\t\tfailureCode: \"permission_denied\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Access was denied; verify the target path and current authority, then request or change permissions before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:EACCES|EPERM)\\b/i.test(message) || /(?:permission|access) (?:is )?denied/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"invalidOption\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"invalid_option\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"Option rejected; re-read command help and remove or replace it before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:invalid|unknown|unrecognized) (?:command-line )?(?:option|argument)\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"invalidPattern\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"invalid_pattern\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"The search pattern was invalid; simplify it or correct its regex/glob escaping before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/(?:regex|regular expression|glob) (?:parse )?error\\b/i.test(message) ||\n\t\t\t\t/\\bunclosed (?:group|class)\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"outputLimit\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"output_limit\",\n\t\tguidance:\n\t\t\t\"Output exceeded its bound; narrow the scope, page the request, or use the retained artifact before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:output|result|response).*(?:limit|truncat|too large)\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"timedOut\",\n\t\tphase: \"timeout\",\n\t\tfailureCode: \"timeout\",\n\t\tguidance:\n\t\t\t\"The operation timed out; narrow or split the work, then retry once only when repeating it is safe and still required.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/\\b(?:command|operation|process|request|tool)\\s+(?:timed out|timeout(?: after)?)\\b/i.test(message) ||\n\t\t\t\t/\\bETIMEDOUT\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"cancelled\",\n\t\tphase: \"cancelled\",\n\t\tfailureCode: \"cancelled\",\n\t\tguidance:\n\t\t\t\"The operation was cancelled; retry only if it is still required and the cancellation condition has cleared.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/^(?:operation|request|tool) (?:was )?(?:aborted|cancelled|canceled)\\b/i.test(message) ||\n\t\t\t\t/\\bAbortError\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n] as const satisfies readonly ToolExecutionErrorCatalogueEntry[];\n\nexport type ToolExecutionErrorClass = (typeof TOOL_EXECUTION_ERROR_CATALOGUE)[number][\"name\"];\nconst executionErrorCatalogue: readonly ToolExecutionErrorCatalogueEntry[] = TOOL_EXECUTION_ERROR_CATALOGUE;\n\nexport interface ToolExecutionErrorPolicy {\n\tname: ToolExecutionErrorClass;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory: ToolExecutionAttemptMemory;\n\tretainDiagnostic: boolean;\n}\n\nexport function getToolExecutionErrorPolicy(errorMessage: string): ToolExecutionErrorPolicy | undefined {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.matches(errorMessage));\n\tif (!entry) return undefined;\n\treturn {\n\t\tname: entry.name as ToolExecutionErrorClass,\n\t\tphase: entry.phase,\n\t\tguidance: entry.guidance,\n\t\t...(entry.failureCode ? { failureCode: entry.failureCode } : {}),\n\t\tattemptMemory: entry.attemptMemory ?? \"retain\",\n\t\tretainDiagnostic: entry.retainDiagnostic ?? false,\n\t};\n}\n\nexport function getToolExecutionAttemptMemory(failureCode: string): ToolExecutionAttemptMemory {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.failureCode === failureCode);\n\treturn entry?.attemptMemory ?? \"retain\";\n}\n\nexport function getToolExecutionErrorGuidance(errorMessage: string): string | undefined {\n\treturn getToolExecutionErrorPolicy(errorMessage)?.guidance;\n}\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/registry.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,kBAAkB;IAClB,oBAAoB;IACpB,iBAAiB;IACjB,2BAA2B;IAC3B,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,kBAAkB;IAClB,gBAAgB;IAChB,mBAAmB;IACnB,uBAAuB;IACvB,qBAAqB;IACrB,0BAA0B;IAC1B,qBAAqB;IACrB,mBAAmB;CACV,CAAC;AAWX,MAAM,CAAC,MAAM,oBAAoB,GAAuC;IACvE;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,2DAA2D;QACzE,YAAY,EAAE,+CAA+C;KAC7D;IACD;QACC,IAAI,EAAE,oBAAoB;QAC1B,YAAY,EAAE,8DAA8D;QAC5E,YAAY,EAAE,6EAA6E;KAC3F;IACD;QACC,IAAI,EAAE,iBAAiB;QACvB,YAAY,EAAE,uEAAuE;QACrF,YAAY,EACX,+GAA+G;KAChH;IACD;QACC,IAAI,EAAE,2BAA2B;QACjC,YAAY,EACX,6GAA6G;QAC9G,YAAY,EACX,uHAAuH;KACxH;IACD;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,+DAA+D;QAC7E,YAAY,EAAE,kEAAkE;KAChF;IACD;QACC,IAAI,EAAE,gBAAgB;QACtB,YAAY,EAAE,mEAAmE;QACjF,YAAY,EAAE,kEAAkE;KAChF;IACD;QACC,IAAI,EAAE,wBAAwB;QAC9B,YAAY,EAAE,kEAAkE;QAChF,YAAY,EAAE,oEAAoE;KAClF;IACD;QACC,IAAI,EAAE,kBAAkB;QACxB,YAAY,EAAE,wDAAwD;QACtE,YAAY,EAAE,6EAA6E;KAC3F;IACD;QACC,IAAI,EAAE,gBAAgB;QACtB,YAAY,EAAE,2DAA2D;QACzE,YAAY,EAAE,iFAAiF;KAC/F;IACD;QACC,IAAI,EAAE,mBAAmB;QACzB,YAAY,EAAE,uEAAuE;QACr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AAO;QACN,IAAI,EAAE,KAAK,CAAC,IAA+B;QAC3C,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,aAAa,EAAE,KAAK,CAAC,aAAa,IAAI,QAAQ;QAC9C,gBAAgB,EAAE,KAAK,CAAC,gBAAgB,IAAI,KAAK;KACjD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,WAAmB;IAChE,MAAM,KAAK,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,WAAW,KAAK,WAAW,CAAC,CAAC;IACjG,OAAO,KAAK,EAAE,aAAa,IAAI,QAAQ,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,YAAoB;IACjE,OAAO,2BAA2B,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC;AAC5D,CAAC","sourcesContent":["export const TOOL_REPAIR_MODE_NAMES = [\n\t\"nullOptionalDrop\",\n\t\"nullRequiredBounce\",\n\t\"jsonStringParse\",\n\t\"jsonObjectPropertySalvage\",\n\t\"singleObjectWrap\",\n\t\"bareScalarWrap\",\n\t\"emptyObjectPlaceholder\",\n\t\"numberFromString\",\n\t\"boolFromString\",\n\t\"enumCaseNormalize\",\n\t\"propertyCaseNormalize\",\n\t\"singleElementUnwrap\",\n\t\"stringifiedNumberInArray\",\n\t\"bashCommandArgvJoin\",\n\t\"bashCommandUnwrap\",\n] as const;\n\nexport type ToolRepairModeName = (typeof TOOL_REPAIR_MODE_NAMES)[number];\nexport type ToolRepairFailureModeName = ToolRepairModeName | \"other\";\n\nexport interface ToolRepairRegistryEntry {\n\tname: ToolRepairModeName;\n\tnoteTemplate: string;\n\tstandingRule: string;\n}\n\nexport const TOOL_REPAIR_REGISTRY: readonly ToolRepairRegistryEntry[] = [\n\t{\n\t\tname: \"nullOptionalDrop\",\n\t\tnoteTemplate: \"sent null for optional `{path}` -> omit the field instead\",\n\t\tstandingRule: \"Omit optional fields instead of sending null.\",\n\t},\n\t{\n\t\tname: \"nullRequiredBounce\",\n\t\tnoteTemplate: \"`{path}` is required and cannot be null -> send a real value\",\n\t\tstandingRule: \"Send real values for required fields; never send null for a required field.\",\n\t},\n\t{\n\t\tname: \"jsonStringParse\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted JSON string -> send a raw JSON array/object\",\n\t\tstandingRule:\n\t\t\t\"Send raw JSON arrays/objects where the tool schema expects arrays/objects; do not quote them as JSON strings.\",\n\t},\n\t{\n\t\tname: \"jsonObjectPropertySalvage\",\n\t\tnoteTemplate:\n\t\t\t\"sent `{path}` as malformed JSON with recoverable declared properties -> keep the schema-declared properties\",\n\t\tstandingRule:\n\t\t\t\"When sending JSON objects, use strict JSON syntax with commas between properties and no extra text inside the object.\",\n\t},\n\t{\n\t\tname: \"singleObjectWrap\",\n\t\tnoteTemplate: \"sent one object where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single object in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"bareScalarWrap\",\n\t\tnoteTemplate: \"sent a single value where `{path}` takes a list -> wrap it in [ ]\",\n\t\tstandingRule: \"Wrap a single scalar in [ ] when the tool schema expects a list.\",\n\t},\n\t{\n\t\tname: \"emptyObjectPlaceholder\",\n\t\tnoteTemplate: \"sent `{}` as a placeholder -> omit `{path}`; its default applies\",\n\t\tstandingRule: \"Omit defaulted object fields instead of sending `{}` placeholders.\",\n\t},\n\t{\n\t\tname: \"numberFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted number -> send a bare number\",\n\t\tstandingRule: \"Send bare numbers where the tool schema expects numbers; do not quote them.\",\n\t},\n\t{\n\t\tname: \"boolFromString\",\n\t\tnoteTemplate: \"sent `{path}` as a quoted boolean -> send bare true/false\",\n\t\tstandingRule: \"Send bare true/false where the tool schema expects booleans; do not quote them.\",\n\t},\n\t{\n\t\tname: \"enumCaseNormalize\",\n\t\tnoteTemplate: \"`{path}` matched a declared enum value after case/space normalization\",\n\t\tstandingRule: \"Use enum values exactly as declared, preserving case and spacing.\",\n\t},\n\t{\n\t\tname: \"propertyCaseNormalize\",\n\t\tnoteTemplate: \"sent `{path}` with different property-key casing -> use the schema key casing\",\n\t\tstandingRule: \"Use tool argument property names exactly as declared in the schema, preserving case.\",\n\t},\n\t{\n\t\tname: \"singleElementUnwrap\",\n\t\tnoteTemplate: \"sent `{path}` as a 1-item list where a single value was expected -> send the value\",\n\t\tstandingRule:\n\t\t\t\"Send a single value directly when the tool schema expects a single value; do not wrap it in a one-item list.\",\n\t},\n\t{\n\t\tname: \"stringifiedNumberInArray\",\n\t\tnoteTemplate: \"list `{path}` holds quoted numbers -> send bare numbers\",\n\t\tstandingRule: \"Use bare numbers inside number arrays; do not quote them.\",\n\t},\n\t{\n\t\tname: \"bashCommandArgvJoin\",\n\t\tnoteTemplate: \"bash takes one command string, not an argv list -> joined the argv values\",\n\t\tstandingRule: \"For bash, send one command string rather than an argv array.\",\n\t},\n\t{\n\t\tname: \"bashCommandUnwrap\",\n\t\tnoteTemplate: \"bash `command` is a string -> unwrapped the command object\",\n\t\tstandingRule: \"For bash, send `command` as a string rather than an object wrapper.\",\n\t},\n] as const;\n\nconst registryByName = new Map(TOOL_REPAIR_REGISTRY.map((entry) => [entry.name, entry]));\n\nexport function getToolRepairRegistryEntry(name: ToolRepairModeName): ToolRepairRegistryEntry {\n\tconst entry = registryByName.get(name);\n\tif (!entry) throw new Error(`Unknown tool repair mode: ${name}`);\n\treturn entry;\n}\n\nexport function formatToolRepairNote(name: ToolRepairModeName, path: string): string {\n\treturn getToolRepairRegistryEntry(name).noteTemplate.replaceAll(\"{path}\", path);\n}\n\nexport function formatToolRepairStandingRule(name: ToolRepairModeName): string {\n\treturn getToolRepairRegistryEntry(name).standingRule;\n}\n\nexport type ToolExecutionAttemptMemory = \"retain\" | \"discard\";\nexport type ToolFailurePhase =\n\t| \"validation\"\n\t| \"policy\"\n\t| \"preflight\"\n\t| \"execution\"\n\t| \"timeout\"\n\t| \"cancelled\"\n\t| \"provisioning\";\n\nexport const REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE = {\n\tfailureCode: \"repeated_successful_call\",\n\tdiagnostic: \"The identical phone tool call already succeeded and was not executed again.\",\n\tguidance:\n\t\t\"Use the previous successful result and continue; it is quoted in the diagnostic. Answer the user if the task is complete, or call a different required tool. Do not retry the same call unchanged.\",\n} as const;\n\ninterface ToolExecutionErrorCatalogueEntry {\n\tname: string;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory?: ToolExecutionAttemptMemory;\n\tretainDiagnostic?: boolean;\n\tmatches(message: string): boolean;\n}\n\nexport const TOOL_EXECUTION_ERROR_CATALOGUE = [\n\t{\n\t\tname: \"provisioningFailed\",\n\t\tphase: \"provisioning\",\n\t\tfailureCode: \"provisioning_failed\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Provisioning failed; use the exact diagnostic, repair that cause, and retry only after the environment changes.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_TOOL_PROVISIONING_FAILED\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"commandNotFound\",\n\t\tphase: \"provisioning\",\n\t\tguidance: \"Command was not found; check the command name or available tools before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /^spawn \\S+ ENOENT\\b/i.test(message) || /(?:^|\\n|:)\\s*command not found\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"encodingCorruption\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"encoding_corruption\",\n\t\tattemptMemory: \"discard\",\n\t\tguidance:\n\t\t\t\"Change approach: exact UTF-8 text replacement is unsafe for this file. Use an encoding-aware or byte-safe tool/workflow instead; do not replay the text edit.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_ENCODING_CORRUPTION\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"repeatedSuccessfulCall\",\n\t\tphase: \"execution\",\n\t\tfailureCode: REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.failureCode,\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance: REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.guidance,\n\t\tmatches(message: string): boolean {\n\t\t\treturn message === REPEATED_SUCCESSFUL_TOOL_CALL_FAILURE.diagnostic;\n\t\t},\n\t},\n\t{\n\t\tname: \"fileMutationRetarget\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"mutation_retarget_required\",\n\t\tattemptMemory: \"discard\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"The mutation payload is already retained by the harness. Choose only the corrected target path and reuse the exact payloadRef from the diagnostic; do not regenerate content or edits.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bPI_FILE_MUTATION_RETARGET\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"fileNotFound\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Path was not found; list the parent directory or re-read the path before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\bENOENT\\b/i.test(message) || /no such file or directory/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"editOldTextNotFound\",\n\t\tphase: \"execution\",\n\t\tguidance: \"Re-read the target file and use the exact current text before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /(?:oldText|old text|exact text).*(?:not found|no match|failed to match|must match)/is.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"pathOutsideCwd\",\n\t\tphase: \"policy\",\n\t\tguidance: \"Choose a path inside the current working directory, or ask before changing scope.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /outside (?:the )?(?:current working directory|cwd|workspace|root)/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"permissionDenied\",\n\t\tphase: \"policy\",\n\t\tfailureCode: \"permission_denied\",\n\t\tretainDiagnostic: true,\n\t\tguidance:\n\t\t\t\"Access was denied; verify the target path and current authority, then request or change permissions before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:EACCES|EPERM)\\b/i.test(message) || /(?:permission|access) (?:is )?denied/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"invalidOption\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"invalid_option\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"Option rejected; re-read command help and remove or replace it before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:invalid|unknown|unrecognized) (?:command-line )?(?:option|argument)\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"invalidPattern\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"invalid_pattern\",\n\t\tretainDiagnostic: true,\n\t\tguidance: \"The search pattern was invalid; simplify it or correct its regex/glob escaping before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/(?:regex|regular expression|glob) (?:parse )?error\\b/i.test(message) ||\n\t\t\t\t/\\bunclosed (?:group|class)\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"outputLimit\",\n\t\tphase: \"execution\",\n\t\tfailureCode: \"output_limit\",\n\t\tguidance:\n\t\t\t\"Output exceeded its bound; narrow the scope, page the request, or use the retained artifact before retrying.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn /\\b(?:output|result|response).*(?:limit|truncat|too large)\\b/i.test(message);\n\t\t},\n\t},\n\t{\n\t\tname: \"timedOut\",\n\t\tphase: \"timeout\",\n\t\tfailureCode: \"timeout\",\n\t\tguidance:\n\t\t\t\"The operation timed out; narrow or split the work, then retry once only when repeating it is safe and still required.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/\\b(?:command|operation|process|request|tool)\\s+(?:timed out|timeout(?: after)?)\\b/i.test(message) ||\n\t\t\t\t/\\bETIMEDOUT\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n\t{\n\t\tname: \"cancelled\",\n\t\tphase: \"cancelled\",\n\t\tfailureCode: \"cancelled\",\n\t\tguidance:\n\t\t\t\"The operation was cancelled; retry only if it is still required and the cancellation condition has cleared.\",\n\t\tmatches(message: string): boolean {\n\t\t\treturn (\n\t\t\t\t/^(?:operation|request|tool) (?:was )?(?:aborted|cancelled|canceled)\\b/i.test(message) ||\n\t\t\t\t/\\bAbortError\\b/i.test(message)\n\t\t\t);\n\t\t},\n\t},\n] as const satisfies readonly ToolExecutionErrorCatalogueEntry[];\n\nexport type ToolExecutionErrorClass = (typeof TOOL_EXECUTION_ERROR_CATALOGUE)[number][\"name\"];\nconst executionErrorCatalogue: readonly ToolExecutionErrorCatalogueEntry[] = TOOL_EXECUTION_ERROR_CATALOGUE;\n\nexport interface ToolExecutionErrorPolicy {\n\tname: ToolExecutionErrorClass;\n\tphase: ToolFailurePhase;\n\tguidance: string;\n\tfailureCode?: string;\n\tattemptMemory: ToolExecutionAttemptMemory;\n\tretainDiagnostic: boolean;\n}\n\nexport function getToolExecutionErrorPolicy(errorMessage: string): ToolExecutionErrorPolicy | undefined {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.matches(errorMessage));\n\tif (!entry) return undefined;\n\treturn {\n\t\tname: entry.name as ToolExecutionErrorClass,\n\t\tphase: entry.phase,\n\t\tguidance: entry.guidance,\n\t\t...(entry.failureCode ? { failureCode: entry.failureCode } : {}),\n\t\tattemptMemory: entry.attemptMemory ?? \"retain\",\n\t\tretainDiagnostic: entry.retainDiagnostic ?? false,\n\t};\n}\n\nexport function getToolExecutionAttemptMemory(failureCode: string): ToolExecutionAttemptMemory {\n\tconst entry = executionErrorCatalogue.find((candidate) => candidate.failureCode === failureCode);\n\treturn entry?.attemptMemory ?? \"retain\";\n}\n\nexport function getToolExecutionErrorGuidance(errorMessage: string): string | undefined {\n\treturn getToolExecutionErrorPolicy(errorMessage)?.guidance;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"text-protocol-history.d.ts","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAyB,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAE5G;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,iBAAiB,GAAG,MAAM,CAGlF"}
1
+ {"version":3,"file":"text-protocol-history.d.ts","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-history.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAyB,KAAK,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAEzF;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAE5G;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,iBAAiB,GAAG,MAAM,CAMlF"}
@@ -17,6 +17,9 @@ export function renderTextProtocolAssistantCall(toolCall, variant) {
17
17
  */
18
18
  export function renderTextProtocolToolResult(toolResult) {
19
19
  const text = joinTextContent(toolResult.content);
20
- return `Tool result (${toolResult.toolName}):\n${text.length > 0 ? text : "(see attached image)"}`;
20
+ const result = text.length > 0 ? text : "(see attached image)";
21
+ return toolResult.isError
22
+ ? `Tool result (${toolResult.toolName}; failed):\n${result}\nFollow the repair or next_action before retrying; do not resend the unchanged call.`
23
+ : `Tool result (${toolResult.toolName}; succeeded):\n${result}\nUse this result and continue. Do not repeat this unchanged successful call.`;
21
24
  }
22
25
  //# sourceMappingURL=text-protocol-history.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-protocol-history.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE,OAAO,EAAE,qBAAqB,EAAgC,MAAM,oBAAoB,CAAC;AAEzF;;;;;;GAMG;AACH,MAAM,UAAU,+BAA+B,CAAC,QAAkB,EAAE,OAAgC;IACnG,OAAO,qBAAqB,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;AAChG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,UAA6B;IACzE,MAAM,IAAI,GAAG,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,gBAAgB,UAAU,CAAC,QAAQ,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,sBAAsB,EAAE,CAAC;AACpG,CAAC","sourcesContent":["import { joinTextContent } from \"../../providers/transform-messages.ts\";\nimport type { ToolCall, ToolResultMessage } from \"../../types.ts\";\nimport { formatVariantEnvelope, type TextToolProtocolVariant } from \"./text-protocol.ts\";\n\n/**\n * Renders a prior text-protocol tool call as the assistant-visible history text, in the exact\n * dialect `variant` teaches (reusing {@link formatVariantEnvelope} so a phone model sees its own\n * call echoed back exactly as the primer taught it to speak - the round-trip invariant this\n * module is gated on: `parseTextToolCalls(renderTextProtocolAssistantCall(call, variant), tools)`\n * must recover the SAME name+arguments).\n */\nexport function renderTextProtocolAssistantCall(toolCall: ToolCall, variant: TextToolProtocolVariant): string {\n\treturn formatVariantEnvelope(variant, toolCall.name, JSON.stringify(toolCall.arguments ?? {}));\n}\n\n/**\n * Renders a tool result as plain text a text-protocol (phone) model reads as a user turn. The\n * protocol has no `tool_call_id`; the caller places this immediately after the echoed call it\n * answers (§2.3: conversation ORDER + tool name is the only linkage a phone model has).\n */\nexport function renderTextProtocolToolResult(toolResult: ToolResultMessage): string {\n\tconst text = joinTextContent(toolResult.content);\n\treturn `Tool result (${toolResult.toolName}):\\n${text.length > 0 ? text : \"(see attached image)\"}`;\n}\n"]}
1
+ {"version":3,"file":"text-protocol-history.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE,OAAO,EAAE,qBAAqB,EAAgC,MAAM,oBAAoB,CAAC;AAEzF;;;;;;GAMG;AACH,MAAM,UAAU,+BAA+B,CAAC,QAAkB,EAAE,OAAgC;IACnG,OAAO,qBAAqB,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,CAAC;AAChG,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,UAA6B;IACzE,MAAM,IAAI,GAAG,eAAe,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,sBAAsB,CAAC;IAC/D,OAAO,UAAU,CAAC,OAAO;QACxB,CAAC,CAAC,gBAAgB,UAAU,CAAC,QAAQ,eAAe,MAAM,uFAAuF;QACjJ,CAAC,CAAC,gBAAgB,UAAU,CAAC,QAAQ,kBAAkB,MAAM,+EAA+E,CAAC;AAC/I,CAAC","sourcesContent":["import { joinTextContent } from \"../../providers/transform-messages.ts\";\nimport type { ToolCall, ToolResultMessage } from \"../../types.ts\";\nimport { formatVariantEnvelope, type TextToolProtocolVariant } from \"./text-protocol.ts\";\n\n/**\n * Renders a prior text-protocol tool call as the assistant-visible history text, in the exact\n * dialect `variant` teaches (reusing {@link formatVariantEnvelope} so a phone model sees its own\n * call echoed back exactly as the primer taught it to speak - the round-trip invariant this\n * module is gated on: `parseTextToolCalls(renderTextProtocolAssistantCall(call, variant), tools)`\n * must recover the SAME name+arguments).\n */\nexport function renderTextProtocolAssistantCall(toolCall: ToolCall, variant: TextToolProtocolVariant): string {\n\treturn formatVariantEnvelope(variant, toolCall.name, JSON.stringify(toolCall.arguments ?? {}));\n}\n\n/**\n * Renders a tool result as plain text a text-protocol (phone) model reads as a user turn. The\n * protocol has no `tool_call_id`; the caller places this immediately after the echoed call it\n * answers (§2.3: conversation ORDER + tool name is the only linkage a phone model has).\n */\nexport function renderTextProtocolToolResult(toolResult: ToolResultMessage): string {\n\tconst text = joinTextContent(toolResult.content);\n\tconst result = text.length > 0 ? text : \"(see attached image)\";\n\treturn toolResult.isError\n\t\t? `Tool result (${toolResult.toolName}; failed):\\n${result}\\nFollow the repair or next_action before retrying; do not resend the unchanged call.`\n\t\t: `Tool result (${toolResult.toolName}; succeeded):\\n${result}\\nUse this result and continue. Do not repeat this unchanged successful call.`;\n}\n"]}
@@ -11,7 +11,12 @@ export declare class TextProtocolLiveFilter {
11
11
  private closer;
12
12
  private rawLength;
13
13
  private visibleText;
14
+ private completedEnvelopes;
14
15
  get visible(): string;
16
+ /** Number of complete envelope delimiters observed in this append-only block. */
17
+ get completedEnvelopeCount(): number;
18
+ /** True while a suffix can still become an opener, or while an envelope body is open. */
19
+ get holdingPotentialEnvelope(): boolean;
15
20
  advance(delta: string): string;
16
21
  finish(fullText: string): string;
17
22
  private rebuild;
@@ -1 +1 @@
1
- {"version":3,"file":"text-protocol-live-filter.d.ts","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-live-filter.ts"],"names":[],"mappings":"AAsCA;;;;;;;GAOG;AACH,qBAAa,sBAAsB;IAClC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,WAAW,CAAM;IAEzB,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI7B;IAED,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/B;IAED,OAAO,CAAC,OAAO;IAQf,OAAO,CAAC,OAAO;CAsCf"}
1
+ {"version":3,"file":"text-protocol-live-filter.d.ts","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-live-filter.ts"],"names":[],"mappings":"AAsCA;;;;;;;GAOG;AACH,qBAAa,sBAAsB;IAClC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,kBAAkB,CAAK;IAE/B,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,iFAAiF;IACjF,IAAI,sBAAsB,IAAI,MAAM,CAEnC;IAED,yFAAyF;IACzF,IAAI,wBAAwB,IAAI,OAAO,CAEtC;IAED,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI7B;IAED,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/B;IAED,OAAO,CAAC,OAAO;IASf,OAAO,CAAC,OAAO;CAuCf"}
@@ -45,10 +45,19 @@ export class TextProtocolLiveFilter {
45
45
  this.pending = "";
46
46
  this.rawLength = 0;
47
47
  this.visibleText = "";
48
+ this.completedEnvelopes = 0;
48
49
  }
49
50
  get visible() {
50
51
  return this.visibleText;
51
52
  }
53
+ /** Number of complete envelope delimiters observed in this append-only block. */
54
+ get completedEnvelopeCount() {
55
+ return this.completedEnvelopes;
56
+ }
57
+ /** True while a suffix can still become an opener, or while an envelope body is open. */
58
+ get holdingPotentialEnvelope() {
59
+ return this.closer !== undefined || this.pending.length > 0;
60
+ }
52
61
  advance(delta) {
53
62
  this.rawLength += delta.length;
54
63
  this.consume(delta);
@@ -64,6 +73,7 @@ export class TextProtocolLiveFilter {
64
73
  this.closer = undefined;
65
74
  this.rawLength = fullText.length;
66
75
  this.visibleText = "";
76
+ this.completedEnvelopes = 0;
67
77
  this.consume(fullText);
68
78
  }
69
79
  consume(chunk) {
@@ -81,6 +91,7 @@ export class TextProtocolLiveFilter {
81
91
  }
82
92
  this.pending = this.pending.slice(closerIndex + this.closer.length);
83
93
  this.closer = undefined;
94
+ this.completedEnvelopes++;
84
95
  continue;
85
96
  }
86
97
  if (!TEXT_PROTOCOL_ENVELOPE_TRIGGER.test(this.pending)) {
@@ -1 +1 @@
1
- {"version":3,"file":"text-protocol-live-filter.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-live-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAA0C,MAAM,oBAAoB,CAAC;AAEpH,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAE9C,SAAS,0BAA0B,CAClC,IAAY;IAEZ,IAAI,IAA+E,CAAC;IACpF,KAAK,MAAM,OAAO,IAAI,sCAAsC,EAAE,CAAC;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,SAAS;QAC3B,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK;YAAE,IAAI,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,gCAAgC,CAAC,IAAY;IACrD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,OAAO,IAAI,sCAAsC,EAAE,CAAC;QAC9D,MAAM,SAAS,GAAG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E,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACpC,CAAC;QAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,WAAW,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["import { TEXT_TOOL_PROTOCOL_ENVELOPE_DELIMITERS, type TextToolProtocolEnvelopeDelimiter } from \"./text-protocol.ts\";\n\nconst TEXT_PROTOCOL_ENVELOPE_TRIGGER = /[<`]/;\n\nfunction findEarliestEnvelopeOpener(\n\ttext: string,\n): { index: number; pattern: TextToolProtocolEnvelopeDelimiter } | undefined {\n\tlet best: { index: number; pattern: TextToolProtocolEnvelopeDelimiter } | undefined;\n\tfor (const pattern of TEXT_TOOL_PROTOCOL_ENVELOPE_DELIMITERS) {\n\t\tconst index = text.indexOf(pattern.opener);\n\t\tif (index === -1) continue;\n\t\tif (!best || index < best.index) best = { index, pattern };\n\t}\n\treturn best;\n}\n\nfunction longestPendingOpenerPrefixLength(text: string): number {\n\tlet longest = 0;\n\tfor (const pattern of TEXT_TOOL_PROTOCOL_ENVELOPE_DELIMITERS) {\n\t\tconst maxLength = Math.min(text.length, pattern.opener.length - 1);\n\t\tfor (let length = maxLength; length > 0; length -= 1) {\n\t\t\tif (pattern.opener.startsWith(text.slice(text.length - length))) {\n\t\t\t\tlongest = Math.max(longest, length);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn longest;\n}\n\nfunction longestPendingCloserPrefixLength(text: string, closer: string): number {\n\tconst maxLength = Math.min(text.length, closer.length - 1);\n\tfor (let length = maxLength; length > 0; length -= 1) {\n\t\tif (closer.startsWith(text.slice(text.length - length))) return length;\n\t}\n\treturn 0;\n}\n\n/**\n * Incrementally projects safe prose from one append-only streamed text block.\n *\n * Prose mode retains only the bounded suffix that could grow into an envelope opener.\n * Envelope mode drops body text immediately and retains only a possible closer suffix.\n * `finish` reconciles once against an authoritative final value if a provider did not emit\n * append-only deltas.\n */\nexport class TextProtocolLiveFilter {\n\tprivate pending = \"\";\n\tprivate closer: string | undefined;\n\tprivate rawLength = 0;\n\tprivate visibleText = \"\";\n\n\tget visible(): string {\n\t\treturn this.visibleText;\n\t}\n\n\tadvance(delta: string): string {\n\t\tthis.rawLength += delta.length;\n\t\tthis.consume(delta);\n\t\treturn this.visibleText;\n\t}\n\n\tfinish(fullText: string): string {\n\t\tif (fullText.length !== this.rawLength) this.rebuild(fullText);\n\t\treturn this.visibleText;\n\t}\n\n\tprivate rebuild(fullText: string): void {\n\t\tthis.pending = \"\";\n\t\tthis.closer = undefined;\n\t\tthis.rawLength = fullText.length;\n\t\tthis.visibleText = \"\";\n\t\tthis.consume(fullText);\n\t}\n\n\tprivate consume(chunk: string): void {\n\t\tif (chunk.length === 0) return;\n\t\tthis.pending += chunk;\n\t\tconst visibleParts: string[] = [];\n\n\t\twhile (this.pending.length > 0) {\n\t\t\tif (this.closer !== undefined) {\n\t\t\t\tconst closerIndex = this.pending.indexOf(this.closer);\n\t\t\t\tif (closerIndex === -1) {\n\t\t\t\t\tconst pendingLength = longestPendingCloserPrefixLength(this.pending, this.closer);\n\t\t\t\t\tthis.pending = pendingLength > 0 ? this.pending.slice(-pendingLength) : \"\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.pending = this.pending.slice(closerIndex + this.closer.length);\n\t\t\t\tthis.closer = undefined;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!TEXT_PROTOCOL_ENVELOPE_TRIGGER.test(this.pending)) {\n\t\t\t\tvisibleParts.push(this.pending);\n\t\t\t\tthis.pending = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst match = findEarliestEnvelopeOpener(this.pending);\n\t\t\tif (!match) {\n\t\t\t\tconst pendingLength = longestPendingOpenerPrefixLength(this.pending);\n\t\t\t\tconst visibleEnd = this.pending.length - pendingLength;\n\t\t\t\tif (visibleEnd > 0) visibleParts.push(this.pending.slice(0, visibleEnd));\n\t\t\t\tthis.pending = pendingLength > 0 ? this.pending.slice(visibleEnd) : \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (match.index > 0) visibleParts.push(this.pending.slice(0, match.index));\n\t\t\tthis.pending = this.pending.slice(match.index + match.pattern.opener.length);\n\t\t\tthis.closer = match.pattern.closer;\n\t\t}\n\n\t\tif (visibleParts.length > 0) this.visibleText += visibleParts.join(\"\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"text-protocol-live-filter.js","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol-live-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sCAAsC,EAA0C,MAAM,oBAAoB,CAAC;AAEpH,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAE9C,SAAS,0BAA0B,CAClC,IAAY;IAEZ,IAAI,IAA+E,CAAC;IACpF,KAAK,MAAM,OAAO,IAAI,sCAAsC,EAAE,CAAC;QAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,KAAK,KAAK,CAAC,CAAC;YAAE,SAAS;QAC3B,IAAI,CAAC,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK;YAAE,IAAI,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,gCAAgC,CAAC,IAAY;IACrD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,OAAO,IAAI,sCAAsC,EAAE,CAAC;QAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnE,KAAK,IAAI,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,MAAM,IAAI,CA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,CAAC,CAAC;YAC3E,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7E,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACpC,CAAC;QAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,WAAW,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["import { TEXT_TOOL_PROTOCOL_ENVELOPE_DELIMITERS, type TextToolProtocolEnvelopeDelimiter } from \"./text-protocol.ts\";\n\nconst TEXT_PROTOCOL_ENVELOPE_TRIGGER = /[<`]/;\n\nfunction findEarliestEnvelopeOpener(\n\ttext: string,\n): { index: number; pattern: TextToolProtocolEnvelopeDelimiter } | undefined {\n\tlet best: { index: number; pattern: TextToolProtocolEnvelopeDelimiter } | undefined;\n\tfor (const pattern of TEXT_TOOL_PROTOCOL_ENVELOPE_DELIMITERS) {\n\t\tconst index = text.indexOf(pattern.opener);\n\t\tif (index === -1) continue;\n\t\tif (!best || index < best.index) best = { index, pattern };\n\t}\n\treturn best;\n}\n\nfunction longestPendingOpenerPrefixLength(text: string): number {\n\tlet longest = 0;\n\tfor (const pattern of TEXT_TOOL_PROTOCOL_ENVELOPE_DELIMITERS) {\n\t\tconst maxLength = Math.min(text.length, pattern.opener.length - 1);\n\t\tfor (let length = maxLength; length > 0; length -= 1) {\n\t\t\tif (pattern.opener.startsWith(text.slice(text.length - length))) {\n\t\t\t\tlongest = Math.max(longest, length);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn longest;\n}\n\nfunction longestPendingCloserPrefixLength(text: string, closer: string): number {\n\tconst maxLength = Math.min(text.length, closer.length - 1);\n\tfor (let length = maxLength; length > 0; length -= 1) {\n\t\tif (closer.startsWith(text.slice(text.length - length))) return length;\n\t}\n\treturn 0;\n}\n\n/**\n * Incrementally projects safe prose from one append-only streamed text block.\n *\n * Prose mode retains only the bounded suffix that could grow into an envelope opener.\n * Envelope mode drops body text immediately and retains only a possible closer suffix.\n * `finish` reconciles once against an authoritative final value if a provider did not emit\n * append-only deltas.\n */\nexport class TextProtocolLiveFilter {\n\tprivate pending = \"\";\n\tprivate closer: string | undefined;\n\tprivate rawLength = 0;\n\tprivate visibleText = \"\";\n\tprivate completedEnvelopes = 0;\n\n\tget visible(): string {\n\t\treturn this.visibleText;\n\t}\n\n\t/** Number of complete envelope delimiters observed in this append-only block. */\n\tget completedEnvelopeCount(): number {\n\t\treturn this.completedEnvelopes;\n\t}\n\n\t/** True while a suffix can still become an opener, or while an envelope body is open. */\n\tget holdingPotentialEnvelope(): boolean {\n\t\treturn this.closer !== undefined || this.pending.length > 0;\n\t}\n\n\tadvance(delta: string): string {\n\t\tthis.rawLength += delta.length;\n\t\tthis.consume(delta);\n\t\treturn this.visibleText;\n\t}\n\n\tfinish(fullText: string): string {\n\t\tif (fullText.length !== this.rawLength) this.rebuild(fullText);\n\t\treturn this.visibleText;\n\t}\n\n\tprivate rebuild(fullText: string): void {\n\t\tthis.pending = \"\";\n\t\tthis.closer = undefined;\n\t\tthis.rawLength = fullText.length;\n\t\tthis.visibleText = \"\";\n\t\tthis.completedEnvelopes = 0;\n\t\tthis.consume(fullText);\n\t}\n\n\tprivate consume(chunk: string): void {\n\t\tif (chunk.length === 0) return;\n\t\tthis.pending += chunk;\n\t\tconst visibleParts: string[] = [];\n\n\t\twhile (this.pending.length > 0) {\n\t\t\tif (this.closer !== undefined) {\n\t\t\t\tconst closerIndex = this.pending.indexOf(this.closer);\n\t\t\t\tif (closerIndex === -1) {\n\t\t\t\t\tconst pendingLength = longestPendingCloserPrefixLength(this.pending, this.closer);\n\t\t\t\t\tthis.pending = pendingLength > 0 ? this.pending.slice(-pendingLength) : \"\";\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tthis.pending = this.pending.slice(closerIndex + this.closer.length);\n\t\t\t\tthis.closer = undefined;\n\t\t\t\tthis.completedEnvelopes++;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!TEXT_PROTOCOL_ENVELOPE_TRIGGER.test(this.pending)) {\n\t\t\t\tvisibleParts.push(this.pending);\n\t\t\t\tthis.pending = \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tconst match = findEarliestEnvelopeOpener(this.pending);\n\t\t\tif (!match) {\n\t\t\t\tconst pendingLength = longestPendingOpenerPrefixLength(this.pending);\n\t\t\t\tconst visibleEnd = this.pending.length - pendingLength;\n\t\t\t\tif (visibleEnd > 0) visibleParts.push(this.pending.slice(0, visibleEnd));\n\t\t\t\tthis.pending = pendingLength > 0 ? this.pending.slice(visibleEnd) : \"\";\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (match.index > 0) visibleParts.push(this.pending.slice(0, match.index));\n\t\t\tthis.pending = this.pending.slice(match.index + match.pattern.opener.length);\n\t\t\tthis.closer = match.pattern.closer;\n\t\t}\n\n\t\tif (visibleParts.length > 0) this.visibleText += visibleParts.join(\"\");\n\t}\n}\n"]}
@@ -19,6 +19,10 @@ export declare function isTextToolProtocolVariant(value: unknown): value is Text
19
19
  export interface TextToolProtocolOptions {
20
20
  variant?: TextToolProtocolVariant;
21
21
  }
22
+ export interface TextToolProtocolParseOptions {
23
+ callIdPrefix?: string;
24
+ callIndexOffset?: number;
25
+ }
22
26
  export declare function normalizeTextToolProtocolOptions(option: boolean | TextToolProtocolOptions | undefined): TextToolProtocolOptions | undefined;
23
27
  /**
24
28
  * Renders one call as the wire text for `variant`. Exported read-only for the history round-trip
@@ -27,5 +31,5 @@ export declare function normalizeTextToolProtocolOptions(option: boolean | TextT
27
31
  */
28
32
  export declare function formatVariantEnvelope(variant: TextToolProtocolVariant, toolName: string, argsJson: string): string;
29
33
  export declare function generateTextToolProtocolPrimer(tools: readonly Tool[], options?: TextToolProtocolOptions): string;
30
- export declare function parseTextToolCalls(text: string, knownTools: readonly Tool[]): ParsedTextToolCalls;
34
+ export declare function parseTextToolCalls(text: string, knownTools: readonly Tool[], options?: TextToolProtocolParseOptions): ParsedTextToolCalls;
31
35
  //# sourceMappingURL=text-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"text-protocol.d.ts","sourceRoot":"","sources":["../../../src/utils/tool-repair/text-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAErD,MAAM,MAAM,4BAA4B,GAAG,SAAS,GAAG,cAAc,GAAG,cAAc,GAAG,mBAAmB,CAAC;AAE7G,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,4BAA4B,CAAC;CACvC;AAED,MAAM,MAAM,uBAAuB,GAAG,UAAU,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,CAAC;AAEhG,yGAAyG;AACzG,eAAO,MAAM,2BAA2B,EAAE,SAAS,uBAAuB,EAKzE,CAAC;AAOF,MAAM,WAAW,iCAAiC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf;AAED,4FAA4F;AAC5F,eAAO,MAAM,sCAAsC,EAAE,SAAS,iCAAiC,EAK9F,CAAC;AAEF,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,uBAAuB,CAE1F;AAED,MAAM,WAAW,uBAAuB;IACvC,OAAO,CAAC,EAAE,uBAAuB,CAAC;CAClC;AAkWD,wBAAgB,gCAAgC,CAC/C,MAAM,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,GACnD,uBAAuB,GAAG,SAAS,CAIrC;AAmBD;;;;GAIG;AACH,wBAAgB,qBAAqB,C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AC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAqXD,wBAAgB,gCAAgC,CAC/C,MAAM,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,GACnD,uBAAuB,GAAG,SAAS,CAIrC;AAmBD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CASlH;AA8JD,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,uBAAuB,GAAG,MAAM,CAchH;AAED,wBAAgB,kBAAkB,CACjC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,IAAI,EAAE,EAC3B,OAAO,CAAC,EAAE,4BAA4B,GACpC,mBAAmB,CAqBrB"}
@@ -265,14 +265,17 @@ function extractNameFromMalformedJson(raw) {
265
265
  const match = /"(?:name|tool)"\s*:\s*"([^"]+)"/.exec(raw);
266
266
  return match?.[1];
267
267
  }
268
- function parsePiCallEnvelope(match, names, index) {
268
+ function textToolCallId(prefix, index) {
269
+ return `${prefix}-${index}`;
270
+ }
271
+ function parsePiCallEnvelope(match, names, index, idPrefix) {
269
272
  if (!match.name)
270
273
  return undefined;
271
274
  const parsed = parseJsonValue(match.body);
272
275
  const args = parsed.ok ? coerceArguments(parsed.value) : coerceArguments(match.body.trim());
273
276
  return {
274
277
  type: "toolCall",
275
- id: `text-tool-${index}`,
278
+ id: textToolCallId(idPrefix, index),
276
279
  name: match.name,
277
280
  arguments: args.arguments,
278
281
  rawArguments: parsed.ok ? args.rawArguments : { text: match.body.trim() },
@@ -280,7 +283,7 @@ function parsePiCallEnvelope(match, names, index) {
280
283
  errorMessage: textToolErrorMessage(match.name, names),
281
284
  };
282
285
  }
283
- function parseFunctionXmlEnvelope(match, names, index) {
286
+ function parseFunctionXmlEnvelope(match, names, index, idPrefix) {
284
287
  if (!match.name)
285
288
  return undefined;
286
289
  if (new RegExp(`<\\/?${FUNCTION_TAG}\\b`, "i").test(match.body))
@@ -305,18 +308,18 @@ function parseFunctionXmlEnvelope(match, names, index) {
305
308
  return undefined;
306
309
  return {
307
310
  type: "toolCall",
308
- id: `text-tool-${index}`,
311
+ id: textToolCallId(idPrefix, index),
309
312
  name: match.name,
310
313
  arguments: params,
311
314
  source: "text-protocol",
312
315
  errorMessage: textToolErrorMessage(match.name, names),
313
316
  };
314
317
  }
315
- function parseEnvelope(match, names, index) {
318
+ function parseEnvelope(match, names, index, idPrefix) {
316
319
  if (match.kind === "pi_call")
317
- return parsePiCallEnvelope(match, names, index);
320
+ return parsePiCallEnvelope(match, names, index, idPrefix);
318
321
  if (match.kind === "function_xml")
319
- return parseFunctionXmlEnvelope(match, names, index);
322
+ return parseFunctionXmlEnvelope(match, names, index, idPrefix);
320
323
  const parsed = parseJsonObject(match.body);
321
324
  if (!parsed) {
322
325
  const name = extractNameFromMalformedJson(match.body);
@@ -324,7 +327,7 @@ function parseEnvelope(match, names, index) {
324
327
  return undefined;
325
328
  return {
326
329
  type: "toolCall",
327
- id: `text-tool-${index}`,
330
+ id: textToolCallId(idPrefix, index),
328
331
  name,
329
332
  arguments: match.body.trim(),
330
333
  rawArguments: { text: match.body.trim() },
@@ -340,7 +343,7 @@ function parseEnvelope(match, names, index) {
340
343
  const args = coerceArguments(argsValue);
341
344
  return {
342
345
  type: "toolCall",
343
- id: `text-tool-${index}`,
346
+ id: textToolCallId(idPrefix, index),
344
347
  name: nameValue,
345
348
  arguments: args.arguments,
346
349
  rawArguments: args.rawArguments,
@@ -411,6 +414,20 @@ function stringExampleForProperty(propertyName) {
411
414
  return "text";
412
415
  return "value";
413
416
  }
417
+ function schemaAlternatives(schemaValue) {
418
+ const schema = schemaRecord(schemaValue);
419
+ if (!schema)
420
+ return [];
421
+ const alternatives = Array.isArray(schema.anyOf)
422
+ ? schema.anyOf
423
+ : Array.isArray(schema.oneOf)
424
+ ? schema.oneOf
425
+ : undefined;
426
+ if (!alternatives)
427
+ return [schema];
428
+ const records = alternatives.map(schemaRecord).filter((entry) => entry !== undefined);
429
+ return records.length > 0 ? records : [schema];
430
+ }
414
431
  function exampleValueForSchema(schemaValue, propertyName) {
415
432
  const schema = schemaRecord(schemaValue);
416
433
  if (!schema)
@@ -439,7 +456,7 @@ function requiredPropertyNames(parameters) {
439
456
  return Array.isArray(parameters?.required) ? parameters.required.filter(firstString) : [];
440
457
  }
441
458
  function exampleArgumentsForParameters(parametersValue) {
442
- const parameters = schemaRecord(parametersValue);
459
+ const parameters = schemaAlternatives(parametersValue)[0];
443
460
  const properties = schemaRecord(parameters?.properties);
444
461
  if (!properties)
445
462
  return {};
@@ -488,22 +505,24 @@ function formatDefault(value) {
488
505
  return json ? `=${json}` : "";
489
506
  }
490
507
  function formatToolProjection(tool) {
491
- const parameters = schemaRecord(tool.parameters);
492
- const properties = schemaRecord(parameters?.properties);
493
- const required = requiredPropertyNames(parameters);
494
- const requiredSet = new Set(required);
495
- const args = properties
496
- ? orderedPropertyNames(properties, required)
497
- .map((name) => {
498
- const schema = schemaRecord(properties[name]);
499
- const optional = requiredSet.has(name) ? "" : "?";
500
- const defaultText = schema && "default" in schema ? formatDefault(schema.default) : "";
501
- return `${name}:${typeLabel(schema)}${optional}${defaultText}`;
502
- })
503
- .join(", ")
504
- : "";
508
+ const signatures = schemaAlternatives(tool.parameters).map((parameters) => {
509
+ const properties = schemaRecord(parameters.properties);
510
+ const required = requiredPropertyNames(parameters);
511
+ const requiredSet = new Set(required);
512
+ const args = properties
513
+ ? orderedPropertyNames(properties, required)
514
+ .map((name) => {
515
+ const schema = schemaRecord(properties[name]);
516
+ const optional = requiredSet.has(name) ? "" : "?";
517
+ const defaultText = schema && "default" in schema ? formatDefault(schema.default) : "";
518
+ return `${name}:${typeLabel(schema)}${optional}${defaultText}`;
519
+ })
520
+ .join(", ")
521
+ : "";
522
+ return `${tool.name}(${args})`;
523
+ });
505
524
  const description = tool.description.replace(/\s+/g, " ").trim();
506
- return `${tool.name}(${args}) - ${description}`;
525
+ return `${signatures.join(" OR ")} - ${description}`;
507
526
  }
508
527
  function toolHasArrayParameter(tool) {
509
528
  const parameters = schemaRecord(tool.parameters);
@@ -532,6 +551,7 @@ function protocolHeader(variant) {
532
551
  "Arguments are one JSON object: double-quoted keys/strings, arrays as [ ] (never a quoted string), optional args omitted rather than null.",
533
552
  "Reasoning may appear as prose before an envelope, never inside one.",
534
553
  "Emit several envelopes in one reply to call multiple tools in parallel; each is executed and answered on its own.",
554
+ "After a successful tool result, use it and continue; do not repeat the same unchanged call.",
535
555
  "Files, directories, searches, edits, writes, and shell commands always go through a tool envelope - never type out shell commands, file paths, or invented results yourself.",
536
556
  ];
537
557
  }
@@ -549,7 +569,7 @@ export function generateTextToolProtocolPrimer(tools, options) {
549
569
  }
550
570
  return lines.join("\n");
551
571
  }
552
- export function parseTextToolCalls(text, knownTools) {
572
+ export function parseTextToolCalls(text, knownTools, options) {
553
573
  if (knownTools.length === 0)
554
574
  return { calls: [], text, attempted: false };
555
575
  const matches = findToolEnvelopes(text);
@@ -557,8 +577,10 @@ export function parseTextToolCalls(text, knownTools) {
557
577
  return { calls: [], text, attempted: false };
558
578
  const names = [...knownToolNames(knownTools)];
559
579
  const parsed = [];
580
+ const idPrefix = options?.callIdPrefix?.trim() || "text-tool";
581
+ const indexOffset = options?.callIndexOffset ?? 0;
560
582
  for (const [index, match] of matches.entries()) {
561
- const call = parseEnvelope(match, names, index + 1);
583
+ const call = parseEnvelope(match, names, indexOffset + index + 1, idPrefix);
562
584
  if (call)
563
585
  parsed.push({ match, call });
564
586
  }