@code-yeongyu/senpi 2026.7.13 → 2026.7.14-2

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 (103) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
  3. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +14 -5
  4. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
  5. package/dist/core/extensions/builtin/terminal/runtime-session.d.ts +1 -1
  6. package/dist/core/extensions/builtin/terminal/runtime-session.d.ts.map +1 -1
  7. package/dist/core/extensions/builtin/terminal/runtime-session.js +3 -2
  8. package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
  9. package/dist/core/extensions/builtin/websearch/websearch/native.d.ts +1 -1
  10. package/dist/core/extensions/builtin/websearch/websearch/native.d.ts.map +1 -1
  11. package/dist/core/extensions/builtin/websearch/websearch/native.js +83 -33
  12. package/dist/core/extensions/builtin/websearch/websearch/native.js.map +1 -1
  13. package/dist/core/extensions/builtin/websearch/websearch/provider-endpoints.d.ts.map +1 -1
  14. package/dist/core/extensions/builtin/websearch/websearch/provider-endpoints.js +2 -1
  15. package/dist/core/extensions/builtin/websearch/websearch/provider-endpoints.js.map +1 -1
  16. package/dist/core/extensions/builtin/websearch/websearch/tool.d.ts.map +1 -1
  17. package/dist/core/extensions/builtin/websearch/websearch/tool.js +3 -3
  18. package/dist/core/extensions/builtin/websearch/websearch/tool.js.map +1 -1
  19. package/dist/core/model-registry.d.ts.map +1 -1
  20. package/dist/core/model-registry.js +1 -0
  21. package/dist/core/model-registry.js.map +1 -1
  22. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +18 -0
  23. package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
  24. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +16 -23
  25. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  26. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  27. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +2 -23
  28. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  29. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +175 -158
  30. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  31. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts +60 -0
  32. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts.map +1 -1
  33. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +54 -0
  34. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js.map +1 -1
  35. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +1 -1
  36. package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js.map +1 -1
  37. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts +92 -0
  38. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -1
  39. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +72 -0
  40. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js.map +1 -1
  41. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +23 -22
  42. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
  43. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +54 -54
  44. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
  45. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +0 -136
  46. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
  47. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +0 -136
  48. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
  49. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
  50. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +9 -0
  51. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
  52. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +1 -1
  53. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
  54. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +6 -2
  55. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
  56. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +8 -0
  57. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +1 -0
  58. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +92 -0
  59. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +1 -0
  60. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +6 -0
  61. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +1 -0
  62. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +54 -0
  63. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +1 -0
  64. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts +4 -0
  65. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts.map +1 -0
  66. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js +4 -0
  67. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js.map +1 -0
  68. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts +7 -0
  69. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts.map +1 -0
  70. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js +16 -0
  71. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js.map +1 -0
  72. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts +19 -0
  73. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts.map +1 -0
  74. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js +217 -0
  75. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js.map +1 -0
  76. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +4 -0
  77. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +1 -0
  78. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +46 -0
  79. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +1 -0
  80. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts +13 -0
  81. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts.map +1 -0
  82. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js +144 -0
  83. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js.map +1 -0
  84. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +5 -0
  85. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +1 -0
  86. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +208 -0
  87. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +1 -0
  88. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts +4 -0
  89. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts.map +1 -0
  90. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js +17 -0
  91. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js.map +1 -0
  92. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts +5 -0
  93. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts.map +1 -0
  94. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js +34 -0
  95. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js.map +1 -0
  96. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +3 -1
  97. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
  98. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -1
  99. package/node_modules/@earendil-works/pi-ai/package.json +1 -1
  100. package/node_modules/@earendil-works/pi-pty/native/prebuilds/darwin-arm64/senpi_pty.darwin-arm64.node +0 -0
  101. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  102. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  103. package/package.json +6 -6
