@teleporthq/teleport-plugin-next-workflows 0.43.53 → 0.43.55
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/__tests__/ai-chat-rag-sql-parameterization.test.ts +237 -0
- package/__tests__/ai-embedding-optional.test.ts +77 -0
- package/__tests__/ai-model-capabilities.test.ts +234 -0
- package/__tests__/ai-provider-coverage.test.ts +183 -0
- package/__tests__/cart-clear-db-mirror.test.ts +45 -0
- package/__tests__/cart-get-total-storefront-tax.test.ts +165 -0
- package/__tests__/cron-route-loop-templateparams.test.ts +15 -6
- package/__tests__/data-create-item-order-notification.test.ts +33 -0
- package/__tests__/ecommerce-customhandler-rewriter.test.ts +1 -1
- package/__tests__/internal-request-headers.test.ts +159 -0
- package/__tests__/order-details-route.test.ts +238 -0
- package/__tests__/resolve-config-template-params.test.ts +174 -0
- package/__tests__/utility-nodes.test.ts +27 -11
- package/dist/cjs/api-route-generator.d.ts.map +1 -1
- package/dist/cjs/api-route-generator.js +27 -15
- package/dist/cjs/api-route-generator.js.map +1 -1
- package/dist/cjs/ecommerce/order-details-route.d.ts +18 -0
- package/dist/cjs/ecommerce/order-details-route.d.ts.map +1 -0
- package/dist/cjs/ecommerce/order-details-route.js +172 -0
- package/dist/cjs/ecommerce/order-details-route.js.map +1 -0
- package/dist/cjs/ecommerce-customhandler-rewriter.d.ts +1 -1
- package/dist/cjs/ecommerce-customhandler-rewriter.d.ts.map +1 -1
- package/dist/cjs/ecommerce-customhandler-rewriter.js +20 -4
- package/dist/cjs/ecommerce-customhandler-rewriter.js.map +1 -1
- package/dist/cjs/executor-generator.d.ts.map +1 -1
- package/dist/cjs/executor-generator.js +69 -11
- package/dist/cjs/executor-generator.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-custom-prompt.js +1 -1
- package/dist/cjs/nodes/ai/ai-custom-prompt.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-detect-language.js +1 -1
- package/dist/cjs/nodes/ai/ai-detect-language.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-generate-text-embedding.d.ts.map +1 -1
- package/dist/cjs/nodes/ai/ai-generate-text-embedding.js +47 -4
- package/dist/cjs/nodes/ai/ai-generate-text-embedding.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-provider-utils.d.ts +2 -0
- package/dist/cjs/nodes/ai/ai-provider-utils.d.ts.map +1 -1
- package/dist/cjs/nodes/ai/ai-provider-utils.js +195 -106
- package/dist/cjs/nodes/ai/ai-provider-utils.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-sentiment-analysis.js +1 -1
- package/dist/cjs/nodes/ai/ai-sentiment-analysis.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-summarization.js +1 -1
- package/dist/cjs/nodes/ai/ai-summarization.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-text-classifier.js +1 -1
- package/dist/cjs/nodes/ai/ai-text-classifier.js.map +1 -1
- package/dist/cjs/nodes/ai/ai-text-transform.js +1 -1
- package/dist/cjs/nodes/ai/ai-text-transform.js.map +1 -1
- package/dist/cjs/nodes/cart/cart-clear.d.ts.map +1 -1
- package/dist/cjs/nodes/cart/cart-clear.js +40 -0
- package/dist/cjs/nodes/cart/cart-clear.js.map +1 -1
- package/dist/cjs/nodes/cart/cart-get-total.d.ts.map +1 -1
- package/dist/cjs/nodes/cart/cart-get-total.js +56 -15
- package/dist/cjs/nodes/cart/cart-get-total.js.map +1 -1
- package/dist/cjs/nodes/data/data-count.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-count.js +6 -1
- package/dist/cjs/nodes/data/data-count.js.map +1 -1
- package/dist/cjs/nodes/data/data-create-item.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-create-item.js +45 -9
- package/dist/cjs/nodes/data/data-create-item.js.map +1 -1
- package/dist/cjs/nodes/data/data-delete-item.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-delete-item.js +7 -4
- package/dist/cjs/nodes/data/data-delete-item.js.map +1 -1
- package/dist/cjs/nodes/data/data-raw-query.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-raw-query.js +7 -1
- package/dist/cjs/nodes/data/data-raw-query.js.map +1 -1
- package/dist/cjs/nodes/data/data-select.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-select.js +6 -1
- package/dist/cjs/nodes/data/data-select.js.map +1 -1
- package/dist/cjs/nodes/data/data-update-item.d.ts.map +1 -1
- package/dist/cjs/nodes/data/data-update-item.js +7 -4
- package/dist/cjs/nodes/data/data-update-item.js.map +1 -1
- package/dist/cjs/nodes/utility/utility-hybrid-search.js +2 -2
- package/dist/cjs/nodes/utility/utility-hybrid-search.js.map +1 -1
- package/dist/cjs/nodes/utility/utility-semantic-search.js +1 -1
- package/dist/cjs/nodes/utility/utility-semantic-search.js.map +1 -1
- package/dist/cjs/nodes/utility/utility-similarity-scoring.d.ts.map +1 -1
- package/dist/cjs/nodes/utility/utility-similarity-scoring.js +49 -3
- package/dist/cjs/nodes/utility/utility-similarity-scoring.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/workflow-project-plugin.d.ts.map +1 -1
- package/dist/cjs/workflow-project-plugin.js +10 -4
- package/dist/cjs/workflow-project-plugin.js.map +1 -1
- package/dist/esm/api-route-generator.d.ts.map +1 -1
- package/dist/esm/api-route-generator.js +27 -15
- package/dist/esm/api-route-generator.js.map +1 -1
- package/dist/esm/ecommerce/order-details-route.d.ts +18 -0
- package/dist/esm/ecommerce/order-details-route.d.ts.map +1 -0
- package/dist/esm/ecommerce/order-details-route.js +167 -0
- package/dist/esm/ecommerce/order-details-route.js.map +1 -0
- package/dist/esm/ecommerce-customhandler-rewriter.d.ts +1 -1
- package/dist/esm/ecommerce-customhandler-rewriter.d.ts.map +1 -1
- package/dist/esm/ecommerce-customhandler-rewriter.js +20 -4
- package/dist/esm/ecommerce-customhandler-rewriter.js.map +1 -1
- package/dist/esm/executor-generator.d.ts.map +1 -1
- package/dist/esm/executor-generator.js +69 -11
- package/dist/esm/executor-generator.js.map +1 -1
- package/dist/esm/nodes/ai/ai-custom-prompt.js +1 -1
- package/dist/esm/nodes/ai/ai-custom-prompt.js.map +1 -1
- package/dist/esm/nodes/ai/ai-detect-language.js +1 -1
- package/dist/esm/nodes/ai/ai-detect-language.js.map +1 -1
- package/dist/esm/nodes/ai/ai-generate-text-embedding.d.ts.map +1 -1
- package/dist/esm/nodes/ai/ai-generate-text-embedding.js +47 -4
- package/dist/esm/nodes/ai/ai-generate-text-embedding.js.map +1 -1
- package/dist/esm/nodes/ai/ai-provider-utils.d.ts +2 -0
- package/dist/esm/nodes/ai/ai-provider-utils.d.ts.map +1 -1
- package/dist/esm/nodes/ai/ai-provider-utils.js +194 -105
- package/dist/esm/nodes/ai/ai-provider-utils.js.map +1 -1
- package/dist/esm/nodes/ai/ai-sentiment-analysis.js +1 -1
- package/dist/esm/nodes/ai/ai-sentiment-analysis.js.map +1 -1
- package/dist/esm/nodes/ai/ai-summarization.js +1 -1
- package/dist/esm/nodes/ai/ai-summarization.js.map +1 -1
- package/dist/esm/nodes/ai/ai-text-classifier.js +1 -1
- package/dist/esm/nodes/ai/ai-text-classifier.js.map +1 -1
- package/dist/esm/nodes/ai/ai-text-transform.js +1 -1
- package/dist/esm/nodes/ai/ai-text-transform.js.map +1 -1
- package/dist/esm/nodes/cart/cart-clear.d.ts.map +1 -1
- package/dist/esm/nodes/cart/cart-clear.js +40 -0
- package/dist/esm/nodes/cart/cart-clear.js.map +1 -1
- package/dist/esm/nodes/cart/cart-get-total.d.ts.map +1 -1
- package/dist/esm/nodes/cart/cart-get-total.js +56 -15
- package/dist/esm/nodes/cart/cart-get-total.js.map +1 -1
- package/dist/esm/nodes/data/data-count.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-count.js +6 -1
- package/dist/esm/nodes/data/data-count.js.map +1 -1
- package/dist/esm/nodes/data/data-create-item.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-create-item.js +45 -9
- package/dist/esm/nodes/data/data-create-item.js.map +1 -1
- package/dist/esm/nodes/data/data-delete-item.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-delete-item.js +7 -4
- package/dist/esm/nodes/data/data-delete-item.js.map +1 -1
- package/dist/esm/nodes/data/data-raw-query.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-raw-query.js +7 -1
- package/dist/esm/nodes/data/data-raw-query.js.map +1 -1
- package/dist/esm/nodes/data/data-select.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-select.js +6 -1
- package/dist/esm/nodes/data/data-select.js.map +1 -1
- package/dist/esm/nodes/data/data-update-item.d.ts.map +1 -1
- package/dist/esm/nodes/data/data-update-item.js +7 -4
- package/dist/esm/nodes/data/data-update-item.js.map +1 -1
- package/dist/esm/nodes/utility/utility-hybrid-search.js +2 -2
- package/dist/esm/nodes/utility/utility-hybrid-search.js.map +1 -1
- package/dist/esm/nodes/utility/utility-semantic-search.js +1 -1
- package/dist/esm/nodes/utility/utility-semantic-search.js.map +1 -1
- package/dist/esm/nodes/utility/utility-similarity-scoring.d.ts.map +1 -1
- package/dist/esm/nodes/utility/utility-similarity-scoring.js +49 -3
- package/dist/esm/nodes/utility/utility-similarity-scoring.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/workflow-project-plugin.d.ts.map +1 -1
- package/dist/esm/workflow-project-plugin.js +10 -4
- package/dist/esm/workflow-project-plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/api-route-generator.ts +27 -15
- package/src/ecommerce/order-details-route.ts +195 -0
- package/src/ecommerce-customhandler-rewriter.ts +24 -4
- package/src/executor-generator.ts +69 -11
- package/src/nodes/ai/ai-custom-prompt.ts +2 -2
- package/src/nodes/ai/ai-detect-language.ts +2 -2
- package/src/nodes/ai/ai-generate-text-embedding.ts +49 -4
- package/src/nodes/ai/ai-provider-utils.ts +216 -106
- package/src/nodes/ai/ai-sentiment-analysis.ts +2 -2
- package/src/nodes/ai/ai-summarization.ts +2 -2
- package/src/nodes/ai/ai-text-classifier.ts +2 -2
- package/src/nodes/ai/ai-text-transform.ts +2 -2
- package/src/nodes/cart/cart-clear.ts +40 -0
- package/src/nodes/cart/cart-get-total.ts +61 -17
- package/src/nodes/data/data-count.ts +6 -1
- package/src/nodes/data/data-create-item.ts +45 -9
- package/src/nodes/data/data-delete-item.ts +6 -0
- package/src/nodes/data/data-raw-query.ts +8 -1
- package/src/nodes/data/data-select.ts +6 -1
- package/src/nodes/data/data-update-item.ts +6 -0
- package/src/nodes/utility/utility-hybrid-search.ts +2 -2
- package/src/nodes/utility/utility-semantic-search.ts +1 -1
- package/src/nodes/utility/utility-similarity-scoring.ts +56 -3
- package/src/workflow-project-plugin.ts +10 -4
|
@@ -33,6 +33,10 @@ export function generateAIProviderUtils(): string {
|
|
|
33
33
|
wrapWithGuard('__ai_resolveTextField', __ai_resolveTextField),
|
|
34
34
|
wrapWithGuard('__ai_resolveToken', __ai_resolveToken),
|
|
35
35
|
wrapWithGuard('__ai_detectProvider', __ai_detectProvider),
|
|
36
|
+
wrapWithGuard('__ai_resolveProvider', __ai_resolveProvider),
|
|
37
|
+
wrapWithGuard('__ai_modelCapabilities', __ai_modelCapabilities),
|
|
38
|
+
wrapWithGuard('__ai_providerBaseURL', __ai_providerBaseURL),
|
|
39
|
+
wrapWithGuard('__ai_openAICompatibleBody', __ai_openAICompatibleBody),
|
|
36
40
|
wrapWithGuard('__ai_clampTemperature', __ai_clampTemperature),
|
|
37
41
|
wrapWithGuard('__ai_parseJSON', __ai_parseJSON),
|
|
38
42
|
wrapWithGuard('__ai_callProvider', __ai_callProvider),
|
|
@@ -52,33 +56,15 @@ var __ai_callProviderStreaming = typeof __ai_callProviderStreaming !== 'undefine
|
|
|
52
56
|
const userMessage = params.userMessage;
|
|
53
57
|
const temperature = params.temperature;
|
|
54
58
|
const maxTokens = params.maxTokens;
|
|
59
|
+
const caps = __ai_modelCapabilities(provider, model, maxTokens);
|
|
55
60
|
const __nodeRequire = typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require;
|
|
56
61
|
|
|
57
|
-
if (provider === 'openai') {
|
|
58
|
-
const _mod = __nodeRequire('openai');
|
|
59
|
-
const OpenAI = _mod.default || _mod;
|
|
60
|
-
const messages = [];
|
|
61
|
-
if (systemMessage) messages.push({ role: 'system', content: systemMessage });
|
|
62
|
-
messages.push({ role: 'user', content: userMessage });
|
|
63
|
-
const client = new OpenAI({ apiKey: token });
|
|
64
|
-
const opts = { model: model, messages: messages, temperature: temperature, max_tokens: maxTokens, stream: true, stream_options: { include_usage: true } };
|
|
65
|
-
const stream = await client.chat.completions.create(opts);
|
|
66
|
-
let usage = {};
|
|
67
|
-
for await (const chunk of stream) {
|
|
68
|
-
if (chunk.usage) {
|
|
69
|
-
usage = { promptTokens: chunk.usage.prompt_tokens || 0, completionTokens: chunk.usage.completion_tokens || 0, totalTokens: chunk.usage.total_tokens || 0 };
|
|
70
|
-
}
|
|
71
|
-
const delta = chunk.choices && chunk.choices[0] && chunk.choices[0].delta && chunk.choices[0].delta.content;
|
|
72
|
-
if (delta) await onChunk(delta);
|
|
73
|
-
}
|
|
74
|
-
return { usage: usage };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
62
|
if (provider === 'anthropic') {
|
|
78
63
|
const _mod = __nodeRequire('@anthropic-ai/sdk');
|
|
79
64
|
const Anthropic = _mod.default || _mod;
|
|
80
65
|
const client = new Anthropic({ apiKey: token });
|
|
81
|
-
const opts = { model: model, messages: [{ role: 'user', content: userMessage }],
|
|
66
|
+
const opts = { model: model, messages: [{ role: 'user', content: userMessage }], max_tokens: caps.maxTokens, stream: true };
|
|
67
|
+
if (caps.supportsTemperature) { opts.temperature = temperature; }
|
|
82
68
|
if (systemMessage) opts.system = systemMessage;
|
|
83
69
|
const stream = await client.messages.create(opts);
|
|
84
70
|
let promptTokens = 0;
|
|
@@ -114,9 +100,11 @@ var __ai_callProviderStreaming = typeof __ai_callProviderStreaming !== 'undefine
|
|
|
114
100
|
let fullPrompt = '';
|
|
115
101
|
if (systemMessage) fullPrompt += systemMessage + '\\n\\n';
|
|
116
102
|
fullPrompt += userMessage;
|
|
103
|
+
const generationConfig = { maxOutputTokens: caps.maxTokens };
|
|
104
|
+
if (caps.supportsTemperature) { generationConfig.temperature = temperature; }
|
|
117
105
|
const result = await genModel.generateContentStream({
|
|
118
106
|
contents: [{ role: 'user', parts: [{ text: fullPrompt }] }],
|
|
119
|
-
generationConfig:
|
|
107
|
+
generationConfig: generationConfig
|
|
120
108
|
});
|
|
121
109
|
for await (const chunk of result.stream) {
|
|
122
110
|
try {
|
|
@@ -133,7 +121,8 @@ var __ai_callProviderStreaming = typeof __ai_callProviderStreaming !== 'undefine
|
|
|
133
121
|
const _mod = __nodeRequire('cohere-ai');
|
|
134
122
|
const CohereClient = _mod.CohereClient;
|
|
135
123
|
const client = new CohereClient({ token: token });
|
|
136
|
-
const opts = { model: model, message: userMessage,
|
|
124
|
+
const opts = { model: model, message: userMessage, maxTokens: caps.maxTokens };
|
|
125
|
+
if (caps.supportsTemperature) { opts.temperature = temperature; }
|
|
137
126
|
if (systemMessage) opts.preamble = systemMessage;
|
|
138
127
|
const stream = await client.chatStream(opts);
|
|
139
128
|
let usage = {};
|
|
@@ -156,7 +145,9 @@ var __ai_callProviderStreaming = typeof __ai_callProviderStreaming !== 'undefine
|
|
|
156
145
|
const messages = [];
|
|
157
146
|
if (systemMessage) messages.push({ role: 'system', content: systemMessage });
|
|
158
147
|
messages.push({ role: 'user', content: userMessage });
|
|
159
|
-
const
|
|
148
|
+
const opts = { model: model, messages: messages, maxTokens: caps.maxTokens };
|
|
149
|
+
if (caps.supportsTemperature) { opts.temperature = temperature; }
|
|
150
|
+
const stream = await client.chat.stream(opts);
|
|
160
151
|
let usage = {};
|
|
161
152
|
for await (const event of stream) {
|
|
162
153
|
const delta = event.data && event.data.choices && event.data.choices[0] && event.data.choices[0].delta && event.data.choices[0].delta.content;
|
|
@@ -170,14 +161,13 @@ var __ai_callProviderStreaming = typeof __ai_callProviderStreaming !== 'undefine
|
|
|
170
161
|
|
|
171
162
|
const _mod = __nodeRequire('openai');
|
|
172
163
|
const OpenAI = _mod.default || _mod;
|
|
173
|
-
const baseURL = provider
|
|
164
|
+
const baseURL = __ai_providerBaseURL(provider);
|
|
174
165
|
const clientOpts = { apiKey: token };
|
|
175
166
|
if (baseURL) clientOpts.baseURL = baseURL;
|
|
176
167
|
const client = new OpenAI(clientOpts);
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const opts = { model: model, messages: messages, temperature: temperature, max_tokens: maxTokens, stream: true, stream_options: { include_usage: true } };
|
|
168
|
+
const opts = __ai_openAICompatibleBody(caps, model, systemMessage, userMessage, temperature, false);
|
|
169
|
+
opts.stream = true;
|
|
170
|
+
opts.stream_options = { include_usage: true };
|
|
181
171
|
const stream = await client.chat.completions.create(opts);
|
|
182
172
|
let usage = {};
|
|
183
173
|
for await (const chunk of stream) {
|
|
@@ -270,40 +260,185 @@ function __ai_resolveToken(token: any): string {
|
|
|
270
260
|
return String(token)
|
|
271
261
|
}
|
|
272
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Last-resort provider inference for nodes saved before the editor started
|
|
265
|
+
* writing `config.provider`.
|
|
266
|
+
*
|
|
267
|
+
* ⛔ This is a heuristic and it is WRONG for several current model ids —
|
|
268
|
+
* `magistral-medium-latest` and `ministral-8b-latest` are Mistral,
|
|
269
|
+
* `command-a-03-2025` is Cohere, and Together serves Llama under
|
|
270
|
+
* `meta-llama/…`. Every unmatched id falls through to OpenAI and the request
|
|
271
|
+
* goes to the wrong API with the wrong key. The patterns below cover the whole
|
|
272
|
+
* shipped catalogue, but the durable fix is `config.provider`, which
|
|
273
|
+
* `__ai_resolveProvider` prefers.
|
|
274
|
+
*/
|
|
273
275
|
function __ai_detectProvider(modelId: any): string {
|
|
274
|
-
|
|
276
|
+
const id = String(modelId || '').toLowerCase()
|
|
277
|
+
if (!id) {
|
|
275
278
|
return 'openai'
|
|
276
279
|
}
|
|
277
|
-
|
|
280
|
+
// Perplexity first: its retired ids are `llama-3.1-sonar-*`, which would
|
|
281
|
+
// otherwise be claimed by the Llama branch below.
|
|
282
|
+
if (id.indexOf('sonar') >= 0) {
|
|
283
|
+
return 'perplexity'
|
|
284
|
+
}
|
|
285
|
+
if (id.indexOf('gpt-') === 0 || /^o\d/.test(id)) {
|
|
278
286
|
return 'openai'
|
|
279
287
|
}
|
|
280
|
-
if (
|
|
288
|
+
if (id.indexOf('claude') === 0) {
|
|
281
289
|
return 'anthropic'
|
|
282
290
|
}
|
|
283
|
-
if (
|
|
291
|
+
if (id.indexOf('gemini') === 0) {
|
|
284
292
|
return 'google'
|
|
285
293
|
}
|
|
286
|
-
if (
|
|
294
|
+
if (id.indexOf('command') === 0) {
|
|
287
295
|
return 'cohere'
|
|
288
296
|
}
|
|
289
|
-
if (
|
|
297
|
+
if (
|
|
298
|
+
id.indexOf('mistral') === 0 ||
|
|
299
|
+
id.indexOf('mixtral') === 0 ||
|
|
300
|
+
id.indexOf('ministral') === 0 ||
|
|
301
|
+
id.indexOf('magistral') === 0 ||
|
|
302
|
+
id.indexOf('pixtral') === 0 ||
|
|
303
|
+
id.indexOf('codestral') === 0 ||
|
|
304
|
+
id.indexOf('devstral') === 0 ||
|
|
305
|
+
id.indexOf('open-mistral') === 0 ||
|
|
306
|
+
id.indexOf('open-mixtral') === 0
|
|
307
|
+
) {
|
|
290
308
|
return 'mistral'
|
|
291
309
|
}
|
|
292
|
-
if (
|
|
293
|
-
return 'perplexity'
|
|
294
|
-
}
|
|
295
|
-
if (modelId.startsWith('llama-')) {
|
|
310
|
+
if (id.indexOf('meta-llama/') === 0 || id.indexOf('llama') === 0) {
|
|
296
311
|
return 'meta'
|
|
297
312
|
}
|
|
298
313
|
return 'openai'
|
|
299
314
|
}
|
|
300
315
|
|
|
316
|
+
/** The provider a node will call: explicit config wins, inference is fallback. */
|
|
317
|
+
function __ai_resolveProvider(config: any): string {
|
|
318
|
+
const explicit = config && config.provider
|
|
319
|
+
if (typeof explicit === 'string' && explicit.trim()) {
|
|
320
|
+
return explicit.trim()
|
|
321
|
+
}
|
|
322
|
+
return __ai_detectProvider(config && config.model)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Request-shape rules that differ per model. Getting these wrong is a hard 400,
|
|
327
|
+
* not a degraded answer:
|
|
328
|
+
*
|
|
329
|
+
* - Anthropic removed `temperature` from Opus 4.7 onward, Sonnet 5 onward, and
|
|
330
|
+
* the Fable / Mythos line. Sending one fails the request outright.
|
|
331
|
+
* - OpenAI's reasoning models (`o1`, `o3`, `o4-mini`, every `gpt-5*`) replaced
|
|
332
|
+
* `max_tokens` with `max_completion_tokens` and reject a custom temperature.
|
|
333
|
+
* Their budget also covers hidden reasoning tokens, so a small cap is spent
|
|
334
|
+
* thinking and the answer comes back EMPTY with no error — hence the floor.
|
|
335
|
+
*
|
|
336
|
+
* Mirrored in the editor by `getAIModelCapabilities`
|
|
337
|
+
* (`features/workflows/constants/ai-providers/capabilities.ts`), which uses the
|
|
338
|
+
* same rules to hide the Temperature field. Keep the two in sync.
|
|
339
|
+
*/
|
|
340
|
+
function __ai_modelCapabilities(provider: any, model: any, requestedMaxTokens: any): any {
|
|
341
|
+
const id = String(model || '').toLowerCase()
|
|
342
|
+
// Anthropic rejects a request with no max_tokens at all, so every provider
|
|
343
|
+
// gets a concrete number rather than `undefined`.
|
|
344
|
+
const requested =
|
|
345
|
+
typeof requestedMaxTokens === 'number' && requestedMaxTokens > 0 ? requestedMaxTokens : 1024
|
|
346
|
+
const caps: any = {
|
|
347
|
+
supportsTemperature: true,
|
|
348
|
+
maxTokensParam: 'max_tokens',
|
|
349
|
+
maxTokens: requested,
|
|
350
|
+
reasoningModel: false,
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (provider === 'anthropic') {
|
|
354
|
+
const match = /^claude-(fable|mythos|opus|sonnet|haiku)-(\d+)(?:-(\d+))?/.exec(id)
|
|
355
|
+
if (match) {
|
|
356
|
+
const family = match[1]
|
|
357
|
+
const major = parseInt(match[2], 10)
|
|
358
|
+
const minor = match[3] ? parseInt(match[3], 10) : 0
|
|
359
|
+
if (family === 'fable' || family === 'mythos') {
|
|
360
|
+
caps.supportsTemperature = false
|
|
361
|
+
} else if (family === 'opus' && (major > 4 || (major === 4 && minor >= 7))) {
|
|
362
|
+
caps.supportsTemperature = false
|
|
363
|
+
} else if (family === 'sonnet' && major >= 5) {
|
|
364
|
+
caps.supportsTemperature = false
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return caps
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (provider === 'openai' && (/^o\d/.test(id) || id.indexOf('gpt-5') === 0)) {
|
|
371
|
+
caps.supportsTemperature = false
|
|
372
|
+
caps.maxTokensParam = 'max_completion_tokens'
|
|
373
|
+
caps.reasoningModel = true
|
|
374
|
+
// The budget covers hidden reasoning tokens as well as the visible answer.
|
|
375
|
+
// Below this floor the model can spend the whole allowance thinking and
|
|
376
|
+
// return an EMPTY string with a normal 200 — a silent failure in a live
|
|
377
|
+
// chat. The editor states the same floor next to the Max Tokens field.
|
|
378
|
+
if (caps.maxTokens < 2000) {
|
|
379
|
+
caps.maxTokens = 2000
|
|
380
|
+
}
|
|
381
|
+
return caps
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return caps
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Floor applied to OpenAI reasoning models — see `__ai_modelCapabilities`. */
|
|
388
|
+
export const AI_REASONING_MODEL_MIN_TOKENS = 2000
|
|
389
|
+
|
|
390
|
+
/** The OpenAI-compatible base URL a provider is reached on, or undefined. */
|
|
391
|
+
function __ai_providerBaseURL(provider: any): string | undefined {
|
|
392
|
+
if (provider === 'perplexity') {
|
|
393
|
+
return 'https://api.perplexity.ai'
|
|
394
|
+
}
|
|
395
|
+
if (provider === 'meta') {
|
|
396
|
+
// Llama has no first-party inference API — Together AI serves it over an
|
|
397
|
+
// OpenAI-compatible endpoint, which is why Meta model ids are Together's
|
|
398
|
+
// namespaced `meta-llama/…` ones and the key is a Together key.
|
|
399
|
+
return 'https://api.together.xyz/v1'
|
|
400
|
+
}
|
|
401
|
+
return undefined
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Builds a Chat Completions request body honouring the model's capabilities:
|
|
406
|
+
* the right output-token field, and `temperature` only where it is accepted.
|
|
407
|
+
*/
|
|
408
|
+
function __ai_openAICompatibleBody(
|
|
409
|
+
caps: any,
|
|
410
|
+
model: any,
|
|
411
|
+
systemMessage: any,
|
|
412
|
+
userMessage: any,
|
|
413
|
+
temperature: any,
|
|
414
|
+
jsonMode: any
|
|
415
|
+
): any {
|
|
416
|
+
const messages: any[] = []
|
|
417
|
+
if (systemMessage) {
|
|
418
|
+
messages.push({ role: 'system', content: systemMessage })
|
|
419
|
+
}
|
|
420
|
+
messages.push({ role: 'user', content: userMessage })
|
|
421
|
+
|
|
422
|
+
const opts: any = { model, messages }
|
|
423
|
+
opts[caps.maxTokensParam] = caps.maxTokens
|
|
424
|
+
if (caps.supportsTemperature) {
|
|
425
|
+
opts.temperature = temperature
|
|
426
|
+
}
|
|
427
|
+
if (jsonMode) {
|
|
428
|
+
opts.response_format = { type: 'json_object' }
|
|
429
|
+
}
|
|
430
|
+
return opts
|
|
431
|
+
}
|
|
432
|
+
|
|
301
433
|
function __ai_clampTemperature(temp: any, provider: string): number {
|
|
434
|
+
// ⛔ Must stay aligned with DEFAULT_TEMPERATURE_RANGES in the editor
|
|
435
|
+
// (`features/workflows/constants/ai-providers/capabilities.ts`), or the
|
|
436
|
+
// inspector will accept a value the runtime silently rewrites.
|
|
302
437
|
const ranges: Record<string, number[]> = {
|
|
303
438
|
openai: [0, 2],
|
|
304
439
|
anthropic: [0, 1],
|
|
305
|
-
google: [0,
|
|
306
|
-
cohere: [0,
|
|
440
|
+
google: [0, 2],
|
|
441
|
+
cohere: [0, 1],
|
|
307
442
|
mistral: [0, 1],
|
|
308
443
|
meta: [0, 2],
|
|
309
444
|
perplexity: [0, 2],
|
|
@@ -350,47 +485,11 @@ async function __ai_callProvider(params: any): Promise<any> {
|
|
|
350
485
|
const systemMessage = params.systemMessage
|
|
351
486
|
const userMessage = params.userMessage
|
|
352
487
|
const temperature = params.temperature
|
|
353
|
-
const maxTokens = params.maxTokens
|
|
354
488
|
const jsonMode = params.jsonMode || false
|
|
489
|
+
const caps = __ai_modelCapabilities(provider, model, params.maxTokens)
|
|
355
490
|
const __nodeRequire =
|
|
356
491
|
typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require
|
|
357
492
|
|
|
358
|
-
if (provider === 'openai') {
|
|
359
|
-
return (async function () {
|
|
360
|
-
const _mod = __nodeRequire('openai')
|
|
361
|
-
const OpenAI = _mod.default || _mod
|
|
362
|
-
const messages: any[] = []
|
|
363
|
-
if (systemMessage) {
|
|
364
|
-
messages.push({ role: 'system', content: systemMessage })
|
|
365
|
-
}
|
|
366
|
-
messages.push({ role: 'user', content: userMessage })
|
|
367
|
-
const client = new OpenAI({ apiKey: token })
|
|
368
|
-
const opts: any = {
|
|
369
|
-
model,
|
|
370
|
-
messages,
|
|
371
|
-
temperature,
|
|
372
|
-
max_tokens: maxTokens,
|
|
373
|
-
}
|
|
374
|
-
if (jsonMode) {
|
|
375
|
-
opts.response_format = { type: 'json_object' }
|
|
376
|
-
}
|
|
377
|
-
const completion = await client.chat.completions.create(opts)
|
|
378
|
-
const usage = completion.usage || {}
|
|
379
|
-
return {
|
|
380
|
-
content:
|
|
381
|
-
(completion.choices[0] &&
|
|
382
|
-
completion.choices[0].message &&
|
|
383
|
-
completion.choices[0].message.content) ||
|
|
384
|
-
'',
|
|
385
|
-
usage: {
|
|
386
|
-
promptTokens: usage.prompt_tokens || 0,
|
|
387
|
-
completionTokens: usage.completion_tokens || 0,
|
|
388
|
-
totalTokens: usage.total_tokens || 0,
|
|
389
|
-
},
|
|
390
|
-
}
|
|
391
|
-
})()
|
|
392
|
-
}
|
|
393
|
-
|
|
394
493
|
if (provider === 'anthropic') {
|
|
395
494
|
return (async function () {
|
|
396
495
|
const _mod = __nodeRequire('@anthropic-ai/sdk')
|
|
@@ -399,8 +498,12 @@ async function __ai_callProvider(params: any): Promise<any> {
|
|
|
399
498
|
const opts: any = {
|
|
400
499
|
model,
|
|
401
500
|
messages: [{ role: 'user', content: userMessage }],
|
|
402
|
-
|
|
403
|
-
|
|
501
|
+
// Anthropic requires max_tokens on every request; the capability
|
|
502
|
+
// resolver guarantees a positive number.
|
|
503
|
+
max_tokens: caps.maxTokens,
|
|
504
|
+
}
|
|
505
|
+
if (caps.supportsTemperature) {
|
|
506
|
+
opts.temperature = temperature
|
|
404
507
|
}
|
|
405
508
|
if (systemMessage) {
|
|
406
509
|
opts.system = systemMessage
|
|
@@ -437,9 +540,16 @@ async function __ai_callProvider(params: any): Promise<any> {
|
|
|
437
540
|
fullPrompt += systemMessage + '\n\n'
|
|
438
541
|
}
|
|
439
542
|
fullPrompt += userMessage
|
|
543
|
+
const generationConfig: any = { maxOutputTokens: caps.maxTokens }
|
|
544
|
+
if (caps.supportsTemperature) {
|
|
545
|
+
generationConfig.temperature = temperature
|
|
546
|
+
}
|
|
547
|
+
if (jsonMode) {
|
|
548
|
+
generationConfig.responseMimeType = 'application/json'
|
|
549
|
+
}
|
|
440
550
|
const result = await genModel.generateContent({
|
|
441
551
|
contents: [{ role: 'user', parts: [{ text: fullPrompt }] }],
|
|
442
|
-
generationConfig
|
|
552
|
+
generationConfig,
|
|
443
553
|
})
|
|
444
554
|
const resp = result.response
|
|
445
555
|
const meta = resp.usageMetadata || {}
|
|
@@ -462,8 +572,10 @@ async function __ai_callProvider(params: any): Promise<any> {
|
|
|
462
572
|
const opts: any = {
|
|
463
573
|
model,
|
|
464
574
|
message: userMessage,
|
|
465
|
-
|
|
466
|
-
|
|
575
|
+
maxTokens: caps.maxTokens,
|
|
576
|
+
}
|
|
577
|
+
if (caps.supportsTemperature) {
|
|
578
|
+
opts.temperature = temperature
|
|
467
579
|
}
|
|
468
580
|
if (systemMessage) {
|
|
469
581
|
opts.preamble = systemMessage
|
|
@@ -491,12 +603,18 @@ async function __ai_callProvider(params: any): Promise<any> {
|
|
|
491
603
|
messages.push({ role: 'system', content: systemMessage })
|
|
492
604
|
}
|
|
493
605
|
messages.push({ role: 'user', content: userMessage })
|
|
494
|
-
const
|
|
606
|
+
const opts: any = {
|
|
495
607
|
model,
|
|
496
608
|
messages,
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
609
|
+
maxTokens: caps.maxTokens,
|
|
610
|
+
}
|
|
611
|
+
if (caps.supportsTemperature) {
|
|
612
|
+
opts.temperature = temperature
|
|
613
|
+
}
|
|
614
|
+
if (jsonMode) {
|
|
615
|
+
opts.responseFormat = { type: 'json_object' }
|
|
616
|
+
}
|
|
617
|
+
const response = await client.chat.complete(opts)
|
|
500
618
|
const choice = response.choices && response.choices[0] ? response.choices[0] : ({} as any)
|
|
501
619
|
const usage = response.usage || {}
|
|
502
620
|
return {
|
|
@@ -510,35 +628,27 @@ async function __ai_callProvider(params: any): Promise<any> {
|
|
|
510
628
|
})()
|
|
511
629
|
}
|
|
512
630
|
|
|
513
|
-
// meta, perplexity, or unknown
|
|
631
|
+
// openai, meta (via Together), perplexity, or an unknown provider — all
|
|
632
|
+
// reachable through the OpenAI-compatible Chat Completions shape.
|
|
514
633
|
return (async function () {
|
|
515
634
|
const _mod = __nodeRequire('openai')
|
|
516
635
|
const OpenAI = _mod.default || _mod
|
|
517
|
-
const baseURL =
|
|
518
|
-
provider === 'perplexity'
|
|
519
|
-
? 'https://api.perplexity.ai'
|
|
520
|
-
: provider === 'meta'
|
|
521
|
-
? 'https://api.together.xyz/v1'
|
|
522
|
-
: undefined
|
|
636
|
+
const baseURL = __ai_providerBaseURL(provider)
|
|
523
637
|
const clientOpts: any = { apiKey: token }
|
|
524
638
|
if (baseURL) {
|
|
525
639
|
clientOpts.baseURL = baseURL
|
|
526
640
|
}
|
|
527
641
|
const client = new OpenAI(clientOpts)
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
messages.push({ role: 'user', content: userMessage })
|
|
533
|
-
const opts: any = {
|
|
642
|
+
// Only first-party OpenAI implements JSON mode; the compatible endpoints
|
|
643
|
+
// reject the parameter, so it is dropped for them.
|
|
644
|
+
const opts = __ai_openAICompatibleBody(
|
|
645
|
+
caps,
|
|
534
646
|
model,
|
|
535
|
-
|
|
647
|
+
systemMessage,
|
|
648
|
+
userMessage,
|
|
536
649
|
temperature,
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (jsonMode && !baseURL) {
|
|
540
|
-
opts.response_format = { type: 'json_object' }
|
|
541
|
-
}
|
|
650
|
+
jsonMode && !baseURL
|
|
651
|
+
)
|
|
542
652
|
const completion = await client.chat.completions.create(opts)
|
|
543
653
|
const usage = completion.usage || {}
|
|
544
654
|
return {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
declare function __ai_resolveTextField(val: any): string
|
|
9
9
|
declare function __ai_resolveToken(token: any): string
|
|
10
|
-
declare function
|
|
10
|
+
declare function __ai_resolveProvider(config: any): string
|
|
11
11
|
declare function __ai_clampTemperature(temp: any, provider: string): number
|
|
12
12
|
declare function __ai_callProvider(params: any): Promise<any>
|
|
13
13
|
declare function __ai_parseJSON(text: any): any
|
|
@@ -47,7 +47,7 @@ async function ai_sentiment_analysis(
|
|
|
47
47
|
return { error: true, message: err.message, code: 'authentication_error' }
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const provider =
|
|
50
|
+
const provider = __ai_resolveProvider(config)
|
|
51
51
|
const temperature = __ai_clampTemperature(0, provider)
|
|
52
52
|
|
|
53
53
|
let systemPrompt
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
declare function __ai_resolveTextField(val: any): string
|
|
9
9
|
declare function __ai_resolveToken(token: any): string
|
|
10
|
-
declare function
|
|
10
|
+
declare function __ai_resolveProvider(config: any): string
|
|
11
11
|
declare function __ai_clampTemperature(temp: any, provider: string): number
|
|
12
12
|
declare function __ai_callProvider(params: any): Promise<any>
|
|
13
13
|
declare function __ai_handleStreamingCall(
|
|
@@ -35,7 +35,7 @@ async function ai_summarization(
|
|
|
35
35
|
return { error: true, message: err.message, code: 'authentication_error' }
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
const provider =
|
|
38
|
+
const provider = __ai_resolveProvider(config)
|
|
39
39
|
const temperature = __ai_clampTemperature(0.3, provider)
|
|
40
40
|
|
|
41
41
|
const length = config.length || 'medium'
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
declare function __ai_resolveTextField(val: any): string
|
|
9
9
|
declare function __ai_resolveToken(token: any): string
|
|
10
|
-
declare function
|
|
10
|
+
declare function __ai_resolveProvider(config: any): string
|
|
11
11
|
declare function __ai_clampTemperature(temp: any, provider: string): number
|
|
12
12
|
declare function __ai_callProvider(params: any): Promise<any>
|
|
13
13
|
declare function __ai_parseJSON(text: any): any
|
|
@@ -56,7 +56,7 @@ async function ai_text_classifier(
|
|
|
56
56
|
return { error: true, message: err.message, code: 'authentication_error' }
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const provider =
|
|
59
|
+
const provider = __ai_resolveProvider(config)
|
|
60
60
|
const temperature = __ai_clampTemperature(0, provider)
|
|
61
61
|
|
|
62
62
|
let systemPrompt
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
declare function __ai_resolveTextField(val: any): string
|
|
9
9
|
declare function __ai_resolveToken(token: any): string
|
|
10
|
-
declare function
|
|
10
|
+
declare function __ai_resolveProvider(config: any): string
|
|
11
11
|
declare function __ai_clampTemperature(temp: any, provider: string): number
|
|
12
12
|
declare function __ai_callProvider(params: any): Promise<any>
|
|
13
13
|
declare function __ai_handleStreamingCall(
|
|
@@ -38,7 +38,7 @@ async function ai_text_transform(
|
|
|
38
38
|
return { error: true, message: err.message, code: 'authentication_error' }
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const provider =
|
|
41
|
+
const provider = __ai_resolveProvider(config)
|
|
42
42
|
const temperature = __ai_clampTemperature(0.3, provider)
|
|
43
43
|
|
|
44
44
|
const langNames: Record<string, string> = {
|
|
@@ -3,7 +3,47 @@ import { NodeHandlerGenerator, handlerToString } from '../types'
|
|
|
3
3
|
async function cart_clear() {
|
|
4
4
|
try {
|
|
5
5
|
localStorage.setItem('workflow_cart', JSON.stringify([]))
|
|
6
|
+
|
|
7
|
+
// Mirror the empty cart into the DATABASE cart as well.
|
|
8
|
+
//
|
|
9
|
+
// `EcommerceProvider` re-hydrates from `/api/cart/load` whenever
|
|
10
|
+
// localStorage is empty on mount (see `cartDbMountEffect` in
|
|
11
|
+
// ecommerce-context-generator). Clearing only localStorage therefore
|
|
12
|
+
// leaves the server copy intact, and the very next full page load
|
|
13
|
+
// (checkout -> order-details, or any hard reload) resurrects the cart the
|
|
14
|
+
// buyer just ordered. The provider's own debounced persist would push the
|
|
15
|
+
// empty state eventually, but it fires 300ms later — after a post-order
|
|
16
|
+
// redirect has already navigated away.
|
|
17
|
+
//
|
|
18
|
+
// `/api/cart/sync` is the same endpoint the provider persists through: it
|
|
19
|
+
// resolves identity server-side (NextAuth token for signed-in users, the
|
|
20
|
+
// client `sessionId` for guests) and transactionally replaces the active
|
|
21
|
+
// cart's items — so an empty payload empties the stored cart for BOTH
|
|
22
|
+
// identities. Deliberately does NOT flip the cart's status to ordered:
|
|
23
|
+
// this handler also backs the storefront's plain "Clear cart" button, and
|
|
24
|
+
// that cart was never ordered. Checkout owns that signal (see the
|
|
25
|
+
// data-create-item handler).
|
|
26
|
+
//
|
|
27
|
+
// Fire-and-forget and fully guarded: the route only exists for Postgres
|
|
28
|
+
// datasources (see `isPostgresCartDataSource`), so a 404 here is a normal,
|
|
29
|
+
// expected outcome that must never surface to the shopper or abort the
|
|
30
|
+
// workflow.
|
|
6
31
|
if (typeof window !== 'undefined') {
|
|
32
|
+
try {
|
|
33
|
+
// Marks this empty cart as DELIBERATE. `EcommerceProvider`'s DB
|
|
34
|
+
// reconcile effect reads the stamp (`wasCartJustCleared`) so it can
|
|
35
|
+
// tell "just checked out" apart from "first visit, restore my cart"
|
|
36
|
+
// and skip re-hydrating while the sync below is still in flight.
|
|
37
|
+
localStorage.setItem('workflow_cart_cleared_at', String(Date.now()))
|
|
38
|
+
const sessionId = localStorage.getItem('workflow_cart_session_id') || null
|
|
39
|
+
fetch('/api/cart/sync', {
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: { 'Content-Type': 'application/json' },
|
|
42
|
+
body: JSON.stringify({ items: [], sessionId }),
|
|
43
|
+
}).catch(function () {})
|
|
44
|
+
} catch (_dbErr) {
|
|
45
|
+
/* localStorage or fetch unavailable — local clear already succeeded */
|
|
46
|
+
}
|
|
7
47
|
window.dispatchEvent(new CustomEvent('teleport:cart-changed'))
|
|
8
48
|
}
|
|
9
49
|
return { success: true }
|