@opengeni/db 3.7.4 → 4.0.0-canary.0
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/automations.d.ts +4 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-integrations.d.ts +2 -0
- package/dist/{chunk-6DPJA36C.js → chunk-2XEZK4LF.js} +7 -1
- package/dist/chunk-2XEZK4LF.js.map +1 -0
- package/dist/{chunk-4NAR7FBA.js → chunk-3RI33YQN.js} +67 -1
- package/dist/chunk-3RI33YQN.js.map +1 -0
- package/dist/{chunk-SZAWDXQC.js → chunk-CJROYHSC.js} +3 -3
- package/dist/{chunk-DZCYW2WT.js → chunk-MX6V5F65.js} +2 -2
- package/dist/{chunk-S3TDDCS2.js → chunk-N5VXJ4I2.js} +151 -78
- package/dist/chunk-N5VXJ4I2.js.map +1 -0
- package/dist/{chunk-U4WPPEBH.js → chunk-NLFHMPUB.js} +2 -2
- package/dist/{chunk-5NNCGFQY.js → chunk-P6NSEG2S.js} +2 -2
- package/dist/{chunk-O56DM5GZ.js → chunk-QM6YOWHZ.js} +624 -57
- package/dist/chunk-QM6YOWHZ.js.map +1 -0
- package/dist/{chunk-US4IS6IV.js → chunk-RZNOSEMC.js} +2 -2
- package/dist/{chunk-F6PBS6WE.js → chunk-UFAMOUWL.js} +2 -2
- package/dist/codemode-operations.d.ts +5 -0
- package/dist/codex-token-resolver.d.ts +6 -2
- package/dist/connection-token-resolver.d.ts +8 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/generated-images.d.ts +15 -0
- package/dist/index.d.ts +393 -91
- package/dist/index.js +9992 -6069
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +9 -0
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/managed-user-setup.d.ts +3 -0
- package/dist/mcp-oauth.d.ts +80 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +3 -1
- package/dist/model-catalog.d.ts +153 -0
- package/dist/model-context-snapshots.d.ts +20 -0
- package/dist/new-session-drafts.d.ts +12 -0
- package/dist/organization-membership-lifecycle.d.ts +8 -1
- package/dist/organization-model-providers.d.ts +101 -0
- package/dist/pack-components.d.ts +1 -0
- package/dist/pr-review.d.ts +9 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +8 -8
- package/dist/schema.d.ts +7708 -5050
- package/dist/schema.js +25 -1
- package/dist/session-background-commands.d.ts +18 -6
- package/dist/session-background-commands.js +15 -9
- package/dist/session-control.d.ts +37 -2
- package/dist/session-goal-pacing.d.ts +3 -6
- package/dist/session-queue-commands.d.ts +17 -0
- package/dist/session-tenancy.js +3 -3
- package/dist/tool-gateway-approvals.d.ts +31 -0
- package/dist/video-generation.js +3 -3
- package/dist/workspace-artifacts.d.ts +17 -3
- package/dist/xai-subscription.d.ts +8 -0
- package/drizzle/0387_bound_host_export_session_payloads.sql +165 -0
- package/drizzle/0388_sandbox_provider_deadline_interactions.sql +491 -0
- package/drizzle/0389_model_catalog_and_gateway_custom_models.sql +241 -0
- package/drizzle/0390_organization_model_provider_connections.sql +197 -0
- package/drizzle/0391_sandbox_provider_deadline_interaction_followup.sql +295 -0
- package/drizzle/0392_context_compaction_pending_observability.sql +198 -0
- package/drizzle/0393_workspace_memory_and_learning_defaults.sql +102 -0
- package/drizzle/0394_session_selected_skill_activation.sql +20 -0
- package/drizzle/0395_scheduled_task_unclaimed_occurrence_invalidation.sql +154 -0
- package/drizzle/0396_model_call_equivalent_credit_cost.sql +28 -0
- package/drizzle/0397_sandbox_deadline_rotation_preemption.sql +113 -0
- package/drizzle/0398_organization_workspace_management_entry.sql +206 -0
- package/drizzle/0399_additional_managed_organization_creation.sql +691 -0
- package/drizzle/0400_session_attempt_model_context_snapshots.sql +65 -0
- package/drizzle/0401_organization_user_setup_token_transport.sql +178 -0
- package/drizzle/0402_session_input_wait_and_background_command_results.sql +1023 -0
- package/drizzle/0403_codex_unconditional_credential_leasing.sql +181 -0
- package/drizzle/0404_mcp_oauth_authorization_server.sql +471 -0
- package/drizzle/0405_tool_gateway_approval_capabilities.sql +184 -0
- package/drizzle/0406_workspace_html_site_sources.sql +71 -0
- package/package.json +6 -6
- package/src/automations.ts +9 -1
- package/src/capability-integrations.ts +8 -0
- package/src/codemode-operations.ts +31 -21
- package/src/codex-token-resolver.ts +16 -6
- package/src/connection-token-resolver.ts +52 -3
- package/src/generated-images.ts +70 -6
- package/src/index.ts +3894 -994
- package/src/insights-model-bundle.ts +54 -5
- package/src/insights.ts +53 -7
- package/src/managed-user-setup.ts +14 -3
- package/src/mcp-oauth.ts +488 -0
- package/src/migrate.ts +9 -1
- package/src/model-catalog.ts +682 -0
- package/src/model-context-snapshots.ts +151 -0
- package/src/new-session-drafts.ts +66 -21
- package/src/organization-membership-lifecycle.ts +47 -5
- package/src/organization-model-providers.ts +614 -0
- package/src/pack-components.ts +15 -2
- package/src/pr-review.ts +19 -0
- package/src/provision-roles.ts +4 -0
- package/src/runtime-posture.ts +64 -0
- package/src/schema.ts +666 -61
- package/src/session-background-commands.ts +180 -78
- package/src/session-control.ts +181 -12
- package/src/session-goal-pacing.ts +4 -8
- package/src/session-queue-commands.ts +157 -82
- package/src/tool-gateway-approvals.ts +168 -0
- package/src/workspace-artifacts.ts +633 -178
- package/src/xai-subscription.ts +66 -14
- package/dist/chunk-4NAR7FBA.js.map +0 -1
- package/dist/chunk-6DPJA36C.js.map +0 -1
- package/dist/chunk-O56DM5GZ.js.map +0 -1
- package/dist/chunk-S3TDDCS2.js.map +0 -1
- /package/dist/{chunk-SZAWDXQC.js.map → chunk-CJROYHSC.js.map} +0 -0
- /package/dist/{chunk-DZCYW2WT.js.map → chunk-MX6V5F65.js.map} +0 -0
- /package/dist/{chunk-U4WPPEBH.js.map → chunk-NLFHMPUB.js.map} +0 -0
- /package/dist/{chunk-5NNCGFQY.js.map → chunk-P6NSEG2S.js.map} +0 -0
- /package/dist/{chunk-US4IS6IV.js.map → chunk-RZNOSEMC.js.map} +0 -0
- /package/dist/{chunk-F6PBS6WE.js.map → chunk-UFAMOUWL.js.map} +0 -0
|
@@ -116,6 +116,8 @@ function mapModelRows(value: unknown, label: string): ModelCallFactAggregateRow[
|
|
|
116
116
|
pricedCostMicros: numberValue(row, "pricedCostMicros"),
|
|
117
117
|
estimatedProviderCostMicros: numberValue(row, "estimatedProviderCostMicros"),
|
|
118
118
|
estimatedProviderCostKnownCalls: numberValue(row, "estimatedProviderCostKnownCalls"),
|
|
119
|
+
equivalentCreditCostMicros: numberValue(row, "equivalentCreditCostMicros"),
|
|
120
|
+
equivalentCreditCostKnownCalls: numberValue(row, "equivalentCreditCostKnownCalls"),
|
|
119
121
|
}));
|
|
120
122
|
}
|
|
121
123
|
|
|
@@ -126,6 +128,8 @@ function mapRootRows(value: unknown, label: string): RootSessionDriverRow[] {
|
|
|
126
128
|
pricedCostMicros: numberValue(row, "pricedCostMicros"),
|
|
127
129
|
estimatedProviderCostMicros: numberValue(row, "estimatedProviderCostMicros"),
|
|
128
130
|
estimatedProviderCostKnownCalls: numberValue(row, "estimatedProviderCostKnownCalls"),
|
|
131
|
+
equivalentCreditCostMicros: numberValue(row, "equivalentCreditCostMicros"),
|
|
132
|
+
equivalentCreditCostKnownCalls: numberValue(row, "equivalentCreditCostKnownCalls"),
|
|
129
133
|
totalTokens: numberValue(row, "totalTokens"),
|
|
130
134
|
cachedTokens: numberValue(row, "cachedTokens"),
|
|
131
135
|
cacheInputTokens: numberValue(row, "cacheInputTokens"),
|
|
@@ -153,6 +157,8 @@ function mapBundle(value: unknown): WorkspaceInsightsModelBundle {
|
|
|
153
157
|
costMicros: numberValue(row, "costMicros"),
|
|
154
158
|
estimatedProviderCostMicros: numberValue(row, "estimatedProviderCostMicros"),
|
|
155
159
|
estimatedProviderCostKnownCalls: numberValue(row, "estimatedProviderCostKnownCalls"),
|
|
160
|
+
equivalentCreditCostMicros: numberValue(row, "equivalentCreditCostMicros"),
|
|
161
|
+
equivalentCreditCostKnownCalls: numberValue(row, "equivalentCreditCostKnownCalls"),
|
|
156
162
|
inputTokens: numberValue(row, "inputTokens"),
|
|
157
163
|
outputTokens: numberValue(row, "outputTokens"),
|
|
158
164
|
cachedTokens: numberValue(row, "cachedTokens"),
|
|
@@ -173,6 +179,8 @@ function mapBundle(value: unknown): WorkspaceInsightsModelBundle {
|
|
|
173
179
|
pricedCostMicros: numberValue(row, "pricedCostMicros"),
|
|
174
180
|
estimatedProviderCostMicros: numberValue(row, "estimatedProviderCostMicros"),
|
|
175
181
|
estimatedProviderCostKnownCalls: numberValue(row, "estimatedProviderCostKnownCalls"),
|
|
182
|
+
equivalentCreditCostMicros: numberValue(row, "equivalentCreditCostMicros"),
|
|
183
|
+
equivalentCreditCostKnownCalls: numberValue(row, "equivalentCreditCostKnownCalls"),
|
|
176
184
|
totalTokens: numberValue(row, "totalTokens"),
|
|
177
185
|
cachedTokens: numberValue(row, "cachedTokens"),
|
|
178
186
|
cacheInputTokens: numberValue(row, "cacheInputTokens"),
|
|
@@ -203,6 +211,7 @@ function mapBundle(value: unknown): WorkspaceInsightsModelBundle {
|
|
|
203
211
|
totalTokens: nullableNumber(row, "totalTokens"),
|
|
204
212
|
pricedCostMicros: numberValue(row, "pricedCostMicros"),
|
|
205
213
|
estimatedProviderCostMicros: nullableNumber(row, "estimatedProviderCostMicros"),
|
|
214
|
+
equivalentCreditCostMicros: nullableNumber(row, "equivalentCreditCostMicros"),
|
|
206
215
|
pricingSource: nullableString(row, "pricingSource"),
|
|
207
216
|
})),
|
|
208
217
|
promptContributions: {
|
|
@@ -261,6 +270,7 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
261
270
|
fact.total_tokens,
|
|
262
271
|
fact.priced_cost_micros,
|
|
263
272
|
fact.estimated_provider_cost_micros,
|
|
273
|
+
fact.equivalent_credit_cost_micros,
|
|
264
274
|
fact.pricing_source,
|
|
265
275
|
fact.context_contributions,
|
|
266
276
|
fact.occurred_at,
|
|
@@ -286,7 +296,8 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
286
296
|
fact.reasoning_tokens,
|
|
287
297
|
fact.total_tokens,
|
|
288
298
|
fact.priced_cost_micros,
|
|
289
|
-
fact.estimated_provider_cost_micros
|
|
299
|
+
fact.estimated_provider_cost_micros,
|
|
300
|
+
fact.equivalent_credit_cost_micros
|
|
290
301
|
from opengeni_private.visible_workspace_insights_model_call_facts(
|
|
291
302
|
${input.workspaceId},
|
|
292
303
|
${input.priorSince.toISOString()}::timestamp with time zone,
|
|
@@ -340,7 +351,11 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
340
351
|
coalesce(sum(fact.estimated_provider_cost_micros), 0)::bigint
|
|
341
352
|
as estimated_provider_cost_micros,
|
|
342
353
|
count(fact.estimated_provider_cost_micros)::bigint
|
|
343
|
-
as estimated_provider_cost_known_calls
|
|
354
|
+
as estimated_provider_cost_known_calls,
|
|
355
|
+
coalesce(sum(fact.equivalent_credit_cost_micros), 0)::bigint
|
|
356
|
+
as equivalent_credit_cost_micros,
|
|
357
|
+
count(fact.equivalent_credit_cost_micros)::bigint
|
|
358
|
+
as equivalent_credit_cost_known_calls
|
|
344
359
|
from current_visible fact
|
|
345
360
|
group by fact.provider, fact.model, fact.billing_path
|
|
346
361
|
), prior_model_rows as (
|
|
@@ -368,7 +383,11 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
368
383
|
coalesce(sum(fact.estimated_provider_cost_micros), 0)::bigint
|
|
369
384
|
as estimated_provider_cost_micros,
|
|
370
385
|
count(fact.estimated_provider_cost_micros)::bigint
|
|
371
|
-
as estimated_provider_cost_known_calls
|
|
386
|
+
as estimated_provider_cost_known_calls,
|
|
387
|
+
coalesce(sum(fact.equivalent_credit_cost_micros), 0)::bigint
|
|
388
|
+
as equivalent_credit_cost_micros,
|
|
389
|
+
count(fact.equivalent_credit_cost_micros)::bigint
|
|
390
|
+
as equivalent_credit_cost_known_calls
|
|
372
391
|
from prior_visible fact
|
|
373
392
|
group by fact.provider, fact.model, fact.billing_path
|
|
374
393
|
), current_series_rows as (
|
|
@@ -381,6 +400,10 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
381
400
|
as estimated_provider_cost_micros,
|
|
382
401
|
count(fact.estimated_provider_cost_micros)::bigint
|
|
383
402
|
as estimated_provider_cost_known_calls,
|
|
403
|
+
coalesce(sum(fact.equivalent_credit_cost_micros), 0)::bigint
|
|
404
|
+
as equivalent_credit_cost_micros,
|
|
405
|
+
count(fact.equivalent_credit_cost_micros)::bigint
|
|
406
|
+
as equivalent_credit_cost_known_calls,
|
|
384
407
|
coalesce(sum(fact.input_tokens), 0)::bigint as input_tokens,
|
|
385
408
|
coalesce(sum(fact.output_tokens), 0)::bigint as output_tokens,
|
|
386
409
|
coalesce(sum(fact.cached_tokens), 0)::bigint as cached_tokens,
|
|
@@ -408,6 +431,10 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
408
431
|
as estimated_provider_cost_micros,
|
|
409
432
|
count(fact.estimated_provider_cost_micros)::bigint
|
|
410
433
|
as estimated_provider_cost_known_calls,
|
|
434
|
+
coalesce(sum(fact.equivalent_credit_cost_micros), 0)::bigint
|
|
435
|
+
as equivalent_credit_cost_micros,
|
|
436
|
+
count(fact.equivalent_credit_cost_micros)::bigint
|
|
437
|
+
as equivalent_credit_cost_known_calls,
|
|
411
438
|
coalesce(sum(fact.total_tokens), 0)::bigint as total_tokens,
|
|
412
439
|
coalesce(sum(fact.cached_tokens), 0)::bigint as cached_tokens,
|
|
413
440
|
coalesce(sum(fact.input_tokens) filter (
|
|
@@ -433,6 +460,10 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
433
460
|
as estimated_provider_cost_micros,
|
|
434
461
|
count(fact.estimated_provider_cost_micros)::bigint
|
|
435
462
|
as estimated_provider_cost_known_calls,
|
|
463
|
+
coalesce(sum(fact.equivalent_credit_cost_micros), 0)::bigint
|
|
464
|
+
as equivalent_credit_cost_micros,
|
|
465
|
+
count(fact.equivalent_credit_cost_micros)::bigint
|
|
466
|
+
as equivalent_credit_cost_known_calls,
|
|
436
467
|
coalesce(sum(fact.total_tokens), 0)::bigint as total_tokens,
|
|
437
468
|
coalesce(sum(fact.cached_tokens), 0)::bigint as cached_tokens,
|
|
438
469
|
coalesce(sum(fact.input_tokens) filter (
|
|
@@ -454,6 +485,10 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
454
485
|
as estimated_provider_cost_micros,
|
|
455
486
|
count(fact.estimated_provider_cost_micros)::bigint
|
|
456
487
|
as estimated_provider_cost_known_calls,
|
|
488
|
+
coalesce(sum(fact.equivalent_credit_cost_micros), 0)::bigint
|
|
489
|
+
as equivalent_credit_cost_micros,
|
|
490
|
+
count(fact.equivalent_credit_cost_micros)::bigint
|
|
491
|
+
as equivalent_credit_cost_known_calls,
|
|
457
492
|
coalesce(sum(fact.total_tokens), 0)::bigint as total_tokens,
|
|
458
493
|
coalesce(sum(fact.cached_tokens), 0)::bigint as cached_tokens,
|
|
459
494
|
coalesce(sum(fact.input_tokens) filter (
|
|
@@ -491,6 +526,7 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
491
526
|
fact.total_tokens,
|
|
492
527
|
fact.priced_cost_micros,
|
|
493
528
|
fact.estimated_provider_cost_micros,
|
|
529
|
+
fact.equivalent_credit_cost_micros,
|
|
494
530
|
fact.pricing_source
|
|
495
531
|
from current_visible fact
|
|
496
532
|
left join selected_sessions session
|
|
@@ -539,7 +575,9 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
539
575
|
'cacheKnownCalls', cache_known_calls,
|
|
540
576
|
'pricedCostMicros', priced_cost_micros,
|
|
541
577
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
542
|
-
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls
|
|
578
|
+
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls,
|
|
579
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
580
|
+
'equivalentCreditCostKnownCalls', equivalent_credit_cost_known_calls
|
|
543
581
|
) order by provider, model, billing_path)
|
|
544
582
|
from current_model_rows
|
|
545
583
|
), '[]'::jsonb),
|
|
@@ -560,7 +598,9 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
560
598
|
'cacheKnownCalls', cache_known_calls,
|
|
561
599
|
'pricedCostMicros', priced_cost_micros,
|
|
562
600
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
563
|
-
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls
|
|
601
|
+
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls,
|
|
602
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
603
|
+
'equivalentCreditCostKnownCalls', equivalent_credit_cost_known_calls
|
|
564
604
|
) order by provider, model, billing_path)
|
|
565
605
|
from prior_model_rows
|
|
566
606
|
), '[]'::jsonb),
|
|
@@ -570,6 +610,8 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
570
610
|
'costMicros', cost_micros,
|
|
571
611
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
572
612
|
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls,
|
|
613
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
614
|
+
'equivalentCreditCostKnownCalls', equivalent_credit_cost_known_calls,
|
|
573
615
|
'inputTokens', input_tokens,
|
|
574
616
|
'outputTokens', output_tokens,
|
|
575
617
|
'cachedTokens', cached_tokens,
|
|
@@ -590,6 +632,8 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
590
632
|
'pricedCostMicros', priced_cost_micros,
|
|
591
633
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
592
634
|
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls,
|
|
635
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
636
|
+
'equivalentCreditCostKnownCalls', equivalent_credit_cost_known_calls,
|
|
593
637
|
'totalTokens', total_tokens,
|
|
594
638
|
'cachedTokens', cached_tokens,
|
|
595
639
|
'cacheInputTokens', cache_input_tokens
|
|
@@ -603,6 +647,8 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
603
647
|
'pricedCostMicros', priced_cost_micros,
|
|
604
648
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
605
649
|
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls,
|
|
650
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
651
|
+
'equivalentCreditCostKnownCalls', equivalent_credit_cost_known_calls,
|
|
606
652
|
'totalTokens', total_tokens,
|
|
607
653
|
'cachedTokens', cached_tokens,
|
|
608
654
|
'cacheInputTokens', cache_input_tokens
|
|
@@ -615,6 +661,8 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
615
661
|
'pricedCostMicros', priced_cost_micros,
|
|
616
662
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
617
663
|
'estimatedProviderCostKnownCalls', estimated_provider_cost_known_calls,
|
|
664
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
665
|
+
'equivalentCreditCostKnownCalls', equivalent_credit_cost_known_calls,
|
|
618
666
|
'totalTokens', total_tokens,
|
|
619
667
|
'cachedTokens', cached_tokens,
|
|
620
668
|
'cacheInputTokens', cache_input_tokens,
|
|
@@ -651,6 +699,7 @@ export async function readWorkspaceInsightsModelBundle(
|
|
|
651
699
|
'totalTokens', total_tokens,
|
|
652
700
|
'pricedCostMicros', priced_cost_micros,
|
|
653
701
|
'estimatedProviderCostMicros', estimated_provider_cost_micros,
|
|
702
|
+
'equivalentCreditCostMicros', equivalent_credit_cost_micros,
|
|
654
703
|
'pricingSource', pricing_source
|
|
655
704
|
) order by occurred_at desc, id desc)
|
|
656
705
|
from recent_rows
|
package/src/insights.ts
CHANGED
|
@@ -29,6 +29,8 @@ export type ModelCallFactAggregateRow = {
|
|
|
29
29
|
pricedCostMicros: number;
|
|
30
30
|
estimatedProviderCostMicros: number;
|
|
31
31
|
estimatedProviderCostKnownCalls: number;
|
|
32
|
+
equivalentCreditCostMicros: number;
|
|
33
|
+
equivalentCreditCostKnownCalls: number;
|
|
32
34
|
};
|
|
33
35
|
|
|
34
36
|
export type InsightsDayBucket = {
|
|
@@ -60,6 +62,8 @@ export type RootSessionDriverRow = {
|
|
|
60
62
|
pricedCostMicros: number;
|
|
61
63
|
estimatedProviderCostMicros: number;
|
|
62
64
|
estimatedProviderCostKnownCalls: number;
|
|
65
|
+
equivalentCreditCostMicros: number;
|
|
66
|
+
equivalentCreditCostKnownCalls: number;
|
|
63
67
|
totalTokens: number;
|
|
64
68
|
cachedTokens: number;
|
|
65
69
|
cacheInputTokens: number;
|
|
@@ -70,6 +74,8 @@ export type ScheduleFactAggregate = {
|
|
|
70
74
|
pricedCostMicros: number;
|
|
71
75
|
estimatedProviderCostMicros: number;
|
|
72
76
|
estimatedProviderCostKnownCalls: number;
|
|
77
|
+
equivalentCreditCostMicros: number;
|
|
78
|
+
equivalentCreditCostKnownCalls: number;
|
|
73
79
|
totalTokens: number;
|
|
74
80
|
cachedTokens: number;
|
|
75
81
|
cacheInputTokens: number;
|
|
@@ -134,6 +140,7 @@ export type RecentModelCallRow = {
|
|
|
134
140
|
totalTokens: number | null;
|
|
135
141
|
pricedCostMicros: number;
|
|
136
142
|
estimatedProviderCostMicros: number | null;
|
|
143
|
+
equivalentCreditCostMicros: number | null;
|
|
137
144
|
pricingSource: string | null;
|
|
138
145
|
};
|
|
139
146
|
|
|
@@ -360,6 +367,8 @@ export async function aggregateModelCallFacts(
|
|
|
360
367
|
pricedCostMicros: sql<number>`coalesce(sum(${modelCallFacts.pricedCostMicros}) filter (where ${modelCallFacts.billingPath} = 'opengeni_credits'), 0)`,
|
|
361
368
|
estimatedProviderCostMicros: sql<number>`coalesce(sum(${modelCallFacts.estimatedProviderCostMicros}), 0)`,
|
|
362
369
|
estimatedProviderCostKnownCalls: sql<number>`count(${modelCallFacts.estimatedProviderCostMicros})::int`,
|
|
370
|
+
equivalentCreditCostMicros: sql<number>`coalesce(sum(${modelCallFacts.equivalentCreditCostMicros}), 0)`,
|
|
371
|
+
equivalentCreditCostKnownCalls: sql<number>`count(${modelCallFacts.equivalentCreditCostMicros})::int`,
|
|
363
372
|
})
|
|
364
373
|
.from(source)
|
|
365
374
|
.where(and(...clauses))
|
|
@@ -381,6 +390,8 @@ export async function aggregateModelCallFacts(
|
|
|
381
390
|
pricedCostMicros: Number(row.pricedCostMicros),
|
|
382
391
|
estimatedProviderCostMicros: Number(row.estimatedProviderCostMicros),
|
|
383
392
|
estimatedProviderCostKnownCalls: Number(row.estimatedProviderCostKnownCalls),
|
|
393
|
+
equivalentCreditCostMicros: Number(row.equivalentCreditCostMicros),
|
|
394
|
+
equivalentCreditCostKnownCalls: Number(row.equivalentCreditCostKnownCalls),
|
|
384
395
|
}));
|
|
385
396
|
});
|
|
386
397
|
}
|
|
@@ -389,6 +400,8 @@ export type ModelCallFactSeriesAggregate = {
|
|
|
389
400
|
costMicros: number;
|
|
390
401
|
estimatedProviderCostMicros: number;
|
|
391
402
|
estimatedProviderCostKnownCalls: number;
|
|
403
|
+
equivalentCreditCostMicros: number;
|
|
404
|
+
equivalentCreditCostKnownCalls: number;
|
|
392
405
|
inputTokens: number;
|
|
393
406
|
outputTokens: number;
|
|
394
407
|
cachedTokens: number;
|
|
@@ -436,6 +449,8 @@ async function aggregateModelCallFactsByBucket(
|
|
|
436
449
|
costMicros: sql<number>`coalesce(sum(${modelCallFacts.pricedCostMicros}) filter (where ${modelCallFacts.billingPath} = 'opengeni_credits'), 0)`,
|
|
437
450
|
estimatedProviderCostMicros: sql<number>`coalesce(sum(${modelCallFacts.estimatedProviderCostMicros}), 0)`,
|
|
438
451
|
estimatedProviderCostKnownCalls: sql<number>`count(${modelCallFacts.estimatedProviderCostMicros})::int`,
|
|
452
|
+
equivalentCreditCostMicros: sql<number>`coalesce(sum(${modelCallFacts.equivalentCreditCostMicros}), 0)`,
|
|
453
|
+
equivalentCreditCostKnownCalls: sql<number>`count(${modelCallFacts.equivalentCreditCostMicros})::int`,
|
|
439
454
|
inputTokens: sql<number>`coalesce(sum(${modelCallFacts.inputTokens}), 0)`,
|
|
440
455
|
outputTokens: sql<number>`coalesce(sum(${modelCallFacts.outputTokens}), 0)`,
|
|
441
456
|
cachedTokens: sql<number>`coalesce(sum(${modelCallFacts.cachedTokens}), 0)`,
|
|
@@ -457,6 +472,8 @@ async function aggregateModelCallFactsByBucket(
|
|
|
457
472
|
costMicros: Number(row.costMicros),
|
|
458
473
|
estimatedProviderCostMicros: Number(row.estimatedProviderCostMicros),
|
|
459
474
|
estimatedProviderCostKnownCalls: Number(row.estimatedProviderCostKnownCalls),
|
|
475
|
+
equivalentCreditCostMicros: Number(row.equivalentCreditCostMicros),
|
|
476
|
+
equivalentCreditCostKnownCalls: Number(row.equivalentCreditCostKnownCalls),
|
|
460
477
|
inputTokens: Number(row.inputTokens),
|
|
461
478
|
outputTokens: Number(row.outputTokens),
|
|
462
479
|
cachedTokens: Number(row.cachedTokens),
|
|
@@ -630,6 +647,8 @@ export async function aggregateRootSessionDrivers(
|
|
|
630
647
|
pricedCostMicros: sql<number>`coalesce(sum(${modelCallFacts.pricedCostMicros}) filter (where ${modelCallFacts.billingPath} = 'opengeni_credits'), 0)`,
|
|
631
648
|
estimatedProviderCostMicros: sql<number>`coalesce(sum(${modelCallFacts.estimatedProviderCostMicros}), 0)`,
|
|
632
649
|
estimatedProviderCostKnownCalls: sql<number>`count(${modelCallFacts.estimatedProviderCostMicros})::int`,
|
|
650
|
+
equivalentCreditCostMicros: sql<number>`coalesce(sum(${modelCallFacts.equivalentCreditCostMicros}), 0)`,
|
|
651
|
+
equivalentCreditCostKnownCalls: sql<number>`count(${modelCallFacts.equivalentCreditCostMicros})::int`,
|
|
633
652
|
totalTokens: sql<number>`coalesce(sum(${modelCallFacts.totalTokens}), 0)`,
|
|
634
653
|
cachedTokens: sql<number>`coalesce(sum(${modelCallFacts.cachedTokens}), 0)`,
|
|
635
654
|
cacheInputTokens: sql<number>`coalesce(sum(${modelCallFacts.inputTokens}) filter (where ${modelCallFacts.cachedTokens} is not null and ${modelCallFacts.inputTokens} is not null), 0)`,
|
|
@@ -659,6 +678,8 @@ export async function aggregateRootSessionDrivers(
|
|
|
659
678
|
pricedCostMicros: Number(row.pricedCostMicros),
|
|
660
679
|
estimatedProviderCostMicros: Number(row.estimatedProviderCostMicros),
|
|
661
680
|
estimatedProviderCostKnownCalls: Number(row.estimatedProviderCostKnownCalls),
|
|
681
|
+
equivalentCreditCostMicros: Number(row.equivalentCreditCostMicros),
|
|
682
|
+
equivalentCreditCostKnownCalls: Number(row.equivalentCreditCostKnownCalls),
|
|
662
683
|
totalTokens: Number(row.totalTokens),
|
|
663
684
|
cachedTokens: Number(row.cachedTokens),
|
|
664
685
|
cacheInputTokens: Number(row.cacheInputTokens),
|
|
@@ -735,6 +756,9 @@ export async function listRecentModelCalls(
|
|
|
735
756
|
estimatedProviderCostMicros: sql<
|
|
736
757
|
number | null
|
|
737
758
|
>`${modelCallFacts.estimatedProviderCostMicros}`,
|
|
759
|
+
equivalentCreditCostMicros: sql<
|
|
760
|
+
number | null
|
|
761
|
+
>`${modelCallFacts.equivalentCreditCostMicros}`,
|
|
738
762
|
pricingSource: sql<string | null>`${modelCallFacts.pricingSource}`,
|
|
739
763
|
})
|
|
740
764
|
.from(source)
|
|
@@ -763,6 +787,10 @@ export async function listRecentModelCalls(
|
|
|
763
787
|
row.estimatedProviderCostMicros,
|
|
764
788
|
"estimated provider cost",
|
|
765
789
|
),
|
|
790
|
+
equivalentCreditCostMicros: insightsNullableNumber(
|
|
791
|
+
row.equivalentCreditCostMicros,
|
|
792
|
+
"equivalent credit cost",
|
|
793
|
+
),
|
|
766
794
|
}));
|
|
767
795
|
});
|
|
768
796
|
}
|
|
@@ -886,6 +914,8 @@ export async function aggregateScheduleFacts(
|
|
|
886
914
|
pricedCostMicros: sql<number>`coalesce(sum(${modelCallFacts.pricedCostMicros}) filter (where ${modelCallFacts.billingPath} = 'opengeni_credits'), 0)`,
|
|
887
915
|
estimatedProviderCostMicros: sql<number>`coalesce(sum(${modelCallFacts.estimatedProviderCostMicros}), 0)`,
|
|
888
916
|
estimatedProviderCostKnownCalls: sql<number>`count(${modelCallFacts.estimatedProviderCostMicros})::int`,
|
|
917
|
+
equivalentCreditCostMicros: sql<number>`coalesce(sum(${modelCallFacts.equivalentCreditCostMicros}), 0)`,
|
|
918
|
+
equivalentCreditCostKnownCalls: sql<number>`count(${modelCallFacts.equivalentCreditCostMicros})::int`,
|
|
889
919
|
totalTokens: sql<number>`coalesce(sum(${modelCallFacts.totalTokens}), 0)`,
|
|
890
920
|
cachedTokens: sql<number>`coalesce(sum(${modelCallFacts.cachedTokens}), 0)`,
|
|
891
921
|
cacheInputTokens: sql<number>`coalesce(sum(${modelCallFacts.inputTokens}) filter (where ${modelCallFacts.cachedTokens} is not null and ${modelCallFacts.inputTokens} is not null), 0)`,
|
|
@@ -906,6 +936,8 @@ export async function aggregateScheduleFacts(
|
|
|
906
936
|
pricedCostMicros: Number(row.pricedCostMicros),
|
|
907
937
|
estimatedProviderCostMicros: Number(row.estimatedProviderCostMicros),
|
|
908
938
|
estimatedProviderCostKnownCalls: Number(row.estimatedProviderCostKnownCalls),
|
|
939
|
+
equivalentCreditCostMicros: Number(row.equivalentCreditCostMicros),
|
|
940
|
+
equivalentCreditCostKnownCalls: Number(row.equivalentCreditCostKnownCalls),
|
|
909
941
|
totalTokens: Number(row.totalTokens),
|
|
910
942
|
cachedTokens: Number(row.cachedTokens),
|
|
911
943
|
cacheInputTokens: Number(row.cacheInputTokens),
|
|
@@ -1106,7 +1138,7 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1106
1138
|
|
|
1107
1139
|
let considered = 0;
|
|
1108
1140
|
let upserted = 0;
|
|
1109
|
-
let cursorOccurredAt = input.since;
|
|
1141
|
+
let cursorOccurredAt = input.since.toISOString();
|
|
1110
1142
|
let cursorId = "00000000-0000-0000-0000-000000000000";
|
|
1111
1143
|
|
|
1112
1144
|
while (considered < limit) {
|
|
@@ -1122,6 +1154,7 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1122
1154
|
turnAttemptId: schema.sessionEvents.turnAttemptId,
|
|
1123
1155
|
payload: schema.sessionEvents.payload,
|
|
1124
1156
|
occurredAt: schema.sessionEvents.occurredAt,
|
|
1157
|
+
cursorOccurredAt: sql<string>`${schema.sessionEvents.occurredAt}::text`,
|
|
1125
1158
|
})
|
|
1126
1159
|
.from(schema.sessionEvents)
|
|
1127
1160
|
.where(
|
|
@@ -1132,7 +1165,7 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1132
1165
|
lt(schema.sessionEvents.occurredAt, until),
|
|
1133
1166
|
sql`${schema.sessionEvents.turnId} is not null`,
|
|
1134
1167
|
// Keyset on (occurred_at, id) so same-millisecond bursts cannot be skipped.
|
|
1135
|
-
sql`(${schema.sessionEvents.occurredAt}, ${schema.sessionEvents.id}) > (${cursorOccurredAt}, ${cursorId}::uuid)`,
|
|
1168
|
+
sql`(${schema.sessionEvents.occurredAt}, ${schema.sessionEvents.id}) > (${cursorOccurredAt}::timestamptz, ${cursorId}::uuid)`,
|
|
1136
1169
|
),
|
|
1137
1170
|
)
|
|
1138
1171
|
.orderBy(schema.sessionEvents.occurredAt, schema.sessionEvents.id)
|
|
@@ -1141,7 +1174,7 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1141
1174
|
if (page.length === 0) break;
|
|
1142
1175
|
considered += page.length;
|
|
1143
1176
|
const last = page[page.length - 1]!;
|
|
1144
|
-
cursorOccurredAt = last.
|
|
1177
|
+
cursorOccurredAt = last.cursorOccurredAt;
|
|
1145
1178
|
cursorId = last.id;
|
|
1146
1179
|
|
|
1147
1180
|
const batchUpserted = await withRlsContext(db, context, async (scopedDb) => {
|
|
@@ -1158,6 +1191,15 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1158
1191
|
const providerApi = typeof payload.providerApi === "string" ? payload.providerApi : null;
|
|
1159
1192
|
const model = typeof payload.model === "string" ? payload.model : null;
|
|
1160
1193
|
if (!sourceKey || !provider || !providerApi || !model) continue;
|
|
1194
|
+
const upstreamProvider =
|
|
1195
|
+
typeof payload.upstreamProvider === "string" &&
|
|
1196
|
+
/^[a-z0-9][a-z0-9-]{0,63}$/.test(payload.upstreamProvider)
|
|
1197
|
+
? payload.upstreamProvider
|
|
1198
|
+
: null;
|
|
1199
|
+
const durableBillingPath =
|
|
1200
|
+
payload.billingPath === "external" || payload.billingPath === "opengeni_credits"
|
|
1201
|
+
? payload.billingPath
|
|
1202
|
+
: null;
|
|
1161
1203
|
|
|
1162
1204
|
const sourceResourceId = `${event.turnId}:${sourceKey}`;
|
|
1163
1205
|
const [cost] = await scopedDb
|
|
@@ -1183,11 +1225,15 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1183
1225
|
)
|
|
1184
1226
|
.limit(1);
|
|
1185
1227
|
|
|
1186
|
-
//
|
|
1187
|
-
//
|
|
1228
|
+
// New usage events carry the accepted billing authority because a
|
|
1229
|
+
// deployment-funded free call legitimately writes both model.tokens
|
|
1230
|
+
// and model.cost=0. Older events predate that field: their external
|
|
1231
|
+
// subscription/workspace calls wrote cost=0 without tokens, while
|
|
1232
|
+
// zero-token credits calls wrote neither.
|
|
1188
1233
|
const pricedCostMicros = cost ? Number(cost.quantity) : 0;
|
|
1189
1234
|
const billingPath =
|
|
1190
|
-
|
|
1235
|
+
durableBillingPath ??
|
|
1236
|
+
(cost != null && pricedCostMicros === 0 && !tokenRow ? "external" : "opengeni_credits");
|
|
1191
1237
|
|
|
1192
1238
|
const [turn] = await scopedDb
|
|
1193
1239
|
.select({
|
|
@@ -1239,7 +1285,7 @@ export async function backfillModelCallFactsFromSessionEvents(
|
|
|
1239
1285
|
turnId: event.turnId,
|
|
1240
1286
|
turnAttemptId: event.turnAttemptId,
|
|
1241
1287
|
sourceKey,
|
|
1242
|
-
provider,
|
|
1288
|
+
provider: upstreamProvider ?? provider,
|
|
1243
1289
|
providerApi,
|
|
1244
1290
|
model,
|
|
1245
1291
|
billingPath,
|
|
@@ -150,6 +150,8 @@ export type OrganizationUserSetupDeliveryClaim =
|
|
|
150
150
|
role: "viewer" | "member" | "admin";
|
|
151
151
|
}>;
|
|
152
152
|
expiresAt: string;
|
|
153
|
+
setupTokenTransport: "fragment" | "query" | null;
|
|
154
|
+
payloadDigest: string | null;
|
|
153
155
|
};
|
|
154
156
|
|
|
155
157
|
export async function claimOrganizationUserSetupDelivery(
|
|
@@ -169,7 +171,7 @@ export async function claimOrganizationUserSetupDelivery(
|
|
|
169
171
|
await setSubjectRlsContext(scopedDb, input.actorSubjectId);
|
|
170
172
|
const [row] = await rawRows<{ result: unknown }>(
|
|
171
173
|
scopedDb,
|
|
172
|
-
sql`select
|
|
174
|
+
sql`select claim_organization_user_setup_delivery_v2(
|
|
173
175
|
${JSON.stringify(input)}::jsonb
|
|
174
176
|
) as result`,
|
|
175
177
|
);
|
|
@@ -188,6 +190,7 @@ export async function prepareOrganizationUserSetupDelivery(
|
|
|
188
190
|
claimHolderId: string;
|
|
189
191
|
tokenDigest: string;
|
|
190
192
|
payloadDigest: string;
|
|
193
|
+
setupTokenTransport: "fragment" | "query";
|
|
191
194
|
providerIdempotencyScope: string;
|
|
192
195
|
providerIdempotencyRetentionSeconds: number;
|
|
193
196
|
},
|
|
@@ -199,7 +202,7 @@ export async function prepareOrganizationUserSetupDelivery(
|
|
|
199
202
|
await setSubjectRlsContext(scopedDb, input.actorSubjectId);
|
|
200
203
|
await rawRows(
|
|
201
204
|
scopedDb,
|
|
202
|
-
sql`select
|
|
205
|
+
sql`select prepare_organization_user_setup_delivery_v2(
|
|
203
206
|
${JSON.stringify(input)}::jsonb
|
|
204
207
|
)`,
|
|
205
208
|
);
|
|
@@ -273,7 +276,13 @@ function parseOrganizationUserSetupDeliveryClaim(
|
|
|
273
276
|
typeof candidate.organizationName !== "string" ||
|
|
274
277
|
!["owner", "admin", "member"].includes(String(candidate.organizationRole)) ||
|
|
275
278
|
!workspaceAccess.success ||
|
|
276
|
-
typeof candidate.expiresAt !== "string"
|
|
279
|
+
typeof candidate.expiresAt !== "string" ||
|
|
280
|
+
(candidate.setupTokenTransport !== null &&
|
|
281
|
+
candidate.setupTokenTransport !== "fragment" &&
|
|
282
|
+
candidate.setupTokenTransport !== "query") ||
|
|
283
|
+
(candidate.payloadDigest !== null &&
|
|
284
|
+
(typeof candidate.payloadDigest !== "string" ||
|
|
285
|
+
!/^[0-9a-f]{64}$/u.test(candidate.payloadDigest)))
|
|
277
286
|
) {
|
|
278
287
|
throw new Error("Organization user setup delivery claim returned an invalid result");
|
|
279
288
|
}
|
|
@@ -290,6 +299,8 @@ function parseOrganizationUserSetupDeliveryClaim(
|
|
|
290
299
|
organizationRole: candidate.organizationRole as "owner" | "admin" | "member",
|
|
291
300
|
sharedWorkspaceAccess: workspaceAccess.data,
|
|
292
301
|
expiresAt: candidate.expiresAt,
|
|
302
|
+
setupTokenTransport: candidate.setupTokenTransport,
|
|
303
|
+
payloadDigest: candidate.payloadDigest,
|
|
293
304
|
};
|
|
294
305
|
}
|
|
295
306
|
|