@valerypopoff/rivet2-core 2.1.8 → 2.1.9
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/cjs/bundle.cjs +1922 -1125
- package/dist/cjs/bundle.cjs.map +4 -4
- package/dist/esm/model/GraphProcessor.js +1 -0
- package/dist/esm/model/SplitRunProcessor.js +19 -10
- package/dist/esm/model/ToolCallContinuationCoordinator.js +6 -1
- package/dist/esm/model/chat/aiSdkMessages.js +8 -0
- package/dist/esm/model/chat-v2/chatV2CallObserver.js +2 -0
- package/dist/esm/model/chat-v2/chatV2EditorCache.js +22 -0
- package/dist/esm/model/chat-v2/chatV2Outputs.js +41 -31
- package/dist/esm/model/chat-v2/chatV2Pipeline.js +122 -44
- package/dist/esm/model/chat-v2/chatV2ProviderProfile.js +1 -0
- package/dist/esm/model/chat-v2/chatV2RequestPlan.js +6 -5
- package/dist/esm/model/chat-v2/chatV2Shared.js +1 -6
- package/dist/esm/model/chat-v2/chatV2Types.js +11 -1
- package/dist/esm/model/chat-v2/developerMessageRoles.js +45 -0
- package/dist/esm/model/chat-v2/llmChatV2NodeData.js +3 -5
- package/dist/esm/model/chat-v2/llmChatV2NodeEditors.js +22 -13
- package/dist/esm/model/chat-v2/llmChatV2NodeRuntime.js +224 -68
- package/dist/esm/model/chat-v2/llmProfile.js +21 -0
- package/dist/esm/model/chat-v2/llmProfileFallback.js +288 -0
- package/dist/esm/model/chat-v2/messageConverter.js +14 -0
- package/dist/esm/model/chat-v2/providerOptions.js +44 -11
- package/dist/esm/model/chat-v2/toolContinuation.js +0 -4
- package/dist/esm/model/nodes/AssembleMessageNode.js +6 -0
- package/dist/esm/model/nodes/DelegateFunctionCallNode.js +12 -0
- package/dist/esm/model/nodes/LLMChatV2Node.js +115 -11
- package/dist/esm/model/nodes/PromptNode.js +9 -2
- package/dist/esm/model/nodes/toolCallDelegation.js +18 -2
- package/dist/esm/plugins/anthropic/nodes/ChatAnthropicNode.js +22 -28
- package/dist/esm/plugins/google/google.js +20 -9
- package/dist/esm/plugins/google/nodes/ChatGoogleNode.js +17 -6
- package/dist/esm/utils/chatMessageToOpenAIChatCompletionMessage.js +4 -0
- package/dist/esm/utils/serialization/serialization.js +19 -0
- package/dist/types/model/DataValue.d.ts +7 -1
- package/dist/types/model/NodeBase.d.ts +6 -0
- package/dist/types/model/ProcessContext.d.ts +4 -0
- package/dist/types/model/SplitRunProcessor.d.ts +2 -1
- package/dist/types/model/chat-v2/chatV2EditorCache.d.ts +4 -0
- package/dist/types/model/chat-v2/chatV2Outputs.d.ts +5 -5
- package/dist/types/model/chat-v2/chatV2Pipeline.d.ts +33 -0
- package/dist/types/model/chat-v2/chatV2ProviderProfile.d.ts +1 -0
- package/dist/types/model/chat-v2/chatV2RequestPlan.d.ts +2 -2
- package/dist/types/model/chat-v2/chatV2Shared.d.ts +0 -1
- package/dist/types/model/chat-v2/chatV2Types.d.ts +24 -0
- package/dist/types/model/chat-v2/developerMessageRoles.d.ts +10 -0
- package/dist/types/model/chat-v2/llmChatV2NodeData.d.ts +4 -1
- package/dist/types/model/chat-v2/llmChatV2NodeRuntime.d.ts +18 -2
- package/dist/types/model/chat-v2/llmProfile.d.ts +7 -0
- package/dist/types/model/chat-v2/llmProfileFallback.d.ts +79 -0
- package/dist/types/model/chat-v2/providerOptions.d.ts +1 -0
- package/dist/types/model/nodes/AssembleMessageNode.d.ts +2 -1
- package/dist/types/model/nodes/PromptNode.d.ts +2 -2
- package/dist/types/plugins/google/google.d.ts +12 -1
- package/dist/types/plugins/google/nodes/ChatGoogleNode.d.ts +2 -1
- package/package.json +1 -1
|
@@ -102,6 +102,7 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
102
102
|
label: 'Type',
|
|
103
103
|
options: [
|
|
104
104
|
{ value: 'system', label: 'System' },
|
|
105
|
+
{ value: 'developer', label: 'Developer' },
|
|
105
106
|
{ value: 'user', label: 'User' },
|
|
106
107
|
{ value: 'assistant', label: 'Assistant' },
|
|
107
108
|
{ value: 'function', label: 'Function' },
|
|
@@ -162,7 +163,7 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
162
163
|
static getUIData() {
|
|
163
164
|
return {
|
|
164
165
|
infoBoxBody: dedent `
|
|
165
|
-
Outputs a chat message, which is a string of text with an attached "type" saying who sent the message (User, Assistant, System) and optionally an attached "name".
|
|
166
|
+
Outputs a chat message, which is a string of text with an attached "type" saying who sent the message (User, Assistant, System, Developer) and optionally an attached "name".
|
|
166
167
|
|
|
167
168
|
Also provides the same <span style="color: var(--primary)">{{interpolation}}</span> capabilities as a Text node.
|
|
168
169
|
|
|
@@ -182,7 +183,7 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
182
183
|
outputValue = outputValue.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
183
184
|
const type = getInputOrData(this.data, inputs, 'type', 'string');
|
|
184
185
|
const isCacheBreakpoint = getInputOrData(this.data, inputs, 'isCacheBreakpoint', 'boolean');
|
|
185
|
-
if (['assistant', 'system', 'user', 'function'].includes(type) === false) {
|
|
186
|
+
if (['assistant', 'system', 'developer', 'user', 'function'].includes(type) === false) {
|
|
186
187
|
throw new Error(`Invalid type: ${type}`);
|
|
187
188
|
}
|
|
188
189
|
const message = match(type)
|
|
@@ -190,6 +191,11 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
190
191
|
type,
|
|
191
192
|
message: outputValue,
|
|
192
193
|
isCacheBreakpoint,
|
|
194
|
+
}))
|
|
195
|
+
.with('developer', (type) => ({
|
|
196
|
+
type,
|
|
197
|
+
message: outputValue,
|
|
198
|
+
isCacheBreakpoint,
|
|
193
199
|
}))
|
|
194
200
|
.with('user', (type) => ({
|
|
195
201
|
type,
|
|
@@ -246,6 +252,7 @@ export class PromptNodeImpl extends NodeImpl {
|
|
|
246
252
|
export const promptNode = nodeDefinition(PromptNodeImpl, 'Prompt');
|
|
247
253
|
const typeDisplay = {
|
|
248
254
|
assistant: 'Assistant',
|
|
255
|
+
developer: 'Developer',
|
|
249
256
|
system: 'System',
|
|
250
257
|
user: 'User',
|
|
251
258
|
function: 'Function',
|
|
@@ -43,6 +43,15 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
43
43
|
};
|
|
44
44
|
const outputs = records.length === 1
|
|
45
45
|
? {
|
|
46
|
+
['assistant-message']: preToolMessageOutput,
|
|
47
|
+
['tool-name']: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
value: records[0].name,
|
|
50
|
+
},
|
|
51
|
+
['tool-arguments']: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
value: records[0].arguments,
|
|
54
|
+
},
|
|
46
55
|
['output']: {
|
|
47
56
|
type: 'string',
|
|
48
57
|
value: records[0].output,
|
|
@@ -51,9 +60,17 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
51
60
|
type: 'chat-message',
|
|
52
61
|
value: records[0].message,
|
|
53
62
|
},
|
|
54
|
-
['assistant-message']: preToolMessageOutput,
|
|
55
63
|
}
|
|
56
64
|
: {
|
|
65
|
+
['assistant-message']: preToolMessageOutput,
|
|
66
|
+
['tool-name']: {
|
|
67
|
+
type: 'string[]',
|
|
68
|
+
value: records.map((record) => record.name),
|
|
69
|
+
},
|
|
70
|
+
['tool-arguments']: {
|
|
71
|
+
type: 'object[]',
|
|
72
|
+
value: records.map((record) => record.arguments),
|
|
73
|
+
},
|
|
57
74
|
['output']: {
|
|
58
75
|
type: 'string[]',
|
|
59
76
|
value: records.map((record) => record.output),
|
|
@@ -62,7 +79,6 @@ export function buildDelegatedToolCallOutputs(records, preToolMessage, cost) {
|
|
|
62
79
|
type: 'chat-message[]',
|
|
63
80
|
value: records.map((record) => record.message),
|
|
64
81
|
},
|
|
65
|
-
['assistant-message']: preToolMessageOutput,
|
|
66
82
|
};
|
|
67
83
|
if (cost != null) {
|
|
68
84
|
outputs['cost'] = { type: 'number', value: cost };
|
|
@@ -338,15 +338,16 @@ export const ChatAnthropicNodeImpl = {
|
|
|
338
338
|
return acc;
|
|
339
339
|
}, '');
|
|
340
340
|
prompt += '\n\nAssistant:';
|
|
341
|
-
|
|
342
|
-
const system =
|
|
341
|
+
const useMessageApi = model.startsWith('claude-3') || model.startsWith('claude-sonnet') || model.startsWith('claude-opus');
|
|
342
|
+
const system = useMessageApi ? getSystemPrompt(inputs) : undefined;
|
|
343
343
|
let { maxTokens } = data;
|
|
344
344
|
const tokenizerInfo = {
|
|
345
345
|
node: context.node,
|
|
346
346
|
model,
|
|
347
347
|
endpoint: undefined,
|
|
348
348
|
};
|
|
349
|
-
const
|
|
349
|
+
const systemText = typeof system === 'string' ? system : system?.map((message) => message.text).join('\n\n');
|
|
350
|
+
const tokenCountEstimate = await context.tokenizer.getTokenCountForString([systemText, prompt].filter(Boolean).join('\n\n'), tokenizerInfo);
|
|
350
351
|
const modelInfo = anthropicModels[model] ?? {
|
|
351
352
|
maxTokens: Number.MAX_SAFE_INTEGER,
|
|
352
353
|
cost: {
|
|
@@ -389,7 +390,6 @@ export const ChatAnthropicNodeImpl = {
|
|
|
389
390
|
? tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.parameters }))
|
|
390
391
|
: undefined,
|
|
391
392
|
};
|
|
392
|
-
const useMessageApi = model.startsWith('claude-3') || model.startsWith('claude-sonnet') || model.startsWith('claude-opus');
|
|
393
393
|
const cacheKey = JSON.stringify(useMessageApi ? messageOptions : completionOptions);
|
|
394
394
|
if (data.cache) {
|
|
395
395
|
const cached = cache.get(cacheKey);
|
|
@@ -618,34 +618,28 @@ export const chatAnthropicNode = pluginNodeDefinition(ChatAnthropicNodeImpl, 'Ch
|
|
|
618
618
|
export function getSystemPrompt(inputs) {
|
|
619
619
|
const systemInput = inputs['system'];
|
|
620
620
|
const system = coerceTypeOptional(systemInput, 'string');
|
|
621
|
+
const systemMessages = [];
|
|
621
622
|
if (system) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
?
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
},
|
|
632
|
-
];
|
|
623
|
+
systemMessages.push({
|
|
624
|
+
type: 'text',
|
|
625
|
+
text: system,
|
|
626
|
+
cache_control: systemInput?.type === 'chat-message'
|
|
627
|
+
? systemInput.value.isCacheBreakpoint
|
|
628
|
+
? { type: 'ephemeral' }
|
|
629
|
+
: null
|
|
630
|
+
: null,
|
|
631
|
+
});
|
|
633
632
|
}
|
|
634
|
-
const
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
type: 'text',
|
|
641
|
-
text: coerceType({ type: 'chat-message', value: message }, 'string'),
|
|
642
|
-
cache_control: message.isCacheBreakpoint ? { type: 'ephemeral' } : null,
|
|
643
|
-
};
|
|
633
|
+
for (const message of coercePromptToChatMessages(inputs['prompt'])) {
|
|
634
|
+
if (message.type === 'system' || message.type === 'developer') {
|
|
635
|
+
systemMessages.push({
|
|
636
|
+
type: 'text',
|
|
637
|
+
text: coerceType({ type: 'chat-message', value: message }, 'string'),
|
|
638
|
+
cache_control: message.isCacheBreakpoint ? { type: 'ephemeral' } : null,
|
|
644
639
|
});
|
|
645
|
-
return converted;
|
|
646
640
|
}
|
|
647
641
|
}
|
|
648
|
-
return undefined;
|
|
642
|
+
return systemMessages.length > 0 ? systemMessages : undefined;
|
|
649
643
|
}
|
|
650
644
|
function getChatMessages(inputs) {
|
|
651
645
|
const prompt = inputs['prompt'];
|
|
@@ -670,7 +664,7 @@ export async function chatMessagesToClaude3ChatMessages(chatMessages) {
|
|
|
670
664
|
return combinedMessages;
|
|
671
665
|
}
|
|
672
666
|
async function chatMessageToClaude3ChatMessage(message) {
|
|
673
|
-
if (message.type === 'system') {
|
|
667
|
+
if (message.type === 'system' || message.type === 'developer') {
|
|
674
668
|
return undefined;
|
|
675
669
|
}
|
|
676
670
|
if (message.type === 'function') {
|
|
@@ -83,6 +83,18 @@ export const generativeAiOptions = Object.entries(generativeAiGoogleModels).map(
|
|
|
83
83
|
value: id,
|
|
84
84
|
label: displayName,
|
|
85
85
|
}));
|
|
86
|
+
export function getVertexGenerativeModelOptions(options) {
|
|
87
|
+
return {
|
|
88
|
+
model: options.model,
|
|
89
|
+
systemInstruction: options.systemPrompt,
|
|
90
|
+
generationConfig: {
|
|
91
|
+
maxOutputTokens: options.max_output_tokens,
|
|
92
|
+
temperature: options.temperature,
|
|
93
|
+
topP: options.top_p,
|
|
94
|
+
topK: options.top_k,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
86
98
|
export async function* streamGenerativeAi({ apiKey, model, systemPrompt, prompt, maxOutputTokens, temperature, topP, topK, signal, tools, thinkingBudget, additionalHeaders, }) {
|
|
87
99
|
const { GoogleGenAI } = await import('@google/genai');
|
|
88
100
|
const genAi = new GoogleGenAI({ apiKey });
|
|
@@ -127,21 +139,20 @@ export async function* streamGenerativeAi({ apiKey, model, systemPrompt, prompt,
|
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
141
|
}
|
|
130
|
-
export async function* streamChatCompletions({ project, location, applicationCredentials, model, signal, max_output_tokens, temperature, top_p, top_k, prompt, }) {
|
|
142
|
+
export async function* streamChatCompletions({ project, location, applicationCredentials, model, signal, max_output_tokens, temperature, top_p, top_k, systemPrompt, prompt, }) {
|
|
131
143
|
// Dynamic import: the Google auth library fails under static CJS require.
|
|
132
144
|
const { VertexAI } = await import('@google-cloud/vertexai');
|
|
133
145
|
// Can't find a way to pass the credentials path in
|
|
134
146
|
process.env.GOOGLE_APPLICATION_CREDENTIALS = applicationCredentials;
|
|
135
147
|
const vertexAi = new VertexAI({ project, location });
|
|
136
|
-
const generativeModel = vertexAi.preview.getGenerativeModel({
|
|
148
|
+
const generativeModel = vertexAi.preview.getGenerativeModel(getVertexGenerativeModelOptions({
|
|
137
149
|
model,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
150
|
+
systemPrompt,
|
|
151
|
+
max_output_tokens,
|
|
152
|
+
temperature,
|
|
153
|
+
top_p,
|
|
154
|
+
top_k,
|
|
155
|
+
}));
|
|
145
156
|
const response = await generativeModel.generateContentStream({
|
|
146
157
|
contents: prompt,
|
|
147
158
|
});
|
|
@@ -273,14 +273,13 @@ export const ChatGoogleNodeImpl = {
|
|
|
273
273
|
},
|
|
274
274
|
async process(data, inputs, context) {
|
|
275
275
|
const output = {};
|
|
276
|
-
const systemPrompt = coerceTypeOptional(inputs['systemPrompt'], 'string');
|
|
277
276
|
const rawModel = getInputOrData(data, inputs, 'model');
|
|
278
277
|
const model = rawModel;
|
|
279
278
|
const temperature = getInputOrData(data, inputs, 'temperature', 'number');
|
|
280
279
|
const topP = getInputOrData(data, inputs, 'top_p', 'number');
|
|
281
280
|
const useTopP = getInputOrData(data, inputs, 'useTopP', 'boolean');
|
|
282
281
|
const thinkingBudget = getInputOrData(data, inputs, 'thinkingBudget', 'number');
|
|
283
|
-
const { messages } = getChatGoogleNodeMessages(inputs);
|
|
282
|
+
const { messages, systemPrompt } = getChatGoogleNodeMessages(inputs);
|
|
284
283
|
let prompt = await Promise.all(messages.map(async (message) => {
|
|
285
284
|
if (message.type === 'user' || message.type === 'assistant') {
|
|
286
285
|
const parts = await Promise.all([message.message].flat().map(async (part) => {
|
|
@@ -343,7 +342,7 @@ export const ChatGoogleNodeImpl = {
|
|
|
343
342
|
],
|
|
344
343
|
};
|
|
345
344
|
}
|
|
346
|
-
throw new Error(
|
|
345
|
+
throw new Error('Google Vertex AI received an unsupported message type.');
|
|
347
346
|
}));
|
|
348
347
|
// Collapse sequential function responses into a single function response with mutliple parts
|
|
349
348
|
prompt = prompt.reduce((acc, message) => {
|
|
@@ -368,7 +367,10 @@ export const ChatGoogleNodeImpl = {
|
|
|
368
367
|
endpoint: undefined,
|
|
369
368
|
};
|
|
370
369
|
// TODO Better token counting for Google models.
|
|
371
|
-
const
|
|
370
|
+
const tokenMessages = systemPrompt
|
|
371
|
+
? [{ type: 'system', message: systemPrompt }, ...messages]
|
|
372
|
+
: messages;
|
|
373
|
+
const tokenCount = await context.tokenizer.getTokenCountForMessages(tokenMessages, undefined, tokenizerInfo);
|
|
372
374
|
if (generativeAiGoogleModels[model]) {
|
|
373
375
|
maxTokens = clampMaxTokensToModelLimit(output, model, tokenCount, maxTokens, generativeAiGoogleModels[model].maxTokens);
|
|
374
376
|
}
|
|
@@ -478,6 +480,7 @@ export const ChatGoogleNodeImpl = {
|
|
|
478
480
|
temperature: useTopP ? undefined : temperature,
|
|
479
481
|
top_p: useTopP ? topP : undefined,
|
|
480
482
|
top_k: undefined,
|
|
483
|
+
systemPrompt,
|
|
481
484
|
project: project,
|
|
482
485
|
location: location,
|
|
483
486
|
applicationCredentials: applicationCredentials,
|
|
@@ -579,6 +582,14 @@ export const ChatGoogleNodeImpl = {
|
|
|
579
582
|
};
|
|
580
583
|
export const chatGoogleNode = pluginNodeDefinition(ChatGoogleNodeImpl, 'Chat (Google, Legacy)');
|
|
581
584
|
export function getChatGoogleNodeMessages(inputs) {
|
|
582
|
-
const
|
|
583
|
-
|
|
585
|
+
const promptMessages = coercePromptToChatMessages(inputs['prompt'], { requirePrompt: true });
|
|
586
|
+
const instructionMessages = promptMessages.filter((message) => message.type === 'system' || message.type === 'developer');
|
|
587
|
+
const systemPromptParts = [
|
|
588
|
+
coerceTypeOptional(inputs['systemPrompt'], 'string'),
|
|
589
|
+
...instructionMessages.map((message) => coerceTypeOptional({ type: 'chat-message', value: message }, 'string')),
|
|
590
|
+
].filter((part) => !!part);
|
|
591
|
+
return {
|
|
592
|
+
messages: promptMessages.filter((message) => message.type !== 'system' && message.type !== 'developer'),
|
|
593
|
+
systemPrompt: systemPromptParts.length > 0 ? systemPromptParts.join('\n\n') : undefined,
|
|
594
|
+
};
|
|
584
595
|
}
|
|
@@ -28,6 +28,10 @@ export async function chatMessageToOpenAIChatCompletionMessage(message, options)
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
})
|
|
31
|
+
.with({ type: 'developer' }, (m) => ({
|
|
32
|
+
role: 'developer',
|
|
33
|
+
content: onlyStringContent(m),
|
|
34
|
+
}))
|
|
31
35
|
.with({ type: 'user' }, async (m) => {
|
|
32
36
|
const parts = Array.isArray(m.message) ? m.message : [m.message];
|
|
33
37
|
if (parts.length === 1 && typeof parts[0] === 'string') {
|
|
@@ -71,6 +71,24 @@ function hasLegacyDataBusFlag(node) {
|
|
|
71
71
|
const data = node.data;
|
|
72
72
|
return node.type === 'passthrough' && data != null && Object.hasOwn(data, 'renderAsDataBus');
|
|
73
73
|
}
|
|
74
|
+
function migrateLegacyLLMChatV2Diagnostics(node) {
|
|
75
|
+
if (node.type !== 'llmChatV2' || node.data == null || typeof node.data !== 'object') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const data = node.data;
|
|
79
|
+
if (data.outputRequestStatus !== true) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Output request details used to expose all three diagnostics together.
|
|
83
|
+
// Materialize the split settings on load so existing output connections and
|
|
84
|
+
// editor-visible behavior remain unchanged after the setting was separated.
|
|
85
|
+
if (!Object.hasOwn(data, 'outputRequestError')) {
|
|
86
|
+
data.outputRequestError = true;
|
|
87
|
+
}
|
|
88
|
+
if (!Object.hasOwn(data, 'outputRequestBody')) {
|
|
89
|
+
data.outputRequestBody = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
74
92
|
function normalizeDeserializedNode(node) {
|
|
75
93
|
if (node.type === 'code' && node.title === 'Code') {
|
|
76
94
|
node.title = 'Code (legacy)';
|
|
@@ -82,6 +100,7 @@ function normalizeDeserializedNode(node) {
|
|
|
82
100
|
const { renderAsDataBus: _legacyFlag, ...data } = node.data;
|
|
83
101
|
node.data = data;
|
|
84
102
|
}
|
|
103
|
+
migrateLegacyLLMChatV2Diagnostics(node);
|
|
85
104
|
}
|
|
86
105
|
function deserializeProjectByVersion(serializedProject, version) {
|
|
87
106
|
switch (version) {
|
|
@@ -15,6 +15,12 @@ export type SystemChatMessage = {
|
|
|
15
15
|
/** If true, this message marks a breakpoint when used with prompt caching (as of right now, Anthropic-only). */
|
|
16
16
|
isCacheBreakpoint?: boolean;
|
|
17
17
|
};
|
|
18
|
+
export type DeveloperChatMessage = {
|
|
19
|
+
type: 'developer';
|
|
20
|
+
message: ChatMessageMessagePart | ChatMessageMessagePart[];
|
|
21
|
+
/** If true, this message marks a breakpoint when used with prompt caching (as of right now, Anthropic-only). */
|
|
22
|
+
isCacheBreakpoint?: boolean;
|
|
23
|
+
};
|
|
18
24
|
export type UserChatMessage = {
|
|
19
25
|
type: 'user';
|
|
20
26
|
message: ChatMessageMessagePart | ChatMessageMessagePart[];
|
|
@@ -48,7 +54,7 @@ export type FunctionResponseChatMessage = {
|
|
|
48
54
|
/** If true, this message marks a breakpoint when used with prompt caching (as of right now, Anthropic-only). */
|
|
49
55
|
isCacheBreakpoint?: boolean;
|
|
50
56
|
};
|
|
51
|
-
export type ChatMessage = SystemChatMessage | UserChatMessage | AssistantChatMessage | FunctionResponseChatMessage;
|
|
57
|
+
export type ChatMessage = SystemChatMessage | DeveloperChatMessage | UserChatMessage | AssistantChatMessage | FunctionResponseChatMessage;
|
|
52
58
|
export type ChatMessageMessagePart = string | {
|
|
53
59
|
type: 'image';
|
|
54
60
|
mediaType: SupportedImageMediaTypes;
|
|
@@ -85,6 +85,12 @@ export type NodeInputDefinition = {
|
|
|
85
85
|
description?: string;
|
|
86
86
|
/** Will the input value attempt to be coerced into the desired type? */
|
|
87
87
|
coerced?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Whether an array on this port participates in a node's Many-runs fan-out.
|
|
90
|
+
* Most inputs retain the default `split`; configuration collections such as
|
|
91
|
+
* an LLM Profile fallback chain can opt into `preserve-array`.
|
|
92
|
+
*/
|
|
93
|
+
splitRunBehavior?: 'split' | 'preserve-array';
|
|
88
94
|
};
|
|
89
95
|
/** Represents an output definition of a node. */
|
|
90
96
|
export type NodeOutputDefinition = {
|
|
@@ -52,6 +52,10 @@ export type ChatV2CallFinishedEvent = {
|
|
|
52
52
|
callId: ChatV2CallId;
|
|
53
53
|
/** Zero-based attempt index within this Chat V2 pipeline request. */
|
|
54
54
|
attemptIndex: number;
|
|
55
|
+
/** Zero-based profile index when LLM Chat is using a profile fallback chain. */
|
|
56
|
+
profileIndex?: number;
|
|
57
|
+
/** Zero-based model round within one auto-continued LLM Chat invocation. */
|
|
58
|
+
roundIndex?: number;
|
|
55
59
|
nodeId: NodeId;
|
|
56
60
|
processId: ProcessId;
|
|
57
61
|
provider: ChatV2Provider;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type ChartNode } from './NodeBase.js';
|
|
1
|
+
import { type ChartNode, type NodeInputDefinition } from './NodeBase.js';
|
|
2
2
|
import type { ProcessId } from './ProcessContext.js';
|
|
3
3
|
import type { Inputs, Outputs } from './GraphProcessor.js';
|
|
4
4
|
export type SplitRunDeps = {
|
|
5
5
|
getInputValues(node: ChartNode): Inputs;
|
|
6
|
+
getInputDefinitions(node: ChartNode): NodeInputDefinition[];
|
|
6
7
|
isExcludedDueToControlFlow(node: ChartNode, inputValues: Inputs, processId: ProcessId): boolean;
|
|
7
8
|
processNodeWithInputData(node: ChartNode, inputs: Inputs, index: number, processId: ProcessId, partialOutput?: (node: ChartNode, partialOutputs: Outputs, index: number) => void): Promise<Outputs>;
|
|
8
9
|
splitRunConcurrency: number;
|
|
@@ -2,6 +2,7 @@ import type { Outputs } from '../GraphProcessor.js';
|
|
|
2
2
|
import type { ResolvedChatV2ProviderConfig } from './providerOptions.js';
|
|
3
3
|
import type { ChatV2Provider, ChatV2ProviderOptions, ChatV2ToolChoice } from './chatV2Types.js';
|
|
4
4
|
import type { LLMChatV2EditorCacheKeyParts, LLMChatV2NodeData } from './llmChatV2NodeData.js';
|
|
5
|
+
import type { LLMProfileValue } from './llmProfileTypes.js';
|
|
5
6
|
export declare function buildLLMChatV2EditorCacheKey(parts: LLMChatV2EditorCacheKeyParts): string;
|
|
6
7
|
export declare function cloneLLMChatV2EditorCacheOutputs(outputs: Outputs): Outputs;
|
|
7
8
|
export declare function resolveLLMChatV2EditorCache(params: {
|
|
@@ -19,6 +20,9 @@ export declare function resolveLLMChatV2EditorCache(params: {
|
|
|
19
20
|
responseFormatParameters: unknown;
|
|
20
21
|
systemPrompt: unknown;
|
|
21
22
|
toolChoice: ChatV2ToolChoice | undefined;
|
|
23
|
+
profileChain?: readonly LLMProfileValue[] | undefined;
|
|
24
|
+
/** Keeps scalar profile output shapes distinct from one-item profile arrays. */
|
|
25
|
+
profileChainUsesArray?: boolean | undefined;
|
|
22
26
|
}): {
|
|
23
27
|
cacheKey: string | undefined;
|
|
24
28
|
cachedOutputs: Outputs | undefined;
|
|
@@ -2,8 +2,8 @@ import type { LanguageModelUsage } from 'ai';
|
|
|
2
2
|
import type { ChatMessage } from '../DataValue.js';
|
|
3
3
|
import type { Outputs } from '../GraphProcessor.js';
|
|
4
4
|
import { type StreamedFunctionCall } from '../chat/streamChatResponse.js';
|
|
5
|
-
import type
|
|
6
|
-
type ChatV2CommonOutputOptions = Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'includeFunctionCalls' | 'functionCallMode' | 'retryOnNon200' | 'responseFormat'>;
|
|
5
|
+
import { type ChatV2NormalizedUsage, type ChatV2ReasoningOutput, type RunChatV2PipelineOptions } from './chatV2Types.js';
|
|
6
|
+
type ChatV2CommonOutputOptions = Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'outputRequestError' | 'outputRequestBody' | 'includeFunctionCalls' | 'functionCallMode' | 'retryOnNon200' | 'responseFormat'>;
|
|
7
7
|
type CreateChatV2CommonOutputsOptions = ChatV2CommonOutputOptions & {
|
|
8
8
|
requestMessages: ChatMessage[];
|
|
9
9
|
response: string;
|
|
@@ -17,7 +17,7 @@ type CreateChatV2CommonOutputsOptions = ChatV2CommonOutputOptions & {
|
|
|
17
17
|
requestErrors: string[];
|
|
18
18
|
requestBodies?: unknown[] | undefined;
|
|
19
19
|
};
|
|
20
|
-
type CreateChatV2ProviderFailureOutputsOptions = Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'includeFunctionCalls' | 'retryOnNon200'> & {
|
|
20
|
+
type CreateChatV2ProviderFailureOutputsOptions = Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'outputRequestError' | 'outputRequestBody' | 'includeFunctionCalls' | 'retryOnNon200'> & {
|
|
21
21
|
requestMessages: ChatMessage[];
|
|
22
22
|
responseStatus: number | undefined;
|
|
23
23
|
responseError: string;
|
|
@@ -26,6 +26,6 @@ type CreateChatV2ProviderFailureOutputsOptions = Pick<RunChatV2PipelineOptions,
|
|
|
26
26
|
requestBodies?: unknown[] | undefined;
|
|
27
27
|
};
|
|
28
28
|
export declare function normalizeChatV2Usage(usage: LanguageModelUsage | undefined, options: Pick<RunChatV2PipelineOptions, 'provider' | 'modelId'>): ChatV2NormalizedUsage | undefined;
|
|
29
|
-
export declare function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }: CreateChatV2CommonOutputsOptions): Outputs;
|
|
30
|
-
export declare function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, includeFunctionCalls, retryOnNon200, }: CreateChatV2ProviderFailureOutputsOptions): Outputs;
|
|
29
|
+
export declare function createChatV2CommonOutputs({ requestMessages, response, structuredOutput, functionCalls, usage, reasoning, requestStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, outputRequestError, outputRequestBody, includeFunctionCalls, functionCallMode, retryOnNon200, responseFormat, }: CreateChatV2CommonOutputsOptions): Outputs;
|
|
30
|
+
export declare function createChatV2ProviderFailureOutputs({ requestMessages, responseStatus, responseError, requestStatuses, requestErrors, requestBodies, outputUsage, outputReasoning, outputRequestStatus, outputRequestError, outputRequestBody, includeFunctionCalls, retryOnNon200, }: CreateChatV2ProviderFailureOutputsOptions): Outputs;
|
|
31
31
|
export {};
|
|
@@ -1,2 +1,35 @@
|
|
|
1
|
+
import type { ChatMessage } from '../DataValue.js';
|
|
1
2
|
import type { ChatV2PipelineResult, RunChatV2PipelineOptions } from './chatV2Types.js';
|
|
3
|
+
import { type ChatV2RequestPlan } from './chatV2RequestPlan.js';
|
|
4
|
+
export type ChatV2PipelineProviderFailure = {
|
|
5
|
+
requestMessages: ChatMessage[];
|
|
6
|
+
options: RunChatV2PipelineOptions;
|
|
7
|
+
plan: ChatV2RequestPlan;
|
|
8
|
+
normalizedError: unknown;
|
|
9
|
+
rawError: unknown;
|
|
10
|
+
requestStatuses: number[];
|
|
11
|
+
requestErrors: string[];
|
|
12
|
+
/** A completed non-200 custom stream may still have a useful response body. */
|
|
13
|
+
diagnosticResult?: ChatV2PipelineResult;
|
|
14
|
+
};
|
|
15
|
+
export type ChatV2PipelineExecution = {
|
|
16
|
+
outcome: 'success';
|
|
17
|
+
result: ChatV2PipelineResult;
|
|
18
|
+
} | {
|
|
19
|
+
outcome: 'provider-failure';
|
|
20
|
+
failure: ChatV2PipelineProviderFailure;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Runs one provider/model round without deciding whether a provider failure
|
|
24
|
+
* should become diagnostic outputs or should advance an LLM Profile fallback
|
|
25
|
+
* chain. Shared prompt/schema/tool construction errors deliberately continue
|
|
26
|
+
* to throw: they are graph configuration errors, not a profile failure.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runChatV2PipelineExecution(options: RunChatV2PipelineOptions): Promise<ChatV2PipelineExecution>;
|
|
29
|
+
/**
|
|
30
|
+
* Retains the established single-profile behavior: request-detail mode can
|
|
31
|
+
* turn a provider failure into normal excluded outputs; otherwise it remains
|
|
32
|
+
* a thrown normalized provider error.
|
|
33
|
+
*/
|
|
34
|
+
export declare function materializeChatV2PipelineFailure(failure: ChatV2PipelineProviderFailure): ChatV2PipelineResult;
|
|
2
35
|
export declare function runChatV2Pipeline(options: RunChatV2PipelineOptions): Promise<ChatV2PipelineResult>;
|
|
@@ -38,6 +38,7 @@ export declare function createResolvedChatV2Provider(options: {
|
|
|
38
38
|
headers?: Record<string, string> | undefined;
|
|
39
39
|
credential: ChatV2CredentialResult;
|
|
40
40
|
onRequestBody?: CreateChatV2ModelOptions['onRequestBody'];
|
|
41
|
+
transformRequestBody?: CreateChatV2ModelOptions['transformRequestBody'];
|
|
41
42
|
}): Promise<{
|
|
42
43
|
profile: ChatV2ProviderProfile;
|
|
43
44
|
model: ChatV2Model;
|
|
@@ -10,9 +10,9 @@ export type ChatV2RequestPlan = {
|
|
|
10
10
|
cooldownMs: number;
|
|
11
11
|
};
|
|
12
12
|
request: Omit<StreamChatV2Options, 'abortSignal' | 'executeStream' | 'executeGenerate' | 'onPartialOutput'>;
|
|
13
|
-
output: Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'includeFunctionCalls' | 'functionCallMode'>;
|
|
13
|
+
output: Pick<RunChatV2PipelineOptions, 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'outputRequestError' | 'outputRequestBody' | 'includeFunctionCalls' | 'functionCallMode'>;
|
|
14
14
|
};
|
|
15
|
-
type BuildChatV2RequestPlanOptions = Pick<RunChatV2PipelineOptions, 'provider' | 'model' | 'modelId' | 'maxTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'responseOutput' | 'responseFormat' | 'providerOptions' | 'toolChoice' | 'retryOnNon200' | 'retryOnNon200RepeatTimes' | 'retryOnNon200CooldownMs' | 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'includeFunctionCalls' | 'emitPartialOutputs' | 'functionCallMode'> & {
|
|
15
|
+
type BuildChatV2RequestPlanOptions = Pick<RunChatV2PipelineOptions, 'provider' | 'model' | 'modelId' | 'maxTokens' | 'temperature' | 'topP' | 'topK' | 'presencePenalty' | 'frequencyPenalty' | 'stopSequences' | 'seed' | 'responseOutput' | 'responseFormat' | 'providerOptions' | 'toolChoice' | 'retryOnNon200' | 'retryOnNon200RepeatTimes' | 'retryOnNon200CooldownMs' | 'outputUsage' | 'outputReasoning' | 'outputRequestStatus' | 'outputRequestError' | 'outputRequestBody' | 'includeFunctionCalls' | 'emitPartialOutputs' | 'functionCallMode'> & {
|
|
16
16
|
messages: ChatV2MessageList;
|
|
17
17
|
tools?: ChatV2ToolSet | undefined;
|
|
18
18
|
};
|
|
@@ -114,16 +114,40 @@ export type RunChatV2PipelineOptions = {
|
|
|
114
114
|
outputUsage?: boolean | undefined;
|
|
115
115
|
outputReasoning?: boolean | undefined;
|
|
116
116
|
outputRequestStatus?: boolean | undefined;
|
|
117
|
+
outputRequestError?: boolean | undefined;
|
|
118
|
+
outputRequestBody?: boolean | undefined;
|
|
117
119
|
includeFunctionCalls?: boolean | undefined;
|
|
118
120
|
emitPartialOutputs?: boolean | undefined;
|
|
119
121
|
functionCallMode?: AssistantMessageFunctionCallMode | undefined;
|
|
120
122
|
retryOnNon200?: boolean | undefined;
|
|
121
123
|
retryOnNon200RepeatTimes?: number | undefined;
|
|
122
124
|
retryOnNon200CooldownMs?: number | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Internal, privacy-bounded metadata for an ordered LLM Profile fallback
|
|
127
|
+
* chain. It is forwarded to physical-call observers but never sent to a
|
|
128
|
+
* provider.
|
|
129
|
+
*/
|
|
130
|
+
profileIndex?: number | undefined;
|
|
131
|
+
roundIndex?: number | undefined;
|
|
132
|
+
/** Internal physical-call trace used by the LLM Profile fallback coordinator. */
|
|
133
|
+
onProviderAttempt?: ((attempt: ChatV2ProviderAttempt) => void) | undefined;
|
|
123
134
|
context: Pick<InternalProcessContext, 'signal' | 'onPartialOutputs'> & Partial<Pick<InternalProcessContext, 'node' | 'onChatV2CallFinished' | 'processId'>>;
|
|
124
135
|
executeStream?: ChatV2StreamExecutor | undefined;
|
|
125
136
|
executeGenerate?: ChatV2GenerateExecutor | undefined;
|
|
126
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Older LLM Chat nodes used Output request details as one switch for status,
|
|
140
|
+
* error, and request body. Keep that saved contract intact while newly saved
|
|
141
|
+
* nodes use the independent controls.
|
|
142
|
+
*/
|
|
143
|
+
export declare function shouldOutputChatV2RequestError(options: Pick<RunChatV2PipelineOptions, 'outputRequestStatus' | 'outputRequestError'>): boolean;
|
|
144
|
+
export declare function shouldOutputChatV2RequestBody(options: Pick<RunChatV2PipelineOptions, 'outputRequestStatus' | 'outputRequestBody'>): boolean;
|
|
145
|
+
export type ChatV2ProviderAttempt = {
|
|
146
|
+
attemptIndex: number;
|
|
147
|
+
outcome: 'success' | 'provider-failure';
|
|
148
|
+
status?: number | undefined;
|
|
149
|
+
error?: unknown;
|
|
150
|
+
};
|
|
127
151
|
export type ChatV2PipelineResult = {
|
|
128
152
|
commonOutputs: Outputs;
|
|
129
153
|
requestMessages: ChatMessage[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ChatMessage } from '../DataValue.js';
|
|
2
|
+
export type InstructionMessageRole = Extract<ChatMessage['type'], 'system' | 'developer'>;
|
|
3
|
+
export declare function getInstructionMessageRoles(messages: ChatMessage[]): InstructionMessageRole[];
|
|
4
|
+
/**
|
|
5
|
+
* AI SDK's provider-neutral ModelMessage represents both Rivet system and
|
|
6
|
+
* developer instructions with role `system`. Restore the explicit Rivet roles
|
|
7
|
+
* only at OpenAI-compatible wire boundaries, after the provider has built its
|
|
8
|
+
* request body.
|
|
9
|
+
*/
|
|
10
|
+
export declare function restoreOpenAICompatibleInstructionRoles(body: unknown, roles: InstructionMessageRole[]): unknown;
|
|
@@ -54,6 +54,8 @@ export type LLMChatV2NodeConfigData = ChatV2CommonNodeData & {
|
|
|
54
54
|
retryOnNon200RepeatTimes?: number;
|
|
55
55
|
retryOnNon200CooldownMs?: number;
|
|
56
56
|
outputRequestStatus?: boolean;
|
|
57
|
+
outputRequestError?: boolean;
|
|
58
|
+
outputRequestBody?: boolean;
|
|
57
59
|
};
|
|
58
60
|
export type LLMChatV2NodeData = LLMChatV2NodeConfigData;
|
|
59
61
|
export type LLMChatV2Node = ChartNode<'llmChatV2', LLMChatV2NodeData>;
|
|
@@ -74,7 +76,8 @@ export type LLMChatV2EditorCacheKeyParts = {
|
|
|
74
76
|
responseFormatParameters: unknown;
|
|
75
77
|
providerOptions: unknown;
|
|
76
78
|
toolChoice: unknown;
|
|
79
|
+
/** Ordered, credential-fingerprinted fallback profile configuration. */
|
|
80
|
+
profileChain?: unknown;
|
|
77
81
|
};
|
|
78
82
|
export declare function createLLMChatV2NodeData(): LLMChatV2NodeData;
|
|
79
|
-
export declare function hasLLMChatV2BuiltInToolsEnabled(data: LLMChatV2NodeData): boolean;
|
|
80
83
|
export declare function shouldIncludeLLMChatV2ToolCalls(data: LLMChatV2NodeData): boolean;
|
|
@@ -1,21 +1,37 @@
|
|
|
1
1
|
import type { GptFunction } from '../DataValue.js';
|
|
2
2
|
import type { Inputs, Outputs } from '../GraphProcessor.js';
|
|
3
3
|
import type { InternalProcessContext } from '../ProcessContext.js';
|
|
4
|
+
import { type LLMProfileAttempt } from './llmProfileFallback.js';
|
|
4
5
|
import type { ChatV2ProviderProfile } from './chatV2ProviderProfile.js';
|
|
5
|
-
import type
|
|
6
|
+
import { type ChatV2PipelineResult, type RunChatV2PipelineOptions } from './chatV2Types.js';
|
|
6
7
|
import { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs } from './chatV2EditorCache.js';
|
|
7
8
|
import { type LLMChatV2EditorCacheKeyParts, type LLMChatV2NodeData } from './llmChatV2NodeData.js';
|
|
8
9
|
export { buildLLMChatV2EditorCacheKey, cloneLLMChatV2EditorCacheOutputs };
|
|
9
10
|
export { resolveLLMChatV2RuntimeProviderOptions } from './chatV2RuntimeOptions.js';
|
|
11
|
+
export type { LLMProfileAttempt } from './llmProfileFallback.js';
|
|
10
12
|
export type LLMChatV2RuntimeConfig = {
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Shared invocation values plus a profile-shaped placeholder in From profile
|
|
15
|
+
* mode. The actual provider model is resolved lazily by `runPipeline` so a
|
|
16
|
+
* broken primary candidate can advance to the next profile.
|
|
17
|
+
*/
|
|
12
18
|
runOptions: RunChatV2PipelineOptions;
|
|
19
|
+
/** A safe summary of the first configured candidate for editor/runtime consumers. */
|
|
20
|
+
providerProfile: ChatV2ProviderProfile;
|
|
21
|
+
runPipeline: (options: RunChatV2PipelineOptions) => Promise<ChatV2PipelineResult>;
|
|
13
22
|
functions: GptFunction[] | undefined;
|
|
14
23
|
cacheKey: string | undefined;
|
|
15
24
|
cachedOutputs: Outputs | undefined;
|
|
16
25
|
editorCache: Map<string, unknown> | undefined;
|
|
17
26
|
shouldAutoContinueToolCalls: boolean;
|
|
18
27
|
maxToolRounds: number;
|
|
28
|
+
profileAttempts: LLMProfileAttempt[] | undefined;
|
|
29
|
+
/** True only when the incoming LLM Profile value was an actual array. */
|
|
30
|
+
profileChainUsesArray: boolean;
|
|
31
|
+
/** Defined for From profile runs, including a scalar single-profile input. */
|
|
32
|
+
profileChainLength: number | undefined;
|
|
33
|
+
getProfileSummary: (() => string) | undefined;
|
|
34
|
+
isProfileFallbackExhausted: () => boolean;
|
|
19
35
|
};
|
|
20
36
|
export declare function resolveLLMChatV2RuntimeConfig(params: {
|
|
21
37
|
data: LLMChatV2NodeData;
|