@standardagents/builder 0.24.6 → 0.24.7
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 +151 -23
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/{ApiKeysView-CmZKVcOR.js → ApiKeysView-C_QyBNy2.js} +1 -1
- package/dist/client/{CenteredContentView-DK7rPUK2.js → CenteredContentView-c7OLhxvd.js} +1 -1
- package/dist/client/CompositionView-DqKI6dJ9.js +32 -0
- package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-h7YuRPAr.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-DQIo2wlE.js} +1 -1
- package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-BpQ6CMUp.js → CopyButton.vue_vue_type_script_setup_true_lang-q-A7DQTq.js} +1 -1
- package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-DCUZbvUM.js → DataTable.vue_vue_type_script_setup_true_lang-B0UNyBiO.js} +1 -1
- package/dist/client/{JsonViewer-CvwfQYW-.js → JsonViewer-DrA7M9_g.js} +1 -1
- package/dist/client/{LoginView-DnaG5knS.js → LoginView-BxbNgfzz.js} +1 -1
- package/dist/client/{MarketplaceView-fX_Juw54.js → MarketplaceView-DXrtN6-0.js} +1 -1
- package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-CFFVfl1g.js → Modal.vue_vue_type_script_setup_true_lang-CLZzFYMW.js} +1 -1
- package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-B68s7Jo1.js → ModelModal.vue_vue_type_script_setup_true_lang-BaLZApRs.js} +1 -1
- package/dist/client/{ModelsView-lv4-IyA2.js → ModelsView-CVtPgAVZ.js} +1 -1
- package/dist/client/{PromptEditView-DGaxlMMx.js → PromptEditView-Dhc0rBHD.js} +1 -1
- package/dist/client/{PromptModal-DaW1J_W6.js → PromptModal-DXt6M359.js} +1 -1
- package/dist/client/{PromptsView-CdiBqZey.js → PromptsView-y3yvzkjM.js} +1 -1
- package/dist/client/{ProvidersView-B37bgFKh.js → ProvidersView-DN-SmDPF.js} +1 -1
- package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-lIW3rtYB.js +22 -0
- package/dist/client/ThreadsView-B1Xo2bP0.js +1 -0
- package/dist/client/{ToolsView-BMKgNq7O.js → ToolsView-DYj_Mk9L.js} +1 -1
- package/dist/client/{UsersView-BDKchqNQ.js → UsersView-BLNNFDUM.js} +1 -1
- package/dist/client/{VariablesView-BPioaCbu.js → VariablesView-D4-5tNwt.js} +1 -1
- package/dist/client/assets/{ThreadInspectorPane-lJJckks4.css → ThreadInspectorPane-CGrBd6US.css} +1 -1
- package/dist/client/assets/index-B38KmIlM.css +1 -0
- package/dist/client/{index-BVfRoUms.js → index-0OxNDXyK.js} +2 -2
- package/dist/client/index.html +2 -2
- package/dist/{index-D3FNNQWC.d.ts → index-Bd--_E_1.d.ts} +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +177 -35
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -1
- package/dist/runtime.d.ts +12 -2
- package/dist/runtime.js +175 -35
- package/dist/runtime.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/package.json +5 -5
- package/dist/client/CompositionView-BvVMnyYP.js +0 -32
- package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DHlNdv7o.js +0 -22
- package/dist/client/ThreadsView-BAfuNShv.js +0 -1
- package/dist/client/assets/index-Djjx6d3k.css +0 -1
package/dist/runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as ThreadEnv, A as Agent, h as ThreadMetadata, i as ToolResult, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-
|
|
2
|
-
export { f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, c as createThreadEndpointHandler, d as defineController } from './index-
|
|
1
|
+
import { e as ThreadEnv, A as Agent, h as ThreadMetadata, i as ToolResult, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-Bd--_E_1.js';
|
|
2
|
+
export { f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, c as createThreadEndpointHandler, d as defineController } from './index-Bd--_E_1.js';
|
|
3
3
|
import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, ClientToolRequest, ClientToolResponse, SkillMetadata, SkillFileInput, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, PromptEnvPart, VariableDefinition, SubpromptConfig as SubpromptConfig$1, PromptToolConfig as PromptToolConfig$1, SubagentToolConfig as SubagentToolConfig$1, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
|
|
4
4
|
export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ModelCapabilities as ProviderModelCapabilities, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
|
|
5
5
|
import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
|
|
@@ -759,6 +759,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
759
759
|
inputCost: number;
|
|
760
760
|
cachedCost: number;
|
|
761
761
|
outputCost: number;
|
|
762
|
+
routerFeeCost: number;
|
|
762
763
|
requestCount: number;
|
|
763
764
|
messageCount: number;
|
|
764
765
|
byModel: Record<string, {
|
|
@@ -766,6 +767,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
766
767
|
inputCost: number;
|
|
767
768
|
cachedCost: number;
|
|
768
769
|
outputCost: number;
|
|
770
|
+
routerFeeCost: number;
|
|
769
771
|
count: number;
|
|
770
772
|
}>;
|
|
771
773
|
}>;
|
|
@@ -855,6 +857,8 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
855
857
|
cost_input: number | null;
|
|
856
858
|
cost_cached: number | null;
|
|
857
859
|
cost_output: number | null;
|
|
860
|
+
cost_router_fee: number | null;
|
|
861
|
+
router_fee_percent: number | null;
|
|
858
862
|
cost_total: number | null;
|
|
859
863
|
message_history_length: number | null;
|
|
860
864
|
tools_available: number | null;
|
|
@@ -3312,6 +3316,12 @@ interface ProviderLookupResult {
|
|
|
3312
3316
|
modelDef: ModelDefinition$1<string>;
|
|
3313
3317
|
/** True when requests route through the Standard Agents platform (hosted routing or a registered override). */
|
|
3314
3318
|
viaPlatform: boolean;
|
|
3319
|
+
/**
|
|
3320
|
+
* Platform origin serving the passthrough proxy when built-in hosted routing
|
|
3321
|
+
* is active. Lets request logging look up the router-fee percent observed on
|
|
3322
|
+
* this origin's proxied responses.
|
|
3323
|
+
*/
|
|
3324
|
+
platformProxyOrigin?: string;
|
|
3315
3325
|
}
|
|
3316
3326
|
/**
|
|
3317
3327
|
* Provider registry implementation
|
package/dist/runtime.js
CHANGED
|
@@ -234,6 +234,12 @@ function resolveModelPricing(modelDef, providerName) {
|
|
|
234
234
|
}
|
|
235
235
|
return null;
|
|
236
236
|
}
|
|
237
|
+
function calculateRouterFee(rawCost, feePercent) {
|
|
238
|
+
if (!(rawCost > 0) || !(feePercent > 0)) {
|
|
239
|
+
return 0;
|
|
240
|
+
}
|
|
241
|
+
return roundCost(rawCost * feePercent / 100);
|
|
242
|
+
}
|
|
237
243
|
function calculateUsageCost(usage, pricing) {
|
|
238
244
|
if (!pricing) {
|
|
239
245
|
return null;
|
|
@@ -264,6 +270,66 @@ var init_pricing = __esm({
|
|
|
264
270
|
TOKENS_PER_MILLION = 1e6;
|
|
265
271
|
}
|
|
266
272
|
});
|
|
273
|
+
|
|
274
|
+
// src/agents/providers/router-fee.ts
|
|
275
|
+
function requestUrl(input) {
|
|
276
|
+
if (typeof input === "string") return input;
|
|
277
|
+
if (input instanceof URL) return input.toString();
|
|
278
|
+
if (typeof input === "object" && input !== null && typeof input.url === "string") {
|
|
279
|
+
return input.url;
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
function observeResponse(url, headers) {
|
|
284
|
+
if (!url) return;
|
|
285
|
+
for (const origin of registeredOrigins) {
|
|
286
|
+
if (!url.startsWith(`${origin}/v1/proxy/`)) continue;
|
|
287
|
+
const raw = headers.get(ROUTER_FEE_HEADER);
|
|
288
|
+
if (raw !== null) {
|
|
289
|
+
const percent = Number(raw);
|
|
290
|
+
if (Number.isFinite(percent) && percent >= 0) {
|
|
291
|
+
observedFeePercentByOrigin.set(origin, percent);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function installObserver() {
|
|
298
|
+
if (observerInstalled) return;
|
|
299
|
+
const original = globalThis.fetch;
|
|
300
|
+
if (typeof original !== "function") return;
|
|
301
|
+
const bound = original.bind(globalThis);
|
|
302
|
+
const wrapped = async (input, init) => {
|
|
303
|
+
const response = await bound(input, init);
|
|
304
|
+
try {
|
|
305
|
+
observeResponse(requestUrl(input), response.headers);
|
|
306
|
+
} catch {
|
|
307
|
+
}
|
|
308
|
+
return response;
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
globalThis.fetch = wrapped;
|
|
312
|
+
observerInstalled = true;
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function registerPlatformProxyOrigin(origin) {
|
|
317
|
+
if (!origin) return;
|
|
318
|
+
registeredOrigins.add(origin.replace(/\/+$/, ""));
|
|
319
|
+
installObserver();
|
|
320
|
+
}
|
|
321
|
+
function getObservedRouterFeePercent(origin) {
|
|
322
|
+
return observedFeePercentByOrigin.get(origin.replace(/\/+$/, "")) ?? null;
|
|
323
|
+
}
|
|
324
|
+
var ROUTER_FEE_HEADER, registeredOrigins, observedFeePercentByOrigin, observerInstalled;
|
|
325
|
+
var init_router_fee = __esm({
|
|
326
|
+
"src/agents/providers/router-fee.ts"() {
|
|
327
|
+
ROUTER_FEE_HEADER = "X-Standard-Agents-Router-Fee-Percent";
|
|
328
|
+
registeredOrigins = /* @__PURE__ */ new Set();
|
|
329
|
+
observedFeePercentByOrigin = /* @__PURE__ */ new Map();
|
|
330
|
+
observerInstalled = false;
|
|
331
|
+
}
|
|
332
|
+
});
|
|
267
333
|
async function readCompletedArg(partialJson, argName) {
|
|
268
334
|
if (!partialJson || !argName) return void 0;
|
|
269
335
|
try {
|
|
@@ -814,6 +880,7 @@ var init_ProviderRegistry = __esm({
|
|
|
814
880
|
"src/agents/providers/ProviderRegistry.ts"() {
|
|
815
881
|
init_TestProvider();
|
|
816
882
|
init_platform_routing();
|
|
883
|
+
init_router_fee();
|
|
817
884
|
init_factory();
|
|
818
885
|
ProviderRegistryImpl = class {
|
|
819
886
|
providerCache = /* @__PURE__ */ new Map();
|
|
@@ -908,21 +975,22 @@ var init_ProviderRegistry = __esm({
|
|
|
908
975
|
apiKey: routing.apiKey,
|
|
909
976
|
baseUrl: routing.baseUrl
|
|
910
977
|
};
|
|
978
|
+
registerPlatformProxyOrigin(routing.origin);
|
|
911
979
|
const fingerprint = this.getProviderFingerprint(`platform:${providerName}`, modelDef, config);
|
|
912
980
|
const cached = this.providerCache.get(modelName);
|
|
913
981
|
if (cached?.fingerprint === fingerprint) {
|
|
914
|
-
return this.buildResult(cached.provider, modelDef, true);
|
|
982
|
+
return this.buildResult(cached.provider, modelDef, true, routing.origin);
|
|
915
983
|
}
|
|
916
|
-
return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true);
|
|
984
|
+
return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true, routing.origin);
|
|
917
985
|
}
|
|
918
986
|
throw new Error(`No API key found for provider: ${providerName}. Set the provider key or STANDARD_AGENTS_API_KEY.`);
|
|
919
987
|
}
|
|
920
|
-
buildResult(provider, modelDef, viaPlatform) {
|
|
921
|
-
return { provider, modelName: modelDef.model, modelDef, viaPlatform };
|
|
988
|
+
buildResult(provider, modelDef, viaPlatform, platformProxyOrigin) {
|
|
989
|
+
return { provider, modelName: modelDef.model, modelDef, viaPlatform, platformProxyOrigin };
|
|
922
990
|
}
|
|
923
|
-
cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform) {
|
|
991
|
+
cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform, platformProxyOrigin) {
|
|
924
992
|
this.providerCache.set(modelName, { provider, fingerprint, viaPlatform });
|
|
925
|
-
return this.buildResult(provider, modelDef, viaPlatform);
|
|
993
|
+
return this.buildResult(provider, modelDef, viaPlatform, platformProxyOrigin);
|
|
926
994
|
}
|
|
927
995
|
getProviderFingerprint(providerName, modelDef, config) {
|
|
928
996
|
return JSON.stringify({
|
|
@@ -1386,6 +1454,7 @@ var NON_VISION_PLACEHOLDER_TEXT, STREAM_FIRST_CHUNK_TIMEOUT_MS, STREAM_STALL_TIM
|
|
|
1386
1454
|
var init_LLMRequest = __esm({
|
|
1387
1455
|
"src/agents/LLMRequest.ts"() {
|
|
1388
1456
|
init_pricing();
|
|
1457
|
+
init_router_fee();
|
|
1389
1458
|
init_types();
|
|
1390
1459
|
init_FlowEngine();
|
|
1391
1460
|
init_toolProgress();
|
|
@@ -1649,11 +1718,7 @@ var init_LLMRequest = __esm({
|
|
|
1649
1718
|
*/
|
|
1650
1719
|
static async callModel(modelId, context, state, logId) {
|
|
1651
1720
|
const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
|
|
1652
|
-
const { provider, modelName, modelDef, viaPlatform } = await ProviderRegistry2.getProvider(
|
|
1653
|
-
modelId,
|
|
1654
|
-
state.env,
|
|
1655
|
-
state.thread.instance
|
|
1656
|
-
);
|
|
1721
|
+
const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(modelId, state.env, state.thread.instance);
|
|
1657
1722
|
const streamAbort = new AbortController();
|
|
1658
1723
|
const parentSignal = state.abortController?.signal;
|
|
1659
1724
|
let onParentAbort;
|
|
@@ -1932,6 +1997,12 @@ var init_LLMRequest = __esm({
|
|
|
1932
1997
|
};
|
|
1933
1998
|
response._provider = provider;
|
|
1934
1999
|
response._viaPlatform = viaPlatform;
|
|
2000
|
+
if (platformProxyOrigin) {
|
|
2001
|
+
const feePercent = getObservedRouterFeePercent(platformProxyOrigin);
|
|
2002
|
+
if (feePercent !== null) {
|
|
2003
|
+
response._routerFeePercent = feePercent;
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
1935
2006
|
response._providerResponseId = providerResponseId;
|
|
1936
2007
|
response._timing = {
|
|
1937
2008
|
latencyMs: firstChunkAt > 0 ? firstChunkAt - requestSentAt : null,
|
|
@@ -2060,7 +2131,10 @@ var init_LLMRequest = __esm({
|
|
|
2060
2131
|
const resolvedPricing = resolveModelPricing(modelDef) ?? resolveUsageReportedPricing(response.usage) ?? resolveModelPricing(modelDef, providerName);
|
|
2061
2132
|
const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
|
|
2062
2133
|
const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
|
|
2063
|
-
const
|
|
2134
|
+
const rawProviderCost = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
|
|
2135
|
+
const routerFeePercent = standardAgentsRouterUsed && typeof response._routerFeePercent === "number" && response._routerFeePercent > 0 ? response._routerFeePercent : null;
|
|
2136
|
+
const costRouterFee = routerFeePercent !== null && rawProviderCost !== null ? calculateRouterFee(rawProviderCost, routerFeePercent) : null;
|
|
2137
|
+
const cost_total = rawProviderCost !== null && costRouterFee !== null && costRouterFee > 0 ? roundCost(rawProviderCost + costRouterFee) : rawProviderCost;
|
|
2064
2138
|
const actualProvider = normalizeProviderMetadataValue(response.usage.provider) ?? null;
|
|
2065
2139
|
const aggregateResponse = response._aggregate_response;
|
|
2066
2140
|
const responseBody = aggregateResponse ? JSON.stringify(aggregateResponse) : JSON.stringify(response);
|
|
@@ -2126,6 +2200,8 @@ var init_LLMRequest = __esm({
|
|
|
2126
2200
|
cost_input: calculatedCost?.costInput,
|
|
2127
2201
|
cost_cached: calculatedCost?.costCached,
|
|
2128
2202
|
cost_output: calculatedCost?.costOutput,
|
|
2203
|
+
cost_router_fee: costRouterFee ?? void 0,
|
|
2204
|
+
router_fee_percent: routerFeePercent ?? void 0,
|
|
2129
2205
|
latency_ms: Date.now() - startTime,
|
|
2130
2206
|
time_to_first_token_ms: timing?.latencyMs ?? void 0,
|
|
2131
2207
|
generation_ms: timing?.generationMs ?? void 0,
|
|
@@ -2166,8 +2242,10 @@ var init_LLMRequest = __esm({
|
|
|
2166
2242
|
actual_provider = ?17,
|
|
2167
2243
|
standard_agents_router_used = ?18,
|
|
2168
2244
|
time_to_first_token_ms = ?19,
|
|
2169
|
-
generation_ms = ?20
|
|
2170
|
-
|
|
2245
|
+
generation_ms = ?20,
|
|
2246
|
+
cost_router_fee = ?21,
|
|
2247
|
+
router_fee_percent = ?22
|
|
2248
|
+
WHERE id = ?23
|
|
2171
2249
|
`,
|
|
2172
2250
|
logData.response_body,
|
|
2173
2251
|
logData.input_tokens,
|
|
@@ -2189,6 +2267,8 @@ var init_LLMRequest = __esm({
|
|
|
2189
2267
|
standardAgentsRouterUsed ? 1 : 0,
|
|
2190
2268
|
logData.time_to_first_token_ms ?? null,
|
|
2191
2269
|
logData.generation_ms ?? null,
|
|
2270
|
+
logData.cost_router_fee ?? null,
|
|
2271
|
+
logData.router_fee_percent ?? null,
|
|
2192
2272
|
logId
|
|
2193
2273
|
);
|
|
2194
2274
|
}
|
|
@@ -2527,9 +2607,24 @@ ${errorStack}` : ""}${errorDetails}`;
|
|
|
2527
2607
|
updates.push(`actual_provider = ?${paramIndex++}`);
|
|
2528
2608
|
values.push(actualProvider);
|
|
2529
2609
|
}
|
|
2610
|
+
let updatedCostTotal;
|
|
2611
|
+
let updatedRouterFee;
|
|
2530
2612
|
if (metadata.generation_cost !== void 0) {
|
|
2613
|
+
updatedCostTotal = metadata.generation_cost;
|
|
2614
|
+
const rawCost = typeof metadata.generation_cost === "number" ? metadata.generation_cost : Number(metadata.generation_cost);
|
|
2615
|
+
if (Number.isFinite(rawCost)) {
|
|
2616
|
+
const feePercent = await this.readRouterFeePercent(state, logId);
|
|
2617
|
+
if (feePercent !== null && feePercent > 0) {
|
|
2618
|
+
updatedRouterFee = calculateRouterFee(rawCost, feePercent);
|
|
2619
|
+
updatedCostTotal = roundCost(rawCost + updatedRouterFee);
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2531
2622
|
updates.push(`cost_total = ?${paramIndex++}`);
|
|
2532
|
-
values.push(
|
|
2623
|
+
values.push(updatedCostTotal);
|
|
2624
|
+
if (updatedRouterFee !== void 0) {
|
|
2625
|
+
updates.push(`cost_router_fee = ?${paramIndex++}`);
|
|
2626
|
+
values.push(updatedRouterFee);
|
|
2627
|
+
}
|
|
2533
2628
|
}
|
|
2534
2629
|
if (updates.length === 0) {
|
|
2535
2630
|
return;
|
|
@@ -2544,7 +2639,8 @@ ${errorStack}` : ""}${errorDetails}`;
|
|
|
2544
2639
|
data: {
|
|
2545
2640
|
id: logId,
|
|
2546
2641
|
...actualProvider !== void 0 && { actual_provider: actualProvider },
|
|
2547
|
-
...metadata.generation_cost !== void 0 && { cost_total:
|
|
2642
|
+
...metadata.generation_cost !== void 0 && { cost_total: updatedCostTotal },
|
|
2643
|
+
...updatedRouterFee !== void 0 && { cost_router_fee: updatedRouterFee }
|
|
2548
2644
|
}
|
|
2549
2645
|
});
|
|
2550
2646
|
}
|
|
@@ -2552,6 +2648,23 @@ ${errorStack}` : ""}${errorDetails}`;
|
|
|
2552
2648
|
console.error("Failed to update log with metadata (non-fatal):", error);
|
|
2553
2649
|
}
|
|
2554
2650
|
}
|
|
2651
|
+
/**
|
|
2652
|
+
* Router-fee percent recorded on a log row by logSuccess, or null when the
|
|
2653
|
+
* row has none (BYOK) or the storage shape doesn't expose it.
|
|
2654
|
+
*/
|
|
2655
|
+
static async readRouterFeePercent(state, logId) {
|
|
2656
|
+
try {
|
|
2657
|
+
const cursor = await state.storage.sql.exec(
|
|
2658
|
+
`SELECT router_fee_percent FROM logs WHERE id = ?`,
|
|
2659
|
+
logId
|
|
2660
|
+
);
|
|
2661
|
+
const row = cursor?.toArray?.()[0];
|
|
2662
|
+
const percent = row?.router_fee_percent;
|
|
2663
|
+
return typeof percent === "number" && Number.isFinite(percent) ? percent : null;
|
|
2664
|
+
} catch {
|
|
2665
|
+
return null;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2555
2668
|
};
|
|
2556
2669
|
}
|
|
2557
2670
|
});
|
|
@@ -14702,8 +14815,28 @@ var migration32 = {
|
|
|
14702
14815
|
}
|
|
14703
14816
|
};
|
|
14704
14817
|
|
|
14818
|
+
// src/durable-objects/migrations/033_add_router_fee.ts
|
|
14819
|
+
var migration33 = {
|
|
14820
|
+
version: 33,
|
|
14821
|
+
name: "add_router_fee",
|
|
14822
|
+
async up(sql) {
|
|
14823
|
+
const tableInfo = sql.exec(`PRAGMA table_info(logs)`).toArray();
|
|
14824
|
+
const hasColumn = (name) => tableInfo.some((col) => col.name === name);
|
|
14825
|
+
if (!hasColumn("cost_router_fee")) {
|
|
14826
|
+
await sql.exec(`
|
|
14827
|
+
ALTER TABLE logs ADD COLUMN cost_router_fee REAL;
|
|
14828
|
+
`);
|
|
14829
|
+
}
|
|
14830
|
+
if (!hasColumn("router_fee_percent")) {
|
|
14831
|
+
await sql.exec(`
|
|
14832
|
+
ALTER TABLE logs ADD COLUMN router_fee_percent REAL;
|
|
14833
|
+
`);
|
|
14834
|
+
}
|
|
14835
|
+
}
|
|
14836
|
+
};
|
|
14837
|
+
|
|
14705
14838
|
// src/durable-objects/migrations/index.ts
|
|
14706
|
-
var migrations = [migration, migration2, migration3, migration4, migration5, migration6, migration7, migration8, migration9, migration10, migration11, migration12, migration13, migration14, migration15, migration16, migration17, migration18, migration19, migration20, migration21, migration22, migration23, migration24, migration25, migration26, migration27, migration28, migration29, migration30, migration31, migration32];
|
|
14839
|
+
var migrations = [migration, migration2, migration3, migration4, migration5, migration6, migration7, migration8, migration9, migration10, migration11, migration12, migration13, migration14, migration15, migration16, migration17, migration18, migration19, migration20, migration21, migration22, migration23, migration24, migration25, migration26, migration27, migration28, migration29, migration30, migration31, migration32, migration33];
|
|
14707
14840
|
var LATEST_SCHEMA_VERSION = migrations.length;
|
|
14708
14841
|
|
|
14709
14842
|
// src/durable-objects/DurableThread.ts
|
|
@@ -16822,9 +16955,9 @@ var DurableThread = class _DurableThread extends DurableObject {
|
|
|
16822
16955
|
* Each migration is run in order, starting from the current version + 1.
|
|
16823
16956
|
*/
|
|
16824
16957
|
async runMigrations(fromVersion) {
|
|
16825
|
-
for (const
|
|
16826
|
-
if (
|
|
16827
|
-
await
|
|
16958
|
+
for (const migration44 of migrations) {
|
|
16959
|
+
if (migration44.version > fromVersion) {
|
|
16960
|
+
await migration44.up(this.ctx.storage.sql);
|
|
16828
16961
|
}
|
|
16829
16962
|
}
|
|
16830
16963
|
}
|
|
@@ -18311,6 +18444,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
18311
18444
|
let inputCost = 0;
|
|
18312
18445
|
let cachedCost = 0;
|
|
18313
18446
|
let outputCost = 0;
|
|
18447
|
+
let routerFeeCost = 0;
|
|
18314
18448
|
let requestCount = 0;
|
|
18315
18449
|
const modelRows = await this.ctx.storage.sql.exec(
|
|
18316
18450
|
`
|
|
@@ -18319,6 +18453,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
18319
18453
|
SUM(CASE WHEN cost_cached IS NOT NULL THEN cost_input END) AS input_cost,
|
|
18320
18454
|
SUM(cost_cached) AS cached_cost,
|
|
18321
18455
|
SUM(cost_output) AS output_cost,
|
|
18456
|
+
SUM(cost_router_fee) AS router_fee_cost,
|
|
18322
18457
|
COUNT(*) AS request_count
|
|
18323
18458
|
FROM logs
|
|
18324
18459
|
WHERE cost_total IS NOT NULL
|
|
@@ -18331,12 +18466,14 @@ ${resultContent}${attachmentSummary}`;
|
|
|
18331
18466
|
inputCost: row.input_cost ?? 0,
|
|
18332
18467
|
cachedCost: row.cached_cost ?? 0,
|
|
18333
18468
|
outputCost: row.output_cost ?? 0,
|
|
18469
|
+
routerFeeCost: row.router_fee_cost ?? 0,
|
|
18334
18470
|
count: row.request_count
|
|
18335
18471
|
};
|
|
18336
18472
|
totalCost += row.total_cost;
|
|
18337
18473
|
inputCost += row.input_cost ?? 0;
|
|
18338
18474
|
cachedCost += row.cached_cost ?? 0;
|
|
18339
18475
|
outputCost += row.output_cost ?? 0;
|
|
18476
|
+
routerFeeCost += row.router_fee_cost ?? 0;
|
|
18340
18477
|
requestCount += row.request_count;
|
|
18341
18478
|
}
|
|
18342
18479
|
const messageRow = await this.ctx.storage.sql.exec(
|
|
@@ -18348,6 +18485,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
18348
18485
|
inputCost,
|
|
18349
18486
|
cachedCost,
|
|
18350
18487
|
outputCost,
|
|
18488
|
+
routerFeeCost,
|
|
18351
18489
|
requestCount,
|
|
18352
18490
|
messageCount,
|
|
18353
18491
|
byModel
|
|
@@ -18564,7 +18702,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
18564
18702
|
l.request_body, l.request_headers, l.response_body, l.response_headers,
|
|
18565
18703
|
l.status_code, l.reasoning_content, l.input_tokens, l.cached_tokens, l.output_tokens,
|
|
18566
18704
|
l.reasoning_tokens, l.total_tokens, l.latency_ms, l.time_to_first_token_ms, l.generation_ms,
|
|
18567
|
-
l.finish_reason, l.error, l.error_type, l.cost_input, l.cost_cached, l.cost_output, l.cost_total,
|
|
18705
|
+
l.finish_reason, l.error, l.error_type, l.cost_input, l.cost_cached, l.cost_output, l.cost_router_fee, l.router_fee_percent, l.cost_total,
|
|
18568
18706
|
l.message_history_length, l.tools_available, l.prompt_name, l.tools_called,
|
|
18569
18707
|
l.queued_tools, l.provider_tools, l.parent_log_id, l.tools_schema, l.system_prompt,
|
|
18570
18708
|
l.errors, l.retry_of_log_id, l.tool_results, l.is_complete, l.created_at,
|
|
@@ -18656,6 +18794,8 @@ ${resultContent}${attachmentSummary}`;
|
|
|
18656
18794
|
cost_input: row.cost_input,
|
|
18657
18795
|
cost_cached: row.cost_cached,
|
|
18658
18796
|
cost_output: row.cost_output,
|
|
18797
|
+
cost_router_fee: row.cost_router_fee,
|
|
18798
|
+
router_fee_percent: row.router_fee_percent,
|
|
18659
18799
|
cost_total: row.cost_total,
|
|
18660
18800
|
message_history_length: row.message_history_length,
|
|
18661
18801
|
tools_available: row.tools_available,
|
|
@@ -20558,7 +20698,7 @@ ${resultContent}${attachmentSummary}`;
|
|
|
20558
20698
|
};
|
|
20559
20699
|
|
|
20560
20700
|
// src/durable-objects/agentbuilder-migrations/0001_initial.ts
|
|
20561
|
-
var
|
|
20701
|
+
var migration34 = {
|
|
20562
20702
|
version: 1,
|
|
20563
20703
|
async up(sql) {
|
|
20564
20704
|
sql.exec(`
|
|
@@ -20657,7 +20797,7 @@ var migration33 = {
|
|
|
20657
20797
|
};
|
|
20658
20798
|
|
|
20659
20799
|
// src/durable-objects/agentbuilder-migrations/0002_add_tenvs_properties.ts
|
|
20660
|
-
var
|
|
20800
|
+
var migration35 = {
|
|
20661
20801
|
version: 2,
|
|
20662
20802
|
async up(sql) {
|
|
20663
20803
|
sql.exec(`ALTER TABLE threads ADD COLUMN tenvs TEXT`);
|
|
@@ -20669,7 +20809,7 @@ var migration34 = {
|
|
|
20669
20809
|
};
|
|
20670
20810
|
|
|
20671
20811
|
// src/durable-objects/agentbuilder-migrations/0003_add_parent_and_terminated.ts
|
|
20672
|
-
var
|
|
20812
|
+
var migration36 = {
|
|
20673
20813
|
version: 3,
|
|
20674
20814
|
async up(sql) {
|
|
20675
20815
|
sql.exec(`ALTER TABLE threads ADD COLUMN parent TEXT REFERENCES threads(id)`);
|
|
@@ -20682,7 +20822,7 @@ var migration35 = {
|
|
|
20682
20822
|
};
|
|
20683
20823
|
|
|
20684
20824
|
// src/durable-objects/agentbuilder-migrations/0004_add_env_tables.ts
|
|
20685
|
-
var
|
|
20825
|
+
var migration37 = {
|
|
20686
20826
|
version: 4,
|
|
20687
20827
|
async up(sql) {
|
|
20688
20828
|
sql.exec(`ALTER TABLE threads ADD COLUMN env TEXT`);
|
|
@@ -20706,7 +20846,7 @@ var migration36 = {
|
|
|
20706
20846
|
};
|
|
20707
20847
|
|
|
20708
20848
|
// src/durable-objects/agentbuilder-migrations/0005_add_pending_subagent_env_requests.ts
|
|
20709
|
-
var
|
|
20849
|
+
var migration38 = {
|
|
20710
20850
|
version: 5,
|
|
20711
20851
|
async up(sql) {
|
|
20712
20852
|
sql.exec(`
|
|
@@ -20732,7 +20872,7 @@ var migration37 = {
|
|
|
20732
20872
|
};
|
|
20733
20873
|
|
|
20734
20874
|
// src/durable-objects/agentbuilder-migrations/0006_add_env_value_types.ts
|
|
20735
|
-
var
|
|
20875
|
+
var migration39 = {
|
|
20736
20876
|
version: 6,
|
|
20737
20877
|
async up(sql) {
|
|
20738
20878
|
sql.exec(
|
|
@@ -20747,7 +20887,7 @@ var migration38 = {
|
|
|
20747
20887
|
};
|
|
20748
20888
|
|
|
20749
20889
|
// src/durable-objects/agentbuilder-migrations/0007_platform_identity_replica.ts
|
|
20750
|
-
var
|
|
20890
|
+
var migration40 = {
|
|
20751
20891
|
version: 7,
|
|
20752
20892
|
async up(sql) {
|
|
20753
20893
|
sql.exec(`ALTER TABLE users ADD COLUMN platform_user_id TEXT`);
|
|
@@ -20776,7 +20916,7 @@ var migration39 = {
|
|
|
20776
20916
|
};
|
|
20777
20917
|
|
|
20778
20918
|
// src/durable-objects/agentbuilder-migrations/0008_add_skills.ts
|
|
20779
|
-
var
|
|
20919
|
+
var migration41 = {
|
|
20780
20920
|
version: 8,
|
|
20781
20921
|
async up(sql) {
|
|
20782
20922
|
sql.exec(`
|
|
@@ -20807,7 +20947,7 @@ var migration40 = {
|
|
|
20807
20947
|
};
|
|
20808
20948
|
|
|
20809
20949
|
// src/durable-objects/agentbuilder-migrations/0009_add_user_permissions.ts
|
|
20810
|
-
var
|
|
20950
|
+
var migration42 = {
|
|
20811
20951
|
version: 9,
|
|
20812
20952
|
async up(sql) {
|
|
20813
20953
|
sql.exec(`ALTER TABLE users ADD COLUMN permissions TEXT`);
|
|
@@ -20818,7 +20958,7 @@ var migration41 = {
|
|
|
20818
20958
|
};
|
|
20819
20959
|
|
|
20820
20960
|
// src/durable-objects/agentbuilder-migrations/0010_add_device_logins.ts
|
|
20821
|
-
var
|
|
20961
|
+
var migration43 = {
|
|
20822
20962
|
version: 10,
|
|
20823
20963
|
async up(sql) {
|
|
20824
20964
|
sql.exec(`
|
|
@@ -20838,7 +20978,7 @@ var migration42 = {
|
|
|
20838
20978
|
};
|
|
20839
20979
|
|
|
20840
20980
|
// src/durable-objects/agentbuilder-migrations/index.ts
|
|
20841
|
-
var migrations2 = [
|
|
20981
|
+
var migrations2 = [migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43];
|
|
20842
20982
|
var LATEST_SCHEMA_VERSION2 = 10;
|
|
20843
20983
|
|
|
20844
20984
|
// src/utils/crypto.ts
|
|
@@ -21601,9 +21741,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
|
|
|
21601
21741
|
}
|
|
21602
21742
|
}
|
|
21603
21743
|
async runMigrations(fromVersion) {
|
|
21604
|
-
for (const
|
|
21605
|
-
if (
|
|
21606
|
-
await
|
|
21744
|
+
for (const migration44 of migrations2) {
|
|
21745
|
+
if (migration44.version > fromVersion) {
|
|
21746
|
+
await migration44.up(this.ctx.storage.sql);
|
|
21607
21747
|
}
|
|
21608
21748
|
}
|
|
21609
21749
|
}
|