@jonab/azure-ai-sdk 0.5.17
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/README.md +2 -0
- package/dist/adapters/anthropic-adapter.d.ts +172 -0
- package/dist/adapters/anthropic-adapter.d.ts.map +1 -0
- package/dist/adapters/anthropic-adapter.js +394 -0
- package/dist/adapters/anthropic-adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +15 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +85 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/openai-adapter.d.ts +180 -0
- package/dist/adapters/openai-adapter.d.ts.map +1 -0
- package/dist/adapters/openai-adapter.js +363 -0
- package/dist/adapters/openai-adapter.js.map +1 -0
- package/dist/adapters/openai-legacy-adapter.d.ts +70 -0
- package/dist/adapters/openai-legacy-adapter.d.ts.map +1 -0
- package/dist/adapters/openai-legacy-adapter.js +38 -0
- package/dist/adapters/openai-legacy-adapter.js.map +1 -0
- package/dist/adapters/types.d.ts +109 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +2 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/azure-foundry-chat-language-model.d.ts +37 -0
- package/dist/azure-foundry-chat-language-model.d.ts.map +1 -0
- package/dist/azure-foundry-chat-language-model.js +119 -0
- package/dist/azure-foundry-chat-language-model.js.map +1 -0
- package/dist/azure-foundry-chat-options.d.ts +34 -0
- package/dist/azure-foundry-chat-options.d.ts.map +1 -0
- package/dist/azure-foundry-chat-options.js +2 -0
- package/dist/azure-foundry-chat-options.js.map +1 -0
- package/dist/azure-foundry-error.d.ts +12 -0
- package/dist/azure-foundry-error.d.ts.map +1 -0
- package/dist/azure-foundry-error.js +15 -0
- package/dist/azure-foundry-error.js.map +1 -0
- package/dist/azure-foundry-provider.d.ts +239 -0
- package/dist/azure-foundry-provider.d.ts.map +1 -0
- package/dist/azure-foundry-provider.js +263 -0
- package/dist/azure-foundry-provider.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { LanguageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
|
|
2
|
+
import { ParseResult } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ChatAdapter, ParsedResponse, ParsedStreamChunk } from './types.js';
|
|
5
|
+
export declare const anthropicResponseSchema: z.ZodObject<{
|
|
6
|
+
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
7
|
+
type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
8
|
+
role: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
9
|
+
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"text">;
|
|
11
|
+
text: z.ZodString;
|
|
12
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"tool_use">;
|
|
14
|
+
id: z.ZodString;
|
|
15
|
+
name: z.ZodString;
|
|
16
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
17
|
+
}, z.core.$strip>]>>;
|
|
18
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
19
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
stop_sequence: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
22
|
+
input_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
23
|
+
output_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
24
|
+
}, z.core.$strip>>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
declare const anthropicChunkSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"message_start">;
|
|
28
|
+
message: z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
type: z.ZodString;
|
|
31
|
+
role: z.ZodString;
|
|
32
|
+
content: z.ZodArray<z.ZodUnknown>;
|
|
33
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
34
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
35
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
36
|
+
input_tokens: z.ZodNumber;
|
|
37
|
+
output_tokens: z.ZodNumber;
|
|
38
|
+
}, z.core.$strip>>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
41
|
+
type: z.ZodLiteral<"content_block_start">;
|
|
42
|
+
index: z.ZodNumber;
|
|
43
|
+
content_block: z.ZodObject<{
|
|
44
|
+
type: z.ZodString;
|
|
45
|
+
text: z.ZodOptional<z.ZodString>;
|
|
46
|
+
id: z.ZodOptional<z.ZodString>;
|
|
47
|
+
name: z.ZodOptional<z.ZodString>;
|
|
48
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
51
|
+
type: z.ZodLiteral<"content_block_delta">;
|
|
52
|
+
index: z.ZodNumber;
|
|
53
|
+
delta: z.ZodUnion<readonly [z.ZodObject<{
|
|
54
|
+
type: z.ZodLiteral<"text_delta">;
|
|
55
|
+
text: z.ZodString;
|
|
56
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
57
|
+
type: z.ZodLiteral<"input_json_delta">;
|
|
58
|
+
partial_json: z.ZodString;
|
|
59
|
+
}, z.core.$strip>]>;
|
|
60
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
61
|
+
type: z.ZodLiteral<"content_block_stop">;
|
|
62
|
+
index: z.ZodNumber;
|
|
63
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
64
|
+
type: z.ZodLiteral<"message_delta">;
|
|
65
|
+
delta: z.ZodObject<{
|
|
66
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
67
|
+
stop_sequence: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
70
|
+
output_tokens: z.ZodNumber;
|
|
71
|
+
}, z.core.$strip>>>;
|
|
72
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
73
|
+
type: z.ZodLiteral<"message_stop">;
|
|
74
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
75
|
+
type: z.ZodLiteral<"ping">;
|
|
76
|
+
}, z.core.$strip>]>;
|
|
77
|
+
type AnthropicResponse = z.infer<typeof anthropicResponseSchema>;
|
|
78
|
+
type AnthropicChunk = z.infer<typeof anthropicChunkSchema>;
|
|
79
|
+
export declare class AnthropicAdapter implements ChatAdapter<AnthropicResponse, AnthropicChunk> {
|
|
80
|
+
readonly responseSchema: z.ZodObject<{
|
|
81
|
+
id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
82
|
+
type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
83
|
+
role: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
84
|
+
content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
85
|
+
type: z.ZodLiteral<"text">;
|
|
86
|
+
text: z.ZodString;
|
|
87
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
88
|
+
type: z.ZodLiteral<"tool_use">;
|
|
89
|
+
id: z.ZodString;
|
|
90
|
+
name: z.ZodString;
|
|
91
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
92
|
+
}, z.core.$strip>]>>;
|
|
93
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
94
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
95
|
+
stop_sequence: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
96
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
97
|
+
input_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
98
|
+
output_tokens: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
99
|
+
}, z.core.$strip>>>;
|
|
100
|
+
}, z.core.$strip>;
|
|
101
|
+
readonly chunkSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
102
|
+
type: z.ZodLiteral<"message_start">;
|
|
103
|
+
message: z.ZodObject<{
|
|
104
|
+
id: z.ZodString;
|
|
105
|
+
type: z.ZodString;
|
|
106
|
+
role: z.ZodString;
|
|
107
|
+
content: z.ZodArray<z.ZodUnknown>;
|
|
108
|
+
model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
109
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
110
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
111
|
+
input_tokens: z.ZodNumber;
|
|
112
|
+
output_tokens: z.ZodNumber;
|
|
113
|
+
}, z.core.$strip>>>;
|
|
114
|
+
}, z.core.$strip>;
|
|
115
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
116
|
+
type: z.ZodLiteral<"content_block_start">;
|
|
117
|
+
index: z.ZodNumber;
|
|
118
|
+
content_block: z.ZodObject<{
|
|
119
|
+
type: z.ZodString;
|
|
120
|
+
text: z.ZodOptional<z.ZodString>;
|
|
121
|
+
id: z.ZodOptional<z.ZodString>;
|
|
122
|
+
name: z.ZodOptional<z.ZodString>;
|
|
123
|
+
input: z.ZodOptional<z.ZodUnknown>;
|
|
124
|
+
}, z.core.$strip>;
|
|
125
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
+
type: z.ZodLiteral<"content_block_delta">;
|
|
127
|
+
index: z.ZodNumber;
|
|
128
|
+
delta: z.ZodUnion<readonly [z.ZodObject<{
|
|
129
|
+
type: z.ZodLiteral<"text_delta">;
|
|
130
|
+
text: z.ZodString;
|
|
131
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
132
|
+
type: z.ZodLiteral<"input_json_delta">;
|
|
133
|
+
partial_json: z.ZodString;
|
|
134
|
+
}, z.core.$strip>]>;
|
|
135
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
136
|
+
type: z.ZodLiteral<"content_block_stop">;
|
|
137
|
+
index: z.ZodNumber;
|
|
138
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
139
|
+
type: z.ZodLiteral<"message_delta">;
|
|
140
|
+
delta: z.ZodObject<{
|
|
141
|
+
stop_reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
142
|
+
stop_sequence: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
usage: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
145
|
+
output_tokens: z.ZodNumber;
|
|
146
|
+
}, z.core.$strip>>>;
|
|
147
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
148
|
+
type: z.ZodLiteral<"message_stop">;
|
|
149
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
150
|
+
type: z.ZodLiteral<"ping">;
|
|
151
|
+
}, z.core.$strip>]>;
|
|
152
|
+
readonly urlSuffix = "/anthropic/v1/messages";
|
|
153
|
+
readonly additionalHeaders: {
|
|
154
|
+
'anthropic-version': string;
|
|
155
|
+
};
|
|
156
|
+
private finishReason;
|
|
157
|
+
private inputTokens;
|
|
158
|
+
private outputTokens;
|
|
159
|
+
private readonly toolCallAccumulators;
|
|
160
|
+
private readonly openTextIds;
|
|
161
|
+
private readonly generateId;
|
|
162
|
+
constructor(generateId: () => string);
|
|
163
|
+
buildRequest(options: LanguageModelV3CallOptions, modelId: string, modelInBody: boolean): {
|
|
164
|
+
body: Record<string, unknown>;
|
|
165
|
+
warnings: SharedV3Warning[];
|
|
166
|
+
};
|
|
167
|
+
parseResponse(raw: AnthropicResponse): ParsedResponse;
|
|
168
|
+
parseChunk(chunk: ParseResult<AnthropicChunk>): ParsedStreamChunk[];
|
|
169
|
+
flush(): ParsedStreamChunk[];
|
|
170
|
+
}
|
|
171
|
+
export {};
|
|
172
|
+
//# sourceMappingURL=anthropic-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/anthropic-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAG1B,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAuC5E,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;iBAclC,CAAC;AAoEH,QAAA,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAQxB,CAAC;AAEH,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACjE,KAAK,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAgK3D,qBAAa,gBAAiB,YAAW,WAAW,CAAC,iBAAiB,EAAE,cAAc,CAAC;IACrF,QAAQ,CAAC,cAAc;;;;;;;;;;;;;;;;;;;;sBAA2B;IAClD,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAAwB;IAG5C,QAAQ,CAAC,SAAS,4BAA4B;IAG9C,QAAQ,CAAC,iBAAiB;;MAAyC;IACnE,OAAO,CAAC,YAAY,CAAqE;IACzF,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAGjC;IACJ,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;gBAE9B,UAAU,EAAE,MAAM,MAAM;IAIpC,YAAY,CACV,OAAO,EAAE,0BAA0B,EACnC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,OAAO,GACnB;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;KAAE;IAyBjE,aAAa,CAAC,GAAG,EAAE,iBAAiB,GAAG,cAAc;IA0BrD,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc,CAAC,GAAG,iBAAiB,EAAE;IAiFnE,KAAK,IAAI,iBAAiB,EAAE;CAoB7B"}
|
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Zod schemas
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
const textContentBlockSchema = z.object({
|
|
6
|
+
type: z.literal('text'),
|
|
7
|
+
text: z.string(),
|
|
8
|
+
});
|
|
9
|
+
const toolUseContentBlockSchema = z.object({
|
|
10
|
+
type: z.literal('tool_use'),
|
|
11
|
+
id: z.string(),
|
|
12
|
+
name: z.string(),
|
|
13
|
+
input: z.record(z.string(), z.unknown()),
|
|
14
|
+
});
|
|
15
|
+
const contentBlockSchema = z.union([textContentBlockSchema, toolUseContentBlockSchema]);
|
|
16
|
+
export const anthropicResponseSchema = z.object({
|
|
17
|
+
id: z.string().nullish(),
|
|
18
|
+
type: z.string().nullish(),
|
|
19
|
+
role: z.string().nullish(),
|
|
20
|
+
content: z.array(contentBlockSchema),
|
|
21
|
+
model: z.string().nullish(),
|
|
22
|
+
stop_reason: z.string().nullish(),
|
|
23
|
+
stop_sequence: z.string().nullish(),
|
|
24
|
+
usage: z
|
|
25
|
+
.object({
|
|
26
|
+
input_tokens: z.number().nullish(),
|
|
27
|
+
output_tokens: z.number().nullish(),
|
|
28
|
+
})
|
|
29
|
+
.nullish(),
|
|
30
|
+
});
|
|
31
|
+
// Anthropic streaming uses Server-Sent Events with different message types
|
|
32
|
+
const anthropicStreamMessageStartSchema = z.object({
|
|
33
|
+
type: z.literal('message_start'),
|
|
34
|
+
message: z.object({
|
|
35
|
+
id: z.string(),
|
|
36
|
+
type: z.string(),
|
|
37
|
+
role: z.string(),
|
|
38
|
+
content: z.array(z.unknown()),
|
|
39
|
+
model: z.string().nullish(),
|
|
40
|
+
stop_reason: z.string().nullish(),
|
|
41
|
+
usage: z
|
|
42
|
+
.object({
|
|
43
|
+
input_tokens: z.number(),
|
|
44
|
+
output_tokens: z.number(),
|
|
45
|
+
})
|
|
46
|
+
.nullish(),
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
const anthropicStreamContentBlockStartSchema = z.object({
|
|
50
|
+
type: z.literal('content_block_start'),
|
|
51
|
+
index: z.number(),
|
|
52
|
+
content_block: z.object({
|
|
53
|
+
type: z.string(),
|
|
54
|
+
text: z.string().optional(),
|
|
55
|
+
id: z.string().optional(),
|
|
56
|
+
name: z.string().optional(),
|
|
57
|
+
input: z.unknown().optional(),
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
const anthropicStreamContentBlockDeltaSchema = z.object({
|
|
61
|
+
type: z.literal('content_block_delta'),
|
|
62
|
+
index: z.number(),
|
|
63
|
+
delta: z.union([
|
|
64
|
+
z.object({ type: z.literal('text_delta'), text: z.string() }),
|
|
65
|
+
z.object({ type: z.literal('input_json_delta'), partial_json: z.string() }),
|
|
66
|
+
]),
|
|
67
|
+
});
|
|
68
|
+
const anthropicStreamContentBlockStopSchema = z.object({
|
|
69
|
+
type: z.literal('content_block_stop'),
|
|
70
|
+
index: z.number(),
|
|
71
|
+
});
|
|
72
|
+
const anthropicStreamMessageDeltaSchema = z.object({
|
|
73
|
+
type: z.literal('message_delta'),
|
|
74
|
+
delta: z.object({
|
|
75
|
+
stop_reason: z.string().nullish(),
|
|
76
|
+
stop_sequence: z.string().nullish(),
|
|
77
|
+
}),
|
|
78
|
+
usage: z
|
|
79
|
+
.object({
|
|
80
|
+
output_tokens: z.number(),
|
|
81
|
+
})
|
|
82
|
+
.nullish(),
|
|
83
|
+
});
|
|
84
|
+
const anthropicStreamMessageStopSchema = z.object({
|
|
85
|
+
type: z.literal('message_stop'),
|
|
86
|
+
});
|
|
87
|
+
const anthropicStreamPingSchema = z.object({
|
|
88
|
+
type: z.literal('ping'),
|
|
89
|
+
});
|
|
90
|
+
const anthropicChunkSchema = z.union([
|
|
91
|
+
anthropicStreamMessageStartSchema,
|
|
92
|
+
anthropicStreamContentBlockStartSchema,
|
|
93
|
+
anthropicStreamContentBlockDeltaSchema,
|
|
94
|
+
anthropicStreamContentBlockStopSchema,
|
|
95
|
+
anthropicStreamMessageDeltaSchema,
|
|
96
|
+
anthropicStreamMessageStopSchema,
|
|
97
|
+
anthropicStreamPingSchema,
|
|
98
|
+
]);
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Shared helpers
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
function mapFinishReason(reason) {
|
|
103
|
+
const raw = reason ?? undefined;
|
|
104
|
+
const unified = (() => {
|
|
105
|
+
switch (reason) {
|
|
106
|
+
case 'end_turn': return 'stop';
|
|
107
|
+
case 'max_tokens': return 'length';
|
|
108
|
+
case 'tool_use': return 'tool-calls';
|
|
109
|
+
case 'stop_sequence': return 'stop';
|
|
110
|
+
default: return 'other';
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
return { unified, raw };
|
|
114
|
+
}
|
|
115
|
+
function convertToAnthropicMessages(prompt) {
|
|
116
|
+
const messages = [];
|
|
117
|
+
let systemPrompt;
|
|
118
|
+
for (const message of prompt) {
|
|
119
|
+
switch (message.role) {
|
|
120
|
+
case 'system': {
|
|
121
|
+
// Anthropic expects system as a separate parameter, not a message
|
|
122
|
+
systemPrompt = message.content;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case 'user': {
|
|
126
|
+
const content = [];
|
|
127
|
+
for (const part of message.content) {
|
|
128
|
+
if (part.type === 'text') {
|
|
129
|
+
content.push({ type: 'text', text: part.text });
|
|
130
|
+
}
|
|
131
|
+
else if (part.type === 'file') {
|
|
132
|
+
const { data, mediaType } = part;
|
|
133
|
+
// Anthropic supports images via base64 URLs
|
|
134
|
+
if (mediaType.startsWith('image/')) {
|
|
135
|
+
let base64Data;
|
|
136
|
+
if (data instanceof URL) {
|
|
137
|
+
// For URLs, we'd need to fetch them; for now, treat as external
|
|
138
|
+
content.push({ type: 'text', text: `[Image URL: ${data.href}]` });
|
|
139
|
+
}
|
|
140
|
+
else if (typeof data === 'string') {
|
|
141
|
+
base64Data = data;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
base64Data = Buffer.from(data).toString('base64');
|
|
145
|
+
}
|
|
146
|
+
if (typeof data !== 'string' && !(data instanceof URL)) {
|
|
147
|
+
// Image blocks would go here, but Anthropic's model format differs
|
|
148
|
+
content.push({ type: 'text', text: `[Image: ${mediaType}]` });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
messages.push({ role: 'user', content });
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case 'assistant': {
|
|
157
|
+
const content = [];
|
|
158
|
+
let textContent = '';
|
|
159
|
+
for (const part of message.content) {
|
|
160
|
+
switch (part.type) {
|
|
161
|
+
case 'text':
|
|
162
|
+
textContent += part.text;
|
|
163
|
+
break;
|
|
164
|
+
case 'tool-call':
|
|
165
|
+
if (textContent) {
|
|
166
|
+
content.push({ type: 'text', text: textContent });
|
|
167
|
+
textContent = '';
|
|
168
|
+
}
|
|
169
|
+
content.push({
|
|
170
|
+
type: 'tool_use',
|
|
171
|
+
id: part.toolCallId,
|
|
172
|
+
name: part.toolName,
|
|
173
|
+
input: typeof part.input === 'string' ? JSON.parse(part.input) : part.input,
|
|
174
|
+
});
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (textContent) {
|
|
179
|
+
content.push({ type: 'text', text: textContent });
|
|
180
|
+
}
|
|
181
|
+
messages.push({ role: 'assistant', content });
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case 'tool': {
|
|
185
|
+
for (const part of message.content) {
|
|
186
|
+
if (part.type !== 'tool-result')
|
|
187
|
+
continue;
|
|
188
|
+
const content = toolResultToString(part.output);
|
|
189
|
+
messages.push({
|
|
190
|
+
role: 'user',
|
|
191
|
+
content: [
|
|
192
|
+
{
|
|
193
|
+
type: 'text',
|
|
194
|
+
text: `Tool result from ${part.toolCallId}: ${content}`,
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { messages, system: systemPrompt };
|
|
204
|
+
}
|
|
205
|
+
function toolResultToString(output) {
|
|
206
|
+
if (output.type === 'text' || output.type === 'error-text') {
|
|
207
|
+
return String(output.value ?? '');
|
|
208
|
+
}
|
|
209
|
+
if (output.type === 'json' || output.type === 'error-json') {
|
|
210
|
+
return JSON.stringify(output.value);
|
|
211
|
+
}
|
|
212
|
+
if (output.type === 'content' && Array.isArray(output.value)) {
|
|
213
|
+
return output.value
|
|
214
|
+
.map((p) => p.text ?? '')
|
|
215
|
+
.join('');
|
|
216
|
+
}
|
|
217
|
+
return JSON.stringify(output);
|
|
218
|
+
}
|
|
219
|
+
function buildTools(options) {
|
|
220
|
+
const warnings = [];
|
|
221
|
+
let tools;
|
|
222
|
+
if (options.topK != null)
|
|
223
|
+
warnings.push({ type: 'unsupported', feature: 'topK' });
|
|
224
|
+
if (options.presencePenalty != null)
|
|
225
|
+
warnings.push({ type: 'unsupported', feature: 'presencePenalty' });
|
|
226
|
+
if (options.frequencyPenalty != null)
|
|
227
|
+
warnings.push({ type: 'unsupported', feature: 'frequencyPenalty' });
|
|
228
|
+
if (options.tools && options.tools.length > 0) {
|
|
229
|
+
tools = options.tools
|
|
230
|
+
.filter((t) => t.type === 'function')
|
|
231
|
+
.map((t) => ({
|
|
232
|
+
name: t.name,
|
|
233
|
+
description: t.description,
|
|
234
|
+
input_schema: t.inputSchema,
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
return { tools, warnings };
|
|
238
|
+
}
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
// Anthropic adapter (Messages API for Azure Foundry)
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
export class AnthropicAdapter {
|
|
243
|
+
responseSchema = anthropicResponseSchema;
|
|
244
|
+
chunkSchema = anthropicChunkSchema;
|
|
245
|
+
// Anthropic Messages API path — overrides the default '/chat/completions'
|
|
246
|
+
urlSuffix = '/anthropic/v1/messages';
|
|
247
|
+
// Required by the Anthropic API
|
|
248
|
+
additionalHeaders = { 'anthropic-version': '2023-06-01' };
|
|
249
|
+
finishReason = { unified: 'other', raw: undefined };
|
|
250
|
+
inputTokens;
|
|
251
|
+
outputTokens;
|
|
252
|
+
toolCallAccumulators = new Map();
|
|
253
|
+
openTextIds = new Set();
|
|
254
|
+
generateId;
|
|
255
|
+
constructor(generateId) {
|
|
256
|
+
this.generateId = generateId;
|
|
257
|
+
}
|
|
258
|
+
buildRequest(options, modelId, modelInBody) {
|
|
259
|
+
const { tools, warnings } = buildTools(options);
|
|
260
|
+
const { messages, system } = convertToAnthropicMessages(options.prompt);
|
|
261
|
+
// Suppress temperature/top_p of 0
|
|
262
|
+
const explicitTemperature = options.temperature !== 0 ? options.temperature : undefined;
|
|
263
|
+
const explicitTopP = options.topP !== 0 ? options.topP : undefined;
|
|
264
|
+
const body = {
|
|
265
|
+
...(modelInBody ? { model: modelId } : {}),
|
|
266
|
+
messages,
|
|
267
|
+
max_tokens: options.maxOutputTokens ?? 4096,
|
|
268
|
+
temperature: explicitTemperature,
|
|
269
|
+
top_p: explicitTopP,
|
|
270
|
+
...(system ? { system } : {}),
|
|
271
|
+
...(tools != null ? { tools } : {}),
|
|
272
|
+
};
|
|
273
|
+
for (const key of Object.keys(body)) {
|
|
274
|
+
if (body[key] === undefined)
|
|
275
|
+
delete body[key];
|
|
276
|
+
}
|
|
277
|
+
return { body, warnings };
|
|
278
|
+
}
|
|
279
|
+
parseResponse(raw) {
|
|
280
|
+
const content = [];
|
|
281
|
+
for (const block of raw.content) {
|
|
282
|
+
if (block.type === 'text') {
|
|
283
|
+
content.push({ type: 'text', text: block.text });
|
|
284
|
+
}
|
|
285
|
+
else if (block.type === 'tool_use') {
|
|
286
|
+
content.push({
|
|
287
|
+
type: 'tool-call',
|
|
288
|
+
toolCallId: block.id,
|
|
289
|
+
toolName: block.name,
|
|
290
|
+
input: JSON.stringify(block.input),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
content,
|
|
296
|
+
finishReason: mapFinishReason(raw.stop_reason),
|
|
297
|
+
usage: {
|
|
298
|
+
inputTokens: raw.usage?.input_tokens ?? undefined,
|
|
299
|
+
outputTokens: raw.usage?.output_tokens ?? undefined,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
parseChunk(chunk) {
|
|
304
|
+
if (!chunk.success)
|
|
305
|
+
return [{ type: 'error', error: chunk.error }];
|
|
306
|
+
const parts = [];
|
|
307
|
+
const value = chunk.value;
|
|
308
|
+
switch (value.type) {
|
|
309
|
+
case 'message_start': {
|
|
310
|
+
if (value.message.usage) {
|
|
311
|
+
this.inputTokens = value.message.usage.input_tokens;
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case 'content_block_start': {
|
|
316
|
+
const idx = value.index;
|
|
317
|
+
if (value.content_block.type === 'text') {
|
|
318
|
+
const textId = `text-${idx}`;
|
|
319
|
+
this.openTextIds.add(textId);
|
|
320
|
+
parts.push({ type: 'text-start', id: textId });
|
|
321
|
+
}
|
|
322
|
+
else if (value.content_block.type === 'tool_use') {
|
|
323
|
+
const toolId = value.content_block.id ?? this.generateId();
|
|
324
|
+
const toolName = value.content_block.name ?? '';
|
|
325
|
+
this.toolCallAccumulators.set(idx, {
|
|
326
|
+
id: toolId,
|
|
327
|
+
name: toolName,
|
|
328
|
+
inputJson: '',
|
|
329
|
+
});
|
|
330
|
+
parts.push({ type: 'tool-input-start', id: toolId, toolName });
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
case 'content_block_delta': {
|
|
335
|
+
const idx = value.index;
|
|
336
|
+
const delta = value.delta;
|
|
337
|
+
if (delta.type === 'text_delta') {
|
|
338
|
+
const textId = `text-${idx}`;
|
|
339
|
+
parts.push({ type: 'text-delta', id: textId, delta: delta.text });
|
|
340
|
+
}
|
|
341
|
+
else if (delta.type === 'input_json_delta') {
|
|
342
|
+
const acc = this.toolCallAccumulators.get(idx);
|
|
343
|
+
if (acc) {
|
|
344
|
+
acc.inputJson += delta.partial_json;
|
|
345
|
+
parts.push({ type: 'tool-input-delta', id: acc.id, delta: delta.partial_json });
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case 'content_block_stop': {
|
|
351
|
+
const idx = value.index;
|
|
352
|
+
const acc = this.toolCallAccumulators.get(idx);
|
|
353
|
+
if (acc) {
|
|
354
|
+
const textId = `text-${idx}`;
|
|
355
|
+
if (this.openTextIds.has(textId)) {
|
|
356
|
+
parts.push({ type: 'text-end', id: textId });
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
case 'message_delta': {
|
|
362
|
+
if (value.delta.stop_reason) {
|
|
363
|
+
this.finishReason = mapFinishReason(value.delta.stop_reason);
|
|
364
|
+
}
|
|
365
|
+
if (value.usage) {
|
|
366
|
+
this.outputTokens = value.usage.output_tokens;
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
case 'message_stop': {
|
|
371
|
+
// End of stream
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return parts;
|
|
376
|
+
}
|
|
377
|
+
flush() {
|
|
378
|
+
const parts = [];
|
|
379
|
+
for (const textId of this.openTextIds) {
|
|
380
|
+
parts.push({ type: 'text-end', id: textId });
|
|
381
|
+
}
|
|
382
|
+
for (const acc of this.toolCallAccumulators.values()) {
|
|
383
|
+
parts.push({ type: 'tool-input-end', id: acc.id });
|
|
384
|
+
parts.push({ type: 'tool-call', toolCallId: acc.id, toolName: acc.name, input: acc.inputJson });
|
|
385
|
+
}
|
|
386
|
+
parts.push({
|
|
387
|
+
type: 'finish',
|
|
388
|
+
finishReason: this.finishReason,
|
|
389
|
+
usage: { inputTokens: this.inputTokens, outputTokens: this.outputTokens },
|
|
390
|
+
});
|
|
391
|
+
return parts;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
//# sourceMappingURL=anthropic-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic-adapter.js","sourceRoot":"","sources":["../../src/adapters/anthropic-adapter.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAsBxB,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACvB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE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oBAChB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC;gBAChD,CAAC;gBACD,MAAM;YACR,CAAC;YAED,KAAK,cAAc,CAAC,CAAC,CAAC;gBACpB,gBAAgB;gBAChB,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK;QACH,MAAM,KAAK,GAAwB,EAAE,CAAC;QAEtC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACtC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,EAAE,EAAE,CAAC;YACrD,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;QAClG,CAAC;QAED,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE;SAC1E,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AdapterType, ChatAdapter } from './types.js';
|
|
2
|
+
export { OpenAIAdapter } from './openai-adapter.js';
|
|
3
|
+
export { OpenAILegacyAdapter } from './openai-legacy-adapter.js';
|
|
4
|
+
export { AnthropicAdapter } from './anthropic-adapter.js';
|
|
5
|
+
export type { AdapterType, ChatAdapter } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve and instantiate the correct ChatAdapter for a given model.
|
|
8
|
+
*
|
|
9
|
+
* Resolution order:
|
|
10
|
+
* 1. Explicit adapterType from settings — user always wins
|
|
11
|
+
* 2. Model ID heuristic — pattern-matched against known model families
|
|
12
|
+
* 3. Default: 'openai'
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveAdapter(modelId: string, adapterType: AdapterType | undefined, idGenerator?: () => string): ChatAdapter;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA6D3D;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,WAAW,GAAE,MAAM,MAAmB,GACrC,WAAW,CAiBb"}
|