@animalabs/membrane 0.1.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/context/index.d.ts +10 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +9 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/process.d.ts +22 -0
- package/dist/context/process.d.ts.map +1 -0
- package/dist/context/process.js +369 -0
- package/dist/context/process.js.map +1 -0
- package/dist/context/types.d.ts +118 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/context/types.js +60 -0
- package/dist/context/types.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/membrane.d.ts +96 -0
- package/dist/membrane.d.ts.map +1 -0
- package/dist/membrane.js +893 -0
- package/dist/membrane.js.map +1 -0
- package/dist/providers/anthropic.d.ts +36 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +265 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +8 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +8 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai-compatible.d.ts +74 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai-compatible.js +412 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/providers/openai.d.ts +69 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +455 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +76 -0
- package/dist/providers/openrouter.d.ts.map +1 -0
- package/dist/providers/openrouter.js +492 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/transforms/chat.d.ts +52 -0
- package/dist/transforms/chat.d.ts.map +1 -0
- package/dist/transforms/chat.js +136 -0
- package/dist/transforms/chat.js.map +1 -0
- package/dist/transforms/index.d.ts +6 -0
- package/dist/transforms/index.d.ts.map +1 -0
- package/dist/transforms/index.js +6 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/prefill.d.ts +89 -0
- package/dist/transforms/prefill.d.ts.map +1 -0
- package/dist/transforms/prefill.js +401 -0
- package/dist/transforms/prefill.js.map +1 -0
- package/dist/types/config.d.ts +103 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +21 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/content.d.ts +81 -0
- package/dist/types/content.d.ts.map +1 -0
- package/dist/types/content.js +40 -0
- package/dist/types/content.js.map +1 -0
- package/dist/types/errors.d.ts +42 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +208 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +46 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +38 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/provider.d.ts +155 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/types/provider.js +5 -0
- package/dist/types/provider.js.map +1 -0
- package/dist/types/request.d.ts +78 -0
- package/dist/types/request.d.ts.map +1 -0
- package/dist/types/request.js +5 -0
- package/dist/types/request.js.map +1 -0
- package/dist/types/response.d.ts +131 -0
- package/dist/types/response.d.ts.map +1 -0
- package/dist/types/response.js +7 -0
- package/dist/types/response.js.map +1 -0
- package/dist/types/streaming.d.ts +164 -0
- package/dist/types/streaming.d.ts.map +1 -0
- package/dist/types/streaming.js +5 -0
- package/dist/types/streaming.js.map +1 -0
- package/dist/types/tools.d.ts +71 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/types/tools.js +5 -0
- package/dist/types/tools.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/stream-parser.d.ts +53 -0
- package/dist/utils/stream-parser.d.ts.map +1 -0
- package/dist/utils/stream-parser.js +359 -0
- package/dist/utils/stream-parser.js.map +1 -0
- package/dist/utils/tool-parser.d.ts +130 -0
- package/dist/utils/tool-parser.d.ts.map +1 -0
- package/dist/utils/tool-parser.js +571 -0
- package/dist/utils/tool-parser.js.map +1 -0
- package/package.json +37 -0
- package/src/context/index.ts +24 -0
- package/src/context/process.ts +520 -0
- package/src/context/types.ts +231 -0
- package/src/index.ts +23 -0
- package/src/membrane.ts +1174 -0
- package/src/providers/anthropic.ts +340 -0
- package/src/providers/index.ts +31 -0
- package/src/providers/openai-compatible.ts +570 -0
- package/src/providers/openai.ts +625 -0
- package/src/providers/openrouter.ts +662 -0
- package/src/transforms/chat.ts +212 -0
- package/src/transforms/index.ts +22 -0
- package/src/transforms/prefill.ts +585 -0
- package/src/types/config.ts +172 -0
- package/src/types/content.ts +181 -0
- package/src/types/errors.ts +277 -0
- package/src/types/index.ts +154 -0
- package/src/types/message.ts +89 -0
- package/src/types/provider.ts +249 -0
- package/src/types/request.ts +131 -0
- package/src/types/response.ts +223 -0
- package/src/types/streaming.ts +231 -0
- package/src/types/tools.ts +92 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/stream-parser.ts +440 -0
- package/src/utils/tool-parser.ts +715 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalized message types
|
|
3
|
+
*/
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Helpers
|
|
6
|
+
// ============================================================================
|
|
7
|
+
/**
|
|
8
|
+
* Create a simple text message
|
|
9
|
+
*/
|
|
10
|
+
export function textMessage(participant, text, metadata) {
|
|
11
|
+
return {
|
|
12
|
+
participant,
|
|
13
|
+
content: [{ type: 'text', text }],
|
|
14
|
+
metadata,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extract all text content from a message
|
|
19
|
+
*/
|
|
20
|
+
export function extractText(message) {
|
|
21
|
+
return message.content
|
|
22
|
+
.filter((block) => block.type === 'text')
|
|
23
|
+
.map((block) => block.text)
|
|
24
|
+
.join('\n');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if message has any media content
|
|
28
|
+
*/
|
|
29
|
+
export function hasMedia(message) {
|
|
30
|
+
return message.content.some((block) => ['image', 'document', 'audio', 'video'].includes(block.type));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if message has tool use
|
|
34
|
+
*/
|
|
35
|
+
export function hasToolUse(message) {
|
|
36
|
+
return message.content.some((block) => block.type === 'tool_use');
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/types/message.ts"],"names":[],"mappings":"AAAA;;GAEG;AA+CH,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,WAAmB,EAAE,IAAY,EAAE,QAA0B;IACvF,OAAO;QACL,WAAW;QACX,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACjC,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAA0B;IACpD,OAAO,OAAO,CAAC,OAAO;SACnB,MAAM,CAAC,CAAC,KAAK,EAA2C,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;SACjF,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,OAA0B;IACjD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACpC,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAC7D,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAA0B;IACnD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider capability and registry types
|
|
3
|
+
*/
|
|
4
|
+
export interface ProviderQuirks {
|
|
5
|
+
/** Anthropic: must trim trailing whitespace from assistant messages */
|
|
6
|
+
trimAssistantTrailingWhitespace?: boolean;
|
|
7
|
+
/** Most providers: require alternating user/assistant roles */
|
|
8
|
+
requiresAlternatingRoles?: boolean;
|
|
9
|
+
/** Prefill mode: images must be in user turns */
|
|
10
|
+
imagesMustBeInUserTurn?: boolean;
|
|
11
|
+
/** Whether stop sequence is consumed (not in output) or present */
|
|
12
|
+
stopSequenceConsumed?: boolean;
|
|
13
|
+
/** Parameters to strip from request (provider rejects them) */
|
|
14
|
+
rejectParams?: string[];
|
|
15
|
+
/** Provider-specific notes */
|
|
16
|
+
notes?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface MediaCapabilities {
|
|
19
|
+
imageInput: boolean;
|
|
20
|
+
pdfInput: boolean;
|
|
21
|
+
audioInput: boolean;
|
|
22
|
+
videoInput: boolean;
|
|
23
|
+
imageGeneration: boolean;
|
|
24
|
+
maxImageSizeBytes?: number;
|
|
25
|
+
maxImageDimensions?: {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
};
|
|
29
|
+
maxPdfPages?: number;
|
|
30
|
+
maxAudioDurationSec?: number;
|
|
31
|
+
maxVideoDurationSec?: number;
|
|
32
|
+
imageFormats?: string[];
|
|
33
|
+
audioFormats?: string[];
|
|
34
|
+
videoFormats?: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface ProviderCapabilities {
|
|
37
|
+
supportsPrefill: boolean;
|
|
38
|
+
supportsChat: boolean;
|
|
39
|
+
supportsCaching: boolean;
|
|
40
|
+
supportsThinking: boolean;
|
|
41
|
+
supportsStreaming: boolean;
|
|
42
|
+
media: MediaCapabilities;
|
|
43
|
+
maxContextTokens: number;
|
|
44
|
+
maxOutputTokens: number;
|
|
45
|
+
maxStopSequences: number;
|
|
46
|
+
maxCacheBreakpoints?: number;
|
|
47
|
+
quirks: ProviderQuirks;
|
|
48
|
+
}
|
|
49
|
+
export interface ModelPricing {
|
|
50
|
+
/** Cost per million input tokens */
|
|
51
|
+
inputPerMillion: number;
|
|
52
|
+
/** Cost per million output tokens */
|
|
53
|
+
outputPerMillion: number;
|
|
54
|
+
/** Cost per million cache write tokens */
|
|
55
|
+
cacheWritePerMillion?: number;
|
|
56
|
+
/** Cost per million cache read tokens */
|
|
57
|
+
cacheReadPerMillion?: number;
|
|
58
|
+
/** Currency code */
|
|
59
|
+
currency: string;
|
|
60
|
+
}
|
|
61
|
+
export interface ModelDefinition {
|
|
62
|
+
/** Unique model identifier */
|
|
63
|
+
id: string;
|
|
64
|
+
/** Provider (anthropic, openrouter, google, etc.) */
|
|
65
|
+
provider: string;
|
|
66
|
+
/** Display name for UI */
|
|
67
|
+
displayName: string;
|
|
68
|
+
/** Capabilities */
|
|
69
|
+
capabilities: ProviderCapabilities;
|
|
70
|
+
/** Pricing (optional) */
|
|
71
|
+
pricing?: ModelPricing;
|
|
72
|
+
/** Aliases that resolve to this model */
|
|
73
|
+
aliases?: string[];
|
|
74
|
+
/** Whether model is deprecated */
|
|
75
|
+
deprecated?: boolean;
|
|
76
|
+
/** Successor model if deprecated */
|
|
77
|
+
successorId?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ModelRegistry {
|
|
80
|
+
/** Get capabilities for a model */
|
|
81
|
+
getCapabilities(modelId: string): ProviderCapabilities | undefined;
|
|
82
|
+
/** Get pricing for a model */
|
|
83
|
+
getPricing(modelId: string): ModelPricing | undefined;
|
|
84
|
+
/** Get quirks for a model */
|
|
85
|
+
getQuirks(modelId: string): ProviderQuirks | undefined;
|
|
86
|
+
/** Get full model definition */
|
|
87
|
+
getModel(modelId: string): ModelDefinition | undefined;
|
|
88
|
+
/** Resolve alias to canonical model ID */
|
|
89
|
+
resolveModel(idOrAlias: string): string;
|
|
90
|
+
/** List all models (optionally filtered) */
|
|
91
|
+
listModels(filter?: ModelFilter): ModelDefinition[];
|
|
92
|
+
}
|
|
93
|
+
export interface ModelFilter {
|
|
94
|
+
provider?: string;
|
|
95
|
+
supportsPrefill?: boolean;
|
|
96
|
+
supportsThinking?: boolean;
|
|
97
|
+
supportsImageGeneration?: boolean;
|
|
98
|
+
includeDeprecated?: boolean;
|
|
99
|
+
}
|
|
100
|
+
export interface ProviderAdapter {
|
|
101
|
+
/** Provider name */
|
|
102
|
+
readonly name: string;
|
|
103
|
+
/** Check if this adapter handles a model */
|
|
104
|
+
supportsModel(modelId: string): boolean;
|
|
105
|
+
/** Make a completion request (non-streaming) */
|
|
106
|
+
complete(request: ProviderRequest, options?: ProviderRequestOptions): Promise<ProviderResponse>;
|
|
107
|
+
/** Make a streaming request */
|
|
108
|
+
stream(request: ProviderRequest, callbacks: StreamCallbacks, options?: ProviderRequestOptions): Promise<ProviderResponse>;
|
|
109
|
+
}
|
|
110
|
+
export interface ProviderRequest {
|
|
111
|
+
/** Raw messages in provider format */
|
|
112
|
+
messages: unknown[];
|
|
113
|
+
/** System prompt - can be string or content blocks with cache_control */
|
|
114
|
+
system?: string | unknown[];
|
|
115
|
+
/** Model ID */
|
|
116
|
+
model: string;
|
|
117
|
+
/** Max tokens */
|
|
118
|
+
maxTokens: number;
|
|
119
|
+
/** Temperature */
|
|
120
|
+
temperature?: number;
|
|
121
|
+
/** Stop sequences */
|
|
122
|
+
stopSequences?: string[];
|
|
123
|
+
/** Tools in provider format */
|
|
124
|
+
tools?: unknown[];
|
|
125
|
+
/** Additional provider-specific params */
|
|
126
|
+
extra?: Record<string, unknown>;
|
|
127
|
+
}
|
|
128
|
+
export interface ProviderRequestOptions {
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
timeoutMs?: number;
|
|
131
|
+
}
|
|
132
|
+
export interface ProviderResponse {
|
|
133
|
+
/** Raw response content */
|
|
134
|
+
content: unknown;
|
|
135
|
+
/** Stop reason in provider format */
|
|
136
|
+
stopReason: string;
|
|
137
|
+
/** Which stop sequence triggered */
|
|
138
|
+
stopSequence?: string;
|
|
139
|
+
/** Usage in provider format */
|
|
140
|
+
usage: {
|
|
141
|
+
inputTokens: number;
|
|
142
|
+
outputTokens: number;
|
|
143
|
+
cacheCreationTokens?: number;
|
|
144
|
+
cacheReadTokens?: number;
|
|
145
|
+
};
|
|
146
|
+
/** Model that actually ran */
|
|
147
|
+
model: string;
|
|
148
|
+
/** Raw response for debugging */
|
|
149
|
+
raw: unknown;
|
|
150
|
+
}
|
|
151
|
+
export interface StreamCallbacks {
|
|
152
|
+
onChunk: (chunk: string) => void;
|
|
153
|
+
onContentBlock?: (index: number, block: unknown) => void;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,+BAA+B,CAAC,EAAE,OAAO,CAAC;IAE1C,+DAA+D;IAC/D,wBAAwB,CAAC,EAAE,OAAO,CAAC;IAEnC,iDAAiD;IACjD,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC,mEAAmE;IACnE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB,8BAA8B;IAC9B,KA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;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,CAAC;IAEF,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IAEd,iCAAiC;IACjC,GAAG,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request types for membrane
|
|
3
|
+
*/
|
|
4
|
+
import type { NormalizedMessage } from './message.js';
|
|
5
|
+
import type { ToolDefinition } from './tools.js';
|
|
6
|
+
export interface GenerationConfig {
|
|
7
|
+
/** Model identifier */
|
|
8
|
+
model: string;
|
|
9
|
+
/** Maximum tokens to generate */
|
|
10
|
+
maxTokens: number;
|
|
11
|
+
/** Temperature (0-2) */
|
|
12
|
+
temperature?: number;
|
|
13
|
+
/** Top P nucleus sampling */
|
|
14
|
+
topP?: number;
|
|
15
|
+
/** Top K sampling (provider-specific) */
|
|
16
|
+
topK?: number;
|
|
17
|
+
/** Presence penalty (provider-specific) */
|
|
18
|
+
presencePenalty?: number;
|
|
19
|
+
/** Frequency penalty (provider-specific) */
|
|
20
|
+
frequencyPenalty?: number;
|
|
21
|
+
/** Enable thinking/reasoning mode */
|
|
22
|
+
thinking?: {
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
budgetTokens?: number;
|
|
25
|
+
};
|
|
26
|
+
/** Image generation config (Gemini) */
|
|
27
|
+
imageGeneration?: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
modalities: ('TEXT' | 'IMAGE')[];
|
|
30
|
+
aspectRatio?: '1:1' | '16:9' | '9:16' | '4:3' | '3:4';
|
|
31
|
+
imageSize?: 'SMALL' | 'MEDIUM' | 'LARGE';
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type StopSequenceStrategy = 'none' | 'post-facto' | 'resume-on-unclosed';
|
|
35
|
+
export interface StopSequenceConfig {
|
|
36
|
+
/** Stop sequences to use */
|
|
37
|
+
sequences: string[];
|
|
38
|
+
/** Strategy for handling false positives */
|
|
39
|
+
strategy?: StopSequenceStrategy;
|
|
40
|
+
/** Max resumptions for 'resume-on-unclosed' strategy */
|
|
41
|
+
maxResumptions?: number;
|
|
42
|
+
/** Additional sequences only checked post-facto (not sent to API) */
|
|
43
|
+
postFactoOnly?: string[];
|
|
44
|
+
}
|
|
45
|
+
export interface RequestOptions {
|
|
46
|
+
/** Abort signal for cancellation */
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
/** Request timeout in milliseconds */
|
|
49
|
+
timeoutMs?: number;
|
|
50
|
+
/** Request ID for correlation */
|
|
51
|
+
requestId?: string;
|
|
52
|
+
/** Tags for filtering/attribution */
|
|
53
|
+
tags?: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
export type ToolMode = 'xml' | 'native' | 'auto';
|
|
56
|
+
export interface NormalizedRequest {
|
|
57
|
+
/** Conversation messages */
|
|
58
|
+
messages: NormalizedMessage[];
|
|
59
|
+
/** System prompt */
|
|
60
|
+
system?: string;
|
|
61
|
+
/** Generation configuration */
|
|
62
|
+
config: GenerationConfig;
|
|
63
|
+
/** Tool definitions */
|
|
64
|
+
tools?: ToolDefinition[];
|
|
65
|
+
/** Tool execution mode (default: 'auto') */
|
|
66
|
+
toolMode?: ToolMode;
|
|
67
|
+
/** Stop sequence configuration */
|
|
68
|
+
stopSequences?: StopSequenceConfig | string[];
|
|
69
|
+
/**
|
|
70
|
+
* Maximum participants to include in auto-generated stop sequences (prefill mode).
|
|
71
|
+
* Set to 0 to disable participant-based stop sequences (allows frags/quotes).
|
|
72
|
+
* If not specified, uses membrane config default (10).
|
|
73
|
+
*/
|
|
74
|
+
maxParticipantsForStop?: number;
|
|
75
|
+
/** Provider-specific parameters (pass-through) */
|
|
76
|
+
providerParams?: Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/types/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD,MAAM,WAAW,gBAAgB;IAC/B,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IAEd,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAElB,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,2CAA2C;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,4CAA4C;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,qCAAqC;IACrC,QAAQ,CAAC,EAAE;QACT,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IAEF,uCAAuC;IACvC,eAAe,CAAC,EAAE;QAChB,OAAO,EAAE,OAAO,CAAC;QACjB,UAAU,EAAE,CAAC,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;QACjC,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;QACtD,SAAS,CAAC,EAAE,OAAO,GAAG,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@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/types/request.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response types for membrane
|
|
3
|
+
*/
|
|
4
|
+
import type { ContentBlock } from './content.js';
|
|
5
|
+
import type { ToolCall, ToolResult } from './tools.js';
|
|
6
|
+
export type StopReason = 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'refusal' | 'abort';
|
|
7
|
+
export interface BasicUsage {
|
|
8
|
+
inputTokens: number;
|
|
9
|
+
outputTokens: number;
|
|
10
|
+
}
|
|
11
|
+
export interface DetailedUsage extends BasicUsage {
|
|
12
|
+
/** Tokens used for cache creation */
|
|
13
|
+
cacheCreationTokens?: number;
|
|
14
|
+
/** Tokens read from cache */
|
|
15
|
+
cacheReadTokens?: number;
|
|
16
|
+
/** Tokens used for thinking/reasoning */
|
|
17
|
+
thinkingTokens?: number;
|
|
18
|
+
/** Estimated cost breakdown */
|
|
19
|
+
estimatedCost?: CostBreakdown;
|
|
20
|
+
}
|
|
21
|
+
export interface CostBreakdown {
|
|
22
|
+
input: number;
|
|
23
|
+
output: number;
|
|
24
|
+
cacheWrite?: number;
|
|
25
|
+
cacheRead?: number;
|
|
26
|
+
total: number;
|
|
27
|
+
currency: string;
|
|
28
|
+
}
|
|
29
|
+
export interface StopInfo {
|
|
30
|
+
reason: StopReason;
|
|
31
|
+
/** Which stop sequence triggered (if stop_sequence) */
|
|
32
|
+
triggeredSequence?: string;
|
|
33
|
+
/** Whether output was truncated */
|
|
34
|
+
wasTruncated: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface ModelInfo {
|
|
37
|
+
/** Model ID that was requested */
|
|
38
|
+
requested: string;
|
|
39
|
+
/** Model ID that actually ran (may differ due to routing/fallback) */
|
|
40
|
+
actual: string;
|
|
41
|
+
/** Provider that served the request */
|
|
42
|
+
provider: string;
|
|
43
|
+
}
|
|
44
|
+
export interface TimingInfo {
|
|
45
|
+
/** Total request duration */
|
|
46
|
+
totalDurationMs: number;
|
|
47
|
+
/** Time to first token (streaming only) */
|
|
48
|
+
timeToFirstTokenMs?: number;
|
|
49
|
+
/** Tokens per second (streaming only) */
|
|
50
|
+
tokensPerSecond?: number;
|
|
51
|
+
/** Number of retry attempts */
|
|
52
|
+
attempts: number;
|
|
53
|
+
/** Delay between retries */
|
|
54
|
+
retryDelaysMs?: number[];
|
|
55
|
+
}
|
|
56
|
+
export interface CacheInfo {
|
|
57
|
+
/** Number of cache markers in request */
|
|
58
|
+
markersInRequest: number;
|
|
59
|
+
/** Tokens created in cache */
|
|
60
|
+
tokensCreated: number;
|
|
61
|
+
/** Tokens read from cache */
|
|
62
|
+
tokensRead: number;
|
|
63
|
+
/** Cache hit ratio (0-1) */
|
|
64
|
+
hitRatio: number;
|
|
65
|
+
}
|
|
66
|
+
export interface ResponseDetails {
|
|
67
|
+
stop: StopInfo;
|
|
68
|
+
usage: DetailedUsage;
|
|
69
|
+
timing: TimingInfo;
|
|
70
|
+
model: ModelInfo;
|
|
71
|
+
cache: CacheInfo;
|
|
72
|
+
}
|
|
73
|
+
export interface RawAccess {
|
|
74
|
+
/** Exact request body sent to provider */
|
|
75
|
+
request: unknown;
|
|
76
|
+
/** Exact response received from provider */
|
|
77
|
+
response: unknown;
|
|
78
|
+
/** Response headers */
|
|
79
|
+
headers?: Record<string, string>;
|
|
80
|
+
}
|
|
81
|
+
export interface NormalizedResponse {
|
|
82
|
+
/** Response content blocks (parsed/structured) */
|
|
83
|
+
content: ContentBlock[];
|
|
84
|
+
/**
|
|
85
|
+
* Raw assistant output text including all XML.
|
|
86
|
+
* Use this for building subsequent turn context (verbatim prefill).
|
|
87
|
+
*/
|
|
88
|
+
rawAssistantText: string;
|
|
89
|
+
/**
|
|
90
|
+
* Tool calls extracted from the response.
|
|
91
|
+
* Convenience accessor - these are also in content as tool_use blocks.
|
|
92
|
+
*/
|
|
93
|
+
toolCalls: ToolCall[];
|
|
94
|
+
/**
|
|
95
|
+
* Tool results that were executed during this response.
|
|
96
|
+
* Empty if no tools were called or tool execution was disabled.
|
|
97
|
+
*/
|
|
98
|
+
toolResults: ToolResult[];
|
|
99
|
+
/** Why generation stopped */
|
|
100
|
+
stopReason: StopReason;
|
|
101
|
+
/** Basic usage (always available) */
|
|
102
|
+
usage: BasicUsage;
|
|
103
|
+
/** Detailed response information */
|
|
104
|
+
details: ResponseDetails;
|
|
105
|
+
/** Raw request/response for debugging */
|
|
106
|
+
raw: RawAccess;
|
|
107
|
+
}
|
|
108
|
+
export interface AbortedResponse {
|
|
109
|
+
aborted: true;
|
|
110
|
+
/** Content received before abort */
|
|
111
|
+
partialContent?: ContentBlock[];
|
|
112
|
+
/** Tokens consumed before abort */
|
|
113
|
+
partialUsage?: BasicUsage;
|
|
114
|
+
/** Why it was aborted */
|
|
115
|
+
reason: 'user' | 'timeout' | 'error';
|
|
116
|
+
/**
|
|
117
|
+
* Raw assistant text accumulated before abort.
|
|
118
|
+
* Use for displaying partial output or as prefill to continue.
|
|
119
|
+
*/
|
|
120
|
+
rawAssistantText?: string;
|
|
121
|
+
/**
|
|
122
|
+
* Tool calls that were executed before abort.
|
|
123
|
+
*/
|
|
124
|
+
toolCalls?: ToolCall[];
|
|
125
|
+
/**
|
|
126
|
+
* Tool results received before abort.
|
|
127
|
+
*/
|
|
128
|
+
toolResults?: ToolResult[];
|
|
129
|
+
}
|
|
130
|
+
export declare function isAbortedResponse(response: NormalizedResponse | AbortedResponse): response is AbortedResponse;
|
|
131
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/types/response.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;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AE1B,yBAAyB;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IAErC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAEvB;;OAEG;IACH,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,kBAAkB,GAAG,eAAe,GAC7C,QAAQ,IAAI,eAAe,CAE7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/types/response.ts"],"names":[],"mappings":"AAAA;;GAEG;AAwNH,MAAM,UAAU,iBAAiB,CAC/B,QAA8C;IAE9C,OAAO,SAAS,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming types for membrane
|
|
3
|
+
*/
|
|
4
|
+
import type { ContentBlock } from './content.js';
|
|
5
|
+
import type { ToolCall, ToolResult, ToolContext } from './tools.js';
|
|
6
|
+
import type { BasicUsage } from './response.js';
|
|
7
|
+
/**
|
|
8
|
+
* Membrane block types - logical content regions at the context level.
|
|
9
|
+
* These are abstract structures, not tied to any wire format.
|
|
10
|
+
*/
|
|
11
|
+
export type MembraneBlockType = 'text' | 'thinking' | 'tool_call' | 'tool_result';
|
|
12
|
+
/**
|
|
13
|
+
* Membrane block - a logical content region with full content.
|
|
14
|
+
* Used in block_complete events.
|
|
15
|
+
*/
|
|
16
|
+
export interface MembraneBlock {
|
|
17
|
+
type: MembraneBlockType;
|
|
18
|
+
content?: string;
|
|
19
|
+
toolId?: string;
|
|
20
|
+
toolName?: string;
|
|
21
|
+
input?: Record<string, unknown>;
|
|
22
|
+
isError?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Chunk type - alias for MembraneBlockType for clarity in chunk contexts
|
|
26
|
+
*/
|
|
27
|
+
export type ChunkType = MembraneBlockType;
|
|
28
|
+
/**
|
|
29
|
+
* Metadata about a streaming chunk.
|
|
30
|
+
* Provides context about which block the chunk belongs to and its visibility.
|
|
31
|
+
*/
|
|
32
|
+
export interface ChunkMeta {
|
|
33
|
+
/** Which membrane block type this chunk belongs to */
|
|
34
|
+
type: ChunkType;
|
|
35
|
+
/** Convenience flag for TTS/display filtering - false for thinking/tool content */
|
|
36
|
+
visible: boolean;
|
|
37
|
+
/** Which content block this belongs to (0-indexed) */
|
|
38
|
+
blockIndex: number;
|
|
39
|
+
/** Tool nesting depth (for nested tool calls) */
|
|
40
|
+
depth?: number;
|
|
41
|
+
/** For tool_call chunks - which part of the tool call is streaming */
|
|
42
|
+
toolCallPart?: 'name' | 'id' | 'input';
|
|
43
|
+
/** Tool use ID (for tool_call / tool_result chunks) */
|
|
44
|
+
toolId?: string;
|
|
45
|
+
/** Tool name (for tool_call chunks, once known) */
|
|
46
|
+
toolName?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Block start event - signals a new block is starting.
|
|
50
|
+
* Fired before any onChunk calls for that block.
|
|
51
|
+
*/
|
|
52
|
+
export interface BlockStartEvent {
|
|
53
|
+
event: 'block_start';
|
|
54
|
+
index: number;
|
|
55
|
+
block: {
|
|
56
|
+
type: MembraneBlockType;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Block complete event - signals a block is done.
|
|
61
|
+
* Includes full accumulated content. Fired after all onChunk calls for that block.
|
|
62
|
+
*/
|
|
63
|
+
export interface BlockCompleteEvent {
|
|
64
|
+
event: 'block_complete';
|
|
65
|
+
index: number;
|
|
66
|
+
block: MembraneBlock;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Block event - either start or complete.
|
|
70
|
+
* Note: No block_delta - streaming content is provided via onChunk with metadata.
|
|
71
|
+
*/
|
|
72
|
+
export type BlockEvent = BlockStartEvent | BlockCompleteEvent;
|
|
73
|
+
/**
|
|
74
|
+
* @deprecated Use BlockEvent instead. BlockDelta is no longer used;
|
|
75
|
+
* streaming content is provided via onChunk with ChunkMeta.
|
|
76
|
+
*/
|
|
77
|
+
export type BlockDelta = {
|
|
78
|
+
type: 'text';
|
|
79
|
+
text: string;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'thinking';
|
|
82
|
+
thinking: string;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'tool_input';
|
|
85
|
+
partialJson: string;
|
|
86
|
+
};
|
|
87
|
+
export interface StreamState {
|
|
88
|
+
/** Accumulated text output */
|
|
89
|
+
accumulated: string;
|
|
90
|
+
/** Current content blocks (updated during stream) */
|
|
91
|
+
contentBlocks: ContentBlock[];
|
|
92
|
+
/** Current tool execution depth */
|
|
93
|
+
toolDepth: number;
|
|
94
|
+
/** Tool calls executed so far */
|
|
95
|
+
toolCallsExecuted: ToolCall[];
|
|
96
|
+
/** Tokens generated so far (estimate) */
|
|
97
|
+
tokensGenerated: number;
|
|
98
|
+
/** Abort function */
|
|
99
|
+
abort: () => void;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Callback for text chunks - called immediately as tokens arrive.
|
|
103
|
+
* Includes metadata about block type, visibility, and position.
|
|
104
|
+
*/
|
|
105
|
+
export type OnChunkCallback = (chunk: string, meta: ChunkMeta) => void;
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated Use onBlock + onChunk with ChunkMeta instead.
|
|
108
|
+
* This callback is superseded by:
|
|
109
|
+
* - onBlock for structured block_start/block_complete events
|
|
110
|
+
* - onChunk with ChunkMeta for streaming content with block context
|
|
111
|
+
*/
|
|
112
|
+
export type OnContentBlockCallback = (index: number, block: ContentBlock) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Callback for tool execution
|
|
115
|
+
* Return tool results to continue; throw to abort
|
|
116
|
+
*/
|
|
117
|
+
export type OnToolCallsCallback = (calls: ToolCall[], context: ToolContext) => Promise<ToolResult[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Callback for pre-tool content notification
|
|
120
|
+
* Called with content that appeared before tool calls
|
|
121
|
+
*/
|
|
122
|
+
export type OnPreToolContentCallback = (content: string) => Promise<void> | void;
|
|
123
|
+
/**
|
|
124
|
+
* Callback for usage updates during streaming
|
|
125
|
+
*/
|
|
126
|
+
export type OnUsageCallback = (usage: BasicUsage) => void;
|
|
127
|
+
/**
|
|
128
|
+
* Callback for structured block events during streaming.
|
|
129
|
+
* Provides parsed block information as it's detected.
|
|
130
|
+
*/
|
|
131
|
+
export type OnBlockCallback = (event: BlockEvent) => void;
|
|
132
|
+
export interface StreamOptions {
|
|
133
|
+
/** Abort signal for cancellation */
|
|
134
|
+
signal?: AbortSignal;
|
|
135
|
+
/** Request timeout */
|
|
136
|
+
timeoutMs?: number;
|
|
137
|
+
/** Request ID for correlation */
|
|
138
|
+
requestId?: string;
|
|
139
|
+
/** Called immediately for each text chunk */
|
|
140
|
+
onChunk?: OnChunkCallback;
|
|
141
|
+
/** Called when content blocks update (thinking, images) */
|
|
142
|
+
onContentBlockUpdate?: OnContentBlockCallback;
|
|
143
|
+
/** Called when tool calls are detected; return results to continue */
|
|
144
|
+
onToolCalls?: OnToolCallsCallback;
|
|
145
|
+
/** Called with content before tool calls (for UI preview) */
|
|
146
|
+
onPreToolContent?: OnPreToolContentCallback;
|
|
147
|
+
/** Called with usage updates */
|
|
148
|
+
onUsage?: OnUsageCallback;
|
|
149
|
+
/** Called for structured block events (thinking, tool_use, tool_result) */
|
|
150
|
+
onBlock?: OnBlockCallback;
|
|
151
|
+
/** Maximum tool execution depth (default: 10) */
|
|
152
|
+
maxToolDepth?: number;
|
|
153
|
+
/** Timeout for each tool execution */
|
|
154
|
+
toolTimeoutMs?: number;
|
|
155
|
+
}
|
|
156
|
+
export interface CompleteOptions {
|
|
157
|
+
/** Abort signal for cancellation */
|
|
158
|
+
signal?: AbortSignal;
|
|
159
|
+
/** Request timeout */
|
|
160
|
+
timeoutMs?: number;
|
|
161
|
+
/** Request ID for correlation */
|
|
162
|
+
requestId?: string;
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/types/streaming.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAMhD;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,aAAa,CAAC;AAElF;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAMD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAE1C;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,sDAAsD;IACtD,IAAI,EAAE,SAAS,CAAC;IAEhB,mFAAmF;IACnF,OAAO,EAAE,OAAO,CAAC;IAEjB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IAEnB,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;IAEvC,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,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