@animalabs/membrane 0.5.51 → 0.5.53

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 (134) hide show
  1. package/dist/context/index.d.ts +12 -0
  2. package/dist/context/index.js +11 -0
  3. package/dist/context/index.js.map +1 -0
  4. package/dist/context/process.d.ts +43 -0
  5. package/dist/context/process.js +381 -0
  6. package/dist/context/process.js.map +1 -0
  7. package/dist/context/types.d.ts +164 -0
  8. package/dist/context/types.js +61 -0
  9. package/dist/context/types.js.map +1 -0
  10. package/dist/formatters/anthropic-xml.d.ts +63 -0
  11. package/dist/formatters/anthropic-xml.js +417 -0
  12. package/dist/formatters/anthropic-xml.js.map +1 -0
  13. package/dist/formatters/completions.d.ts +68 -0
  14. package/dist/formatters/completions.js +261 -0
  15. package/dist/formatters/completions.js.map +1 -0
  16. package/dist/formatters/index.d.ts +10 -0
  17. package/dist/formatters/index.d.ts.map +1 -1
  18. package/dist/formatters/index.js +8 -0
  19. package/dist/formatters/index.js.map +1 -0
  20. package/dist/formatters/native.d.ts +35 -0
  21. package/dist/formatters/native.d.ts.map +1 -1
  22. package/dist/formatters/native.js +346 -0
  23. package/dist/formatters/native.js.map +1 -0
  24. package/dist/formatters/normalize-tool-pairs.d.ts +75 -0
  25. package/dist/formatters/normalize-tool-pairs.d.ts.map +1 -0
  26. package/dist/formatters/normalize-tool-pairs.js +498 -0
  27. package/dist/formatters/normalize-tool-pairs.js.map +1 -0
  28. package/dist/formatters/types.d.ts +222 -0
  29. package/dist/formatters/types.d.ts.map +1 -1
  30. package/dist/formatters/types.js +7 -0
  31. package/dist/formatters/types.js.map +1 -0
  32. package/dist/index.d.ts +13 -0
  33. package/dist/index.js +20 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/membrane.d.ts +155 -0
  36. package/dist/providers/anthropic.d.ts +36 -0
  37. package/dist/providers/bedrock.d.ts +43 -0
  38. package/dist/providers/gemini.d.ts +68 -0
  39. package/dist/providers/gemini.js +538 -0
  40. package/dist/providers/gemini.js.map +1 -0
  41. package/dist/providers/index.d.ts +13 -0
  42. package/dist/providers/index.js +13 -0
  43. package/dist/providers/index.js.map +1 -0
  44. package/dist/providers/mock.d.ts +90 -0
  45. package/dist/providers/mock.d.ts.map +1 -0
  46. package/dist/providers/mock.js +210 -0
  47. package/dist/providers/mock.js.map +1 -0
  48. package/dist/providers/openai-compatible.d.ts +82 -0
  49. package/dist/providers/openai-compatible.js +480 -0
  50. package/dist/providers/openai-compatible.js.map +1 -0
  51. package/dist/providers/openai-completions.d.ts +89 -0
  52. package/dist/providers/openai-completions.js +347 -0
  53. package/dist/providers/openai-completions.js.map +1 -0
  54. package/dist/providers/openai-responses.d.ts +77 -0
  55. package/dist/providers/openai-responses.js +333 -0
  56. package/dist/providers/openai-responses.js.map +1 -0
  57. package/dist/providers/openai.d.ts +77 -0
  58. package/dist/providers/openai.js +533 -0
  59. package/dist/providers/openai.js.map +1 -0
  60. package/dist/providers/openrouter.d.ts +82 -0
  61. package/dist/providers/openrouter.js +556 -0
  62. package/dist/providers/openrouter.js.map +1 -0
  63. package/dist/providers/utils.d.ts +44 -0
  64. package/dist/providers/utils.d.ts.map +1 -0
  65. package/dist/providers/utils.js +100 -0
  66. package/dist/providers/utils.js.map +1 -0
  67. package/dist/registry/default-pricing.d.ts +3 -0
  68. package/dist/registry/default-pricing.d.ts.map +1 -0
  69. package/dist/registry/default-pricing.js +75 -0
  70. package/dist/registry/default-pricing.js.map +1 -0
  71. package/dist/transforms/chat.d.ts +52 -0
  72. package/dist/transforms/chat.js +136 -0
  73. package/dist/transforms/chat.js.map +1 -0
  74. package/dist/transforms/index.d.ts +5 -0
  75. package/dist/transforms/index.js +7 -0
  76. package/dist/transforms/index.js.map +1 -0
  77. package/dist/types/config.d.ts +110 -0
  78. package/dist/types/config.js +21 -0
  79. package/dist/types/config.js.map +1 -0
  80. package/dist/types/content.d.ts +87 -0
  81. package/dist/types/content.d.ts.map +1 -0
  82. package/dist/types/content.js +40 -0
  83. package/dist/types/content.js.map +1 -0
  84. package/dist/types/errors.d.ts +50 -0
  85. package/dist/types/errors.d.ts.map +1 -0
  86. package/dist/types/errors.js +253 -0
  87. package/dist/types/errors.js.map +1 -0
  88. package/dist/types/index.d.ts +20 -0
  89. package/dist/types/index.js +10 -0
  90. package/dist/types/index.js.map +1 -0
  91. package/dist/types/message.d.ts +52 -0
  92. package/dist/types/message.d.ts.map +1 -0
  93. package/dist/types/message.js +38 -0
  94. package/dist/types/message.js.map +1 -0
  95. package/dist/types/provider.d.ts +169 -0
  96. package/dist/types/provider.d.ts.map +1 -0
  97. package/dist/types/provider.js +5 -0
  98. package/dist/types/provider.js.map +1 -0
  99. package/dist/types/request.d.ts +116 -0
  100. package/dist/types/request.d.ts.map +1 -0
  101. package/dist/types/request.js +5 -0
  102. package/dist/types/request.js.map +1 -0
  103. package/dist/types/response.d.ts +131 -0
  104. package/dist/types/response.d.ts.map +1 -0
  105. package/dist/types/response.js +7 -0
  106. package/dist/types/response.js.map +1 -0
  107. package/dist/types/streaming.d.ts +194 -0
  108. package/dist/types/streaming.js +5 -0
  109. package/dist/types/streaming.js.map +1 -0
  110. package/dist/types/tools.d.ts +71 -0
  111. package/dist/types/tools.d.ts.map +1 -0
  112. package/dist/types/tools.js +5 -0
  113. package/dist/types/tools.js.map +1 -0
  114. package/dist/utils/cost.d.ts +10 -0
  115. package/dist/utils/cost.d.ts.map +1 -0
  116. package/dist/utils/cost.js +19 -0
  117. package/dist/utils/cost.js.map +1 -0
  118. package/dist/utils/index.d.ts +7 -0
  119. package/dist/utils/index.js +6 -0
  120. package/dist/utils/index.js.map +1 -0
  121. package/dist/utils/stream-parser.d.ts +84 -0
  122. package/dist/utils/stream-parser.js +418 -0
  123. package/dist/utils/stream-parser.js.map +1 -0
  124. package/dist/utils/tool-parser.d.ts +134 -0
  125. package/dist/utils/tool-parser.js +600 -0
  126. package/dist/utils/tool-parser.js.map +1 -0
  127. package/dist/yielding-stream.d.ts +60 -0
  128. package/dist/yielding-stream.js +206 -0
  129. package/dist/yielding-stream.js.map +1 -0
  130. package/package.json +1 -1
  131. package/src/formatters/index.ts +9 -0
  132. package/src/formatters/native.ts +12 -1
  133. package/src/formatters/normalize-tool-pairs.ts +622 -0
  134. package/src/formatters/types.ts +39 -0
