@animalabs/membrane 0.5.47 → 0.5.51
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/membrane.d.ts.map +1 -1
- package/dist/membrane.js +72 -5
- package/dist/membrane.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +11 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/bedrock.d.ts.map +1 -1
- package/dist/providers/bedrock.js +9 -0
- package/dist/providers/bedrock.js.map +1 -1
- package/dist/types/yielding-stream.d.ts +10 -1
- package/dist/types/yielding-stream.d.ts.map +1 -1
- package/dist/types/yielding-stream.js.map +1 -1
- package/package.json +5 -1
- package/src/membrane.ts +77 -6
- package/src/providers/anthropic.ts +12 -0
- package/src/providers/bedrock.ts +8 -0
- package/src/types/yielding-stream.ts +10 -1
- package/dist/context/index.d.ts +0 -12
- package/dist/context/index.js +0 -11
- package/dist/context/index.js.map +0 -1
- package/dist/context/process.d.ts +0 -43
- package/dist/context/process.js +0 -381
- package/dist/context/process.js.map +0 -1
- package/dist/context/types.d.ts +0 -164
- package/dist/context/types.js +0 -61
- package/dist/context/types.js.map +0 -1
- package/dist/formatters/anthropic-xml.d.ts +0 -63
- package/dist/formatters/anthropic-xml.js +0 -417
- package/dist/formatters/anthropic-xml.js.map +0 -1
- package/dist/formatters/completions.d.ts +0 -68
- package/dist/formatters/completions.js +0 -261
- package/dist/formatters/completions.js.map +0 -1
- package/dist/formatters/index.d.ts +0 -8
- package/dist/formatters/index.js +0 -7
- package/dist/formatters/index.js.map +0 -1
- package/dist/formatters/native.d.ts +0 -35
- package/dist/formatters/native.js +0 -336
- package/dist/formatters/native.js.map +0 -1
- package/dist/formatters/types.d.ts +0 -167
- package/dist/formatters/types.js +0 -7
- package/dist/formatters/types.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -20
- package/dist/index.js.map +0 -1
- package/dist/membrane.d.ts +0 -155
- package/dist/providers/anthropic.d.ts +0 -36
- package/dist/providers/bedrock.d.ts +0 -43
- package/dist/providers/gemini.d.ts +0 -68
- package/dist/providers/gemini.js +0 -538
- package/dist/providers/gemini.js.map +0 -1
- package/dist/providers/index.d.ts +0 -13
- package/dist/providers/index.js +0 -13
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/mock.d.ts +0 -90
- package/dist/providers/mock.d.ts.map +0 -1
- package/dist/providers/mock.js +0 -210
- package/dist/providers/mock.js.map +0 -1
- package/dist/providers/openai-compatible.d.ts +0 -82
- package/dist/providers/openai-compatible.js +0 -480
- package/dist/providers/openai-compatible.js.map +0 -1
- package/dist/providers/openai-completions.d.ts +0 -89
- package/dist/providers/openai-completions.js +0 -347
- package/dist/providers/openai-completions.js.map +0 -1
- package/dist/providers/openai-responses.d.ts +0 -77
- package/dist/providers/openai-responses.js +0 -333
- package/dist/providers/openai-responses.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -77
- package/dist/providers/openai.js +0 -533
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/openrouter.d.ts +0 -82
- package/dist/providers/openrouter.js +0 -556
- package/dist/providers/openrouter.js.map +0 -1
- package/dist/providers/utils.d.ts +0 -44
- package/dist/providers/utils.d.ts.map +0 -1
- package/dist/providers/utils.js +0 -100
- package/dist/providers/utils.js.map +0 -1
- package/dist/registry/default-pricing.d.ts +0 -3
- package/dist/registry/default-pricing.d.ts.map +0 -1
- package/dist/registry/default-pricing.js +0 -75
- package/dist/registry/default-pricing.js.map +0 -1
- package/dist/transforms/chat.d.ts +0 -52
- package/dist/transforms/chat.js +0 -136
- package/dist/transforms/chat.js.map +0 -1
- package/dist/transforms/index.d.ts +0 -5
- package/dist/transforms/index.js +0 -7
- package/dist/transforms/index.js.map +0 -1
- package/dist/transforms/prefill.d.ts +0 -89
- package/dist/transforms/prefill.d.ts.map +0 -1
- package/dist/transforms/prefill.js +0 -391
- package/dist/transforms/prefill.js.map +0 -1
- package/dist/types/config.d.ts +0 -110
- package/dist/types/config.js +0 -21
- package/dist/types/config.js.map +0 -1
- package/dist/types/content.d.ts +0 -87
- package/dist/types/content.d.ts.map +0 -1
- package/dist/types/content.js +0 -40
- package/dist/types/content.js.map +0 -1
- package/dist/types/errors.d.ts +0 -50
- package/dist/types/errors.d.ts.map +0 -1
- package/dist/types/errors.js +0 -253
- package/dist/types/errors.js.map +0 -1
- package/dist/types/index.d.ts +0 -20
- package/dist/types/index.js +0 -10
- package/dist/types/index.js.map +0 -1
- package/dist/types/message.d.ts +0 -52
- package/dist/types/message.d.ts.map +0 -1
- package/dist/types/message.js +0 -38
- package/dist/types/message.js.map +0 -1
- package/dist/types/provider.d.ts +0 -169
- package/dist/types/provider.d.ts.map +0 -1
- package/dist/types/provider.js +0 -5
- package/dist/types/provider.js.map +0 -1
- package/dist/types/request.d.ts +0 -116
- package/dist/types/request.d.ts.map +0 -1
- package/dist/types/request.js +0 -5
- package/dist/types/request.js.map +0 -1
- package/dist/types/response.d.ts +0 -131
- package/dist/types/response.d.ts.map +0 -1
- package/dist/types/response.js +0 -7
- package/dist/types/response.js.map +0 -1
- package/dist/types/streaming.d.ts +0 -194
- package/dist/types/streaming.js +0 -5
- package/dist/types/streaming.js.map +0 -1
- package/dist/types/tools.d.ts +0 -71
- package/dist/types/tools.d.ts.map +0 -1
- package/dist/types/tools.js +0 -5
- package/dist/types/tools.js.map +0 -1
- package/dist/utils/cost.d.ts +0 -10
- package/dist/utils/cost.d.ts.map +0 -1
- package/dist/utils/cost.js +0 -19
- package/dist/utils/cost.js.map +0 -1
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/index.js +0 -6
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/stream-parser.d.ts +0 -84
- package/dist/utils/stream-parser.js +0 -418
- package/dist/utils/stream-parser.js.map +0 -1
- package/dist/utils/tool-parser.d.ts +0 -134
- package/dist/utils/tool-parser.js +0 -600
- package/dist/utils/tool-parser.js.map +0 -1
- package/dist/yielding-stream.d.ts +0 -60
- package/dist/yielding-stream.js +0 -206
- package/dist/yielding-stream.js.map +0 -1
package/dist/providers/utils.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Safely parse a JSON string, returning an empty object on failure.
|
|
3
|
-
* Used for tool call arguments which may be malformed from streaming.
|
|
4
|
-
*/
|
|
5
|
-
export function safeParseJson(str) {
|
|
6
|
-
try {
|
|
7
|
-
return JSON.parse(str || '{}');
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
console.warn('[membrane] Failed to parse tool arguments JSON:', e);
|
|
11
|
-
return {};
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Create a combined AbortSignal that fires on either the caller's signal
|
|
16
|
-
* or a timeout (whichever comes first).
|
|
17
|
-
*
|
|
18
|
-
* The returned `cleanup` function MUST be called in a `finally` block to
|
|
19
|
-
* clear the timeout and remove the event listener, preventing leaks.
|
|
20
|
-
*
|
|
21
|
-
* Timeout aborts with `DOMException('Request timed out', 'AbortError')`
|
|
22
|
-
* so it classifies identically to user-initiated aborts.
|
|
23
|
-
*/
|
|
24
|
-
export function createCombinedSignal(signal, timeoutMs) {
|
|
25
|
-
if (!signal && !timeoutMs)
|
|
26
|
-
return {};
|
|
27
|
-
if (signal && !timeoutMs)
|
|
28
|
-
return { signal };
|
|
29
|
-
const controller = new AbortController();
|
|
30
|
-
let timeoutId;
|
|
31
|
-
if (timeoutMs) {
|
|
32
|
-
timeoutId = setTimeout(() => controller.abort(new DOMException('Request timed out', 'AbortError')), timeoutMs);
|
|
33
|
-
}
|
|
34
|
-
const onAbort = () => controller.abort(signal.reason);
|
|
35
|
-
if (signal) {
|
|
36
|
-
if (signal.aborted) {
|
|
37
|
-
controller.abort(signal.reason);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
signal: controller.signal,
|
|
45
|
-
cleanup: () => {
|
|
46
|
-
if (timeoutId)
|
|
47
|
-
clearTimeout(timeoutId);
|
|
48
|
-
if (signal)
|
|
49
|
-
signal.removeEventListener('abort', onAbort);
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* SSE (Server-Sent Events) line parser that correctly handles events
|
|
55
|
-
* split across multiple TCP chunks.
|
|
56
|
-
*
|
|
57
|
-
* The naive approach of `chunk.split('\n').filter(l => l.startsWith('data: '))`
|
|
58
|
-
* silently drops events when an SSE line spans two chunks:
|
|
59
|
-
* Chunk 1: `data: {"choices":[{"delta":{"content":"don'` (no newline — incomplete)
|
|
60
|
-
* Chunk 2: `t do that"}}]}\n` (doesn't start with `data: `)
|
|
61
|
-
* Result: the entire event is lost, causing "skipped words" in output.
|
|
62
|
-
*
|
|
63
|
-
* This parser buffers partial lines and only yields complete `data: ...` lines.
|
|
64
|
-
*/
|
|
65
|
-
export class SSELineParser {
|
|
66
|
-
buffer = '';
|
|
67
|
-
/**
|
|
68
|
-
* Feed a raw chunk from the stream reader and get back complete SSE data lines.
|
|
69
|
-
* Each returned string is the content after `data: ` (e.g. the JSON payload or `[DONE]`).
|
|
70
|
-
*/
|
|
71
|
-
feed(chunk) {
|
|
72
|
-
this.buffer += chunk;
|
|
73
|
-
const results = [];
|
|
74
|
-
// Split on newlines, keeping the last (potentially incomplete) segment in the buffer
|
|
75
|
-
const lines = this.buffer.split('\n');
|
|
76
|
-
this.buffer = lines.pop() || '';
|
|
77
|
-
for (const line of lines) {
|
|
78
|
-
const trimmed = line.trim();
|
|
79
|
-
if (trimmed.startsWith('data: ')) {
|
|
80
|
-
results.push(trimmed.slice(6));
|
|
81
|
-
}
|
|
82
|
-
// Skip empty lines, comments (`:...`), and other SSE fields (event:, id:, retry:)
|
|
83
|
-
}
|
|
84
|
-
return results;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Flush any remaining buffered content (call when stream ends).
|
|
88
|
-
*/
|
|
89
|
-
flush() {
|
|
90
|
-
if (!this.buffer.trim())
|
|
91
|
-
return [];
|
|
92
|
-
const trimmed = this.buffer.trim();
|
|
93
|
-
this.buffer = '';
|
|
94
|
-
if (trimmed.startsWith('data: ')) {
|
|
95
|
-
return [trimmed.slice(6)];
|
|
96
|
-
}
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAuB;IACnD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,CAAC,CAAC,CAAC;QACnE,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAoB,EACpB,SAAkB;IAElB,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,CAAC;IACrC,IAAI,MAAM,IAAI,CAAC,SAAS;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAE5C,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,SAAoD,CAAC;IAEzD,IAAI,SAAS,EAAE,CAAC;QACd,SAAS,GAAG,UAAU,CACpB,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC,EAC3E,SAAS,CACV,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,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IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAAE,OAAO,EAAE,CAAC;QACnC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-pricing.d.ts","sourceRoot":"","sources":["../../src/registry/default-pricing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAkEzD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAU3E"}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Built-in pricing table for known models.
|
|
3
|
-
* Prices in USD per million tokens. Last updated: 2025-07.
|
|
4
|
-
*
|
|
5
|
-
* Used as fallback when no ModelRegistry is configured.
|
|
6
|
-
* Registry pricing (if available) takes precedence.
|
|
7
|
-
*/
|
|
8
|
-
const PRICING_TABLE = [
|
|
9
|
-
// Anthropic — Claude 4.6
|
|
10
|
-
{
|
|
11
|
-
prefix: 'claude-opus-4-6',
|
|
12
|
-
pricing: { inputPerMillion: 15, outputPerMillion: 75, cacheWritePerMillion: 18.75, cacheReadPerMillion: 1.50, currency: 'USD' },
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
prefix: 'claude-sonnet-4-6',
|
|
16
|
-
pricing: { inputPerMillion: 3, outputPerMillion: 15, cacheWritePerMillion: 3.75, cacheReadPerMillion: 0.30, currency: 'USD' },
|
|
17
|
-
},
|
|
18
|
-
// Anthropic — Claude 4.5
|
|
19
|
-
{
|
|
20
|
-
prefix: 'claude-haiku-4-5',
|
|
21
|
-
pricing: { inputPerMillion: 0.80, outputPerMillion: 4, cacheWritePerMillion: 1.00, cacheReadPerMillion: 0.08, currency: 'USD' },
|
|
22
|
-
},
|
|
23
|
-
// Anthropic — Claude 4
|
|
24
|
-
{
|
|
25
|
-
prefix: 'claude-opus-4',
|
|
26
|
-
pricing: { inputPerMillion: 15, outputPerMillion: 75, cacheWritePerMillion: 18.75, cacheReadPerMillion: 1.50, currency: 'USD' },
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
prefix: 'claude-sonnet-4',
|
|
30
|
-
pricing: { inputPerMillion: 3, outputPerMillion: 15, cacheWritePerMillion: 3.75, cacheReadPerMillion: 0.30, currency: 'USD' },
|
|
31
|
-
},
|
|
32
|
-
// Anthropic — Claude 3.5
|
|
33
|
-
{
|
|
34
|
-
prefix: 'claude-3-5-sonnet',
|
|
35
|
-
pricing: { inputPerMillion: 3, outputPerMillion: 15, cacheWritePerMillion: 3.75, cacheReadPerMillion: 0.30, currency: 'USD' },
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
prefix: 'claude-3-5-haiku',
|
|
39
|
-
pricing: { inputPerMillion: 0.80, outputPerMillion: 4, cacheWritePerMillion: 1.00, cacheReadPerMillion: 0.08, currency: 'USD' },
|
|
40
|
-
},
|
|
41
|
-
// OpenAI — GPT-4o
|
|
42
|
-
{
|
|
43
|
-
prefix: 'gpt-4o-2024',
|
|
44
|
-
pricing: { inputPerMillion: 2.50, outputPerMillion: 10, cacheReadPerMillion: 1.25, currency: 'USD' },
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
prefix: 'gpt-4o',
|
|
48
|
-
pricing: { inputPerMillion: 2.50, outputPerMillion: 10, cacheReadPerMillion: 1.25, currency: 'USD' },
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
prefix: 'gpt-4o-mini',
|
|
52
|
-
pricing: { inputPerMillion: 0.15, outputPerMillion: 0.60, cacheReadPerMillion: 0.075, currency: 'USD' },
|
|
53
|
-
},
|
|
54
|
-
// Google — Gemini 2.5
|
|
55
|
-
{
|
|
56
|
-
prefix: 'gemini-2.5-pro',
|
|
57
|
-
pricing: { inputPerMillion: 1.25, outputPerMillion: 10, currency: 'USD' },
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
prefix: 'gemini-2.5-flash',
|
|
61
|
-
pricing: { inputPerMillion: 0.15, outputPerMillion: 0.60, currency: 'USD' },
|
|
62
|
-
},
|
|
63
|
-
];
|
|
64
|
-
export function getDefaultPricing(modelId) {
|
|
65
|
-
let best;
|
|
66
|
-
let bestLen = 0;
|
|
67
|
-
for (const entry of PRICING_TABLE) {
|
|
68
|
-
if (modelId.startsWith(entry.prefix) && entry.prefix.length > bestLen) {
|
|
69
|
-
best = entry.pricing;
|
|
70
|
-
bestLen = entry.prefix.length;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return best;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=default-pricing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"default-pricing.js","sourceRoot":"","sources":["../../src/registry/default-pricing.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,aAAa,GAAqD;IACtE,yBAAyB;IACzB;QACE,MAAM,EAAE,iBAAiB;QACzB,OAAO,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;KAChI;IACD;QACE,MAAM,EAAE,mBAAmB;QAC3B,OAAO,EAAE,EAAE,eAAe,EAAE,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC9H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IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,mBAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;KACrG;IACD;QACE,MAAM,EAAE,aAAa;QACrB,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE;KACxG;IACD,sBAAsB;IACtB;QACE,MAAM,EAAE,gBAAgB;QACxB,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC1E;IACD;QACE,MAAM,EAAE,kBAAkB;QAC1B,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;KAC5E;CACF,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,IAAI,IAA8B,CAAC;IACnC,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;QAClC,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;YACtE,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;YACrB,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chat mode transforms
|
|
3
|
-
*
|
|
4
|
-
* Converts normalized messages to role-based alternating format
|
|
5
|
-
* for providers that don't support prefill mode.
|
|
6
|
-
*/
|
|
7
|
-
import type { NormalizedRequest } from '../types/index.js';
|
|
8
|
-
export interface ChatMessage {
|
|
9
|
-
role: 'user' | 'assistant';
|
|
10
|
-
content: ChatContent[];
|
|
11
|
-
}
|
|
12
|
-
export type ChatContent = {
|
|
13
|
-
type: 'text';
|
|
14
|
-
text: string;
|
|
15
|
-
} | {
|
|
16
|
-
type: 'image';
|
|
17
|
-
source: {
|
|
18
|
-
type: 'base64';
|
|
19
|
-
data: string;
|
|
20
|
-
mediaType: string;
|
|
21
|
-
};
|
|
22
|
-
} | {
|
|
23
|
-
type: 'tool_use';
|
|
24
|
-
id: string;
|
|
25
|
-
name: string;
|
|
26
|
-
input: Record<string, unknown>;
|
|
27
|
-
} | {
|
|
28
|
-
type: 'tool_result';
|
|
29
|
-
tool_use_id: string;
|
|
30
|
-
content: string;
|
|
31
|
-
};
|
|
32
|
-
export interface ChatTransformResult {
|
|
33
|
-
/** System prompt */
|
|
34
|
-
system: string;
|
|
35
|
-
/** Messages in role-based format */
|
|
36
|
-
messages: ChatMessage[];
|
|
37
|
-
/** Stop sequences to use */
|
|
38
|
-
stopSequences: string[];
|
|
39
|
-
}
|
|
40
|
-
export interface ChatTransformOptions {
|
|
41
|
-
/** Name of the assistant participant (default: 'Claude') */
|
|
42
|
-
assistantName?: string;
|
|
43
|
-
/** Names to treat as 'user' role */
|
|
44
|
-
userParticipants?: string[];
|
|
45
|
-
/** How to handle multiple consecutive same-role messages */
|
|
46
|
-
mergeStrategy?: 'concatenate' | 'separate';
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Transform normalized request to chat format
|
|
50
|
-
*/
|
|
51
|
-
export declare function transformToChat(request: NormalizedRequest, options?: ChatTransformOptions): ChatTransformResult;
|
|
52
|
-
//# sourceMappingURL=chat.d.ts.map
|
package/dist/transforms/chat.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chat mode transforms
|
|
3
|
-
*
|
|
4
|
-
* Converts normalized messages to role-based alternating format
|
|
5
|
-
* for providers that don't support prefill mode.
|
|
6
|
-
*/
|
|
7
|
-
import { isTextContent, isToolUseContent, isToolResultContent } from '../types/index.js';
|
|
8
|
-
// ============================================================================
|
|
9
|
-
// Main Transform Function
|
|
10
|
-
// ============================================================================
|
|
11
|
-
/**
|
|
12
|
-
* Transform normalized request to chat format
|
|
13
|
-
*/
|
|
14
|
-
export function transformToChat(request, options = {}) {
|
|
15
|
-
const { assistantName = 'Claude', userParticipants = [], mergeStrategy = 'concatenate', } = options;
|
|
16
|
-
const userSet = new Set(userParticipants);
|
|
17
|
-
const messages = [];
|
|
18
|
-
for (const message of request.messages) {
|
|
19
|
-
const role = determineRole(message.participant, assistantName, userSet);
|
|
20
|
-
const content = transformContent(message.content);
|
|
21
|
-
if (mergeStrategy === 'concatenate' && messages.length > 0) {
|
|
22
|
-
const lastMessage = messages[messages.length - 1];
|
|
23
|
-
if (lastMessage && lastMessage.role === role) {
|
|
24
|
-
// Merge with previous message
|
|
25
|
-
lastMessage.content.push(...content);
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
messages.push({ role, content });
|
|
30
|
-
}
|
|
31
|
-
// Ensure alternating roles (required by most providers)
|
|
32
|
-
const normalizedMessages = ensureAlternatingRoles(messages);
|
|
33
|
-
// Build stop sequences
|
|
34
|
-
const stopSequences = buildChatStopSequences(request);
|
|
35
|
-
return {
|
|
36
|
-
system: request.system ?? '',
|
|
37
|
-
messages: normalizedMessages,
|
|
38
|
-
stopSequences,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// ============================================================================
|
|
42
|
-
// Helper Functions
|
|
43
|
-
// ============================================================================
|
|
44
|
-
function determineRole(participant, assistantName, userSet) {
|
|
45
|
-
if (participant === assistantName) {
|
|
46
|
-
return 'assistant';
|
|
47
|
-
}
|
|
48
|
-
if (userSet.has(participant)) {
|
|
49
|
-
return 'user';
|
|
50
|
-
}
|
|
51
|
-
// Default: non-assistant is user
|
|
52
|
-
return 'user';
|
|
53
|
-
}
|
|
54
|
-
function transformContent(blocks) {
|
|
55
|
-
const result = [];
|
|
56
|
-
for (const block of blocks) {
|
|
57
|
-
if (isTextContent(block)) {
|
|
58
|
-
result.push({ type: 'text', text: block.text });
|
|
59
|
-
}
|
|
60
|
-
else if (block.type === 'image' && block.source.type === 'base64') {
|
|
61
|
-
result.push({
|
|
62
|
-
type: 'image',
|
|
63
|
-
source: {
|
|
64
|
-
type: 'base64',
|
|
65
|
-
data: block.source.data,
|
|
66
|
-
mediaType: block.source.mediaType,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else if (isToolUseContent(block)) {
|
|
71
|
-
result.push({
|
|
72
|
-
type: 'tool_use',
|
|
73
|
-
id: block.id,
|
|
74
|
-
name: block.name,
|
|
75
|
-
input: block.input,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else if (isToolResultContent(block)) {
|
|
79
|
-
const content = typeof block.content === 'string'
|
|
80
|
-
? block.content
|
|
81
|
-
: JSON.stringify(block.content);
|
|
82
|
-
result.push({
|
|
83
|
-
type: 'tool_result',
|
|
84
|
-
tool_use_id: block.toolUseId,
|
|
85
|
-
content,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
// Other block types are skipped or could be handled here
|
|
89
|
-
}
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
function ensureAlternatingRoles(messages) {
|
|
93
|
-
if (messages.length === 0)
|
|
94
|
-
return messages;
|
|
95
|
-
const result = [];
|
|
96
|
-
let lastRole = null;
|
|
97
|
-
for (const message of messages) {
|
|
98
|
-
if (lastRole === message.role) {
|
|
99
|
-
// Insert empty message of opposite role
|
|
100
|
-
const fillerRole = message.role === 'user' ? 'assistant' : 'user';
|
|
101
|
-
result.push({
|
|
102
|
-
role: fillerRole,
|
|
103
|
-
content: [{ type: 'text', text: '...' }],
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
result.push(message);
|
|
107
|
-
lastRole = message.role;
|
|
108
|
-
}
|
|
109
|
-
// Ensure starts with user
|
|
110
|
-
const first = result[0];
|
|
111
|
-
if (result.length > 0 && first && first.role === 'assistant') {
|
|
112
|
-
result.unshift({
|
|
113
|
-
role: 'user',
|
|
114
|
-
content: [{ type: 'text', text: '...' }],
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
function buildChatStopSequences(request) {
|
|
120
|
-
const sequences = [];
|
|
121
|
-
// Add tool-related stop if tools are defined
|
|
122
|
-
if (request.tools && request.tools.length > 0) {
|
|
123
|
-
sequences.push('</function_calls>');
|
|
124
|
-
}
|
|
125
|
-
// Add any explicit stop sequences from request
|
|
126
|
-
if (request.stopSequences) {
|
|
127
|
-
if (Array.isArray(request.stopSequences)) {
|
|
128
|
-
sequences.push(...request.stopSequences);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
sequences.push(...request.stopSequences.sequences);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return sequences;
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=chat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/transforms/chat.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AA2CzF,+EAA+E;AAC/E,0BAA0B;AAC1B,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,OAA0B,EAC1B,UAAgC,EAAE;IAElC,MAAM,EACJ,aAAa,GAAG,QAAQ,EACxB,gBAAgB,GAAG,EAAE,EACrB,aAAa,GAAG,aAAa,GAC9B,GAAG,OAAO,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAkB,EAAE,CAAC;IAEnC,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACvC,MAAM,I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C9C,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACtC,CAAC;IAED,+CAA+C;IAC/C,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;YACzC,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/transforms/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,iDAAiD;AACjD,yEAAyE;AAEzE,OAAO,EACL,eAAe,GAKhB,MAAM,WAAW,CAAC"}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Prefill mode transforms
|
|
3
|
-
*
|
|
4
|
-
* Converts normalized messages to participant-based conversation log format:
|
|
5
|
-
*
|
|
6
|
-
* Alice: Hello there!
|
|
7
|
-
*
|
|
8
|
-
* Bob: Hi Alice!
|
|
9
|
-
*
|
|
10
|
-
* Claude: [assistant continuation starts here...]
|
|
11
|
-
*
|
|
12
|
-
* Key features:
|
|
13
|
-
* - Cache control markers for Anthropic prompt caching
|
|
14
|
-
* - Image flushing (images cause conversation flush to user turn)
|
|
15
|
-
* - Tool injection into conversation
|
|
16
|
-
*/
|
|
17
|
-
import type { NormalizedRequest, CacheControl } from '../types/index.js';
|
|
18
|
-
/**
|
|
19
|
-
* Content block in provider format (Anthropic-style)
|
|
20
|
-
* Can include cache_control for prompt caching
|
|
21
|
-
*/
|
|
22
|
-
export interface ProviderTextBlock {
|
|
23
|
-
type: 'text';
|
|
24
|
-
text: string;
|
|
25
|
-
cache_control?: CacheControl;
|
|
26
|
-
}
|
|
27
|
-
export interface ProviderImageBlock {
|
|
28
|
-
type: 'image';
|
|
29
|
-
source: {
|
|
30
|
-
type: 'base64';
|
|
31
|
-
media_type: string;
|
|
32
|
-
data: string;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export type ProviderContentBlock = ProviderTextBlock | ProviderImageBlock;
|
|
36
|
-
export interface ProviderMessage {
|
|
37
|
-
role: 'user' | 'assistant';
|
|
38
|
-
content: string | ProviderContentBlock[];
|
|
39
|
-
}
|
|
40
|
-
export interface PrefillTransformResult {
|
|
41
|
-
/** System prompt content blocks (may have cache_control) */
|
|
42
|
-
systemContent: ProviderContentBlock[];
|
|
43
|
-
/** Messages in provider format (ready for API) */
|
|
44
|
-
messages: ProviderMessage[];
|
|
45
|
-
/** For legacy compatibility: system as string */
|
|
46
|
-
system: string;
|
|
47
|
-
/** For legacy compatibility: user content as string */
|
|
48
|
-
userContent: string;
|
|
49
|
-
/** For legacy compatibility: assistant prefill as string */
|
|
50
|
-
assistantPrefill: string;
|
|
51
|
-
/** Stop sequences to use */
|
|
52
|
-
stopSequences: string[];
|
|
53
|
-
/** Number of cache markers applied */
|
|
54
|
-
cacheMarkersApplied: number;
|
|
55
|
-
}
|
|
56
|
-
export interface PrefillTransformOptions {
|
|
57
|
-
/** Name of the assistant participant (default: 'Claude') */
|
|
58
|
-
assistantName?: string;
|
|
59
|
-
/** Maximum participants to include in stop sequences */
|
|
60
|
-
maxParticipantsForStop?: number;
|
|
61
|
-
/** Custom stop sequences to add */
|
|
62
|
-
additionalStopSequences?: string[];
|
|
63
|
-
/**
|
|
64
|
-
* Where to inject tool definitions:
|
|
65
|
-
* - 'conversation': Inject into assistant content ~N messages from end (default)
|
|
66
|
-
* - 'system': Inject into system prompt
|
|
67
|
-
* - 'none': No injection (use getToolInstructions() for manual placement)
|
|
68
|
-
*/
|
|
69
|
-
toolInjectionMode?: 'conversation' | 'system' | 'none';
|
|
70
|
-
/** Position to inject tools when mode is 'conversation' (from end of messages) */
|
|
71
|
-
toolInjectionPosition?: number;
|
|
72
|
-
/** Enable prompt caching (default: true) */
|
|
73
|
-
promptCaching?: boolean;
|
|
74
|
-
/** Message delimiter for base models (e.g., '</s>') */
|
|
75
|
-
messageDelimiter?: string;
|
|
76
|
-
/** Context prefix for simulacrum seeding */
|
|
77
|
-
contextPrefix?: string;
|
|
78
|
-
/** Start assistant response with <thinking> tag */
|
|
79
|
-
prefillThinking?: boolean;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Transform normalized request to prefill format with cache control support
|
|
83
|
-
*/
|
|
84
|
-
export declare function transformToPrefill(request: NormalizedRequest, options?: PrefillTransformOptions): PrefillTransformResult;
|
|
85
|
-
/**
|
|
86
|
-
* Build a continuation request from accumulated output
|
|
87
|
-
*/
|
|
88
|
-
export declare function buildContinuationPrefill(originalResult: PrefillTransformResult, accumulated: string): PrefillTransformResult;
|
|
89
|
-
//# sourceMappingURL=prefill.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prefill.d.ts","sourceRoot":"","sources":["../../src/transforms/prefill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAEV,iBAAiB,EAGjB,YAAY,EACb,MAAM,mBAAmB,CAAC;AAQ3B;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,YAAY,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG,kBAAkB,CAAC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