@rtsee/messenger-signaling 0.0.109 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/messenger-signaling/src/models/RTSeeMessengerSignaling.d.ts +4 -0
- package/dist/messenger-signaling/src/models/RTSeeMessengerSignaling.d.ts.map +1 -1
- package/dist/messenger-signaling/src/models/RTSeeMessengerSignaling.js +152 -0
- package/dist/messenger-signaling/src/models/RTSeeMessengerSignaling.js.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/Ozzy.d.ts +19 -1
- package/dist/messenger-signaling/src/models/ozzy/Ozzy.d.ts.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/Ozzy.js +89 -3
- package/dist/messenger-signaling/src/models/ozzy/Ozzy.js.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/BedrockConverseConnector.d.ts +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/BedrockConverseConnector.d.ts.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/BedrockConverseConnector.js +20 -14
- package/dist/messenger-signaling/src/models/ozzy/connectors/BedrockConverseConnector.js.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/GCloudConverseConnector.d.ts +11 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/GCloudConverseConnector.d.ts.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/GCloudConverseConnector.js +264 -27
- package/dist/messenger-signaling/src/models/ozzy/connectors/GCloudConverseConnector.js.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/LlmConverseConnector.d.ts +2 -2
- package/dist/messenger-signaling/src/models/ozzy/connectors/LlmConverseConnector.d.ts.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/connectors/LlmConverseConnector.js +2 -2
- package/dist/messenger-signaling/src/models/ozzy/connectors/LlmConverseConnector.js.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/tasks/StoryCreatorTask.d.ts +11 -1
- package/dist/messenger-signaling/src/models/ozzy/tasks/StoryCreatorTask.d.ts.map +1 -1
- package/dist/messenger-signaling/src/models/ozzy/tasks/StoryCreatorTask.js +236 -19
- package/dist/messenger-signaling/src/models/ozzy/tasks/StoryCreatorTask.js.map +1 -1
- package/package.json +2 -2
|
@@ -28,9 +28,9 @@ class BedrockConverseConnector extends LlmConverseConnector_js_1.LlmConverseConn
|
|
|
28
28
|
region: options.region
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
stream(llmStream, flowId, prompt, systemPrompt, model, depth = 0, tools, rawTools, agentId) {
|
|
31
|
+
stream(llmStream, flowId, prompt, systemPrompt, model, depth = 0, tools, rawTools, agentId, maxTokens) {
|
|
32
32
|
const bedrockCompatiblePrompt = this.preparePrompt(prompt);
|
|
33
|
-
const streamRequest = this.prepareConverseStreamCommand(model, bedrockCompatiblePrompt, systemPrompt, tools);
|
|
33
|
+
const streamRequest = this.prepareConverseStreamCommand(model, bedrockCompatiblePrompt, systemPrompt, tools, maxTokens);
|
|
34
34
|
if (depth > 0) {
|
|
35
35
|
return this.continueFlow(llmStream, flowId, streamRequest, tools, rawTools, depth, agentId);
|
|
36
36
|
}
|
|
@@ -59,7 +59,10 @@ class BedrockConverseConnector extends LlmConverseConnector_js_1.LlmConverseConn
|
|
|
59
59
|
await this.handleConverseStreamOutput(llmStream, output, flowState, converseCommandInput, tools, rawTools, depth, agentId);
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
|
-
console.
|
|
62
|
+
console.error(`Error while opening Bedrock converse stream:`, error);
|
|
63
|
+
flowState.finished = true;
|
|
64
|
+
llmStream.emitEnd(true);
|
|
65
|
+
this.flowStates.delete(flowId);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
async handleConverseStreamOutput(llmStream, output, flowState, originalRequest, tools, rawTools, depth = 0, agentId) {
|
|
@@ -200,23 +203,26 @@ class BedrockConverseConnector extends LlmConverseConnector_js_1.LlmConverseConn
|
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
205
|
formatTools(rawTools) {
|
|
203
|
-
return rawTools.map((ot) =>
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
return rawTools.map((ot) => {
|
|
207
|
+
const rawSchema = ot.definition?.inputSchema ?? ot.definition?.parameters ?? ot.definition;
|
|
208
|
+
return {
|
|
209
|
+
toolSpec: {
|
|
210
|
+
name: ot.name,
|
|
211
|
+
description: ot.description || ot.name,
|
|
212
|
+
inputSchema: {
|
|
213
|
+
json: (0, ai_1.asSchema)(rawSchema).jsonSchema,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
});
|
|
212
218
|
}
|
|
213
|
-
prepareConverseStreamCommand(model, prompt, systemPrompt, tools) {
|
|
219
|
+
prepareConverseStreamCommand(model, prompt, systemPrompt, tools, maxTokens) {
|
|
214
220
|
const modelId = this.resolveModelId(model);
|
|
215
221
|
return {
|
|
216
222
|
modelId,
|
|
217
223
|
messages: prompt,
|
|
218
224
|
inferenceConfig: {
|
|
219
|
-
maxTokens:
|
|
225
|
+
maxTokens: maxTokens || 8192
|
|
220
226
|
},
|
|
221
227
|
toolConfig: tools && tools.length ? { tools } : undefined,
|
|
222
228
|
system: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BedrockConverseConnector.js","sourceRoot":"","sources":["../../../../../../src/models/ozzy/connectors/BedrockConverseConnector.ts"],"names":[],"mappings":";;;AAAA,uEAAiE;AAMjE,4EAQyC;AACzC,0CAA0D;AAG1D,2BAA8B;AAE9B,MAAM,iBAAiB,GAA2B;IAChD,CAAC,mBAAU,CAAC,KAAK,CAAC,EAAE,6CAA6C;IACjE,CAAC,mBAAU,CAAC,MAAM,CAAC,EAAE,8CAA8C;IACnE,CAAC,mBAAU,CAAC,IAAI,CAAC,EAAE,8BAA8B;IACjD,+DAA+D;IAC/D,CAAC,mBAAU,CAAC,QAAQ,CAAC,EAAE,8BAA8B;CACtD,CAAC;AAEF,MAAa,wBAAyB,SAAQ,8CAAkC;IAC9E,MAAM,CAAuB;IAC7B,UAAU,CAA8B;IAExC,YAAY,OAAyC;QACnD,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI;gBAC1C,mBAAU,CAAC,KAAK,EAAE,mBAAU,CAAC,MAAM,EAAE,mBAAU,CAAC,IAAI,EAAE,mBAAU,CAAC,QAAQ;aAC1E;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,6CAAoB,CAAC;YACrC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;IACL,CAAC;IAES,MAAM,CACd,SAA4B,EAC5B,MAAc,EACd,MAAc,EACd,YAAoB,EACpB,KAAa,EACb,QAAgB,CAAC,EACjB,KAAc,EACd,QAAsB,EACtB,OAAgB;
|
|
1
|
+
{"version":3,"file":"BedrockConverseConnector.js","sourceRoot":"","sources":["../../../../../../src/models/ozzy/connectors/BedrockConverseConnector.ts"],"names":[],"mappings":";;;AAAA,uEAAiE;AAMjE,4EAQyC;AACzC,0CAA0D;AAG1D,2BAA8B;AAE9B,MAAM,iBAAiB,GAA2B;IAChD,CAAC,mBAAU,CAAC,KAAK,CAAC,EAAE,6CAA6C;IACjE,CAAC,mBAAU,CAAC,MAAM,CAAC,EAAE,8CAA8C;IACnE,CAAC,mBAAU,CAAC,IAAI,CAAC,EAAE,8BAA8B;IACjD,+DAA+D;IAC/D,CAAC,mBAAU,CAAC,QAAQ,CAAC,EAAE,8BAA8B;CACtD,CAAC;AAEF,MAAa,wBAAyB,SAAQ,8CAAkC;IAC9E,MAAM,CAAuB;IAC7B,UAAU,CAA8B;IAExC,YAAY,OAAy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C,QAAyB;QACrD,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,OAAO;gBACV,OAAO,WAAW,CAAC;YACrB,KAAK,MAAM;gBACT,OAAO,MAAM,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAC;YAClB;gBACE,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAkB,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF;AA9WD,4DA8WC"}
|
|
@@ -27,7 +27,7 @@ export declare class GCloudConverseConnector extends LlmConverseConnector<string
|
|
|
27
27
|
* fail the request instead.
|
|
28
28
|
*/
|
|
29
29
|
private getAnthropic;
|
|
30
|
-
protected stream(llmStream: LLMConverseStream, flowId: string, prompt: string, systemPrompt: string, model: string, depth?: number, tools?: VertexTool[], rawTools?: IOzzyTool[], agentId?: string): Promise<void>;
|
|
30
|
+
protected stream(llmStream: LLMConverseStream, flowId: string, prompt: string, systemPrompt: string, model: string, depth?: number, tools?: VertexTool[], rawTools?: IOzzyTool[], agentId?: string, maxTokens?: number): Promise<void>;
|
|
31
31
|
/**
|
|
32
32
|
* Core streaming method that handles both initial and continuation turns.
|
|
33
33
|
*/
|
|
@@ -47,11 +47,21 @@ export declare class GCloudConverseConnector extends LlmConverseConnector<string
|
|
|
47
47
|
private startFlow;
|
|
48
48
|
abortFlow(flowId: string): void;
|
|
49
49
|
protected formatTools(rawTools: IOzzyTool[]): VertexTool[];
|
|
50
|
+
private toVertexSchema;
|
|
50
51
|
private formatAnthropicTools;
|
|
51
52
|
private resolveModelId;
|
|
52
53
|
private prepareAnthropicPrompt;
|
|
53
54
|
private preparePrompt;
|
|
55
|
+
private prepareImagePrompt;
|
|
54
56
|
private ozzyMessagesToVertexContents;
|
|
55
57
|
private ozzyRoleToVertexRole;
|
|
58
|
+
/**
|
|
59
|
+
* Appends systemPrompt to the instructions / prompt when a model does not accept systemPrompt natively.
|
|
60
|
+
*/
|
|
61
|
+
private appendSystemPromptToInstructions;
|
|
62
|
+
/**
|
|
63
|
+
* Appends systemPrompt to Vertex Content[] when falling back from an unsupported systemInstruction.
|
|
64
|
+
*/
|
|
65
|
+
private appendSystemPromptToContents;
|
|
56
66
|
}
|
|
57
67
|
//# sourceMappingURL=GCloudConverseConnector.d.ts.map
|
package/dist/messenger-signaling/src/models/ozzy/connectors/GCloudConverseConnector.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GCloudConverseConnector.d.ts","sourceRoot":"","sources":["../../../../../../src/models/ozzy/connectors/GCloudConverseConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,+BAA+B,EAAE,MAAM,gEAAgE,CAAC;AACjH,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EACL,QAAQ,EAIR,IAAI,IAAI,UAAU,
|
|
1
|
+
{"version":3,"file":"GCloudConverseConnector.d.ts","sourceRoot":"","sources":["../../../../../../src/models/ozzy/connectors/GCloudConverseConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,+BAA+B,EAAE,MAAM,gEAAgE,CAAC;AACjH,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnE,OAAO,EACL,QAAQ,EAIR,IAAI,IAAI,UAAU,EAQnB,MAAM,wBAAwB,CAAC;AAyEhC,qBAAa,uBAAwB,SAAQ,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC;IACnF,QAAQ,EAAE,QAAQ,CAAC;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;OAEG;IACH,OAAO,CAAC,4BAA4B;CAyBrC"}
|
|
@@ -18,8 +18,14 @@ const GCLOUD_MODEL_IDS = {
|
|
|
18
18
|
[common_1.OzzyModels.GCLOUD_OPUS]: 'claude-opus-4-8',
|
|
19
19
|
[common_1.OzzyModels.GCLOUD_OPUS_5_5]: 'claude-opus-5-5',
|
|
20
20
|
// Google
|
|
21
|
-
[common_1.OzzyModels.
|
|
22
|
-
[common_1.OzzyModels.
|
|
21
|
+
[common_1.OzzyModels.GEMINI_3_8_FLASH]: 'gemini-3.8-flash',
|
|
22
|
+
[common_1.OzzyModels.GEMINI_3_6_FLASH]: 'gemini-3.6-flash',
|
|
23
|
+
[common_1.OzzyModels.GEMINI_3_1_PRO]: 'gemini-3.1-pro-preview',
|
|
24
|
+
[common_1.OzzyModels.GEMINI_3_5_FLASH_LITE]: 'gemini-3.5-flash-lite',
|
|
25
|
+
[common_1.OzzyModels.GEMINI_3_1_FLASH_LITE]: 'gemini-3.1-flash-lite',
|
|
26
|
+
[common_1.OzzyModels.GEMINI_FLASH]: 'gemini-3.8-flash',
|
|
27
|
+
[common_1.OzzyModels.GEMINI_PRO]: 'gemini-3.1-pro-preview',
|
|
28
|
+
'gemini-3.1-pro': 'gemini-3.1-pro-preview',
|
|
23
29
|
[common_1.OzzyModels.IMAGEN]: 'imagen-3.0-generate-002',
|
|
24
30
|
// Nano Banana (Gemini image generation) - served from the Vertex `global` location
|
|
25
31
|
// (ids verified via Vertex countTokens; Nano Banana 2/Pro/2 Lite are global-only)
|
|
@@ -34,6 +40,15 @@ const ANTHROPIC_MODELS = [
|
|
|
34
40
|
common_1.OzzyModels.GCLOUD_OPUS,
|
|
35
41
|
common_1.OzzyModels.GCLOUD_OPUS_5_5,
|
|
36
42
|
];
|
|
43
|
+
const GEMINI_MODELS = [
|
|
44
|
+
common_1.OzzyModels.GEMINI_3_8_FLASH,
|
|
45
|
+
common_1.OzzyModels.GEMINI_3_6_FLASH,
|
|
46
|
+
common_1.OzzyModels.GEMINI_3_1_PRO,
|
|
47
|
+
common_1.OzzyModels.GEMINI_3_5_FLASH_LITE,
|
|
48
|
+
common_1.OzzyModels.GEMINI_3_1_FLASH_LITE,
|
|
49
|
+
common_1.OzzyModels.GEMINI_FLASH,
|
|
50
|
+
common_1.OzzyModels.GEMINI_PRO,
|
|
51
|
+
];
|
|
37
52
|
const IMAGE_MODELS = [
|
|
38
53
|
common_1.OzzyModels.IMAGEN,
|
|
39
54
|
common_1.OzzyModels.NANO_BANANA,
|
|
@@ -41,7 +56,8 @@ const IMAGE_MODELS = [
|
|
|
41
56
|
common_1.OzzyModels.NANO_BANANA_2_LITE,
|
|
42
57
|
common_1.OzzyModels.NANO_BANANA_PRO,
|
|
43
58
|
];
|
|
44
|
-
const
|
|
59
|
+
const ANTHROPIC_DEFAULT_MAX_TOKENS = 8192;
|
|
60
|
+
const GEMINI_DEFAULT_MAX_TOKENS = 16384;
|
|
45
61
|
class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConnector {
|
|
46
62
|
vertexAI;
|
|
47
63
|
/** Separate client for image models: Nano Banana models are served from the `global` location */
|
|
@@ -57,7 +73,7 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
57
73
|
...options,
|
|
58
74
|
supportedModels: options.supportedModels || [
|
|
59
75
|
...ANTHROPIC_MODELS,
|
|
60
|
-
|
|
76
|
+
...GEMINI_MODELS,
|
|
61
77
|
...IMAGE_MODELS,
|
|
62
78
|
],
|
|
63
79
|
});
|
|
@@ -111,45 +127,50 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
111
127
|
}
|
|
112
128
|
return this.anthropicClient;
|
|
113
129
|
}
|
|
114
|
-
async stream(llmStream, flowId, prompt, systemPrompt, model, depth = 0, tools, rawTools, agentId) {
|
|
130
|
+
async stream(llmStream, flowId, prompt, systemPrompt, model, depth = 0, tools, rawTools, agentId, maxTokens) {
|
|
115
131
|
const resolvedModel = this.resolveModelId(model);
|
|
116
132
|
// Route image generation to a separate handler
|
|
117
133
|
if (IMAGE_MODELS.includes(model)) {
|
|
118
|
-
return this.generateImage(llmStream, flowId, prompt, resolvedModel);
|
|
134
|
+
return this.generateImage(llmStream, flowId, prompt, resolvedModel, systemPrompt);
|
|
119
135
|
}
|
|
120
136
|
// Claude on Vertex AI: same flow as BedrockConverseConnector
|
|
121
137
|
if (ANTHROPIC_MODELS.includes(model)) {
|
|
122
138
|
if (depth === 0) {
|
|
123
139
|
this.startFlow(flowId);
|
|
124
140
|
}
|
|
125
|
-
return this.streamAnthropic(llmStream, flowId, this.prepareAnthropicPrompt(prompt), systemPrompt, resolvedModel, depth, rawTools, agentId);
|
|
141
|
+
return this.streamAnthropic(llmStream, flowId, this.prepareAnthropicPrompt(prompt), systemPrompt, resolvedModel, depth, rawTools, agentId, maxTokens);
|
|
126
142
|
}
|
|
127
143
|
const contents = this.preparePrompt(prompt);
|
|
128
144
|
if (depth === 0) {
|
|
129
145
|
this.startFlow(flowId);
|
|
130
146
|
}
|
|
131
|
-
await this.streamWithContents(llmStream, flowId, contents, systemPrompt, resolvedModel, depth, tools, rawTools, agentId);
|
|
147
|
+
await this.streamWithContents(llmStream, flowId, contents, systemPrompt, resolvedModel, depth, tools, rawTools, agentId, maxTokens);
|
|
132
148
|
}
|
|
133
149
|
/**
|
|
134
150
|
* Core streaming method that handles both initial and continuation turns.
|
|
135
151
|
*/
|
|
136
|
-
async streamWithContents(llmStream, flowId, contents, systemPrompt, resolvedModel, depth, tools, rawTools, agentId) {
|
|
152
|
+
async streamWithContents(llmStream, flowId, contents, systemPrompt, resolvedModel, depth, tools, rawTools, agentId, maxTokens) {
|
|
137
153
|
const flowState = this.flowStates.get(flowId);
|
|
154
|
+
const systemInstructionContent = systemPrompt?.trim()
|
|
155
|
+
? { role: 'system', parts: [{ text: systemPrompt.trim() }] }
|
|
156
|
+
: undefined;
|
|
138
157
|
const request = {
|
|
139
158
|
contents,
|
|
140
|
-
systemInstruction:
|
|
159
|
+
systemInstruction: systemInstructionContent,
|
|
141
160
|
tools: tools && tools.length ? tools : undefined,
|
|
142
161
|
};
|
|
143
162
|
try {
|
|
144
163
|
const generativeModel = this.vertexAI.getGenerativeModel({
|
|
145
164
|
model: resolvedModel,
|
|
165
|
+
systemInstruction: systemInstructionContent,
|
|
146
166
|
generationConfig: {
|
|
147
|
-
maxOutputTokens:
|
|
167
|
+
maxOutputTokens: maxTokens || GEMINI_DEFAULT_MAX_TOKENS,
|
|
148
168
|
},
|
|
149
169
|
});
|
|
150
170
|
const streamResult = await generativeModel.generateContentStream(request);
|
|
151
171
|
let inputTokens = 0;
|
|
152
172
|
let outputTokens = 0;
|
|
173
|
+
let finishReason;
|
|
153
174
|
const functionCalls = [];
|
|
154
175
|
const modelResponseParts = [];
|
|
155
176
|
for await (const chunk of streamResult.stream) {
|
|
@@ -169,12 +190,18 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
169
190
|
}
|
|
170
191
|
}
|
|
171
192
|
}
|
|
193
|
+
if (chunk.candidates?.[0]?.finishReason) {
|
|
194
|
+
finishReason = chunk.candidates[0].finishReason;
|
|
195
|
+
}
|
|
172
196
|
// Extract usage metadata
|
|
173
197
|
if (chunk.usageMetadata) {
|
|
174
198
|
inputTokens = chunk.usageMetadata.promptTokenCount ?? 0;
|
|
175
199
|
outputTokens = chunk.usageMetadata.candidatesTokenCount ?? 0;
|
|
176
200
|
}
|
|
177
201
|
}
|
|
202
|
+
if (finishReason === 'MAX_TOKENS') {
|
|
203
|
+
console.warn(`[GCloud] Stream stopped because maxOutputTokens limit (${maxTokens || GEMINI_DEFAULT_MAX_TOKENS}) was reached (output tokens: ${outputTokens}). Response was truncated!`);
|
|
204
|
+
}
|
|
178
205
|
// Emit cost
|
|
179
206
|
const totalTokens = inputTokens + outputTokens;
|
|
180
207
|
if (totalTokens > 0) {
|
|
@@ -209,7 +236,7 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
209
236
|
{ role: 'function', parts: functionResponseParts },
|
|
210
237
|
];
|
|
211
238
|
// Recurse
|
|
212
|
-
return this.streamWithContents(llmStream, flowId, continuationContents, systemPrompt, resolvedModel, depth + 1, tools, rawTools, agentId);
|
|
239
|
+
return this.streamWithContents(llmStream, flowId, continuationContents, systemPrompt, resolvedModel, depth + 1, tools, rawTools, agentId, maxTokens);
|
|
213
240
|
}
|
|
214
241
|
// Mark flow complete
|
|
215
242
|
flowState.finished = true;
|
|
@@ -217,6 +244,14 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
217
244
|
this.flowStates.delete(flowId);
|
|
218
245
|
}
|
|
219
246
|
catch (error) {
|
|
247
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
248
|
+
const isSystemPromptUnsupported = Boolean(systemPrompt && systemPrompt.trim()) &&
|
|
249
|
+
/system\s*instruction/i.test(errorMessage);
|
|
250
|
+
if (isSystemPromptUnsupported && !flowState.aborted) {
|
|
251
|
+
console.warn(`[GCloud] Model ${resolvedModel} does not accept systemPrompt as systemInstruction (${errorMessage}). Appending systemPrompt to agent instructions and retrying...`);
|
|
252
|
+
const fallbackContents = this.appendSystemPromptToContents(contents, systemPrompt);
|
|
253
|
+
return this.streamWithContents(llmStream, flowId, fallbackContents, '', resolvedModel, depth, tools, rawTools, agentId, maxTokens);
|
|
254
|
+
}
|
|
220
255
|
console.error(`GCloud stream error for flow ${flowId}:`, error);
|
|
221
256
|
this.emitError(llmStream, error);
|
|
222
257
|
flowState.finished = true;
|
|
@@ -228,7 +263,7 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
228
263
|
* Claude on Vertex AI — mirrors BedrockConverseConnector:
|
|
229
264
|
* streams text, collects tool_use blocks, executes approved tools and recurses with tool results.
|
|
230
265
|
*/
|
|
231
|
-
async streamAnthropic(llmStream, flowId, messages, systemPrompt, resolvedModel, depth, rawTools, agentId) {
|
|
266
|
+
async streamAnthropic(llmStream, flowId, messages, systemPrompt, resolvedModel, depth, rawTools, agentId, maxTokens) {
|
|
232
267
|
const flowState = this.flowStates.get(flowId);
|
|
233
268
|
const tools = rawTools?.length
|
|
234
269
|
? this.formatAnthropicTools(rawTools)
|
|
@@ -237,7 +272,7 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
237
272
|
const anthropic = await this.getAnthropic();
|
|
238
273
|
const stream = await anthropic.messages.create({
|
|
239
274
|
model: resolvedModel,
|
|
240
|
-
max_tokens:
|
|
275
|
+
max_tokens: maxTokens || ANTHROPIC_DEFAULT_MAX_TOKENS,
|
|
241
276
|
system: systemPrompt || undefined,
|
|
242
277
|
messages,
|
|
243
278
|
tools,
|
|
@@ -335,7 +370,7 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
335
370
|
{ role: 'assistant', content: assistantContent },
|
|
336
371
|
{ role: 'user', content: toolResults },
|
|
337
372
|
];
|
|
338
|
-
return this.streamAnthropic(llmStream, flowId, continuation, systemPrompt, resolvedModel, depth + 1, rawTools, agentId);
|
|
373
|
+
return this.streamAnthropic(llmStream, flowId, continuation, systemPrompt, resolvedModel, depth + 1, rawTools, agentId, maxTokens);
|
|
339
374
|
}
|
|
340
375
|
flowState.finished = true;
|
|
341
376
|
llmStream.emitEnd(flowState.aborted);
|
|
@@ -353,17 +388,21 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
353
388
|
* Generate image(s) via Vertex AI (Nano Banana / Imagen) and emit IMAGE_GENERATED events.
|
|
354
389
|
* The signaling layer attaches generated images to the message and renders it in the media widget.
|
|
355
390
|
*/
|
|
356
|
-
async generateImage(llmStream, flowId, prompt, resolvedModel) {
|
|
391
|
+
async generateImage(llmStream, flowId, prompt, resolvedModel, systemPrompt) {
|
|
357
392
|
this.startFlow(flowId);
|
|
358
393
|
const flowState = this.flowStates.get(flowId);
|
|
394
|
+
const effectivePrompt = systemPrompt
|
|
395
|
+
? this.appendSystemPromptToInstructions(prompt, systemPrompt)
|
|
396
|
+
: prompt;
|
|
359
397
|
try {
|
|
360
398
|
const imageModel = this.imageVertexAI.getGenerativeModel({
|
|
361
399
|
model: resolvedModel,
|
|
362
400
|
// Gemini image models have to be asked for image output explicitly
|
|
363
401
|
generationConfig: { responseModalities: ['TEXT', 'IMAGE'] },
|
|
364
402
|
});
|
|
403
|
+
const contents = await this.prepareImagePrompt(effectivePrompt);
|
|
365
404
|
const result = await imageModel.generateContent({
|
|
366
|
-
contents
|
|
405
|
+
contents,
|
|
367
406
|
});
|
|
368
407
|
const response = result.response;
|
|
369
408
|
const parts = response?.candidates?.[0]?.content?.parts;
|
|
@@ -434,19 +473,90 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
434
473
|
}
|
|
435
474
|
}
|
|
436
475
|
formatTools(rawTools) {
|
|
437
|
-
const functionDeclarations = rawTools.map((ot) =>
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
476
|
+
const functionDeclarations = rawTools.map((ot) => {
|
|
477
|
+
const rawSchema = ot.definition?.inputSchema ?? ot.definition?.parameters ?? ot.definition;
|
|
478
|
+
let jsonSchema;
|
|
479
|
+
try {
|
|
480
|
+
jsonSchema = (0, ai_1.asSchema)(rawSchema).jsonSchema;
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
jsonSchema = rawSchema && typeof rawSchema === 'object' && rawSchema.type ? rawSchema : { type: 'object', properties: {} };
|
|
484
|
+
}
|
|
485
|
+
const cleanSchema = this.toVertexSchema(jsonSchema);
|
|
486
|
+
const parameters = {
|
|
487
|
+
type: vertexai_1.FunctionDeclarationSchemaType.OBJECT,
|
|
488
|
+
properties: cleanSchema.properties || {},
|
|
489
|
+
required: cleanSchema.required?.length ? cleanSchema.required : undefined,
|
|
490
|
+
description: cleanSchema.description,
|
|
491
|
+
};
|
|
492
|
+
return {
|
|
493
|
+
name: ot.name,
|
|
494
|
+
description: ot.description || ot.name,
|
|
495
|
+
parameters,
|
|
496
|
+
};
|
|
497
|
+
});
|
|
442
498
|
return [{ functionDeclarations }];
|
|
443
499
|
}
|
|
500
|
+
toVertexSchema(schema) {
|
|
501
|
+
if (!schema || typeof schema !== 'object') {
|
|
502
|
+
return schema;
|
|
503
|
+
}
|
|
504
|
+
const result = {};
|
|
505
|
+
if (schema.type) {
|
|
506
|
+
if (typeof schema.type === 'string') {
|
|
507
|
+
const upper = schema.type.toUpperCase();
|
|
508
|
+
result.type = vertexai_1.SchemaType[upper] || upper;
|
|
509
|
+
}
|
|
510
|
+
else if (Array.isArray(schema.type)) {
|
|
511
|
+
const primary = schema.type.find((t) => t !== 'null') || 'string';
|
|
512
|
+
const upper = String(primary).toUpperCase();
|
|
513
|
+
result.type = vertexai_1.SchemaType[upper] || upper;
|
|
514
|
+
if (schema.type.includes('null')) {
|
|
515
|
+
result.nullable = true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else if (schema.properties) {
|
|
520
|
+
result.type = vertexai_1.SchemaType.OBJECT;
|
|
521
|
+
}
|
|
522
|
+
if (schema.description) {
|
|
523
|
+
result.description = schema.description;
|
|
524
|
+
}
|
|
525
|
+
if (schema.format) {
|
|
526
|
+
result.format = schema.format;
|
|
527
|
+
}
|
|
528
|
+
if (schema.nullable !== undefined) {
|
|
529
|
+
result.nullable = Boolean(schema.nullable);
|
|
530
|
+
}
|
|
531
|
+
if (Array.isArray(schema.enum)) {
|
|
532
|
+
result.enum = schema.enum.map(String);
|
|
533
|
+
}
|
|
534
|
+
if (schema.properties && typeof schema.properties === 'object') {
|
|
535
|
+
result.properties = {};
|
|
536
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
537
|
+
result.properties[key] = this.toVertexSchema(prop);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (Array.isArray(schema.required) && schema.required.length > 0) {
|
|
541
|
+
result.required = schema.required.map(String);
|
|
542
|
+
}
|
|
543
|
+
if (schema.items) {
|
|
544
|
+
result.items = this.toVertexSchema(schema.items);
|
|
545
|
+
}
|
|
546
|
+
else if (result.type === vertexai_1.SchemaType.ARRAY) {
|
|
547
|
+
result.items = { type: vertexai_1.SchemaType.STRING };
|
|
548
|
+
}
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
444
551
|
formatAnthropicTools(rawTools) {
|
|
445
|
-
return rawTools.map((ot) =>
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
552
|
+
return rawTools.map((ot) => {
|
|
553
|
+
const rawSchema = ot.definition?.inputSchema ?? ot.definition?.parameters ?? ot.definition;
|
|
554
|
+
return {
|
|
555
|
+
name: ot.name,
|
|
556
|
+
description: ot.description || ot.name,
|
|
557
|
+
input_schema: (0, ai_1.asSchema)(rawSchema).jsonSchema,
|
|
558
|
+
};
|
|
559
|
+
});
|
|
450
560
|
}
|
|
451
561
|
resolveModelId(model) {
|
|
452
562
|
return GCLOUD_MODEL_IDS[model] || model;
|
|
@@ -477,6 +587,77 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
477
587
|
catch (e) {
|
|
478
588
|
// Expected for plain text prompts — fall through
|
|
479
589
|
}
|
|
590
|
+
// Extract any inline data URLs (e.g. data:image/png;base64,...) from prompt so they become visual inlineData parts
|
|
591
|
+
const parts = [];
|
|
592
|
+
const dataUrlRegex = /data:(image\/[a-zA-Z0-9.+_-]+);base64,([A-Za-z0-9+/=]+)/g;
|
|
593
|
+
const inlineImages = [];
|
|
594
|
+
let match;
|
|
595
|
+
while ((match = dataUrlRegex.exec(prompt)) !== null) {
|
|
596
|
+
inlineImages.push({
|
|
597
|
+
mimeType: match[1],
|
|
598
|
+
data: match[2],
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
if (inlineImages.length > 0) {
|
|
602
|
+
const cleanedText = prompt.replace(dataUrlRegex, '[Input Image Reference]');
|
|
603
|
+
parts.push({ text: cleanedText });
|
|
604
|
+
for (const img of inlineImages) {
|
|
605
|
+
parts.push({
|
|
606
|
+
inlineData: {
|
|
607
|
+
mimeType: img.mimeType,
|
|
608
|
+
data: img.data,
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
return [{ role: 'user', parts }];
|
|
613
|
+
}
|
|
614
|
+
return [{ role: 'user', parts: [{ text: prompt }] }];
|
|
615
|
+
}
|
|
616
|
+
async prepareImagePrompt(prompt) {
|
|
617
|
+
const parts = [];
|
|
618
|
+
const inlineImages = [];
|
|
619
|
+
// 1. Extract any inline data URLs (e.g. data:image/png;base64,...)
|
|
620
|
+
const dataUrlRegex = /data:(image\/[a-zA-Z0-9.+_-]+);base64,([A-Za-z0-9+/=]+)/g;
|
|
621
|
+
let match;
|
|
622
|
+
while ((match = dataUrlRegex.exec(prompt)) !== null) {
|
|
623
|
+
inlineImages.push({
|
|
624
|
+
mimeType: match[1],
|
|
625
|
+
data: match[2],
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
// 2. Extract any http(s) image URLs from prompt
|
|
629
|
+
const httpUrlRegex = /(?:Base Image URL to Modify|Image URL):\s*(https?:\/\/[^\s"'<>]+)/g;
|
|
630
|
+
while ((match = httpUrlRegex.exec(prompt)) !== null) {
|
|
631
|
+
const imageUrl = match[1];
|
|
632
|
+
try {
|
|
633
|
+
const res = await fetch(imageUrl);
|
|
634
|
+
if (res.ok) {
|
|
635
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
636
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
637
|
+
const mimeType = res.headers.get('content-type') || 'image/jpeg';
|
|
638
|
+
inlineImages.push({
|
|
639
|
+
mimeType,
|
|
640
|
+
data: buffer.toString('base64'),
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
catch (err) {
|
|
645
|
+
console.warn(`[GCloudConverseConnector] Failed to fetch image reference from ${imageUrl}:`, err);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const cleanedText = prompt.replace(dataUrlRegex, '[Input Image Reference]');
|
|
649
|
+
if (inlineImages.length > 0) {
|
|
650
|
+
parts.push({ text: cleanedText });
|
|
651
|
+
for (const img of inlineImages) {
|
|
652
|
+
parts.push({
|
|
653
|
+
inlineData: {
|
|
654
|
+
mimeType: img.mimeType,
|
|
655
|
+
data: img.data,
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
return [{ role: 'user', parts }];
|
|
660
|
+
}
|
|
480
661
|
return [{ role: 'user', parts: [{ text: prompt }] }];
|
|
481
662
|
}
|
|
482
663
|
ozzyMessagesToVertexContents(ozzyMessages) {
|
|
@@ -497,6 +678,62 @@ class GCloudConverseConnector extends LlmConverseConnector_js_1.LlmConverseConne
|
|
|
497
678
|
return 'user';
|
|
498
679
|
}
|
|
499
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Appends systemPrompt to the instructions / prompt when a model does not accept systemPrompt natively.
|
|
683
|
+
*/
|
|
684
|
+
appendSystemPromptToInstructions(prompt, systemPrompt) {
|
|
685
|
+
if (!systemPrompt || !systemPrompt.trim()) {
|
|
686
|
+
return prompt;
|
|
687
|
+
}
|
|
688
|
+
const trimmedSystemPrompt = systemPrompt.trim();
|
|
689
|
+
try {
|
|
690
|
+
const parsed = JSON.parse(prompt);
|
|
691
|
+
if (Array.isArray(parsed) && parsed.length > 0 && parsed[0].role) {
|
|
692
|
+
// Look for the user turn to append instructions
|
|
693
|
+
const lastUser = [...parsed].reverse().find((m) => m.role === 'user') || parsed[parsed.length - 1];
|
|
694
|
+
if (lastUser && !lastUser.text.includes(trimmedSystemPrompt)) {
|
|
695
|
+
lastUser.text = lastUser.text
|
|
696
|
+
? `${lastUser.text}\n\nInstructions:\n${trimmedSystemPrompt}`
|
|
697
|
+
: trimmedSystemPrompt;
|
|
698
|
+
}
|
|
699
|
+
return JSON.stringify(parsed);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
catch {
|
|
703
|
+
// Expected for plain text prompts
|
|
704
|
+
}
|
|
705
|
+
if (prompt && prompt.includes(trimmedSystemPrompt)) {
|
|
706
|
+
return prompt;
|
|
707
|
+
}
|
|
708
|
+
return prompt && prompt.trim()
|
|
709
|
+
? `${prompt.trim()}\n\nInstructions:\n${trimmedSystemPrompt}`
|
|
710
|
+
: trimmedSystemPrompt;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Appends systemPrompt to Vertex Content[] when falling back from an unsupported systemInstruction.
|
|
714
|
+
*/
|
|
715
|
+
appendSystemPromptToContents(contents, systemPrompt) {
|
|
716
|
+
if (!systemPrompt || !systemPrompt.trim() || !contents.length) {
|
|
717
|
+
return contents;
|
|
718
|
+
}
|
|
719
|
+
const trimmed = systemPrompt.trim();
|
|
720
|
+
const cloned = contents.map((c) => ({
|
|
721
|
+
role: c.role,
|
|
722
|
+
parts: c.parts.map((p) => ({ ...p })),
|
|
723
|
+
}));
|
|
724
|
+
// Find the first or last user message to append instructions
|
|
725
|
+
const userTurn = cloned.find((c) => c.role === 'user') || cloned[0];
|
|
726
|
+
const textPart = userTurn.parts.find((p) => typeof p.text === 'string');
|
|
727
|
+
if (textPart && typeof textPart.text === 'string') {
|
|
728
|
+
if (!textPart.text.includes(trimmed)) {
|
|
729
|
+
textPart.text = `${textPart.text}\n\nInstructions:\n${trimmed}`;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
userTurn.parts.push({ text: `Instructions:\n${trimmed}` });
|
|
734
|
+
}
|
|
735
|
+
return cloned;
|
|
736
|
+
}
|
|
500
737
|
}
|
|
501
738
|
exports.GCloudConverseConnector = GCloudConverseConnector;
|
|
502
739
|
//# sourceMappingURL=GCloudConverseConnector.js.map
|