@@ -0,0 +1,261 @@
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
+ // ============================================================================
15
+ // Passthrough Stream Parser (same as NativeFormatter)
16
+ // ============================================================================
17
+ /**
18
+ * Simple pass-through parser for base models.
19
+ * No XML tracking - just accumulates content.
20
+ */
21
+ class CompletionsStreamParser {
22
+ accumulated = '';
23
+ blockIndex = 0;
24
+ blockStarted = false;
25
+ processChunk(chunk) {
26
+ this.accumulated += chunk;
27
+ const meta = {
28
+ type: 'text',
29
+ visible: true,
30
+ blockIndex: this.blockIndex,
31
+ };
32
+ const emissions = [];
33
+ const blockEvents = [];
34
+ // Emit block_start on first chunk
35
+ if (!this.blockStarted) {
36
+ const startEvent = {
37
+ event: 'block_start',
38
+ index: this.blockIndex,
39
+ block: { type: 'text' },
40
+ };
41
+ emissions.push({ kind: 'blockEvent', event: startEvent });
42
+ blockEvents.push(startEvent);
43
+ this.blockStarted = true;
44
+ }
45
+ emissions.push({ kind: 'content', text: chunk, meta });
46
+ return { emissions, content: [{ text: chunk, meta }], blockEvents };
47
+ }
48
+ flush() {
49
+ const emissions = [];
50
+ const blockEvents = [];
51
+ if (this.blockStarted) {
52
+ const completeEvent = {
53
+ event: 'block_complete',
54
+ index: this.blockIndex,
55
+ block: { type: 'text', content: this.accumulated },
56
+ };
57
+ emissions.push({ kind: 'blockEvent', event: completeEvent });
58
+ blockEvents.push(completeEvent);
59
+ this.blockStarted = false;
60
+ }
61
+ return { emissions, content: [], blockEvents };
62
+ }
63
+ getAccumulated() {
64
+ return this.accumulated;
65
+ }
66
+ reset() {
67
+ this.accumulated = '';
68
+ this.blockIndex = 0;
69
+ this.blockStarted = false;
70
+ }
71
+ push(content) {
72
+ this.accumulated += content;
73
+ }
74
+ getCurrentBlockType() {
75
+ return 'text';
76
+ }
77
+ getBlockIndex() {
78
+ return this.blockIndex;
79
+ }
80
+ incrementBlockIndex() {
81
+ this.blockIndex++;
82
+ }
83
+ isInsideBlock() {
84
+ return false;
85
+ }
86
+ getDepths() {
87
+ return { functionCalls: 0, functionResults: 0, thinking: 0 };
88
+ }
89
+ resetForNewIteration() {
90
+ // No special reset needed
91
+ }
92
+ }
93
+ // ============================================================================
94
+ // Completions Formatter
95
+ // ============================================================================
96
+ export class CompletionsFormatter {
97
+ name = 'completions';
98
+ usesPrefill = true;
99
+ config;
100
+ constructor(config = {}) {
101
+ this.config = {
102
+ eotToken: config.eotToken ?? '<|eot|>',
103
+ nameFormat: config.nameFormat ?? '{name}: ',
104
+ messageSeparator: config.messageSeparator ?? '\n\n',
105
+ maxParticipantsForStop: config.maxParticipantsForStop ?? 10,
106
+ caseInsensitiveStops: config.caseInsensitiveStops ?? false,
107
+ warnOnImageStrip: config.warnOnImageStrip ?? true,
108
+ // Completions models don't support images - always strip
109
+ unsupportedMedia: 'strip',
110
+ warnOnStrip: config.warnOnStrip ?? true,
111
+ };
112
+ }
113
+ // ==========================================================================
114
+ // REQUEST BUILDING
115
+ // ==========================================================================
116
+ buildMessages(messages, options) {
117
+ const { assistantParticipant, systemPrompt, additionalStopSequences, maxParticipantsForStop = this.config.maxParticipantsForStop, contextPrefix, } = options;
118
+ const parts = [];
119
+ const participants = new Set();
120
+ let hasStrippedImages = false;
121
+ // Add system prompt as first part if present
122
+ if (systemPrompt) {
123
+ const systemText = typeof systemPrompt === 'string'
124
+ ? systemPrompt
125
+ : systemPrompt
126
+ .filter((b) => b.type === 'text')
127
+ .map(b => b.text)
128
+ .join('\n');
129
+ if (systemText) {
130
+ parts.push(systemText);
131
+ }
132
+ }
133
+ // Add context prefix after system prompt (for simulacrum seeding)
134
+ if (contextPrefix) {
135
+ const assistantPrefix = this.config.nameFormat.replace('{name}', assistantParticipant);
136
+ parts.push(`${assistantPrefix}${contextPrefix}${this.config.eotToken}`);
137
+ }
138
+ // Serialize each message
139
+ for (const message of messages) {
140
+ participants.add(message.participant);
141
+ const { text, hadImages } = this.extractTextContent(message.content);
142
+ if (hadImages) {
143
+ hasStrippedImages = true;
144
+ }
145
+ // Skip empty messages (except if it's the final completion target)
146
+ if (!text.trim()) {
147
+ continue;
148
+ }
149
+ // Format: "Participant: content<eot>"
150
+ const prefix = this.config.nameFormat.replace('{name}', message.participant);
151
+ const eot = this.config.eotToken;
152
+ parts.push(`${prefix}${text}${eot}`);
153
+ }
154
+ // Warn about stripped images
155
+ if (hasStrippedImages && this.config.warnOnImageStrip) {
156
+ console.warn('[CompletionsFormatter] Images were stripped from context (not supported in completions mode)');
157
+ }
158
+ // Add final assistant prefix (no EOT - model generates this)
159
+ const assistantPrefix = this.config.nameFormat.replace('{name}', assistantParticipant);
160
+ parts.push(assistantPrefix.trimEnd()); // Remove trailing space for cleaner completion
161
+ // Join all parts into single prompt
162
+ const prompt = parts.join(this.config.messageSeparator);
163
+ // Build stop sequences from participants
164
+ const stopSequences = this.buildStopSequences(participants, assistantParticipant, maxParticipantsForStop, additionalStopSequences);
165
+ // Return as single assistant message with prompt as content
166
+ // The provider adapter will extract this as the prompt
167
+ const providerMessages = [
168
+ { role: 'assistant', content: prompt },
169
+ ];
170
+ return {
171
+ messages: providerMessages,
172
+ assistantPrefill: prompt,
173
+ stopSequences,
174
+ };
175
+ }
176
+ formatToolResults(results, options) {
177
+ // Completions mode typically doesn't support tools
178
+ // But format them as simple text if needed
179
+ const parts = results.map(r => {
180
+ const content = typeof r.content === 'string' ? r.content : JSON.stringify(r.content);
181
+ return `[Tool Result: ${content}]`;
182
+ });
183
+ return parts.join('\n');
184
+ }
185
+ // ==========================================================================
186
+ // RESPONSE PARSING
187
+ // ==========================================================================
188
+ createStreamParser() {
189
+ return new CompletionsStreamParser();
190
+ }
191
+ parseToolCalls(content) {
192
+ // Base models don't have structured tool output
193
+ return [];
194
+ }
195
+ hasToolUse(content) {
196
+ // Base models determine completion via stop sequences
197
+ return false;
198
+ }
199
+ parseContentBlocks(content) {
200
+ // Trim leading whitespace (model often starts with space after prefix)
201
+ const trimmed = content.replace(/^\s+/, '');
202
+ if (!trimmed) {
203
+ return [];
204
+ }
205
+ return [{ type: 'text', text: trimmed }];
206
+ }
207
+ // ==========================================================================
208
+ // PRIVATE HELPERS
209
+ // ==========================================================================
210
+ extractTextContent(content) {
211
+ const textParts = [];
212
+ let hadImages = false;
213
+ for (const block of content) {
214
+ if (block.type === 'text') {
215
+ textParts.push(block.text);
216
+ }
217
+ else if (block.type === 'image') {
218
+ hadImages = true;
219
+ }
220
+ // Skip tool_use, tool_result, thinking blocks for base models
221
+ }
222
+ return {
223
+ text: textParts.join('\n'),
224
+ hadImages,
225
+ };
226
+ }
227
+ buildStopSequences(participants, assistantParticipant, maxParticipants, additionalStopSequences) {
228
+ const stops = [];
229
+ // Get recent participants (excluding assistant)
230
+ let count = 0;
231
+ for (const participant of participants) {
232
+ if (participant === assistantParticipant)
233
+ continue;
234
+ if (count >= maxParticipants)
235
+ break;
236
+ // Add both "\n\nName:" and "\nName:" variants
237
+ const prefix = this.config.nameFormat.replace('{name}', participant).trimEnd();
238
+ stops.push(`\n\n${prefix}`);
239
+ stops.push(`\n${prefix}`);
240
+ // Add lowercased variants if casing differs (for models that generate mixed-case names)
241
+ if (this.config.caseInsensitiveStops) {
242
+ const lower = this.config.nameFormat.replace('{name}', participant.toLowerCase()).trimEnd();
243
+ if (lower !== prefix) {
244
+ stops.push(`\n\n${lower}`);
245
+ stops.push(`\n${lower}`);
246
+ }
247
+ }
248
+ count++;
249
+ }
250
+ // Add EOT token as stop sequence if configured
251
+ if (this.config.eotToken) {
252
+ stops.push(this.config.eotToken);
253
+ }
254
+ // Add any additional stop sequences
255
+ if (additionalStopSequences?.length) {
256
+ stops.push(...additionalStopSequences);
257
+ }
258
+ return stops;
259
+ }
260
+ }
261
+ //# sourceMappingURL=completions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions.js","sourceRoot":"","sources":["../../src/formatters/completions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAoEH,+EAA+E;AAC/E,sDAAsD;AACtD,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,uBAAuB;IACnB,WAAW,GAAG,EAAE,CAAC;IACjB,UAAU,GAAG,CAAC,CAAC;IACf,YAAY,GAAG,KAAK,CAAC;IAE7B,YAAY,CAAC,KAAa;QACxB,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC;QAC1B,MAAM,IAAI,GAAG;YACX,IAAI,EAAE,MAAe;YACrB,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;QAEF,MAAM,SAAS,GAAqB,EAAE,CAAC;QACvC,MAAM,WAAW,GAAiB,EAAE,CAAC;QAErC,kCAAkC;QAClC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,UAAU,GAAe;gBAC7B,KAAK,EAAE,aAAa;gBACpB,KAAK,EAAE,IAAI,CAAC,UAAU;gBACtB,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;aACxB,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;YAC1D,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC7B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAA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AK,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Formatter exports
3
+ */
4
+ export type { PrefillFormatter, StreamParser, FormatterConfig, BuildOptions, BuildResult, ParseResult, BlockType, ProviderMessage, } from './types.js';
5
+ export { AnthropicXmlFormatter, type AnthropicXmlFormatterConfig } from './anthropic-xml.js';
6
+ export { NativeFormatter, type NativeFormatterConfig } from './native.js';
7
+ export { CompletionsFormatter, type CompletionsFormatterConfig } from './completions.js';
8
+ export { normalizeToolPairs, MembraneNormalizerError, type NormalizeOptions, type NormalizeResult, type ProviderBlock, } from './normalize-tool-pairs.js';
9
+ export type { NormalizeEvent } from './types.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,KAAK,0BAA0B,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,KAAK,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAEzF,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Formatter exports
3
+ */
4
+ export { AnthropicXmlFormatter } from './anthropic-xml.js';
5
+ export { NativeFormatter } from './native.js';
6
+ export { CompletionsFormatter } from './completions.js';
7
+ export { normalizeToolPairs, MembraneNormalizerError, } from './normalize-tool-pairs.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/formatters/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH,OAAO,EAAE,qBAAqB,EAAoC,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,eAAe,EAA8B,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAmC,MAAM,kBAAkB,CAAC;AAEzF,OAAO,EACL,kBAAkB,EAClB,uBAAuB,GAIxB,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Native Formatter
3
+ *
4
+ * Pass-through formatter that converts messages to standard user/assistant
5
+ * format without prefill. Uses native API tool calling.
6
+ *
7
+ * Supports two participant modes:
8
+ * - 'simple': Strict two-party (Human/Assistant), no names in content
9
+ * - 'multiuser': Multiple participants, names prefixed to content
10
+ */
11
+ import type { NormalizedMessage, ContentBlock, ToolCall, ToolResult } from '../types/index.js';
12
+ import type { PrefillFormatter, StreamParser, BuildOptions, BuildResult, FormatterConfig } from './types.js';
13
+ export interface NativeFormatterConfig extends FormatterConfig {
14
+ /**
15
+ * Format for participant name prefix in multiuser mode.
16
+ * Use {name} as placeholder. Default: '{name}: '
17
+ */
18
+ nameFormat?: string;
19
+ }
20
+ export declare class NativeFormatter implements PrefillFormatter {
21
+ readonly name = "native";
22
+ readonly usesPrefill = false;
23
+ private config;
24
+ constructor(config?: NativeFormatterConfig);
25
+ buildMessages(messages: NormalizedMessage[], options: BuildOptions): BuildResult;
26
+ formatToolResults(results: ToolResult[]): string;
27
+ createStreamParser(): StreamParser;
28
+ parseToolCalls(content: string): ToolCall[];
29
+ hasToolUse(content: string): boolean;
30
+ parseContentBlocks(content: string): ContentBlock[];
31
+ private convertContent;
32
+ private mergeConsecutiveRoles;
33
+ private convertToNativeTools;
34
+ }
35
+ //# sourceMappingURL=native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../../src/formatters/native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EAEZ,QAAQ,EACR,UAAU,EACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EAMhB,MAAM,YAAY,CAAC;AAMpB,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAyGD,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,WAAW,SAAS;IAE7B,OAAO,CAAC,MAAM,CAAkC;gBAEpC,MAAM,GAAE,qBAA0B;IAY9C,aAAa,CAAC,QAAQ,EAAE,iBAAiB,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,WAAW;IAwHhF,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM;IAchD,kBAAkB,IAAI,YAAY;IAIl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