@animalabs/membrane 0.5.46 → 0.5.50

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 (139) hide show
  1. package/dist/membrane.d.ts.map +1 -1
  2. package/dist/membrane.js +104 -11
  3. package/dist/membrane.js.map +1 -1
  4. package/dist/providers/anthropic.d.ts.map +1 -1
  5. package/dist/providers/anthropic.js +11 -1
  6. package/dist/providers/anthropic.js.map +1 -1
  7. package/dist/providers/bedrock.d.ts.map +1 -1
  8. package/dist/providers/bedrock.js +23 -4
  9. package/dist/providers/bedrock.js.map +1 -1
  10. package/dist/types/yielding-stream.d.ts +10 -1
  11. package/dist/types/yielding-stream.d.ts.map +1 -1
  12. package/dist/types/yielding-stream.js.map +1 -1
  13. package/package.json +5 -1
  14. package/src/membrane.ts +127 -13
  15. package/src/providers/anthropic.ts +12 -0
  16. package/src/providers/bedrock.ts +21 -4
  17. package/src/types/yielding-stream.ts +10 -1
  18. package/dist/context/index.d.ts +0 -12
  19. package/dist/context/index.js +0 -11
  20. package/dist/context/index.js.map +0 -1
  21. package/dist/context/process.d.ts +0 -43
  22. package/dist/context/process.js +0 -381
  23. package/dist/context/process.js.map +0 -1
  24. package/dist/context/types.d.ts +0 -164
  25. package/dist/context/types.js +0 -61
  26. package/dist/context/types.js.map +0 -1
  27. package/dist/formatters/anthropic-xml.d.ts +0 -63
  28. package/dist/formatters/anthropic-xml.js +0 -417
  29. package/dist/formatters/anthropic-xml.js.map +0 -1
  30. package/dist/formatters/completions.d.ts +0 -68
  31. package/dist/formatters/completions.js +0 -261
  32. package/dist/formatters/completions.js.map +0 -1
  33. package/dist/formatters/index.d.ts +0 -8
  34. package/dist/formatters/index.js +0 -7
  35. package/dist/formatters/index.js.map +0 -1
  36. package/dist/formatters/native.d.ts +0 -35
  37. package/dist/formatters/native.js +0 -336
  38. package/dist/formatters/native.js.map +0 -1
  39. package/dist/formatters/types.d.ts +0 -167
  40. package/dist/formatters/types.js +0 -7
  41. package/dist/formatters/types.js.map +0 -1
  42. package/dist/index.d.ts +0 -13
  43. package/dist/index.js +0 -20
  44. package/dist/index.js.map +0 -1
  45. package/dist/membrane.d.ts +0 -146
  46. package/dist/providers/anthropic.d.ts +0 -36
  47. package/dist/providers/bedrock.d.ts +0 -43
  48. package/dist/providers/gemini.d.ts +0 -68
  49. package/dist/providers/gemini.js +0 -538
  50. package/dist/providers/gemini.js.map +0 -1
  51. package/dist/providers/index.d.ts +0 -13
  52. package/dist/providers/index.js +0 -13
  53. package/dist/providers/index.js.map +0 -1
  54. package/dist/providers/mock.d.ts +0 -90
  55. package/dist/providers/mock.d.ts.map +0 -1
  56. package/dist/providers/mock.js +0 -210
  57. package/dist/providers/mock.js.map +0 -1
  58. package/dist/providers/openai-compatible.d.ts +0 -82
  59. package/dist/providers/openai-compatible.js +0 -480
  60. package/dist/providers/openai-compatible.js.map +0 -1
  61. package/dist/providers/openai-completions.d.ts +0 -89
  62. package/dist/providers/openai-completions.js +0 -347
  63. package/dist/providers/openai-completions.js.map +0 -1
  64. package/dist/providers/openai-responses.d.ts +0 -77
  65. package/dist/providers/openai-responses.js +0 -333
  66. package/dist/providers/openai-responses.js.map +0 -1
  67. package/dist/providers/openai.d.ts +0 -77
  68. package/dist/providers/openai.js +0 -533
  69. package/dist/providers/openai.js.map +0 -1
  70. package/dist/providers/openrouter.d.ts +0 -82
  71. package/dist/providers/openrouter.js +0 -556
  72. package/dist/providers/openrouter.js.map +0 -1
  73. package/dist/providers/utils.d.ts +0 -44
  74. package/dist/providers/utils.d.ts.map +0 -1
  75. package/dist/providers/utils.js +0 -100
  76. package/dist/providers/utils.js.map +0 -1
  77. package/dist/registry/default-pricing.d.ts +0 -3
  78. package/dist/registry/default-pricing.d.ts.map +0 -1
  79. package/dist/registry/default-pricing.js +0 -75
  80. package/dist/registry/default-pricing.js.map +0 -1
  81. package/dist/transforms/chat.d.ts +0 -52
  82. package/dist/transforms/chat.js +0 -136
  83. package/dist/transforms/chat.js.map +0 -1
  84. package/dist/transforms/index.d.ts +0 -5
  85. package/dist/transforms/index.js +0 -7
  86. package/dist/transforms/index.js.map +0 -1
  87. package/dist/types/config.d.ts +0 -110
  88. package/dist/types/config.js +0 -21
  89. package/dist/types/config.js.map +0 -1
  90. package/dist/types/content.d.ts +0 -87
  91. package/dist/types/content.d.ts.map +0 -1
  92. package/dist/types/content.js +0 -40
  93. package/dist/types/content.js.map +0 -1
  94. package/dist/types/errors.d.ts +0 -50
  95. package/dist/types/errors.d.ts.map +0 -1
  96. package/dist/types/errors.js +0 -253
  97. package/dist/types/errors.js.map +0 -1
  98. package/dist/types/index.d.ts +0 -20
  99. package/dist/types/index.js +0 -10
  100. package/dist/types/index.js.map +0 -1
  101. package/dist/types/message.d.ts +0 -52
  102. package/dist/types/message.d.ts.map +0 -1
  103. package/dist/types/message.js +0 -38
  104. package/dist/types/message.js.map +0 -1
  105. package/dist/types/provider.d.ts +0 -169
  106. package/dist/types/provider.d.ts.map +0 -1
  107. package/dist/types/provider.js +0 -5
  108. package/dist/types/provider.js.map +0 -1
  109. package/dist/types/request.d.ts +0 -116
  110. package/dist/types/request.d.ts.map +0 -1
  111. package/dist/types/request.js +0 -5
  112. package/dist/types/request.js.map +0 -1
  113. package/dist/types/response.d.ts +0 -131
  114. package/dist/types/response.d.ts.map +0 -1
  115. package/dist/types/response.js +0 -7
  116. package/dist/types/response.js.map +0 -1
  117. package/dist/types/streaming.d.ts +0 -194
  118. package/dist/types/streaming.js +0 -5
  119. package/dist/types/streaming.js.map +0 -1
  120. package/dist/types/tools.d.ts +0 -71
  121. package/dist/types/tools.d.ts.map +0 -1
  122. package/dist/types/tools.js +0 -5
  123. package/dist/types/tools.js.map +0 -1
  124. package/dist/utils/cost.d.ts +0 -10
  125. package/dist/utils/cost.d.ts.map +0 -1
  126. package/dist/utils/cost.js +0 -19
  127. package/dist/utils/cost.js.map +0 -1
  128. package/dist/utils/index.d.ts +0 -7
  129. package/dist/utils/index.js +0 -6
  130. package/dist/utils/index.js.map +0 -1
  131. package/dist/utils/stream-parser.d.ts +0 -84
  132. package/dist/utils/stream-parser.js +0 -418
  133. package/dist/utils/stream-parser.js.map +0 -1
  134. package/dist/utils/tool-parser.d.ts +0 -134
  135. package/dist/utils/tool-parser.js +0 -600
  136. package/dist/utils/tool-parser.js.map +0 -1
  137. package/dist/yielding-stream.d.ts +0 -60
  138. package/dist/yielding-stream.js +0 -206
  139. package/dist/yielding-stream.js.map +0 -1