@@ -0,0 +1,208 @@
1
+ import { coerceParameters } from "./coerce-parameters.js";
2
+ import { findNextInvokeMatch } from "./invoke-match.js";
3
+ import { findIncompleteInvokeOpenTag, findInvokeOpenTag, getSafeInvokeTextLength, scanInvokeBlock, } from "./invoke-tag-scanner.js";
4
+ import { parseAnthropicXmlGeneratedText } from "./parse.js";
5
+ import { ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH, createPendingFragment, } from "./stream-boundary.js";
6
+ import { createToolResolver } from "./tool-resolver.js";
7
+ export { ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH } from "./stream-boundary.js";
8
+ const FUNCTION_CALLS_OPEN_TAG = /<\s*function_calls\s*>/;
9
+ const FUNCTION_CALLS_CLOSE_TAG = /<\s*\/\s*function_calls\s*>/;
10
+ const FUNCTION_CALLS_COMPLETE_TAG = /^<\s*\/?\s*function_calls\s*>/;
11
+ const FUNCTION_CALLS_OPEN_PREFIX = "<function_calls>";
12
+ const FUNCTION_CALLS_CLOSE_PREFIX = "</function_calls>";
13
+ const EAGER_OPEN_TAG_SCAN_LENGTH = 128;
14
+ const RETAINED_FRAGMENT_OVERFLOW_MESSAGE = `Anthropic XML streaming fragment exceeded the ${ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH}-character retained-input limit.`;
15
+ function shouldEmitRawToolCallTextOnError(options) {
16
+ return options?.emitRawToolCallTextOnError === true;
17
+ }
18
+ function emitText(events, text) {
19
+ if (text.length > 0) {
20
+ events.push({ type: "text", text });
21
+ }
22
+ }
23
+ function findFunctionCallsTag(pattern, text, fromIndex) {
24
+ const match = pattern.exec(text.slice(fromIndex));
25
+ if (!match || match.index === undefined) {
26
+ return null;
27
+ }
28
+ return { index: fromIndex + match.index, length: match[0].length };
29
+ }
30
+ function isPotentialFunctionCallsTag(candidate) {
31
+ if (FUNCTION_CALLS_COMPLETE_TAG.test(candidate)) {
32
+ return false;
33
+ }
34
+ const compactCandidate = candidate.replace(/\s/g, "");
35
+ return (FUNCTION_CALLS_OPEN_PREFIX.startsWith(compactCandidate) ||
36
+ FUNCTION_CALLS_CLOSE_PREFIX.startsWith(compactCandidate));
37
+ }
38
+ function getSafeStreamTextLength(text) {
39
+ const scannerSafeLength = getSafeInvokeTextLength(text);
40
+ const lastTagIndex = text.lastIndexOf("<");
41
+ if (lastTagIndex === -1) {
42
+ return scannerSafeLength;
43
+ }
44
+ return isPotentialFunctionCallsTag(text.slice(lastTagIndex))
45
+ ? Math.min(scannerSafeLength, lastTagIndex)
46
+ : scannerSafeLength;
47
+ }
48
+ function reportError(options, message, toolCall) {
49
+ options?.onError?.(message, { toolCall });
50
+ }
51
+ export function createAnthropicXmlStreamParser(tools, options) {
52
+ const resolveTool = createToolResolver(tools);
53
+ let buffer = "";
54
+ let nextToolCallIndex = 0;
55
+ let pendingFragment = null;
56
+ function retainPendingFragment(kind) {
57
+ pendingFragment = createPendingFragment(kind, buffer);
58
+ }
59
+ function overflowPendingFragment() {
60
+ const retainedFragment = buffer;
61
+ buffer = "";
62
+ pendingFragment = null;
63
+ reportError(options, RETAINED_FRAGMENT_OVERFLOW_MESSAGE, retainedFragment);
64
+ const events = [];
65
+ if (shouldEmitRawToolCallTextOnError(options)) {
66
+ emitText(events, retainedFragment);
67
+ }
68
+ return events;
69
+ }
70
+ function processBuffer() {
71
+ const events = [];
72
+ pendingFragment = null;
73
+ while (buffer.length > 0) {
74
+ const invokeOpenTag = findInvokeOpenTag(buffer, 0);
75
+ const functionCallsOpenTag = findFunctionCallsTag(FUNCTION_CALLS_OPEN_TAG, buffer, 0);
76
+ if (functionCallsOpenTag && (!invokeOpenTag || functionCallsOpenTag.index <= invokeOpenTag.index)) {
77
+ if (functionCallsOpenTag.index > 0) {
78
+ emitText(events, buffer.slice(0, functionCallsOpenTag.index));
79
+ buffer = buffer.slice(functionCallsOpenTag.index);
80
+ continue;
81
+ }
82
+ const functionCallsCloseTag = findFunctionCallsTag(FUNCTION_CALLS_CLOSE_TAG, buffer, functionCallsOpenTag.length);
83
+ if (!functionCallsCloseTag) {
84
+ retainPendingFragment("function-calls");
85
+ break;
86
+ }
87
+ const wrapperEnd = functionCallsCloseTag.index + functionCallsCloseTag.length;
88
+ const wrapperContent = buffer.slice(functionCallsOpenTag.length, functionCallsCloseTag.index);
89
+ if (parseAnthropicXmlGeneratedText(wrapperContent, tools).length > 0) {
90
+ buffer = wrapperContent + buffer.slice(wrapperEnd);
91
+ }
92
+ else {
93
+ emitText(events, buffer.slice(0, wrapperEnd));
94
+ buffer = buffer.slice(wrapperEnd);
95
+ }
96
+ continue;
97
+ }
98
+ if (invokeOpenTag) {
99
+ if (invokeOpenTag.index > 0) {
100
+ emitText(events, buffer.slice(0, invokeOpenTag.index));
101
+ buffer = buffer.slice(invokeOpenTag.index);
102
+ continue;
103
+ }
104
+ const tool = resolveTool(invokeOpenTag.toolName);
105
+ const block = scanInvokeBlock(buffer, invokeOpenTag);
106
+ if (!tool) {
107
+ const nextKnownInvoke = findNextInvokeMatch(buffer, invokeOpenTag.index + invokeOpenTag.length, (toolName) => resolveTool(toolName) !== undefined);
108
+ if (nextKnownInvoke &&
109
+ (block === null || (nextKnownInvoke.block !== null && nextKnownInvoke.block.end === block.end))) {
110
+ emitText(events, buffer.slice(0, nextKnownInvoke.openingTag.index));
111
+ buffer = buffer.slice(nextKnownInvoke.openingTag.index);
112
+ continue;
113
+ }
114
+ }
115
+ if (!block) {
116
+ retainPendingFragment("invoke");
117
+ break;
118
+ }
119
+ const originalCallText = buffer.slice(0, block.end);
120
+ buffer = buffer.slice(block.end);
121
+ if (!tool) {
122
+ emitText(events, originalCallText);
123
+ continue;
124
+ }
125
+ const index = nextToolCallIndex;
126
+ nextToolCallIndex += 1;
127
+ const id = `anthropic-xml-tool-${index}`;
128
+ const argumentsRecord = block.parameters ? coerceParameters(block.parameters, tool) : null;
129
+ if (argumentsRecord === null) {
130
+ reportError(options, "Could not process streaming Anthropic XML tool call, keeping original text.", originalCallText);
131
+ if (shouldEmitRawToolCallTextOnError(options)) {
132
+ emitText(events, originalCallText);
133
+ }
134
+ continue;
135
+ }
136
+ events.push({ type: "toolcall_start", index, name: tool.name, id });
137
+ events.push({
138
+ type: "toolcall_delta",
139
+ index,
140
+ argumentsDelta: JSON.stringify(argumentsRecord),
141
+ });
142
+ events.push({ type: "toolcall_end", index, name: tool.name, id, arguments: argumentsRecord });
143
+ continue;
144
+ }
145
+ const safeLength = getSafeStreamTextLength(buffer);
146
+ if (safeLength === 0) {
147
+ if (buffer.length >= EAGER_OPEN_TAG_SCAN_LENGTH) {
148
+ retainPendingFragment("open-tag");
149
+ }
150
+ break;
151
+ }
152
+ emitText(events, buffer.slice(0, safeLength));
153
+ buffer = buffer.slice(safeLength);
154
+ }
155
+ return events;
156
+ }
157
+ return {
158
+ feed(textDelta) {
159
+ if (textDelta.length === 0) {
160
+ return [];
161
+ }
162
+ const events = [];
163
+ let offset = 0;
164
+ while (offset < textDelta.length) {
165
+ const capacity = ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH - buffer.length;
166
+ if (capacity === 0) {
167
+ events.push(...overflowPendingFragment());
168
+ continue;
169
+ }
170
+ const nextOffset = Math.min(textDelta.length, offset + capacity);
171
+ const chunk = textDelta.slice(offset, nextOffset);
172
+ offset = nextOffset;
173
+ buffer += chunk;
174
+ if (pendingFragment) {
175
+ if (pendingFragment.matcher.feed(chunk)) {
176
+ events.push(...processBuffer());
177
+ }
178
+ }
179
+ else {
180
+ events.push(...processBuffer());
181
+ }
182
+ if (pendingFragment && buffer.length === ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH) {
183
+ events.push(...overflowPendingFragment());
184
+ }
185
+ }
186
+ return events;
187
+ },
188
+ finish() {
189
+ const events = processBuffer();
190
+ if (buffer.length === 0) {
191
+ return events;
192
+ }
193
+ const invokeOpenTag = findInvokeOpenTag(buffer, 0) ?? findIncompleteInvokeOpenTag(buffer, 0);
194
+ if (invokeOpenTag && invokeOpenTag.index === 0 && resolveTool(invokeOpenTag.toolName)) {
195
+ reportError(options, "Could not complete streaming Anthropic XML tool call at finish.", buffer);
196
+ if (shouldEmitRawToolCallTextOnError(options)) {
197
+ emitText(events, buffer);
198
+ }
199
+ }
200
+ else {
201
+ emitText(events, buffer);
202
+ }
203
+ buffer = "";
204
+ return events;
205
+ },
206
+ };
207
+ }
208
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/stream.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EACN,2BAA2B,EAC3B,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EACN,0CAA0C,EAC1C,qBAAqB,GAErB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,0CAA0C,EAAE,MAAM,sBAAsB,CAAC;AAElF,MAAM,uBAAuB,GAAG,wBAAwB,CAAC;AACzD,MAAM,wBAAwB,GAAG,6BAA6B,CAAC;AAC/D,MAAM,2BAA2B,GAAG,+BAA+B,CAAC;AACpE,MAAM,0BAA0B,GAAG,kBAAkB,CAAC;AACtD,MAAM,2BAA2B,GAAG,mBAAmB,CAAC;AACxD,MAAM,0BAA0B,GAAG,GAAG,CAAC;AACvC,MAAM,kCAAkC,GAAG,iDAAiD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AC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;wBACzC,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,EAAE,CAAC,CAAC;oBACjC,CAAC;gBACF,CAAC;qBAAM,CAAC;oBACP,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,EAAE,CAAC,CAAC;gBACjC,CAAC;gBAED,IAAI,eAAe,IAAI,MAAM,CAAC,MAAM,KAAK,0CAA0C,EAAE,CAAC;oBACrF,MAAM,CAAC,IAAI,CAAC,GAAG,uBAAuB,EAAE,CAAC,CAAC;gBAC3C,CAAC;YACF,CAAC;YACD,OAAO,MAAM,CAAC;QACf,CAAC;QACD,MAAM;YACL,MAAM,MAAM,GAAG,aAAa,EAAE,CAAC;YAC/B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,MAAM,CAAC;YACf,CAAC;YAED,MAAM,aAAa,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,2BAA2B,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAC7F,IAAI,aAAa,IAAI,aAAa,CAAC,KAAK,KAAK,CAAC,IAAI,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACvF,WAAW,CAAC,OAAO,EAAE,iEAAiE,EAAE,MAAM,CAAC,CAAC;gBAChG,IAAI,gCAAgC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAC1B,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAC1B,CAAC;YACD,MAAM,GAAG,EAAE,CAAC;YACZ,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\nimport type { ParserOptions, StreamParser, StreamParserEvent } from \"../../types.ts\";\nimport { coerceParameters } from \"./coerce-parameters.ts\";\nimport { findNextInvokeMatch } from \"./invoke-match.ts\";\nimport {\n\tfindIncompleteInvokeOpenTag,\n\tfindInvokeOpenTag,\n\tgetSafeInvokeTextLength,\n\tscanInvokeBlock,\n} from \"./invoke-tag-scanner.ts\";\nimport { parseAnthropicXmlGeneratedText } from \"./parse.ts\";\nimport {\n\tANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH,\n\tcreatePendingFragment,\n\ttype PendingFragment,\n} from \"./stream-boundary.ts\";\nimport { createToolResolver } from \"./tool-resolver.ts\";\n\nexport { ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH } from \"./stream-boundary.ts\";\n\nconst FUNCTION_CALLS_OPEN_TAG = /<\\s*function_calls\\s*>/;\nconst FUNCTION_CALLS_CLOSE_TAG = /<\\s*\\/\\s*function_calls\\s*>/;\nconst FUNCTION_CALLS_COMPLETE_TAG = /^<\\s*\\/?\\s*function_calls\\s*>/;\nconst FUNCTION_CALLS_OPEN_PREFIX = \"<function_calls>\";\nconst FUNCTION_CALLS_CLOSE_PREFIX = \"</function_calls>\";\nconst EAGER_OPEN_TAG_SCAN_LENGTH = 128;\nconst RETAINED_FRAGMENT_OVERFLOW_MESSAGE = `Anthropic XML streaming fragment exceeded the ${ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH}-character retained-input limit.`;\n\ntype FunctionCallsTag = {\n\treadonly index: number;\n\treadonly length: number;\n};\n\nfunction shouldEmitRawToolCallTextOnError(options?: ParserOptions): boolean {\n\treturn options?.emitRawToolCallTextOnError === true;\n}\n\nfunction emitText(events: StreamParserEvent[], text: string): void {\n\tif (text.length > 0) {\n\t\tevents.push({ type: \"text\", text });\n\t}\n}\n\nfunction findFunctionCallsTag(pattern: RegExp, text: string, fromIndex: number): FunctionCallsTag | null {\n\tconst match = pattern.exec(text.slice(fromIndex));\n\tif (!match || match.index === undefined) {\n\t\treturn null;\n\t}\n\n\treturn { index: fromIndex + match.index, length: match[0].length };\n}\n\nfunction isPotentialFunctionCallsTag(candidate: string): boolean {\n\tif (FUNCTION_CALLS_COMPLETE_TAG.test(candidate)) {\n\t\treturn false;\n\t}\n\tconst compactCandidate = candidate.replace(/\\s/g, \"\");\n\treturn (\n\t\tFUNCTION_CALLS_OPEN_PREFIX.startsWith(compactCandidate) ||\n\t\tFUNCTION_CALLS_CLOSE_PREFIX.startsWith(compactCandidate)\n\t);\n}\n\nfunction getSafeStreamTextLength(text: string): number {\n\tconst scannerSafeLength = getSafeInvokeTextLength(text);\n\tconst lastTagIndex = text.lastIndexOf(\"<\");\n\tif (lastTagIndex === -1) {\n\t\treturn scannerSafeLength;\n\t}\n\n\treturn isPotentialFunctionCallsTag(text.slice(lastTagIndex))\n\t\t? Math.min(scannerSafeLength, lastTagIndex)\n\t\t: scannerSafeLength;\n}\n\nfunction reportError(options: ParserOptions | undefined, message: string, toolCall: string): void {\n\toptions?.onError?.(message, { toolCall });\n}\n\nexport function createAnthropicXmlStreamParser(tools: Tool[], options?: ParserOptions): StreamParser {\n\tconst resolveTool = createToolResolver(tools);\n\tlet buffer = \"\";\n\tlet nextToolCallIndex = 0;\n\tlet pendingFragment: PendingFragment | null = null;\n\n\tfunction retainPendingFragment(kind: PendingFragment[\"kind\"]): void {\n\t\tpendingFragment = createPendingFragment(kind, buffer);\n\t}\n\n\tfunction overflowPendingFragment(): StreamParserEvent[] {\n\t\tconst retainedFragment = buffer;\n\t\tbuffer = \"\";\n\t\tpendingFragment = null;\n\t\treportError(options, RETAINED_FRAGMENT_OVERFLOW_MESSAGE, retainedFragment);\n\n\t\tconst events: StreamParserEvent[] = [];\n\t\tif (shouldEmitRawToolCallTextOnError(options)) {\n\t\t\temitText(events, retainedFragment);\n\t\t}\n\t\treturn events;\n\t}\n\n\tfunction processBuffer(): StreamParserEvent[] {\n\t\tconst events: StreamParserEvent[] = [];\n\t\tpendingFragment = null;\n\n\t\twhile (buffer.length > 0) {\n\t\t\tconst invokeOpenTag = findInvokeOpenTag(buffer, 0);\n\t\t\tconst functionCallsOpenTag = findFunctionCallsTag(FUNCTION_CALLS_OPEN_TAG, buffer, 0);\n\n\t\t\tif (functionCallsOpenTag && (!invokeOpenTag || functionCallsOpenTag.index <= invokeOpenTag.index)) {\n\t\t\t\tif (functionCallsOpenTag.index > 0) {\n\t\t\t\t\temitText(events, buffer.slice(0, functionCallsOpenTag.index));\n\t\t\t\t\tbuffer = buffer.slice(functionCallsOpenTag.index);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst functionCallsCloseTag = findFunctionCallsTag(\n\t\t\t\t\tFUNCTION_CALLS_CLOSE_TAG,\n\t\t\t\t\tbuffer,\n\t\t\t\t\tfunctionCallsOpenTag.length,\n\t\t\t\t);\n\t\t\t\tif (!functionCallsCloseTag) {\n\t\t\t\t\tretainPendingFragment(\"function-calls\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst wrapperEnd = functionCallsCloseTag.index + functionCallsCloseTag.length;\n\t\t\t\tconst wrapperContent = buffer.slice(functionCallsOpenTag.length, functionCallsCloseTag.index);\n\t\t\t\tif (parseAnthropicXmlGeneratedText(wrapperContent, tools).length > 0) {\n\t\t\t\t\tbuffer = wrapperContent + buffer.slice(wrapperEnd);\n\t\t\t\t} else {\n\t\t\t\t\temitText(events, buffer.slice(0, wrapperEnd));\n\t\t\t\t\tbuffer = buffer.slice(wrapperEnd);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (invokeOpenTag) {\n\t\t\t\tif (invokeOpenTag.index > 0) {\n\t\t\t\t\temitText(events, buffer.slice(0, invokeOpenTag.index));\n\t\t\t\t\tbuffer = buffer.slice(invokeOpenTag.index);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst tool = resolveTool(invokeOpenTag.toolName);\n\t\t\t\tconst block = scanInvokeBlock(buffer, invokeOpenTag);\n\t\t\t\tif (!tool) {\n\t\t\t\t\tconst nextKnownInvoke = findNextInvokeMatch(\n\t\t\t\t\t\tbuffer,\n\t\t\t\t\t\tinvokeOpenTag.index + invokeOpenTag.length,\n\t\t\t\t\t\t(toolName) => resolveTool(toolName) !== undefined,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tnextKnownInvoke &&\n\t\t\t\t\t\t(block === null || (nextKnownInvoke.block !== null && nextKnownInvoke.block.end === block.end))\n\t\t\t\t\t) {\n\t\t\t\t\t\temitText(events, buffer.slice(0, nextKnownInvoke.openingTag.index));\n\t\t\t\t\t\tbuffer = buffer.slice(nextKnownInvoke.openingTag.index);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!block) {\n\t\t\t\t\tretainPendingFragment(\"invoke\");\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst originalCallText = buffer.slice(0, block.end);\n\t\t\t\tbuffer = buffer.slice(block.end);\n\n\t\t\t\tif (!tool) {\n\t\t\t\t\temitText(events, originalCallText);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst index = nextToolCallIndex;\n\t\t\t\tnextToolCallIndex += 1;\n\t\t\t\tconst id = `anthropic-xml-tool-${index}`;\n\t\t\t\tconst argumentsRecord = block.parameters ? coerceParameters(block.parameters, tool) : null;\n\t\t\t\tif (argumentsRecord === null) {\n\t\t\t\t\treportError(\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\"Could not process streaming Anthropic XML tool call, keeping original text.\",\n\t\t\t\t\t\toriginalCallText,\n\t\t\t\t\t);\n\t\t\t\t\tif (shouldEmitRawToolCallTextOnError(options)) {\n\t\t\t\t\t\temitText(events, originalCallText);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tevents.push({ type: \"toolcall_start\", index, name: tool.name, id });\n\t\t\t\tevents.push({\n\t\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\t\tindex,\n\t\t\t\t\targumentsDelta: JSON.stringify(argumentsRecord),\n\t\t\t\t});\n\t\t\t\tevents.push({ type: \"toolcall_end\", index, name: tool.name, id, arguments: argumentsRecord });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst safeLength = getSafeStreamTextLength(buffer);\n\t\t\tif (safeLength === 0) {\n\t\t\t\tif (buffer.length >= EAGER_OPEN_TAG_SCAN_LENGTH) {\n\t\t\t\t\tretainPendingFragment(\"open-tag\");\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\temitText(events, buffer.slice(0, safeLength));\n\t\t\tbuffer = buffer.slice(safeLength);\n\t\t}\n\n\t\treturn events;\n\t}\n\n\treturn {\n\t\tfeed(textDelta: string): StreamParserEvent[] {\n\t\t\tif (textDelta.length === 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tconst events: StreamParserEvent[] = [];\n\t\t\tlet offset = 0;\n\t\t\twhile (offset < textDelta.length) {\n\t\t\t\tconst capacity = ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH - buffer.length;\n\t\t\t\tif (capacity === 0) {\n\t\t\t\t\tevents.push(...overflowPendingFragment());\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst nextOffset = Math.min(textDelta.length, offset + capacity);\n\t\t\t\tconst chunk = textDelta.slice(offset, nextOffset);\n\t\t\t\toffset = nextOffset;\n\t\t\t\tbuffer += chunk;\n\n\t\t\t\tif (pendingFragment) {\n\t\t\t\t\tif (pendingFragment.matcher.feed(chunk)) {\n\t\t\t\t\t\tevents.push(...processBuffer());\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tevents.push(...processBuffer());\n\t\t\t\t}\n\n\t\t\t\tif (pendingFragment && buffer.length === ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH) {\n\t\t\t\t\tevents.push(...overflowPendingFragment());\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn events;\n\t\t},\n\t\tfinish(): StreamParserEvent[] {\n\t\t\tconst events = processBuffer();\n\t\t\tif (buffer.length === 0) {\n\t\t\t\treturn events;\n\t\t\t}\n\n\t\t\tconst invokeOpenTag = findInvokeOpenTag(buffer, 0) ?? findIncompleteInvokeOpenTag(buffer, 0);\n\t\t\tif (invokeOpenTag && invokeOpenTag.index === 0 && resolveTool(invokeOpenTag.toolName)) {\n\t\t\t\treportError(options, \"Could not complete streaming Anthropic XML tool call at finish.\", buffer);\n\t\t\t\tif (shouldEmitRawToolCallTextOnError(options)) {\n\t\t\t\t\temitText(events, buffer);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\temitText(events, buffer);\n\t\t\t}\n\t\t\tbuffer = \"\";\n\t\t\treturn events;\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { Tool } from "../../../types.ts";
2
+ export type ToolResolver = (toolName: string) => Tool | undefined;
3
+ export declare function createToolResolver(tools: readonly Tool[]): ToolResolver;
4
+ //# sourceMappingURL=tool-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-resolver.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/tool-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GAAG,SAAS,CAAC;AAElE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,YAAY,CAiBvE"}
@@ -0,0 +1,17 @@
1
+ export function createToolResolver(tools) {
2
+ const exactToolMap = new Map(tools.map((tool) => [tool.name, tool]));
3
+ const insensitiveToolMap = new Map();
4
+ for (const tool of tools) {
5
+ const normalizedName = tool.name.toLowerCase();
6
+ const existing = insensitiveToolMap.get(normalizedName);
7
+ insensitiveToolMap.set(normalizedName, existing === undefined ? tool : existing === tool ? tool : null);
8
+ }
9
+ return (toolName) => {
10
+ const exactTool = exactToolMap.get(toolName);
11
+ if (exactTool) {
12
+ return exactTool;
13
+ }
14
+ return insensitiveToolMap.get(toolName.toLowerCase()) ?? undefined;
15
+ };
16
+ }
17
+ //# sourceMappingURL=tool-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-resolver.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/tool-resolver.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kBAAkB,CAAC,KAAsB;IACxD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACrE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC1D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAG,kBAAkB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACxD,kBAAkB,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACzG,CAAC;IAED,OAAO,CAAC,QAAgB,EAAoB,EAAE;QAC7C,MAAM,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,SAAS,EAAE,CAAC;YACf,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,SAAS,CAAC;IACpE,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\n\nexport type ToolResolver = (toolName: string) => Tool | undefined;\n\nexport function createToolResolver(tools: readonly Tool[]): ToolResolver {\n\tconst exactToolMap = new Map(tools.map((tool) => [tool.name, tool]));\n\tconst insensitiveToolMap = new Map<string, Tool | null>();\n\tfor (const tool of tools) {\n\t\tconst normalizedName = tool.name.toLowerCase();\n\t\tconst existing = insensitiveToolMap.get(normalizedName);\n\t\tinsensitiveToolMap.set(normalizedName, existing === undefined ? tool : existing === tool ? tool : null);\n\t}\n\n\treturn (toolName: string): Tool | undefined => {\n\t\tconst exactTool = exactToolMap.get(toolName);\n\t\tif (exactTool) {\n\t\t\treturn exactTool;\n\t\t}\n\n\t\treturn insensitiveToolMap.get(toolName.toLowerCase()) ?? undefined;\n\t};\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export declare function encodeXmlText(value: string): string;
2
+ export declare function encodeXmlParameterText(value: string): string;
3
+ export declare function encodeXmlAttribute(value: string): string;
4
+ export declare function decodeXmlEntities(value: string): string;
5
+ //# sourceMappingURL=xml-entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-entities.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/xml-entities.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAMD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB5D;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASvD"}
@@ -0,0 +1,34 @@
1
+ export function encodeXmlText(value) {
2
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
3
+ }
4
+ function encodeXmlLineBreaks(value) {
5
+ return value.replaceAll("\r", "&#13;").replaceAll("\n", "&#10;");
6
+ }
7
+ export function encodeXmlParameterText(value) {
8
+ const encoded = encodeXmlText(value);
9
+ let contentStart = 0;
10
+ while (encoded[contentStart] === "\r" || encoded[contentStart] === "\n") {
11
+ contentStart += 1;
12
+ }
13
+ let contentEnd = encoded.length;
14
+ while (contentEnd > contentStart && (encoded[contentEnd - 1] === "\r" || encoded[contentEnd - 1] === "\n")) {
15
+ contentEnd -= 1;
16
+ }
17
+ return (encodeXmlLineBreaks(encoded.slice(0, contentStart)) +
18
+ encoded.slice(contentStart, contentEnd) +
19
+ encodeXmlLineBreaks(encoded.slice(contentEnd)));
20
+ }
21
+ export function encodeXmlAttribute(value) {
22
+ return encodeXmlText(value).replaceAll('"', "&quot;").replaceAll("'", "&apos;");
23
+ }
24
+ export function decodeXmlEntities(value) {
25
+ return value
26
+ .replaceAll("&#13;", "\r")
27
+ .replaceAll("&#10;", "\n")
28
+ .replaceAll("&quot;", '"')
29
+ .replaceAll("&apos;", "'")
30
+ .replaceAll("&lt;", "<")
31
+ .replaceAll("&gt;", ">")
32
+ .replaceAll("&amp;", "&");
33
+ }
34
+ //# sourceMappingURL=xml-entities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-entities.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/xml-entities.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,aAAa,CAAC,KAAa;IAC1C,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACvF,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACzC,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAa;IACnD,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CA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Text(value: string): string {\n\treturn value.replaceAll(\"&\", \"&amp;\").replaceAll(\"<\", \"&lt;\").replaceAll(\">\", \"&gt;\");\n}\n\nfunction encodeXmlLineBreaks(value: string): string {\n\treturn value.replaceAll(\"\\r\", \"&#13;\").replaceAll(\"\\n\", \"&#10;\");\n}\n\nexport function encodeXmlParameterText(value: string): string {\n\tconst encoded = encodeXmlText(value);\n\tlet contentStart = 0;\n\twhile (encoded[contentStart] === \"\\r\" || encoded[contentStart] === \"\\n\") {\n\t\tcontentStart += 1;\n\t}\n\n\tlet contentEnd = encoded.length;\n\twhile (contentEnd > contentStart && (encoded[contentEnd - 1] === \"\\r\" || encoded[contentEnd - 1] === \"\\n\")) {\n\t\tcontentEnd -= 1;\n\t}\n\n\treturn (\n\t\tencodeXmlLineBreaks(encoded.slice(0, contentStart)) +\n\t\tencoded.slice(contentStart, contentEnd) +\n\t\tencodeXmlLineBreaks(encoded.slice(contentEnd))\n\t);\n}\n\nexport function encodeXmlAttribute(value: string): string {\n\treturn encodeXmlText(value).replaceAll('\"', \"&quot;\").replaceAll(\"'\", \"&apos;\");\n}\n\nexport function decodeXmlEntities(value: string): string {\n\treturn value\n\t\t.replaceAll(\"&#13;\", \"\\r\")\n\t\t.replaceAll(\"&#10;\", \"\\n\")\n\t\t.replaceAll(\"&quot;\", '\"')\n\t\t.replaceAll(\"&apos;\", \"'\")\n\t\t.replaceAll(\"&lt;\", \"<\")\n\t\t.replaceAll(\"&gt;\", \">\")\n\t\t.replaceAll(\"&amp;\", \"&\");\n}\n"]}
@@ -3,9 +3,11 @@ import type { ImageContent, TextContent, Tool } from "../types.ts";
3
3
  * Supported tool call formats for models that don't natively support tool calling.
