@langchain/google-common 0.2.17 → 1.0.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/CHANGELOG.md +17 -0
- package/LICENSE +6 -6
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth.cjs +82 -116
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +46 -0
- package/dist/auth.d.cts.map +1 -0
- package/dist/auth.d.ts +41 -36
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +80 -110
- package/dist/auth.js.map +1 -0
- package/dist/chat_models.cjs +251 -466
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +98 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +87 -73
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +245 -457
- package/dist/chat_models.js.map +1 -0
- package/dist/connection.cjs +321 -466
- package/dist/connection.cjs.map +1 -0
- package/dist/connection.d.cts +109 -0
- package/dist/connection.d.cts.map +1 -0
- package/dist/connection.d.ts +98 -91
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +317 -459
- package/dist/connection.js.map +1 -0
- package/dist/embeddings.cjs +135 -186
- package/dist/embeddings.cjs.map +1 -0
- package/dist/embeddings.d.cts +44 -0
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +38 -32
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +133 -181
- package/dist/embeddings.js.map +1 -0
- package/dist/experimental/media.cjs +380 -482
- package/dist/experimental/media.cjs.map +1 -0
- package/dist/experimental/media.d.cts +198 -0
- package/dist/experimental/media.d.cts.map +1 -0
- package/dist/experimental/media.d.ts +190 -202
- package/dist/experimental/media.d.ts.map +1 -0
- package/dist/experimental/media.js +369 -468
- package/dist/experimental/media.js.map +1 -0
- package/dist/experimental/utils/media_core.cjs +403 -517
- package/dist/experimental/utils/media_core.cjs.map +1 -0
- package/dist/experimental/utils/media_core.d.cts +215 -0
- package/dist/experimental/utils/media_core.d.cts.map +1 -0
- package/dist/experimental/utils/media_core.d.ts +171 -165
- package/dist/experimental/utils/media_core.d.ts.map +1 -0
- package/dist/experimental/utils/media_core.js +395 -506
- package/dist/experimental/utils/media_core.js.map +1 -0
- package/dist/index.cjs +58 -27
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/llms.cjs +157 -244
- package/dist/llms.cjs.map +1 -0
- package/dist/llms.d.cts +72 -0
- package/dist/llms.d.cts.map +1 -0
- package/dist/llms.d.ts +64 -54
- package/dist/llms.d.ts.map +1 -0
- package/dist/llms.js +154 -238
- package/dist/llms.js.map +1 -0
- package/dist/output_parsers.cjs +148 -173
- package/dist/output_parsers.cjs.map +1 -0
- package/dist/output_parsers.d.cts +53 -0
- package/dist/output_parsers.d.cts.map +1 -0
- package/dist/output_parsers.d.ts +46 -42
- package/dist/output_parsers.d.ts.map +1 -0
- package/dist/output_parsers.js +146 -168
- package/dist/output_parsers.js.map +1 -0
- package/dist/types-anthropic.d.cts +229 -0
- package/dist/types-anthropic.d.cts.map +1 -0
- package/dist/types-anthropic.d.ts +221 -215
- package/dist/types-anthropic.d.ts.map +1 -0
- package/dist/types.cjs +51 -62
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +748 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +669 -656
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +46 -45
- package/dist/types.js.map +1 -0
- package/dist/utils/anthropic.cjs +598 -821
- package/dist/utils/anthropic.cjs.map +1 -0
- package/dist/utils/anthropic.js +597 -818
- package/dist/utils/anthropic.js.map +1 -0
- package/dist/utils/common.cjs +130 -211
- package/dist/utils/common.cjs.map +1 -0
- package/dist/utils/common.d.cts +13 -0
- package/dist/utils/common.d.cts.map +1 -0
- package/dist/utils/common.d.ts +12 -7
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +128 -207
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/failed_handler.cjs +28 -30
- package/dist/utils/failed_handler.cjs.map +1 -0
- package/dist/utils/failed_handler.d.cts +9 -0
- package/dist/utils/failed_handler.d.cts.map +1 -0
- package/dist/utils/failed_handler.d.ts +8 -2
- package/dist/utils/failed_handler.d.ts.map +1 -0
- package/dist/utils/failed_handler.js +28 -28
- package/dist/utils/failed_handler.js.map +1 -0
- package/dist/utils/gemini.cjs +1020 -1488
- package/dist/utils/gemini.cjs.map +1 -0
- package/dist/utils/gemini.d.cts +51 -0
- package/dist/utils/gemini.d.cts.map +1 -0
- package/dist/utils/gemini.d.ts +51 -48
- package/dist/utils/gemini.d.ts.map +1 -0
- package/dist/utils/gemini.js +1015 -1479
- package/dist/utils/gemini.js.map +1 -0
- package/dist/utils/index.cjs +38 -23
- package/dist/utils/index.d.cts +8 -0
- package/dist/utils/index.d.ts +8 -7
- package/dist/utils/index.js +8 -7
- package/dist/utils/palm.d.cts +11 -0
- package/dist/utils/palm.d.cts.map +1 -0
- package/dist/utils/palm.d.ts +9 -4
- package/dist/utils/palm.d.ts.map +1 -0
- package/dist/utils/safety.cjs +13 -22
- package/dist/utils/safety.cjs.map +1 -0
- package/dist/utils/safety.d.cts +12 -0
- package/dist/utils/safety.d.cts.map +1 -0
- package/dist/utils/safety.d.ts +10 -4
- package/dist/utils/safety.d.ts.map +1 -0
- package/dist/utils/safety.js +13 -19
- package/dist/utils/safety.js.map +1 -0
- package/dist/utils/stream.cjs +296 -475
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.d.cts +165 -0
- package/dist/utils/stream.d.cts.map +1 -0
- package/dist/utils/stream.d.ts +156 -131
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +293 -469
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.cjs +43 -81
- package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts +22 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.ts +21 -6
- package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.js +40 -76
- package/dist/utils/zod_to_gemini_parameters.js.map +1 -0
- package/package.json +69 -85
- package/dist/types-anthropic.cjs +0 -2
- package/dist/types-anthropic.js +0 -1
- package/dist/utils/anthropic.d.ts +0 -4
- package/dist/utils/palm.cjs +0 -2
- package/dist/utils/palm.js +0 -1
- package/experimental/media.cjs +0 -1
- package/experimental/media.d.cts +0 -1
- package/experimental/media.d.ts +0 -1
- package/experimental/media.js +0 -1
- package/experimental/utils/media_core.cjs +0 -1
- package/experimental/utils/media_core.d.cts +0 -1
- package/experimental/utils/media_core.d.ts +0 -1
- package/experimental/utils/media_core.js +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/types.cjs +0 -1
- package/types.d.cts +0 -1
- package/types.d.ts +0 -1
- package/types.js +0 -1
- package/utils.cjs +0 -1
- package/utils.d.cts +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
package/dist/output_parsers.js
CHANGED
|
@@ -1,169 +1,147 @@
|
|
|
1
1
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
textPrefix(_text, _grounding) {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
chunkSuffixLink(chunk, index) {
|
|
153
|
-
const num = index + 1;
|
|
154
|
-
const info = chunk.retrievedContext ?? chunk.web;
|
|
155
|
-
const url = info.uri;
|
|
156
|
-
const site = info.title;
|
|
157
|
-
return `${num}. [${site}](${url})`;
|
|
158
|
-
}
|
|
159
|
-
textSuffix(_text, grounding) {
|
|
160
|
-
let ret = "\n**Search Sources**\n";
|
|
161
|
-
const chunks = grounding.metadata.groundingChunks;
|
|
162
|
-
chunks.forEach((chunk, index) => {
|
|
163
|
-
ret = `${ret}${this.chunkSuffixLink(chunk, index)}\n`;
|
|
164
|
-
});
|
|
165
|
-
const search = this.searchSuggestion(grounding);
|
|
166
|
-
ret = `${ret}\n${search}`;
|
|
167
|
-
return ret;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
2
|
+
|
|
3
|
+
//#region src/output_parsers.ts
|
|
4
|
+
var BaseGoogleSearchOutputParser = class extends BaseLLMOutputParser {
|
|
5
|
+
lc_namespace = ["google_common", "output_parsers"];
|
|
6
|
+
generationToGroundingInfo(generation) {
|
|
7
|
+
if ("message" in generation) {
|
|
8
|
+
const responseMetadata = generation?.message?.response_metadata;
|
|
9
|
+
const metadata = responseMetadata?.groundingMetadata;
|
|
10
|
+
const supports = responseMetadata?.groundingSupport ?? metadata?.groundingSupports ?? [];
|
|
11
|
+
if (metadata) return {
|
|
12
|
+
metadata,
|
|
13
|
+
supports
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
generationsToGroundingInfo(generations) {
|
|
19
|
+
for (const generation of generations) {
|
|
20
|
+
const info = this.generationToGroundingInfo(generation);
|
|
21
|
+
if (info !== void 0) return info;
|
|
22
|
+
}
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
generationToString(generation) {
|
|
26
|
+
if ("message" in generation) {
|
|
27
|
+
const content = generation?.message?.content;
|
|
28
|
+
if (typeof content === "string") return content;
|
|
29
|
+
else return content.map((c) => {
|
|
30
|
+
if (c?.type === "text") return c?.text ?? "";
|
|
31
|
+
else return "";
|
|
32
|
+
}).reduce((previousValue, currentValue) => `${previousValue}${currentValue}`);
|
|
33
|
+
}
|
|
34
|
+
return generation.text;
|
|
35
|
+
}
|
|
36
|
+
generationsToString(generations) {
|
|
37
|
+
return generations.map((generation) => this.generationToString(generation)).reduce((previousValue, currentValue) => `${previousValue}${currentValue}`);
|
|
38
|
+
}
|
|
39
|
+
annotateSegment(text, grounding, support, index) {
|
|
40
|
+
const start = support.segment.startIndex ?? 0;
|
|
41
|
+
const end = support.segment.endIndex;
|
|
42
|
+
const textBefore = text.substring(0, start);
|
|
43
|
+
const textSegment = text.substring(start, end);
|
|
44
|
+
const textAfter = text.substring(end);
|
|
45
|
+
const textPrefix = this.segmentPrefix(grounding, support, index) ?? "";
|
|
46
|
+
const textSuffix = this.segmentSuffix(grounding, support, index) ?? "";
|
|
47
|
+
return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;
|
|
48
|
+
}
|
|
49
|
+
annotateTextSegments(text, grounding) {
|
|
50
|
+
let ret = text;
|
|
51
|
+
for (let co = grounding.supports.length - 1; co >= 0; co -= 1) {
|
|
52
|
+
const support = grounding.supports[co];
|
|
53
|
+
ret = this.annotateSegment(ret, grounding, support, co);
|
|
54
|
+
}
|
|
55
|
+
return ret;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Google requires us to
|
|
59
|
+
* "Display the Search Suggestion exactly as provided without any modifications"
|
|
60
|
+
* So this will typically be called from the textSuffix() method to get
|
|
61
|
+
* a string that renders HTML.
|
|
62
|
+
* See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions
|
|
63
|
+
* @param grounding
|
|
64
|
+
*/
|
|
65
|
+
searchSuggestion(grounding) {
|
|
66
|
+
return grounding?.metadata?.searchEntryPoint?.renderedContent ?? "";
|
|
67
|
+
}
|
|
68
|
+
annotateText(text, grounding) {
|
|
69
|
+
const prefix = this.textPrefix(text, grounding) ?? "";
|
|
70
|
+
const suffix = this.textSuffix(text, grounding) ?? "";
|
|
71
|
+
const body = this.annotateTextSegments(text, grounding);
|
|
72
|
+
return `${prefix}${body}${suffix}`;
|
|
73
|
+
}
|
|
74
|
+
async parseResult(generations, _callbacks) {
|
|
75
|
+
const text = this.generationsToString(generations);
|
|
76
|
+
const grounding = this.generationsToGroundingInfo(generations);
|
|
77
|
+
if (!grounding) return text;
|
|
78
|
+
return this.annotateText(text, grounding);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
var SimpleGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
|
|
82
|
+
segmentPrefix(_grounding, _support, _index) {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
segmentSuffix(_grounding, support, _index) {
|
|
86
|
+
const indices = support.groundingChunkIndices.map((i) => i + 1);
|
|
87
|
+
return ` [${indices.join(", ")}]`;
|
|
88
|
+
}
|
|
89
|
+
textPrefix(_text, _grounding) {
|
|
90
|
+
return "Google Says:\n";
|
|
91
|
+
}
|
|
92
|
+
chunkToString(chunk, index) {
|
|
93
|
+
const info = chunk.retrievedContext ?? chunk.web;
|
|
94
|
+
return `${index + 1}. ${info.title} - ${info.uri}`;
|
|
95
|
+
}
|
|
96
|
+
textSuffix(_text, grounding) {
|
|
97
|
+
let ret = "\n";
|
|
98
|
+
const chunks = grounding?.metadata?.groundingChunks ?? [];
|
|
99
|
+
chunks.forEach((chunk, index) => {
|
|
100
|
+
ret = `${ret}${this.chunkToString(chunk, index)}\n`;
|
|
101
|
+
});
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var MarkdownGoogleSearchOutputParser = class extends BaseGoogleSearchOutputParser {
|
|
106
|
+
segmentPrefix(_grounding, _support, _index) {
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
chunkLink(grounding, index) {
|
|
110
|
+
const chunk = grounding.metadata.groundingChunks[index];
|
|
111
|
+
const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;
|
|
112
|
+
const num = index + 1;
|
|
113
|
+
return `[[${num}](${url})]`;
|
|
114
|
+
}
|
|
115
|
+
segmentSuffix(grounding, support, _index) {
|
|
116
|
+
let ret = "";
|
|
117
|
+
support.groundingChunkIndices.forEach((chunkIndex) => {
|
|
118
|
+
const link = this.chunkLink(grounding, chunkIndex);
|
|
119
|
+
ret = `${ret}${link}`;
|
|
120
|
+
});
|
|
121
|
+
return ret;
|
|
122
|
+
}
|
|
123
|
+
textPrefix(_text, _grounding) {
|
|
124
|
+
return void 0;
|
|
125
|
+
}
|
|
126
|
+
chunkSuffixLink(chunk, index) {
|
|
127
|
+
const num = index + 1;
|
|
128
|
+
const info = chunk.retrievedContext ?? chunk.web;
|
|
129
|
+
const url = info.uri;
|
|
130
|
+
const site = info.title;
|
|
131
|
+
return `${num}. [${site}](${url})`;
|
|
132
|
+
}
|
|
133
|
+
textSuffix(_text, grounding) {
|
|
134
|
+
let ret = "\n**Search Sources**\n";
|
|
135
|
+
const chunks = grounding.metadata.groundingChunks;
|
|
136
|
+
chunks.forEach((chunk, index) => {
|
|
137
|
+
ret = `${ret}${this.chunkSuffixLink(chunk, index)}\n`;
|
|
138
|
+
});
|
|
139
|
+
const search = this.searchSuggestion(grounding);
|
|
140
|
+
ret = `${ret}\n${search}`;
|
|
141
|
+
return ret;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
export { BaseGoogleSearchOutputParser, MarkdownGoogleSearchOutputParser, SimpleGoogleSearchOutputParser };
|
|
147
|
+
//# sourceMappingURL=output_parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output_parsers.js","names":["generation: Generation | ChatGeneration","generations: Generations","content: MessageContent","text: string","grounding: GroundingInfo","support: GeminiGroundingSupport","index: number","_callbacks?: Callbacks","_grounding: GroundingInfo","_support: GeminiGroundingSupport","_index: number","indices: number[]","_text: string","chunk: GeminiGroundingChunk","chunks: GeminiGroundingChunk[]"],"sources":["../src/output_parsers.ts"],"sourcesContent":["import { BaseLLMOutputParser } from \"@langchain/core/output_parsers\";\nimport { Callbacks } from \"@langchain/core/callbacks/manager\";\nimport { ChatGeneration, Generation } from \"@langchain/core/outputs\";\nimport { MessageContent } from \"@langchain/core/messages\";\nimport {\n GeminiGroundingChunk,\n GeminiGroundingMetadata,\n GeminiGroundingSupport,\n} from \"./types.js\";\n\ntype Generations = Generation[] | ChatGeneration[];\n\ntype GroundingInfo = {\n metadata: GeminiGroundingMetadata;\n supports: GeminiGroundingSupport[];\n};\n\nexport abstract class BaseGoogleSearchOutputParser extends BaseLLMOutputParser<string> {\n lc_namespace: string[] = [\"google_common\", \"output_parsers\"];\n\n protected generationToGroundingInfo(\n generation: Generation | ChatGeneration\n ): GroundingInfo | undefined {\n if (\"message\" in generation) {\n const responseMetadata = generation?.message?.response_metadata;\n const metadata = responseMetadata?.groundingMetadata;\n const supports =\n responseMetadata?.groundingSupport ?? metadata?.groundingSupports ?? [];\n if (metadata) {\n return {\n metadata,\n supports,\n };\n }\n }\n return undefined;\n }\n\n protected generationsToGroundingInfo(\n generations: Generations\n ): GroundingInfo | undefined {\n for (const generation of generations) {\n const info = this.generationToGroundingInfo(generation);\n if (info !== undefined) {\n return info;\n }\n }\n return undefined;\n }\n\n protected generationToString(\n generation: Generation | ChatGeneration\n ): string {\n if (\"message\" in generation) {\n const content: MessageContent = generation?.message?.content;\n if (typeof content === \"string\") {\n return content;\n } else {\n return content\n .map((c) => {\n if (c?.type === \"text\") {\n return c?.text ?? \"\";\n } else {\n return \"\";\n }\n })\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n }\n return generation.text;\n }\n\n protected generationsToString(generations: Generations): string {\n return generations\n .map((generation) => this.generationToString(generation))\n .reduce(\n (previousValue, currentValue) => `${previousValue}${currentValue}`\n );\n }\n\n protected abstract segmentPrefix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected abstract segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string | undefined;\n\n protected annotateSegment(\n text: string,\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n index: number\n ): string {\n const start = support.segment.startIndex ?? 0;\n const end = support.segment.endIndex;\n\n const textBefore = text.substring(0, start);\n const textSegment = text.substring(start, end);\n const textAfter = text.substring(end);\n\n const textPrefix = this.segmentPrefix(grounding, support, index) ?? \"\";\n const textSuffix = this.segmentSuffix(grounding, support, index) ?? \"\";\n\n return `${textBefore}${textPrefix}${textSegment}${textSuffix}${textAfter}`;\n }\n\n protected annotateTextSegments(\n text: string,\n grounding: GroundingInfo\n ): string {\n // Go through each support info in reverse, since the segment info\n // is sorted, and we won't need to adjust string indexes this way.\n let ret = text;\n for (let co = grounding.supports.length - 1; co >= 0; co -= 1) {\n const support = grounding.supports[co];\n ret = this.annotateSegment(ret, grounding, support, co);\n }\n return ret;\n }\n\n protected abstract textPrefix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n protected abstract textSuffix(\n text: string,\n grounding: GroundingInfo\n ): string | undefined;\n\n /**\n * Google requires us to\n * \"Display the Search Suggestion exactly as provided without any modifications\"\n * So this will typically be called from the textSuffix() method to get\n * a string that renders HTML.\n * See https://ai.google.dev/gemini-api/docs/grounding/search-suggestions\n * @param grounding\n */\n protected searchSuggestion(grounding: GroundingInfo): string {\n return grounding?.metadata?.searchEntryPoint?.renderedContent ?? \"\";\n }\n\n protected annotateText(text: string, grounding: GroundingInfo): string {\n const prefix = this.textPrefix(text, grounding) ?? \"\";\n const suffix = this.textSuffix(text, grounding) ?? \"\";\n const body = this.annotateTextSegments(text, grounding);\n return `${prefix}${body}${suffix}`;\n }\n\n async parseResult(\n generations: Generations,\n _callbacks?: Callbacks\n ): Promise<string> {\n const text = this.generationsToString(generations);\n\n const grounding = this.generationsToGroundingInfo(generations);\n if (!grounding) {\n return text;\n }\n\n return this.annotateText(text, grounding);\n }\n}\n\nexport class SimpleGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected segmentSuffix(\n _grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n const indices: number[] = support.groundingChunkIndices.map((i) => i + 1);\n return ` [${indices.join(\", \")}]`;\n }\n\n protected textPrefix(_text: string, _grounding: GroundingInfo): string {\n return \"Google Says:\\n\";\n }\n\n protected chunkToString(chunk: GeminiGroundingChunk, index: number): string {\n const info = chunk.retrievedContext ?? chunk.web;\n return `${index + 1}. ${info.title} - ${info.uri}`;\n }\n\n protected textSuffix(_text: string, grounding: GroundingInfo): string {\n let ret = \"\\n\";\n const chunks: GeminiGroundingChunk[] =\n grounding?.metadata?.groundingChunks ?? [];\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkToString(chunk, index)}\\n`;\n });\n return ret;\n }\n}\n\nexport class MarkdownGoogleSearchOutputParser extends BaseGoogleSearchOutputParser {\n protected segmentPrefix(\n _grounding: GroundingInfo,\n _support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n return undefined;\n }\n\n protected chunkLink(grounding: GroundingInfo, index: number): string {\n const chunk = grounding.metadata.groundingChunks[index];\n const url = chunk.retrievedContext?.uri ?? chunk.web?.uri;\n const num = index + 1;\n return `[[${num}](${url})]`;\n }\n\n protected segmentSuffix(\n grounding: GroundingInfo,\n support: GeminiGroundingSupport,\n _index: number\n ): string | undefined {\n let ret = \"\";\n support.groundingChunkIndices.forEach((chunkIndex) => {\n const link = this.chunkLink(grounding, chunkIndex);\n ret = `${ret}${link}`;\n });\n return ret;\n }\n\n protected textPrefix(\n _text: string,\n _grounding: GroundingInfo\n ): string | undefined {\n return undefined;\n }\n\n protected chunkSuffixLink(\n chunk: GeminiGroundingChunk,\n index: number\n ): string {\n const num = index + 1;\n const info = chunk.retrievedContext ?? chunk.web;\n const url = info.uri;\n const site = info.title;\n return `${num}. [${site}](${url})`;\n }\n\n protected textSuffix(\n _text: string,\n grounding: GroundingInfo\n ): string | undefined {\n let ret = \"\\n**Search Sources**\\n\";\n const chunks: GeminiGroundingChunk[] = grounding.metadata.groundingChunks;\n chunks.forEach((chunk, index) => {\n ret = `${ret}${this.chunkSuffixLink(chunk, index)}\\n`;\n });\n\n const search = this.searchSuggestion(grounding);\n ret = `${ret}\\n${search}`;\n\n return ret;\n }\n}\n"],"mappings":";;;AAiBA,IAAsB,+BAAtB,cAA2D,oBAA4B;CACrF,eAAyB,CAAC,iBAAiB,gBAAiB;CAE5D,AAAU,0BACRA,YAC2B;AAC3B,MAAI,aAAa,YAAY;GAC3B,MAAM,mBAAmB,YAAY,SAAS;GAC9C,MAAM,WAAW,kBAAkB;GACnC,MAAM,WACJ,kBAAkB,oBAAoB,UAAU,qBAAqB,CAAE;AACzE,OAAI,SACF,QAAO;IACL;IACA;GACD;EAEJ;AACD,SAAO;CACR;CAED,AAAU,2BACRC,aAC2B;AAC3B,OAAK,MAAM,cAAc,aAAa;GACpC,MAAM,OAAO,KAAK,0BAA0B,WAAW;AACvD,OAAI,SAAS,OACX,QAAO;EAEV;AACD,SAAO;CACR;CAED,AAAU,mBACRD,YACQ;AACR,MAAI,aAAa,YAAY;GAC3B,MAAME,UAA0B,YAAY,SAAS;AACrD,OAAI,OAAO,YAAY,SACrB,QAAO;OAEP,QAAO,QACJ,IAAI,CAAC,MAAM;AACV,QAAI,GAAG,SAAS,OACd,QAAO,GAAG,QAAQ;QAElB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QAAQ,CAAC,eAAe;GACpD,MAAM,OAAO,KAAK,UAAU,WAAW,WAAW;GAClD,MAAM,GAAG,MAAM,MAAM;EACtB,EAAC;AACF,SAAO;CACR;CAED,AAAU,WACRE,OACAJ,YACoB;AACpB,SAAO;CACR;CAED,AAAU,gBACRK,OACAP,OACQ;EACR,MAAM,MAAM,QAAQ;EACpB,MAAM,OAAO,MAAM,oBAAoB,MAAM;EAC7C,MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,KAAK;AAClB,SAAO,GAAG,IAAI,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;CACnC;CAED,AAAU,WACRM,OACAR,WACoB;EACpB,IAAI,MAAM;EACV,MAAMU,SAAiC,UAAU,SAAS;EAC1D,OAAO,QAAQ,CAAC,OAAO,UAAU;GAC/B,MAAM,GAAG,MAAM,KAAK,gBAAgB,OAAO,MAAM,CAAC,EAAE,CAAC;EACtD,EAAC;EAEF,MAAM,SAAS,KAAK,iBAAiB,UAAU;EAC/C,MAAM,GAAG,IAAI,EAAE,EAAE,QAAQ;AAEzB,SAAO;CACR;AACF"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
//#region src/types-anthropic.d.ts
|
|
2
|
+
interface AnthropicCacheControl {
|
|
3
|
+
type: "ephemeral" | string;
|
|
4
|
+
}
|
|
5
|
+
interface AnthropicMessageContentBase {
|
|
6
|
+
type: string;
|
|
7
|
+
cache_control?: AnthropicCacheControl | null;
|
|
8
|
+
}
|
|
9
|
+
interface AnthropicMessageContentText extends AnthropicMessageContentBase {
|
|
10
|
+
type: "text";
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
interface AnthropicMessageContentImage extends AnthropicMessageContentBase {
|
|
14
|
+
type: "image";
|
|
15
|
+
source: {
|
|
16
|
+
type: "base64" | string;
|
|
17
|
+
media_type?: string;
|
|
18
|
+
data: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "url" | string;
|
|
21
|
+
url: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface AnthropicMessageContentThinking extends AnthropicMessageContentBase {
|
|
25
|
+
type: "thinking";
|
|
26
|
+
thinking: string;
|
|
27
|
+
signature: string;
|
|
28
|
+
}
|
|
29
|
+
interface AnthropicMessageContentDocument extends AnthropicMessageContentBase {
|
|
30
|
+
type: "document";
|
|
31
|
+
source: {
|
|
32
|
+
type: "base64" | "text" | string;
|
|
33
|
+
media_type?: "application/pdf" | "text/plain" | string;
|
|
34
|
+
data: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "url" | string;
|
|
37
|
+
url: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "content" | string;
|
|
40
|
+
content: {
|
|
41
|
+
type: "image" | string;
|
|
42
|
+
source: {
|
|
43
|
+
type: "base64" | string;
|
|
44
|
+
data: string;
|
|
45
|
+
media_type?: "image/jpeg" | "image/png" | "image/gif" | "image/webp" | string;
|
|
46
|
+
} | {
|
|
47
|
+
type: "url" | string;
|
|
48
|
+
url: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: "text" | string;
|
|
51
|
+
text: string;
|
|
52
|
+
};
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
citations?: {
|
|
56
|
+
enabled?: boolean;
|
|
57
|
+
};
|
|
58
|
+
context?: string;
|
|
59
|
+
title?: string;
|
|
60
|
+
}
|
|
61
|
+
interface AnthropicMessageContentRedactedThinking extends AnthropicMessageContentBase {
|
|
62
|
+
type: "redacted_thinking";
|
|
63
|
+
data: string;
|
|
64
|
+
}
|
|
65
|
+
// TODO: Define this
|
|
66
|
+
type AnthropicMessageContentToolUseInput = object;
|
|
67
|
+
interface AnthropicMessageContentToolUse extends AnthropicMessageContentBase {
|
|
68
|
+
type: "tool_use";
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
input: AnthropicMessageContentToolUseInput;
|
|
72
|
+
}
|
|
73
|
+
type AnthropicMessageContentToolResultContent = AnthropicMessageContentText | AnthropicMessageContentImage;
|
|
74
|
+
interface AnthropicMessageContentToolResult extends AnthropicMessageContentBase {
|
|
75
|
+
type: "tool_result";
|
|
76
|
+
tool_use_id: string;
|
|
77
|
+
is_error?: boolean;
|
|
78
|
+
content: string | AnthropicMessageContentToolResultContent[];
|
|
79
|
+
}
|
|
80
|
+
type AnthropicMessageContent = AnthropicMessageContentText | AnthropicMessageContentImage | AnthropicMessageContentToolUse | AnthropicMessageContentToolResult | AnthropicMessageContentThinking | AnthropicMessageContentRedactedThinking;
|
|
81
|
+
interface AnthropicMessage {
|
|
82
|
+
role: string;
|
|
83
|
+
content: string | AnthropicMessageContent[];
|
|
84
|
+
}
|
|
85
|
+
interface AnthropicMetadata {
|
|
86
|
+
user_id?: string | null;
|
|
87
|
+
}
|
|
88
|
+
interface AnthropicToolChoiceBase {
|
|
89
|
+
type: string;
|
|
90
|
+
}
|
|
91
|
+
interface AnthropicToolChoiceAuto extends AnthropicToolChoiceBase {
|
|
92
|
+
type: "auto";
|
|
93
|
+
}
|
|
94
|
+
interface AnthropicToolChoiceAny extends AnthropicToolChoiceBase {
|
|
95
|
+
type: "any";
|
|
96
|
+
}
|
|
97
|
+
interface AnthropicToolChoiceTool extends AnthropicToolChoiceBase {
|
|
98
|
+
type: "tool";
|
|
99
|
+
name: string;
|
|
100
|
+
}
|
|
101
|
+
type AnthropicToolChoice = AnthropicToolChoiceAuto | AnthropicToolChoiceAny | AnthropicToolChoiceTool;
|
|
102
|
+
// TODO: Define this
|
|
103
|
+
type AnthropicToolInputSchema = object;
|
|
104
|
+
interface AnthropicTool {
|
|
105
|
+
type?: string; // Just available on tools 20241022 and later?
|
|
106
|
+
name: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
cache_control?: AnthropicCacheControl;
|
|
109
|
+
input_schema: AnthropicToolInputSchema;
|
|
110
|
+
}
|
|
111
|
+
interface AnthropicThinkingEnabled {
|
|
112
|
+
type: "enabled";
|
|
113
|
+
budget_tokens: number;
|
|
114
|
+
}
|
|
115
|
+
interface AnthropicThinkingDisabled {
|
|
116
|
+
type: "disabled";
|
|
117
|
+
}
|
|
118
|
+
type AnthropicThinking = AnthropicThinkingEnabled | AnthropicThinkingDisabled;
|
|
119
|
+
interface AnthropicRequest {
|
|
120
|
+
anthropic_version: string;
|
|
121
|
+
messages: AnthropicMessage[];
|
|
122
|
+
system?: string;
|
|
123
|
+
stream?: boolean;
|
|
124
|
+
max_tokens: number;
|
|
125
|
+
temperature?: number;
|
|
126
|
+
top_k?: number;
|
|
127
|
+
top_p?: number;
|
|
128
|
+
stop_sequences?: string[];
|
|
129
|
+
metadata?: AnthropicMetadata;
|
|
130
|
+
tool_choice?: AnthropicToolChoice;
|
|
131
|
+
tools?: AnthropicTool[];
|
|
132
|
+
thinking?: AnthropicThinking;
|
|
133
|
+
}
|
|
134
|
+
type AnthropicRequestSettings = Pick<AnthropicRequest, "max_tokens" | "temperature" | "top_k" | "top_p" | "stop_sequences" | "stream">;
|
|
135
|
+
interface AnthropicContentText {
|
|
136
|
+
type: "text";
|
|
137
|
+
text: string;
|
|
138
|
+
}
|
|
139
|
+
interface AnthropicContentToolUse {
|
|
140
|
+
type: "tool_use";
|
|
141
|
+
id: string;
|
|
142
|
+
name: string;
|
|
143
|
+
input: object;
|
|
144
|
+
}
|
|
145
|
+
interface AnthropicContentThinking {
|
|
146
|
+
type: "thinking";
|
|
147
|
+
thinking: string;
|
|
148
|
+
signature: string;
|
|
149
|
+
}
|
|
150
|
+
interface AnthropicContentRedactedThinking {
|
|
151
|
+
type: "redacted_thinking";
|
|
152
|
+
data: string;
|
|
153
|
+
}
|
|
154
|
+
type AnthropicContent = AnthropicContentText | AnthropicContentToolUse | AnthropicContentThinking | AnthropicContentRedactedThinking;
|
|
155
|
+
interface AnthropicUsage {
|
|
156
|
+
input_tokens: number;
|
|
157
|
+
output_tokens: number;
|
|
158
|
+
cache_creation_input_tokens: number | null;
|
|
159
|
+
cache_creation_output_tokens: number | null;
|
|
160
|
+
cache_read_input_tokens: number | null;
|
|
161
|
+
}
|
|
162
|
+
type AnthropicResponseData = AnthropicResponseMessage | AnthropicStreamBaseEvent;
|
|
163
|
+
interface AnthropicResponseMessage {
|
|
164
|
+
id: string;
|
|
165
|
+
type: string;
|
|
166
|
+
role: string;
|
|
167
|
+
content: AnthropicContent[];
|
|
168
|
+
model: string;
|
|
169
|
+
stop_reason: string | null;
|
|
170
|
+
stop_sequence: string | null;
|
|
171
|
+
usage: AnthropicUsage;
|
|
172
|
+
}
|
|
173
|
+
interface AnthropicAPIConfig {
|
|
174
|
+
version?: string;
|
|
175
|
+
thinking?: AnthropicThinking;
|
|
176
|
+
}
|
|
177
|
+
type AnthropicStreamEventType = "message_start" | "content_block_start" | "content_block_delta" | "content_block_stop" | "message_delta" | "message_stop" | "ping" | "error";
|
|
178
|
+
type AnthropicStreamDeltaType = "text_delta" | "input_json_delta";
|
|
179
|
+
interface AnthropicStreamBaseEvent {
|
|
180
|
+
type: AnthropicStreamEventType;
|
|
181
|
+
}
|
|
182
|
+
interface AnthropicStreamMessageStartEvent extends AnthropicStreamBaseEvent {
|
|
183
|
+
type: "message_start";
|
|
184
|
+
message: AnthropicResponseMessage;
|
|
185
|
+
}
|
|
186
|
+
interface AnthropicStreamContentBlockStartEvent extends AnthropicStreamBaseEvent {
|
|
187
|
+
type: "content_block_start";
|
|
188
|
+
index: number;
|
|
189
|
+
content_block: AnthropicContent;
|
|
190
|
+
}
|
|
191
|
+
interface AnthropicStreamBaseDelta {
|
|
192
|
+
type: AnthropicStreamDeltaType;
|
|
193
|
+
}
|
|
194
|
+
interface AnthropicStreamTextDelta extends AnthropicStreamBaseDelta {
|
|
195
|
+
type: "text_delta";
|
|
196
|
+
text: string;
|
|
197
|
+
}
|
|
198
|
+
interface AnthropicStreamInputJsonDelta extends AnthropicStreamBaseDelta {
|
|
199
|
+
type: "input_json_delta";
|
|
200
|
+
partial_json: string;
|
|
201
|
+
}
|
|
202
|
+
type AnthropicStreamDelta = AnthropicStreamTextDelta | AnthropicStreamInputJsonDelta;
|
|
203
|
+
interface AnthropicStreamContentBlockDeltaEvent extends AnthropicStreamBaseEvent {
|
|
204
|
+
type: "content_block_delta";
|
|
205
|
+
index: number;
|
|
206
|
+
delta: AnthropicStreamDelta;
|
|
207
|
+
}
|
|
208
|
+
interface AnthropicStreamContentBlockStopEvent extends AnthropicStreamBaseEvent {
|
|
209
|
+
type: "content_block_stop";
|
|
210
|
+
index: number;
|
|
211
|
+
}
|
|
212
|
+
interface AnthropicStreamMessageDeltaEvent extends AnthropicStreamBaseEvent {
|
|
213
|
+
type: "message_delta";
|
|
214
|
+
delta: Partial<AnthropicResponseMessage>;
|
|
215
|
+
}
|
|
216
|
+
interface AnthropicStreamMessageStopEvent extends AnthropicStreamBaseEvent {
|
|
217
|
+
type: "message_stop";
|
|
218
|
+
}
|
|
219
|
+
interface AnthropicStreamPingEvent extends AnthropicStreamBaseEvent {
|
|
220
|
+
type: "ping";
|
|
221
|
+
}
|
|
222
|
+
interface AnthropicStreamErrorEvent extends AnthropicStreamBaseEvent {
|
|
223
|
+
type: "error";
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
+
error: any;
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { AnthropicAPIConfig, AnthropicCacheControl, AnthropicContent, AnthropicContentRedactedThinking, AnthropicContentText, AnthropicContentThinking, AnthropicContentToolUse, AnthropicMessage, AnthropicMessageContent, AnthropicMessageContentDocument, AnthropicMessageContentImage, AnthropicMessageContentRedactedThinking, AnthropicMessageContentText, AnthropicMessageContentThinking, AnthropicMessageContentToolResult, AnthropicMessageContentToolResultContent, AnthropicMessageContentToolUse, AnthropicMessageContentToolUseInput, AnthropicMetadata, AnthropicRequest, AnthropicRequestSettings, AnthropicResponseData, AnthropicResponseMessage, AnthropicStreamBaseDelta, AnthropicStreamBaseEvent, AnthropicStreamContentBlockDeltaEvent, AnthropicStreamContentBlockStartEvent, AnthropicStreamContentBlockStopEvent, AnthropicStreamDelta, AnthropicStreamDeltaType, AnthropicStreamErrorEvent, AnthropicStreamEventType, AnthropicStreamInputJsonDelta, AnthropicStreamMessageDeltaEvent, AnthropicStreamMessageStartEvent, AnthropicStreamMessageStopEvent, AnthropicStreamPingEvent, AnthropicStreamTextDelta, AnthropicThinking, AnthropicThinkingDisabled, AnthropicThinkingEnabled, AnthropicTool, AnthropicToolChoice, AnthropicToolChoiceAny, AnthropicToolChoiceAuto, AnthropicToolChoiceTool, AnthropicToolInputSchema, AnthropicUsage };
|
|
229
|
+
//# sourceMappingURL=types-anthropic.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-anthropic.d.cts","names":["AnthropicCacheControl","AnthropicMessageContentBase","AnthropicMessageContentText","AnthropicMessageContentImage","AnthropicMessageContentThinking","AnthropicMessageContentDocument","AnthropicMessageContentRedactedThinking","AnthropicMessageContentToolUseInput","AnthropicMessageContentToolUse","AnthropicMessageContentToolResultContent","AnthropicMessageContentToolResult","AnthropicMessageContent","AnthropicMessage","AnthropicMetadata","AnthropicToolChoiceBase","AnthropicToolChoiceAuto","AnthropicToolChoiceAny","AnthropicToolChoiceTool","AnthropicToolChoice","AnthropicToolInputSchema","AnthropicTool","AnthropicThinkingEnabled","AnthropicThinkingDisabled","AnthropicThinking","AnthropicRequest","AnthropicRequestSettings","Pick","AnthropicContentText","AnthropicContentToolUse","AnthropicContentThinking","AnthropicContentRedactedThinking","AnthropicContent","AnthropicUsage","AnthropicResponseData","AnthropicResponseMessage","AnthropicStreamBaseEvent","AnthropicAPIConfig","AnthropicStreamEventType","AnthropicStreamDeltaType","AnthropicStreamMessageStartEvent","AnthropicStreamContentBlockStartEvent","AnthropicStreamBaseDelta","AnthropicStreamTextDelta","AnthropicStreamInputJsonDelta","AnthropicStreamDelta","AnthropicStreamContentBlockDeltaEvent","AnthropicStreamContentBlockStopEvent","AnthropicStreamMessageDeltaEvent","Partial","AnthropicStreamMessageStopEvent","AnthropicStreamPingEvent","AnthropicStreamErrorEvent"],"sources":["../src/types-anthropic.d.ts"],"sourcesContent":["export interface AnthropicCacheControl {\n type: \"ephemeral\" | string;\n}\ninterface AnthropicMessageContentBase {\n type: string;\n cache_control?: AnthropicCacheControl | null;\n}\nexport interface AnthropicMessageContentText extends AnthropicMessageContentBase {\n type: \"text\";\n text: string;\n}\nexport interface AnthropicMessageContentImage extends AnthropicMessageContentBase {\n type: \"image\";\n source: {\n type: \"base64\" | string;\n media_type?: string;\n data: string;\n } | {\n type: \"url\" | string;\n url: string;\n };\n}\nexport interface AnthropicMessageContentThinking extends AnthropicMessageContentBase {\n type: \"thinking\";\n thinking: string;\n signature: string;\n}\nexport interface AnthropicMessageContentDocument extends AnthropicMessageContentBase {\n type: \"document\";\n source: {\n type: \"base64\" | \"text\" | string;\n media_type?: \"application/pdf\" | \"text/plain\" | string;\n data: string;\n } | {\n type: \"url\" | string;\n url: string;\n } | {\n type: \"content\" | string;\n content: {\n type: \"image\" | string;\n source: {\n type: \"base64\" | string;\n data: string;\n media_type?: \"image/jpeg\" | \"image/png\" | \"image/gif\" | \"image/webp\" | string;\n } | {\n type: \"url\" | string;\n url: string;\n } | {\n type: \"text\" | string;\n text: string;\n };\n }[];\n };\n citations?: {\n enabled?: boolean;\n };\n context?: string;\n title?: string;\n}\nexport interface AnthropicMessageContentRedactedThinking extends AnthropicMessageContentBase {\n type: \"redacted_thinking\";\n data: string;\n}\n// TODO: Define this\nexport type AnthropicMessageContentToolUseInput = object;\nexport interface AnthropicMessageContentToolUse extends AnthropicMessageContentBase {\n type: \"tool_use\";\n id: string;\n name: string;\n input: AnthropicMessageContentToolUseInput;\n}\nexport type AnthropicMessageContentToolResultContent = AnthropicMessageContentText | AnthropicMessageContentImage;\nexport interface AnthropicMessageContentToolResult extends AnthropicMessageContentBase {\n type: \"tool_result\";\n tool_use_id: string;\n is_error?: boolean;\n content: string | AnthropicMessageContentToolResultContent[];\n}\nexport type AnthropicMessageContent = AnthropicMessageContentText | AnthropicMessageContentImage | AnthropicMessageContentToolUse | AnthropicMessageContentToolResult | AnthropicMessageContentThinking | AnthropicMessageContentRedactedThinking;\nexport interface AnthropicMessage {\n role: string;\n content: string | AnthropicMessageContent[];\n}\nexport interface AnthropicMetadata {\n user_id?: string | null;\n}\ninterface AnthropicToolChoiceBase {\n type: string;\n}\nexport interface AnthropicToolChoiceAuto extends AnthropicToolChoiceBase {\n type: \"auto\";\n}\nexport interface AnthropicToolChoiceAny extends AnthropicToolChoiceBase {\n type: \"any\";\n}\nexport interface AnthropicToolChoiceTool extends AnthropicToolChoiceBase {\n type: \"tool\";\n name: string;\n}\nexport type AnthropicToolChoice = AnthropicToolChoiceAuto | AnthropicToolChoiceAny | AnthropicToolChoiceTool;\n// TODO: Define this\nexport type AnthropicToolInputSchema = object;\nexport interface AnthropicTool {\n type?: string; // Just available on tools 20241022 and later?\n name: string;\n description?: string;\n cache_control?: AnthropicCacheControl;\n input_schema: AnthropicToolInputSchema;\n}\nexport interface AnthropicThinkingEnabled {\n type: \"enabled\";\n budget_tokens: number;\n}\nexport interface AnthropicThinkingDisabled {\n type: \"disabled\";\n}\nexport type AnthropicThinking = AnthropicThinkingEnabled | AnthropicThinkingDisabled;\nexport interface AnthropicRequest {\n anthropic_version: string;\n messages: AnthropicMessage[];\n system?: string;\n stream?: boolean;\n max_tokens: number;\n temperature?: number;\n top_k?: number;\n top_p?: number;\n stop_sequences?: string[];\n metadata?: AnthropicMetadata;\n tool_choice?: AnthropicToolChoice;\n tools?: AnthropicTool[];\n thinking?: AnthropicThinking;\n}\nexport type AnthropicRequestSettings = Pick<AnthropicRequest, \"max_tokens\" | \"temperature\" | \"top_k\" | \"top_p\" | \"stop_sequences\" | \"stream\">;\nexport interface AnthropicContentText {\n type: \"text\";\n text: string;\n}\nexport interface AnthropicContentToolUse {\n type: \"tool_use\";\n id: string;\n name: string;\n input: object;\n}\nexport interface AnthropicContentThinking {\n type: \"thinking\";\n thinking: string;\n signature: string;\n}\nexport interface AnthropicContentRedactedThinking {\n type: \"redacted_thinking\";\n data: string;\n}\nexport type AnthropicContent = AnthropicContentText | AnthropicContentToolUse | AnthropicContentThinking | AnthropicContentRedactedThinking;\nexport interface AnthropicUsage {\n input_tokens: number;\n output_tokens: number;\n cache_creation_input_tokens: number | null;\n cache_creation_output_tokens: number | null;\n cache_read_input_tokens: number | null;\n}\nexport type AnthropicResponseData = AnthropicResponseMessage | AnthropicStreamBaseEvent;\nexport interface AnthropicResponseMessage {\n id: string;\n type: string;\n role: string;\n content: AnthropicContent[];\n model: string;\n stop_reason: string | null;\n stop_sequence: string | null;\n usage: AnthropicUsage;\n}\nexport interface AnthropicAPIConfig {\n version?: string;\n thinking?: AnthropicThinking;\n}\nexport type AnthropicStreamEventType = \"message_start\" | \"content_block_start\" | \"content_block_delta\" | \"content_block_stop\" | \"message_delta\" | \"message_stop\" | \"ping\" | \"error\";\nexport type AnthropicStreamDeltaType = \"text_delta\" | \"input_json_delta\";\nexport interface AnthropicStreamBaseEvent {\n type: AnthropicStreamEventType;\n}\nexport interface AnthropicStreamMessageStartEvent extends AnthropicStreamBaseEvent {\n type: \"message_start\";\n message: AnthropicResponseMessage;\n}\nexport interface AnthropicStreamContentBlockStartEvent extends AnthropicStreamBaseEvent {\n type: \"content_block_start\";\n index: number;\n content_block: AnthropicContent;\n}\nexport interface AnthropicStreamBaseDelta {\n type: AnthropicStreamDeltaType;\n}\nexport interface AnthropicStreamTextDelta extends AnthropicStreamBaseDelta {\n type: \"text_delta\";\n text: string;\n}\nexport interface AnthropicStreamInputJsonDelta extends AnthropicStreamBaseDelta {\n type: \"input_json_delta\";\n partial_json: string;\n}\nexport type AnthropicStreamDelta = AnthropicStreamTextDelta | AnthropicStreamInputJsonDelta;\nexport interface AnthropicStreamContentBlockDeltaEvent extends AnthropicStreamBaseEvent {\n type: \"content_block_delta\";\n index: number;\n delta: AnthropicStreamDelta;\n}\nexport interface AnthropicStreamContentBlockStopEvent extends AnthropicStreamBaseEvent {\n type: \"content_block_stop\";\n index: number;\n}\nexport interface AnthropicStreamMessageDeltaEvent extends AnthropicStreamBaseEvent {\n type: \"message_delta\";\n delta: Partial<AnthropicResponseMessage>;\n}\nexport interface AnthropicStreamMessageStopEvent extends AnthropicStreamBaseEvent {\n type: \"message_stop\";\n}\nexport interface AnthropicStreamPingEvent extends AnthropicStreamBaseEvent {\n type: \"ping\";\n}\nexport interface AnthropicStreamErrorEvent extends AnthropicStreamBaseEvent {\n type: \"error\";\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error: any;\n}\nexport {};\n"],"mappings":";UAAiBA,qBAAAA;EAAAA,IAAAA,EAAAA,WAAAA,GAAAA,MAAqB;AAErC;AAKD,UAJUC,2BAAAA,CAIkC;EAI3BE,IAAAA,EAAAA,MAAAA;EAWAC,aAAAA,CAAAA,EAjBGJ,qBAiB4B,GAAA,IAAA;AAKhD;AAgCiBM,UApDAJ,2BAAAA,SAAoCD,2BAoDYA,CAAAA;EAKrDM,IAAAA,EAAAA,MAAAA;EACKC,IAAAA,EAAAA,MAAAA;;AAIND,UA1DMJ,4BAAAA,SAAqCF,2BA0D3CM,CAAAA;EAAmC,IAJUN,EAAAA,OAAAA;EAA2B,MAAA,EAAA;IAMvEQ,IAAAA,EAAAA,QAAAA,GAAAA,MAAAA;IAAwC,UAAA,CAAA,EAAA,MAAA;IAAGP,IAAAA,EAAAA,MAAAA;EAA2B,CAAA,GAAGC;IAA4B,IAAA,EAAA,KAAA,GAAA,MAAA;IAChGO,GAAAA,EAAAA,MAAAA;EAAiC,CAAA;;AAAST,UAlD1CG,+BAAAA,SAAwCH,2BAkDEA,CAAAA;EAA2B,IAAA,EAAA,UAAA;EAM1EU,QAAAA,EAAAA,MAAAA;EAAuB,SAAA,EAAA,MAAA;;AAAiCR,UAnDnDE,+BAAAA,SAAwCJ,2BAmDWE,CAAAA;EAA4B,IAAGK,EAAAA,UAAAA;EAA8B,MAAGE,EAAAA;IAAoCN,IAAAA,EAAAA,QAAAA,GAAAA,MA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