@@ -1,63 +0,0 @@
1
- /**
2
- * Anthropic XML Formatter
3
- *
4
- * Prefill-based formatting for Anthropic models using XML tool syntax.
5
- * This is the "classic" membrane format with:
6
- * - Participant: content format
7
- * - <function_calls>/<function_results> for tools
8
- * - <thinking> blocks for extended thinking
9
- */
10
- import type { NormalizedMessage, ContentBlock, ToolCall, ToolResult } from '../types/index.js';
11
- import type { PrefillFormatter, StreamParser, BuildOptions, BuildResult, FormatterConfig } from './types.js';
12
- export interface AnthropicXmlFormatterConfig extends FormatterConfig {
13
- /**
14
- * How to handle tool definitions:
15
- * - 'xml': Inject into conversation as XML (prefill mode)
16
- * - 'native': Pass to API as native tools
17
- * Default: 'xml'
18
- */
19
- toolMode?: 'xml' | 'native';
20
- /**
21
- * Where to inject tool definitions when toolMode is 'xml':
22
- * - 'conversation': Inject into assistant content N messages from end
23
- * - 'system': Inject into system prompt
24
- * Default: 'conversation'
25
- */
26
- toolInjectionMode?: 'conversation' | 'system';
27
- /**
28
- * Position to inject tools (from end of messages).
29
- * Default: 10
30
- */
31
- toolInjectionPosition?: number;
32
- /**
33
- * Message delimiter for base models (e.g., '</s>').
34
- * Default: '' (none)
35
- */
36
- messageDelimiter?: string;
37
- /**
38
- * Maximum participants to include in stop sequences.
39
- * Default: 10
40
- */
41
- maxParticipantsForStop?: number;
42
- }
43
- export declare class AnthropicXmlFormatter implements PrefillFormatter {
44
- readonly name = "anthropic-xml";
45
- readonly usesPrefill = true;
46
- private config;
47
- constructor(config?: AnthropicXmlFormatterConfig);
48
- buildMessages(messages: NormalizedMessage[], options: BuildOptions): BuildResult;
49
- formatToolResults(results: ToolResult[], options?: {
50
- thinking?: boolean;
51
- }): string;
52
- createStreamParser(): StreamParser;
53
- parseToolCalls(content: string): ToolCall[];
54
- hasToolUse(content: string): boolean;
55
- parseContentBlocks(content: string): ContentBlock[];
56
- private extractContent;
57
- private formatToolDefinitionsXml;
58
- private formatToolsForInjection;
59
- private injectToolsIntoSystem;
60
- private buildStopSequences;
61
- private convertToNativeTools;
62
- }
63
- //# sourceMappingURL=anthropic-xml.d.ts.map
@@ -1,417 +0,0 @@
1
- /**
2
- * Anthropic XML Formatter
3
- *
4
- * Prefill-based formatting for Anthropic models using XML tool syntax.
5
- * This is the "classic" membrane format with:
6
- * - Participant: content format
7
- * - <function_calls>/<function_results> for tools
8
- * - <thinking> blocks for extended thinking
9
- */
10
- import { parseToolCalls as parseToolCallsXml, formatToolResults as formatToolResultsXml, parseAccumulatedIntoBlocks, formatToolDefinitions, } from '../utils/tool-parser.js';
11
- import { IncrementalXmlParser } from '../utils/stream-parser.js';
12
- // ============================================================================
13
- // Anthropic XML Formatter
14
- // ============================================================================
15
- export class AnthropicXmlFormatter {
16
- name = 'anthropic-xml';
17
- usesPrefill = true;
18
- config;
19
- constructor(config = {}) {
20
- this.config = {
21
- toolMode: config.toolMode ?? 'xml',
22
- toolInjectionMode: config.toolInjectionMode ?? 'conversation',
23
- toolInjectionPosition: config.toolInjectionPosition ?? 10,
24
- messageDelimiter: config.messageDelimiter ?? '',
25
- maxParticipantsForStop: config.maxParticipantsForStop ?? 10,
26
- unsupportedMedia: config.unsupportedMedia ?? 'error',
27
- warnOnStrip: config.warnOnStrip ?? true,
28
- };
29
- }
30
- // ==========================================================================
31
- // REQUEST BUILDING
32
- // ==========================================================================
33
- buildMessages(messages, options) {
34
- const { assistantParticipant, tools, thinking, systemPrompt, promptCaching = false, cacheTtl, contextPrefix, prefillUserMessage, hasCacheMarker, } = options;
35
- // Build cache_control object (with optional TTL for extended caching)
36
- const cacheControl = { type: 'ephemeral' };
37
- if (cacheTtl) {
38
- cacheControl.ttl = cacheTtl;
39
- }
40
- const providerMessages = [];
41
- const joiner = this.config.messageDelimiter ? '' : '\n';
42
- // Track conversation state
43
- let currentConversation = [];
44
- let lastNonEmptyParticipant = null;
45
- // Track cache markers applied
46
- let cacheMarkersApplied = 0;
47
- // Calculate tool injection point
48
- const totalMessages = messages.length;
49
- const toolInjectionIndex = Math.max(0, totalMessages - this.config.toolInjectionPosition);
50
- let toolsInjected = false;
51
- const hasToolsForConversation = this.config.toolMode === 'xml' &&
52
- this.config.toolInjectionMode === 'conversation' &&
53
- tools &&
54
- tools.length > 0;
55
- const toolsText = hasToolsForConversation ? this.formatToolsForInjection(tools) : '';
56
- // Build system content
57
- let systemText = typeof systemPrompt === 'string' ? systemPrompt : '';
58
- if (Array.isArray(systemPrompt)) {
59
- systemText = systemPrompt
60
- .filter((b) => b.type === 'text')
61
- .map(b => b.text)
62
- .join('\n');
63
- }
64
- // Inject tools into system if configured
65
- if (this.config.toolMode === 'xml' && this.config.toolInjectionMode === 'system' && tools?.length) {
66
- const toolsXml = this.formatToolDefinitionsXml(tools);
67
- systemText = this.injectToolsIntoSystem(systemText, toolsXml);
68
- }
69
- // Build system content with optional cache control
70
- let systemContent;
71
- if (systemText) {
72
- const systemBlock = { type: 'text', text: systemText };
73
- if (promptCaching) {
74
- systemBlock.cache_control = cacheControl;
75
- cacheMarkersApplied++;
76
- }
77
- systemContent = [systemBlock];
78
- }
79
- // Add context prefix as first cached assistant message (for simulacrum seeding)
80
- if (contextPrefix) {
81
- const prefixBlock = { type: 'text', text: contextPrefix };
82
- if (promptCaching) {
83
- prefixBlock.cache_control = cacheControl;
84
- cacheMarkersApplied++;
85
- }
86
- providerMessages.push({
87
- role: 'assistant',
88
- content: [prefixBlock],
89
- });
90
- }
91
- // Process messages
92
- for (let i = 0; i < messages.length; i++) {
93
- const message = messages[i];
94
- if (!message)
95
- continue;
96
- const isLastMessage = i === messages.length - 1;
97
- const isAssistant = message.participant === assistantParticipant;
98
- // Extract content
99
- const { text, images, hasUnsupportedMedia } = this.extractContent(message.content, message.participant);
100
- const hasImages = images.length > 0;
101
- const isEmpty = !text.trim() && !hasImages;
102
- // Handle unsupported media
103
- if (hasUnsupportedMedia) {
104
- if (this.config.unsupportedMedia === 'error') {
105
- throw new Error(`AnthropicXmlFormatter does not support media in message from ${message.participant}. Configure unsupportedMedia: 'strip' to ignore.`);
106
- }
107
- else if (this.config.warnOnStrip) {
108
- console.warn(`[AnthropicXmlFormatter] Stripped unsupported media from message`);
109
- }
110
- }
111
- // Check for tool results
112
- const hasToolResult = message.content.some(c => c.type === 'tool_result');
113
- // If message has images, flush and add as user turn
114
- if (hasImages && !isEmpty) {
115
- if (currentConversation.length > 0) {
116
- providerMessages.push({
117
- role: 'assistant',
118
- content: currentConversation.join(joiner),
119
- });
120
- currentConversation = [];
121
- }
122
- const userContent = [];
123
- if (text) {
124
- userContent.push({ type: 'text', text: `${message.participant}: ${text}` });
125
- }
126
- userContent.push(...images);
127
- providerMessages.push({ role: 'user', content: userContent });
128
- lastNonEmptyParticipant = message.participant;
129
- continue;
130
- }
131
- // Skip empty messages except last
132
- if (isEmpty && !isLastMessage) {
133
- continue;
134
- }
135
- // Check hasCacheMarker callback - flush content BEFORE this message with cache_control
136
- // (backward compatibility: callback marks WHERE cache boundary should be)
137
- if (hasCacheMarker && hasCacheMarker(message, i)) {
138
- if (currentConversation.length > 0 && promptCaching) {
139
- const content = currentConversation.join(joiner);
140
- const contentBlock = { type: 'text', text: content };
141
- contentBlock.cache_control = cacheControl;
142
- cacheMarkersApplied++;
143
- providerMessages.push({
144
- role: 'assistant',
145
- content: [contentBlock],
146
- });
147
- currentConversation = [];
148
- }
149
- else if (currentConversation.length > 0) {
150
- providerMessages.push({
151
- role: 'assistant',
152
- content: currentConversation.join(joiner),
153
- });
154
- currentConversation = [];
155
- }
156
- }
157
- // Inject tools before this message if at injection point
158
- const shouldInjectHere = toolInjectionIndex > 0 ? i >= toolInjectionIndex : i === 0;
159
- if (hasToolsForConversation && !toolsInjected && shouldInjectHere) {
160
- currentConversation.push(toolsText);
161
- toolsInjected = true;
162
- }
163
- // Check bot continuation
164
- const isBotMessage = message.participant === assistantParticipant;
165
- const isContinuation = isBotMessage && lastNonEmptyParticipant === assistantParticipant && !hasToolResult;
166
- if (isContinuation && isLastMessage) {
167
- // Bot continuation - don't add prefix
168
- continue;
169
- }
170
- else if (isLastMessage && isEmpty) {
171
- // Completion target - prefix added below
172
- }
173
- else if (text) {
174
- currentConversation.push(`${message.participant}: ${text}${this.config.messageDelimiter}`);
175
- if (!hasToolResult) {
176
- lastNonEmptyParticipant = message.participant;
177
- }
178
- }
179
- // Check cacheBreakpoint - flush INCLUDING this message with cache_control
180
- // (explicit user control: this message is the last thing to be cached)
181
- if (message.cacheBreakpoint && promptCaching && currentConversation.length > 0) {
182
- const content = currentConversation.join(joiner);
183
- const contentBlock = { type: 'text', text: content };
184
- contentBlock.cache_control = cacheControl;
185
- cacheMarkersApplied++;
186
- providerMessages.push({
187
- role: 'assistant',
188
- content: [contentBlock],
189
- });
190
- currentConversation = [];
191
- }
192
- }
193
- // Determine turn prefix
194
- let turnPrefix;
195
- if (thinking?.enabled) {
196
- turnPrefix = `${assistantParticipant}: <thinking>`;
197
- }
198
- else {
199
- turnPrefix = `${assistantParticipant}:`;
200
- }
201
- // Flush remaining conversation
202
- if (hasToolsForConversation && !toolsInjected) {
203
- currentConversation.push(toolsText);
204
- }
205
- if (currentConversation.length > 0) {
206
- providerMessages.push({
207
- role: 'assistant',
208
- content: [...currentConversation, turnPrefix].join(joiner),
209
- });
210
- }
211
- else {
212
- providerMessages.push({
213
- role: 'assistant',
214
- content: turnPrefix,
215
- });
216
- }
217
- // Ensure first message is user role (required by Claude Messages API,
218
- // strictly enforced by Bedrock and older Claude models)
219
- if (providerMessages.length > 0 && providerMessages[0].role !== 'user') {
220
- if (prefillUserMessage) {
221
- // Explicit custom prefill user message from config
222
- providerMessages.unshift({
223
- role: 'user',
224
- content: prefillUserMessage,
225
- });
226
- }
227
- else if (!systemText) {
228
- // No system prompt and no custom prefill: default to CLI simulation mode
229
- // for context purity in prefill format (chapter2 parity)
230
- const cliSystemBlock = {
231
- type: 'text',
232
- text: 'The assistant is in CLI simulation mode, and responds to the user\'s CLI commands only with the output of the command.',
233
- };
234
- if (promptCaching) {
235
- cliSystemBlock.cache_control = cacheControl;
236
- cacheMarkersApplied++;
237
- }
238
- systemContent = [cliSystemBlock];
239
- providerMessages.unshift({
240
- role: 'user',
241
- content: '<cmd>cat untitled.txt</cmd>',
242
- });
243
- }
244
- else {
245
- // System prompt is set but no custom prefill — use generic marker
246
- providerMessages.unshift({
247
- role: 'user',
248
- content: '[Start]',
249
- });
250
- }
251
- }
252
- // Build stop sequences
253
- const stopSequences = this.buildStopSequences(messages, assistantParticipant, options);
254
- // Native tools if configured
255
- const nativeTools = this.config.toolMode === 'native' && tools?.length
256
- ? this.convertToNativeTools(tools)
257
- : undefined;
258
- return {
259
- messages: providerMessages,
260
- systemContent,
261
- assistantPrefill: typeof providerMessages[providerMessages.length - 1]?.content === 'string'
262
- ? providerMessages[providerMessages.length - 1].content
263
- : undefined,
264
- stopSequences,
265
- nativeTools,
266
- cacheMarkersApplied,
267
- };
268
- }
269
- formatToolResults(results, options) {
270
- let xml = formatToolResultsXml(results);
271
- if (options?.thinking) {
272
- xml += '\n<thinking>';
273
- }
274
- return xml;
275
- }
276
- // ==========================================================================
277
- // RESPONSE PARSING
278
- // ==========================================================================
279
- createStreamParser() {
280
- return new IncrementalXmlParser();
281
- }
282
- parseToolCalls(content) {
283
- const result = parseToolCallsXml(content);
284
- return result?.calls ?? [];
285
- }
286
- hasToolUse(content) {
287
- return /<(antml:)?function_calls>/.test(content);
288
- }
289
- parseContentBlocks(content) {
290
- const { blocks } = parseAccumulatedIntoBlocks(content);
291
- return blocks;
292
- }
293
- // ==========================================================================
294
- // PRIVATE HELPERS
295
- // ==========================================================================
296
- extractContent(content, participant) {
297
- const parts = [];
298
- const images = [];
299
- let hasUnsupportedMedia = false;
300
- for (const block of content) {
301
- if (block.type === 'text') {
302
- parts.push(block.text);
303
- }
304
- else if (block.type === 'image') {
305
- if (block.source.type === 'base64') {
306
- images.push({
307
- type: 'image',
308
- source: {
309
- type: 'base64',
310
- media_type: block.source.mediaType,
311
- data: block.source.data,
312
- },
313
- });
314
- }
315
- }
316
- else if (block.type === 'tool_use') {
317
- parts.push(`${participant}>[${block.name}]: ${JSON.stringify(block.input)}`);
318
- }
319
- else if (block.type === 'tool_result') {
320
- const resultText = typeof block.content === 'string'
321
- ? block.content
322
- : JSON.stringify(block.content);
323
- parts.push(`${participant}<[tool_result]: ${resultText}`);
324
- }
325
- else if (block.type === 'document' || block.type === 'audio') {
326
- hasUnsupportedMedia = true;
327
- }
328
- }
329
- return { text: parts.join('\n'), images, hasUnsupportedMedia };
330
- }
331
- formatToolDefinitionsXml(tools) {
332
- const toolsForPrompt = tools.map((tool) => ({
333
- name: tool.name,
334
- description: tool.description,
335
- parameters: tool.inputSchema.properties
336
- ? Object.fromEntries(Object.entries(tool.inputSchema.properties).map(([name, schema]) => [
337
- name,
338
- {
339
- type: schema.type,
340
- description: schema.description,
341
- required: tool.inputSchema.required?.includes(name),
342
- enum: schema.enum,
343
- },
344
- ]))
345
- : {},
346
- }));
347
- return formatToolDefinitions(toolsForPrompt);
348
- }
349
- formatToolsForInjection(tools) {
350
- const toolsXml = this.formatToolDefinitionsXml(tools);
351
- // Assemble tags to avoid triggering stop sequences
352
- const FUNC_CALLS_OPEN = '<' + 'function_calls>';
353
- const FUNC_CALLS_CLOSE = '</' + 'function_calls>';
354
- const INVOKE_OPEN = '<' + 'invoke name="';
355
- const INVOKE_CLOSE = '</' + 'invoke>';
356
- const PARAM_OPEN = '<' + 'parameter name="';
357
- const PARAM_CLOSE = '</' + 'parameter>';
358
- return `
359
- <available_tools>
360
- ${toolsXml}
361
- </available_tools>
362
-
363
- When you want to use a tool, output:
364
- ${FUNC_CALLS_OPEN}
365
- ${INVOKE_OPEN}tool_name">
366
- ${PARAM_OPEN}param_name">value${PARAM_CLOSE}
367
- ${INVOKE_CLOSE}
368
- ${FUNC_CALLS_CLOSE}`;
369
- }
370
- injectToolsIntoSystem(system, toolsXml) {
371
- const toolsSection = `
372
- <available_tools>
373
- ${toolsXml}
374
- </available_tools>
375
-
376
- When you want to use a tool, output:
377
- <function_calls>
378
- <invoke name="tool_name">
379
- <parameter name="param_name">value</parameter>
380
- </invoke>
381
- </function_calls>
382
- `;
383
- return system + '\n\n' + toolsSection;
384
- }
385
- buildStopSequences(messages, assistantName, options) {
386
- const sequences = [];
387
- // Use option's maxParticipantsForStop, falling back to config
388
- const maxParticipants = options.maxParticipantsForStop ?? this.config.maxParticipantsForStop;
389
- // Collect unique participants (excluding assistant)
390
- const participants = new Set();
391
- for (let i = messages.length - 1; i >= 0 && participants.size < maxParticipants; i--) {
392
- const message = messages[i];
393
- if (message && message.participant !== assistantName) {
394
- participants.add(message.participant);
395
- }
396
- }
397
- // Participant-based stops
398
- for (const participant of participants) {
399
- sequences.push(`\n${participant}:`);
400
- }
401
- // Tool-related stop
402
- sequences.push('</function_calls>');
403
- // Add any additional stop sequences from options
404
- if (options.additionalStopSequences?.length) {
405
- sequences.push(...options.additionalStopSequences);
406
- }
407
- return sequences;
408
- }
409
- convertToNativeTools(tools) {
410
- return tools.map(tool => ({
411
- name: tool.name,
412
- description: tool.description,
413
- input_schema: tool.inputSchema,
414
- }));
415
- }
416
- }
417
- //# sourceMappingURL=anthropic-xml.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anthropic-xml.js","sourceRoot":"","sources":["../../src/formatters/anthropic-xml.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiBH,OAAO,EACL,cAAc,IAAI,iBAAiB,EACnC,iBAAiB,IAAI,oBAAoB,EACzC,0BAA0B,EAC1B,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,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C;QAE7F,oDAAoD;QACpD,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,GAAG,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;YACrF,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,OAAO,IAAI,OAAO,CAAC,WAAW,KAAK,aAAa,EAAE,CAAC;gBACrD,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,0BAA0B;QAC1B,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,SAAS,CAAC,IAAI,CAAC,KAAK,WAAW,GAAG,CAAC,CAAC;QACtC,CAAC;QAED,oBAAoB;QACpB,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEpC,iDAAiD;QACjD,IAAI,OAAO,CAAC,uBAAuB,EAAE,MAAM,EAAE,CAAC;YAC5C,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,oBAAoB,CAAC,KAAuB;QAClD,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,YAAY,EAAE,IAAI,CAAC,WAAW;SAC/B,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
@@ -1,68 +0,0 @@
1
- /**
2
- * Completions Formatter
3
- *
4
- * Formatter for base/completion models that use single-prompt input.
5
- * Serializes conversations to "Participant: content<eot>" format.
6
- *
7
- * Key features:
8
- * - Converts multi-turn conversations to single prompt string
9
- * - Adds configurable end-of-turn tokens
10
- * - Generates stop sequences from participant names
11
- * - Strips images (not supported in completion models)
12
- * - No XML block parsing (passthrough mode)
13
- */
14
- import type { NormalizedMessage, ContentBlock, ToolCall, ToolResult } from '../types/index.js';
15
- import type { PrefillFormatter, StreamParser, BuildOptions, BuildResult, FormatterConfig } from './types.js';
16
- export interface CompletionsFormatterConfig extends FormatterConfig {
17
- /**
18
- * End-of-turn token to append after each message.
19
- * Set to empty string to disable.
20
- * Default: '<|eot|>'
21
- */
22
- eotToken?: string;
23
- /**
24
- * Format for participant name prefix.
25
- * Use {name} as placeholder.
26
- * Default: '{name}: '
27
- */
28
- nameFormat?: string;
29
- /**
30
- * Message separator between turns.
31
- * Default: '\n\n'
32
- */
33
- messageSeparator?: string;
34
- /**
35
- * Maximum participants to include in stop sequences.
36
- * Default: 10
37
- */
38
- maxParticipantsForStop?: number;
39
- /**
40
- * Add lowercased variants of participant stop sequences.
41
- * Useful for models whose tokenizer doesn't normalize casing,
42
- * allowing simmed names with different casing to still trigger stops.
43
- * Default: false
44
- */
45
- caseInsensitiveStops?: boolean;
46
- /**
47
- * Whether to warn when images are stripped.
48
- * Default: true
49
- */
50
- warnOnImageStrip?: boolean;
51
- }
52
- export declare class CompletionsFormatter implements PrefillFormatter {
53
- readonly name = "completions";
54
- readonly usesPrefill = true;
55
- private config;
56
- constructor(config?: CompletionsFormatterConfig);
57
- buildMessages(messages: NormalizedMessage[], options: BuildOptions): BuildResult;
58
- formatToolResults(results: ToolResult[], options?: {
59
- thinking?: boolean;
60
- }): string;
61
- createStreamParser(): StreamParser;
62
- parseToolCalls(content: string): ToolCall[];
63
- hasToolUse(content: string): boolean;
64
- parseContentBlocks(content: string): ContentBlock[];
65
- private extractTextContent;
66
- private buildStopSequences;
67
- }
68
- //# sourceMappingURL=completions.d.ts.map