@xopcai/xopc 0.0.170 → 0.0.172
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-CkUp1qvf.js → activity-store-C3Y-bESI.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DDuem4HM.js → agent-avatar-dicebear-CPyev9P7.js} +1 -1
- package/dist/gateway/static/root/assets/agents-Bf_kK2Ay.js +2 -0
- package/dist/gateway/static/root/assets/{api-BnuPQhJW.js → api-B7qEr_Rw.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-DdZw8Hi1.js → app-management-settings-panel-Br_9-7fs.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BN8Vk2bX.js → appearance-settings-uyLcRPai.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-DXFCP5-1.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-C82MaDQj.js → archive-plugin-B19REnR5.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-uilrwSdW.js → attachment-load-DLWCC4Yi.js} +1 -1
- package/dist/gateway/static/root/assets/{automation-suggestion-card-CkDZjAmy.js → automation-suggestion-card-ky5S5lly.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-D8pT1o2O.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-B7NTL0_T.js → binary-plugins-CtPEzLlo.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-D_LDNlB-.js → block-editor-CQVR4Xij.js} +32 -32
- package/dist/gateway/static/root/assets/browser-settings-page-Bav_skKN.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-UFVUzn4v.js → browser-workflow-inputs-CimCGbhq.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CGgC0N92.js → browser-workflows-page-DewuCw3p.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-BHaYYo9E.js +7 -0
- package/dist/gateway/static/root/assets/{capability-presets-api-DUIorGUd.js → capability-presets-api-B5RTs-Az.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-settings-panel-PTz00nR4.js → capability-presets-settings-panel-BgchTh81.js} +1 -1
- package/dist/gateway/static/root/assets/{channel-recipient-api-BYwSB8c6.js → channel-recipient-api-Czu0YzIZ.js} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-BP0e62wt.js +1 -0
- package/dist/gateway/static/root/assets/channels-status-swr-DBWKfeGe.js +1 -0
- package/dist/gateway/static/root/assets/connector-logo-Di3gnR_D.js +1 -0
- package/dist/gateway/static/root/assets/connectors-page-CC5kh0de.js +2 -0
- package/dist/gateway/static/root/assets/{desktop-pet-CkT98fPT.js → desktop-pet-D-ZUNHhn.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-DkbIzdA3.js → desktop-pet-settings-C3L6AI8_.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-dBQvj1sG.js → directory-picker-path-field-Dvq4iG6P.js} +1 -1
- package/dist/gateway/static/root/assets/dreaming-settings-D9i54kWO.js +3 -0
- package/dist/gateway/static/root/assets/{extension-debug-page-BfxoIiNo.js → extension-debug-page-BecQjU0J.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-EIJ3wIb7.js → extension-page-BeVkPSm-.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-DBBec51N.js → extension-settings-page-DMoo2mKx.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-4_u53Ufq.js → gateway-config-api-Bthb3_6v.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-v9kJM59H.js → gateway-settings-Bh8nPvJQ.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CXITih5d.js → gateway-startup-retry-D3USVm9D.js} +1 -1
- package/dist/gateway/static/root/assets/goal-create-dialog-Dp0AyDHI.js +1 -0
- package/dist/gateway/static/root/assets/goal-detail-page-CNt7nrdS.js +4 -0
- package/dist/gateway/static/root/assets/{goals-config-api-D54YQPon.js → goals-config-api-C_2QWBtb.js} +1 -1
- package/dist/gateway/static/root/assets/goals-page-Bm_NZFiZ.js +2 -0
- package/dist/gateway/static/root/assets/{goals-settings-DDezXaVi.js → goals-settings-DhL643tc.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-CRsIUeZN.js → heartbeat-settings-COVFwp7C.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-CY6cQUHL.js → image-generation-api-BNQlnwpU.js} +1 -1
- package/dist/gateway/static/root/assets/index-C_XSKOH6.css +1 -0
- package/dist/gateway/static/root/assets/{index-Dfq2laZe.js → index-DUasAutC.js} +67 -67
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D9k7EDdY.js → keyboard-shortcuts-settings-DfdJRJVy.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-DZwkD1co.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-DbaiBolh.js → local-apps-page-BvCPOgoi.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-Dqp9H2Uf.js → locale-store-BP0vD37A.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-DoCY0Mm9.js → logs-page-dNL0Y1dA.js} +3 -3
- package/dist/gateway/static/root/assets/{markdown-split-BGlQR-Be.js → markdown-split-YO1rDk9m.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-BpaeV6f_.js → media-plugins-CU_RRf-q.js} +1 -1
- package/dist/gateway/static/root/assets/messages-BWtP5TFz.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-Cd2HpciM.js → notes-page-CeFiOK3S.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-B8MKxpZb.js +4 -0
- package/dist/gateway/static/root/assets/{page-tabs-DyimBUp_.js → page-tabs-tiHmRJUA.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-BKZulEYr.js → preview-open-alternatives-CU6XgaCz.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-Bjz9BxBY.js → product-open-page-Dn4_qor4.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-CWBuuX-S.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-BJSsLsXH.js +1 -0
- package/dist/gateway/static/root/assets/remote-access-hub-DXJDb8vB.js +1 -0
- package/dist/gateway/static/root/assets/{save-bar-controls-BPTqb2_r.js → save-bar-controls-edDUIbXo.js} +1 -1
- package/dist/gateway/static/root/assets/{schedule-field-YN0D81Dk.js → schedule-field-DqJO_5Yb.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-BmY5PSS2.js → schema-form-CMh0jzy5.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-DeHpWgxM.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-Cf-TEYUd.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-B-RhgD_p.js → settings-form-section-Bb0Bc3nJ.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-DkPupX2B.js → settings-loading-skeleton-DQhADvz1.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-2QBMvaxj.js → settings-page-b0M5HukN.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-CtrW-LD6.js → settings-page-layout-hvjtIjvh.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BFyfed_g.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-BezIW1n9.js → share-preview-page-rbeaOpTg.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-CYnH9sTt.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-Cr8_m-jS.js +1 -0
- package/dist/gateway/static/root/assets/skills-page-Chtc1xDO.js +2 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-WAFhKyAu.js → system-settings-panel-BHo_hgnL.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BiC0gIBa.js → theme-store-C3KnnjcU.js} +1 -1
- package/dist/gateway/static/root/assets/time-picker-D-G-uwVJ.js +1 -0
- package/dist/gateway/static/root/assets/{typed-models-lib-WAQO3F_8.js → typed-models-lib-DtRnG-YI.js} +1 -1
- package/dist/gateway/static/root/assets/{use-channel-catalog-CKlfsSeU.js → use-channel-catalog-CWWItX2g.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-D7qMR26X.js +1 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-BAFHF0_v.js → voice-api-key-field-BTnltQHZ.js} +1 -1
- package/dist/gateway/static/root/assets/work-discovery-page-CpqFZze9.js +1 -0
- package/dist/gateway/static/root/assets/work-item-detail-page-t4dXpGC0.js +1 -0
- package/dist/gateway/static/root/assets/work-page-BXwDKiMZ.js +1 -0
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-1OP4HyvS.js → workflow-run-setup-panel-D7vKChFZ.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-Bos9HyqT.js +11 -0
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/src/agent/embedded/run-for-session.js +71 -24
- package/dist/src/agent/embedded/run-turn.js +68 -4
- package/dist/src/agent/inbound/inbound-loop.d.ts +0 -2
- package/dist/src/agent/inbound/inbound-loop.js +0 -2
- package/dist/src/agent/memory/builtin-provider.js +4 -4
- package/dist/src/agent/memory/compaction-planner.d.ts +16 -0
- package/dist/src/agent/memory/compaction-planner.js +152 -0
- package/dist/src/agent/memory/compaction-policy.d.ts +10 -0
- package/dist/src/agent/memory/compaction-policy.js +24 -0
- package/dist/src/agent/memory/compaction.d.ts +21 -22
- package/dist/src/agent/memory/compaction.js +220 -194
- package/dist/src/agent/memory/context-budget.d.ts +40 -0
- package/dist/src/agent/memory/context-budget.js +106 -0
- package/dist/src/agent/memory/manager.d.ts +4 -1
- package/dist/src/agent/memory/manager.js +8 -3
- package/dist/src/agent/memory/understanding/service.d.ts +2 -0
- package/dist/src/agent/memory/understanding/service.js +11 -9
- package/dist/src/agent/orchestration/context-overflow.d.ts +1 -0
- package/dist/src/agent/orchestration/context-overflow.js +19 -0
- package/dist/src/agent/orchestration/loop-guard.js +13 -9
- package/dist/src/agent/reply/post-compaction-context.d.ts +4 -0
- package/dist/src/agent/reply/post-compaction-context.js +5 -3
- package/dist/src/agent/service/process-direct-one-shot.js +1 -2
- package/dist/src/agent/service/process-direct-streaming.js +1 -2
- package/dist/src/agent/service.d.ts +1 -2
- package/dist/src/agent/service.js +16 -44
- package/dist/src/agent/session/session-inspector.js +10 -2
- package/dist/src/automations/domain/validation.d.ts +8 -8
- package/dist/src/automations/draft/automation-draft-validator.d.ts +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/config/schema.d.ts +17 -1
- package/dist/src/connectors/composio-sessions.d.ts +1 -0
- package/dist/src/connectors/composio-sessions.js +14 -5
- package/dist/src/connectors/composio-triggers.d.ts +1 -1
- package/dist/src/connectors/composio-triggers.js +4 -3
- package/dist/src/connectors/composio.js +1 -0
- package/dist/src/connectors/{connector-memory-sync.d.ts → connected-source-ingestion.d.ts} +11 -4
- package/dist/src/connectors/{connector-memory-sync.js → connected-source-ingestion.js} +49 -101
- package/dist/src/connectors/connected-source-normalizers.d.ts +15 -0
- package/dist/src/connectors/connected-source-normalizers.js +186 -0
- package/dist/src/connectors/connector-identity.d.ts +2 -0
- package/dist/src/connectors/connector-identity.js +29 -0
- package/dist/src/connectors/learning-coordinator.d.ts +25 -0
- package/dist/src/connectors/learning-coordinator.js +214 -0
- package/dist/src/connectors/learning-recipes.d.ts +22 -0
- package/dist/src/connectors/learning-recipes.js +121 -0
- package/dist/src/connectors/runtime-status.d.ts +1 -8
- package/dist/src/connectors/runtime-status.js +4 -29
- package/dist/src/gateway/hono/lib/config-payload.d.ts +23 -0
- package/dist/src/gateway/hono/lib/config-payload.js +3 -0
- package/dist/src/gateway/hono/routes/config-patch/misc.d.ts +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +28 -0
- package/dist/src/gateway/hono/routes/connectors.js +76 -118
- package/dist/src/gateway/hono/routes/models.js +24 -0
- package/dist/src/gateway/hono/routes/public-gateway.js +3 -2
- package/dist/src/gateway/hono/routes/sessions.js +17 -42
- package/dist/src/gateway/hono/routes/you.js +86 -5
- package/dist/src/gateway/service/sessions-api.d.ts +2 -3
- package/dist/src/gateway/service/sessions-api.js +4 -7
- package/dist/src/gateway/service.d.ts +5 -2
- package/dist/src/gateway/service.js +16 -11
- package/dist/src/knowledge/connected-understanding-pipeline.d.ts +19 -0
- package/dist/src/knowledge/connected-understanding-pipeline.js +268 -0
- package/dist/src/knowledge/index.d.ts +1 -0
- package/dist/src/knowledge/index.js +2 -1
- package/dist/src/knowledge/ingestion-service.d.ts +6 -4
- package/dist/src/knowledge/ingestion-service.js +13 -10
- package/dist/src/knowledge/local-folder-adapter.js +1 -0
- package/dist/src/knowledge/people-graph.js +43 -110
- package/dist/src/knowledge/types.d.ts +3 -0
- package/dist/src/providers/xopc-cloud-account-service.d.ts +40 -0
- package/dist/src/providers/xopc-cloud-account-service.js +65 -0
- package/dist/src/session/index.d.ts +1 -2
- package/dist/src/session/index.js +1 -2
- package/dist/src/session/init-session-turn.d.ts +0 -1
- package/dist/src/session/init-session-turn.js +1 -2
- package/dist/src/session/manager.d.ts +11 -17
- package/dist/src/session/manager.js +11 -14
- package/dist/src/session/session-context-for-llm.d.ts +19 -1
- package/dist/src/session/session-context-for-llm.js +87 -129
- package/dist/src/session/store.d.ts +28 -23
- package/dist/src/session/store.js +94 -83
- package/dist/src/session/transcript-format.d.ts +2 -8
- package/dist/src/session/types.d.ts +8 -6
- package/dist/src/session/user-round-delete.d.ts +3 -6
- package/dist/src/session/user-round-delete.js +12 -16
- package/dist/src/storage/sqlite/connector-learning-repository.d.ts +47 -0
- package/dist/src/storage/sqlite/connector-learning-repository.js +110 -0
- package/dist/src/storage/sqlite/index.d.ts +4 -2
- package/dist/src/storage/sqlite/index.js +5 -3
- package/dist/src/storage/sqlite/knowledge-repository.d.ts +4 -2
- package/dist/src/storage/sqlite/knowledge-repository.js +24 -13
- package/dist/src/storage/sqlite/migrations/060_remove_runtime_transcript_messages.sql +45 -0
- package/dist/src/storage/sqlite/migrations/061_drop_compaction_checkpoints.sql +2 -0
- package/dist/src/storage/sqlite/migrations/062_connector_learning_jobs.sql +27 -0
- package/dist/src/storage/sqlite/migrations/063_knowledge_collection_scopes.sql +14 -0
- package/dist/src/storage/sqlite/migrations/064_user_claims.sql +60 -0
- package/dist/src/storage/sqlite/migrations/065_knowledge_item_scope_identity.sql +116 -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/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/schema.sql +0 -19
- package/dist/src/storage/sqlite/transcript-repository.d.ts +6 -11
- package/dist/src/storage/sqlite/transcript-repository.js +90 -84
- package/dist/src/storage/sqlite/user-claims-repository.d.ts +101 -0
- package/dist/src/storage/sqlite/user-claims-repository.js +241 -0
- package/dist/src/user-context/config.d.ts +67 -2
- package/dist/src/user-context/config.js +36 -3
- package/dist/src/user-context/projection.d.ts +36 -1
- package/dist/src/user-context/projection.js +84 -6
- package/dist/src/work-discovery/service.js +1 -0
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/agents-BiaQhiQp.js +0 -2
- package/dist/gateway/static/root/assets/apps-page-CuL8Q4yF.js +0 -1
- package/dist/gateway/static/root/assets/automations-page-TZOluRNp.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-C-l6O68Z.js +0 -8
- package/dist/gateway/static/root/assets/capabilities-settings-panel-BW8c0xPp.js +0 -7
- package/dist/gateway/static/root/assets/channels-settings-h9CsE0GT.js +0 -1
- package/dist/gateway/static/root/assets/channels-status-swr-C058Mcfr.js +0 -1
- package/dist/gateway/static/root/assets/connector-logo-CsbegNqi.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-BWALafGW.js +0 -2
- package/dist/gateway/static/root/assets/dreaming-settings-DkdnKMZx.js +0 -3
- package/dist/gateway/static/root/assets/goal-create-dialog-y2Y3p7_k.js +0 -1
- package/dist/gateway/static/root/assets/goal-detail-page-DuzL-alv.js +0 -4
- package/dist/gateway/static/root/assets/goals-page-OeLtfKI2.js +0 -2
- package/dist/gateway/static/root/assets/index-o4uaOGKT.css +0 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-3ssYIEK6.js +0 -2
- package/dist/gateway/static/root/assets/messages-KEk-hTFt.js +0 -3
- package/dist/gateway/static/root/assets/notes-workbench-CatZNAPc.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-DJUOgqm4.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-BQQAD_nu.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-fIGXTTnA.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-BuU-8FCe.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-DlKoeZm3.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-BSUcDFnb.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-Bk2-SwGJ.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-e_Fx1kVC.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-D_cCADfj.js +0 -2
- package/dist/gateway/static/root/assets/time-picker-fqRXpNJV.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-9Ov4htPW.js +0 -1
- package/dist/gateway/static/root/assets/work-discovery-page-DGN2FxWv.js +0 -1
- package/dist/gateway/static/root/assets/work-item-detail-page-HmyWSgUo.js +0 -1
- package/dist/gateway/static/root/assets/work-page-D3iKVjFq.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-B5L4SFw4.js +0 -11
- package/dist/src/agent/lifecycle/handlers/compaction.d.ts +0 -13
- package/dist/src/agent/lifecycle/handlers/compaction.js +0 -18
- package/dist/src/connectors/memory-sync-coordinator.d.ts +0 -28
- package/dist/src/connectors/memory-sync-coordinator.js +0 -162
- package/dist/src/connectors/memory-sync-profile.d.ts +0 -13
- package/dist/src/connectors/memory-sync-profile.js +0 -73
- package/dist/src/session/compaction-checkpoints.d.ts +0 -8
- package/dist/src/session/compaction-checkpoints.js +0 -19
|
@@ -8,6 +8,7 @@ export type KnowledgeChangeKind = 'added' | 'modified' | 'deleted';
|
|
|
8
8
|
export interface KnowledgeSourceItem {
|
|
9
9
|
id: string;
|
|
10
10
|
sourceInstanceId: string;
|
|
11
|
+
collectionScope: string;
|
|
11
12
|
externalId: string;
|
|
12
13
|
itemType: string;
|
|
13
14
|
authorRole?: KnowledgeAuthorRole;
|
|
@@ -42,6 +43,7 @@ export interface KnowledgeSourceChange {
|
|
|
42
43
|
export interface KnowledgeSourceItemInput {
|
|
43
44
|
id?: string;
|
|
44
45
|
sourceInstanceId: string;
|
|
46
|
+
collectionScope: string;
|
|
45
47
|
externalId: string;
|
|
46
48
|
itemType: string;
|
|
47
49
|
authorRole?: KnowledgeAuthorRole;
|
|
@@ -73,6 +75,7 @@ export interface KnowledgeSyncRun {
|
|
|
73
75
|
}
|
|
74
76
|
export interface KnowledgePullInput {
|
|
75
77
|
instanceId: string;
|
|
78
|
+
collectionScope: string;
|
|
76
79
|
cursor?: string;
|
|
77
80
|
windowStart?: string;
|
|
78
81
|
signal: AbortSignal;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type CredentialResolver } from '../auth/credentials.js';
|
|
3
|
+
declare const accountSummarySchema: z.ZodObject<{
|
|
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>;
|
|
24
|
+
export declare class XopcCloudAccountError extends Error {
|
|
25
|
+
readonly status: number;
|
|
26
|
+
readonly code?: string;
|
|
27
|
+
constructor(message: string, status: number, code?: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class XopcCloudAccountService {
|
|
30
|
+
private readonly fetchImpl;
|
|
31
|
+
private readonly routerUrl;
|
|
32
|
+
private readonly credentials;
|
|
33
|
+
constructor(options?: {
|
|
34
|
+
fetchImpl?: typeof fetch;
|
|
35
|
+
routerUrl?: string;
|
|
36
|
+
credentials?: Pick<CredentialResolver, 'resolveApiKey'>;
|
|
37
|
+
});
|
|
38
|
+
getSummary(days?: 1 | 7 | 30): Promise<XopcCloudAccountSummary | null>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getCredentialResolver, init_credentials } from "../auth/credentials.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/providers/xopc-cloud-account-service.ts
|
|
4
|
+
init_credentials();
|
|
5
|
+
const DEFAULT_ROUTER_URL = "https://router.xopc.ai/v1";
|
|
6
|
+
const accountSummarySchema = z.object({
|
|
7
|
+
balance: z.object({
|
|
8
|
+
credits: z.number().int().nonnegative(),
|
|
9
|
+
updatedAt: z.string().datetime()
|
|
10
|
+
}),
|
|
11
|
+
usage: z.object({
|
|
12
|
+
days: z.union([
|
|
13
|
+
z.literal(1),
|
|
14
|
+
z.literal(7),
|
|
15
|
+
z.literal(30)
|
|
16
|
+
]),
|
|
17
|
+
requests: z.number().int().nonnegative(),
|
|
18
|
+
inputTokens: z.number().int().nonnegative(),
|
|
19
|
+
outputTokens: z.number().int().nonnegative(),
|
|
20
|
+
totalTokens: z.number().int().nonnegative(),
|
|
21
|
+
errors: z.number().int().nonnegative(),
|
|
22
|
+
averageLatencyMs: z.number().nonnegative(),
|
|
23
|
+
chargedCredits: z.number().int().nonnegative()
|
|
24
|
+
}),
|
|
25
|
+
links: z.object({
|
|
26
|
+
details: z.string().url(),
|
|
27
|
+
purchase: z.string().url()
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
var XopcCloudAccountError = class extends Error {
|
|
31
|
+
constructor(message, status, code) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.name = "XopcCloudAccountError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var XopcCloudAccountService = class {
|
|
39
|
+
fetchImpl;
|
|
40
|
+
routerUrl;
|
|
41
|
+
credentials;
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
44
|
+
this.routerUrl = (options.routerUrl ?? process.env.XOPC_MODEL_ROUTER_URL ?? DEFAULT_ROUTER_URL).replace(/\/+$/, "");
|
|
45
|
+
this.credentials = options.credentials ?? getCredentialResolver();
|
|
46
|
+
}
|
|
47
|
+
async getSummary(days = 7) {
|
|
48
|
+
const accessToken = await this.credentials.resolveApiKey("xopc-cloud");
|
|
49
|
+
if (!accessToken) return null;
|
|
50
|
+
const response = await this.fetchImpl(`${this.routerUrl}/account/summary?days=${days}`, {
|
|
51
|
+
headers: {
|
|
52
|
+
authorization: `Bearer ${accessToken}`,
|
|
53
|
+
accept: "application/json"
|
|
54
|
+
},
|
|
55
|
+
signal: AbortSignal.timeout(3e4)
|
|
56
|
+
});
|
|
57
|
+
const body = await response.json().catch(() => null);
|
|
58
|
+
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);
|
|
59
|
+
const parsed = accountSummarySchema.safeParse(body);
|
|
60
|
+
if (!parsed.success) throw new XopcCloudAccountError("XOPC account summary returned an invalid response", response.status, "invalid_response");
|
|
61
|
+
return parsed.data;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { XopcCloudAccountError, XopcCloudAccountService };
|
|
@@ -6,8 +6,7 @@ export { SessionConfigStore, resolveThinkingLevel, resolveReasoningLevel, resolv
|
|
|
6
6
|
export { resolveEffectiveThinkingLevel, resolveEffectiveReasoningLevel } from './thinking-resolve.js';
|
|
7
7
|
export type { SessionAgentConfig } from './config-types.js';
|
|
8
8
|
export { normalizeWorkingDirectoryInput, effectiveWorkspacePathForSession, projectWorkspacePath, } from './session-workspace.js';
|
|
9
|
-
export { SessionStatus, type SessionMetadata, type SessionDetail, type SessionListQuery, type PaginatedResult, type SessionStats, type ExportFormat, type SessionExport, type SessionTranscriptSummary, type
|
|
10
|
-
export { normalizeCompactionCheckpointId } from './compaction-checkpoints.js';
|
|
9
|
+
export { SessionStatus, type SessionMetadata, type SessionDetail, type SessionListQuery, type PaginatedResult, type SessionStats, type ExportFormat, type SessionExport, type SessionTranscriptSummary, type CompactionBoundarySummary, } from './types.js';
|
|
11
10
|
export { shouldSkipWebchatInboundByAbortCutoff } from './abort-cutoff.js';
|
|
12
11
|
export { DEFAULT_RESET_AT_HOUR, DEFAULT_RESET_MODE, DEFAULT_IDLE_MINUTES, evaluateSessionFreshness, resolveDailyResetAtMs, resolveSessionResetPolicy, type SessionFreshness, type SessionResetConfig, type SessionResetMode, type SessionResetPolicy, type SessionResetType, } from './reset-policy.js';
|
|
13
12
|
export { resolveChannelResetConfig, resolveSessionResetType, } from './reset-type.js';
|
|
@@ -3,7 +3,6 @@ import { buildSessionContextForLlm, isTranscriptContextEntry, mergeLlmMessagesPr
|
|
|
3
3
|
import { effectiveWorkspacePathForSession, normalizeWorkingDirectoryInput, projectWorkspacePath } from "./session-workspace.js";
|
|
4
4
|
import { emitSessionTranscriptUpdate, onSessionTranscriptUpdate } from "./transcript-events.js";
|
|
5
5
|
import { fallbackTitleFromMessages, generateSessionTitleFromMessages, getSessionTitleSource, isWebchatSessionKey, maybeRefineSessionTitleWithLlm, maybeSetProvisionalSessionTitle, provisionalTitleFromUserText, sanitizeGeneratedSessionTitle, sanitizeSessionTitle, shouldAutoTitleSessionKey, shouldRefineSessionTitleWithLlm } from "./session-title.js";
|
|
6
|
-
import { normalizeCompactionCheckpointId } from "./compaction-checkpoints.js";
|
|
7
6
|
import { flattenMessageContent, messagesToClientHistory } from "./client-history.js";
|
|
8
7
|
import { SessionStore } from "./store.js";
|
|
9
8
|
import { applySessionPatchToMetadata } from "./patch-metadata.js";
|
|
@@ -18,4 +17,4 @@ import { resolveSession, resolveSessionKeyForRequest } from "./resolve-session.j
|
|
|
18
17
|
import { DEFAULT_RESET_TRIGGERS, RESET_OVERLAP_COMMANDS, bareResetAckMessage, matchResetTriggers, resolveResetTriggers, shouldSkipResetOverlapCommand, stripLeadingEnvelopeTimestamp } from "./reset-triggers.js";
|
|
19
18
|
import { initSessionTurn } from "./init-session-turn.js";
|
|
20
19
|
import { CURRENT_SESSION_TRANSCRIPT_VERSION, XOPC_SESSION_TRANSCRIPT_TYPE } from "./transcript-format.js";
|
|
21
|
-
export { CURRENT_SESSION_TRANSCRIPT_VERSION, DEFAULT_IDLE_MINUTES, DEFAULT_RESET_AT_HOUR, DEFAULT_RESET_MODE, DEFAULT_RESET_TRIGGERS, RESET_OVERLAP_COMMANDS, SessionConfigStore, SessionIndex, SessionStatus, SessionStore, XOPC_SESSION_TRANSCRIPT_TYPE, applySessionPatchToMetadata, bareResetAckMessage, buildSessionContextForLlm, effectiveWorkspacePathForSession, emitSessionTranscriptUpdate, evaluateSessionFreshness, fallbackTitleFromMessages, flattenMessageContent, generateSessionTitleFromMessages, getSessionTitleSource, initSessionTurn, isTranscriptContextEntry, isWebchatSessionKey, matchResetTriggers, maybeRefineSessionTitleWithLlm, maybeSetProvisionalSessionTitle, mergeLlmMessagesPreservingContextRows, messagesToClientHistory,
|
|
20
|
+
export { CURRENT_SESSION_TRANSCRIPT_VERSION, DEFAULT_IDLE_MINUTES, DEFAULT_RESET_AT_HOUR, DEFAULT_RESET_MODE, DEFAULT_RESET_TRIGGERS, RESET_OVERLAP_COMMANDS, SessionConfigStore, SessionIndex, SessionStatus, SessionStore, XOPC_SESSION_TRANSCRIPT_TYPE, applySessionPatchToMetadata, bareResetAckMessage, buildSessionContextForLlm, effectiveWorkspacePathForSession, emitSessionTranscriptUpdate, evaluateSessionFreshness, fallbackTitleFromMessages, flattenMessageContent, generateSessionTitleFromMessages, getSessionTitleSource, initSessionTurn, isTranscriptContextEntry, isWebchatSessionKey, matchResetTriggers, maybeRefineSessionTitleWithLlm, maybeSetProvisionalSessionTitle, mergeLlmMessagesPreservingContextRows, messagesToClientHistory, normalizeWorkingDirectoryInput, onSessionTranscriptUpdate, projectWorkspacePath, provisionalTitleFromUserText, resolveChannelResetConfig, resolveDailyResetAtMs, resolveEffectiveReasoningLevel, resolveEffectiveThinkingLevel, resolveReasoningLevel, resolveResetTriggers, resolveSession, resolveSessionKeyForRequest, resolveSessionLifecycleTimestamps, resolveSessionResetPolicy, resolveSessionResetType, resolveThinkingLevel, resolveVerboseLevel, sanitizeGeneratedSessionTitle, sanitizeSessionTitle, shouldAutoTitleSessionKey, shouldRefineSessionTitleWithLlm, shouldSkipResetOverlapCommand, shouldSkipWebchatInboundByAbortCutoff, stripLeadingEnvelopeTimestamp, transcriptRowsFromJsonArray };
|
|
@@ -50,8 +50,7 @@ async function initSessionTurn(opts) {
|
|
|
50
50
|
now,
|
|
51
51
|
policy: resetPolicy
|
|
52
52
|
}) : { fresh: false };
|
|
53
|
-
const
|
|
54
|
-
const staleRollover = Boolean(sessionMetadata && !skipImplicit && !freshness.fresh);
|
|
53
|
+
const staleRollover = Boolean(sessionMetadata && resetPolicy.configured === true && !freshness.fresh);
|
|
55
54
|
const needsRollover = triggerMatch.resetTriggered || staleRollover;
|
|
56
55
|
let sessionId = sessionMetadata?.sessionId;
|
|
57
56
|
let previousSessionId;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
+
import type { Api, Model } from '@earendil-works/pi-ai/compat';
|
|
2
3
|
import { SessionStore } from './store.js';
|
|
3
4
|
import type { SessionMetadata, SessionDetail, SessionListQuery, PaginatedResult, GlobalSessionStats, ExportFormat, SessionStatus } from './types.js';
|
|
4
5
|
import type { SessionMetadataSeed } from '../storage/sqlite/index.js';
|
|
5
6
|
import type { Message } from './types.js';
|
|
6
|
-
import type { CompactionConfig, CompactionResult } from '../agent/memory/compaction.js';
|
|
7
|
+
import type { CompactionConfig, CompactionExecutionOptions, CompactionResult } from '../agent/memory/compaction.js';
|
|
7
8
|
import type { XopcSessionTranscriptV1 } from './transcript-format.js';
|
|
8
9
|
import type { XopcTranscriptContextEntry } from './session-context-for-llm.js';
|
|
9
10
|
import { type SessionPatchBody } from './patch-metadata.js';
|
|
@@ -129,6 +130,11 @@ export declare class SessionIndex extends EventEmitter {
|
|
|
129
130
|
saveMessages(key: string, messages: any[], options?: {
|
|
130
131
|
metadata?: SessionMetadataSeed;
|
|
131
132
|
}): Promise<void>;
|
|
133
|
+
deleteUserRound(key: string, userRoundIndex: number): Promise<{
|
|
134
|
+
deleted: number;
|
|
135
|
+
removedMessages: import("@earendil-works/pi-agent-core").AgentMessage[];
|
|
136
|
+
remainingMessages: import("@earendil-works/pi-agent-core").AgentMessage[];
|
|
137
|
+
}>;
|
|
132
138
|
/**
|
|
133
139
|
* Append `kind: 'context'` transcript row (persisted, excluded from {@link loadMessages} / LLM).
|
|
134
140
|
*/
|
|
@@ -172,29 +178,17 @@ export declare class SessionIndex extends EventEmitter {
|
|
|
172
178
|
tool: number;
|
|
173
179
|
needsTrim: boolean;
|
|
174
180
|
};
|
|
175
|
-
/** Prepare compaction run */
|
|
176
|
-
prepareCompaction(key: string, messages: any[], contextWindow: number): {
|
|
177
|
-
needsCompaction: boolean;
|
|
178
|
-
messages: import("@earendil-works/pi-agent-core").AgentMessage[];
|
|
179
|
-
stats: {
|
|
180
|
-
needed: boolean;
|
|
181
|
-
reason: string;
|
|
182
|
-
usagePercent?: number;
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
181
|
/** Compact session messages */
|
|
186
|
-
compact(key: string, messages: any[],
|
|
182
|
+
compact(key: string, messages: any[], model: Model<Api>, instructions?: string, force?: boolean, executionOptions?: CompactionExecutionOptions): Promise<CompactionResult>;
|
|
187
183
|
/** Compaction stats for a session */
|
|
188
184
|
getCompactionStats(key: string): Promise<{
|
|
189
185
|
compactionCount: number;
|
|
190
186
|
totalTokensBefore: number;
|
|
191
187
|
totalTokensAfter: number;
|
|
192
|
-
lastCompactionAt:
|
|
188
|
+
lastCompactionAt: string;
|
|
193
189
|
}>;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
getCompactionCheckpointDetail(key: string, checkpointId: string): Promise<import("./types.js").CompactionCheckpointDetail>;
|
|
197
|
-
restoreCompactionCheckpoint(key: string, checkpointId: string): Promise<void>;
|
|
190
|
+
listCompactionBoundaries(key: string): Promise<import("./types.js").CompactionBoundarySummary[]>;
|
|
191
|
+
restoreBeforeCompactionBoundary(key: string, compactionId: string): Promise<void>;
|
|
198
192
|
/** Estimate token usage for messages */
|
|
199
193
|
estimateTokenUsage(key: string, messages: any[]): Promise<number>;
|
|
200
194
|
}
|
|
@@ -224,6 +224,11 @@ var SessionIndex = class extends EventEmitter$1 {
|
|
|
224
224
|
async saveMessages(key, messages, options) {
|
|
225
225
|
return this.store.saveMessages(key, messages, options);
|
|
226
226
|
}
|
|
227
|
+
async deleteUserRound(key, userRoundIndex) {
|
|
228
|
+
const result = await this.store.deleteUserRound(key, userRoundIndex);
|
|
229
|
+
if (result) this.emit("sessionUpdated", { key });
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
227
232
|
/**
|
|
228
233
|
* Append `kind: 'context'` transcript row (persisted, excluded from {@link loadMessages} / LLM).
|
|
229
234
|
*/
|
|
@@ -261,27 +266,19 @@ var SessionIndex = class extends EventEmitter$1 {
|
|
|
261
266
|
getWindowStats(messages) {
|
|
262
267
|
return this.store.getWindowStats(messages);
|
|
263
268
|
}
|
|
264
|
-
/** Prepare compaction run */
|
|
265
|
-
prepareCompaction(key, messages, contextWindow) {
|
|
266
|
-
return this.store.prepareCompaction(key, messages, contextWindow);
|
|
267
|
-
}
|
|
268
269
|
/** Compact session messages */
|
|
269
|
-
compact(key, messages,
|
|
270
|
-
return this.store.compact(key, messages,
|
|
270
|
+
compact(key, messages, model, instructions, force, executionOptions) {
|
|
271
|
+
return this.store.compact(key, messages, model, instructions, force, executionOptions);
|
|
271
272
|
}
|
|
272
273
|
/** Compaction stats for a session */
|
|
273
274
|
async getCompactionStats(key) {
|
|
274
275
|
return this.store.getCompactionStats(key);
|
|
275
276
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return this.store.listCompactionCheckpoints(key);
|
|
279
|
-
}
|
|
280
|
-
getCompactionCheckpointDetail(key, checkpointId) {
|
|
281
|
-
return this.store.getCompactionCheckpointDetail(key, checkpointId);
|
|
277
|
+
listCompactionBoundaries(key) {
|
|
278
|
+
return this.store.listCompactionBoundaries(key);
|
|
282
279
|
}
|
|
283
|
-
|
|
284
|
-
return this.store.
|
|
280
|
+
restoreBeforeCompactionBoundary(key, compactionId) {
|
|
281
|
+
return this.store.restoreBeforeCompactionBoundary(key, compactionId);
|
|
285
282
|
}
|
|
286
283
|
/** Estimate token usage for messages */
|
|
287
284
|
async estimateTokenUsage(key, messages) {
|
|
@@ -68,6 +68,21 @@ export interface XopcTranscriptCompactionSummaryEntry {
|
|
|
68
68
|
tokensBefore?: number;
|
|
69
69
|
timestamp?: string | number;
|
|
70
70
|
}
|
|
71
|
+
/** Append-only compaction boundary containing the exact LLM context at that point. */
|
|
72
|
+
export interface XopcTranscriptCompactionEntry {
|
|
73
|
+
type: 'compaction';
|
|
74
|
+
at: string;
|
|
75
|
+
baseSeq: number;
|
|
76
|
+
plannerVersion: number;
|
|
77
|
+
summaryModelRef: string;
|
|
78
|
+
qualityAudit: 'passed' | 'disabled';
|
|
79
|
+
summary: string;
|
|
80
|
+
messages: AgentMessage[];
|
|
81
|
+
firstKeptIndex: number;
|
|
82
|
+
tokensBefore: number;
|
|
83
|
+
tokensAfter: number;
|
|
84
|
+
restoredFromCompactionId?: string;
|
|
85
|
+
}
|
|
71
86
|
/** Persisted label change for a transcript entry. */
|
|
72
87
|
export interface XopcTranscriptLabelEntry {
|
|
73
88
|
type: 'label';
|
|
@@ -102,14 +117,17 @@ export interface XopcTranscriptSessionInfoEntry {
|
|
|
102
117
|
name?: string;
|
|
103
118
|
timestamp?: string | number;
|
|
104
119
|
}
|
|
105
|
-
export type TranscriptStoredRow = AgentMessage | XopcTranscriptContextEntry | XopcTranscriptBashExecutionEntry | XopcTranscriptCustomMessageEntry | XopcTranscriptCustomMessageFileEntry | XopcTranscriptCustomStateEntry | XopcTranscriptBranchSummaryEntry | XopcTranscriptCompactionSummaryEntry | XopcTranscriptLabelEntry | XopcTranscriptThinkingLevelChangeEntry | XopcTranscriptModelChangeEntry | XopcTranscriptSessionInfoEntry;
|
|
120
|
+
export type TranscriptStoredRow = AgentMessage | XopcTranscriptContextEntry | XopcTranscriptBashExecutionEntry | XopcTranscriptCustomMessageEntry | XopcTranscriptCustomMessageFileEntry | XopcTranscriptCustomStateEntry | XopcTranscriptBranchSummaryEntry | XopcTranscriptCompactionSummaryEntry | XopcTranscriptCompactionEntry | XopcTranscriptLabelEntry | XopcTranscriptThinkingLevelChangeEntry | XopcTranscriptModelChangeEntry | XopcTranscriptSessionInfoEntry;
|
|
106
121
|
export declare function isTranscriptContextEntry(x: unknown): x is XopcTranscriptContextEntry;
|
|
107
122
|
export declare function isTranscriptBashExecutionEntry(x: unknown): x is XopcTranscriptBashExecutionEntry;
|
|
108
123
|
export declare function isTranscriptCustomMessageEntry(x: unknown): x is XopcTranscriptCustomMessageEntry | XopcTranscriptCustomMessageFileEntry;
|
|
109
124
|
export declare function isTranscriptCustomStateEntry(x: unknown): x is XopcTranscriptCustomStateEntry;
|
|
110
125
|
export declare function isTranscriptSummaryMessageEntry(x: unknown): x is XopcTranscriptBranchSummaryEntry | XopcTranscriptCompactionSummaryEntry;
|
|
126
|
+
export declare function isTranscriptCompactionEntry(x: unknown): x is XopcTranscriptCompactionEntry;
|
|
111
127
|
export declare function isTranscriptLabelEntry(x: unknown): x is XopcTranscriptLabelEntry;
|
|
112
128
|
export declare function isTranscriptMetadataEntry(x: unknown): x is XopcTranscriptThinkingLevelChangeEntry | XopcTranscriptModelChangeEntry | XopcTranscriptSessionInfoEntry;
|
|
129
|
+
/** Runtime-derived messages are never authoritative transcript rows. */
|
|
130
|
+
export declare function isRuntimeOnlyTranscriptMessage(x: unknown): boolean;
|
|
113
131
|
/**
|
|
114
132
|
* Normalize a JSON array from on-disk transcript into stored rows (drops unrecognized objects).
|
|
115
133
|
*/
|
|
@@ -21,6 +21,11 @@ function isTranscriptSummaryMessageEntry(x) {
|
|
|
21
21
|
const role = x.role;
|
|
22
22
|
return role === "branchSummary" || role === "compactionSummary";
|
|
23
23
|
}
|
|
24
|
+
function isTranscriptCompactionEntry(x) {
|
|
25
|
+
if (!x || typeof x !== "object") return false;
|
|
26
|
+
const row = x;
|
|
27
|
+
return row.type === "compaction" && typeof row.at === "string" && typeof row.baseSeq === "number" && Number.isInteger(row.baseSeq) && typeof row.plannerVersion === "number" && Number.isInteger(row.plannerVersion) && typeof row.summaryModelRef === "string" && (row.qualityAudit === "passed" || row.qualityAudit === "disabled") && typeof row.summary === "string" && Array.isArray(row.messages) && typeof row.firstKeptIndex === "number" && typeof row.tokensBefore === "number" && typeof row.tokensAfter === "number";
|
|
28
|
+
}
|
|
24
29
|
function isTranscriptLabelEntry(x) {
|
|
25
30
|
if (!x || typeof x !== "object") return false;
|
|
26
31
|
return x.type === "label";
|
|
@@ -37,13 +42,15 @@ const LLM_ROLES = new Set([
|
|
|
37
42
|
"tool",
|
|
38
43
|
"toolResult"
|
|
39
44
|
]);
|
|
40
|
-
const CODING_CONTEXT_LOOKBACK = 80;
|
|
41
|
-
const CODING_CONTEXT_MAX_LINES = 24;
|
|
42
45
|
function isLikelyAgentMessage(x) {
|
|
43
46
|
if (!x || typeof x !== "object") return false;
|
|
44
47
|
const role = x.role;
|
|
45
48
|
return typeof role === "string" && LLM_ROLES.has(role);
|
|
46
49
|
}
|
|
50
|
+
/** Runtime-derived messages are never authoritative transcript rows. */
|
|
51
|
+
function isRuntimeOnlyTranscriptMessage(x) {
|
|
52
|
+
return isLikelyAgentMessage(x) && x.droppable === true;
|
|
53
|
+
}
|
|
47
54
|
function parseTimestampValue(timestamp) {
|
|
48
55
|
if (typeof timestamp === "number") return Number.isFinite(timestamp) ? timestamp : void 0;
|
|
49
56
|
if (typeof timestamp !== "string") return;
|
|
@@ -93,33 +100,6 @@ function asRecord(value) {
|
|
|
93
100
|
function stringValue(value) {
|
|
94
101
|
return typeof value === "string" ? value : void 0;
|
|
95
102
|
}
|
|
96
|
-
function parseJsonRecord(value) {
|
|
97
|
-
if (typeof value !== "string" || !value.trim()) return null;
|
|
98
|
-
try {
|
|
99
|
-
return asRecord(JSON.parse(value));
|
|
100
|
-
} catch {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function textFromContent(content) {
|
|
105
|
-
if (typeof content === "string") return content;
|
|
106
|
-
if (!Array.isArray(content)) return "";
|
|
107
|
-
return content.map((part) => {
|
|
108
|
-
if (typeof part === "string") return part;
|
|
109
|
-
const rec = asRecord(part);
|
|
110
|
-
if (!rec) return "";
|
|
111
|
-
if (rec.type === "text" && typeof rec.text === "string") return rec.text;
|
|
112
|
-
return "";
|
|
113
|
-
}).filter(Boolean).join("");
|
|
114
|
-
}
|
|
115
|
-
function toolNameFromBlock(block) {
|
|
116
|
-
const fn = asRecord(block.function);
|
|
117
|
-
return stringValue(block.name) ?? stringValue(block.toolName) ?? stringValue(fn?.name) ?? "tool";
|
|
118
|
-
}
|
|
119
|
-
function toolArgsFromBlock(block) {
|
|
120
|
-
const fn = asRecord(block.function);
|
|
121
|
-
return asRecord(block.arguments) ?? asRecord(block.args) ?? asRecord(block.input) ?? asRecord(fn?.arguments) ?? parseJsonRecord(block.arguments) ?? parseJsonRecord(block.args) ?? parseJsonRecord(block.input) ?? parseJsonRecord(fn?.arguments) ?? {};
|
|
122
|
-
}
|
|
123
103
|
function toolCallIdFromBlock(block) {
|
|
124
104
|
return stringValue(block.id) ?? stringValue(block.toolCallId) ?? stringValue(block.tool_call_id) ?? stringValue(block.tool_call_id$);
|
|
125
105
|
}
|
|
@@ -127,112 +107,84 @@ function toolResultId(row) {
|
|
|
127
107
|
const rec = row;
|
|
128
108
|
return stringValue(rec.toolCallId) ?? stringValue(rec.tool_call_id) ?? stringValue(rec.tool_call_id$);
|
|
129
109
|
}
|
|
130
|
-
function
|
|
131
|
-
if (
|
|
132
|
-
const
|
|
133
|
-
if (topLevelDetails) return topLevelDetails;
|
|
134
|
-
const contentText = textFromContent(row.content);
|
|
135
|
-
if (!contentText.trim()) return null;
|
|
136
|
-
try {
|
|
137
|
-
const rec = asRecord(JSON.parse(contentText));
|
|
138
|
-
return asRecord(rec?.details) ?? rec;
|
|
139
|
-
} catch {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function collectToolResults(messages) {
|
|
144
|
-
const results = /* @__PURE__ */ new Map();
|
|
145
|
-
for (const message of messages) {
|
|
146
|
-
const role = message.role;
|
|
147
|
-
if (role !== "tool" && role !== "toolResult") continue;
|
|
148
|
-
const id = toolResultId(message);
|
|
149
|
-
if (id) results.set(id, message);
|
|
150
|
-
}
|
|
151
|
-
return results;
|
|
152
|
-
}
|
|
153
|
-
function extractToolCalls(message) {
|
|
110
|
+
function toolCallIds(message) {
|
|
111
|
+
if (message.role !== "assistant") return [];
|
|
112
|
+
const ids = [];
|
|
154
113
|
const content = message.content;
|
|
155
|
-
const calls = [];
|
|
156
114
|
if (Array.isArray(content)) for (const block of content) {
|
|
157
115
|
const rec = asRecord(block);
|
|
158
116
|
const type = rec ? stringValue(rec.type) : void 0;
|
|
159
117
|
if (!rec || type !== "toolCall" && type !== "tool_use" && type !== "tool_call") continue;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
name: toolNameFromBlock(rec),
|
|
163
|
-
args: toolArgsFromBlock(rec)
|
|
164
|
-
});
|
|
118
|
+
const id = toolCallIdFromBlock(rec);
|
|
119
|
+
if (id) ids.push(id);
|
|
165
120
|
}
|
|
166
|
-
const
|
|
167
|
-
if (Array.isArray(
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
const name = stringValue(fn?.name) ?? stringValue(rec?.name);
|
|
171
|
-
if (!rec || !name) continue;
|
|
172
|
-
calls.push({
|
|
173
|
-
id: stringValue(rec.id),
|
|
174
|
-
name,
|
|
175
|
-
args: parseJsonRecord(fn?.arguments) ?? asRecord(fn?.arguments) ?? {}
|
|
176
|
-
});
|
|
121
|
+
const calls = message.tool_calls;
|
|
122
|
+
if (Array.isArray(calls)) for (const call of calls) {
|
|
123
|
+
const id = stringValue(asRecord(call)?.id);
|
|
124
|
+
if (id) ids.push(id);
|
|
177
125
|
}
|
|
178
|
-
return
|
|
179
|
-
}
|
|
180
|
-
function summarizePlan(details) {
|
|
181
|
-
const lines = (Array.isArray(details.plan) ? details.plan : []).map((item) => {
|
|
182
|
-
const rec = asRecord(item);
|
|
183
|
-
const step = stringValue(rec?.step)?.trim();
|
|
184
|
-
const status = stringValue(rec?.status)?.trim();
|
|
185
|
-
return step && status ? `${status}: ${step}` : "";
|
|
186
|
-
}).filter(Boolean).slice(0, 8);
|
|
187
|
-
if (lines.length === 0) return void 0;
|
|
188
|
-
const explanation = stringValue(details.explanation)?.trim();
|
|
189
|
-
return `Plan${explanation ? ` (${explanation})` : ""}: ${lines.join(" | ")}`;
|
|
190
|
-
}
|
|
191
|
-
function summarizeCommand(args, details) {
|
|
192
|
-
const command = stringValue(details?.command) ?? stringValue(args.cmd) ?? stringValue(args.command) ?? "";
|
|
193
|
-
const status = stringValue(details?.status) ?? (details?.exitCode === 0 ? "success" : "unknown");
|
|
194
|
-
const exitCode = typeof details?.exitCode === "number" ? details.exitCode : void 0;
|
|
195
|
-
const hint = stringValue(details?.failureHint);
|
|
196
|
-
return [
|
|
197
|
-
`Command ${status}: ${command || "(unknown command)"}`,
|
|
198
|
-
exitCode !== void 0 ? `exit=${exitCode}` : "",
|
|
199
|
-
hint ? `hint=${hint}` : ""
|
|
200
|
-
].filter(Boolean).join(" ");
|
|
126
|
+
return ids;
|
|
201
127
|
}
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
128
|
+
function filterAssistantToolCalls(message, pairedIds) {
|
|
129
|
+
const record = message;
|
|
130
|
+
const content = record.content;
|
|
131
|
+
const filteredContent = Array.isArray(content) ? content.filter((block) => {
|
|
132
|
+
const rec = asRecord(block);
|
|
133
|
+
const type = rec ? stringValue(rec.type) : void 0;
|
|
134
|
+
if (!rec || type !== "toolCall" && type !== "tool_use" && type !== "tool_call") return true;
|
|
135
|
+
const id = toolCallIdFromBlock(rec);
|
|
136
|
+
return id !== void 0 && pairedIds.has(id);
|
|
137
|
+
}) : content;
|
|
138
|
+
const toolCalls = record.tool_calls;
|
|
139
|
+
const filteredToolCalls = Array.isArray(toolCalls) ? toolCalls.filter((call) => {
|
|
140
|
+
const id = stringValue(asRecord(call)?.id);
|
|
141
|
+
return id !== void 0 && pairedIds.has(id);
|
|
142
|
+
}) : toolCalls;
|
|
143
|
+
const hadArrayContent = Array.isArray(content);
|
|
144
|
+
const hadToolCalls = Array.isArray(toolCalls);
|
|
145
|
+
const hasContent = Array.isArray(filteredContent) ? filteredContent.length > 0 : typeof filteredContent === "string" ? filteredContent.trim().length > 0 : filteredContent !== void 0 && filteredContent !== null;
|
|
146
|
+
const hasToolCalls = Array.isArray(filteredToolCalls) && filteredToolCalls.length > 0;
|
|
147
|
+
if (!hasContent && !hasToolCalls) return null;
|
|
148
|
+
return {
|
|
149
|
+
...record,
|
|
150
|
+
...hadArrayContent ? { content: filteredContent } : {},
|
|
151
|
+
...hadToolCalls ? { tool_calls: filteredToolCalls } : {}
|
|
152
|
+
};
|
|
209
153
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
for (
|
|
215
|
-
|
|
216
|
-
for (const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
154
|
+
/** Providers require every retained tool call and result to form an ordered pair. */
|
|
155
|
+
function sanitizeToolPairs(messages) {
|
|
156
|
+
const callIndex = /* @__PURE__ */ new Map();
|
|
157
|
+
const resultIndex = /* @__PURE__ */ new Map();
|
|
158
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
159
|
+
const message = messages[index];
|
|
160
|
+
for (const id of toolCallIds(message)) if (!callIndex.has(id)) callIndex.set(id, index);
|
|
161
|
+
const role = String(message.role ?? "");
|
|
162
|
+
if (role === "tool" || role === "toolResult") {
|
|
163
|
+
const id = toolResultId(message);
|
|
164
|
+
if (id && !resultIndex.has(id)) resultIndex.set(id, index);
|
|
221
165
|
}
|
|
222
166
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
167
|
+
const pairedIds = /* @__PURE__ */ new Set();
|
|
168
|
+
for (const [id, callAt] of callIndex) {
|
|
169
|
+
const resultAt = resultIndex.get(id);
|
|
170
|
+
if (resultAt !== void 0 && resultAt > callAt) pairedIds.add(id);
|
|
171
|
+
}
|
|
172
|
+
const out = [];
|
|
173
|
+
for (const message of messages) {
|
|
174
|
+
const role = String(message.role ?? "");
|
|
175
|
+
if (role === "tool" || role === "toolResult") {
|
|
176
|
+
const id = toolResultId(message);
|
|
177
|
+
if (id && pairedIds.has(id)) out.push(message);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (message.role === "assistant") {
|
|
181
|
+
const filtered = filterAssistantToolCalls(message, pairedIds);
|
|
182
|
+
if (filtered) out.push(filtered);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
out.push(message);
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
236
188
|
}
|
|
237
189
|
/**
|
|
238
190
|
* Normalize a JSON array from on-disk transcript into stored rows (drops unrecognized objects).
|
|
@@ -260,6 +212,10 @@ function transcriptRowsFromJsonArray(arr) {
|
|
|
260
212
|
out.push(x);
|
|
261
213
|
continue;
|
|
262
214
|
}
|
|
215
|
+
if (isTranscriptCompactionEntry(x)) {
|
|
216
|
+
out.push(x);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
263
219
|
if (isTranscriptLabelEntry(x)) {
|
|
264
220
|
out.push(x);
|
|
265
221
|
continue;
|
|
@@ -276,8 +232,12 @@ function transcriptRowsFromJsonArray(arr) {
|
|
|
276
232
|
function buildSessionContextForLlm(rows) {
|
|
277
233
|
const out = [];
|
|
278
234
|
for (const r of rows) {
|
|
235
|
+
if (isTranscriptCompactionEntry(r)) {
|
|
236
|
+
out.length = 0;
|
|
237
|
+
out.push(...r.messages);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
279
240
|
if (isTranscriptContextEntry(r)) continue;
|
|
280
|
-
if (r.type === "compaction") continue;
|
|
281
241
|
if (isTranscriptBashExecutionEntry(r)) {
|
|
282
242
|
const msg = bashExecutionRowToLlmMessage(r);
|
|
283
243
|
if (msg) out.push(msg);
|
|
@@ -289,9 +249,7 @@ function buildSessionContextForLlm(rows) {
|
|
|
289
249
|
}
|
|
290
250
|
if (isLikelyAgentMessage(r)) out.push(r);
|
|
291
251
|
}
|
|
292
|
-
|
|
293
|
-
if (codingContext) out.push(codingContext);
|
|
294
|
-
return out;
|
|
252
|
+
return sanitizeToolPairs(out);
|
|
295
253
|
}
|
|
296
254
|
/** Visible chat messages only - no LLM-only audit/context expansion. */
|
|
297
255
|
function buildSessionDisplayMessages(rows) {
|
|
@@ -326,4 +284,4 @@ function mergeLlmMessagesPreservingContextRows(prevRows, llmMessages) {
|
|
|
326
284
|
return out;
|
|
327
285
|
}
|
|
328
286
|
//#endregion
|
|
329
|
-
export { buildSessionContextForLlm, buildSessionDisplayMessages, isTranscriptBashExecutionEntry, isTranscriptContextEntry, isTranscriptCustomMessageEntry, isTranscriptCustomStateEntry, isTranscriptLabelEntry, isTranscriptMetadataEntry, isTranscriptSummaryMessageEntry, mergeLlmMessagesPreservingContextRows, transcriptRowsFromJsonArray };
|
|
287
|
+
export { buildSessionContextForLlm, buildSessionDisplayMessages, isRuntimeOnlyTranscriptMessage, isTranscriptBashExecutionEntry, isTranscriptCompactionEntry, isTranscriptContextEntry, isTranscriptCustomMessageEntry, isTranscriptCustomStateEntry, isTranscriptLabelEntry, isTranscriptMetadataEntry, isTranscriptSummaryMessageEntry, mergeLlmMessagesPreservingContextRows, transcriptRowsFromJsonArray };
|