4
4
  * - "hermes": Hermes 2/3 format with special delimiters
5
5
  * - "xml": XML-based tool call format
6
+ * - "yaml-xml": YAML arguments inside XML tool tags
6
7
  * - "gemma4-delimiter": Gemma 4 specific delimiter format
8
+ * - "anthropic-xml": Legacy Anthropic invoke/parameter XML format
7
9
  */
8
- export type ToolCallFormat = "hermes" | "xml" | "yaml-xml" | "gemma4-delimiter";
10
+ export type ToolCallFormat = "hermes" | "xml" | "yaml-xml" | "gemma4-delimiter" | "anthropic-xml";
9
11
  /**
10
12
  * Content type for tool results (text or image)
11
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,kBAAkB,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC7B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACxE;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GACjE;IACA,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM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H,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAE/F;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IAEpE;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,EAAE,CAAC;IAE3F;;;;OAIG;IACH,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC;CACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImageContent, TextContent, Tool } from \"../types.ts\";\n\n/**\n * Supported tool call formats for models that don't natively support tool calling.\n * - \"hermes\": Hermes 2/3 format with special delimiters\n * - \"xml\": XML-based tool call format\n * - \"gemma4-delimiter\": Gemma 4 specific delimiter format\n */\nexport type ToolCallFormat = \"hermes\" | \"xml\" | \"yaml-xml\" | \"gemma4-delimiter\";\n\n/**\n * Content type for tool results (text or image)\n */\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface ParserOptions {\n\temitRawToolCallTextOnError?: boolean;\n\tonError?: (message: string, metadata?: Record<string, unknown>) => void;\n}\n\n/**\n * A parsed tool call extracted from generated text\n */\nexport interface ParsedToolCall {\n\tname: string;\n\targuments: Record<string, unknown>;\n}\n\n/**\n * Events emitted by the stream parser during text processing.\n * Maps 1:1 to AssistantMessageEventStream events for seamless integration.\n */\nexport type StreamParserEvent =\n\t| { type: \"text\"; text: string }\n\t| { type: \"toolcall_start\"; index: number; name: string; id: string }\n\t| { type: \"toolcall_delta\"; index: number; argumentsDelta: string }\n\t| {\n\t\t\ttype: \"toolcall_end\";\n\t\t\tindex: number;\n\t\t\tname: string;\n\t\t\tid: string;\n\t\t\targuments: Record<string, unknown>;\n\t };\n\n/**\n * Stream parser for incremental tool call parsing during streaming.\n */\nexport interface StreamParser {\n\t/**\n\t * Feed a text delta into the parser and receive any events generated.\n\t * @param textDelta - The next chunk of text to parse\n\t * @returns Array of parser events (text or tool call events)\n\t */\n\tfeed(textDelta: string): StreamParserEvent[];\n\n\t/**\n\t * Signal that the stream has ended and receive any final events.\n\t * @returns Array of final parser events\n\t */\n\tfinish(): StreamParserEvent[];\n}\n\n/**\n * Protocol interface for formatting and parsing tool calls in different formats.\n * Implementations handle the specifics of each tool call format (Hermes, XML, etc.)\n */\nexport interface ToolCallProtocol {\n\t/**\n\t * Format tools into a system prompt that instructs the model how to use tools.\n\t * @param tools - Array of available tools\n\t * @returns Formatted system prompt string\n\t */\n\tformatToolsSystemPrompt(tools: Tool[]): string;\n\n\t/**\n\t * Format a tool response for inclusion in the conversation context.\n\t * @param toolName - Name of the tool that was called\n\t * @param toolCallId - Unique identifier for this tool call\n\t * @param content - Array of content blocks (text or images) representing the result\n\t * @returns Formatted tool response string\n\t */\n\tformatToolResponse(toolName: string, toolCallId: string, content: ToolResultContent[]): string;\n\n\t/**\n\t * Format a tool call for sending to the model.\n\t * @param name - Name of the tool to call\n\t * @param args - Arguments for the tool call\n\t * @returns Formatted tool call string\n\t */\n\tformatToolCall(name: string, args: Record<string, unknown>): string;\n\n\t/**\n\t * Parse generated text to extract tool calls.\n\t * @param text - The generated text to parse\n\t * @param tools - Available tools for validation\n\t * @returns Array of parsed tool calls\n\t */\n\tparseGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];\n\n\t/**\n\t * Create a stream parser for incremental parsing during streaming.\n\t * @param tools - Available tools for the parser to recognize\n\t * @returns A new StreamParser instance\n\t */\n\tcreateStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImageContent, TextContent, Tool } from \"../types.ts\";\n\n/**\n * Supported tool call formats for models that don't natively support tool calling.\n * - \"hermes\": Hermes 2/3 format with special delimiters\n * - \"xml\": XML-based tool call format\n * - \"yaml-xml\": YAML arguments inside XML tool tags\n * - \"gemma4-delimiter\": Gemma 4 specific delimiter format\n * - \"anthropic-xml\": Legacy Anthropic invoke/parameter XML format\n */\nexport type ToolCallFormat = \"hermes\" | \"xml\" | \"yaml-xml\" | \"gemma4-delimiter\" | \"anthropic-xml\";\n\n/**\n * Content type for tool results (text or image)\n */\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface ParserOptions {\n\temitRawToolCallTextOnError?: boolean;\n\tonError?: (message: string, metadata?: Record<string, unknown>) => void;\n}\n\n/**\n * A parsed tool call extracted from generated text\n */\nexport interface ParsedToolCall {\n\tname: string;\n\targuments: Record<string, unknown>;\n}\n\n/**\n * Events emitted by the stream parser during text processing.\n * Maps 1:1 to AssistantMessageEventStream events for seamless integration.\n */\nexport type StreamParserEvent =\n\t| { type: \"text\"; text: string }\n\t| { type: \"toolcall_start\"; index: number; name: string; id: string }\n\t| { type: \"toolcall_delta\"; index: number; argumentsDelta: string }\n\t| {\n\t\t\ttype: \"toolcall_end\";\n\t\t\tindex: number;\n\t\t\tname: string;\n\t\t\tid: string;\n\t\t\targuments: Record<string, unknown>;\n\t };\n\n/**\n * Stream parser for incremental tool call parsing during streaming.\n */\nexport interface StreamParser {\n\t/**\n\t * Feed a text delta into the parser and receive any events generated.\n\t * @param textDelta - The next chunk of text to parse\n\t * @returns Array of parser events (text or tool call events)\n\t */\n\tfeed(textDelta: string): StreamParserEvent[];\n\n\t/**\n\t * Signal that the stream has ended and receive any final events.\n\t * @returns Array of final parser events\n\t */\n\tfinish(): StreamParserEvent[];\n}\n\n/**\n * Protocol interface for formatting and parsing tool calls in different formats.\n * Implementations handle the specifics of each tool call format (Hermes, XML, etc.)\n */\nexport interface ToolCallProtocol {\n\t/**\n\t * Format tools into a system prompt that instructs the model how to use tools.\n\t * @param tools - Array of available tools\n\t * @returns Formatted system prompt string\n\t */\n\tformatToolsSystemPrompt(tools: Tool[]): string;\n\n\t/**\n\t * Format a tool response for inclusion in the conversation context.\n\t * @param toolName - Name of the tool that was called\n\t * @param toolCallId - Unique identifier for this tool call\n\t * @param content - Array of content blocks (text or images) representing the result\n\t * @returns Formatted tool response string\n\t */\n\tformatToolResponse(toolName: string, toolCallId: string, content: ToolResultContent[]): string;\n\n\t/**\n\t * Format a tool call for sending to the model.\n\t * @param name - Name of the tool to call\n\t * @param args - Arguments for the tool call\n\t * @returns Formatted tool call string\n\t */\n\tformatToolCall(name: string, args: Record<string, unknown>): string;\n\n\t/**\n\t * Parse generated text to extract tool calls.\n\t * @param text - The generated text to parse\n\t * @param tools - Available tools for validation\n\t * @returns Array of parsed tool calls\n\t */\n\tparseGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];\n\n\t/**\n\t * Create a stream parser for incremental parsing during streaming.\n\t * @param tools - Available tools for the parser to recognize\n\t * @returns A new StreamParser instance\n\t */\n\tcreateStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-ai",
3
3
  "private": true,
