@standardagents/builder 0.13.0 → 0.13.2
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/built-in-routes.js +44805 -14038
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +29 -29
- package/dist/client/vue.js +1 -1
- package/dist/image-processing.js +34 -13
- package/dist/image-processing.js.map +1 -1
- package/dist/{index-T0gR5l-G.d.ts → index-8zDQpR2z.d.ts} +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +475 -73
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.js +97 -31
- package/dist/plugin.js.map +1 -1
- package/dist/sip.wasm +0 -0
- package/dist/test.d.ts +1 -1
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ProviderError, mapReasoningLevel, defineTool } from '@standardagents/spec';
|
|
2
2
|
export { ProviderError, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import {
|
|
4
|
+
import { transform, collect } from '@standardagents/sip';
|
|
5
5
|
import * as fs4 from 'fs';
|
|
6
6
|
import fs4__default from 'fs';
|
|
7
7
|
import * as path8 from 'path';
|
|
@@ -193,6 +193,274 @@ var init_StreamManager = __esm({
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
|
+
|
|
197
|
+
// src/agents/pricing.ts
|
|
198
|
+
function getGoogleFallbackPricing(modelId) {
|
|
199
|
+
const normalized = normalizeGoogleModelId(modelId);
|
|
200
|
+
const exact = GOOGLE_MODEL_PRICING[normalized];
|
|
201
|
+
if (exact) return { ...exact, source: "google-static" };
|
|
202
|
+
const prefixMatch = GOOGLE_MODEL_PRICING_PREFIXES.find((entry) => normalized.startsWith(entry.prefix));
|
|
203
|
+
if (prefixMatch) return { ...prefixMatch.pricing, source: "google-static" };
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
function getGroqFallbackPricing(modelId) {
|
|
207
|
+
const pricing = GROQ_MODEL_PRICING[normalizeModelId(modelId)];
|
|
208
|
+
return pricing ? { ...pricing, source: "groq-static" } : null;
|
|
209
|
+
}
|
|
210
|
+
function getXAIFallbackPricing(modelId) {
|
|
211
|
+
const pricing = XAI_MODEL_PRICING[normalizeModelId(modelId)];
|
|
212
|
+
return pricing ? { ...pricing, source: "xai-static" } : null;
|
|
213
|
+
}
|
|
214
|
+
function normalizeModelId(modelId) {
|
|
215
|
+
return (modelId || "").trim().toLowerCase();
|
|
216
|
+
}
|
|
217
|
+
function normalizeGoogleModelId(modelId) {
|
|
218
|
+
return normalizeModelId(modelId).replace(/^google\//, "").replace(/^models\//, "").replace(/^publishers\/google\/models\//, "");
|
|
219
|
+
}
|
|
220
|
+
function roundCost(value) {
|
|
221
|
+
return Number(value.toFixed(12));
|
|
222
|
+
}
|
|
223
|
+
function getCerebrasFallbackPricing(modelId) {
|
|
224
|
+
const pricing = CEREBRAS_MODEL_PRICING[normalizeModelId(modelId)];
|
|
225
|
+
return pricing ? { ...pricing, source: "cerebras-static" } : null;
|
|
226
|
+
}
|
|
227
|
+
function resolveModelPricing(modelDef, providerName) {
|
|
228
|
+
if (typeof modelDef.inputPrice === "number" && typeof modelDef.outputPrice === "number") {
|
|
229
|
+
return {
|
|
230
|
+
inputPrice: modelDef.inputPrice,
|
|
231
|
+
outputPrice: modelDef.outputPrice,
|
|
232
|
+
cachedPrice: modelDef.cachedPrice,
|
|
233
|
+
source: "model"
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
if (providerName === "cerebras") {
|
|
237
|
+
return getCerebrasFallbackPricing(modelDef.model);
|
|
238
|
+
}
|
|
239
|
+
if (providerName === "google") {
|
|
240
|
+
return getGoogleFallbackPricing(modelDef.model);
|
|
241
|
+
}
|
|
242
|
+
if (providerName === "groq") {
|
|
243
|
+
return getGroqFallbackPricing(modelDef.model);
|
|
244
|
+
}
|
|
245
|
+
if (providerName === "xai") {
|
|
246
|
+
return getXAIFallbackPricing(modelDef.model);
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
function calculateUsageCost(usage, pricing) {
|
|
251
|
+
if (!pricing) {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const cachedTokens = Math.max(usage.prompt_tokens_details?.cached_tokens || 0, 0);
|
|
255
|
+
const promptTokens = Math.max(usage.prompt_tokens || 0, 0);
|
|
256
|
+
const completionTokens = Math.max(usage.completion_tokens || 0, 0);
|
|
257
|
+
const reasoningTokens = pricing.source === "google-static" ? Math.max(usage.completion_tokens_details?.reasoning_tokens || 0, 0) : 0;
|
|
258
|
+
const billableOutputTokens = completionTokens + reasoningTokens;
|
|
259
|
+
const uncachedPromptTokens = Math.max(promptTokens - cachedTokens, 0);
|
|
260
|
+
const cachedTokenPrice = pricing.cachedPrice ?? pricing.inputPrice;
|
|
261
|
+
const costInput = roundCost(
|
|
262
|
+
(uncachedPromptTokens * pricing.inputPrice + cachedTokens * cachedTokenPrice) / TOKENS_PER_MILLION
|
|
263
|
+
);
|
|
264
|
+
const costOutput = roundCost(billableOutputTokens * pricing.outputPrice / TOKENS_PER_MILLION);
|
|
265
|
+
return {
|
|
266
|
+
costInput,
|
|
267
|
+
costOutput,
|
|
268
|
+
costTotal: roundCost(costInput + costOutput)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
var TOKENS_PER_MILLION, CEREBRAS_MODEL_PRICING, GOOGLE_MODEL_PRICING, GOOGLE_MODEL_PRICING_PREFIXES, GROQ_MODEL_PRICING, XAI_MODEL_PRICING;
|
|
272
|
+
var init_pricing = __esm({
|
|
273
|
+
"src/agents/pricing.ts"() {
|
|
274
|
+
TOKENS_PER_MILLION = 1e6;
|
|
275
|
+
CEREBRAS_MODEL_PRICING = {
|
|
276
|
+
"zai-glm-4.7": {
|
|
277
|
+
inputPrice: 2.25,
|
|
278
|
+
outputPrice: 2.75
|
|
279
|
+
},
|
|
280
|
+
"gpt-oss-120b": {
|
|
281
|
+
inputPrice: 0.35,
|
|
282
|
+
outputPrice: 0.75
|
|
283
|
+
},
|
|
284
|
+
"llama3.1-8b": {
|
|
285
|
+
inputPrice: 0.1,
|
|
286
|
+
outputPrice: 0.1
|
|
287
|
+
},
|
|
288
|
+
"qwen-3-235b-a22b-instruct-2507": {
|
|
289
|
+
inputPrice: 0.6,
|
|
290
|
+
outputPrice: 1.2
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
GOOGLE_MODEL_PRICING = {
|
|
294
|
+
"gemini-3-pro-preview": {
|
|
295
|
+
inputPrice: 2,
|
|
296
|
+
outputPrice: 12,
|
|
297
|
+
cachedPrice: 0.2
|
|
298
|
+
},
|
|
299
|
+
"gemini-3.1-pro-preview": {
|
|
300
|
+
inputPrice: 2,
|
|
301
|
+
outputPrice: 12,
|
|
302
|
+
cachedPrice: 0.2
|
|
303
|
+
},
|
|
304
|
+
"gemini-2.5-pro": {
|
|
305
|
+
inputPrice: 1.25,
|
|
306
|
+
outputPrice: 10,
|
|
307
|
+
cachedPrice: 0.125
|
|
308
|
+
},
|
|
309
|
+
"gemini-2.5-flash": {
|
|
310
|
+
inputPrice: 0.3,
|
|
311
|
+
outputPrice: 2.5,
|
|
312
|
+
cachedPrice: 0.03
|
|
313
|
+
},
|
|
314
|
+
"gemini-2.5-flash-lite": {
|
|
315
|
+
inputPrice: 0.1,
|
|
316
|
+
outputPrice: 0.4,
|
|
317
|
+
cachedPrice: 0.01
|
|
318
|
+
},
|
|
319
|
+
"gemini-3-flash-preview": {
|
|
320
|
+
inputPrice: 0.5,
|
|
321
|
+
outputPrice: 3,
|
|
322
|
+
cachedPrice: 0.05
|
|
323
|
+
},
|
|
324
|
+
"gemini-3.1-flash-lite-preview": {
|
|
325
|
+
inputPrice: 0.25,
|
|
326
|
+
outputPrice: 1.5,
|
|
327
|
+
cachedPrice: 0.025
|
|
328
|
+
},
|
|
329
|
+
"deep-research-pro-preview-12-2025": {
|
|
330
|
+
inputPrice: 2,
|
|
331
|
+
outputPrice: 12,
|
|
332
|
+
cachedPrice: 0.2
|
|
333
|
+
},
|
|
334
|
+
"gemini-2.0-flash": {
|
|
335
|
+
inputPrice: 0.1,
|
|
336
|
+
outputPrice: 0.4,
|
|
337
|
+
cachedPrice: 0.025
|
|
338
|
+
},
|
|
339
|
+
"gemini-2.0-flash-001": {
|
|
340
|
+
inputPrice: 0.1,
|
|
341
|
+
outputPrice: 0.4,
|
|
342
|
+
cachedPrice: 0.025
|
|
343
|
+
},
|
|
344
|
+
"gemini-2.0-flash-lite": {
|
|
345
|
+
inputPrice: 0.075,
|
|
346
|
+
outputPrice: 0.3
|
|
347
|
+
},
|
|
348
|
+
"gemini-2.0-flash-lite-001": {
|
|
349
|
+
inputPrice: 0.075,
|
|
350
|
+
outputPrice: 0.3
|
|
351
|
+
},
|
|
352
|
+
"gemini-2.5-computer-use-preview-10-2025": {
|
|
353
|
+
inputPrice: 1.25,
|
|
354
|
+
outputPrice: 10
|
|
355
|
+
},
|
|
356
|
+
"gemini-2.5-flash-image": {
|
|
357
|
+
inputPrice: 0.3,
|
|
358
|
+
outputPrice: 0
|
|
359
|
+
},
|
|
360
|
+
"gemini-3.1-flash-image-preview": {
|
|
361
|
+
inputPrice: 0.5,
|
|
362
|
+
outputPrice: 3
|
|
363
|
+
},
|
|
364
|
+
"gemini-3-pro-image-preview": {
|
|
365
|
+
inputPrice: 2,
|
|
366
|
+
outputPrice: 0
|
|
367
|
+
},
|
|
368
|
+
"nano-banana-pro-preview": {
|
|
369
|
+
inputPrice: 2,
|
|
370
|
+
outputPrice: 0
|
|
371
|
+
},
|
|
372
|
+
"gemma-4-31b-it": {
|
|
373
|
+
inputPrice: 0,
|
|
374
|
+
outputPrice: 0,
|
|
375
|
+
cachedPrice: 0
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
GOOGLE_MODEL_PRICING_PREFIXES = [
|
|
379
|
+
{
|
|
380
|
+
prefix: "gemini-3.1-pro-preview",
|
|
381
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-3.1-pro-preview"]
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
prefix: "gemini-3-pro-preview",
|
|
385
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-3-pro-preview"]
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
prefix: "gemini-3-flash-preview",
|
|
389
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-3-flash-preview"]
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
prefix: "gemini-3.1-flash-lite-preview",
|
|
393
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-3.1-flash-lite-preview"]
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
prefix: "gemini-2.5-flash-lite-preview-",
|
|
397
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-2.5-flash-lite"]
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
prefix: "gemini-flash-latest",
|
|
401
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-2.5-flash"]
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
prefix: "gemini-flash-lite-latest",
|
|
405
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-2.5-flash-lite"]
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
prefix: "gemini-pro-latest",
|
|
409
|
+
pricing: GOOGLE_MODEL_PRICING["gemini-2.5-pro"]
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
prefix: "gemma-4-",
|
|
413
|
+
pricing: {
|
|
414
|
+
inputPrice: 0,
|
|
415
|
+
outputPrice: 0,
|
|
416
|
+
cachedPrice: 0
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
prefix: "gemma-3-",
|
|
421
|
+
pricing: {
|
|
422
|
+
inputPrice: 0,
|
|
423
|
+
outputPrice: 0,
|
|
424
|
+
cachedPrice: 0
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
prefix: "gemma-3n-",
|
|
429
|
+
pricing: {
|
|
430
|
+
inputPrice: 0,
|
|
431
|
+
outputPrice: 0,
|
|
432
|
+
cachedPrice: 0
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
];
|
|
436
|
+
GROQ_MODEL_PRICING = {
|
|
437
|
+
"llama-3.1-8b-instant": { inputPrice: 0.05, outputPrice: 0.08 },
|
|
438
|
+
"llama-3.3-70b-versatile": { inputPrice: 0.59, outputPrice: 0.79 },
|
|
439
|
+
"meta-llama/llama-4-scout-17b-16e-instruct": { inputPrice: 0.11, outputPrice: 0.34 },
|
|
440
|
+
"moonshotai/kimi-k2-instruct": { inputPrice: 1, outputPrice: 3 },
|
|
441
|
+
"openai/gpt-oss-120b": { inputPrice: 0.15, cachedPrice: 0.075, outputPrice: 0.6 },
|
|
442
|
+
"openai/gpt-oss-20b": { inputPrice: 0.075, cachedPrice: 0.037, outputPrice: 0.3 },
|
|
443
|
+
"qwen/qwen3-32b": { inputPrice: 0.29, outputPrice: 0.59 }
|
|
444
|
+
};
|
|
445
|
+
XAI_MODEL_PRICING = {
|
|
446
|
+
"grok-4-0709": { inputPrice: 30, cachedPrice: 7.5, outputPrice: 150 },
|
|
447
|
+
"grok-4": { inputPrice: 30, cachedPrice: 7.5, outputPrice: 150 },
|
|
448
|
+
"grok-4-latest": { inputPrice: 30, cachedPrice: 7.5, outputPrice: 150 },
|
|
449
|
+
"grok-4-fast-reasoning": { inputPrice: 2, cachedPrice: 0.5, outputPrice: 5 },
|
|
450
|
+
"grok-4-fast-non-reasoning": { inputPrice: 2, cachedPrice: 0.5, outputPrice: 5 },
|
|
451
|
+
"grok-4-1-fast-reasoning": { inputPrice: 2, cachedPrice: 0.5, outputPrice: 5 },
|
|
452
|
+
"grok-4-1-fast-non-reasoning": { inputPrice: 2, cachedPrice: 0.5, outputPrice: 5 },
|
|
453
|
+
"grok-4.20-0309-reasoning": { inputPrice: 20, cachedPrice: 2, outputPrice: 60 },
|
|
454
|
+
"grok-4.20-0309-non-reasoning": { inputPrice: 20, cachedPrice: 2, outputPrice: 60 },
|
|
455
|
+
"grok-4.20-multi-agent-0309": { inputPrice: 20, cachedPrice: 2, outputPrice: 60 },
|
|
456
|
+
"grok-code-fast-1": { inputPrice: 2, cachedPrice: 0.2, outputPrice: 15 },
|
|
457
|
+
"grok-3": { inputPrice: 30, cachedPrice: 7.5, outputPrice: 150 },
|
|
458
|
+
"grok-3-latest": { inputPrice: 30, cachedPrice: 7.5, outputPrice: 150 },
|
|
459
|
+
"grok-3-mini": { inputPrice: 3, cachedPrice: 0.75, outputPrice: 5 },
|
|
460
|
+
"grok-3-mini-latest": { inputPrice: 3, cachedPrice: 0.75, outputPrice: 5 }
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
});
|
|
196
464
|
var init_types2 = __esm({
|
|
197
465
|
"src/agents/providers/types.ts"() {
|
|
198
466
|
}
|
|
@@ -648,6 +916,12 @@ var init_ProviderRegistry = __esm({
|
|
|
648
916
|
if (modelDef.providerOptions?.baseUrl) {
|
|
649
917
|
config.baseUrl = modelDef.providerOptions.baseUrl;
|
|
650
918
|
}
|
|
919
|
+
if (providerName === "cloudflare" && !config.baseUrl && env.CLOUDFLARE_ACCOUNT_ID) {
|
|
920
|
+
config.baseUrl = `https://api.cloudflare.com/client/v4/accounts/${env.CLOUDFLARE_ACCOUNT_ID}/ai/v1`;
|
|
921
|
+
}
|
|
922
|
+
if (providerName === "cloudflare" && env.CLOUDFLARE_ACCOUNT_ID) {
|
|
923
|
+
config.accountId = env.CLOUDFLARE_ACCOUNT_ID;
|
|
924
|
+
}
|
|
651
925
|
return this.cacheAndReturn(modelName, providerFactory(config), modelDef);
|
|
652
926
|
}
|
|
653
927
|
buildResult(provider, modelDef) {
|
|
@@ -662,10 +936,14 @@ var init_ProviderRegistry = __esm({
|
|
|
662
936
|
*/
|
|
663
937
|
getApiKeyForProvider(providerName, env) {
|
|
664
938
|
const apiKeyEnvVarMap = {
|
|
939
|
+
cloudflare: "CLOUDFLARE_API_TOKEN",
|
|
940
|
+
cerebras: "CEREBRAS_API_KEY",
|
|
941
|
+
google: "GOOGLE_API_KEY",
|
|
942
|
+
groq: "GROQ_API_KEY",
|
|
665
943
|
openai: "OPENAI_API_KEY",
|
|
666
944
|
openrouter: "OPENROUTER_API_KEY",
|
|
667
945
|
anthropic: "ANTHROPIC_API_KEY",
|
|
668
|
-
|
|
946
|
+
xai: "XAI_API_KEY"
|
|
669
947
|
};
|
|
670
948
|
const envVar = apiKeyEnvVarMap[providerName.toLowerCase()];
|
|
671
949
|
if (envVar && env[envVar]) {
|
|
@@ -715,6 +993,13 @@ function modelSupportsImageInput(modelDef) {
|
|
|
715
993
|
}
|
|
716
994
|
return true;
|
|
717
995
|
}
|
|
996
|
+
function modelSupportsToolCalls(modelDef) {
|
|
997
|
+
const supportsToolCalls = modelDef.capabilities?.supportsToolCalls;
|
|
998
|
+
if (typeof supportsToolCalls === "boolean") {
|
|
999
|
+
return supportsToolCalls;
|
|
1000
|
+
}
|
|
1001
|
+
return true;
|
|
1002
|
+
}
|
|
718
1003
|
function filterImagesFromProviderMessages(messages) {
|
|
719
1004
|
let removedUserImageParts = 0;
|
|
720
1005
|
let removedToolImageAttachments = 0;
|
|
@@ -766,6 +1051,15 @@ function filterImagesFromProviderMessages(messages) {
|
|
|
766
1051
|
removedToolImageAttachments
|
|
767
1052
|
};
|
|
768
1053
|
}
|
|
1054
|
+
function filterEmptyAssistantProviderMessages(messages) {
|
|
1055
|
+
return messages.filter((message) => {
|
|
1056
|
+
if (message.role !== "assistant") return true;
|
|
1057
|
+
const hasToolCalls = Array.isArray(message.toolCalls) && message.toolCalls.length > 0;
|
|
1058
|
+
const hasReasoning = typeof message.reasoning === "string" ? message.reasoning.trim().length > 0 : Boolean(message.reasoningDetails);
|
|
1059
|
+
const hasContent = typeof message.content === "string" ? message.content.trim().length > 0 : message.content !== null;
|
|
1060
|
+
return hasToolCalls || hasReasoning || hasContent;
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
769
1063
|
function stripBase64FromMessages(messages, imagePathMap) {
|
|
770
1064
|
return messages.map((msg) => {
|
|
771
1065
|
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
@@ -911,25 +1205,31 @@ function transformToolChoice(toolChoice) {
|
|
|
911
1205
|
function buildRequestBody(context, modelDef) {
|
|
912
1206
|
const transformedMessages = transformMessages(context.messages);
|
|
913
1207
|
const supportsImageInput = modelSupportsImageInput(modelDef);
|
|
1208
|
+
const supportsToolCalls = modelSupportsToolCalls(modelDef);
|
|
914
1209
|
let requestMessages = transformedMessages;
|
|
915
1210
|
let visionFiltering;
|
|
916
1211
|
if (!supportsImageInput) {
|
|
917
1212
|
const filtered = filterImagesFromProviderMessages(transformedMessages);
|
|
918
1213
|
requestMessages = filtered.messages;
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1214
|
+
if (filtered.removedUserImageParts > 0 || filtered.removedToolImageAttachments > 0) {
|
|
1215
|
+
visionFiltering = {
|
|
1216
|
+
enabled: true,
|
|
1217
|
+
reason: "model_no_vision",
|
|
1218
|
+
removedUserImageParts: filtered.removedUserImageParts,
|
|
1219
|
+
removedToolImageAttachments: filtered.removedToolImageAttachments
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
925
1222
|
}
|
|
1223
|
+
requestMessages = filterEmptyAssistantProviderMessages(requestMessages);
|
|
1224
|
+
const tools = supportsToolCalls ? transformTools(context.tools) : void 0;
|
|
1225
|
+
const toolChoice = supportsToolCalls ? transformToolChoice(context.tool_choice) : void 0;
|
|
926
1226
|
return {
|
|
927
1227
|
requestBody: {
|
|
928
1228
|
model: modelDef.model,
|
|
929
1229
|
messages: requestMessages,
|
|
930
|
-
tools
|
|
931
|
-
toolChoice
|
|
932
|
-
parallelToolCalls: context.parallel_tool_calls,
|
|
1230
|
+
tools,
|
|
1231
|
+
toolChoice,
|
|
1232
|
+
parallelToolCalls: supportsToolCalls ? context.parallel_tool_calls : void 0,
|
|
933
1233
|
reasoning: context.reasoning ? {
|
|
934
1234
|
level: reasoningEffortToLevel(context.reasoning.effort),
|
|
935
1235
|
maxTokens: context.reasoning.max_tokens,
|
|
@@ -971,6 +1271,7 @@ function convertUsage(usage) {
|
|
|
971
1271
|
var NON_VISION_PLACEHOLDER_TEXT, LLMRequest;
|
|
972
1272
|
var init_LLMRequest = __esm({
|
|
973
1273
|
"src/agents/LLMRequest.ts"() {
|
|
1274
|
+
init_pricing();
|
|
974
1275
|
init_types();
|
|
975
1276
|
NON_VISION_PLACEHOLDER_TEXT = "[Image omitted: model does not support vision]";
|
|
976
1277
|
LLMRequest = class {
|
|
@@ -1080,7 +1381,7 @@ var init_LLMRequest = __esm({
|
|
|
1080
1381
|
timestamp: Date.now()
|
|
1081
1382
|
});
|
|
1082
1383
|
const response = await this.callModel(actualModelId, context, state, logId);
|
|
1083
|
-
await this.logSuccess(response, state, actualModelId, startTime, context, logId);
|
|
1384
|
+
await this.logSuccess(response, state, actualModelId, startTime, context, logId, modelDef);
|
|
1084
1385
|
state.emitTelemetry?.({
|
|
1085
1386
|
type: "llm_response",
|
|
1086
1387
|
tokens: response.usage.total_tokens,
|
|
@@ -1405,10 +1706,14 @@ var init_LLMRequest = __esm({
|
|
|
1405
1706
|
/**
|
|
1406
1707
|
* Update log with successful response data (best-effort, non-blocking)
|
|
1407
1708
|
*/
|
|
1408
|
-
static async logSuccess(response, state, modelId, startTime, context, logId) {
|
|
1709
|
+
static async logSuccess(response, state, modelId, startTime, context, logId, modelDef) {
|
|
1409
1710
|
try {
|
|
1410
1711
|
const toolsCalled = response.tool_calls ? JSON.stringify(response.tool_calls.map((tc) => tc.function.name)) : null;
|
|
1411
|
-
const
|
|
1712
|
+
const providerName = response._provider?.name;
|
|
1713
|
+
const resolvedPricing = resolveModelPricing(modelDef, providerName);
|
|
1714
|
+
const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
|
|
1715
|
+
const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
|
|
1716
|
+
const cost_total = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
|
|
1412
1717
|
const actualProvider = response.usage.provider;
|
|
1413
1718
|
const aggregateResponse = response._aggregate_response;
|
|
1414
1719
|
const responseBody = aggregateResponse ? JSON.stringify(aggregateResponse) : JSON.stringify(response);
|
|
@@ -1449,6 +1754,8 @@ var init_LLMRequest = __esm({
|
|
|
1449
1754
|
output_tokens: response.usage.completion_tokens,
|
|
1450
1755
|
reasoning_tokens: response.usage.completion_tokens_details?.reasoning_tokens || 0,
|
|
1451
1756
|
total_tokens: response.usage.total_tokens,
|
|
1757
|
+
cost_input: calculatedCost?.costInput,
|
|
1758
|
+
cost_output: calculatedCost?.costOutput,
|
|
1452
1759
|
latency_ms: Date.now() - startTime,
|
|
1453
1760
|
finish_reason: response.finish_reason,
|
|
1454
1761
|
tools_called: toolsCalled ?? void 0,
|
|
@@ -1473,15 +1780,17 @@ var init_LLMRequest = __esm({
|
|
|
1473
1780
|
output_tokens = ?4,
|
|
1474
1781
|
reasoning_tokens = ?5,
|
|
1475
1782
|
total_tokens = ?6,
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1783
|
+
cost_input = ?7,
|
|
1784
|
+
cost_output = ?8,
|
|
1785
|
+
latency_ms = ?9,
|
|
1786
|
+
finish_reason = ?10,
|
|
1787
|
+
tools_called = ?11,
|
|
1788
|
+
cost_total = ?12,
|
|
1789
|
+
is_complete = ?13,
|
|
1790
|
+
reasoning_content = ?14,
|
|
1791
|
+
provider_tools = ?15,
|
|
1792
|
+
actual_provider = ?16
|
|
1793
|
+
WHERE id = ?17
|
|
1485
1794
|
`,
|
|
1486
1795
|
logData.response_body,
|
|
1487
1796
|
logData.input_tokens,
|
|
@@ -1489,6 +1798,8 @@ var init_LLMRequest = __esm({
|
|
|
1489
1798
|
logData.output_tokens,
|
|
1490
1799
|
logData.reasoning_tokens,
|
|
1491
1800
|
logData.total_tokens,
|
|
1801
|
+
logData.cost_input ?? null,
|
|
1802
|
+
logData.cost_output ?? null,
|
|
1492
1803
|
logData.latency_ms,
|
|
1493
1804
|
logData.finish_reason,
|
|
1494
1805
|
logData.tools_called,
|
|
@@ -5558,10 +5869,16 @@ function svgToDataUri(svg) {
|
|
|
5558
5869
|
const encoded = encodeURIComponent(svg).replace(/'/g, "%27").replace(/"/g, "%22");
|
|
5559
5870
|
return `data:image/svg+xml,${encoded}`;
|
|
5560
5871
|
}
|
|
5872
|
+
function normalizeIcon(icon) {
|
|
5873
|
+
if (icon.startsWith("data:") || icon.endsWith(".svg") || icon.includes(".svg?")) {
|
|
5874
|
+
return icon;
|
|
5875
|
+
}
|
|
5876
|
+
return svgToDataUri(icon);
|
|
5877
|
+
}
|
|
5561
5878
|
function getOpenAIIconDataUri() {
|
|
5562
|
-
return
|
|
5879
|
+
return normalizeIcon(OPENAI_ICON);
|
|
5563
5880
|
}
|
|
5564
|
-
var DEFAULT_REASONING_LEVELS, OPENAI_NATIVE_TOOLS, OPENAI_ICON, OpenAIProvider, openaiProviderOptions, openai;
|
|
5881
|
+
var DEFAULT_REASONING_LEVELS, OPENAI_NATIVE_TOOLS, openai_default, OPENAI_ICON, OpenAIProvider, openaiProviderOptions, openai;
|
|
5565
5882
|
var init_dist = __esm({
|
|
5566
5883
|
"../openai/dist/index.js"() {
|
|
5567
5884
|
DEFAULT_REASONING_LEVELS = {
|
|
@@ -5576,10 +5893,8 @@ var init_dist = __esm({
|
|
|
5576
5893
|
"code_interpreter",
|
|
5577
5894
|
"file_search"
|
|
5578
5895
|
]);
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
<path d="M19.3418 18.5599V14.7599C19.3418 14.4399 19.4608 14.1998 19.7382 14.04L27.3102 9.63997C28.3409 9.03999 29.5699 8.76014 30.8383 8.76014C35.5954 8.76014 38.6085 12.4802 38.6085 16.4401C38.6085 16.72 38.6085 17.04 38.5687 17.3601L30.7194 12.72C30.2437 12.4401 29.7678 12.4401 29.2922 12.72L19.3418 18.5599ZM37.0226 33.36V24.2799C37.0226 23.7197 36.7846 23.3197 36.309 23.0398L26.3586 17.1998L29.6093 15.3197C29.8868 15.1599 30.1247 15.1599 30.4022 15.3197L37.9741 19.7197C40.1547 20.9999 41.6213 23.7197 41.6213 26.3596C41.6213 29.3995 39.8375 32.1999 37.0226 33.36ZM17.0029 25.3601L13.7522 23.4402C13.4748 23.2804 13.3557 23.0402 13.3557 22.7202V13.9203C13.3557 9.64039 16.6065 6.40016 21.0069 6.40016C22.6722 6.40016 24.2179 6.96029 25.5265 7.96025L17.7168 12.5204C17.2412 12.8003 17.0033 13.2002 17.0033 13.7605L17.0029 25.3601ZM24 29.44L19.3418 26.8001V21.2003L24 18.5604L28.6578 21.2003V26.8001L24 29.44ZM26.993 41.6002C25.3278 41.6002 23.7821 41.04 22.4735 40.0402L30.2831 35.4799C30.7588 35.2001 30.9967 34.8001 30.9967 34.2399V22.6399L34.2873 24.5598C34.5646 24.7196 34.6837 24.9597 34.6837 25.2798V34.0797C34.6837 38.3596 31.3931 41.6002 26.993 41.6002ZM17.5975 32.6802L10.0255 28.2803C7.84493 27.0001 6.37833 24.2803 6.37833 21.6404C6.37833 18.5604 8.20193 15.8004 11.0164 14.6403V23.7602C11.0164 24.3204 11.2544 24.7204 11.73 25.0003L21.641 30.8001L18.3902 32.6802C18.1129 32.84 17.8749 32.84 17.5975 32.6802ZM17.1617 39.2402C12.682 39.2402 9.39151 35.8402 9.39151 31.6401C9.39151 31.3201 9.43125 31.0001 9.47066 30.68L17.2803 35.2402C17.7559 35.5201 18.2319 35.5201 18.7074 35.2402L28.6578 29.4404V33.2404C28.6578 33.5605 28.5388 33.8005 28.2614 33.9604L20.6894 38.3604C19.6586 38.9603 18.4301 39.2402 17.1617 39.2402ZM26.993 44C31.7899 44 35.7936 40.5601 36.7057 36C41.1457 34.8399 44 30.6399 44 26.36C44 23.5598 42.8108 20.8401 40.6701 18.88C40.8683 18.0399 40.9872 17.1998 40.9872 16.3602C40.9872 10.6403 36.3885 6.35998 31.0763 6.35998C30.0062 6.35998 28.9754 6.51979 27.9446 6.88001C26.1604 5.11992 23.7025 4 21.0069 4C16.2101 4 12.2064 7.4398 11.2943 12C6.8543 13.1601 4 17.3601 4 21.6399C4 24.4401 5.18916 27.1599 7.32995 29.1199C7.13174 29.96 7.01277 30.8001 7.01277 31.6398C7.01277 37.3597 11.6114 41.6399 16.9236 41.6399C17.9938 41.6399 19.0246 41.4801 20.0554 41.1199C21.8392 42.88 24.2971 44 26.993 44Z" fill="black"/>
|
|
5582
|
-
</svg>`;
|
|
5896
|
+
openai_default = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" fill="none" viewBox="0 0 128 128"><g clip-path="url(%23clip0_2138_504)"><g clip-path="url(%23clip1_2138_504)"><path fill="%23000" d="M118.824 52.388a31.9 31.9 0 0 0-2.74-26.192 32.25 32.25 0 0 0-34.736-15.472A31.9 31.9 0 0 0 57.296 0C43.28-.032 30.844 8.992 26.532 22.328A31.9 31.9 0 0 0 5.208 37.796C-1.828 49.924-.224 65.212 9.176 75.612a31.9 31.9 0 0 0 2.74 26.192 32.25 32.25 0 0 0 34.736 15.472 31.88 31.88 0 0 0 24.052 10.72c14.024.036 26.464-8.996 30.776-22.344a31.9 31.9 0 0 0 21.324-15.468 32.26 32.26 0 0 0-3.976-37.804zm-48.112 67.244a23.9 23.9 0 0 1-15.356-5.552c.196-.104.536-.292.756-.428L81.6 98.932a4.14 4.14 0 0 0 2.096-3.628V59.372l10.772 6.22a.38.38 0 0 1 .208.296v29.756c-.016 13.232-10.732 23.96-23.964 23.988M19.176 97.62a23.88 23.88 0 0 1-2.86-16.072c.188.112.52.316.756.452L42.56 96.72a4.15 4.15 0 0 0 4.188 0l31.116-17.968v12.44a.4.4 0 0 1-.152.332L51.948 106.4c-11.476 6.608-26.132 2.68-32.768-8.78zm-6.708-55.636a23.9 23.9 0 0 1 12.484-10.516c0 .22-.012.608-.012.88v29.444a4.15 4.15 0 0 0 2.092 3.624L58.148 83.38 47.376 89.6a.38.38 0 0 1-.364.032L21.244 74.744c-11.452-6.632-15.38-21.284-8.78-32.756zm88.504 20.596L69.856 44.612l10.772-6.216a.38.38 0 0 1 .364-.032L106.76 53.24c11.472 6.628 15.404 21.304 8.776 32.776a23.98 23.98 0 0 1-12.48 10.512V66.204a4.14 4.14 0 0 0-2.08-3.624zm10.72-16.136c-.188-.116-.52-.316-.756-.452l-25.488-14.72a4.15 4.15 0 0 0-4.188 0L50.144 49.24V36.8a.4.4 0 0 1 .152-.332L76.06 21.604c11.476-6.62 26.148-2.68 32.764 8.8a23.98 23.98 0 0 1 2.86 16.04zM44.288 68.616l-10.776-6.22a.38.38 0 0 1-.208-.296V32.344C33.312 19.096 44.06 8.36 57.308 8.368a23.98 23.98 0 0 1 15.336 5.552c-.196.104-.532.292-.756.428L46.4 29.068a4.14 4.14 0 0 0-2.096 3.624l-.016 35.916zM50.14 56 64 47.996l13.86 8V72L64 80l-13.86-8z"/></g></g><defs><clipPath id="clip0_2138_504"><path fill="%23fff" d="M0 0h128v128H0z"/></clipPath><clipPath id="clip1_2138_504"><path fill="%23fff" d="M0 0h128v128H0z"/></clipPath></defs></svg>';
|
|
5897
|
+
OPENAI_ICON = openai_default;
|
|
5583
5898
|
OpenAIProvider = class _OpenAIProvider {
|
|
5584
5899
|
name = "openai";
|
|
5585
5900
|
specificationVersion = "1";
|
|
@@ -10870,22 +11185,42 @@ __export(image_processing_exports, {
|
|
|
10870
11185
|
needsProcessing: () => needsProcessing,
|
|
10871
11186
|
processImage: () => processImage
|
|
10872
11187
|
});
|
|
11188
|
+
function clampQuality(quality) {
|
|
11189
|
+
return Math.max(1, Math.min(100, Math.round(quality)));
|
|
11190
|
+
}
|
|
11191
|
+
async function collectTransformedImage(input, width, height, quality) {
|
|
11192
|
+
const image = transform(input, { width, height, quality: clampQuality(quality) });
|
|
11193
|
+
const { data, info } = await collect(image);
|
|
11194
|
+
return {
|
|
11195
|
+
data,
|
|
11196
|
+
mimeType: "image/jpeg",
|
|
11197
|
+
width: info.width,
|
|
11198
|
+
height: info.height
|
|
11199
|
+
};
|
|
11200
|
+
}
|
|
11201
|
+
async function transformToTargetSize(input, maxWidth, maxHeight, maxBytes, quality) {
|
|
11202
|
+
let currentQuality = clampQuality(quality);
|
|
11203
|
+
let result = await collectTransformedImage(input, maxWidth, maxHeight, currentQuality);
|
|
11204
|
+
while (result.data.byteLength > maxBytes && currentQuality > MIN_QUALITY) {
|
|
11205
|
+
currentQuality -= 10;
|
|
11206
|
+
result = await collectTransformedImage(input, maxWidth, maxHeight, currentQuality);
|
|
11207
|
+
}
|
|
11208
|
+
while (result.data.byteLength > maxBytes) {
|
|
11209
|
+
const scaleFactor = Math.sqrt(maxBytes / result.data.byteLength) * 0.9;
|
|
11210
|
+
const nextWidth = Math.max(1, Math.min(result.width - 1, Math.round(result.width * scaleFactor)));
|
|
11211
|
+
const nextHeight = Math.max(1, Math.min(result.height - 1, Math.round(result.height * scaleFactor)));
|
|
11212
|
+
if (nextWidth >= result.width && nextHeight >= result.height) {
|
|
11213
|
+
break;
|
|
11214
|
+
}
|
|
11215
|
+
result = await collectTransformedImage(input, nextWidth, nextHeight, currentQuality);
|
|
11216
|
+
}
|
|
11217
|
+
return result;
|
|
11218
|
+
}
|
|
10873
11219
|
async function processImage(input, inputMimeType) {
|
|
10874
11220
|
if (input.byteLength > MAX_INPUT_SIZE) {
|
|
10875
11221
|
throw new Error(`Image too large: ${input.byteLength} bytes exceeds ${MAX_INPUT_SIZE} byte limit`);
|
|
10876
11222
|
}
|
|
10877
|
-
|
|
10878
|
-
maxWidth: MAX_DIMENSION,
|
|
10879
|
-
maxHeight: MAX_DIMENSION,
|
|
10880
|
-
maxBytes: MAX_SIZE,
|
|
10881
|
-
quality: 85
|
|
10882
|
-
});
|
|
10883
|
-
return {
|
|
10884
|
-
data: result.data,
|
|
10885
|
-
mimeType: "image/jpeg",
|
|
10886
|
-
width: result.width,
|
|
10887
|
-
height: result.height
|
|
10888
|
-
};
|
|
11223
|
+
return await transformToTargetSize(input, MAX_DIMENSION, MAX_DIMENSION, MAX_SIZE, 85);
|
|
10889
11224
|
}
|
|
10890
11225
|
function needsProcessing(data, mimeType) {
|
|
10891
11226
|
const binaryLength = Math.ceil(data.length * 3 / 4);
|
|
@@ -10907,12 +11242,13 @@ function arrayBufferToBase64(buffer) {
|
|
|
10907
11242
|
}
|
|
10908
11243
|
return btoa(binary);
|
|
10909
11244
|
}
|
|
10910
|
-
var MAX_SIZE, MAX_DIMENSION, MAX_INPUT_SIZE;
|
|
11245
|
+
var MAX_SIZE, MAX_DIMENSION, MAX_INPUT_SIZE, MIN_QUALITY;
|
|
10911
11246
|
var init_image_processing = __esm({
|
|
10912
11247
|
"src/image-processing/index.ts"() {
|
|
10913
11248
|
MAX_SIZE = 1.5 * 1024 * 1024;
|
|
10914
11249
|
MAX_DIMENSION = 4096;
|
|
10915
11250
|
MAX_INPUT_SIZE = 20 * 1024 * 1024;
|
|
11251
|
+
MIN_QUALITY = 45;
|
|
10916
11252
|
}
|
|
10917
11253
|
});
|
|
10918
11254
|
var TSCONFIG_CONTENT = `{
|
|
@@ -12289,14 +12625,89 @@ function formatSessionBinding(binding) {
|
|
|
12289
12625
|
return `{ ${parts.join(", ")} }`;
|
|
12290
12626
|
}
|
|
12291
12627
|
|
|
12628
|
+
// src/providers/catalog.ts
|
|
12629
|
+
var FIRST_PARTY_PROVIDERS = [
|
|
12630
|
+
{
|
|
12631
|
+
name: "cloudflare",
|
|
12632
|
+
package: "@standardagents/cloudflare",
|
|
12633
|
+
label: "Cloudflare Workers AI",
|
|
12634
|
+
envKeys: ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]
|
|
12635
|
+
},
|
|
12636
|
+
{
|
|
12637
|
+
name: "cerebras",
|
|
12638
|
+
package: "@standardagents/cerebras",
|
|
12639
|
+
label: "Cerebras",
|
|
12640
|
+
envKeys: ["CEREBRAS_API_KEY"]
|
|
12641
|
+
},
|
|
12642
|
+
{
|
|
12643
|
+
name: "google",
|
|
12644
|
+
package: "@standardagents/google",
|
|
12645
|
+
label: "Google Gemini",
|
|
12646
|
+
envKeys: ["GOOGLE_API_KEY"]
|
|
12647
|
+
},
|
|
12648
|
+
{
|
|
12649
|
+
name: "groq",
|
|
12650
|
+
package: "@standardagents/groq",
|
|
12651
|
+
label: "Groq",
|
|
12652
|
+
envKeys: ["GROQ_API_KEY"]
|
|
12653
|
+
},
|
|
12654
|
+
{
|
|
12655
|
+
name: "openai",
|
|
12656
|
+
package: "@standardagents/openai",
|
|
12657
|
+
label: "OpenAI",
|
|
12658
|
+
envKeys: ["OPENAI_API_KEY"]
|
|
12659
|
+
},
|
|
12660
|
+
{
|
|
12661
|
+
name: "openrouter",
|
|
12662
|
+
package: "@standardagents/openrouter",
|
|
12663
|
+
label: "OpenRouter",
|
|
12664
|
+
envKeys: ["OPENROUTER_API_KEY"]
|
|
12665
|
+
},
|
|
12666
|
+
{
|
|
12667
|
+
name: "xai",
|
|
12668
|
+
package: "@standardagents/xai",
|
|
12669
|
+
label: "xAI",
|
|
12670
|
+
envKeys: ["XAI_API_KEY"]
|
|
12671
|
+
}
|
|
12672
|
+
];
|
|
12673
|
+
function humanizeProviderName(name) {
|
|
12674
|
+
return name.split(/[-_]/g).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
12675
|
+
}
|
|
12676
|
+
function packageToCustomProvider(pkg) {
|
|
12677
|
+
const name = pkg.split("/").pop() || pkg;
|
|
12678
|
+
return {
|
|
12679
|
+
name,
|
|
12680
|
+
package: pkg,
|
|
12681
|
+
label: humanizeProviderName(name),
|
|
12682
|
+
envKeys: [`${name.toUpperCase().replace(/-/g, "_")}_API_KEY`],
|
|
12683
|
+
isCustom: true
|
|
12684
|
+
};
|
|
12685
|
+
}
|
|
12686
|
+
function buildInstalledProviderCatalog(customProviderPackages = []) {
|
|
12687
|
+
const providers = [...FIRST_PARTY_PROVIDERS];
|
|
12688
|
+
const seen = new Set(providers.map((provider) => provider.name));
|
|
12689
|
+
for (const pkg of customProviderPackages) {
|
|
12690
|
+
const provider = packageToCustomProvider(pkg);
|
|
12691
|
+
if (seen.has(provider.name)) continue;
|
|
12692
|
+
providers.push(provider);
|
|
12693
|
+
seen.add(provider.name);
|
|
12694
|
+
}
|
|
12695
|
+
return providers;
|
|
12696
|
+
}
|
|
12697
|
+
function buildProviderPackageMap(customProviderPackages = []) {
|
|
12698
|
+
return Object.fromEntries(
|
|
12699
|
+
buildInstalledProviderCatalog(customProviderPackages).map((provider) => [
|
|
12700
|
+
provider.name,
|
|
12701
|
+
{
|
|
12702
|
+
name: provider.name,
|
|
12703
|
+
package: provider.package
|
|
12704
|
+
}
|
|
12705
|
+
])
|
|
12706
|
+
);
|
|
12707
|
+
}
|
|
12708
|
+
|
|
12292
12709
|
// src/sdk/persistence/index.ts
|
|
12293
|
-
var
|
|
12294
|
-
openai: { name: "openai", package: "@standardagents/openai" },
|
|
12295
|
-
openrouter: { name: "openrouter", package: "@standardagents/openrouter" },
|
|
12296
|
-
anthropic: { name: "anthropic", package: "@standardagents/anthropic" },
|
|
12297
|
-
google: { name: "google", package: "@standardagents/google" },
|
|
12298
|
-
test: { name: "test", package: "@standardagents/builder/test" }
|
|
12299
|
-
};
|
|
12710
|
+
var defaultProviderPackageMap = buildProviderPackageMap();
|
|
12300
12711
|
function nameToFilename(name) {
|
|
12301
12712
|
return name.replace(/[/\\]/g, "__").replace(/[:*?"<>|.]/g, "_").replace(/-/g, "_");
|
|
12302
12713
|
}
|
|
@@ -12308,7 +12719,7 @@ function modelExists(modelsDir, name) {
|
|
|
12308
12719
|
const filePath = getModelFilePath(modelsDir, name);
|
|
12309
12720
|
return fs4__default.existsSync(filePath);
|
|
12310
12721
|
}
|
|
12311
|
-
async function saveModel(modelsDir, data, overwrite = false) {
|
|
12722
|
+
async function saveModel(modelsDir, data, overwrite = false, providerPackageMap = defaultProviderPackageMap) {
|
|
12312
12723
|
try {
|
|
12313
12724
|
if (!fs4__default.existsSync(modelsDir)) {
|
|
12314
12725
|
fs4__default.mkdirSync(modelsDir, { recursive: true });
|
|
@@ -12320,11 +12731,11 @@ async function saveModel(modelsDir, data, overwrite = false) {
|
|
|
12320
12731
|
error: `Model file already exists: ${filePath}. Use update to modify existing models.`
|
|
12321
12732
|
};
|
|
12322
12733
|
}
|
|
12323
|
-
const providerInfo =
|
|
12734
|
+
const providerInfo = providerPackageMap[data.provider];
|
|
12324
12735
|
if (!providerInfo) {
|
|
12325
12736
|
return {
|
|
12326
12737
|
success: false,
|
|
12327
|
-
error: `Unknown provider '${data.provider}'. Must be one of: ${Object.keys(
|
|
12738
|
+
error: `Unknown provider '${data.provider}'. Must be one of: ${Object.keys(providerPackageMap).join(", ")}`
|
|
12328
12739
|
};
|
|
12329
12740
|
}
|
|
12330
12741
|
const content = generateModelFile(data, {
|
|
@@ -12387,7 +12798,7 @@ function transformModelData(data) {
|
|
|
12387
12798
|
}
|
|
12388
12799
|
return transformed;
|
|
12389
12800
|
}
|
|
12390
|
-
function
|
|
12801
|
+
function validateModelDataWithProviders(data, providerPackageMap) {
|
|
12391
12802
|
const errors = {};
|
|
12392
12803
|
if (!data.name || typeof data.name !== "string") {
|
|
12393
12804
|
errors["name"] = "Model name is required";
|
|
@@ -12395,7 +12806,7 @@ function validateModelData(data) {
|
|
|
12395
12806
|
if (!data.provider || typeof data.provider !== "string") {
|
|
12396
12807
|
errors["provider"] = "Provider is required";
|
|
12397
12808
|
} else {
|
|
12398
|
-
const validProviders = Object.keys(
|
|
12809
|
+
const validProviders = Object.keys(providerPackageMap);
|
|
12399
12810
|
if (!validProviders.includes(data.provider)) {
|
|
12400
12811
|
errors["provider"] = `Invalid provider '${data.provider}'. Must be one of: ${validProviders.join(", ")}`;
|
|
12401
12812
|
}
|
|
@@ -16185,6 +16596,8 @@ function agentbuilder(options = {}) {
|
|
|
16185
16596
|
const agentsDir = options.agentsDir ? path8__default.resolve(process.cwd(), options.agentsDir) : path8__default.resolve(process.cwd(), "agents/agents");
|
|
16186
16597
|
const effectsDir = options.effectsDir ? path8__default.resolve(process.cwd(), options.effectsDir) : path8__default.resolve(process.cwd(), "agents/effects");
|
|
16187
16598
|
const outputDir = path8__default.resolve(process.cwd(), ".agents");
|
|
16599
|
+
const installedProviders = buildInstalledProviderCatalog(options.providers || []);
|
|
16600
|
+
const installedProviderPackageMap = buildProviderPackageMap(options.providers || []);
|
|
16188
16601
|
const typeGenConfig = {
|
|
16189
16602
|
modelsDir,
|
|
16190
16603
|
promptsDir,
|
|
@@ -17156,18 +17569,7 @@ export const effectNames = ${JSON.stringify(effects.filter((e) => !e.error).map(
|
|
|
17156
17569
|
`;
|
|
17157
17570
|
}
|
|
17158
17571
|
if (id === RESOLVED_VIRTUAL_PROVIDERS_ID) {
|
|
17159
|
-
const
|
|
17160
|
-
{ name: "openai", package: "@standardagents/openai", label: "OpenAI", envKey: "OPENAI_API_KEY" },
|
|
17161
|
-
{ name: "openrouter", package: "@standardagents/openrouter", label: "OpenRouter", envKey: "OPENROUTER_API_KEY" }
|
|
17162
|
-
];
|
|
17163
|
-
const customProviders = (options.providers || []).map((pkg) => ({
|
|
17164
|
-
name: pkg.split("/").pop() || pkg,
|
|
17165
|
-
package: pkg,
|
|
17166
|
-
label: pkg.split("/").pop() || pkg,
|
|
17167
|
-
envKey: `${(pkg.split("/").pop() || pkg).toUpperCase().replace(/-/g, "_")}_API_KEY`,
|
|
17168
|
-
isCustom: true
|
|
17169
|
-
}));
|
|
17170
|
-
const allProviders = [...firstPartyProviders, ...customProviders];
|
|
17572
|
+
const allProviders = installedProviders;
|
|
17171
17573
|
return `// Virtual providers module - lists available LLM provider packages
|
|
17172
17574
|
export const providers = ${JSON.stringify(allProviders, null, 2)};
|
|
17173
17575
|
|
|
@@ -17457,11 +17859,11 @@ export function getVisibleToolNames() {
|
|
|
17457
17859
|
import { DurableThread as _BaseDurableThread } from '@standardagents/builder/runtime';
|
|
17458
17860
|
import { DurableAgentBuilder as _BaseDurableAgentBuilder } from '@standardagents/builder/runtime';
|
|
17459
17861
|
|
|
17460
|
-
// Import sip WASM module and
|
|
17862
|
+
// Import sip WASM module and readiness helper
|
|
17461
17863
|
// Static import allows workerd to pre-compile the WASM at bundle time
|
|
17462
17864
|
// WASM is bundled in builder's dist to avoid transitive dependency resolution issues
|
|
17463
17865
|
import _sipWasm from '@standardagents/builder/dist/sip.wasm';
|
|
17464
|
-
import {
|
|
17866
|
+
import { ready as _initSipWasm } from '@standardagents/sip';
|
|
17465
17867
|
|
|
17466
17868
|
// Re-export router from virtual:@standardagents-routes
|
|
17467
17869
|
export { router } from 'virtual:@standardagents-routes';
|
|
@@ -17505,7 +17907,7 @@ export class DurableThread extends _BaseDurableThread {
|
|
|
17505
17907
|
// blockConcurrencyWhile ensures WASM is ready before handling any requests
|
|
17506
17908
|
// Pass the statically imported WASM module for workerd to pre-compile
|
|
17507
17909
|
ctx.blockConcurrencyWhile(async () => {
|
|
17508
|
-
await _initSipWasm(_sipWasm);
|
|
17910
|
+
await _initSipWasm({ wasm: _sipWasm });
|
|
17509
17911
|
});
|
|
17510
17912
|
}
|
|
17511
17913
|
|
|
@@ -17606,7 +18008,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
17606
18008
|
try {
|
|
17607
18009
|
const rawBody = await parseRequestBody(req);
|
|
17608
18010
|
const body = transformModelData(rawBody);
|
|
17609
|
-
const fieldErrors =
|
|
18011
|
+
const fieldErrors = validateModelDataWithProviders(body, installedProviderPackageMap);
|
|
17610
18012
|
if (fieldErrors) {
|
|
17611
18013
|
res.statusCode = 400;
|
|
17612
18014
|
res.setHeader("Content-Type", "application/json");
|
|
@@ -17619,7 +18021,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
17619
18021
|
res.end(JSON.stringify({ error: `Model '${body.name}' already exists. Use PUT to update.` }));
|
|
17620
18022
|
return;
|
|
17621
18023
|
}
|
|
17622
|
-
const result = await saveModel(modelsDir, body, false);
|
|
18024
|
+
const result = await saveModel(modelsDir, body, false, installedProviderPackageMap);
|
|
17623
18025
|
if (result.success) {
|
|
17624
18026
|
await reloadModelsModule(server);
|
|
17625
18027
|
await reloadRouterModule(server);
|
|
@@ -17651,7 +18053,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
17651
18053
|
const body = transformModelData(rawBody);
|
|
17652
18054
|
const newName = body.name;
|
|
17653
18055
|
const isNameChange = newName && newName !== urlModelName;
|
|
17654
|
-
const fieldErrors =
|
|
18056
|
+
const fieldErrors = validateModelDataWithProviders(body, installedProviderPackageMap);
|
|
17655
18057
|
if (fieldErrors) {
|
|
17656
18058
|
res.statusCode = 400;
|
|
17657
18059
|
res.setHeader("Content-Type", "application/json");
|
|
@@ -17669,7 +18071,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
|
|
|
17669
18071
|
}
|
|
17670
18072
|
updatedPrompts = await updateModelReferencesInPrompts(promptsDir, urlModelName, newName);
|
|
17671
18073
|
}
|
|
17672
|
-
const result = await saveModel(modelsDir, body, true);
|
|
18074
|
+
const result = await saveModel(modelsDir, body, true, installedProviderPackageMap);
|
|
17673
18075
|
if (result.success) {
|
|
17674
18076
|
await reloadModelsModule(server);
|
|
17675
18077
|
if (updatedPrompts.length > 0) {
|