@xopcai/xopc 0.0.359 → 0.0.360
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/{agent-avatar-dicebear-D-yhlYSG.js → agent-avatar-dicebear-CQTERenW.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CPF0lunJ.js +1 -0
- package/dist/gateway/static/root/assets/agent-plugin-dialog-BjDaZlKy.js +1 -0
- package/dist/gateway/static/root/assets/agents-XopBILLB.js +66 -0
- package/dist/gateway/static/root/assets/{app-management-settings-panel-CiSdkzuX.js → app-management-settings-panel-V5QVeMvW.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-SdlCHKg8.js → appearance-settings-BDkRcoI6.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-ntyBe6mP.js → apps-page-DzCyL89L.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-DU0R5C65.js → automations-page-DOu1wMOV.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-CiY_2otj.js +7 -0
- package/dist/gateway/static/root/assets/{block-editor-CLejMPkV.js → block-editor-K6is5GrS.js} +3 -3
- package/dist/gateway/static/root/assets/{browser-automations-page-BjGswNM0.js → browser-automations-page-B8IiXEBs.js} +2 -2
- package/dist/gateway/static/root/assets/{browser-settings-page-DBcYssNQ.js → browser-settings-page-Cms2Bu3Q.js} +2 -2
- package/dist/gateway/static/root/assets/{capabilities-page-CsTpcrPP.js → capabilities-page-BAFRNHQv.js} +2 -2
- package/dist/gateway/static/root/assets/capabilities-settings-panel-Cws6od1d.js +8 -0
- package/dist/gateway/static/root/assets/{capability-header-actions-B0Xiav_-.js → capability-header-actions-wh3Nr0qS.js} +1 -1
- package/dist/gateway/static/root/assets/channels-DxwismTc.js +1 -0
- package/dist/gateway/static/root/assets/{chat-terminal-dock-C9pMFB6k.js → chat-terminal-dock-BU-X9nu1.js} +2 -2
- package/dist/gateway/static/root/assets/computer-settings-page-MyXsSqFJ.js +1 -0
- package/dist/gateway/static/root/assets/{connector-service-page-OyQKwHNr.js → connector-service-page-DyxPM_MZ.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-C7-OC3MW.js +2 -0
- package/dist/gateway/static/root/assets/{constants-Co2_smKQ.js → constants-Dy8Gw0sF.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-DxGsweV_.js → date-picker-WRFvi7Pu.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-D9ZfAJwn.js → dependency-picker-CLun5Tst.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-DFgK1z5i.js → desktop-pet-iaVa9vVM.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-CyFW0raW.js → desktop-pet-settings-0RS3sP3Z.js} +1 -1
- package/dist/gateway/static/root/assets/device-pairing-wizard-DVAGb04L.js +1 -0
- package/dist/gateway/static/root/assets/{directory-picker-path-field-2nrl6Exh.js → directory-picker-path-field-Btlldlt3.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BodxNAys.js → extension-debug-page-BImQT4PU.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DMb2YFlb.js → extension-page-BmuLv-ET.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-provider-aigS3RJu.js → extension-provider-Dg7cRxDX.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-D3hvXtxi.js → extension-settings-page-7Kr8UJK4.js} +1 -1
- package/dist/gateway/static/root/assets/{fallback-models-DsXySQVF.js → fallback-models-B0w1lumZ.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-settings-DmPvmwYp.js +1 -0
- package/dist/gateway/static/root/assets/home-page-N0Mp-eTJ.js +1 -0
- package/dist/gateway/static/root/assets/{imports-page-Czzsa_Eu.js → imports-page-BLOJY67-.js} +1 -1
- package/dist/gateway/static/root/assets/{index-DUgsBdV3.css → index-B7AHDHSO.css} +1 -1
- package/dist/gateway/static/root/assets/{index-DUU_2HF0.js → index-BXrBL_Hb.js} +41 -41
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-DqsFlXlp.js → keyboard-shortcuts-settings-Dlbsip2R.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-BcDFXc1k.js → local-app-workbench-page-nyWeTK0r.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-BaxqXA1-.js → local-apps-page-CfEpFLs0.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-DmJjZ0Uk.js → logs-page-A38cawkA.js} +2 -2
- package/dist/gateway/static/root/assets/{management-settings-1O7zsu4t.js → management-settings-Cse9K61x.js} +1 -1
- package/dist/gateway/static/root/assets/{note-detail-panel-BLvVlQG8.js → note-detail-panel-CUGVyo2V.js} +3 -3
- package/dist/gateway/static/root/assets/notes-page-Dk89l5dC.js +8 -0
- package/dist/gateway/static/root/assets/{page-context-capture-button-gL3453SU.js → page-context-capture-button-C72qIgBg.js} +1 -1
- package/dist/gateway/static/root/assets/personal-page-DCtduzh8.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-Dw8JPizo.js → product-open-page-CT98FsVl.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-Zg4KZ0vK.js → project-detail-page-BlqOVwKP.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-B33uj1lz.js → projects-page-DVN2q_yR.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BP5kUgIN.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-BLNXzyeh.js → runtime-tools-settings-panel-ry0jprz7.js} +1 -1
- package/dist/gateway/static/root/assets/{scenes-page-D868Zuj9.js → scenes-page-CV1GkOj6.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-5z33VTce.js → schema-form-C5zMrxgR.js} +1 -1
- package/dist/gateway/static/root/assets/{send-session-input-OaBPDJ9E.js → send-session-input-Dt0t5SoR.js} +1 -1
- package/dist/gateway/static/root/assets/session-manager-DDR-gv_e.js +16 -0
- package/dist/gateway/static/root/assets/sessions-page-BXtGeOsR.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-CvFVkELy.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-BG_dOYMq.js → settings-page-C88fsfZF.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-DNj1hD_H.js → setup-status-panel-DESlRgZS.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-M_rAQR60.js → share-preview-page-D5Gey-6E.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-btoP07Fx.js +1 -0
- package/dist/gateway/static/root/assets/{skill-api-BBaKs-Xx.js → skill-api-1hbX3qDC.js} +1 -1
- package/dist/gateway/static/root/assets/skills-page-DYJbwwBT.js +2 -0
- package/dist/gateway/static/root/assets/{system-settings-panel-DKjsZo49.js → system-settings-panel-DbNk-Jwq.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-DSvaiKGb.js → task-detail-page-DoLKOJrE.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-DR8Qu6R_.js → tunnel-api-H3FheXYH.js} +1 -1
- package/dist/gateway/static/root/assets/{usage-page-CAIqAduR.js → usage-page-DGbqcsV6.js} +1 -1
- package/dist/gateway/static/root/assets/{use-composer-attachments-CUaywGe0.js → use-composer-attachments-pzPAUV_o.js} +1 -1
- package/dist/gateway/static/root/assets/{use-file-preview-expanded-D809I8ur.js → use-file-preview-expanded-DNhXjL0W.js} +1 -1
- package/dist/gateway/static/root/assets/user-model-page-7pW4Pazn.js +2 -0
- package/dist/gateway/static/root/assets/{work-discovery-overlay-wGFcle2p.js → work-discovery-overlay-DfyI9kVf.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-CewS2IbN.js → workflow-run-setup-panel-De80GODZ.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-BuH3pC1C.js +6 -0
- package/dist/gateway/static/root/assets/{workspace-api-BtXzxf_w.js → workspace-api-Dwa8kHdY.js} +2 -2
- package/dist/gateway/static/root/index.html +9 -9
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/index.js +2 -0
- package/dist/packages/gateway-contract/src/task-result-delivery.js +30 -0
- package/dist/src/agent/agent-manager.js +3 -3
- package/dist/src/agent/background-review/run-background-review.js +1 -1
- package/dist/src/agent/context/workspace-templates/SOUL.md +2 -0
- package/dist/src/agent/external-tools/endpoint-provider.js +2 -2
- package/dist/src/agent/external-tools/gateway-tools.js +41 -1
- package/dist/src/agent/image/tool-model-config.js +1 -1
- package/dist/src/agent/mcp/oauth/mcp-oauth-store.js +1 -1
- package/dist/src/agent/prompt/sections/behavior.js +4 -1
- package/dist/src/agent/prompt/sections/memory-skills.js +2 -0
- package/dist/src/agent/service.js +2 -2
- package/dist/src/agent/session/session-config-service.js +11 -3
- package/dist/src/agent/skills/hub-lock.js +1 -1
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/tools/factory.js +32 -6
- package/dist/src/agent/tools/personal-preference-tool.js +11 -0
- package/dist/src/agent/tools/personal-request-result-tool.d.ts +22 -0
- package/dist/src/agent/tools/personal-request-result-tool.js +84 -0
- package/dist/src/agent/tools/personal-request-tool.d.ts +3 -0
- package/dist/src/agent/tools/personal-request-tool.js +100 -0
- package/dist/src/agent/tools/personal-task-tool.d.ts +6 -0
- package/dist/src/agent/tools/personal-task-tool.js +12 -10
- package/dist/src/agent/tools/tool-media.js +2 -3
- package/dist/src/agent/tools/xopc-use-tool.js +2 -2
- package/dist/src/agent-catalog/capabilities.js +2 -2
- package/dist/src/auth/credentials.js +1 -1
- package/dist/src/auth/oauth-provider-lock.js +1 -1
- package/dist/src/auth/profiles/store.js +1 -1
- package/dist/src/automations/capabilities/drafts.js +1 -1
- package/dist/src/bootstrap/application-state.js +1 -1
- package/dist/src/browser/providers/browser-ext-install.js +1 -1
- package/dist/src/capabilities/runtime/dispatcher.js +1 -1
- package/dist/src/capabilities/runtime/product.js +1 -1
- package/dist/src/cli/commands/agent.js +1 -1
- package/dist/src/cli/commands/agents.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/commands/onboard/model.js +1 -1
- package/dist/src/cli/templates.js +4 -0
- package/dist/src/cli/utils/init-workspace-core.js +1 -1
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/loader.js +1 -1
- package/dist/src/config/models-json.js +1 -1
- package/dist/src/config/schema.js +1 -1
- package/dist/src/connectors/connection-recovery-service.d.ts +2 -0
- package/dist/src/connectors/connection-recovery-service.js +23 -5
- package/dist/src/extensions/agent-plugins/validation.js +1 -1
- package/dist/src/extensions/lockfile.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agents-admin.js +2 -2
- package/dist/src/gateway/hono/lib/config-payload.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +2 -2
- package/dist/src/gateway/hono/routes/media.js +4 -3
- package/dist/src/gateway/hono/routes/notes.js +2 -2
- package/dist/src/gateway/hono/routes/personal-agent.js +68 -0
- package/dist/src/gateway/hono/routes/projects.js +2 -2
- package/dist/src/gateway/hono/routes/session-input-handler.js +1 -1
- package/dist/src/gateway/hono/routes/tasks.js +1 -1
- package/dist/src/gateway/image-generation-setup.js +2 -2
- package/dist/src/gateway/lock.js +1 -1
- package/dist/src/gateway/media-access.js +2 -2
- package/dist/src/gateway/service.d.ts +3 -0
- package/dist/src/gateway/service.js +46 -5
- package/dist/src/gateway/xopc-cloud-capability-setup.js +1 -1
- package/dist/src/local-apps/service.js +1 -1
- package/dist/src/media/index.js +2 -2
- package/dist/src/media/session-references.d.ts +2 -0
- package/dist/src/media/session-references.js +22 -2
- package/dist/src/media/store.d.ts +1 -0
- package/dist/src/media/store.js +2 -1
- package/dist/src/personal-agent/capability-service.d.ts +14 -0
- package/dist/src/personal-agent/capability-service.js +63 -0
- package/dist/src/personal-agent/communication.d.ts +4 -0
- package/dist/src/personal-agent/communication.js +24 -0
- package/dist/src/personal-agent/model-config.d.ts +5 -0
- package/dist/src/personal-agent/model-config.js +59 -0
- package/dist/src/personal-agent/policy.d.ts +1 -1
- package/dist/src/personal-agent/policy.js +2 -0
- package/dist/src/personal-agent/repository.d.ts +1 -0
- package/dist/src/personal-agent/repository.js +3 -1
- package/dist/src/personal-agent/request-delivery.d.ts +4 -0
- package/dist/src/personal-agent/request-delivery.js +159 -0
- package/dist/src/personal-agent/request-repository.d.ts +33 -0
- package/dist/src/personal-agent/request-repository.js +71 -0
- package/dist/src/personal-agent/request-result.d.ts +21 -0
- package/dist/src/personal-agent/request-result.js +45 -0
- package/dist/src/personal-agent/request-service.d.ts +18 -0
- package/dist/src/personal-agent/request-service.js +308 -0
- package/dist/src/personal-agent/service.js +30 -7
- package/dist/src/providers/model-catalog-persistence.js +1 -1
- package/dist/src/session/client-history.d.ts +2 -1
- package/dist/src/session/client-history.js +40 -0
- package/dist/src/session/compact-history.js +9 -5
- package/dist/src/session/config-store.js +2 -1
- package/dist/src/session/session-context-for-llm.js +55 -0
- package/dist/src/session/store.js +2 -0
- package/dist/src/session/types.d.ts +2 -0
- package/dist/src/storage/sqlite/connection-wait-repository.d.ts +5 -1
- package/dist/src/storage/sqlite/connection-wait-repository.js +38 -8
- package/dist/src/storage/sqlite/migrations/231_task_result_deliveries.sql +32 -0
- package/dist/src/storage/sqlite/migrations/232_personal_requests.sql +28 -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/storage/sqlite/session-repository.js +33 -0
- package/dist/src/tasks/capabilities/read.js +2 -2
- package/dist/src/tasks/task-application-service.d.ts +1 -0
- package/dist/src/tasks/task-application-service.js +7 -0
- package/dist/src/tasks/task-context-assembler.js +1 -0
- package/dist/src/tasks/task-main-update-delivery.js +32 -1
- package/dist/src/tasks/task-result-delivery-repository.d.ts +18 -0
- package/dist/src/tasks/task-result-delivery-repository.js +144 -0
- package/dist/src/tasks/task-result-delivery-service.d.ts +4 -0
- package/dist/src/tasks/task-result-delivery-service.js +128 -0
- package/dist/src/tasks/task-run-coordinator.js +6 -1
- package/dist/src/tasks/task-run-dispatcher.d.ts +1 -0
- package/dist/src/tasks/task-run-dispatcher.js +22 -3
- package/dist/src/tui/backends/embedded-backend.js +2 -2
- package/dist/src/voice/realtime/persona-context.js +1 -1
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CYq-3pbE.js +0 -1
- package/dist/gateway/static/root/assets/agent-plugin-dialog-Cx3UbhqT.js +0 -1
- package/dist/gateway/static/root/assets/agents-Ce9uvui7.js +0 -66
- package/dist/gateway/static/root/assets/automations-workspace-BaHJml4R.js +0 -7
- package/dist/gateway/static/root/assets/capabilities-settings-panel-BXlVwnMr.js +0 -8
- package/dist/gateway/static/root/assets/channels-TPqwcbZ4.js +0 -1
- package/dist/gateway/static/root/assets/computer-settings-page-BJOn14Ow.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-DBWH5bVr.js +0 -2
- package/dist/gateway/static/root/assets/device-pairing-wizard-C6Co5dT3.js +0 -1
- package/dist/gateway/static/root/assets/gateway-settings-CubM1m6Z.js +0 -1
- package/dist/gateway/static/root/assets/home-page-CQ9y_LMT.js +0 -1
- package/dist/gateway/static/root/assets/notes-page-AWU_G61i.js +0 -8
- package/dist/gateway/static/root/assets/personal-page-BPy5m3QR.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-BZoUVzgS.js +0 -1
- package/dist/gateway/static/root/assets/session-manager-BK5IvdGz.js +0 -16
- package/dist/gateway/static/root/assets/sessions-page-Du7ueBFc.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-CaxCsIIZ.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-Cr_Ut6FE.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-DU7fV5pc.js +0 -2
- package/dist/gateway/static/root/assets/user-model-page-C--t6SLp.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-CxfsWFL5.js +0 -6
|
@@ -6,6 +6,7 @@ import { getSqliteDatabase, init_transaction, runSqliteWriteTransaction } from "
|
|
|
6
6
|
import { init_session_instance_repository, readCurrentTranscriptId } from "./session-instance-repository.js";
|
|
7
7
|
import { bumpSessionInputRevision, getSessionInputById, getSessionInputState, init_session_input_repository, insertSessionInput, setSessionInputStatus } from "./session-input-repository.js";
|
|
8
8
|
import { TaskRunRepository, init_task_run_repository } from "../../tasks/task-run-repository.js";
|
|
9
|
+
import { init_request_repository, personalRequestForExecution, personalRequestForWait, updatePersonalRequest } from "../../personal-agent/request-repository.js";
|
|
9
10
|
import { getConnectorAccount, init_connector_account_repository } from "./connector-account-repository.js";
|
|
10
11
|
import { getConnectorConnection, init_connector_repository } from "./connector-repository.js";
|
|
11
12
|
import { randomUUID } from "node:crypto";
|
|
@@ -68,8 +69,10 @@ function requireSessionConnection(input) {
|
|
|
68
69
|
return runSqliteWriteTransaction((db) => {
|
|
69
70
|
const transcriptId = readCurrentTranscriptId(db, input.conversationId);
|
|
70
71
|
const runtime = getSessionInputState(input.conversationId);
|
|
71
|
-
const
|
|
72
|
-
|
|
72
|
+
const originId = input.origin?.inputId ?? runtime.activeInputId;
|
|
73
|
+
const origin = originId ? getSessionInputById(input.conversationId, originId) : void 0;
|
|
74
|
+
const originRunId = input.origin?.runId ?? runtime.activeRunId;
|
|
75
|
+
if (!transcriptId || !origin || !originRunId || origin.expectedTranscriptId && origin.expectedTranscriptId !== transcriptId) throw new Error("Connection recovery requires a queued chat execution.");
|
|
73
76
|
const resumed = origin.payload ? getConnectionWait(origin.payload.waitId) : void 0;
|
|
74
77
|
if (resumed?.resolution === "skipped") return { status: "skipped" };
|
|
75
78
|
const active = getActiveConnectionWait(input.conversationId);
|
|
@@ -97,7 +100,9 @@ function requireSessionConnection(input) {
|
|
|
97
100
|
}
|
|
98
101
|
const lastEntry = db.prepare("SELECT entry_id FROM transcript_entries WHERE transcript_id = ? ORDER BY seq DESC LIMIT 1").get(transcriptId);
|
|
99
102
|
const wait = {
|
|
100
|
-
|
|
103
|
+
conversationId: input.conversationId,
|
|
104
|
+
principalId: input.principalId,
|
|
105
|
+
agentId: input.agentId,
|
|
101
106
|
needs: [...new Map(input.needs.map((need) => [need.key, need])).values()],
|
|
102
107
|
id: randomUUID(),
|
|
103
108
|
transcriptId,
|
|
@@ -105,7 +110,7 @@ function requireSessionConnection(input) {
|
|
|
105
110
|
objectiveRevision: (resumed?.objectiveRevision ?? 0) + 1,
|
|
106
111
|
objectiveUpdatedAt: resumed?.objectiveUpdatedAt ?? origin.createdAtMs,
|
|
107
112
|
originInputId: origin.id,
|
|
108
|
-
originRunId
|
|
113
|
+
originRunId,
|
|
109
114
|
taskRunId: origin.taskRunId,
|
|
110
115
|
checkpoint: {
|
|
111
116
|
entryId: lastEntry?.entry_id,
|
|
@@ -158,10 +163,16 @@ function requireSessionConnection(input) {
|
|
|
158
163
|
});
|
|
159
164
|
}
|
|
160
165
|
/** The input and the wait transition commit together, using the existing queue's unique key. */
|
|
161
|
-
function queueConnectionResolution(wait, resolution) {
|
|
166
|
+
function queueConnectionResolution(wait, resolution, resolvePersonal) {
|
|
162
167
|
return runSqliteWriteTransaction(() => {
|
|
163
168
|
const current = getConnectionWait(wait.id);
|
|
164
169
|
if (!current || current.version !== wait.version || current.status !== "open") throw new Error("WAIT_CHANGED");
|
|
170
|
+
if (resolvePersonal?.(wait, resolution)) return updateConnectionWait({
|
|
171
|
+
...wait,
|
|
172
|
+
status: "closed",
|
|
173
|
+
resolution,
|
|
174
|
+
intent: void 0
|
|
175
|
+
}, wait.version);
|
|
165
176
|
const origin = getSessionInputById(wait.conversationId, wait.originInputId);
|
|
166
177
|
if (!origin) throw new Error("Original input is unavailable.");
|
|
167
178
|
const input = insertSessionInput({
|
|
@@ -239,6 +250,21 @@ function consumeConnectionResume(input) {
|
|
|
239
250
|
}
|
|
240
251
|
function connectionBindings(conversationId) {
|
|
241
252
|
if (!isXopcDatabaseOpen()) return [];
|
|
253
|
+
const personalRequest = personalRequestForExecution(conversationId);
|
|
254
|
+
if (personalRequest?.accountId) {
|
|
255
|
+
const account = getConnectorAccount(personalRequest.accountId);
|
|
256
|
+
return [{
|
|
257
|
+
key: `${personalRequest.connectorId}:${personalRequest.accountId}`,
|
|
258
|
+
target: {
|
|
259
|
+
type: "connector",
|
|
260
|
+
connectorId: personalRequest.connectorId
|
|
261
|
+
},
|
|
262
|
+
label: personalRequest.connectorId,
|
|
263
|
+
capabilities: [],
|
|
264
|
+
accountId: personalRequest.accountId,
|
|
265
|
+
connectionId: account?.currentConnectionId
|
|
266
|
+
}];
|
|
267
|
+
}
|
|
242
268
|
let sessionContext = getConnectionSessionContext(conversationId);
|
|
243
269
|
if (sessionContext?.sessionType === "workflow-subagent" && sessionContext.parentConversationId) sessionContext = getConnectionSessionContext(sessionContext.parentConversationId);
|
|
244
270
|
const workflowAccounts = sessionContext?.sessionType === "workflow-run" ? sessionContext.customData.connectorAccounts : void 0;
|
|
@@ -360,9 +386,11 @@ function cancelConnectionObjective(conversationId) {
|
|
|
360
386
|
if (!wait) return;
|
|
361
387
|
runSqliteWriteTransaction(() => {
|
|
362
388
|
if (wait.queuedInputId) setSessionInputStatus(wait.queuedInputId, "cancelled");
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
389
|
+
const personalRequest = personalRequestForWait(wait.id);
|
|
390
|
+
const runs = new TaskRunRepository();
|
|
391
|
+
const taskRunId = wait.taskRunId ?? (personalRequest?.taskId ? runs.getActiveRoot(personalRequest.taskId)?.id : void 0);
|
|
392
|
+
if (taskRunId) {
|
|
393
|
+
const run = runs.get(taskRunId);
|
|
366
394
|
if (run?.status === "waiting") {
|
|
367
395
|
for (const taskWait of runs.listActiveWaits(run.taskId)) if (taskWait.condition.connectionWaitId === wait.id) runs.resolveWait({
|
|
368
396
|
waitId: taskWait.id,
|
|
@@ -394,6 +422,7 @@ function cancelConnectionObjective(conversationId) {
|
|
|
394
422
|
resolution: "cancelled",
|
|
395
423
|
intent: void 0
|
|
396
424
|
}, wait.version);
|
|
425
|
+
if (personalRequest && personalRequest.state !== "cancelled") updatePersonalRequest(personalRequest, { state: "cancelled" });
|
|
397
426
|
});
|
|
398
427
|
publishConnectionWait(conversationId);
|
|
399
428
|
}
|
|
@@ -414,6 +443,7 @@ var log, events;
|
|
|
414
443
|
var init_connection_wait_repository = __esmMin((() => {
|
|
415
444
|
init_logger();
|
|
416
445
|
init_task_run_repository();
|
|
446
|
+
init_request_repository();
|
|
417
447
|
init_connection();
|
|
418
448
|
init_connector_account_repository();
|
|
419
449
|
init_connector_repository();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
ALTER TABLE task_origin_links ADD COLUMN origin_transcript_id TEXT;
|
|
2
|
+
ALTER TABLE task_origin_links ADD COLUMN request_input_id TEXT;
|
|
3
|
+
UPDATE task_origin_links SET origin_transcript_id = (
|
|
4
|
+
SELECT active_transcript_id FROM sessions WHERE sessions.conversation_id = task_origin_links.conversation_id
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
CREATE TABLE task_run_outcomes (
|
|
8
|
+
task_run_id TEXT NOT NULL REFERENCES task_runs(run_id) ON DELETE CASCADE,
|
|
9
|
+
outcome_id TEXT NOT NULL,
|
|
10
|
+
assignment_epoch INTEGER NOT NULL,
|
|
11
|
+
outcome_json TEXT NOT NULL,
|
|
12
|
+
created_at INTEGER NOT NULL,
|
|
13
|
+
PRIMARY KEY(task_run_id, outcome_id)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
CREATE TABLE task_result_deliveries (
|
|
17
|
+
delivery_id TEXT PRIMARY KEY,
|
|
18
|
+
task_run_id TEXT NOT NULL REFERENCES task_runs(run_id) ON DELETE CASCADE,
|
|
19
|
+
conversation_id TEXT NOT NULL REFERENCES sessions(conversation_id) ON DELETE CASCADE,
|
|
20
|
+
payload_json TEXT NOT NULL,
|
|
21
|
+
status TEXT NOT NULL CHECK(status IN ('pending', 'delivered', 'stale', 'failed')),
|
|
22
|
+
message_entry_id TEXT,
|
|
23
|
+
attempts INTEGER NOT NULL DEFAULT 0,
|
|
24
|
+
next_attempt_at INTEGER NOT NULL,
|
|
25
|
+
last_error TEXT,
|
|
26
|
+
created_at INTEGER NOT NULL,
|
|
27
|
+
delivered_at INTEGER,
|
|
28
|
+
notified_at INTEGER,
|
|
29
|
+
UNIQUE(task_run_id, conversation_id)
|
|
30
|
+
);
|
|
31
|
+
CREATE INDEX idx_task_result_deliveries_pending
|
|
32
|
+
ON task_result_deliveries(status, next_attempt_at);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
CREATE TABLE personal_requests (
|
|
2
|
+
request_id TEXT PRIMARY KEY,
|
|
3
|
+
conversation_id TEXT NOT NULL REFERENCES sessions(conversation_id) ON DELETE CASCADE,
|
|
4
|
+
transcript_id TEXT NOT NULL,
|
|
5
|
+
input_id TEXT NOT NULL,
|
|
6
|
+
idempotency_key TEXT NOT NULL,
|
|
7
|
+
request_hash TEXT NOT NULL,
|
|
8
|
+
objective TEXT NOT NULL,
|
|
9
|
+
connector_id TEXT NOT NULL,
|
|
10
|
+
executor_agent_id TEXT NOT NULL,
|
|
11
|
+
account_id TEXT,
|
|
12
|
+
parameters_json TEXT NOT NULL,
|
|
13
|
+
state TEXT NOT NULL CHECK(state IN ('preflighting','waiting_connection','queued','running','completed','failed','cancelled')),
|
|
14
|
+
connection_wait_id TEXT UNIQUE,
|
|
15
|
+
task_id TEXT UNIQUE REFERENCES tasks(task_id) ON DELETE SET NULL,
|
|
16
|
+
result_json TEXT,
|
|
17
|
+
result_run_id TEXT,
|
|
18
|
+
delivery_entry_id TEXT,
|
|
19
|
+
notified_at INTEGER,
|
|
20
|
+
delivery_attempts INTEGER NOT NULL DEFAULT 0,
|
|
21
|
+
delivery_next_attempt_at INTEGER NOT NULL DEFAULT 0,
|
|
22
|
+
delivery_error TEXT,
|
|
23
|
+
version INTEGER NOT NULL DEFAULT 1,
|
|
24
|
+
created_at INTEGER NOT NULL,
|
|
25
|
+
updated_at INTEGER NOT NULL,
|
|
26
|
+
UNIQUE(conversation_id, transcript_id, idempotency_key)
|
|
27
|
+
);
|
|
28
|
+
CREATE INDEX idx_personal_requests_conversation ON personal_requests(conversation_id, created_at);
|
|
@@ -3,7 +3,7 @@ import type { ApplyMigrationsOptions } from './types.js';
|
|
|
3
3
|
/** Baseline schema version applied from schema.sql on first open. */
|
|
4
4
|
export declare const XOPC_DB_BASELINE_SCHEMA_VERSION = 165;
|
|
5
5
|
/** Latest schema version this release supports (increment when adding migrations). */
|
|
6
|
-
export declare const XOPC_DB_SCHEMA_VERSION =
|
|
6
|
+
export declare const XOPC_DB_SCHEMA_VERSION = 232;
|
|
7
7
|
export declare function resolveMigrationsDir(override?: string): string;
|
|
8
8
|
/**
|
|
9
9
|
* Apply sequential SQL migrations from (currentVersion + 1) through targetVersion.
|
|
@@ -57,7 +57,7 @@ function applySingleMigration(db, migration, discardOldScenes = false) {
|
|
|
57
57
|
*/
|
|
58
58
|
function applyPendingMigrations(db, options = {}) {
|
|
59
59
|
db.function("xopc_operation_id", () => currentOperationId() ?? null);
|
|
60
|
-
const targetVersion = options.targetVersion ??
|
|
60
|
+
const targetVersion = options.targetVersion ?? 232;
|
|
61
61
|
let currentVersion = readSchemaVersion(db);
|
|
62
62
|
if (currentVersion > targetVersion) throw new DatabaseSchemaTooNewError(currentVersion, targetVersion);
|
|
63
63
|
if (!options.migrationsDir && currentVersion < 165) throw new DatabaseSchemaTooOldError(currentVersion, 165);
|
|
@@ -95,7 +95,7 @@ function applyPendingMigrations(db, options = {}) {
|
|
|
95
95
|
}
|
|
96
96
|
/** Inspect schema version without mutating the database. */
|
|
97
97
|
function inspectSchemaMigrationStatus(db, options = {}) {
|
|
98
|
-
const appVersion = options.targetVersion ??
|
|
98
|
+
const appVersion = options.targetVersion ?? 232;
|
|
99
99
|
const dbVersion = readSchemaVersion(db);
|
|
100
100
|
if (dbVersion > appVersion) return {
|
|
101
101
|
dbVersion,
|
|
@@ -137,7 +137,7 @@ var init_runner = __esmMin((() => {
|
|
|
137
137
|
init_errors();
|
|
138
138
|
log = createLogger("Sqlite:Migrations");
|
|
139
139
|
XOPC_DB_BASELINE_SCHEMA_VERSION = 165;
|
|
140
|
-
XOPC_DB_SCHEMA_VERSION =
|
|
140
|
+
XOPC_DB_SCHEMA_VERSION = 232;
|
|
141
141
|
}));
|
|
142
142
|
//#endregion
|
|
143
143
|
init_runner();
|
|
@@ -3,6 +3,7 @@ import { getSqliteDatabase, init_transaction, runSqliteWriteTransaction } from "
|
|
|
3
3
|
import { validateConversationId, validateTranscriptId } from "../../../packages/gateway-contract/src/conversation-identity.js";
|
|
4
4
|
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
5
5
|
import { init_session_instance_repository, readCurrentTranscriptId } from "./session-instance-repository.js";
|
|
6
|
+
import { TaskRunRepository, init_task_run_repository } from "../../tasks/task-run-repository.js";
|
|
6
7
|
import { buildDefaultSessionMetadata, init_session_metadata } from "./session-metadata.js";
|
|
7
8
|
import { init_timestamps, optionalTimestampToMs } from "./timestamps.js";
|
|
8
9
|
import { buildGlobalSessionStats, init_row_mappers, metadataToSessionInsert, sessionRowToMetadata } from "./row-mappers.js";
|
|
@@ -311,6 +312,37 @@ function deleteSessionRecord(conversationId) {
|
|
|
311
312
|
db.prepare(`UPDATE transcripts SET status = 'archived', archive_reason = 'delete', archived_at = ?
|
|
312
313
|
WHERE transcript_id = ?`).run(now, existing.active_transcript_id);
|
|
313
314
|
cancelConnectionObjective(conversationId);
|
|
315
|
+
if (db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'personal_requests'").get()) {
|
|
316
|
+
const requests = db.prepare("SELECT task_id FROM personal_requests WHERE conversation_id = ? AND task_id IS NOT NULL").all(conversationId);
|
|
317
|
+
const runs = new TaskRunRepository();
|
|
318
|
+
for (const request of requests) {
|
|
319
|
+
const run = runs.getActiveRoot(request.task_id);
|
|
320
|
+
if (!run) continue;
|
|
321
|
+
for (const wait of runs.listActiveWaits(request.task_id)) runs.resolveWait({
|
|
322
|
+
waitId: wait.id,
|
|
323
|
+
actor: { kind: "user" },
|
|
324
|
+
resolution: { cancelled: true }
|
|
325
|
+
});
|
|
326
|
+
runs.finalize({
|
|
327
|
+
runId: run.id,
|
|
328
|
+
expectedVersion: run.version,
|
|
329
|
+
actor: { kind: "user" },
|
|
330
|
+
receipt: {
|
|
331
|
+
status: "cancelled",
|
|
332
|
+
summary: "Originating Personal conversation deleted",
|
|
333
|
+
changes: [],
|
|
334
|
+
evidence: [],
|
|
335
|
+
verification: {
|
|
336
|
+
status: "unverified",
|
|
337
|
+
checks: []
|
|
338
|
+
},
|
|
339
|
+
remainingWork: [],
|
|
340
|
+
needsUser: false,
|
|
341
|
+
completionVerdict: "not_achieved"
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
314
346
|
db.prepare(`DELETE FROM sessions WHERE conversation_id = ?`).run(conversationId);
|
|
315
347
|
return true;
|
|
316
348
|
});
|
|
@@ -334,6 +366,7 @@ function resolveSessionAgentId(conversationId) {
|
|
|
334
366
|
}
|
|
335
367
|
var init_session_repository = __esmMin((() => {
|
|
336
368
|
init_connection_wait_repository();
|
|
369
|
+
init_task_run_repository();
|
|
337
370
|
init_src();
|
|
338
371
|
init_changes();
|
|
339
372
|
init_session_metadata();
|
|
@@ -2,10 +2,10 @@ import { ProductReadContracts } from "../../../packages/gateway-contract/src/cap
|
|
|
2
2
|
import { init_src } from "../../../packages/gateway-contract/src/index.js";
|
|
3
3
|
import { TaskRepository, init_task_repository } from "../task-repository.js";
|
|
4
4
|
import { TaskRunRepository, init_task_run_repository } from "../task-run-repository.js";
|
|
5
|
-
import { TaskConversationRepository } from "../task-conversation-repository.js";
|
|
6
|
-
import { TaskReadModelProjector } from "../task-read-model-projector.js";
|
|
7
5
|
import { CapabilityError } from "../../capabilities/runtime/errors.js";
|
|
8
6
|
import { defineReadCapability } from "../../capabilities/runtime/dispatcher.js";
|
|
7
|
+
import { TaskConversationRepository } from "../task-conversation-repository.js";
|
|
8
|
+
import { TaskReadModelProjector } from "../task-read-model-projector.js";
|
|
9
9
|
import { TaskContextRepository } from "../task-context-repository.js";
|
|
10
10
|
import { TaskDependencyService } from "../task-dependency-service.js";
|
|
11
11
|
import { TaskCriterionReviewRepository } from "../task-criterion-review-repository.js";
|
|
@@ -10,6 +10,7 @@ import { TaskContextRepository } from "./task-context-repository.js";
|
|
|
10
10
|
import { TaskDependencyService } from "./task-dependency-service.js";
|
|
11
11
|
import { TaskCriterionReviewRepository } from "./task-criterion-review-repository.js";
|
|
12
12
|
import { TaskCollaborationRepository } from "./task-collaboration-repository.js";
|
|
13
|
+
import { TaskResultDeliveryRepository } from "./task-result-delivery-repository.js";
|
|
13
14
|
import { createHash, randomUUID } from "node:crypto";
|
|
14
15
|
//#region src/tasks/task-application-service.ts
|
|
15
16
|
init_src();
|
|
@@ -97,6 +98,11 @@ var TaskApplicationService = class {
|
|
|
97
98
|
if (input.originConversationId) {
|
|
98
99
|
if (db.prepare(`INSERT INTO task_origin_links (task_id, conversation_id, created_at)
|
|
99
100
|
SELECT ?, conversation_id, ? FROM sessions WHERE conversation_id = ?`).run(task.id, task.createdAt, input.originConversationId).changes !== 1) throw new Error("Task origin conversation not found");
|
|
101
|
+
db.prepare(`UPDATE task_origin_links SET
|
|
102
|
+
origin_transcript_id = (SELECT active_transcript_id FROM sessions WHERE conversation_id = ?),
|
|
103
|
+
request_input_id = (SELECT id FROM session_inputs WHERE conversation_id = ?
|
|
104
|
+
AND status = 'running' ORDER BY created_at_ms DESC LIMIT 1)
|
|
105
|
+
WHERE task_id = ?`).run(input.originConversationId, input.originConversationId, task.id);
|
|
100
106
|
db.prepare(`INSERT INTO task_main_agent_links (task_id, agent_id, origin_conversation_id, created_at)
|
|
101
107
|
SELECT ?, agent_id, conversation_id, ? FROM sessions WHERE conversation_id = ?`).run(task.id, task.createdAt, input.originConversationId);
|
|
102
108
|
}
|
|
@@ -491,6 +497,7 @@ var TaskApplicationService = class {
|
|
|
491
497
|
body: input.receipt.summary || (input.receipt.status === "succeeded" ? "TaskRun completed" : "TaskRun failed"),
|
|
492
498
|
idempotencyKey: `task-run-receipt:${run.id}`
|
|
493
499
|
});
|
|
500
|
+
if (input.receipt.status === "succeeded" || input.receipt.status === "failed") new TaskResultDeliveryRepository().enqueue(run.id, input.receipt.summary, input.receipt.status, input.resultText);
|
|
494
501
|
if (input.receipt.status !== "succeeded") {
|
|
495
502
|
const model = this.#projector.project(task);
|
|
496
503
|
if (!input.suppressAttention) enqueueTaskAttentionRequiredEvent(db, {
|
|
@@ -145,6 +145,7 @@ function buildTaskExecutionDirective(conversationId) {
|
|
|
145
145
|
handoffPayload ? `Handoff snapshot: ${handoffPayload}` : "",
|
|
146
146
|
collaboration.length ? `Recent task collaboration:\n${collaboration.map((entry) => `- ${entry.sequence} ${entry.authorKind} ${entry.kind}: ${JSON.stringify(entry.body.slice(0, 1e3))}`).join("\n")}` : "",
|
|
147
147
|
"Report meaningful progress with xopc_use task collaboration_post. If blocked, post a question and stop this execution turn until answered.",
|
|
148
|
+
"For user-facing files, publish completed outputs with publish_artifacts before finishing. image_generate already publishes its images. Return structured artifact references rather than only local file paths. Published final outcomes are delivered automatically to the originating chat. Keep the final summary short and distinguish generated outputs from verified or accepted results.",
|
|
148
149
|
"Take safe in-scope steps and produce inspectable evidence. Do not claim completion without verification.",
|
|
149
150
|
"</xopc_task_execution>"
|
|
150
151
|
].filter(Boolean).join("\n");
|
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
import { createLogger } from "../utils/logger/index.js";
|
|
2
2
|
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { TaskRunRepository, init_task_run_repository } from "./task-run-repository.js";
|
|
4
|
+
import { init_request_repository, personalRequestForTask } from "../personal-agent/request-repository.js";
|
|
3
5
|
import { TaskCollaborationRepository } from "./task-collaboration-repository.js";
|
|
6
|
+
import { TaskResultDeliveryRepository } from "./task-result-delivery-repository.js";
|
|
4
7
|
//#region src/tasks/task-main-update-delivery.ts
|
|
5
8
|
init_logger();
|
|
9
|
+
init_task_run_repository();
|
|
10
|
+
init_request_repository();
|
|
6
11
|
const log = createLogger("TaskMainUpdateDelivery");
|
|
7
12
|
var TaskMainUpdateDelivery = class {
|
|
8
13
|
#entries = new TaskCollaborationRepository();
|
|
9
14
|
async drain(input, limit = 20) {
|
|
10
15
|
let delivered = 0;
|
|
11
16
|
for (const { entry, conversationId, decision, decisionReason } of this.#entries.pendingMainUpdates(limit)) {
|
|
17
|
+
if ([
|
|
18
|
+
"result",
|
|
19
|
+
"failure",
|
|
20
|
+
"progress"
|
|
21
|
+
].includes(entry.kind) && personalRequestForTask(entry.taskId)) {
|
|
22
|
+
this.#entries.markMainUpdateDelivered(entry.id);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const results = new TaskResultDeliveryRepository();
|
|
26
|
+
const isResult = entry.kind === "result" && entry.taskRunId;
|
|
27
|
+
if (isResult && results.hasForRun(entry.taskRunId)) {
|
|
28
|
+
this.#entries.markMainUpdateDelivered(entry.id);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (isResult && results.hasCapturedOutcome(entry.taskRunId) && [
|
|
32
|
+
"running",
|
|
33
|
+
"waiting",
|
|
34
|
+
"verifying"
|
|
35
|
+
].includes(new TaskRunRepository().get(entry.taskRunId)?.status ?? "")) {
|
|
36
|
+
this.#entries.deferMainUpdate(entry.id);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
12
39
|
if (!input.isAvailable(conversationId)) {
|
|
13
40
|
this.#entries.deferMainUpdate(entry.id);
|
|
14
41
|
continue;
|
|
@@ -31,6 +58,10 @@ var TaskMainUpdateDelivery = class {
|
|
|
31
58
|
entry
|
|
32
59
|
});
|
|
33
60
|
if (!decision) this.#entries.decideMainUpdate(entry.id, verdict.notify ? "notify" : "silent", verdict.reason);
|
|
61
|
+
if (isResult && results.hasForRun(entry.taskRunId)) {
|
|
62
|
+
this.#entries.markMainUpdateDelivered(entry.id);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
34
65
|
if (!verdict.notify) {
|
|
35
66
|
this.#entries.markMainUpdateDelivered(entry.id);
|
|
36
67
|
delivered += 1;
|
|
@@ -40,7 +71,7 @@ var TaskMainUpdateDelivery = class {
|
|
|
40
71
|
`A delegated Task has a new ${entry.kind} update. Task ID: ${entry.taskId}.`,
|
|
41
72
|
`Collaboration entry ID: ${entry.id}.`,
|
|
42
73
|
`Your private notification decision: ${JSON.stringify(verdict.reason)}.`,
|
|
43
|
-
"Read the Task and collaboration board with xopc_use. If this is a worker question, first answer it from the Task brief or conversation with personal_task(command=\"answer\", taskId, questionId, instruction) when available; ask the user only for a genuinely missing fact. For failures, inspect the actual blocker and try a suitable alternative within the user’s authorization before reporting an impasse. Then tell the user what matters in your own words. Keep the response proportionate to the update and recent conversation. Do not expose this internal trigger or repeat already reported details. If a result receipt is generic, use the board for the actual outcome. A finished TaskRun is not proof that the Task passed verification or was accepted; check its receipt and use precise status language. Do not ask the user to close a Task unless requested. Use tools without preliminary user-facing commentary, then give one concise reply."
|
|
74
|
+
"Read the Task and collaboration board with personal_task(command=\"get\", taskId) when available, otherwise xopc_use. If this is a worker question, first answer it from the Task brief or conversation with personal_task(command=\"answer\", taskId, questionId, instruction) when available; ask the user only for a genuinely missing fact. For failures, inspect the actual blocker and try a suitable alternative within the user’s authorization before reporting an impasse. Then tell the user what matters in your own words. Keep the response proportionate to the update and recent conversation. Do not expose this internal trigger or repeat already reported details. If a result receipt is generic, use the board for the actual outcome. A finished TaskRun is not proof that the Task passed verification or was accepted; check its receipt and use precise status language. Do not ask the user to close a Task unless requested. Use tools without preliminary user-facing commentary, then give one concise reply."
|
|
44
75
|
].join("\n");
|
|
45
76
|
if (await input.submitAndConfirm({
|
|
46
77
|
conversationId,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type TurnOutcome } from '@xopcai/gateway-contract';
|
|
2
|
+
export declare function onTaskResultQueued(listener: () => void): () => void;
|
|
3
|
+
export interface TaskResultDeliveryRow {
|
|
4
|
+
delivery_id: string;
|
|
5
|
+
payload_json: string;
|
|
6
|
+
status: 'pending' | 'delivered' | 'stale' | 'failed';
|
|
7
|
+
attempts: number;
|
|
8
|
+
message_entry_id: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare class TaskResultDeliveryRepository {
|
|
11
|
+
capture(runId: string, value: TurnOutcome): void;
|
|
12
|
+
/** Called inside the run completion transaction, after stale receipts are rejected. */
|
|
13
|
+
enqueue(runId: string, summary: string, status: 'succeeded' | 'failed', resultText?: string): boolean;
|
|
14
|
+
hasForRun(runId: string): boolean;
|
|
15
|
+
hasCapturedOutcome(runId: string): boolean;
|
|
16
|
+
pending(limit?: number): TaskResultDeliveryRow[];
|
|
17
|
+
retry(id: string, error: string): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { createLogger } from "../utils/logger/index.js";
|
|
2
|
+
import { init_logger } from "../utils/logger.js";
|
|
3
|
+
import { afterSqliteCommit, getSqliteDatabase, init_transaction, runSqliteWriteTransaction } from "../storage/sqlite/transaction.js";
|
|
4
|
+
import { TurnOutcomeSchema } from "../../packages/gateway-contract/src/turn-outcome.js";
|
|
5
|
+
import { TaskResultDeliverySchema } from "../../packages/gateway-contract/src/task-result-delivery.js";
|
|
6
|
+
import { init_src } from "../../packages/gateway-contract/src/index.js";
|
|
7
|
+
import { TaskRunRepository, init_task_run_repository } from "./task-run-repository.js";
|
|
8
|
+
import { init_request_repository, personalRequestForTask } from "../personal-agent/request-repository.js";
|
|
9
|
+
import { TaskConversationRepository } from "./task-conversation-repository.js";
|
|
10
|
+
import { TaskCollaborationRepository } from "./task-collaboration-repository.js";
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
//#region src/tasks/task-result-delivery-repository.ts
|
|
13
|
+
init_src();
|
|
14
|
+
init_transaction();
|
|
15
|
+
init_task_run_repository();
|
|
16
|
+
init_logger();
|
|
17
|
+
init_request_repository();
|
|
18
|
+
const log = createLogger("TaskResultDelivery");
|
|
19
|
+
const queuedListeners = /* @__PURE__ */ new Set();
|
|
20
|
+
function onTaskResultQueued(listener) {
|
|
21
|
+
queuedListeners.add(listener);
|
|
22
|
+
return () => {
|
|
23
|
+
queuedListeners.delete(listener);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var TaskResultDeliveryRepository = class {
|
|
27
|
+
capture(runId, value) {
|
|
28
|
+
const outcome = TurnOutcomeSchema.parse({
|
|
29
|
+
...value,
|
|
30
|
+
evidence: [],
|
|
31
|
+
changeSet: void 0,
|
|
32
|
+
summary: value.summary.slice(0, 2e3)
|
|
33
|
+
});
|
|
34
|
+
if (outcome.deliverables.length > 50 || JSON.stringify(outcome).length > 256e3) throw new Error("Task outcome exceeds delivery limits");
|
|
35
|
+
const run = new TaskRunRepository().get(runId);
|
|
36
|
+
if (!run || ![
|
|
37
|
+
"running",
|
|
38
|
+
"waiting",
|
|
39
|
+
"verifying"
|
|
40
|
+
].includes(run.status)) return;
|
|
41
|
+
const state = new TaskConversationRepository().getState(run.taskId);
|
|
42
|
+
if (!state || state.activeConversationId !== run.conversationId) return;
|
|
43
|
+
getSqliteDatabase().prepare(`INSERT INTO task_run_outcomes
|
|
44
|
+
(task_run_id, outcome_id, assignment_epoch, outcome_json, created_at)
|
|
45
|
+
VALUES (?, ?, ?, ?, ?) ON CONFLICT(task_run_id, outcome_id) DO NOTHING`).run(runId, outcome.outcomeId, state.assignmentEpoch, JSON.stringify(outcome), Date.now());
|
|
46
|
+
}
|
|
47
|
+
/** Called inside the run completion transaction, after stale receipts are rejected. */
|
|
48
|
+
enqueue(runId, summary, status, resultText) {
|
|
49
|
+
const db = getSqliteDatabase();
|
|
50
|
+
const run = new TaskRunRepository().get(runId);
|
|
51
|
+
if (!run || run.parentRunId) return false;
|
|
52
|
+
const state = new TaskConversationRepository().getState(run.taskId);
|
|
53
|
+
if (!state || state.activeConversationId !== run.conversationId) return false;
|
|
54
|
+
const origin = db.prepare(`SELECT origin.*, task.title FROM task_origin_links origin
|
|
55
|
+
JOIN tasks task ON task.task_id = origin.task_id
|
|
56
|
+
WHERE origin.task_id = ?`).get(run.taskId);
|
|
57
|
+
if (!origin?.origin_transcript_id) return false;
|
|
58
|
+
const outcomes = db.prepare(`SELECT outcome_json FROM task_run_outcomes
|
|
59
|
+
WHERE task_run_id = ? AND assignment_epoch = ? ORDER BY created_at, rowid LIMIT 100`).all(runId, state.assignmentEpoch).map((row) => TurnOutcomeSchema.parse(JSON.parse(row.outcome_json)));
|
|
60
|
+
const latest = outcomes.at(-1);
|
|
61
|
+
if (!latest) return false;
|
|
62
|
+
const artifacts = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const outcome of outcomes) for (const item of outcome.deliverables) artifacts.set(item.sourceFileId ?? item.artifactId, item);
|
|
64
|
+
const deliverables = [...artifacts.values()].slice(-50);
|
|
65
|
+
const text = resultText?.trim() && resultText.trim() !== "NO_REPLY" ? resultText.trim().slice(0, 8e3) : void 0;
|
|
66
|
+
if (!deliverables.length && (!text || status !== "succeeded")) return false;
|
|
67
|
+
if (!deliverables.length && personalRequestForTask(run.taskId)) return false;
|
|
68
|
+
const outcome = {
|
|
69
|
+
...latest,
|
|
70
|
+
deliverables,
|
|
71
|
+
evidence: [],
|
|
72
|
+
changeSet: void 0,
|
|
73
|
+
summary: summary.slice(0, 2e3),
|
|
74
|
+
status: status === "failed" || deliverables.some((item) => item.availability !== "available") ? "partial" : "succeeded"
|
|
75
|
+
};
|
|
76
|
+
const now = Date.now();
|
|
77
|
+
const delivery = TaskResultDeliverySchema.parse({
|
|
78
|
+
version: 1,
|
|
79
|
+
deliveryId: randomUUID(),
|
|
80
|
+
taskId: run.taskId,
|
|
81
|
+
taskRunId: runId,
|
|
82
|
+
taskTitle: origin.title.slice(0, 300),
|
|
83
|
+
conversationId: origin.conversation_id,
|
|
84
|
+
originTranscriptId: origin.origin_transcript_id,
|
|
85
|
+
...origin.request_input_id ? { requestInputId: origin.request_input_id } : {},
|
|
86
|
+
assignmentEpoch: state.assignmentEpoch,
|
|
87
|
+
outcome,
|
|
88
|
+
...text ? { text } : {},
|
|
89
|
+
createdAt: now
|
|
90
|
+
});
|
|
91
|
+
db.prepare(`INSERT INTO task_result_deliveries
|
|
92
|
+
(delivery_id, task_run_id, conversation_id, payload_json, status, next_attempt_at, created_at)
|
|
93
|
+
VALUES (?, ?, ?, ?, 'pending', ?, ?) ON CONFLICT(task_run_id, conversation_id) DO NOTHING`).run(delivery.deliveryId, runId, origin.conversation_id, JSON.stringify(delivery), now, now);
|
|
94
|
+
db.prepare(`UPDATE task_main_update_deliveries SET status = 'delivered', decision = 'silent',
|
|
95
|
+
decision_reason = 'Structured task result delivery', updated_at = ?
|
|
96
|
+
WHERE entry_id IN (SELECT entry_id FROM task_collaboration_entries
|
|
97
|
+
WHERE task_run_id = ? AND kind IN ('result', 'progress'))`).run(now, runId);
|
|
98
|
+
afterSqliteCommit(() => {
|
|
99
|
+
for (const listener of queuedListeners) try {
|
|
100
|
+
listener();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
log.warn({
|
|
103
|
+
err,
|
|
104
|
+
runId
|
|
105
|
+
}, "Task result wake failed; polling will recover");
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
hasForRun(runId) {
|
|
111
|
+
return Boolean(getSqliteDatabase().prepare(`SELECT 1 FROM task_result_deliveries
|
|
112
|
+
WHERE task_run_id = ? AND status IN ('pending', 'delivered')`).get(runId));
|
|
113
|
+
}
|
|
114
|
+
hasCapturedOutcome(runId) {
|
|
115
|
+
return Boolean(getSqliteDatabase().prepare("SELECT 1 FROM task_run_outcomes WHERE task_run_id = ? LIMIT 1").get(runId));
|
|
116
|
+
}
|
|
117
|
+
pending(limit = 20) {
|
|
118
|
+
return getSqliteDatabase().prepare(`SELECT * FROM task_result_deliveries
|
|
119
|
+
WHERE status IN ('pending', 'delivered') AND next_attempt_at <= ? AND notified_at IS NULL
|
|
120
|
+
ORDER BY created_at LIMIT ?`).all(Date.now(), limit);
|
|
121
|
+
}
|
|
122
|
+
retry(id, error) {
|
|
123
|
+
runSqliteWriteTransaction((db) => {
|
|
124
|
+
db.prepare(`UPDATE task_result_deliveries SET attempts = attempts + 1,
|
|
125
|
+
status = CASE WHEN status = 'pending' AND attempts >= 7 THEN 'failed' ELSE status END,
|
|
126
|
+
notified_at = CASE WHEN status = 'delivered' AND attempts >= 7 THEN -1 ELSE notified_at END,
|
|
127
|
+
next_attempt_at = ? + MIN(60000, 1000 * (1 << MIN(attempts, 6))), last_error = ?
|
|
128
|
+
WHERE delivery_id = ? AND status IN ('pending', 'delivered')`).run(Date.now(), error.slice(0, 500), id);
|
|
129
|
+
const row = db.prepare("SELECT task_run_id FROM task_result_deliveries WHERE delivery_id = ? AND status = 'failed'").get(id);
|
|
130
|
+
const run = row ? new TaskRunRepository().get(row.task_run_id) : void 0;
|
|
131
|
+
if (run) new TaskCollaborationRepository().append({
|
|
132
|
+
taskId: run.taskId,
|
|
133
|
+
taskRunId: run.id,
|
|
134
|
+
authorKind: "system",
|
|
135
|
+
authorId: "task-result-delivery",
|
|
136
|
+
kind: "failure",
|
|
137
|
+
body: "The task produced results, but delivery to the main chat failed. Inspect the published artifacts and retry delivery; do not regenerate paid outputs just to send them.",
|
|
138
|
+
idempotencyKey: `task-result-delivery-failed:${id}`
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
//#endregion
|
|
144
|
+
export { TaskResultDeliveryRepository, onTaskResultQueued };
|