4
- "version": "2026.7.13",
4
+ "version": "2026.7.14-2",
5
5
  "description": "Unified LLM API with automatic model discovery and provider configuration",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-pty",
3
3
  "private": true,
4
- "version": "2026.7.13",
4
+ "version": "2026.7.14-2",
5
5
  "description": "Typed PTY session loader for Senpi persistent terminals",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-tui",
3
3
  "private": true,
4
- "version": "2026.7.13",
4
+ "version": "2026.7.14-2",
5
5
  "description": "Terminal User Interface library with differential rendering for efficient text-based applications",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi",
3
- "version": "2026.7.13",
3
+ "version": "2026.7.14-2",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {
@@ -43,11 +43,11 @@
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.91.1",
45
45
  "@aws-sdk/client-bedrock-runtime": "3.1048.0",
46
- "@code-yeongyu/senpi-codemode": "^2026.7.13",
47
- "@earendil-works/pi-agent-core": "^2026.7.13",
48
- "@earendil-works/pi-ai": "^2026.7.13",
49
- "@earendil-works/pi-pty": "^2026.7.13",
50
- "@earendil-works/pi-tui": "^2026.7.13",
46
+ "@code-yeongyu/senpi-codemode": "^2026.7.14-2",
47
+ "@earendil-works/pi-agent-core": "^2026.7.14-2",
48
+ "@earendil-works/pi-ai": "^2026.7.14-2",
49
+ "@earendil-works/pi-pty": "^2026.7.14-2",
50
+ "@earendil-works/pi-tui": "^2026.7.14-2",
51
51
  "@mistralai/mistralai": "2.2.6",
52
52
  "@modelcontextprotocol/sdk": "1.29.0",
53
53
  "@mozilla/readability": "0.6.0",