@animalabs/membrane 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formatters/anthropic-xml.d.ts +63 -0
- package/dist/formatters/anthropic-xml.d.ts.map +1 -0
- package/dist/formatters/anthropic-xml.js +365 -0
- package/dist/formatters/anthropic-xml.js.map +1 -0
- package/dist/formatters/completions.d.ts +61 -0
- package/dist/formatters/completions.d.ts.map +1 -0
- package/dist/formatters/completions.js +224 -0
- package/dist/formatters/completions.js.map +1 -0
- package/dist/formatters/index.d.ts +8 -0
- package/dist/formatters/index.d.ts.map +1 -0
- package/dist/formatters/index.js +7 -0
- package/dist/formatters/index.js.map +1 -0
- package/dist/formatters/native.d.ts +35 -0
- package/dist/formatters/native.d.ts.map +1 -0
- package/dist/formatters/native.js +261 -0
- package/dist/formatters/native.js.map +1 -0
- package/dist/formatters/types.d.ts +152 -0
- package/dist/formatters/types.d.ts.map +1 -0
- package/dist/formatters/types.js +7 -0
- package/dist/formatters/types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/membrane.d.ts +4 -0
- package/dist/membrane.d.ts.map +1 -1
- package/dist/membrane.js +40 -32
- package/dist/membrane.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +3 -2
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/transforms/index.d.ts +0 -1
- package/dist/transforms/index.d.ts.map +1 -1
- package/dist/transforms/index.js +2 -1
- package/dist/transforms/index.js.map +1 -1
- package/dist/types/config.d.ts +7 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/types/streaming.d.ts +6 -0
- package/dist/types/streaming.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/formatters/anthropic-xml.ts +490 -0
- package/src/formatters/completions.ts +343 -0
- package/src/formatters/index.ts +19 -0
- package/src/formatters/native.ts +340 -0
- package/src/formatters/types.ts +229 -0
- package/src/index.ts +3 -0
- package/src/membrane.ts +59 -45
- package/src/providers/anthropic.ts +3 -2
- package/src/transforms/index.ts +2 -10
- package/src/types/config.ts +9 -1
- package/src/types/streaming.ts +9 -0
- package/dist/providers/anthropic-chat.d.ts +0 -50
- package/dist/providers/anthropic-chat.d.ts.map +0 -1
- package/dist/providers/anthropic-chat.js +0 -212
- package/dist/providers/anthropic-chat.js.map +0 -1
- package/dist/providers/anthropic-multiuser.d.ts +0 -64
- package/dist/providers/anthropic-multiuser.d.ts.map +0 -1
- package/dist/providers/anthropic-multiuser.js +0 -297
- package/dist/providers/anthropic-multiuser.js.map +0 -1
- package/src/transforms/prefill.ts +0 -574
|
@@ -0,0 +1,224 @@
|
|
|
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
|
+
processChunk(chunk) {
|
|
25
|
+
this.accumulated += chunk;
|
|
26
|
+
const meta = {
|
|
27
|
+
type: 'text',
|
|
28
|
+
visible: true,
|
|
29
|
+
blockIndex: this.blockIndex,
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
emissions: [{
|
|
33
|
+
kind: 'content',
|
|
34
|
+
text: chunk,
|
|
35
|
+
meta,
|
|
36
|
+
}],
|
|
37
|
+
content: [{ text: chunk, meta }],
|
|
38
|
+
blockEvents: [],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
flush() {
|
|
42
|
+
return { emissions: [], content: [], blockEvents: [] };
|
|
43
|
+
}
|
|
44
|
+
getAccumulated() {
|
|
45
|
+
return this.accumulated;
|
|
46
|
+
}
|
|
47
|
+
reset() {
|
|
48
|
+
this.accumulated = '';
|
|
49
|
+
this.blockIndex = 0;
|
|
50
|
+
}
|
|
51
|
+
push(content) {
|
|
52
|
+
this.accumulated += content;
|
|
53
|
+
}
|
|
54
|
+
getCurrentBlockType() {
|
|
55
|
+
return 'text';
|
|
56
|
+
}
|
|
57
|
+
getBlockIndex() {
|
|
58
|
+
return this.blockIndex;
|
|
59
|
+
}
|
|
60
|
+
incrementBlockIndex() {
|
|
61
|
+
this.blockIndex++;
|
|
62
|
+
}
|
|
63
|
+
isInsideBlock() {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
resetForNewIteration() {
|
|
67
|
+
// No special reset needed
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// Completions Formatter
|
|
72
|
+
// ============================================================================
|
|
73
|
+
export class CompletionsFormatter {
|
|
74
|
+
name = 'completions';
|
|
75
|
+
usesPrefill = true;
|
|
76
|
+
config;
|
|
77
|
+
constructor(config = {}) {
|
|
78
|
+
this.config = {
|
|
79
|
+
eotToken: config.eotToken ?? '<|eot|>',
|
|
80
|
+
nameFormat: config.nameFormat ?? '{name}: ',
|
|
81
|
+
messageSeparator: config.messageSeparator ?? '\n\n',
|
|
82
|
+
maxParticipantsForStop: config.maxParticipantsForStop ?? 10,
|
|
83
|
+
warnOnImageStrip: config.warnOnImageStrip ?? true,
|
|
84
|
+
// Completions models don't support images - always strip
|
|
85
|
+
unsupportedMedia: 'strip',
|
|
86
|
+
warnOnStrip: config.warnOnStrip ?? true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// ==========================================================================
|
|
90
|
+
// REQUEST BUILDING
|
|
91
|
+
// ==========================================================================
|
|
92
|
+
buildMessages(messages, options) {
|
|
93
|
+
const { assistantParticipant, systemPrompt, additionalStopSequences, maxParticipantsForStop = this.config.maxParticipantsForStop, } = options;
|
|
94
|
+
const parts = [];
|
|
95
|
+
const participants = new Set();
|
|
96
|
+
let hasStrippedImages = false;
|
|
97
|
+
// Add system prompt as first part if present
|
|
98
|
+
if (systemPrompt) {
|
|
99
|
+
const systemText = typeof systemPrompt === 'string'
|
|
100
|
+
? systemPrompt
|
|
101
|
+
: systemPrompt
|
|
102
|
+
.filter((b) => b.type === 'text')
|
|
103
|
+
.map(b => b.text)
|
|
104
|
+
.join('\n');
|
|
105
|
+
if (systemText) {
|
|
106
|
+
parts.push(systemText);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Serialize each message
|
|
110
|
+
for (const message of messages) {
|
|
111
|
+
participants.add(message.participant);
|
|
112
|
+
const { text, hadImages } = this.extractTextContent(message.content);
|
|
113
|
+
if (hadImages) {
|
|
114
|
+
hasStrippedImages = true;
|
|
115
|
+
}
|
|
116
|
+
// Skip empty messages (except if it's the final completion target)
|
|
117
|
+
if (!text.trim()) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
// Format: "Participant: content<eot>"
|
|
121
|
+
const prefix = this.config.nameFormat.replace('{name}', message.participant);
|
|
122
|
+
const eot = this.config.eotToken;
|
|
123
|
+
parts.push(`${prefix}${text}${eot}`);
|
|
124
|
+
}
|
|
125
|
+
// Warn about stripped images
|
|
126
|
+
if (hasStrippedImages && this.config.warnOnImageStrip) {
|
|
127
|
+
console.warn('[CompletionsFormatter] Images were stripped from context (not supported in completions mode)');
|
|
128
|
+
}
|
|
129
|
+
// Add final assistant prefix (no EOT - model generates this)
|
|
130
|
+
const assistantPrefix = this.config.nameFormat.replace('{name}', assistantParticipant);
|
|
131
|
+
parts.push(assistantPrefix.trimEnd()); // Remove trailing space for cleaner completion
|
|
132
|
+
// Join all parts into single prompt
|
|
133
|
+
const prompt = parts.join(this.config.messageSeparator);
|
|
134
|
+
// Build stop sequences from participants
|
|
135
|
+
const stopSequences = this.buildStopSequences(participants, assistantParticipant, maxParticipantsForStop, additionalStopSequences);
|
|
136
|
+
// Return as single assistant message with prompt as content
|
|
137
|
+
// The provider adapter will extract this as the prompt
|
|
138
|
+
const providerMessages = [
|
|
139
|
+
{ role: 'assistant', content: prompt },
|
|
140
|
+
];
|
|
141
|
+
return {
|
|
142
|
+
messages: providerMessages,
|
|
143
|
+
assistantPrefill: prompt,
|
|
144
|
+
stopSequences,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
formatToolResults(results, options) {
|
|
148
|
+
// Completions mode typically doesn't support tools
|
|
149
|
+
// But format them as simple text if needed
|
|
150
|
+
const parts = results.map(r => {
|
|
151
|
+
const content = typeof r.content === 'string' ? r.content : JSON.stringify(r.content);
|
|
152
|
+
return `[Tool Result: ${content}]`;
|
|
153
|
+
});
|
|
154
|
+
return parts.join('\n');
|
|
155
|
+
}
|
|
156
|
+
// ==========================================================================
|
|
157
|
+
// RESPONSE PARSING
|
|
158
|
+
// ==========================================================================
|
|
159
|
+
createStreamParser() {
|
|
160
|
+
return new CompletionsStreamParser();
|
|
161
|
+
}
|
|
162
|
+
parseToolCalls(content) {
|
|
163
|
+
// Base models don't have structured tool output
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
hasToolUse(content) {
|
|
167
|
+
// Base models determine completion via stop sequences
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
parseContentBlocks(content) {
|
|
171
|
+
// Trim leading whitespace (model often starts with space after prefix)
|
|
172
|
+
const trimmed = content.replace(/^\s+/, '');
|
|
173
|
+
if (!trimmed) {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
return [{ type: 'text', text: trimmed }];
|
|
177
|
+
}
|
|
178
|
+
// ==========================================================================
|
|
179
|
+
// PRIVATE HELPERS
|
|
180
|
+
// ==========================================================================
|
|
181
|
+
extractTextContent(content) {
|
|
182
|
+
const textParts = [];
|
|
183
|
+
let hadImages = false;
|
|
184
|
+
for (const block of content) {
|
|
185
|
+
if (block.type === 'text') {
|
|
186
|
+
textParts.push(block.text);
|
|
187
|
+
}
|
|
188
|
+
else if (block.type === 'image') {
|
|
189
|
+
hadImages = true;
|
|
190
|
+
}
|
|
191
|
+
// Skip tool_use, tool_result, thinking blocks for base models
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
text: textParts.join('\n'),
|
|
195
|
+
hadImages,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
buildStopSequences(participants, assistantParticipant, maxParticipants, additionalStopSequences) {
|
|
199
|
+
const stops = [];
|
|
200
|
+
// Get recent participants (excluding assistant)
|
|
201
|
+
let count = 0;
|
|
202
|
+
for (const participant of participants) {
|
|
203
|
+
if (participant === assistantParticipant)
|
|
204
|
+
continue;
|
|
205
|
+
if (count >= maxParticipants)
|
|
206
|
+
break;
|
|
207
|
+
// Add both "\n\nName:" and "\nName:" variants
|
|
208
|
+
const prefix = this.config.nameFormat.replace('{name}', participant).trimEnd();
|
|
209
|
+
stops.push(`\n\n${prefix}`);
|
|
210
|
+
stops.push(`\n${prefix}`);
|
|
211
|
+
count++;
|
|
212
|
+
}
|
|
213
|
+
// Add EOT token as stop sequence if configured
|
|
214
|
+
if (this.config.eotToken) {
|
|
215
|
+
stops.push(this.config.eotToken);
|
|
216
|
+
}
|
|
217
|
+
// Add any additional stop sequences
|
|
218
|
+
if (additionalStopSequences?.length) {
|
|
219
|
+
stops.push(...additionalStopSequences);
|
|
220
|
+
}
|
|
221
|
+
return stops;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=completions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completions.js","sourceRoot":"","sources":["../../src/formatters/completions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA0DH,+EAA+E;AAC/E,sDAAsD;AACtD,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,uBAAuB;IACnB,WAAW,GAAG,EAAE,CAAC;IACjB,UAAU,GAAG,CAAC,CAAC;IAEvB,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;QACF,OAAO;YACL,SAAS,EAAE,CAAC;oBACV,IAAI,EAAE,SAAkB;oBACxB,IAAI,EAAE,KAAK;oBACX,IAAI;iBACL,CAAC;YACF,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAChC,WAAW,EAAE,EAAE;SAChB,CAAC;IACJ,CAAC;IAED,KAAK;QACH,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IACzD,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC;IAC9B,CAAC;IAED,mBAAmB;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,mBAAmB;QACjB,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED,aAA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AC,OAAO,MAAM,EAAE,CAAC,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;YAC1B,KAAK,EAAE,CAAC;QACV,CAAC;QAED,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;QAED,oCAAoC;QACpC,IAAI,uBAAuB,EAAE,MAAM,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -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"}
|
|
@@ -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
|
|
@@ -0,0 +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,EAIhB,MAAM,YAAY,CAAC;AAMpB,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AA2ED,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;IAkEhF,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM;IAchD,kBAAkB,IAAI,YAAY;IAIlC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,EAAE;IAM3C,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAKpC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,EAAE;IAYnD,OAAO,CAAC,cAAc;IAkEtB,OAAO,CAAC,qBAAqB;IA2B7B,OAAO,CAAC,oBAAoB;CAO7B"}
|
|
@@ -0,0 +1,261 @@
|
|
|
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
|
+
// ============================================================================
|
|
12
|
+
// Pass-through Stream Parser
|
|
13
|
+
// ============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Simple pass-through parser that doesn't do XML tracking.
|
|
16
|
+
* Just accumulates content and emits text chunks.
|
|
17
|
+
*/
|
|
18
|
+
class PassthroughParser {
|
|
19
|
+
accumulated = '';
|
|
20
|
+
blockIndex = 0;
|
|
21
|
+
processChunk(chunk) {
|
|
22
|
+
this.accumulated += chunk;
|
|
23
|
+
const meta = {
|
|
24
|
+
type: 'text',
|
|
25
|
+
visible: true,
|
|
26
|
+
blockIndex: this.blockIndex,
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
emissions: [{
|
|
30
|
+
kind: 'content',
|
|
31
|
+
text: chunk,
|
|
32
|
+
meta,
|
|
33
|
+
}],
|
|
34
|
+
content: [{ text: chunk, meta }],
|
|
35
|
+
blockEvents: [],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
flush() {
|
|
39
|
+
return { emissions: [], content: [], blockEvents: [] };
|
|
40
|
+
}
|
|
41
|
+
getAccumulated() {
|
|
42
|
+
return this.accumulated;
|
|
43
|
+
}
|
|
44
|
+
reset() {
|
|
45
|
+
this.accumulated = '';
|
|
46
|
+
this.blockIndex = 0;
|
|
47
|
+
}
|
|
48
|
+
push(content) {
|
|
49
|
+
this.accumulated += content;
|
|
50
|
+
}
|
|
51
|
+
getCurrentBlockType() {
|
|
52
|
+
return 'text';
|
|
53
|
+
}
|
|
54
|
+
getBlockIndex() {
|
|
55
|
+
return this.blockIndex;
|
|
56
|
+
}
|
|
57
|
+
incrementBlockIndex() {
|
|
58
|
+
this.blockIndex++;
|
|
59
|
+
}
|
|
60
|
+
isInsideBlock() {
|
|
61
|
+
// Pass-through mode never has nested blocks
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
resetForNewIteration() {
|
|
65
|
+
// No special reset needed for pass-through mode
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// Native Formatter
|
|
70
|
+
// ============================================================================
|
|
71
|
+
export class NativeFormatter {
|
|
72
|
+
name = 'native';
|
|
73
|
+
usesPrefill = false;
|
|
74
|
+
config;
|
|
75
|
+
constructor(config = {}) {
|
|
76
|
+
this.config = {
|
|
77
|
+
nameFormat: config.nameFormat ?? '{name}: ',
|
|
78
|
+
unsupportedMedia: config.unsupportedMedia ?? 'error',
|
|
79
|
+
warnOnStrip: config.warnOnStrip ?? true,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// ==========================================================================
|
|
83
|
+
// REQUEST BUILDING
|
|
84
|
+
// ==========================================================================
|
|
85
|
+
buildMessages(messages, options) {
|
|
86
|
+
const { participantMode, assistantParticipant, humanParticipant, tools, systemPrompt, } = options;
|
|
87
|
+
const providerMessages = [];
|
|
88
|
+
// Validate simple mode participants
|
|
89
|
+
if (participantMode === 'simple' && !humanParticipant) {
|
|
90
|
+
throw new Error('NativeFormatter in simple mode requires humanParticipant option');
|
|
91
|
+
}
|
|
92
|
+
for (const message of messages) {
|
|
93
|
+
// Determine role
|
|
94
|
+
const isAssistant = message.participant === assistantParticipant;
|
|
95
|
+
// Validate participant in simple mode
|
|
96
|
+
if (participantMode === 'simple') {
|
|
97
|
+
if (!isAssistant && message.participant !== humanParticipant) {
|
|
98
|
+
throw new Error(`NativeFormatter in simple mode only supports "${humanParticipant}" and "${assistantParticipant}". ` +
|
|
99
|
+
`Got: "${message.participant}". Use participantMode: 'multiuser' for multiple participants.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const role = isAssistant ? 'assistant' : 'user';
|
|
103
|
+
// Convert content
|
|
104
|
+
const content = this.convertContent(message.content, message.participant, {
|
|
105
|
+
includeNames: participantMode === 'multiuser' && !isAssistant,
|
|
106
|
+
});
|
|
107
|
+
if (content.length === 0) {
|
|
108
|
+
continue; // Skip empty messages
|
|
109
|
+
}
|
|
110
|
+
providerMessages.push({ role, content });
|
|
111
|
+
}
|
|
112
|
+
// Merge consecutive same-role messages (API requires alternating)
|
|
113
|
+
const mergedMessages = this.mergeConsecutiveRoles(providerMessages);
|
|
114
|
+
// Build system content
|
|
115
|
+
let systemContent;
|
|
116
|
+
if (typeof systemPrompt === 'string') {
|
|
117
|
+
systemContent = systemPrompt;
|
|
118
|
+
}
|
|
119
|
+
else if (Array.isArray(systemPrompt)) {
|
|
120
|
+
systemContent = systemPrompt;
|
|
121
|
+
}
|
|
122
|
+
// Native tools
|
|
123
|
+
const nativeTools = tools?.length ? this.convertToNativeTools(tools) : undefined;
|
|
124
|
+
return {
|
|
125
|
+
messages: mergedMessages,
|
|
126
|
+
systemContent,
|
|
127
|
+
stopSequences: [], // Native mode doesn't use custom stop sequences
|
|
128
|
+
nativeTools,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
formatToolResults(results) {
|
|
132
|
+
// Native mode uses API tool_result blocks, not string formatting
|
|
133
|
+
// This method is mainly for prefill modes
|
|
134
|
+
return JSON.stringify(results.map(r => ({
|
|
135
|
+
tool_use_id: r.toolUseId,
|
|
136
|
+
content: r.content,
|
|
137
|
+
is_error: r.isError,
|
|
138
|
+
})));
|
|
139
|
+
}
|
|
140
|
+
// ==========================================================================
|
|
141
|
+
// RESPONSE PARSING
|
|
142
|
+
// ==========================================================================
|
|
143
|
+
createStreamParser() {
|
|
144
|
+
return new PassthroughParser();
|
|
145
|
+
}
|
|
146
|
+
parseToolCalls(content) {
|
|
147
|
+
// Native mode gets tool calls from API response, not from content parsing
|
|
148
|
+
// Return empty - tool calls come through the native API response
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
hasToolUse(content) {
|
|
152
|
+
// Native mode determines tool use from API stop_reason, not content
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
parseContentBlocks(content) {
|
|
156
|
+
// Native mode - content is plain text
|
|
157
|
+
if (!content.trim()) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
return [{ type: 'text', text: content }];
|
|
161
|
+
}
|
|
162
|
+
// ==========================================================================
|
|
163
|
+
// PRIVATE HELPERS
|
|
164
|
+
// ==========================================================================
|
|
165
|
+
convertContent(content, participant, options) {
|
|
166
|
+
const result = [];
|
|
167
|
+
let hasUnsupportedMedia = false;
|
|
168
|
+
for (const block of content) {
|
|
169
|
+
if (block.type === 'text') {
|
|
170
|
+
let text = block.text;
|
|
171
|
+
if (options.includeNames) {
|
|
172
|
+
const prefix = this.config.nameFormat.replace('{name}', participant);
|
|
173
|
+
text = prefix + text;
|
|
174
|
+
}
|
|
175
|
+
const textBlock = { type: 'text', text };
|
|
176
|
+
if (block.cache_control) {
|
|
177
|
+
textBlock.cache_control = block.cache_control;
|
|
178
|
+
}
|
|
179
|
+
result.push(textBlock);
|
|
180
|
+
}
|
|
181
|
+
else if (block.type === 'image') {
|
|
182
|
+
if (block.source.type === 'base64') {
|
|
183
|
+
result.push({
|
|
184
|
+
type: 'image',
|
|
185
|
+
source: {
|
|
186
|
+
type: 'base64',
|
|
187
|
+
media_type: block.source.mediaType,
|
|
188
|
+
data: block.source.data,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (block.type === 'tool_use') {
|
|
194
|
+
result.push({
|
|
195
|
+
type: 'tool_use',
|
|
196
|
+
id: block.id,
|
|
197
|
+
name: block.name,
|
|
198
|
+
input: block.input,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else if (block.type === 'tool_result') {
|
|
202
|
+
result.push({
|
|
203
|
+
type: 'tool_result',
|
|
204
|
+
tool_use_id: block.toolUseId,
|
|
205
|
+
content: block.content,
|
|
206
|
+
is_error: block.isError,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
else if (block.type === 'thinking') {
|
|
210
|
+
result.push({
|
|
211
|
+
type: 'thinking',
|
|
212
|
+
thinking: block.thinking,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
else if (block.type === 'document' || block.type === 'audio') {
|
|
216
|
+
hasUnsupportedMedia = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (hasUnsupportedMedia) {
|
|
220
|
+
if (this.config.unsupportedMedia === 'error') {
|
|
221
|
+
throw new Error(`NativeFormatter: unsupported media type in content. Configure unsupportedMedia: 'strip' to ignore.`);
|
|
222
|
+
}
|
|
223
|
+
else if (this.config.warnOnStrip) {
|
|
224
|
+
console.warn(`[NativeFormatter] Stripped unsupported media from message`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
mergeConsecutiveRoles(messages) {
|
|
230
|
+
if (messages.length === 0)
|
|
231
|
+
return [];
|
|
232
|
+
const merged = [];
|
|
233
|
+
let current = messages[0];
|
|
234
|
+
for (let i = 1; i < messages.length; i++) {
|
|
235
|
+
const next = messages[i];
|
|
236
|
+
if (next.role === current.role) {
|
|
237
|
+
// Merge content arrays
|
|
238
|
+
const currentContent = Array.isArray(current.content) ? current.content : [current.content];
|
|
239
|
+
const nextContent = Array.isArray(next.content) ? next.content : [next.content];
|
|
240
|
+
current = {
|
|
241
|
+
role: current.role,
|
|
242
|
+
content: [...currentContent, ...nextContent],
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
merged.push(current);
|
|
247
|
+
current = next;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
merged.push(current);
|
|
251
|
+
return merged;
|
|
252
|
+
}
|
|
253
|
+
convertToNativeTools(tools) {
|
|
254
|
+
return tools.map(tool => ({
|
|
255
|
+
name: tool.name,
|
|
256
|
+
description: tool.description,
|
|
257
|
+
input_schema: tool.inputSchema,
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native.js","sourceRoot":"","sources":["../../src/formatters/native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAgCH,+EAA+E;AAC/E,6BAA6B;AAC7B,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,iBAAiB;IACb,WAAW,GAAG,EAAE,CAAC;IACjB,UAAU,GAAG,CAAC,CAAC;IAEvB,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;QACF,OAAO;YACL,SAAS,EAAE,CAAC;oBACV,IAAI,EAAE,SAAkB;oBACxB,IAAI,EAAE,KAAK;oBACX,IAAI;iBACL,CAAC;YACF,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YAChC,WAAW,EAAE,EAAE;SAChB,CAAC;IACJ,CAAC;IAED,KAAK;QACH,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IACzD,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,CAAC,OAAe;QAClB,IAAI,CAAC,WAAW,IAAI,OAAO,CAAC;IAC9B,CAAC;IAED,mBAAmB;QACjB,OAAO,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