@xopcai/xopc 0.0.371 → 0.0.373
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-BQ3PMp2q.js → activity-store-BeYLqqr8.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-C8MqXy6W.js → agent-avatar-dicebear--kDkSTqC.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-z4_2-Kn2.js +1 -0
- package/dist/gateway/static/root/assets/{agent-plugin-dialog-BrysdA6F.js → agent-plugin-dialog-BYndK83K.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-BJRyMNx2.js → agents-CVo96cx1.js} +3 -3
- package/dist/gateway/static/root/assets/{agents-admin-api-HBZvVyzF.js → agents-admin-api-B4tgTbWG.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-Bi02swpZ.js → app-management-settings-panel-D9oOJKiH.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-rr0qirDm.js → appearance-settings-B0-8Cdyv.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-Sz3wl3lV.js → apps-page-DasVc6i4.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BO3I9zRP.js → archive-plugin-bI9OLnXj.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-DqdbP0hD.js → automations-page-BlCNqy2i.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-workspace-CxgKlA5d.js → automations-workspace-C8ipDP05.js} +1 -1
- package/dist/gateway/static/root/assets/{binary-plugins-gFD7vH9R.js → binary-plugins-dOwLzjeH.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-CfVR1zGa.js → block-editor-Cktlez6g.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automation-inputs-DxRoKFun.js → browser-automation-inputs-i7h1Svpf.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-automations-page-DeYnh3mY.js → browser-automations-page-KRfDl8ej.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-DDZvlGCD.js → browser-settings-page-BraQ4wnh.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-CY4SiHcP.js → capabilities-CquUV0DP.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-gjQtMhKu.js → capabilities-D4KFLtqM.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-page-Bl6PZqx3.js → capabilities-page-B3m8xGzd.js} +2 -2
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-B-MM4LJA.js → capabilities-settings-panel-VQ4fHuBV.js} +6 -6
- package/dist/gateway/static/root/assets/{capability-header-actions-CAiY7HK1.js → capability-header-actions-f5Ido4Eg.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-D1_fDkhu.js → channels-N4Vc2nEG.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-D6slpF2a.js → chat-terminal-dock-BwvTKwsn.js} +1 -1
- package/dist/gateway/static/root/assets/cloud-credits-BMYMiiNn.js +1 -0
- package/dist/gateway/static/root/assets/{computer-settings-page-D1n_uQHN.js → computer-settings-page-CAwUsKpw.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-FvSCyJzn.js → connector-service-page-C0HuAMuH.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-DroD-gQn.js → connectors-page-BcBmW8JT.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-Bl-HqvGU.js → date-picker-DiQxRpe-.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-DY4nU-HL.js → dependency-picker-Ds0_BJbN.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-_A89B2xw.js → desktop-pet-ZMEOYwrR.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BJWkGynu.js → desktop-pet-settings-DkyTqD07.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-DJ_ITvkI.js → device-pairing-wizard-CvaI5ZJZ.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-Bj2Cpmxs.js → directory-picker-path-field-Bfv93eK1.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BfAtjhoK.js → extension-debug-page-CbgEonkK.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-BFjc1zDp.js → extension-page-JXKGtIdM.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-provider-Br6LXyIj.js → extension-provider-DxlAZ2iy.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-oAwllsMb.js → extension-settings-page-lsQ2xvbr.js} +1 -1
- package/dist/gateway/static/root/assets/{fallback-models-KHd6tw_t.js → fallback-models-7bG0AND1.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-7RKqgU_U.js → gateway-config-swr-BoRkBnsw.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-realtime-C3WQQY10.js +1 -0
- package/dist/gateway/static/root/assets/gateway-realtime-store-cLCDEe4D.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-settings-BIyhyiOq.js → gateway-settings-BpbcoPx9.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-jiV5sbEX.js → gateway-startup-retry-TYSQEQcG.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-CEjaIUTF.js → home-page-BxctC0aJ.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-DO4mXb6I.js → image-generation-api-_pKiNfSq.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-ClFqRiGQ.js → imports-page-Bq8CazCb.js} +1 -1
- package/dist/gateway/static/root/assets/{index-GBFmI8im.js → index-B40-KDN8.js} +7 -7
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-Ca9_GJSQ.js → keyboard-shortcuts-settings-kkAevkl2.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-BaK9zX1-.js → local-app-workbench-page-abLaf1hW.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-1CjSftZ3.js → local-apps-page-nwsnwYjK.js} +1 -1
- package/dist/gateway/static/root/assets/{local-session-drafts-pox8evDV.js → local-session-drafts-Cg9RdsNN.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-COVscAqC.js → locale-store-rWFLl-p4.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-6joZBbcx.js → logs-page-BEgYS-Xg.js} +1 -1
- package/dist/gateway/static/root/assets/{management-settings-Cnubkklb.js → management-settings-D_JQ6_X0.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-B_qnAcW2.js → markdown-view-BHFFusQs.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-C0Pc-wSY.js → media-plugins-BVPTMWJI.js} +1 -1
- package/dist/gateway/static/root/assets/messages-C1SUo4gG.js +3 -0
- package/dist/gateway/static/root/assets/models-hub-cache-Jj8dvYcv.js +1 -0
- package/dist/gateway/static/root/assets/{note-detail-panel-B6DHbMzT.js → note-detail-panel-CCnfurBR.js} +3 -3
- package/dist/gateway/static/root/assets/{notes-api-sBgBcyLW.js → notes-api-CSLVCZBn.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-page-CGZkIKdi.js → notes-page-D9u_znxM.js} +1 -1
- package/dist/gateway/static/root/assets/{page-context-capture-button-y3QmhTu2.js → page-context-capture-button-BO3FoRej.js} +1 -1
- package/dist/gateway/static/root/assets/{personal-page-C_roXCJB.js → personal-page-BJn6UHAF.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CSRYWt0f.js → product-open-page-Dso2_hyl.js} +1 -1
- package/dist/gateway/static/root/assets/{product-preview-content-DuOML6gs.js → product-preview-content-CkvVb3EA.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-v7xtnvha.js → project-detail-page-UjrrzE3H.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-BuJCBT6n.js → projects-page-C1h63P2M.js} +1 -1
- package/dist/gateway/static/root/assets/{registry-api-Bh9UBb-f.js → registry-api-CoMBYjHD.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-DpHnyBnG.js → remote-access-hub-BJifH8AB.js} +1 -1
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-DTMTL0hy.js → runtime-tools-settings-panel-vG1wqcEb.js} +1 -1
- package/dist/gateway/static/root/assets/{scenes-page-B0JqO_fM.js → scenes-page-CwoAoYMX.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-g4z7GH4W.js → schema-form-BIsHdyz7.js} +1 -1
- package/dist/gateway/static/root/assets/{send-session-input-BW40VHiL.js → send-session-input-CLhR1uEp.js} +1 -1
- package/dist/gateway/static/root/assets/{session-api-yjpEz4pP.js → session-api-u_4_kFQt.js} +1 -1
- package/dist/gateway/static/root/assets/{session-manager-BqlvrjPE.js → session-manager-B06ZCie_.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-CftImbH7.js → sessions-page-BcCLp3yU.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-D114UdRI.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-YD-U8BVw.js → settings-page-z9Jlk0BL.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-q_X3kxw2.js → setup-status-panel-CrpXECqe.js} +1 -1
- package/dist/gateway/static/root/assets/{share-link-dialog-HCHM8qnf.js → share-link-dialog-XhiuPKF4.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-Ce6FNWt1.js → share-preview-page-Vc0TQuZ8.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-api-c0dfWz6h.js → shares-api-BVSb1vh4.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-KHRg_-03.js → shares-settings-D9XpTJXP.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-api-BpqDMkNB.js → skill-api-DtPOf1aW.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-reload-api-Ge5XymHa.js → skill-reload-api-BsLx_FXd.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-Bnfn51ks.js → skills-page-Bq9-2b9U.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-CncvC2CI.js → system-settings-panel-P7T729uD.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-BVJKdnMC.js → task-detail-page-CsB9AFx6.js} +1 -1
- package/dist/gateway/static/root/assets/{task-expandable-content-hYcgCEE3.js → task-expandable-content-DxeBTJvh.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BOfCKgl6.js → theme-store-KcQhCg1-.js} +1 -1
- package/dist/gateway/static/root/assets/{tracing-settings-page-DDWFXcST.js → tracing-settings-page-DJRAP3nb.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-g7etuoaT.js → tunnel-api-CuowqIZ7.js} +1 -1
- package/dist/gateway/static/root/assets/usage-page-avX3msoZ.js +1 -0
- package/dist/gateway/static/root/assets/{use-autosave-CSckcjFx.js → use-autosave-C-IWxbzm.js} +1 -1
- package/dist/gateway/static/root/assets/{use-composer-attachments-DJya1hIL.js → use-composer-attachments-Dxphaxk-.js} +1 -1
- package/dist/gateway/static/root/assets/{use-file-preview-expanded-C5ONO7sF.js → use-file-preview-expanded-Du37Gofn.js} +2 -2
- package/dist/gateway/static/root/assets/{user-model-page-jr986ucl.js → user-model-page-DGDBWw7P.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-GEw5x2fU.js → voice-api-key-field-7BImy8Jc.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-3yyVwXln.js → voice-config-api-6MINytQl.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-CC3mr7tX.js → work-discovery-overlay-BgJNz2tH.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-CqpXZJxs.js → workflow-run-setup-panel-1I2q2J_U.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-DOk6tBbK.js → workflows-page-DhJl9pnO.js} +1 -1
- package/dist/gateway/static/root/assets/{workspace-api-WhbMvdBE.js → workspace-api-CXiyhTwv.js} +2 -2
- package/dist/gateway/static/root/assets/xopc-cloud-account-card-CnPBP1V_.js +1 -0
- package/dist/gateway/static/root/index.html +26 -26
- package/dist/package.js +1 -1
- package/dist/packages/endpoint-tools-protocol/src/index.js +4 -110
- package/dist/packages/endpoint-tools-protocol/src/personal.js +2 -2
- package/dist/packages/endpoint-tools-protocol/src/shared-schemas.js +116 -0
- package/dist/packages/gateway-contract/src/cloud-credits.js +80 -0
- package/dist/packages/gateway-contract/src/index.js +2 -0
- package/dist/src/agent/agent-manager.js +4 -4
- package/dist/src/agent/background-review/run-background-review.js +1 -1
- package/dist/src/agent/client-error-format.d.ts +1 -1
- package/dist/src/agent/client-error-format.js +7 -0
- package/dist/src/agent/embedded/model-runtime.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +2 -2
- package/dist/src/agent/embedded/run-turn.js +40 -4
- package/dist/src/agent/embedded/xopc-stream-bridge.js +18 -0
- package/dist/src/agent/image/generation/openai-images-provider.d.ts +2 -1
- package/dist/src/agent/image/generation/openai-images-provider.js +13 -7
- package/dist/src/agent/image/generation/providers/xopc-cloud.js +14 -2
- package/dist/src/agent/image/tool-model-config.js +1 -1
- package/dist/src/agent/service.js +3 -3
- package/dist/src/agent/session/session-inspector.js +1 -1
- package/dist/src/agent/tasks/task-judge-service.js +3 -3
- package/dist/src/agent-config/schema.d.ts +4 -0
- package/dist/src/agent-config/schema.js +1 -0
- package/dist/src/ai-assist/text-assist.js +1 -1
- package/dist/src/auth/credentials.js +2 -2
- package/dist/src/auth/model-credential-store.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/chat-commands/builtins/config.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/doctor/checks/image-providers.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/models.js +42 -1
- package/dist/src/cli/commands/onboard/model.js +3 -3
- package/dist/src/computer/runtime.js +4 -1
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/loader.js +1 -1
- package/dist/src/config/models-json.js +2 -2
- package/dist/src/endpoint-tools/policy.js +2 -1
- package/dist/src/extensions/activation-context.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +1 -0
- package/dist/src/gateway/hono/lib/config-payload.js +2 -2
- package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
- package/dist/src/gateway/hono/routes/models.js +4 -4
- package/dist/src/gateway/hono/routes/observability.js +1 -1
- package/dist/src/gateway/hono/routes/usage.js +15 -5
- package/dist/src/gateway/hono/routes/voice.js +1 -1
- package/dist/src/gateway/service/config-coordinator.js +1 -1
- package/dist/src/gateway/service/session-command-service.js +1 -1
- package/dist/src/gateway/service.js +4 -4
- package/dist/src/home-intelligence/generator.js +1 -1
- package/dist/src/notes/service.js +1 -1
- package/dist/src/observability/runtime.js +1 -1
- package/dist/src/personal-agent/proactivity/service.js +2 -2
- package/dist/src/personal-agent/reply-composer.js +2 -2
- package/dist/src/platform/client.d.ts +1 -1
- package/dist/src/platform/contracts.d.ts +1 -1
- package/dist/src/platform/index.js +1 -1
- package/dist/src/providers/index.js +4 -4
- package/dist/src/providers/model-call.js +15 -1
- package/dist/src/providers/model-registry.js +2 -2
- package/dist/src/providers/provider-auth-service.js +1 -1
- package/dist/src/providers/provider-disconnect-core.js +1 -1
- package/dist/src/providers/register-runtime-providers.js +1 -1
- package/dist/src/providers/xopc-cloud-account-service.d.ts +7 -23
- package/dist/src/providers/xopc-cloud-account-service.js +49 -29
- package/dist/src/providers/xopc-cloud-catalog-coordinator.js +1 -1
- package/dist/src/providers/xopc-cloud-credit-budget.d.ts +14 -0
- package/dist/src/providers/xopc-cloud-credit-budget.js +61 -0
- package/dist/src/storage/sqlite/ai-usage-repository.d.ts +9 -0
- package/dist/src/storage/sqlite/ai-usage-repository.js +94 -5
- package/dist/src/storage/sqlite/migrations/242_cloud_usage_receipts.sql +5 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/tasks/task-main-update-decision-service.js +2 -2
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tui/tui.js +1 -1
- package/dist/src/usage/cloud-capability.d.ts +2 -0
- package/dist/src/usage/cloud-capability.js +34 -0
- package/dist/src/usage/cloud-receipts.d.ts +10 -0
- package/dist/src/usage/cloud-receipts.js +55 -0
- package/dist/src/usage/cost.js +1 -0
- package/dist/src/usage/recorder.js +3 -1
- package/dist/src/usage/scenario-registry.js +15 -0
- package/dist/src/voice/realtime/runtime.js +27 -22
- package/dist/src/voice/stt/providers/xopc-cloud-transcription.js +28 -14
- package/dist/src/voice/tts/providers/xopc-cloud-speech.js +39 -29
- package/dist/src/voice/tts/speech-provider-types.d.ts +1 -0
- package/dist/src/work-discovery/service.js +2 -2
- package/dist/src/workflows/service/workflow-run-service.js +1 -1
- package/package.json +4 -4
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BLaL4law.js +0 -1
- package/dist/gateway/static/root/assets/gateway-realtime-F6D4A7N5.js +0 -1
- package/dist/gateway/static/root/assets/gateway-realtime-store-BheKaO6d.js +0 -1
- package/dist/gateway/static/root/assets/messages-Bb2GK-Nj.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-cache-DyPPksMP.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BkvbSieZ.js +0 -1
- package/dist/gateway/static/root/assets/usage-page-Dao1I-5F.js +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getAiUsageEventView, listAiUsageEvents, listAiUsageTrace, summarizeAiUsage } from "../../../storage/sqlite/ai-usage-repository.js";
|
|
1
|
+
import { getAiUsageEventView, listAiUsageEvents, listAiUsageTrace, pendingAiUsageCloudReceiptIds, summarizeAiUsage } from "../../../storage/sqlite/ai-usage-repository.js";
|
|
2
|
+
import { reconcileCloudUsageReceipt } from "../../../usage/cloud-receipts.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { Hono } from "hono";
|
|
4
5
|
//#region src/gateway/hono/routes/usage.ts
|
|
@@ -41,14 +42,23 @@ function registerUsageRoutes(authenticated, _deps) {
|
|
|
41
42
|
if (error instanceof z.ZodError || error.message.startsWith("invalid_usage_")) return c.json({ error: "invalid_usage_query" }, 400);
|
|
42
43
|
throw error;
|
|
43
44
|
});
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const refreshReceipts = async (query) => {
|
|
46
|
+
await Promise.all(pendingAiUsageCloudReceiptIds(query).map(reconcileCloudUsageReceipt));
|
|
47
|
+
};
|
|
48
|
+
app.get("/summary", async (c) => {
|
|
49
|
+
const query = parseFilters(c.req.query());
|
|
50
|
+
await refreshReceipts(query);
|
|
51
|
+
return c.json(summarizeAiUsage(query));
|
|
52
|
+
});
|
|
53
|
+
app.get("/events", async (c) => {
|
|
46
54
|
const limit = z.coerce.number().int().min(1).max(200).optional().parse(c.req.query("limit"));
|
|
47
|
-
|
|
55
|
+
const query = {
|
|
48
56
|
...parseFilters(c.req.query()),
|
|
49
57
|
limit,
|
|
50
58
|
before: parseCursor(c.req.query("cursor"))
|
|
51
|
-
}
|
|
59
|
+
};
|
|
60
|
+
await refreshReceipts(query);
|
|
61
|
+
return c.json(listAiUsageEvents(query));
|
|
52
62
|
});
|
|
53
63
|
app.get("/events/:id", (c) => {
|
|
54
64
|
const event = getAiUsageEventView(c.req.param("id"));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { voiceSelectionSchema } from "../../../../packages/realtime-protocol/src/voice-catalog.js";
|
|
2
2
|
import { VOICE_TIMING_METRICS, createVoiceSessionRequestSchema, init_voice } from "../../../../packages/realtime-protocol/src/voice.js";
|
|
3
3
|
import { getDefaultModelSync, init_providers, resolveModel } from "../../../providers/index.js";
|
|
4
|
-
import { isPersonalConversation } from "../../../personal-agent/repository.js";
|
|
5
4
|
import { completeWithResolvedCredentials } from "../../../providers/model-call.js";
|
|
5
|
+
import { isPersonalConversation } from "../../../personal-agent/repository.js";
|
|
6
6
|
import { resolveSttProviderConfigSlice } from "../../../voice/stt/config-slice.js";
|
|
7
7
|
import { STTTranscriptionError, transcribe } from "../../../voice/stt/transcribe-core.js";
|
|
8
8
|
import { isSTTAvailable } from "../../../voice/stt/availability.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createLogger } from "../../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../../utils/logger.js";
|
|
3
|
-
import { configureTracing } from "../../observability/runtime.js";
|
|
4
3
|
import { getModelRegistry } from "../../providers/model-registry.js";
|
|
5
4
|
import { init_providers } from "../../providers/index.js";
|
|
5
|
+
import { configureTracing } from "../../observability/runtime.js";
|
|
6
6
|
import { evictAllEmbeddedSessionRunners } from "../../agent/embedded/session-runner.js";
|
|
7
7
|
import { reloadImageGenerationProviders } from "../../agent/image/generation/provider-registry.js";
|
|
8
8
|
import { loadConfig, saveConfig } from "../../config/loader.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getSessionMetadata } from "../../storage/sqlite/session-read-repository.js";
|
|
2
2
|
import { init_session_repository } from "../../storage/sqlite/session-repository.js";
|
|
3
|
-
import { resolveEffectiveAgentConfigForAgent, resolveEffectiveAgentConfigForSession } from "../../config/agent-profile.js";
|
|
4
3
|
import { init_providers, resolveModel } from "../../providers/index.js";
|
|
4
|
+
import { resolveEffectiveAgentConfigForAgent, resolveEffectiveAgentConfigForSession } from "../../config/agent-profile.js";
|
|
5
5
|
import { getPersonalAgentByConversation } from "../../personal-agent/repository.js";
|
|
6
6
|
import { resolveProjectAgentId } from "../../projects/project-agent.js";
|
|
7
7
|
import "../../projects/index.js";
|
|
@@ -18,17 +18,17 @@ import { getSessionConfig, init_config_repository } from "../storage/sqlite/conf
|
|
|
18
18
|
import { init_sqlite } from "../storage/sqlite/index.js";
|
|
19
19
|
import { normalizeAgentId } from "../agent-catalog/id.js";
|
|
20
20
|
import { init_agent_scope, listAgentEntries, resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agent/agent-scope.js";
|
|
21
|
-
import { init_paths, resolveConfigPath, resolveExtensionsDir } from "../config/paths.js";
|
|
22
|
-
import { flushTracing } from "../observability/runtime.js";
|
|
23
21
|
import { init_config, resolveKnowledgeReadPolicy } from "../user-context/config.js";
|
|
24
22
|
import { getAgentDefaultModelRef, init_schema } from "../config/schema.js";
|
|
23
|
+
import { init_paths, resolveConfigPath, resolveExtensionsDir } from "../config/paths.js";
|
|
24
|
+
import { prewarmModelRegistry } from "../providers/model-registry.js";
|
|
25
25
|
import { init_agent_session_key, resolveAgentMainConversationId } from "../routing/agent-session-key.js";
|
|
26
26
|
import { init_session_key, resolveConversationId, sanitizeSegment } from "../routing/session-key.js";
|
|
27
27
|
import { getDefaultAgentId, init_resolve_route } from "../routing/resolve-route.js";
|
|
28
|
-
import { resolveEffectiveAgentProfileForSession } from "../config/agent-profile.js";
|
|
29
|
-
import { prewarmModelRegistry } from "../providers/model-registry.js";
|
|
30
28
|
import { init_providers, providers_exports } from "../providers/index.js";
|
|
29
|
+
import { flushTracing } from "../observability/runtime.js";
|
|
31
30
|
import { AI_USAGE_RETENTION_MS, markStaleAiUsageEventsUnknown, pruneAiUsageEvents } from "../storage/sqlite/ai-usage-repository.js";
|
|
31
|
+
import { resolveEffectiveAgentProfileForSession } from "../config/agent-profile.js";
|
|
32
32
|
import { listKnowledgeItems } from "../knowledge-memory/repository.js";
|
|
33
33
|
import "../knowledge-memory/index.js";
|
|
34
34
|
import { getPersonalAgentByConversation } from "../personal-agent/repository.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { init_agent_scope, resolveDefaultAgentId } from "../agent/agent-scope.js";
|
|
2
|
+
import { extractAssistantText, getAssistantMessageErrorReason } from "../providers/model-response.js";
|
|
2
3
|
import { init_providers, resolveModel } from "../providers/index.js";
|
|
3
4
|
import { completeWithResolvedCredentials, isLocalModelBaseUrl } from "../providers/model-call.js";
|
|
4
|
-
import { extractAssistantText, getAssistantMessageErrorReason } from "../providers/model-response.js";
|
|
5
5
|
import { resolveModelSelector } from "../config/agent-model-intents.js";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
//#region src/home-intelligence/generator.ts
|
|
@@ -7,8 +7,8 @@ import { init_note_markdown, parseNoteMarkdown } from "./note-markdown.js";
|
|
|
7
7
|
import { init_notes_repository, listNoteProjectSummaries } from "../storage/sqlite/notes-repository.js";
|
|
8
8
|
import { changedFieldsFromPatch, emitActivity, previewText, systemActivityActor, systemActivitySource } from "../activity/emitter.js";
|
|
9
9
|
import { getDefaultModelSync, init_providers, resolveModel } from "../providers/index.js";
|
|
10
|
-
import { DomainOutboxDispatcher } from "../infra/domain-outbox-dispatcher.js";
|
|
11
10
|
import { completeWithResolvedCredentials } from "../providers/model-call.js";
|
|
11
|
+
import { DomainOutboxDispatcher } from "../infra/domain-outbox-dispatcher.js";
|
|
12
12
|
import { partitionAttachmentsByReference } from "./note-attachment-sync.js";
|
|
13
13
|
import { buildNoteAgentContextArtifact, getCachedNoteAgentContextArtifact } from "./agent-context.js";
|
|
14
14
|
import { revokeNoteShareRecords } from "../share/note-share-revocation.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { init_context, runWithLogContext } from "../utils/logger/context.js";
|
|
2
2
|
import { createLogger } from "../utils/logger/index.js";
|
|
3
3
|
import { init_logger } from "../utils/logger.js";
|
|
4
|
-
import { CredentialResolver, init_credentials } from "../auth/credentials.js";
|
|
5
4
|
import { TracingConfigSchema, defaultTracingConfig, init_config } from "./config.js";
|
|
5
|
+
import { CredentialResolver, init_credentials } from "../auth/credentials.js";
|
|
6
6
|
import { LangfuseTarget } from "./langfuse.js";
|
|
7
7
|
import { boundedJson, redactString } from "./sanitize.js";
|
|
8
8
|
import { LocalTraceStore } from "./store.js";
|
|
@@ -6,13 +6,13 @@ import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
|
6
6
|
import { init_session_instance_repository, readCurrentTranscriptId } from "../../storage/sqlite/session-instance-repository.js";
|
|
7
7
|
import { appendTranscriptEntry, init_transcript_repository } from "../../storage/sqlite/transcript-repository.js";
|
|
8
8
|
import { AgentCatalogRepository, init_repository } from "../../agent-catalog/repository.js";
|
|
9
|
+
import { extractAssistantText, getAssistantMessageErrorReason, stripCodeFences } from "../../providers/model-response.js";
|
|
9
10
|
import { init_providers, resolveModel } from "../../providers/index.js";
|
|
11
|
+
import { completeWithResolvedCredentials } from "../../providers/model-call.js";
|
|
10
12
|
import { resolveUserContextSessionAccess } from "../../user-context/access-policy.js";
|
|
11
13
|
import { getPersonalAgent } from "../repository.js";
|
|
12
14
|
import { DurableState } from "../../storage/sqlite/durable-state.js";
|
|
13
15
|
import { enqueueDue, enqueueWakeup, getAttention, getAttentionSources, getProactivitySettings, isQuiet, listAttention, localDay, preparationStrategy, recordFeedback, reserveModelCall, saveAttention, sourceFingerprint, userText } from "./repository.js";
|
|
14
|
-
import { completeWithResolvedCredentials } from "../../providers/model-call.js";
|
|
15
|
-
import { extractAssistantText, getAssistantMessageErrorReason, stripCodeFences } from "../../providers/model-response.js";
|
|
16
16
|
import { emitSessionTranscriptUpdate } from "../../session/transcript-events.js";
|
|
17
17
|
import { PERSONAL_PERSONA_GUIDANCE } from "../persona.js";
|
|
18
18
|
import { personalConversationState } from "../conversation-state.js";
|
|
@@ -9,12 +9,12 @@ import { appendTranscriptEntry, init_transcript_repository, loadLlmMessagesForSe
|
|
|
9
9
|
import { getSessionConfig, init_config_repository } from "../storage/sqlite/config-repository.js";
|
|
10
10
|
import { AgentCatalogRepository, init_repository } from "../agent-catalog/repository.js";
|
|
11
11
|
import { init_agent_scope, resolveAgentProfileDir } from "../agent/agent-scope.js";
|
|
12
|
+
import { extractAssistantText, getAssistantMessageErrorReason, stripCodeFences } from "../providers/model-response.js";
|
|
12
13
|
import { init_providers, resolveModel } from "../providers/index.js";
|
|
14
|
+
import { completeWithResolvedCredentials } from "../providers/model-call.js";
|
|
13
15
|
import { getPersonalAgentByConversation } from "./repository.js";
|
|
14
16
|
import { TaskConversationRepository } from "../tasks/task-conversation-repository.js";
|
|
15
17
|
import { loadProfileBootstrapFiles } from "../agent/bootstrap/load-bootstrap-files.js";
|
|
16
|
-
import { completeWithResolvedCredentials } from "../providers/model-call.js";
|
|
17
|
-
import { extractAssistantText, getAssistantMessageErrorReason, stripCodeFences } from "../providers/model-response.js";
|
|
18
18
|
import { emitSessionTranscriptUpdate } from "../session/transcript-events.js";
|
|
19
19
|
import { PERSONAL_PERSONA_GUIDANCE } from "./persona.js";
|
|
20
20
|
import { PERSONAL_REPLY_EXAMPLES, PERSONAL_REPLY_STYLE_RULES } from "./reply-style.js";
|
|
@@ -66,9 +66,9 @@ export declare const RuntimeCommandSchema: z.ZodObject<{
|
|
|
66
66
|
read: "read";
|
|
67
67
|
write: "write";
|
|
68
68
|
execute: "execute";
|
|
69
|
+
purchase: "purchase";
|
|
69
70
|
admin: "admin";
|
|
70
71
|
send: "send";
|
|
71
|
-
purchase: "purchase";
|
|
72
72
|
publish: "publish";
|
|
73
73
|
}>>;
|
|
74
74
|
}, z.core.$strict>;
|
|
@@ -152,9 +152,9 @@ export declare const AgentManifestSchema: z.ZodObject<{
|
|
|
152
152
|
read: "read";
|
|
153
153
|
write: "write";
|
|
154
154
|
execute: "execute";
|
|
155
|
+
purchase: "purchase";
|
|
155
156
|
admin: "admin";
|
|
156
157
|
send: "send";
|
|
157
|
-
purchase: "purchase";
|
|
158
158
|
publish: "publish";
|
|
159
159
|
}>>;
|
|
160
160
|
}, z.core.$strict>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { init_resolution, resolveConnectedPlatformDiscovery, resolveConnectedPlatformEndpoint, setActivePlatformDiscovery } from "./resolution.js";
|
|
2
1
|
import { AgentManifestSchema, PlatformCapabilitySchema, PlatformConfigSchema, PlatformDiscoverySchema, PlatformEventSchema, init_contracts } from "./contracts.js";
|
|
2
|
+
import { init_resolution, resolveConnectedPlatformDiscovery, resolveConnectedPlatformEndpoint, setActivePlatformDiscovery } from "./resolution.js";
|
|
3
3
|
import { PLATFORM_RUNTIME_PROFILE, PLATFORM_RUNTIME_PROVIDER, PlatformRuntimeClient, RuntimeCommandSchema, discoverPlatform } from "./client.js";
|
|
4
4
|
import { processRuntimeCommand } from "./worker.js";
|
|
5
5
|
//#region src/platform/index.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __esmMin, __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { getAgentDefaultModelRef, init_schema } from "../config/schema.js";
|
|
3
|
+
import { assertCurrentModelProvider, init_provider_policy, isRetiredModelProvider } from "./provider-policy.js";
|
|
2
4
|
import { PROVIDER_ENV_MAP, getApiKeyFromEnv, init_env_keys } from "./env-keys.js";
|
|
5
|
+
import { init_model_ref, splitProviderModelRef } from "./model-ref.js";
|
|
6
|
+
import { ModelRegistry, getModelRegistry, init_model_registry, prewarmModelRegistry, resetModelRegistry } from "./model-registry.js";
|
|
3
7
|
import { getModelOAuthProviderIds, init_registry } from "../auth/oauth/registry.js";
|
|
4
|
-
import { assertCurrentModelProvider, init_provider_policy, isRetiredModelProvider } from "./provider-policy.js";
|
|
5
8
|
import { CredentialResolver, hasCredentials, init_credentials } from "../auth/credentials.js";
|
|
6
|
-
import { getAgentDefaultModelRef, init_schema } from "../config/schema.js";
|
|
7
9
|
import { hasProviderAuthOnDiskSync, init_sync_provider_auth } from "../auth/sync-provider-auth.js";
|
|
8
|
-
import { init_model_ref, splitProviderModelRef } from "./model-ref.js";
|
|
9
|
-
import { ModelRegistry, getModelRegistry, init_model_registry, prewarmModelRegistry, resetModelRegistry } from "./model-registry.js";
|
|
10
10
|
import { EXTENSION_PROVIDER_BASE_URL, init_constants } from "./constants.js";
|
|
11
11
|
import { applyOfficialModelMetadataCorrections, getSupplementalModels, init_model_supplements } from "./model-supplements.js";
|
|
12
12
|
import { getProviderRegistry, init_plugin_registry } from "./plugin-registry.js";
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { init_constants } from "./constants.js";
|
|
2
2
|
import { getApiKey, init_providers } from "./index.js";
|
|
3
3
|
import { createExtensionAwareStreamFn } from "./extension-stream-bridge.js";
|
|
4
|
+
import { withCloudUsageResponse } from "../usage/cloud-receipts.js";
|
|
4
5
|
import { finishAiUsageFromMessage, observeAiUsageStream, startAiUsageCall } from "../usage/recorder.js";
|
|
6
|
+
import { assertCloudCreditBudgetActive, cloudCreditBudgetHeaders, reportCloudCreditError } from "./xopc-cloud-credit-budget.js";
|
|
5
7
|
import { completeSimple, normalizeContext } from "@earendil-works/pi-ai/compat";
|
|
6
8
|
//#region src/providers/model-call.ts
|
|
7
9
|
init_constants();
|
|
@@ -25,12 +27,18 @@ async function resolveModelCallApiKey(model, credentialOptions) {
|
|
|
25
27
|
return isLocalModelBaseUrl(model.baseUrl) ? "xopc-local" : void 0;
|
|
26
28
|
}
|
|
27
29
|
async function resolveModelCallOptions(model, options = {}, credentialOptions) {
|
|
30
|
+
assertCloudCreditBudgetActive();
|
|
31
|
+
if (model.provider === "xopc-cloud") options = withCloudUsageResponse(options);
|
|
28
32
|
const apiKey = options.apiKey ?? await resolveModelCallApiKey(model, credentialOptions);
|
|
29
33
|
if (!apiKey) throw new Error(`No API key for provider: ${model.provider}`);
|
|
30
34
|
const { temperature, ...rest } = options;
|
|
31
35
|
return {
|
|
32
36
|
...rest,
|
|
33
37
|
apiKey,
|
|
38
|
+
...model.provider === "xopc-cloud" ? { headers: {
|
|
39
|
+
...options.headers,
|
|
40
|
+
...await cloudCreditBudgetHeaders()
|
|
41
|
+
} } : {},
|
|
34
42
|
...temperature !== void 0 ? { temperature } : {}
|
|
35
43
|
};
|
|
36
44
|
}
|
|
@@ -54,9 +62,11 @@ async function completeWithResolvedCredentials(model, context, options, credenti
|
|
|
54
62
|
return result;
|
|
55
63
|
}
|
|
56
64
|
const result = await usageCall.run(() => completeSimple(model, context, resolvedOptions));
|
|
65
|
+
if (result.errorMessage) reportCloudCreditError(result.errorMessage);
|
|
57
66
|
finishAiUsageFromMessage(usageCall, result);
|
|
58
67
|
return result;
|
|
59
68
|
} catch (error) {
|
|
69
|
+
reportCloudCreditError(error instanceof Error ? error.message : String(error));
|
|
60
70
|
usageCall?.finish({
|
|
61
71
|
status: "failed",
|
|
62
72
|
errorSummary: error instanceof Error ? error.message : String(error)
|
|
@@ -80,7 +90,11 @@ async function createResolvedModelStream(model, context, options, credentialOpti
|
|
|
80
90
|
}
|
|
81
91
|
});
|
|
82
92
|
try {
|
|
83
|
-
|
|
93
|
+
const stream = await usageCall.run(() => createExtensionAwareStreamFn()(model, normalizeContext(context), resolvedOptions));
|
|
94
|
+
stream.result().then((message) => {
|
|
95
|
+
if (message.errorMessage) reportCloudCreditError(message.errorMessage);
|
|
96
|
+
}).catch(() => {});
|
|
97
|
+
return observeAiUsageStream(stream, usageCall);
|
|
84
98
|
} catch (error) {
|
|
85
99
|
usageCall?.finish({
|
|
86
100
|
status: "failed",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { createLogger } from "../utils/logger/index.js";
|
|
3
3
|
import { init_logger } from "../utils/logger.js";
|
|
4
|
-
import {
|
|
4
|
+
import { init_resolve_config_value, resolveConfigValue, resolveHeaders } from "../config/resolve-config-value.js";
|
|
5
5
|
import { resolveModelsJsonPath } from "../config/paths.js";
|
|
6
6
|
import { init_provider_policy, isRetiredModelProvider } from "./provider-policy.js";
|
|
7
|
-
import { init_resolve_config_value, resolveConfigValue, resolveHeaders } from "../config/resolve-config-value.js";
|
|
8
7
|
import { getDefaultModelValues, init_models_json, validateModelsConfig } from "../config/models-json.js";
|
|
8
|
+
import { getApiKeyFromEnv, init_env_keys } from "./env-keys.js";
|
|
9
9
|
import { getModelCatalogStore, init_model_catalog_store } from "./model-catalog-store.js";
|
|
10
10
|
import { init_model_ref, splitProviderModelRef } from "./model-ref.js";
|
|
11
11
|
import { existsSync, readFileSync } from "fs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { init_paths, resolveModelsJsonPath } from "../config/paths.js";
|
|
3
|
-
import { init_register_bundled_oauth_flows, registerBundledOAuthFlows } from "./register-bundled-oauth-flows.js";
|
|
4
3
|
import { assertCurrentModelProvider, init_provider_policy } from "./provider-policy.js";
|
|
4
|
+
import { init_register_bundled_oauth_flows, registerBundledOAuthFlows } from "./register-bundled-oauth-flows.js";
|
|
5
5
|
import { CredentialResolver, init_credentials } from "../auth/credentials.js";
|
|
6
6
|
import { XopcModelCredentialStore, init_model_credential_store } from "../auth/model-credential-store.js";
|
|
7
7
|
import { init_register_runtime_providers, registerRuntimeProviders } from "./register-runtime-providers.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createLogger } from "../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { getModelRegistry, init_model_registry } from "./model-registry.js";
|
|
3
4
|
import { init_oauth_provider_lock, withOAuthProviderLock } from "../auth/oauth-provider-lock.js";
|
|
4
5
|
import { CredentialResolver, init_credentials } from "../auth/credentials.js";
|
|
5
|
-
import { getModelRegistry, init_model_registry } from "./model-registry.js";
|
|
6
6
|
import { getProviderAuthService, init_provider_auth_service } from "./provider-auth-service.js";
|
|
7
7
|
import { evictAllEmbeddedSessionRunners } from "../agent/embedded/session-runner.js";
|
|
8
8
|
//#region src/providers/provider-disconnect-core.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { getOAuthProviderDefinition, init_registry } from "../auth/oauth/registry.js";
|
|
3
2
|
import { init_provider_policy, isRetiredModelProvider } from "./provider-policy.js";
|
|
4
3
|
import { getModelCatalogStore, init_model_catalog_store } from "./model-catalog-store.js";
|
|
4
|
+
import { getOAuthProviderDefinition, init_registry } from "../auth/oauth/registry.js";
|
|
5
5
|
import { XOPC_CLOUD_PROVIDER_ID, init_xopc_cloud_config, resolveXopcModelRouterUrl } from "./xopc-cloud-config.js";
|
|
6
6
|
//#region src/providers/register-runtime-providers.ts
|
|
7
7
|
function registerRuntimeProvider(modelRuntime, source) {
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CloudAccountSummary, type CloudCreditBudget, type CloudBillingReceipt } from '@xopcai/gateway-contract';
|
|
2
2
|
import { type ProviderAuthService } from './provider-auth-service.js';
|
|
3
|
-
|
|
4
|
-
balance: z.ZodObject<{
|
|
5
|
-
credits: z.ZodNumber;
|
|
6
|
-
updatedAt: z.ZodString;
|
|
7
|
-
}, z.core.$strip>;
|
|
8
|
-
usage: z.ZodObject<{
|
|
9
|
-
days: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<7>, z.ZodLiteral<30>]>;
|
|
10
|
-
requests: z.ZodNumber;
|
|
11
|
-
inputTokens: z.ZodNumber;
|
|
12
|
-
outputTokens: z.ZodNumber;
|
|
13
|
-
totalTokens: z.ZodNumber;
|
|
14
|
-
errors: z.ZodNumber;
|
|
15
|
-
averageLatencyMs: z.ZodNumber;
|
|
16
|
-
chargedCredits: z.ZodNumber;
|
|
17
|
-
}, z.core.$strip>;
|
|
18
|
-
links: z.ZodObject<{
|
|
19
|
-
details: z.ZodString;
|
|
20
|
-
purchase: z.ZodString;
|
|
21
|
-
}, z.core.$strip>;
|
|
22
|
-
}, z.core.$strip>;
|
|
23
|
-
export type XopcCloudAccountSummary = z.infer<typeof accountSummarySchema>;
|
|
3
|
+
export type XopcCloudAccountSummary = CloudAccountSummary;
|
|
24
4
|
export declare class XopcCloudAccountError extends Error {
|
|
25
5
|
readonly status: number;
|
|
26
6
|
readonly code?: string;
|
|
@@ -35,6 +15,10 @@ export declare class XopcCloudAccountService {
|
|
|
35
15
|
routerUrl?: string;
|
|
36
16
|
credentials?: Pick<ProviderAuthService, 'resolveApiKey'>;
|
|
37
17
|
});
|
|
18
|
+
private request;
|
|
19
|
+
private parse;
|
|
38
20
|
getSummary(days?: 1 | 7 | 30): Promise<XopcCloudAccountSummary | null>;
|
|
21
|
+
createBudget(limitCreditMicro: string, key: string): Promise<CloudCreditBudget | null>;
|
|
22
|
+
getReceipt(requestId: string): Promise<CloudBillingReceipt | null>;
|
|
23
|
+
getBudget(id: string): Promise<CloudCreditBudget | null>;
|
|
39
24
|
}
|
|
40
|
-
export {};
|
|
@@ -1,33 +1,12 @@
|
|
|
1
|
+
import { cloudAccountSummarySchema, cloudBillingReceiptSchema, cloudCreditBudgetSchema, creditMicroSchema, creditUnitSchema } from "../../packages/gateway-contract/src/cloud-credits.js";
|
|
2
|
+
import { init_src } from "../../packages/gateway-contract/src/index.js";
|
|
1
3
|
import { init_xopc_cloud_config, resolveXopcModelRouterUrl } from "./xopc-cloud-config.js";
|
|
2
4
|
import { getProviderAuthService, init_provider_auth_service } from "./provider-auth-service.js";
|
|
3
5
|
import { z } from "zod";
|
|
4
6
|
//#region src/providers/xopc-cloud-account-service.ts
|
|
7
|
+
init_src();
|
|
5
8
|
init_provider_auth_service();
|
|
6
9
|
init_xopc_cloud_config();
|
|
7
|
-
const accountSummarySchema = z.object({
|
|
8
|
-
balance: z.object({
|
|
9
|
-
credits: z.number().int().nonnegative(),
|
|
10
|
-
updatedAt: z.string().datetime()
|
|
11
|
-
}),
|
|
12
|
-
usage: z.object({
|
|
13
|
-
days: z.union([
|
|
14
|
-
z.literal(1),
|
|
15
|
-
z.literal(7),
|
|
16
|
-
z.literal(30)
|
|
17
|
-
]),
|
|
18
|
-
requests: z.number().int().nonnegative(),
|
|
19
|
-
inputTokens: z.number().int().nonnegative(),
|
|
20
|
-
outputTokens: z.number().int().nonnegative(),
|
|
21
|
-
totalTokens: z.number().int().nonnegative(),
|
|
22
|
-
errors: z.number().int().nonnegative(),
|
|
23
|
-
averageLatencyMs: z.number().nonnegative(),
|
|
24
|
-
chargedCredits: z.number().int().nonnegative()
|
|
25
|
-
}),
|
|
26
|
-
links: z.object({
|
|
27
|
-
details: z.string().url(),
|
|
28
|
-
purchase: z.string().url()
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
10
|
var XopcCloudAccountError = class extends Error {
|
|
32
11
|
constructor(message, status, code) {
|
|
33
12
|
super(message);
|
|
@@ -45,22 +24,63 @@ var XopcCloudAccountService = class {
|
|
|
45
24
|
this.routerUrl = resolveXopcModelRouterUrl(options.routerUrl);
|
|
46
25
|
this.credentials = options.credentials ?? getProviderAuthService();
|
|
47
26
|
}
|
|
48
|
-
async
|
|
27
|
+
async request(path, init) {
|
|
49
28
|
const accessToken = await this.credentials.resolveApiKey("xopc-cloud");
|
|
50
29
|
if (!accessToken) return null;
|
|
51
|
-
const response = await this.fetchImpl(`${this.routerUrl}
|
|
30
|
+
const response = await this.fetchImpl(`${this.routerUrl}${path}`, {
|
|
31
|
+
...init,
|
|
52
32
|
headers: {
|
|
33
|
+
...Object.fromEntries(new Headers(init?.headers)),
|
|
53
34
|
authorization: `Bearer ${accessToken}`,
|
|
54
35
|
accept: "application/json"
|
|
55
36
|
},
|
|
56
|
-
signal: AbortSignal.timeout(3e4)
|
|
37
|
+
signal: AbortSignal.timeout(3e4),
|
|
38
|
+
redirect: "error"
|
|
57
39
|
});
|
|
58
40
|
const body = await response.json().catch(() => null);
|
|
59
41
|
if (!response.ok) throw new XopcCloudAccountError(typeof body?.error?.message === "string" ? body.error.message : `XOPC account summary failed (${response.status})`, response.status, typeof body?.error?.code === "string" ? body.error.code : void 0);
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
if (body === null) throw new XopcCloudAccountError("XOPC Cloud returned invalid JSON", 502, "invalid_response");
|
|
43
|
+
return body;
|
|
44
|
+
}
|
|
45
|
+
parse(schema, body) {
|
|
46
|
+
if (body === null) return null;
|
|
47
|
+
const parsed = schema.safeParse(body);
|
|
48
|
+
if (!parsed.success) throw new XopcCloudAccountError("XOPC Cloud returned an invalid Credit response", 502, "invalid_response");
|
|
62
49
|
return parsed.data;
|
|
63
50
|
}
|
|
51
|
+
async getSummary(days = 7) {
|
|
52
|
+
return this.parse(cloudAccountSummarySchema, await this.request(`/account/summary?version=2&days=${days}`));
|
|
53
|
+
}
|
|
54
|
+
async createBudget(limitCreditMicro, key) {
|
|
55
|
+
creditMicroSchema.parse(limitCreditMicro);
|
|
56
|
+
if (limitCreditMicro === "0" || limitCreditMicro.length > 15 || !/^[\w:.-]{8,128}$/.test(key)) throw new Error("Invalid Credit budget");
|
|
57
|
+
return this.parse(z.object({
|
|
58
|
+
creditUnit: creditUnitSchema,
|
|
59
|
+
budget: cloudCreditBudgetSchema
|
|
60
|
+
}), await this.request("/account/budgets", {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: {
|
|
63
|
+
"content-type": "application/json",
|
|
64
|
+
"Idempotency-Key": key
|
|
65
|
+
},
|
|
66
|
+
body: JSON.stringify({ limitCreditMicro })
|
|
67
|
+
}))?.budget ?? null;
|
|
68
|
+
}
|
|
69
|
+
async getReceipt(requestId) {
|
|
70
|
+
z.string().min(1).max(128).parse(requestId);
|
|
71
|
+
return this.parse(z.object({
|
|
72
|
+
schemaVersion: z.literal(2),
|
|
73
|
+
creditUnit: creditUnitSchema,
|
|
74
|
+
receipt: cloudBillingReceiptSchema
|
|
75
|
+
}), await this.request(`/account/receipts/${encodeURIComponent(requestId)}`))?.receipt ?? null;
|
|
76
|
+
}
|
|
77
|
+
async getBudget(id) {
|
|
78
|
+
z.string().uuid().parse(id);
|
|
79
|
+
return this.parse(z.object({
|
|
80
|
+
creditUnit: creditUnitSchema,
|
|
81
|
+
budget: cloudCreditBudgetSchema
|
|
82
|
+
}), await this.request(`/account/budgets/${encodeURIComponent(id)}`))?.budget ?? null;
|
|
83
|
+
}
|
|
64
84
|
};
|
|
65
85
|
//#endregion
|
|
66
86
|
export { XopcCloudAccountError, XopcCloudAccountService };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createLogger } from "../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
|
-
import { init_oauth_provider_lock, withOAuthProviderLock } from "../auth/oauth-provider-lock.js";
|
|
4
3
|
import { ModelCatalogPersistence, init_model_catalog_persistence } from "./model-catalog-persistence.js";
|
|
5
4
|
import { getModelCatalogStore, init_model_catalog_store } from "./model-catalog-store.js";
|
|
6
5
|
import { getModelRegistry, init_model_registry } from "./model-registry.js";
|
|
6
|
+
import { init_oauth_provider_lock, withOAuthProviderLock } from "../auth/oauth-provider-lock.js";
|
|
7
7
|
import { reloadImageGenerationProviders } from "../agent/image/generation/provider-registry.js";
|
|
8
8
|
import { disconnectProviderCore } from "./provider-disconnect-core.js";
|
|
9
9
|
import { XopcCloudModelSource } from "./xopc-cloud-model-source.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XopcCloudAccountService } from './xopc-cloud-account-service.js';
|
|
2
|
+
export declare function hasCloudCreditBudget(): boolean;
|
|
3
|
+
export declare function cloudCreditBudgetStopMessage(): string | undefined;
|
|
4
|
+
export declare function isCloudCreditBudgetExhausted(message: string): boolean;
|
|
5
|
+
export declare function reportCloudCreditError(message: string): void;
|
|
6
|
+
export declare function assertCloudCreditBudgetActive(): void;
|
|
7
|
+
/** Children inherit their parent's scope; repeated attempts use the same platform budget. */
|
|
8
|
+
export declare function withCloudCreditBudget<T>(options: {
|
|
9
|
+
conversationId: string;
|
|
10
|
+
runId: string;
|
|
11
|
+
limitCreditMicro?: string;
|
|
12
|
+
}, action: () => Promise<T>): Promise<T>;
|
|
13
|
+
export declare function cloudCreditBudgetHeaders(service?: Pick<XopcCloudAccountService, 'createBudget'>): Promise<Record<string, string>>;
|
|
14
|
+
export declare function rejectUnbudgetedCloudTransport(operation?: string): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createLogger } from "../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { XopcCloudAccountService } from "./xopc-cloud-account-service.js";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
//#region src/providers/xopc-cloud-credit-budget.ts
|
|
7
|
+
init_logger();
|
|
8
|
+
const log = createLogger("CloudCreditBudget");
|
|
9
|
+
const scopes = new AsyncLocalStorage();
|
|
10
|
+
const EXHAUSTED = /credit_budget_exhausted|(?:task Credit|Credit task) budget exhausted/i;
|
|
11
|
+
function hasCloudCreditBudget() {
|
|
12
|
+
return Boolean(scopes.getStore());
|
|
13
|
+
}
|
|
14
|
+
function cloudCreditBudgetStopMessage() {
|
|
15
|
+
return scopes.getStore()?.stopped;
|
|
16
|
+
}
|
|
17
|
+
function isCloudCreditBudgetExhausted(message) {
|
|
18
|
+
return EXHAUSTED.test(message);
|
|
19
|
+
}
|
|
20
|
+
function reportCloudCreditError(message) {
|
|
21
|
+
const scope = scopes.getStore();
|
|
22
|
+
if (scope && isCloudCreditBudgetExhausted(message)) scope.stopped = "credit_budget_exhausted: Credit task budget exhausted";
|
|
23
|
+
}
|
|
24
|
+
function assertCloudCreditBudgetActive() {
|
|
25
|
+
const stopped = scopes.getStore()?.stopped;
|
|
26
|
+
if (stopped) throw new Error(stopped);
|
|
27
|
+
}
|
|
28
|
+
/** Children inherit their parent's scope; repeated attempts use the same platform budget. */
|
|
29
|
+
async function withCloudCreditBudget(options, action) {
|
|
30
|
+
if (scopes.getStore() || !options.limitCreditMicro) return action();
|
|
31
|
+
const key = `xopc-run:${createHash("sha256").update(JSON.stringify([options.conversationId, options.runId])).digest("hex")}`;
|
|
32
|
+
return scopes.run({
|
|
33
|
+
key,
|
|
34
|
+
conversationId: options.conversationId,
|
|
35
|
+
runId: options.runId,
|
|
36
|
+
limitCreditMicro: options.limitCreditMicro
|
|
37
|
+
}, action);
|
|
38
|
+
}
|
|
39
|
+
async function cloudCreditBudgetHeaders(service) {
|
|
40
|
+
assertCloudCreditBudgetActive();
|
|
41
|
+
const scope = scopes.getStore();
|
|
42
|
+
if (!scope) return {};
|
|
43
|
+
scope.budget ??= (service ?? new XopcCloudAccountService()).createBudget(scope.limitCreditMicro, scope.key).then((budget) => {
|
|
44
|
+
if (budget) log.info({
|
|
45
|
+
conversationId: scope.conversationId,
|
|
46
|
+
runId: scope.runId,
|
|
47
|
+
creditBudgetId: budget.id,
|
|
48
|
+
limitCreditMicro: budget.limitCreditMicro
|
|
49
|
+
}, "Created Cloud run Credit budget");
|
|
50
|
+
return budget;
|
|
51
|
+
});
|
|
52
|
+
const budget = await scope.budget;
|
|
53
|
+
if (!budget) throw new Error("XOPC Cloud authorization is unavailable");
|
|
54
|
+
assertCloudCreditBudgetActive();
|
|
55
|
+
return { "x-xopc-credit-budget": budget.id };
|
|
56
|
+
}
|
|
57
|
+
function rejectUnbudgetedCloudTransport(operation = "realtime voice") {
|
|
58
|
+
if (scopes.getStore()) throw new Error(`Credit run budgets do not support ${operation} yet`);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { assertCloudCreditBudgetActive, cloudCreditBudgetHeaders, cloudCreditBudgetStopMessage, hasCloudCreditBudget, isCloudCreditBudgetExhausted, rejectUnbudgetedCloudTransport, reportCloudCreditError, withCloudCreditBudget };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AiUsageEvent, AiUsageFinish } from '../../usage/types.js';
|
|
2
|
+
import type { CloudBillingReceipt, UsageBilling, UsageTotals } from '@xopcai/gateway-contract';
|
|
2
3
|
export declare const AI_USAGE_RETENTION_MS: number;
|
|
3
4
|
export declare function insertAiUsageEvent(event: AiUsageEvent): void;
|
|
4
5
|
export declare function finishAiUsageEvent(id: string, finish: AiUsageFinish & {
|
|
@@ -7,6 +8,8 @@ export declare function finishAiUsageEvent(id: string, finish: AiUsageFinish & {
|
|
|
7
8
|
export declare function markStaleAiUsageEventsUnknown(cutoffMs: number, now?: number): number;
|
|
8
9
|
export declare function pruneAiUsageEvents(cutoffMs: number): number;
|
|
9
10
|
export declare function getAiUsageEvent(id: string): Record<string, unknown> | undefined;
|
|
11
|
+
export declare function setAiUsageCloudRequest(id: string, requestId: string): void;
|
|
12
|
+
export declare function setAiUsageCloudReceipt(id: string, receipt: CloudBillingReceipt): void;
|
|
10
13
|
export type AiUsageQuery = {
|
|
11
14
|
from: number;
|
|
12
15
|
to: number;
|
|
@@ -16,6 +19,8 @@ export type AiUsageQuery = {
|
|
|
16
19
|
agentId?: string;
|
|
17
20
|
conversationId?: string;
|
|
18
21
|
};
|
|
22
|
+
export declare function pendingAiUsageCloudReceiptIds(query: AiUsageQuery): string[];
|
|
23
|
+
export declare function markAiUsageCloudReceiptAttempt(id: string): void;
|
|
19
24
|
export type AiUsageTotals = {
|
|
20
25
|
calls: number;
|
|
21
26
|
succeededCalls: number;
|
|
@@ -28,6 +33,7 @@ export type AiUsageTotals = {
|
|
|
28
33
|
totalTokens: number;
|
|
29
34
|
knownCostUsd: string;
|
|
30
35
|
costCompleteness: 'complete' | 'partial' | 'unknown';
|
|
36
|
+
billing: NonNullable<UsageTotals['billing']>;
|
|
31
37
|
};
|
|
32
38
|
export type ConversationAiUsageTotals = Pick<AiUsageTotals, 'calls' | 'unknownCostCalls' | 'totalTokens' | 'knownCostUsd' | 'costCompleteness'>;
|
|
33
39
|
/** Aggregate all retained AI usage records for the requested conversations. */
|
|
@@ -78,6 +84,7 @@ export declare function listAiUsageEvents(query: AiUsageQuery & {
|
|
|
78
84
|
reasoningTokens: number;
|
|
79
85
|
totalTokens: number;
|
|
80
86
|
estimatedCostUsd: string;
|
|
87
|
+
billing: UsageBilling;
|
|
81
88
|
costSource: string;
|
|
82
89
|
pricingSnapshot: Record<string, number>;
|
|
83
90
|
errorSummary: string;
|
|
@@ -110,6 +117,7 @@ export declare function getAiUsageEventView(id: string): {
|
|
|
110
117
|
reasoningTokens: number;
|
|
111
118
|
totalTokens: number;
|
|
112
119
|
estimatedCostUsd: string;
|
|
120
|
+
billing: UsageBilling;
|
|
113
121
|
costSource: string;
|
|
114
122
|
pricingSnapshot: Record<string, number>;
|
|
115
123
|
errorSummary: string;
|
|
@@ -140,6 +148,7 @@ export declare function listAiUsageTrace(traceId: string): {
|
|
|
140
148
|
reasoningTokens: number;
|
|
141
149
|
totalTokens: number;
|
|
142
150
|
estimatedCostUsd: string;
|
|
151
|
+
billing: UsageBilling;
|
|
143
152
|
costSource: string;
|
|
144
153
|
pricingSnapshot: Record<string, number>;
|
|
145
154
|
errorSummary: string;
|