@robota-sdk/agent-provider 3.0.0-beta.64
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/LICENSE +21 -0
- package/dist/browser/index.d.ts +1104 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +7 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/loggers/index.cjs +1 -0
- package/dist/loggers/index.d.ts +151 -0
- package/dist/loggers/index.d.ts.map +1 -0
- package/dist/loggers/index.js +2 -0
- package/dist/loggers/index.js.map +1 -0
- package/dist/node/anthropic/index.cjs +1 -0
- package/dist/node/anthropic/index.d.ts +158 -0
- package/dist/node/anthropic/index.d.ts.map +1 -0
- package/dist/node/anthropic/index.js +1 -0
- package/dist/node/anthropic--1vgLC-e.js +5 -0
- package/dist/node/anthropic--1vgLC-e.js.map +1 -0
- package/dist/node/anthropic-BFQ6DSCP.cjs +4 -0
- package/dist/node/bytedance/index.cjs +1 -0
- package/dist/node/bytedance/index.d.ts +74 -0
- package/dist/node/bytedance/index.d.ts.map +1 -0
- package/dist/node/bytedance/index.js +1 -0
- package/dist/node/bytedance-C_0sF_pJ.js +2 -0
- package/dist/node/bytedance-C_0sF_pJ.js.map +1 -0
- package/dist/node/bytedance-DVPxqEiC.cjs +1 -0
- package/dist/node/chunk-Bmb41Sf3.cjs +1 -0
- package/dist/node/deepseek/index.cjs +1 -0
- package/dist/node/deepseek/index.d.ts +2 -0
- package/dist/node/deepseek/index.js +1 -0
- package/dist/node/deepseek-_8Ixx7rA.js +2 -0
- package/dist/node/deepseek-_8Ixx7rA.js.map +1 -0
- package/dist/node/deepseek-oA2Y6bD0.cjs +1 -0
- package/dist/node/gemini/index.cjs +1 -0
- package/dist/node/gemini/index.d.ts +173 -0
- package/dist/node/gemini/index.d.ts.map +1 -0
- package/dist/node/gemini/index.js +1 -0
- package/dist/node/gemini-Bh2U87MY.js +4 -0
- package/dist/node/gemini-Bh2U87MY.js.map +1 -0
- package/dist/node/gemini-DSaNCxZj.cjs +3 -0
- package/dist/node/gemma/index.cjs +1 -0
- package/dist/node/gemma/index.d.ts +2 -0
- package/dist/node/gemma/index.js +1 -0
- package/dist/node/gemma-Dp_AfCUR.js +2 -0
- package/dist/node/gemma-Dp_AfCUR.js.map +1 -0
- package/dist/node/gemma-G-Pf_PnX.cjs +1 -0
- package/dist/node/google/index.cjs +1 -0
- package/dist/node/google/index.d.ts +14 -0
- package/dist/node/google/index.d.ts.map +1 -0
- package/dist/node/google/index.js +2 -0
- package/dist/node/google/index.js.map +1 -0
- package/dist/node/index-B6PnlDMd.d.ts +82 -0
- package/dist/node/index-B6PnlDMd.d.ts.map +1 -0
- package/dist/node/index-B7UvPJcI.d.ts +315 -0
- package/dist/node/index-B7UvPJcI.d.ts.map +1 -0
- package/dist/node/index-BLPOTNb5.d.ts +98 -0
- package/dist/node/index-BLPOTNb5.d.ts.map +1 -0
- package/dist/node/index-BqixM_XD.d.ts +231 -0
- package/dist/node/index-BqixM_XD.d.ts.map +1 -0
- package/dist/node/index-C3beaqKO.d.ts +231 -0
- package/dist/node/index-C3beaqKO.d.ts.map +1 -0
- package/dist/node/index-Cp2XRh9G.d.ts +82 -0
- package/dist/node/index-Cp2XRh9G.d.ts.map +1 -0
- package/dist/node/index-DSv5xruI.d.ts +98 -0
- package/dist/node/index-DSv5xruI.d.ts.map +1 -0
- package/dist/node/index-w0bV1uaP.d.ts +315 -0
- package/dist/node/index-w0bV1uaP.d.ts.map +1 -0
- package/dist/node/index.cjs +1 -0
- package/dist/node/index.d.ts +8 -0
- package/dist/node/index.js +1 -0
- package/dist/node/openai/index.cjs +1 -0
- package/dist/node/openai/index.d.ts +2 -0
- package/dist/node/openai/index.js +1 -0
- package/dist/node/openai-CRQjg4xF.js +2 -0
- package/dist/node/openai-CRQjg4xF.js.map +1 -0
- package/dist/node/openai-compatible-BYfyY5lb.cjs +1 -0
- package/dist/node/openai-compatible-Dm4Sof9e.js +2 -0
- package/dist/node/openai-compatible-Dm4Sof9e.js.map +1 -0
- package/dist/node/openai-xWC6pY7r.cjs +1 -0
- package/dist/node/qwen/index.cjs +1 -0
- package/dist/node/qwen/index.d.ts +2 -0
- package/dist/node/qwen/index.js +1 -0
- package/dist/node/qwen-ChUZobTL.js +2 -0
- package/dist/node/qwen-ChUZobTL.js.map +1 -0
- package/dist/node/qwen-CjT71vSM.cjs +1 -0
- package/package.json +157 -0
- package/src/anthropic/__tests__/abort-streaming.test.ts +199 -0
- package/src/anthropic/__tests__/model-catalog-refresh.test.ts +92 -0
- package/src/anthropic/__tests__/provider-definition.test.ts +55 -0
- package/src/anthropic/__tests__/provider.test.ts +1357 -0
- package/src/anthropic/__tests__/response-parser.test.ts +326 -0
- package/src/anthropic/index.ts +22 -0
- package/src/anthropic/message-converter.ts +181 -0
- package/src/anthropic/model-catalog-refresh.ts +128 -0
- package/src/anthropic/parsers/response-parser.ts +184 -0
- package/src/anthropic/provider-definition.ts +93 -0
- package/src/anthropic/provider.ts +290 -0
- package/src/anthropic/streaming-handler.ts +204 -0
- package/src/anthropic/types/api-types.ts +158 -0
- package/src/anthropic/types.ts +79 -0
- package/src/bytedance/http-client.test.ts +288 -0
- package/src/bytedance/http-client.ts +163 -0
- package/src/bytedance/index.ts +2 -0
- package/src/bytedance/provider.spec.ts +320 -0
- package/src/bytedance/provider.ts +171 -0
- package/src/bytedance/status-mapper.test.ts +299 -0
- package/src/bytedance/status-mapper.ts +141 -0
- package/src/bytedance/types.ts +68 -0
- package/src/deepseek/defaults.ts +4 -0
- package/src/deepseek/index.ts +22 -0
- package/src/deepseek/model-catalog-refresh.test.ts +57 -0
- package/src/deepseek/model-catalog-refresh.ts +105 -0
- package/src/deepseek/model-catalog.ts +55 -0
- package/src/deepseek/provider-definition.test.ts +109 -0
- package/src/deepseek/provider-definition.ts +132 -0
- package/src/deepseek/provider.test.ts +324 -0
- package/src/deepseek/provider.ts +298 -0
- package/src/deepseek/types.ts +37 -0
- package/src/gemini/execution-helpers.ts +233 -0
- package/src/gemini/genai-transport.test.ts +208 -0
- package/src/gemini/image-operations.test.ts +448 -0
- package/src/gemini/image-operations.ts +261 -0
- package/src/gemini/index.ts +11 -0
- package/src/gemini/message-converter.test.ts +616 -0
- package/src/gemini/message-converter.ts +140 -0
- package/src/gemini/model-catalog-refresh.test.ts +107 -0
- package/src/gemini/model-catalog-refresh.ts +92 -0
- package/src/gemini/provider-definition.test.ts +70 -0
- package/src/gemini/provider-definition.ts +78 -0
- package/src/gemini/provider-extended.test.ts +898 -0
- package/src/gemini/provider.spec.ts +216 -0
- package/src/gemini/provider.ts +279 -0
- package/src/gemini/request-converter.ts +226 -0
- package/src/gemini/tool-schema-converter.ts +78 -0
- package/src/gemini/types/api-types.ts +235 -0
- package/src/gemini/types.ts +121 -0
- package/src/gemma/index.ts +5 -0
- package/src/gemma/message-factory.ts +38 -0
- package/src/gemma/provider-definition.test.ts +43 -0
- package/src/gemma/provider-definition.ts +84 -0
- package/src/gemma/provider-projection.ts +49 -0
- package/src/gemma/provider.test.ts +628 -0
- package/src/gemma/provider.ts +308 -0
- package/src/gemma/pseudo-command-envelope.ts +58 -0
- package/src/gemma/pseudo-tool-call-projector.ts +243 -0
- package/src/gemma/pseudo-tool-call-tag-parser.ts +153 -0
- package/src/gemma/pseudo-tool-call-types.ts +31 -0
- package/src/gemma/reasoning-projector.test.ts +52 -0
- package/src/gemma/reasoning-projector.ts +144 -0
- package/src/gemma/streaming-projection.ts +79 -0
- package/src/gemma/tool-call-argument-parser.ts +126 -0
- package/src/gemma/tool-call-projector.test.ts +227 -0
- package/src/gemma/tool-call-projector.ts +264 -0
- package/src/gemma/types.ts +27 -0
- package/src/google/index.ts +11 -0
- package/src/google/provider-compat.test.ts +19 -0
- package/src/google/provider-definition.ts +6 -0
- package/src/google/provider.ts +10 -0
- package/src/google/types.ts +5 -0
- package/src/index.ts +9 -0
- package/src/openai/adapter.test.ts +494 -0
- package/src/openai/adapter.ts +145 -0
- package/src/openai/chat-completions-chat.ts +189 -0
- package/src/openai/executor-integration.test.ts +206 -0
- package/src/openai/index.ts +21 -0
- package/src/openai/interfaces/payload-logger.ts +48 -0
- package/src/openai/loggers/console-payload-logger.test.ts +173 -0
- package/src/openai/loggers/console-payload-logger.ts +94 -0
- package/src/openai/loggers/console.ts +9 -0
- package/src/openai/loggers/file-payload-logger.test.ts +238 -0
- package/src/openai/loggers/file-payload-logger.ts +112 -0
- package/src/openai/loggers/file.ts +9 -0
- package/src/openai/loggers/index.ts +12 -0
- package/src/openai/loggers/sanitize-openai-log-data.test.ts +89 -0
- package/src/openai/loggers/sanitize-openai-log-data.ts +14 -0
- package/src/openai/message-converter.ts +22 -0
- package/src/openai/model-catalog-refresh.test.ts +92 -0
- package/src/openai/model-catalog-refresh.ts +115 -0
- package/src/openai/openai-request-format.ts +92 -0
- package/src/openai/parsers/response-parser.test.ts +407 -0
- package/src/openai/parsers/response-parser.ts +47 -0
- package/src/openai/provider-definition.test.ts +75 -0
- package/src/openai/provider-definition.ts +132 -0
- package/src/openai/provider.test.ts +1402 -0
- package/src/openai/provider.ts +237 -0
- package/src/openai/responses-chat.ts +258 -0
- package/src/openai/responses-converter.ts +112 -0
- package/src/openai/responses-parser.ts +285 -0
- package/src/openai/responses-stream-utils.ts +45 -0
- package/src/openai/responses-types.ts +195 -0
- package/src/openai/streaming/stream-assembler.ts +3 -0
- package/src/openai/streaming/stream-handler.test.ts +367 -0
- package/src/openai/streaming/stream-handler.ts +119 -0
- package/src/openai/types/api-types.ts +112 -0
- package/src/openai/types.ts +194 -0
- package/src/qwen/defaults.ts +26 -0
- package/src/qwen/index.ts +5 -0
- package/src/qwen/model-catalog-refresh.test.ts +91 -0
- package/src/qwen/model-catalog-refresh.ts +97 -0
- package/src/qwen/provider-capabilities.ts +34 -0
- package/src/qwen/provider-definition.test.ts +139 -0
- package/src/qwen/provider-definition.ts +173 -0
- package/src/qwen/provider-streaming-assembly.ts +40 -0
- package/src/qwen/provider.test.ts +640 -0
- package/src/qwen/provider.ts +293 -0
- package/src/qwen/responses-chat.ts +194 -0
- package/src/qwen/responses-converter.ts +104 -0
- package/src/qwen/responses-parser.ts +299 -0
- package/src/qwen/responses-stream-utils.ts +38 -0
- package/src/qwen/types.ts +228 -0
- package/src/shared/openai-compatible/endpoint-probe.test.ts +52 -0
- package/src/shared/openai-compatible/endpoint-probe.ts +43 -0
- package/src/shared/openai-compatible/index.ts +6 -0
- package/src/shared/openai-compatible/message-converter.test.ts +111 -0
- package/src/shared/openai-compatible/message-converter.ts +84 -0
- package/src/shared/openai-compatible/native-payload-observer.test.ts +43 -0
- package/src/shared/openai-compatible/native-payload-observer.ts +26 -0
- package/src/shared/openai-compatible/response-parser.test.ts +172 -0
- package/src/shared/openai-compatible/response-parser.ts +180 -0
- package/src/shared/openai-compatible/stream-assembler.test.ts +266 -0
- package/src/shared/openai-compatible/stream-assembler.ts +248 -0
- package/src/shared/openai-compatible/types.ts +59 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TUniversalMessage,
|
|
3
|
+
TUniversalMessagePart,
|
|
4
|
+
IMediaOutputRef,
|
|
5
|
+
IImageEditRequest,
|
|
6
|
+
IImageComposeRequest,
|
|
7
|
+
TProviderMediaResult,
|
|
8
|
+
IChatOptions,
|
|
9
|
+
} from '@robota-sdk/agent-core';
|
|
10
|
+
import type { GenerateContentParameters } from '@google/genai';
|
|
11
|
+
import type { IGeminiProviderOptions } from './types';
|
|
12
|
+
|
|
13
|
+
/** Checks whether the given parts contain an image part. */
|
|
14
|
+
export function hasImagePart(parts: TUniversalMessagePart[] | undefined): boolean {
|
|
15
|
+
if (!parts) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return parts.some((part) => part.type === 'image_inline' || part.type === 'image_uri');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Extracts inline image parts from a message and converts them to media output references. */
|
|
22
|
+
export function mapInlineImagePartsToMediaOutputs(
|
|
23
|
+
parts: TUniversalMessagePart[] | undefined,
|
|
24
|
+
): IMediaOutputRef[] {
|
|
25
|
+
if (!parts) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const outputs: IMediaOutputRef[] = [];
|
|
29
|
+
for (const part of parts) {
|
|
30
|
+
if (part.type !== 'image_inline') {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
outputs.push({
|
|
34
|
+
kind: 'uri',
|
|
35
|
+
uri: `data:${part.mimeType};base64,${part.data}`,
|
|
36
|
+
mimeType: part.mimeType,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return outputs;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Parses a data URI into its MIME type and base64 payload. */
|
|
43
|
+
export function parseDataUri(uri: string): { mimeType: string; data: string } | undefined {
|
|
44
|
+
const commaIndex = uri.indexOf(',');
|
|
45
|
+
if (commaIndex < 0) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const header = uri.slice(0, commaIndex);
|
|
49
|
+
const payload = uri.slice(commaIndex + 1);
|
|
50
|
+
if (!header.endsWith(';base64')) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const mimeType = header.replace('data:', '').replace(';base64', '').trim();
|
|
54
|
+
if (mimeType.length === 0 || payload.trim().length === 0) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
mimeType,
|
|
59
|
+
data: payload,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Maps an image input source (inline or URI) to a universal message part. */
|
|
64
|
+
export function mapImageInputSourceToPart(
|
|
65
|
+
source: IImageEditRequest['image'] | IImageComposeRequest['images'][number],
|
|
66
|
+
): TProviderMediaResult<TUniversalMessagePart> {
|
|
67
|
+
if (source.kind === 'inline') {
|
|
68
|
+
if (source.mimeType.trim().length === 0 || source.data.trim().length === 0) {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
error: {
|
|
72
|
+
code: 'PROVIDER_INVALID_REQUEST',
|
|
73
|
+
message: 'Inline image source requires non-empty mimeType and data.',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
ok: true,
|
|
79
|
+
value: {
|
|
80
|
+
type: 'image_inline',
|
|
81
|
+
mimeType: source.mimeType,
|
|
82
|
+
data: source.data,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (!source.uri.startsWith('data:')) {
|
|
87
|
+
return {
|
|
88
|
+
ok: false,
|
|
89
|
+
error: {
|
|
90
|
+
code: 'PROVIDER_INVALID_REQUEST',
|
|
91
|
+
message: 'Google image provider supports only inline or data URI input sources.',
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const parsedResult = parseDataUri(source.uri);
|
|
96
|
+
if (!parsedResult) {
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
error: {
|
|
100
|
+
code: 'PROVIDER_INVALID_REQUEST',
|
|
101
|
+
message: 'Data URI source must use base64 payload.',
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
ok: true,
|
|
107
|
+
value: {
|
|
108
|
+
type: 'image_inline',
|
|
109
|
+
mimeType: parsedResult.mimeType,
|
|
110
|
+
data: parsedResult.data,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Determines which response modalities to request from the Gemini API. */
|
|
116
|
+
export function buildResponseModalities(
|
|
117
|
+
messages: TUniversalMessage[],
|
|
118
|
+
defaultModalities: Array<'TEXT' | 'IMAGE'> | undefined,
|
|
119
|
+
optionModalities: Array<'TEXT' | 'IMAGE'> | undefined,
|
|
120
|
+
): Array<'TEXT' | 'IMAGE'> {
|
|
121
|
+
if (optionModalities && optionModalities.length > 0) {
|
|
122
|
+
return optionModalities;
|
|
123
|
+
}
|
|
124
|
+
const hasImageInput = messages.some((message) => hasImagePart(message.parts));
|
|
125
|
+
if (hasImageInput) {
|
|
126
|
+
return ['TEXT', 'IMAGE'];
|
|
127
|
+
}
|
|
128
|
+
if (defaultModalities && defaultModalities.length > 0) {
|
|
129
|
+
return defaultModalities;
|
|
130
|
+
}
|
|
131
|
+
return ['TEXT'];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Checks whether the specified model is configured as image-capable. */
|
|
135
|
+
export function isImageCapableModel(
|
|
136
|
+
model: string,
|
|
137
|
+
configuredImageModels: string[] | undefined,
|
|
138
|
+
): boolean {
|
|
139
|
+
if (!configuredImageModels || configuredImageModels.length === 0) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return configuredImageModels.includes(model);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Builds the Gemini generation config including response modalities. */
|
|
146
|
+
export function buildGenerationConfig(
|
|
147
|
+
messages: TUniversalMessage[],
|
|
148
|
+
providerOptions: IGeminiProviderOptions,
|
|
149
|
+
options?: IChatOptions,
|
|
150
|
+
): NonNullable<GenerateContentParameters['config']> {
|
|
151
|
+
assertCompatibleStructuredOutputOptions(providerOptions);
|
|
152
|
+
const responseModalities = buildResponseModalities(
|
|
153
|
+
messages,
|
|
154
|
+
providerOptions.defaultResponseModalities,
|
|
155
|
+
options?.google?.responseModalities,
|
|
156
|
+
);
|
|
157
|
+
validateImageCapableModel(options?.model, responseModalities, providerOptions);
|
|
158
|
+
const config: NonNullable<GenerateContentParameters['config']> = { responseModalities };
|
|
159
|
+
applyChatOptions(config, options);
|
|
160
|
+
applySafetySettings(config, providerOptions, options);
|
|
161
|
+
applyStructuredOutputOptions(config, providerOptions);
|
|
162
|
+
applyProviderGenerationOptions(config, providerOptions);
|
|
163
|
+
return config;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function validateImageCapableModel(
|
|
167
|
+
model: string | undefined,
|
|
168
|
+
responseModalities: Array<'TEXT' | 'IMAGE'>,
|
|
169
|
+
providerOptions: IGeminiProviderOptions,
|
|
170
|
+
): void {
|
|
171
|
+
if (!model || !responseModalities.includes('IMAGE')) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (isImageCapableModel(model, providerOptions.imageCapableModels)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
throw new Error(
|
|
178
|
+
`Selected model "${model}" is not configured as image-capable for Google provider.`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function applyChatOptions(
|
|
183
|
+
config: NonNullable<GenerateContentParameters['config']>,
|
|
184
|
+
options?: IChatOptions,
|
|
185
|
+
): void {
|
|
186
|
+
if (typeof options?.temperature === 'number') {
|
|
187
|
+
config.temperature = options.temperature;
|
|
188
|
+
}
|
|
189
|
+
if (typeof options?.maxTokens === 'number') {
|
|
190
|
+
config.maxOutputTokens = options.maxTokens;
|
|
191
|
+
}
|
|
192
|
+
if (typeof options?.google?.topP === 'number') {
|
|
193
|
+
config.topP = options.google.topP;
|
|
194
|
+
}
|
|
195
|
+
if (typeof options?.google?.topK === 'number') {
|
|
196
|
+
config.topK = options.google.topK;
|
|
197
|
+
}
|
|
198
|
+
if (typeof options?.google?.candidateCount === 'number') {
|
|
199
|
+
config.candidateCount = options.google.candidateCount;
|
|
200
|
+
}
|
|
201
|
+
if (options?.google?.stopSequences && options.google.stopSequences.length > 0) {
|
|
202
|
+
config.stopSequences = options.google.stopSequences;
|
|
203
|
+
}
|
|
204
|
+
if (options?.signal) {
|
|
205
|
+
config.abortSignal = options.signal;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function applySafetySettings(
|
|
210
|
+
config: NonNullable<GenerateContentParameters['config']>,
|
|
211
|
+
providerOptions: IGeminiProviderOptions,
|
|
212
|
+
options?: IChatOptions,
|
|
213
|
+
): void {
|
|
214
|
+
const safetySettings = options?.google?.safetySettings ?? providerOptions.safetySettings;
|
|
215
|
+
if (safetySettings && safetySettings.length > 0) {
|
|
216
|
+
config.safetySettings = safetySettings as NonNullable<
|
|
217
|
+
GenerateContentParameters['config']
|
|
218
|
+
>['safetySettings'];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function applyStructuredOutputOptions(
|
|
223
|
+
config: NonNullable<GenerateContentParameters['config']>,
|
|
224
|
+
providerOptions: IGeminiProviderOptions,
|
|
225
|
+
): void {
|
|
226
|
+
if (providerOptions.responseMimeType) {
|
|
227
|
+
config.responseMimeType = providerOptions.responseMimeType;
|
|
228
|
+
}
|
|
229
|
+
if (providerOptions.responseSchema) {
|
|
230
|
+
config.responseMimeType = providerOptions.responseMimeType ?? 'application/json';
|
|
231
|
+
config.responseSchema = providerOptions.responseSchema;
|
|
232
|
+
}
|
|
233
|
+
if (providerOptions.responseJsonSchema) {
|
|
234
|
+
config.responseMimeType = providerOptions.responseMimeType ?? 'application/json';
|
|
235
|
+
config.responseJsonSchema = providerOptions.responseJsonSchema;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function applyProviderGenerationOptions(
|
|
240
|
+
config: NonNullable<GenerateContentParameters['config']>,
|
|
241
|
+
providerOptions: IGeminiProviderOptions,
|
|
242
|
+
): void {
|
|
243
|
+
if (providerOptions.thinkingConfig) {
|
|
244
|
+
config.thinkingConfig = providerOptions.thinkingConfig as NonNullable<
|
|
245
|
+
GenerateContentParameters['config']
|
|
246
|
+
>['thinkingConfig'];
|
|
247
|
+
}
|
|
248
|
+
if (providerOptions.toolConfig) {
|
|
249
|
+
config.toolConfig = providerOptions.toolConfig as NonNullable<
|
|
250
|
+
GenerateContentParameters['config']
|
|
251
|
+
>['toolConfig'];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function assertCompatibleStructuredOutputOptions(providerOptions: IGeminiProviderOptions): void {
|
|
256
|
+
if (providerOptions.responseSchema && providerOptions.responseJsonSchema) {
|
|
257
|
+
throw new Error(
|
|
258
|
+
'Gemini structured output options responseSchema and responseJsonSchema are mutually exclusive.',
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @robota-sdk/agent-provider (gemini)
|
|
3
|
+
*
|
|
4
|
+
* Provides a Gemini API provider implementation with provider-agnostic TUniversalMessage.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Main exports
|
|
8
|
+
export * from './model-catalog-refresh';
|
|
9
|
+
export * from './provider';
|
|
10
|
+
export * from './provider-definition';
|
|
11
|
+
export * from './types';
|