@animalabs/membrane 0.3.0 → 0.3.2
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/providers/index.d.ts +0 -2
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +0 -2
- package/dist/providers/index.js.map +1 -1
- package/package.json +1 -1
- package/src/providers/index.ts +0 -10
- 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/providers/anthropic-chat.ts +0 -294
- package/src/providers/anthropic-multiuser.ts +0 -387
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Provider exports
|
|
3
3
|
*/
|
|
4
4
|
export { AnthropicAdapter, toAnthropicContent, fromAnthropicContent, type AnthropicAdapterConfig, } from './anthropic.js';
|
|
5
|
-
export { AnthropicChatAdapter, type AnthropicChatAdapterConfig, } from './anthropic-chat.js';
|
|
6
|
-
export { AnthropicMultiuserAdapter, type AnthropicMultiuserAdapterConfig, } from './anthropic-multiuser.js';
|
|
7
5
|
export { OpenRouterAdapter, toOpenRouterMessages, fromOpenRouterMessage, type OpenRouterAdapterConfig, } from './openrouter.js';
|
|
8
6
|
export { OpenAIAdapter, toOpenAIContent, fromOpenAIContent, type OpenAIAdapterConfig, } from './openai.js';
|
|
9
7
|
export { OpenAICompatibleAdapter, toOpenAIMessages, fromOpenAIMessage, type OpenAICompatibleAdapterConfig, } from './openai-compatible.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,sBAAsB,GAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,uBAAuB,GAC7B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,6BAA6B,GACnC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,wBAAwB,EACxB,KAAK,8BAA8B,GACpC,MAAM,yBAAyB,CAAC"}
|
package/dist/providers/index.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
* Provider exports
|
|
3
3
|
*/
|
|
4
4
|
export { AnthropicAdapter, toAnthropicContent, fromAnthropicContent, } from './anthropic.js';
|
|
5
|
-
export { AnthropicChatAdapter, } from './anthropic-chat.js';
|
|
6
|
-
export { AnthropicMultiuserAdapter, } from './anthropic-multiuser.js';
|
|
7
5
|
export { OpenRouterAdapter, toOpenRouterMessages, fromOpenRouterMessage, } from './openrouter.js';
|
|
8
6
|
export { OpenAIAdapter, toOpenAIContent, fromOpenAIContent, } from './openai.js';
|
|
9
7
|
export { OpenAICompatibleAdapter, toOpenAIMessages, fromOpenAIMessage, } from './openai-compatible.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GAErB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,GAEtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,GAElB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,wBAAwB,GAEzB,MAAM,yBAAyB,CAAC"}
|
package/package.json
CHANGED
package/src/providers/index.ts
CHANGED
|
@@ -9,16 +9,6 @@ export {
|
|
|
9
9
|
type AnthropicAdapterConfig,
|
|
10
10
|
} from './anthropic.js';
|
|
11
11
|
|
|
12
|
-
export {
|
|
13
|
-
AnthropicChatAdapter,
|
|
14
|
-
type AnthropicChatAdapterConfig,
|
|
15
|
-
} from './anthropic-chat.js';
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
AnthropicMultiuserAdapter,
|
|
19
|
-
type AnthropicMultiuserAdapterConfig,
|
|
20
|
-
} from './anthropic-multiuser.js';
|
|
21
|
-
|
|
22
12
|
export {
|
|
23
13
|
OpenRouterAdapter,
|
|
24
14
|
toOpenRouterMessages,
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Anthropic Chat Adapter - Simple two-party conversation
|
|
3
|
-
*
|
|
4
|
-
* For standard Human/Assistant conversations without multi-user support.
|
|
5
|
-
* - Strict participant validation (only configured human/assistant names allowed)
|
|
6
|
-
* - No participant names in messages (pure user/assistant roles)
|
|
7
|
-
* - Native Anthropic tool API
|
|
8
|
-
*
|
|
9
|
-
* Use AnthropicMultiuserAdapter for multi-party conversations.
|
|
10
|
-
*/
|
|
11
|
-
import type { ProviderAdapter, ProviderRequest, ProviderRequestOptions, ProviderResponse, StreamCallbacks } from '../types/index.js';
|
|
12
|
-
export interface AnthropicChatAdapterConfig {
|
|
13
|
-
/** API key (defaults to ANTHROPIC_API_KEY env var) */
|
|
14
|
-
apiKey?: string;
|
|
15
|
-
/** Base URL override */
|
|
16
|
-
baseURL?: string;
|
|
17
|
-
/** Default max tokens */
|
|
18
|
-
defaultMaxTokens?: number;
|
|
19
|
-
/**
|
|
20
|
-
* Human participant name (default: 'Human')
|
|
21
|
-
* Messages with this participant become 'user' role.
|
|
22
|
-
*/
|
|
23
|
-
humanParticipant?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Assistant participant name (default: 'Claude')
|
|
26
|
-
* Messages with this participant become 'assistant' role.
|
|
27
|
-
*/
|
|
28
|
-
assistantParticipant?: string;
|
|
29
|
-
}
|
|
30
|
-
export declare class AnthropicChatAdapter implements ProviderAdapter {
|
|
31
|
-
readonly name = "anthropic-chat";
|
|
32
|
-
private client;
|
|
33
|
-
private defaultMaxTokens;
|
|
34
|
-
private humanParticipant;
|
|
35
|
-
private assistantParticipant;
|
|
36
|
-
constructor(config?: AnthropicChatAdapterConfig);
|
|
37
|
-
supportsModel(modelId: string): boolean;
|
|
38
|
-
complete(request: ProviderRequest, options?: ProviderRequestOptions): Promise<ProviderResponse>;
|
|
39
|
-
stream(request: ProviderRequest, callbacks: StreamCallbacks, options?: ProviderRequestOptions): Promise<ProviderResponse>;
|
|
40
|
-
/**
|
|
41
|
-
* Convert normalized messages to Anthropic format.
|
|
42
|
-
* Validates that only configured human/assistant participants are used.
|
|
43
|
-
*/
|
|
44
|
-
private convertMessages;
|
|
45
|
-
private buildRequest;
|
|
46
|
-
private parseResponse;
|
|
47
|
-
private handleError;
|
|
48
|
-
private parseRetryAfter;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=anthropic-chat.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-chat.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAe3B,MAAM,WAAW,0BAA0B;IACzC,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,wBAAwB;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAMD,qBAAa,oBAAqB,YAAW,eAAe;IAC1D,QAAQ,CAAC,IAAI,oBAAoB;IACjC,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,oBAAoB,CAAS;gBAEzB,MAAM,GAAE,0BAA+B;IAUnD,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIjC,QAAQ,CACZ,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,gBAAgB,CAAC;IAgBtB,MAAM,CACV,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,eAAe,EAC1B,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,gBAAgB,CAAC;IA4C5B;;;OAGG;IACH,OAAO,CAAC,eAAe;IA0BvB,OAAO,CAAC,YAAY;IAqDpB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,WAAW;IAoCnB,OAAO,CAAC,eAAe;CAQxB"}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Anthropic Chat Adapter - Simple two-party conversation
|
|
3
|
-
*
|
|
4
|
-
* For standard Human/Assistant conversations without multi-user support.
|
|
5
|
-
* - Strict participant validation (only configured human/assistant names allowed)
|
|
6
|
-
* - No participant names in messages (pure user/assistant roles)
|
|
7
|
-
* - Native Anthropic tool API
|
|
8
|
-
*
|
|
9
|
-
* Use AnthropicMultiuserAdapter for multi-party conversations.
|
|
10
|
-
*/
|
|
11
|
-
import Anthropic from '@anthropic-ai/sdk';
|
|
12
|
-
import { MembraneError, rateLimitError, contextLengthError, authError, serverError, abortError, } from '../types/index.js';
|
|
13
|
-
import { toAnthropicContent, fromAnthropicContent } from './anthropic.js';
|
|
14
|
-
// ============================================================================
|
|
15
|
-
// Anthropic Chat Adapter
|
|
16
|
-
// ============================================================================
|
|
17
|
-
export class AnthropicChatAdapter {
|
|
18
|
-
name = 'anthropic-chat';
|
|
19
|
-
client;
|
|
20
|
-
defaultMaxTokens;
|
|
21
|
-
humanParticipant;
|
|
22
|
-
assistantParticipant;
|
|
23
|
-
constructor(config = {}) {
|
|
24
|
-
this.client = new Anthropic({
|
|
25
|
-
apiKey: config.apiKey,
|
|
26
|
-
baseURL: config.baseURL,
|
|
27
|
-
});
|
|
28
|
-
this.defaultMaxTokens = config.defaultMaxTokens ?? 4096;
|
|
29
|
-
this.humanParticipant = config.humanParticipant ?? 'Human';
|
|
30
|
-
this.assistantParticipant = config.assistantParticipant ?? 'Claude';
|
|
31
|
-
}
|
|
32
|
-
supportsModel(modelId) {
|
|
33
|
-
return modelId.startsWith('claude-');
|
|
34
|
-
}
|
|
35
|
-
async complete(request, options) {
|
|
36
|
-
const anthropicRequest = this.buildRequest(request);
|
|
37
|
-
const fullRequest = { ...anthropicRequest, stream: false };
|
|
38
|
-
options?.onRequest?.(fullRequest);
|
|
39
|
-
try {
|
|
40
|
-
const response = await this.client.messages.create(fullRequest, {
|
|
41
|
-
signal: options?.signal,
|
|
42
|
-
});
|
|
43
|
-
return this.parseResponse(response, fullRequest);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
throw this.handleError(error, fullRequest);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async stream(request, callbacks, options) {
|
|
50
|
-
const anthropicRequest = this.buildRequest(request);
|
|
51
|
-
const fullRequest = { ...anthropicRequest, stream: true };
|
|
52
|
-
options?.onRequest?.(fullRequest);
|
|
53
|
-
try {
|
|
54
|
-
const stream = await this.client.messages.stream(anthropicRequest, {
|
|
55
|
-
signal: options?.signal,
|
|
56
|
-
});
|
|
57
|
-
let accumulated = '';
|
|
58
|
-
const contentBlocks = [];
|
|
59
|
-
let currentBlockIndex = -1;
|
|
60
|
-
for await (const event of stream) {
|
|
61
|
-
if (event.type === 'content_block_start') {
|
|
62
|
-
currentBlockIndex = event.index;
|
|
63
|
-
contentBlocks[currentBlockIndex] = event.content_block;
|
|
64
|
-
callbacks.onContentBlock?.(currentBlockIndex, event.content_block);
|
|
65
|
-
}
|
|
66
|
-
else if (event.type === 'content_block_delta') {
|
|
67
|
-
if (event.delta.type === 'text_delta') {
|
|
68
|
-
const chunk = event.delta.text;
|
|
69
|
-
accumulated += chunk;
|
|
70
|
-
callbacks.onChunk(chunk);
|
|
71
|
-
}
|
|
72
|
-
else if (event.delta.type === 'thinking_delta') {
|
|
73
|
-
callbacks.onChunk(event.delta.thinking);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
else if (event.type === 'content_block_stop') {
|
|
77
|
-
callbacks.onContentBlock?.(currentBlockIndex, contentBlocks[currentBlockIndex]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const finalMessage = await stream.finalMessage();
|
|
81
|
-
return this.parseResponse(finalMessage, fullRequest);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw this.handleError(error, fullRequest);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// ============================================================================
|
|
88
|
-
// Message Conversion
|
|
89
|
-
// ============================================================================
|
|
90
|
-
/**
|
|
91
|
-
* Convert normalized messages to Anthropic format.
|
|
92
|
-
* Validates that only configured human/assistant participants are used.
|
|
93
|
-
*/
|
|
94
|
-
convertMessages(messages) {
|
|
95
|
-
const result = [];
|
|
96
|
-
for (const msg of messages) {
|
|
97
|
-
// Validate participant
|
|
98
|
-
if (msg.participant !== this.humanParticipant && msg.participant !== this.assistantParticipant) {
|
|
99
|
-
throw new MembraneError({
|
|
100
|
-
type: 'invalid_request',
|
|
101
|
-
message: `AnthropicChatAdapter only supports two participants: "${this.humanParticipant}" and "${this.assistantParticipant}". ` +
|
|
102
|
-
`Got: "${msg.participant}". Use AnthropicMultiuserAdapter for multi-party conversations.`,
|
|
103
|
-
retryable: false,
|
|
104
|
-
rawError: new Error(`Invalid participant: ${msg.participant}`),
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const role = msg.participant === this.humanParticipant ? 'user' : 'assistant';
|
|
108
|
-
const content = toAnthropicContent(msg.content);
|
|
109
|
-
result.push({ role, content });
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
buildRequest(request) {
|
|
114
|
-
// Get normalized messages from extra (preferred) or fall back to provider messages
|
|
115
|
-
const normalizedMessages = request.extra?.normalizedMessages;
|
|
116
|
-
let messages;
|
|
117
|
-
if (normalizedMessages) {
|
|
118
|
-
messages = this.convertMessages(normalizedMessages);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// Assume already in provider format
|
|
122
|
-
messages = request.messages;
|
|
123
|
-
}
|
|
124
|
-
const params = {
|
|
125
|
-
model: request.model,
|
|
126
|
-
max_tokens: request.maxTokens || this.defaultMaxTokens,
|
|
127
|
-
messages,
|
|
128
|
-
};
|
|
129
|
-
// Handle system prompt
|
|
130
|
-
if (request.system) {
|
|
131
|
-
if (typeof request.system === 'string') {
|
|
132
|
-
params.system = request.system;
|
|
133
|
-
}
|
|
134
|
-
else if (Array.isArray(request.system)) {
|
|
135
|
-
params.system = request.system;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (request.temperature !== undefined) {
|
|
139
|
-
params.temperature = request.temperature;
|
|
140
|
-
}
|
|
141
|
-
if (request.stopSequences && request.stopSequences.length > 0) {
|
|
142
|
-
params.stop_sequences = request.stopSequences;
|
|
143
|
-
}
|
|
144
|
-
if (request.tools && request.tools.length > 0) {
|
|
145
|
-
params.tools = request.tools;
|
|
146
|
-
}
|
|
147
|
-
// Handle extended thinking
|
|
148
|
-
if (request.thinking) {
|
|
149
|
-
params.thinking = request.thinking;
|
|
150
|
-
}
|
|
151
|
-
// Apply extra params (excluding normalizedMessages)
|
|
152
|
-
if (request.extra) {
|
|
153
|
-
const { normalizedMessages: _, ...rest } = request.extra;
|
|
154
|
-
Object.assign(params, rest);
|
|
155
|
-
}
|
|
156
|
-
return params;
|
|
157
|
-
}
|
|
158
|
-
parseResponse(response, rawRequest) {
|
|
159
|
-
return {
|
|
160
|
-
content: fromAnthropicContent(response.content),
|
|
161
|
-
stopReason: response.stop_reason ?? 'end_turn',
|
|
162
|
-
stopSequence: response.stop_sequence ?? undefined,
|
|
163
|
-
usage: {
|
|
164
|
-
inputTokens: response.usage.input_tokens,
|
|
165
|
-
outputTokens: response.usage.output_tokens,
|
|
166
|
-
cacheCreationTokens: response.usage.cache_creation_input_tokens,
|
|
167
|
-
cacheReadTokens: response.usage.cache_read_input_tokens,
|
|
168
|
-
},
|
|
169
|
-
model: response.model,
|
|
170
|
-
rawRequest,
|
|
171
|
-
raw: response,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
handleError(error, rawRequest) {
|
|
175
|
-
if (error instanceof Anthropic.APIError) {
|
|
176
|
-
const status = error.status;
|
|
177
|
-
const message = error.message;
|
|
178
|
-
if (status === 429) {
|
|
179
|
-
const retryAfter = this.parseRetryAfter(error);
|
|
180
|
-
return rateLimitError(message, retryAfter, error, rawRequest);
|
|
181
|
-
}
|
|
182
|
-
if (status === 401) {
|
|
183
|
-
return authError(message, error, rawRequest);
|
|
184
|
-
}
|
|
185
|
-
if (message.includes('context') || message.includes('too long')) {
|
|
186
|
-
return contextLengthError(message, error, rawRequest);
|
|
187
|
-
}
|
|
188
|
-
if (status >= 500) {
|
|
189
|
-
return serverError(message, status, error, rawRequest);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
193
|
-
return abortError(undefined, rawRequest);
|
|
194
|
-
}
|
|
195
|
-
return new MembraneError({
|
|
196
|
-
type: 'unknown',
|
|
197
|
-
message: error instanceof Error ? error.message : String(error),
|
|
198
|
-
retryable: false,
|
|
199
|
-
rawError: error,
|
|
200
|
-
rawRequest,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
parseRetryAfter(error) {
|
|
204
|
-
const message = error.message;
|
|
205
|
-
const match = message.match(/retry after (\d+)/i);
|
|
206
|
-
if (match && match[1]) {
|
|
207
|
-
return parseInt(match[1], 10) * 1000;
|
|
208
|
-
}
|
|
209
|
-
return undefined;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
//# sourceMappingURL=anthropic-chat.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-chat.js","sourceRoot":"","sources":["../../src/providers/anthropic-chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAS1C,OAAO,EACL,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AA6B1E,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E,MAAM,OAAO,oBAAoB;IACtB,IAAI,GAAG,gBAAgB,CAAC;IACzB,MAAM,CAAY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AAoB,CAAC,CAAC;QAClD,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC;QACvC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Anthropic Multiuser Adapter - Multi-party conversation support
|
|
3
|
-
*
|
|
4
|
-
* For conversations with multiple participants (e.g., group chats, Discord).
|
|
5
|
-
* - All non-bot participants map to 'user' role
|
|
6
|
-
* - Bot participant maps to 'assistant' role
|
|
7
|
-
* - Prefixes messages with participant names for context
|
|
8
|
-
* - Native Anthropic tool API
|
|
9
|
-
*
|
|
10
|
-
* Use AnthropicChatAdapter for simple two-party Human/Assistant conversations.
|
|
11
|
-
*/
|
|
12
|
-
import type { ProviderAdapter, ProviderRequest, ProviderRequestOptions, ProviderResponse, StreamCallbacks } from '../types/index.js';
|
|
13
|
-
export interface AnthropicMultiuserAdapterConfig {
|
|
14
|
-
/** API key (defaults to ANTHROPIC_API_KEY env var) */
|
|
15
|
-
apiKey?: string;
|
|
16
|
-
/** Base URL override */
|
|
17
|
-
baseURL?: string;
|
|
18
|
-
/** Default max tokens */
|
|
19
|
-
defaultMaxTokens?: number;
|
|
20
|
-
/**
|
|
21
|
-
* Bot/assistant participant name (default: 'Claude')
|
|
22
|
-
* Messages with this participant become 'assistant' role (no name prefix).
|
|
23
|
-
*/
|
|
24
|
-
assistantParticipant?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Whether to prefix user messages with participant names (default: true)
|
|
27
|
-
* When true: "Alice: Hello there"
|
|
28
|
-
* When false: "Hello there"
|
|
29
|
-
*/
|
|
30
|
-
includeParticipantNames?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Format for participant name prefix (default: '{name}: ')
|
|
33
|
-
* Use {name} as placeholder for participant name.
|
|
34
|
-
*/
|
|
35
|
-
nameFormat?: string;
|
|
36
|
-
}
|
|
37
|
-
export declare class AnthropicMultiuserAdapter implements ProviderAdapter {
|
|
38
|
-
readonly name = "anthropic-multiuser";
|
|
39
|
-
private client;
|
|
40
|
-
private defaultMaxTokens;
|
|
41
|
-
private assistantParticipant;
|
|
42
|
-
private includeParticipantNames;
|
|
43
|
-
private nameFormat;
|
|
44
|
-
constructor(config?: AnthropicMultiuserAdapterConfig);
|
|
45
|
-
supportsModel(modelId: string): boolean;
|
|
46
|
-
complete(request: ProviderRequest, options?: ProviderRequestOptions): Promise<ProviderResponse>;
|
|
47
|
-
stream(request: ProviderRequest, callbacks: StreamCallbacks, options?: ProviderRequestOptions): Promise<ProviderResponse>;
|
|
48
|
-
/**
|
|
49
|
-
* Convert normalized messages to Anthropic format.
|
|
50
|
-
* - Bot messages become assistant role
|
|
51
|
-
* - All other messages become user role with optional name prefix
|
|
52
|
-
*/
|
|
53
|
-
private convertMessages;
|
|
54
|
-
/**
|
|
55
|
-
* Merge consecutive messages with the same role.
|
|
56
|
-
* Anthropic API requires strictly alternating user/assistant messages.
|
|
57
|
-
*/
|
|
58
|
-
private mergeConsecutiveRoles;
|
|
59
|
-
private buildRequest;
|
|
60
|
-
private parseResponse;
|
|
61
|
-
private handleError;
|
|
62
|
-
private parseRetryAfter;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=anthropic-multiuser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-multiuser.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic-multiuser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EAEhB,MAAM,mBAAmB,CAAC;AAe3B,MAAM,WAAW,+BAA+B;IAC9C,sDAAsD;IACtD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,wBAAw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