@botbotgo/agent-harness 0.0.475 → 0.0.476
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/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,36 +1,8 @@
|
|
|
1
|
-
function
|
|
2
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
3
|
-
}
|
|
4
|
-
function parseJson(value) {
|
|
5
|
-
return JSON.parse(asString(value));
|
|
6
|
-
}
|
|
7
|
-
function nowIso() {
|
|
8
|
-
return new Date(Date.now()).toISOString();
|
|
9
|
-
}
|
|
10
|
-
export class SqliteRequestContextStore {
|
|
11
|
-
db;
|
|
12
|
-
constructor(db) {
|
|
13
|
-
this.db = db;
|
|
14
|
-
}
|
|
15
|
-
async saveRequestInput(sessionId, requestId, request) {
|
|
16
|
-
await this.db.execute(`INSERT OR REPLACE INTO request_inputs
|
|
1
|
+
function r(n){return typeof n=="string"?n:String(n??"")}function o(n){return JSON.parse(r(n))}function a(){return new Date(Date.now()).toISOString()}class c{db;constructor(t){this.db=t}async saveRequestInput(t,e,s){await this.db.execute(`INSERT OR REPLACE INTO request_inputs
|
|
17
2
|
(request_id, session_id, request_json, saved_at)
|
|
18
|
-
VALUES (?, ?, ?, ?)`,
|
|
19
|
-
}
|
|
20
|
-
async getRequestInput(sessionId, requestId) {
|
|
21
|
-
const row = await this.db.selectOne("SELECT request_json FROM request_inputs WHERE session_id = ? AND request_id = ?", [sessionId, requestId]);
|
|
22
|
-
return row ? parseJson(row.request_json) : null;
|
|
23
|
-
}
|
|
24
|
-
async clearRequestInput(sessionId, requestId) {
|
|
25
|
-
await this.db.execute("DELETE FROM request_inputs WHERE session_id = ? AND request_id = ?", [sessionId, requestId]);
|
|
26
|
-
}
|
|
27
|
-
async appendSessionMessage(sessionId, message) {
|
|
28
|
-
await this.db.execute(`INSERT INTO session_messages
|
|
3
|
+
VALUES (?, ?, ?, ?)`,[e,t,JSON.stringify(s),s.savedAt])}async getRequestInput(t,e){const s=await this.db.selectOne("SELECT request_json FROM request_inputs WHERE session_id = ? AND request_id = ?",[t,e]);return s?o(s.request_json):null}async clearRequestInput(t,e){await this.db.execute("DELETE FROM request_inputs WHERE session_id = ? AND request_id = ?",[t,e])}async appendSessionMessage(t,e){await this.db.execute(`INSERT INTO session_messages
|
|
29
4
|
(session_id, role, content_json, request_id, created_at)
|
|
30
|
-
VALUES (?, ?, ?, ?, ?)`,
|
|
31
|
-
}
|
|
32
|
-
async listSessionMessages(sessionId, limit = 12) {
|
|
33
|
-
const rows = await this.db.selectAll(`SELECT role, content_json, request_id, created_at
|
|
5
|
+
VALUES (?, ?, ?, ?, ?)`,[t,e.role,JSON.stringify(e.content),e.requestId,e.createdAt])}async listSessionMessages(t,e=12){return(await this.db.selectAll(`SELECT role, content_json, request_id, created_at
|
|
34
6
|
FROM (
|
|
35
7
|
SELECT role, content_json, request_id, created_at, id
|
|
36
8
|
FROM session_messages
|
|
@@ -38,27 +10,6 @@ export class SqliteRequestContextStore {
|
|
|
38
10
|
ORDER BY created_at DESC, id DESC
|
|
39
11
|
LIMIT ?
|
|
40
12
|
) recent
|
|
41
|
-
ORDER BY created_at ASC, id ASC`,
|
|
42
|
-
return rows.map((row) => ({
|
|
43
|
-
role: asString(row.role),
|
|
44
|
-
content: parseJson(row.content_json),
|
|
45
|
-
requestId: asString(row.request_id),
|
|
46
|
-
createdAt: asString(row.created_at),
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
async saveRequestRecoveryIntent(sessionId, requestId, intent) {
|
|
50
|
-
const savedAt = typeof intent.savedAt === "string"
|
|
51
|
-
? (intent.savedAt)
|
|
52
|
-
: nowIso();
|
|
53
|
-
await this.db.execute(`INSERT OR REPLACE INTO recovery_intents
|
|
13
|
+
ORDER BY created_at ASC, id ASC`,[t,e])).map(i=>({role:r(i.role),content:o(i.content_json),requestId:r(i.request_id),createdAt:r(i.created_at)}))}async saveRequestRecoveryIntent(t,e,s){const i=typeof s.savedAt=="string"?s.savedAt:a();await this.db.execute(`INSERT OR REPLACE INTO recovery_intents
|
|
54
14
|
(request_id, session_id, intent_json, saved_at)
|
|
55
|
-
VALUES (?, ?, ?, ?)`,
|
|
56
|
-
}
|
|
57
|
-
async getRequestRecoveryIntent(sessionId, requestId) {
|
|
58
|
-
const row = await this.db.selectOne("SELECT intent_json FROM recovery_intents WHERE session_id = ? AND request_id = ?", [sessionId, requestId]);
|
|
59
|
-
return row ? parseJson(row.intent_json) : null;
|
|
60
|
-
}
|
|
61
|
-
async clearRequestRecoveryIntent(sessionId, requestId) {
|
|
62
|
-
await this.db.execute("DELETE FROM recovery_intents WHERE session_id = ? AND request_id = ?", [sessionId, requestId]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
15
|
+
VALUES (?, ?, ?, ?)`,[e,t,JSON.stringify(s),i])}async getRequestRecoveryIntent(t,e){const s=await this.db.selectOne("SELECT intent_json FROM recovery_intents WHERE session_id = ? AND request_id = ?",[t,e]);return s?o(s.intent_json):null}async clearRequestRecoveryIntent(t,e){await this.db.execute("DELETE FROM recovery_intents WHERE session_id = ? AND request_id = ?",[t,e])}}export{c as SqliteRequestContextStore};
|
|
@@ -1,120 +1,22 @@
|
|
|
1
|
-
function
|
|
2
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
3
|
-
}
|
|
4
|
-
function asNullableString(value) {
|
|
5
|
-
return value == null ? null : asString(value);
|
|
6
|
-
}
|
|
7
|
-
function asBoolean(value) {
|
|
8
|
-
return value === true || value === 1 || value === "1";
|
|
9
|
-
}
|
|
10
|
-
function nowIso() {
|
|
11
|
-
return new Date(Date.now()).toISOString();
|
|
12
|
-
}
|
|
13
|
-
export class SqliteRequestQueueStore {
|
|
14
|
-
db;
|
|
15
|
-
constructor(db) {
|
|
16
|
-
this.db = db;
|
|
17
|
-
}
|
|
18
|
-
mapQueuedRequest(row) {
|
|
19
|
-
return {
|
|
20
|
-
requestId: asString(row.request_id),
|
|
21
|
-
sessionId: asString(row.session_id),
|
|
22
|
-
priority: Number(row.priority ?? 0),
|
|
23
|
-
queueKey: asNullableString(row.queue_key),
|
|
24
|
-
enqueuedAt: asString(row.enqueued_at),
|
|
25
|
-
availableAt: asString(row.available_at),
|
|
26
|
-
claimedBy: asNullableString(row.claimed_by),
|
|
27
|
-
claimedAt: asNullableString(row.claimed_at),
|
|
28
|
-
leaseExpiresAt: asNullableString(row.lease_expires_at),
|
|
29
|
-
attemptCount: Number(row.attempt_count ?? 0),
|
|
30
|
-
lastError: asNullableString(row.last_error),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
mapRequestControl(row) {
|
|
34
|
-
return {
|
|
35
|
-
requestId: asString(row.request_id),
|
|
36
|
-
cancelRequested: asBoolean(row.cancel_requested),
|
|
37
|
-
cancelReason: asNullableString(row.cancel_reason),
|
|
38
|
-
cancelRequestedAt: asNullableString(row.cancel_requested_at),
|
|
39
|
-
heartbeatAt: asNullableString(row.heartbeat_at),
|
|
40
|
-
workerId: asNullableString(row.worker_id),
|
|
41
|
-
workerStartedAt: asNullableString(row.worker_started_at),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async enqueueRequest(input) {
|
|
45
|
-
const enqueuedAt = nowIso();
|
|
46
|
-
await this.db.execute(`INSERT OR REPLACE INTO request_queue
|
|
1
|
+
function u(s){return typeof s=="string"?s:String(s??"")}function a(s){return s==null?null:u(s)}function d(s){return s===!0||s===1||s==="1"}function i(){return new Date(Date.now()).toISOString()}class c{db;constructor(e){this.db=e}mapQueuedRequest(e){return{requestId:u(e.request_id),sessionId:u(e.session_id),priority:Number(e.priority??0),queueKey:a(e.queue_key),enqueuedAt:u(e.enqueued_at),availableAt:u(e.available_at),claimedBy:a(e.claimed_by),claimedAt:a(e.claimed_at),leaseExpiresAt:a(e.lease_expires_at),attemptCount:Number(e.attempt_count??0),lastError:a(e.last_error)}}mapRequestControl(e){return{requestId:u(e.request_id),cancelRequested:d(e.cancel_requested),cancelReason:a(e.cancel_reason),cancelRequestedAt:a(e.cancel_requested_at),heartbeatAt:a(e.heartbeat_at),workerId:a(e.worker_id),workerStartedAt:a(e.worker_started_at)}}async enqueueRequest(e){const t=i();await this.db.execute(`INSERT OR REPLACE INTO request_queue
|
|
47
2
|
(request_id, session_id, priority, queue_key, enqueued_at, available_at, claimed_by, claimed_at, lease_expires_at, attempt_count, last_error)
|
|
48
|
-
VALUES (?, ?, ?, ?, ?, ?, NULL, NULL, NULL, COALESCE((SELECT attempt_count FROM request_queue WHERE request_id = ?), 0), NULL)`, [
|
|
49
|
-
input.requestId,
|
|
50
|
-
input.sessionId,
|
|
51
|
-
input.priority ?? 0,
|
|
52
|
-
input.queueKey ?? null,
|
|
53
|
-
enqueuedAt,
|
|
54
|
-
input.availableAt ?? enqueuedAt,
|
|
55
|
-
input.requestId,
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
async getQueuedRequest(requestId) {
|
|
59
|
-
const row = await this.db.selectOne("SELECT * FROM request_queue WHERE request_id = ?", [requestId]);
|
|
60
|
-
return row ? this.mapQueuedRequest(row) : null;
|
|
61
|
-
}
|
|
62
|
-
async claimQueuedRequest(input) {
|
|
63
|
-
const claimedAt = input.claimedAt ?? nowIso();
|
|
64
|
-
await this.db.execute(`UPDATE request_queue
|
|
3
|
+
VALUES (?, ?, ?, ?, ?, ?, NULL, NULL, NULL, COALESCE((SELECT attempt_count FROM request_queue WHERE request_id = ?), 0), NULL)`,[e.requestId,e.sessionId,e.priority??0,e.queueKey??null,t,e.availableAt??t,e.requestId])}async getQueuedRequest(e){const t=await this.db.selectOne("SELECT * FROM request_queue WHERE request_id = ?",[e]);return t?this.mapQueuedRequest(t):null}async claimQueuedRequest(e){const t=e.claimedAt??i();await this.db.execute(`UPDATE request_queue
|
|
65
4
|
SET claimed_by = ?, claimed_at = ?, lease_expires_at = ?, attempt_count = attempt_count + 1
|
|
66
|
-
WHERE request_id = ? AND session_id = ?`,
|
|
67
|
-
await this.db.execute(`UPDATE request_control
|
|
5
|
+
WHERE request_id = ? AND session_id = ?`,[e.workerId,t,e.leaseExpiresAt,e.requestId,e.sessionId]),await this.db.execute(`UPDATE request_control
|
|
68
6
|
SET heartbeat_at = ?, worker_id = ?, worker_started_at = COALESCE(worker_started_at, ?)
|
|
69
|
-
WHERE request_id = ?`,
|
|
70
|
-
const claimed = await this.getQueuedRequest(input.requestId);
|
|
71
|
-
if (!claimed) {
|
|
72
|
-
throw new Error(`Missing queued request ${input.requestId}`);
|
|
73
|
-
}
|
|
74
|
-
return claimed;
|
|
75
|
-
}
|
|
76
|
-
async renewRequestLease(input) {
|
|
77
|
-
const heartbeatAt = input.heartbeatAt ?? nowIso();
|
|
78
|
-
await this.db.execute(`UPDATE request_queue
|
|
7
|
+
WHERE request_id = ?`,[t,e.workerId,t,e.requestId]);const r=await this.getQueuedRequest(e.requestId);if(!r)throw new Error(`Missing queued request ${e.requestId}`);return r}async renewRequestLease(e){const t=e.heartbeatAt??i();await this.db.execute(`UPDATE request_queue
|
|
79
8
|
SET lease_expires_at = ?, claimed_by = COALESCE(claimed_by, ?), claimed_at = COALESCE(claimed_at, ?)
|
|
80
|
-
WHERE request_id = ?`,
|
|
81
|
-
await this.db.execute(`UPDATE request_control
|
|
9
|
+
WHERE request_id = ?`,[e.leaseExpiresAt,e.workerId,t,e.requestId]),await this.db.execute(`UPDATE request_control
|
|
82
10
|
SET heartbeat_at = ?, worker_id = ?, worker_started_at = COALESCE(worker_started_at, ?)
|
|
83
|
-
WHERE request_id = ?`,
|
|
84
|
-
}
|
|
85
|
-
async releaseRequestClaim(requestId) {
|
|
86
|
-
await this.db.execute("DELETE FROM request_queue WHERE request_id = ?", [requestId]);
|
|
87
|
-
await this.db.execute(`UPDATE request_control
|
|
11
|
+
WHERE request_id = ?`,[t,e.workerId,t,e.requestId])}async releaseRequestClaim(e){await this.db.execute("DELETE FROM request_queue WHERE request_id = ?",[e]),await this.db.execute(`UPDATE request_control
|
|
88
12
|
SET heartbeat_at = NULL, worker_id = NULL, worker_started_at = NULL
|
|
89
|
-
WHERE request_id = ?`,
|
|
90
|
-
}
|
|
91
|
-
async listExpiredClaimedRequests(cutoffIso) {
|
|
92
|
-
const rows = await this.db.selectAll(`SELECT *
|
|
13
|
+
WHERE request_id = ?`,[e])}async listExpiredClaimedRequests(e){return(await this.db.selectAll(`SELECT *
|
|
93
14
|
FROM request_queue
|
|
94
15
|
WHERE claimed_by IS NOT NULL
|
|
95
16
|
AND lease_expires_at IS NOT NULL
|
|
96
17
|
AND lease_expires_at <= ?
|
|
97
|
-
ORDER BY lease_expires_at ASC, request_id ASC`, [
|
|
98
|
-
return rows.map((row) => this.mapQueuedRequest(row));
|
|
99
|
-
}
|
|
100
|
-
async getRequestControl(requestId) {
|
|
101
|
-
const row = await this.db.selectOne("SELECT * FROM request_control WHERE request_id = ?", [requestId]);
|
|
102
|
-
return row ? this.mapRequestControl(row) : null;
|
|
103
|
-
}
|
|
104
|
-
async requestRequestCancel(requestId, reason) {
|
|
105
|
-
const requestedAt = nowIso();
|
|
106
|
-
await this.db.execute(`UPDATE request_control
|
|
18
|
+
ORDER BY lease_expires_at ASC, request_id ASC`,[e])).map(r=>this.mapQueuedRequest(r))}async getRequestControl(e){const t=await this.db.selectOne("SELECT * FROM request_control WHERE request_id = ?",[e]);return t?this.mapRequestControl(t):null}async requestRequestCancel(e,t){const r=i();await this.db.execute(`UPDATE request_control
|
|
107
19
|
SET cancel_requested = 1, cancel_reason = ?, cancel_requested_at = ?
|
|
108
|
-
WHERE request_id = ?`,
|
|
109
|
-
const updated = await this.getRequestControl(requestId);
|
|
110
|
-
if (!updated) {
|
|
111
|
-
throw new Error(`Missing request control for ${requestId}`);
|
|
112
|
-
}
|
|
113
|
-
return updated;
|
|
114
|
-
}
|
|
115
|
-
async clearRequestCancel(requestId) {
|
|
116
|
-
await this.db.execute(`UPDATE request_control
|
|
20
|
+
WHERE request_id = ?`,[t??null,r,e]);const _=await this.getRequestControl(e);if(!_)throw new Error(`Missing request control for ${e}`);return _}async clearRequestCancel(e){await this.db.execute(`UPDATE request_control
|
|
117
21
|
SET cancel_requested = 0, cancel_reason = NULL, cancel_requested_at = NULL
|
|
118
|
-
WHERE request_id = ?`,
|
|
119
|
-
}
|
|
120
|
-
}
|
|
22
|
+
WHERE request_id = ?`,[e])}}export{c as SqliteRequestQueueStore};
|
|
@@ -1,86 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const SQLITE_BUSY_RETRY_DELAY_MS = 100;
|
|
3
|
-
export function asRow(value) {
|
|
4
|
-
return value;
|
|
5
|
-
}
|
|
6
|
-
export function asString(value) {
|
|
7
|
-
return typeof value === "string" ? value : String(value ?? "");
|
|
8
|
-
}
|
|
9
|
-
export function asNullableString(value) {
|
|
10
|
-
return value == null ? null : asString(value);
|
|
11
|
-
}
|
|
12
|
-
export function asBoolean(value) {
|
|
13
|
-
return value === true || value === 1 || value === "1";
|
|
14
|
-
}
|
|
15
|
-
export function parseJson(value) {
|
|
16
|
-
return JSON.parse(asString(value));
|
|
17
|
-
}
|
|
18
|
-
export function toSqliteUrl(filePath) {
|
|
19
|
-
return `file:${filePath}`;
|
|
20
|
-
}
|
|
21
|
-
export function nowIso() {
|
|
22
|
-
return new Date(Date.now()).toISOString();
|
|
23
|
-
}
|
|
24
|
-
function runtimeSqliteErrorShouldIncludeSql(baseMessage) {
|
|
25
|
-
if (process.env.AGENT_HARNESS_RUNTIME_SQLITE_DEBUG === "1") {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
return /SQLITE_CONSTRAINT|FOREIGN KEY|UNIQUE constraint|NOT NULL/i.test(baseMessage);
|
|
29
|
-
}
|
|
30
|
-
function formatRuntimeSqliteErrorMessage(dbPath, sql, baseMessage) {
|
|
31
|
-
let detail = `agent-harness runtime SQLite (${dbPath}): ${baseMessage}`;
|
|
32
|
-
if (sql && runtimeSqliteErrorShouldIncludeSql(baseMessage)) {
|
|
33
|
-
const sqlPreview = sql.replace(/\s+/g, " ").trim();
|
|
34
|
-
const truncated = sqlPreview.length > 220 ? `${sqlPreview.slice(0, 220)}…` : sqlPreview;
|
|
35
|
-
detail += ` [sql=${truncated}]`;
|
|
36
|
-
}
|
|
37
|
-
return detail;
|
|
38
|
-
}
|
|
39
|
-
export function throwWrappedRuntimeSqliteError(dbPath, sql, error) {
|
|
40
|
-
const base = error instanceof Error ? error.message : String(error);
|
|
41
|
-
const wrapped = new Error(formatRuntimeSqliteErrorMessage(dbPath, sql, base));
|
|
42
|
-
wrapped.cause = error;
|
|
43
|
-
throw wrapped;
|
|
44
|
-
}
|
|
45
|
-
function collectErrorMessages(error) {
|
|
46
|
-
const messages = [];
|
|
47
|
-
let current = error;
|
|
48
|
-
while (current instanceof Error) {
|
|
49
|
-
messages.push(current.message);
|
|
50
|
-
current = current.cause;
|
|
51
|
-
}
|
|
52
|
-
if (typeof current === "string" && current.length > 0) {
|
|
53
|
-
messages.push(current);
|
|
54
|
-
}
|
|
55
|
-
return messages;
|
|
56
|
-
}
|
|
57
|
-
export function isSqliteBusyError(error) {
|
|
58
|
-
return collectErrorMessages(error).some((message) => /SQLITE_BUSY|database is locked/i.test(message));
|
|
59
|
-
}
|
|
60
|
-
export function sleep(ms) {
|
|
61
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
62
|
-
}
|
|
63
|
-
export async function executeWithBusyRetry(client, dbPath, sql, args, run) {
|
|
64
|
-
void client;
|
|
65
|
-
for (let attempt = 0;; attempt += 1) {
|
|
66
|
-
try {
|
|
67
|
-
return await run();
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
if (!isSqliteBusyError(error) || attempt >= SQLITE_BUSY_RETRY_ATTEMPTS) {
|
|
71
|
-
throwWrappedRuntimeSqliteError(dbPath, sql, error);
|
|
72
|
-
}
|
|
73
|
-
await sleep(Math.min(SQLITE_BUSY_RETRY_DELAY_MS * (attempt + 1), 1_000));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export function buildWhereClause(filters) {
|
|
78
|
-
const active = filters.filter(([, value]) => value !== undefined);
|
|
79
|
-
if (active.length === 0) {
|
|
80
|
-
return { clause: "", args: [] };
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
clause: ` WHERE ${active.map(([sql]) => sql).join(" AND ")}`,
|
|
84
|
-
args: active.map(([, value]) => value),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
1
|
+
const f=30,T=100;function _(t){return t}function u(t){return typeof t=="string"?t:String(t??"")}function g(t){return t==null?null:u(t)}function R(t){return t===!0||t===1||t==="1"}function m(t){return JSON.parse(u(t))}function x(t){return`file:${t}`}function h(){return new Date(Date.now()).toISOString()}function c(t){return process.env.AGENT_HARNESS_RUNTIME_SQLITE_DEBUG==="1"?!0:/SQLITE_CONSTRAINT|FOREIGN KEY|UNIQUE constraint|NOT NULL/i.test(t)}function a(t,r,e){let o=`agent-harness runtime SQLite (${t}): ${e}`;if(r&&c(e)){const n=r.replace(/\s+/g," ").trim(),i=n.length>220?`${n.slice(0,220)}\u2026`:n;o+=` [sql=${i}]`}return o}function S(t,r,e){const o=e instanceof Error?e.message:String(e),n=new Error(a(t,r,o));throw n.cause=e,n}function l(t){const r=[];let e=t;for(;e instanceof Error;)r.push(e.message),e=e.cause;return typeof e=="string"&&e.length>0&&r.push(e),r}function E(t){return l(t).some(r=>/SQLITE_BUSY|database is locked/i.test(r))}function p(t){return new Promise(r=>setTimeout(r,t))}async function I(t,r,e,o,n){for(let i=0;;i+=1)try{return await n()}catch(s){(!E(s)||i>=30)&&S(r,e,s),await p(Math.min(100*(i+1),1e3))}}function w(t){const r=t.filter(([,e])=>e!==void 0);return r.length===0?{clause:"",args:[]}:{clause:` WHERE ${r.map(([e])=>e).join(" AND ")}`,args:r.map(([,e])=>e)}}export{f as SQLITE_BUSY_RETRY_ATTEMPTS,T as SQLITE_BUSY_RETRY_DELAY_MS,R as asBoolean,g as asNullableString,_ as asRow,u as asString,w as buildWhereClause,I as executeWithBusyRetry,E as isSqliteBusyError,h as nowIso,m as parseJson,p as sleep,S as throwWrappedRuntimeSqliteError,x as toSqliteUrl};
|