@vibedeckx/darwin-arm64 0.3.44 → 0.3.45
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/bin.js +506 -125
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -185779,6 +185779,10 @@ var createScheduledRepos = (kdb, h) => ({
|
|
|
185779
185779
|
const row = await kdb.selectFrom("scheduled_tasks").selectAll().where("project_id", "=", projectId).where("source_session_id", "=", sessionId).where("source_tool_use_id", "=", toolUseId).executeTakeFirst();
|
|
185780
185780
|
return row ? mapTask(row) : void 0;
|
|
185781
185781
|
},
|
|
185782
|
+
listIdsBySourceSession: async (sessionId) => {
|
|
185783
|
+
const rows = await kdb.selectFrom("scheduled_tasks").select("id").where("source_session_id", "=", sessionId).where("source_tool_use_id", "is not", null).orderBy("id", "asc").execute();
|
|
185784
|
+
return rows.map((row) => row.id);
|
|
185785
|
+
},
|
|
185782
185786
|
getByProjectId: async (projectId) => {
|
|
185783
185787
|
const rows = await kdb.selectFrom("scheduled_tasks").selectAll().where("project_id", "=", projectId).orderBy("created_at", "asc").orderBy("id", "asc").execute();
|
|
185784
185788
|
return rows.map(mapTask);
|
|
@@ -186105,6 +186109,7 @@ async function deleteSessionSideRows(trx, sessionIds) {
|
|
|
186105
186109
|
const ids = [...sessionIds];
|
|
186106
186110
|
await trx.deleteFrom("agent_session_remote_grants").where("session_id", "in", ids).execute();
|
|
186107
186111
|
await trx.deleteFrom("agent_session_remote_touches").where("session_id", "in", ids).execute();
|
|
186112
|
+
await trx.deleteFrom("agent_session_retention_holds").where("session_id", "in", ids).execute();
|
|
186108
186113
|
}
|
|
186109
186114
|
|
|
186110
186115
|
// src/storage/repositories/core.ts
|
|
@@ -187085,6 +187090,10 @@ var retentionPredicate = (cutoff) => sql`
|
|
|
187085
187090
|
AND favorited_at IS NULL
|
|
187086
187091
|
AND status <> 'running'
|
|
187087
187092
|
AND ${visibleLifecycle}
|
|
187093
|
+
AND NOT EXISTS (
|
|
187094
|
+
SELECT 1 FROM agent_session_retention_holds h
|
|
187095
|
+
WHERE h.session_id = agent_sessions.id
|
|
187096
|
+
)
|
|
187088
187097
|
AND NOT EXISTS (
|
|
187089
187098
|
SELECT 1 FROM workflow_runs wr
|
|
187090
187099
|
WHERE wr.status IN (${sql.join(WORKFLOW_ACTIVE_STATUSES.map((s3) => sql`${s3}`))})
|
|
@@ -187685,6 +187694,12 @@ var createAgentSessionRepos = (kdb, h) => ({
|
|
|
187685
187694
|
const rows = await kdb.selectFrom("remote_session_mappings").selectAll().execute();
|
|
187686
187695
|
return rows.map(mapRemoteSessionMapping);
|
|
187687
187696
|
},
|
|
187697
|
+
// Same link test as projectRemotes.getByProjectAndServer: the
|
|
187698
|
+
// project_remotes row AND its remote_servers row (that lookup inner-joins).
|
|
187699
|
+
getAllWithLinkState: async () => {
|
|
187700
|
+
const rows = await kdb.selectFrom("remote_session_mappings as mapping").leftJoin("project_remotes as link", (join2) => join2.onRef("link.project_id", "=", "mapping.project_id").onRef("link.remote_server_id", "=", "mapping.remote_server_id")).leftJoin("remote_servers as server", "server.id", "link.remote_server_id").selectAll("mapping").select("server.id as linked_server_id").execute();
|
|
187701
|
+
return rows.map((row) => ({ ...mapRemoteSessionMapping(row), linked: row.linked_server_id != null }));
|
|
187702
|
+
},
|
|
187688
187703
|
listByProject: async (projectId, limit, consumer) => {
|
|
187689
187704
|
const rows = await projectedRemoteMappingBase(kdb).where(sql`case when mapping.workspace_checkout_id is null then mapping.project_id else workspace.project_id end = ${projectId}`).orderBy("mapping.local_session_id", "asc").limit(limit).execute();
|
|
187690
187705
|
rows.forEach((row) => observeProjectedRemoteMapping(consumer, row));
|
|
@@ -188248,6 +188263,36 @@ var createSessionRemoteTouchRepo = (kdb) => ({
|
|
|
188248
188263
|
}
|
|
188249
188264
|
});
|
|
188250
188265
|
|
|
188266
|
+
// src/storage/repositories/session-retention-holds.ts
|
|
188267
|
+
var createSessionRetentionHoldRepo = (kdb) => ({
|
|
188268
|
+
sessionRetentionHolds: {
|
|
188269
|
+
list: async (sessionId) => {
|
|
188270
|
+
const rows = await kdb.selectFrom("agent_session_retention_holds").select(["holder_kind", "holder_id"]).where("session_id", "=", sessionId).orderBy("holder_kind", "asc").orderBy("holder_id", "asc").execute();
|
|
188271
|
+
return rows.map((row) => ({ kind: row.holder_kind, id: row.holder_id }));
|
|
188272
|
+
},
|
|
188273
|
+
listSessionIds: async () => {
|
|
188274
|
+
const rows = await kdb.selectFrom("agent_session_retention_holds").select("session_id").distinct().orderBy("session_id", "asc").execute();
|
|
188275
|
+
return rows.map((row) => row.session_id);
|
|
188276
|
+
},
|
|
188277
|
+
replace: async (sessionId, holds) => {
|
|
188278
|
+
const unique = /* @__PURE__ */ new Map();
|
|
188279
|
+
for (const hold of holds) unique.set(`${hold.kind}\0${hold.id}`, hold);
|
|
188280
|
+
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
188281
|
+
await kdb.transaction().execute(async (trx) => {
|
|
188282
|
+
await trx.deleteFrom("agent_session_retention_holds").where("session_id", "=", sessionId).execute();
|
|
188283
|
+
if (unique.size > 0) {
|
|
188284
|
+
await trx.insertInto("agent_session_retention_holds").values([...unique.values()].map((hold) => ({
|
|
188285
|
+
session_id: sessionId,
|
|
188286
|
+
holder_kind: hold.kind,
|
|
188287
|
+
holder_id: hold.id,
|
|
188288
|
+
created_at: createdAt
|
|
188289
|
+
}))).execute();
|
|
188290
|
+
}
|
|
188291
|
+
});
|
|
188292
|
+
}
|
|
188293
|
+
}
|
|
188294
|
+
});
|
|
188295
|
+
|
|
188251
188296
|
// src/storage/repositories/merge-targets.ts
|
|
188252
188297
|
var createMergeTargetsRepo = (kdb) => ({
|
|
188253
188298
|
mergeTargets: {
|
|
@@ -188598,6 +188643,13 @@ var createSearchCacheRepos = (kdb, _h) => ({
|
|
|
188598
188643
|
if (projectIds.length === 0) return [];
|
|
188599
188644
|
return kdb.selectFrom("search_catalog_sync_state").select(["project_id", "target_id", "last_success_at", "last_attempt_at", "last_error"]).where("project_id", "in", projectIds).execute();
|
|
188600
188645
|
},
|
|
188646
|
+
getCachedSessionTitles: async (localSessionIds) => {
|
|
188647
|
+
const titles = /* @__PURE__ */ new Map();
|
|
188648
|
+
if (localSessionIds.length === 0) return titles;
|
|
188649
|
+
const rows = await kdb.selectFrom("session_search_cache").select(["local_session_id", "title"]).where("local_session_id", "in", [...localSessionIds]).where("deleted_at", "is", null).execute();
|
|
188650
|
+
for (const row of rows) titles.set(row.local_session_id, row.title);
|
|
188651
|
+
return titles;
|
|
188652
|
+
},
|
|
188601
188653
|
// Opportunistic freshness: called where a title transits the server
|
|
188602
188654
|
// anyway (remote title PATCH proxy + local AI title generation).
|
|
188603
188655
|
// UPDATE-only — a title alone must not fabricate a session's existence.
|
|
@@ -204924,6 +204976,20 @@ var initializeSchema = (db) => {
|
|
|
204924
204976
|
last_used_at TEXT NOT NULL,
|
|
204925
204977
|
PRIMARY KEY (session_id, remote_server_id)
|
|
204926
204978
|
);
|
|
204979
|
+
|
|
204980
|
+
-- What keeps a session out of the retention sweep besides a star: one row
|
|
204981
|
+
-- per (session, holder) \u2014 today a schedule proposed from that session.
|
|
204982
|
+
-- Owned by the machine the session lives on (the hub pushes the whole set
|
|
204983
|
+
-- to a worker), since retention runs there. Retention-only: a manual
|
|
204984
|
+
-- delete still goes through and removes the rows via deleteSessionSideRows.
|
|
204985
|
+
-- No FK on session_id, for the same reason as the grants table.
|
|
204986
|
+
CREATE TABLE IF NOT EXISTS agent_session_retention_holds (
|
|
204987
|
+
session_id TEXT NOT NULL,
|
|
204988
|
+
holder_kind TEXT NOT NULL,
|
|
204989
|
+
holder_id TEXT NOT NULL,
|
|
204990
|
+
created_at TEXT NOT NULL,
|
|
204991
|
+
PRIMARY KEY (session_id, holder_kind, holder_id)
|
|
204992
|
+
);
|
|
204927
204993
|
`);
|
|
204928
204994
|
const workspaceCheckoutsTable = db.prepare(
|
|
204929
204995
|
"SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'workspace_checkouts'"
|
|
@@ -206305,6 +206371,7 @@ var createSqliteStorage = async (dbPath) => {
|
|
|
206305
206371
|
...createCrossRemoteAuditRepo(kdb),
|
|
206306
206372
|
...createSessionRemoteGrantRepo(kdb),
|
|
206307
206373
|
...createSessionRemoteTouchRepo(kdb),
|
|
206374
|
+
...createSessionRetentionHoldRepo(kdb),
|
|
206308
206375
|
...createMergeTargetsRepo(kdb),
|
|
206309
206376
|
...createSearchCacheRepos(kdb, h),
|
|
206310
206377
|
...createWorkflowRunRepos(kdb),
|
|
@@ -207978,6 +208045,214 @@ ${GREEN}Done${info}${RESET}
|
|
|
207978
208045
|
}
|
|
207979
208046
|
};
|
|
207980
208047
|
|
|
208048
|
+
// src/trace-context.ts
|
|
208049
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
208050
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
208051
|
+
var VERSION3 = "00";
|
|
208052
|
+
var INVALID_VERSION = "ff";
|
|
208053
|
+
var ZERO_TRACE_ID = "0".repeat(32);
|
|
208054
|
+
var ZERO_SPAN_ID = "0".repeat(16);
|
|
208055
|
+
var HEX_2 = /^[0-9a-f]{2}$/;
|
|
208056
|
+
var HEX_16 = /^[0-9a-f]{16}$/;
|
|
208057
|
+
var HEX_32 = /^[0-9a-f]{32}$/;
|
|
208058
|
+
function parseTraceparent(value) {
|
|
208059
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
208060
|
+
if (typeof raw !== "string") return null;
|
|
208061
|
+
const parts = raw.split("-");
|
|
208062
|
+
if (parts.length < 4) return null;
|
|
208063
|
+
const [version2, traceId, spanId, flags] = parts;
|
|
208064
|
+
if (!HEX_2.test(version2) || version2 === INVALID_VERSION) return null;
|
|
208065
|
+
if (version2 === VERSION3 && parts.length !== 4) return null;
|
|
208066
|
+
if (!HEX_32.test(traceId) || traceId === ZERO_TRACE_ID) return null;
|
|
208067
|
+
if (!HEX_16.test(spanId) || spanId === ZERO_SPAN_ID) return null;
|
|
208068
|
+
if (!HEX_2.test(flags)) return null;
|
|
208069
|
+
return { traceId, spanId, flags };
|
|
208070
|
+
}
|
|
208071
|
+
function formatTraceparent(ctx) {
|
|
208072
|
+
return `${VERSION3}-${ctx.traceId}-${ctx.spanId}-${ctx.sampled ? "01" : "00"}`;
|
|
208073
|
+
}
|
|
208074
|
+
function newTraceId() {
|
|
208075
|
+
return randomBytes2(16).toString("hex");
|
|
208076
|
+
}
|
|
208077
|
+
function newSpanId() {
|
|
208078
|
+
return randomBytes2(8).toString("hex");
|
|
208079
|
+
}
|
|
208080
|
+
function newTraceContext(incoming) {
|
|
208081
|
+
const parsed = parseTraceparent(incoming);
|
|
208082
|
+
if (parsed) {
|
|
208083
|
+
return {
|
|
208084
|
+
traceId: parsed.traceId,
|
|
208085
|
+
spanId: newSpanId(),
|
|
208086
|
+
parentSpanId: parsed.spanId,
|
|
208087
|
+
sampled: (parseInt(parsed.flags, 16) & 1) === 1,
|
|
208088
|
+
continued: true
|
|
208089
|
+
};
|
|
208090
|
+
}
|
|
208091
|
+
return {
|
|
208092
|
+
traceId: newTraceId(),
|
|
208093
|
+
spanId: newSpanId(),
|
|
208094
|
+
sampled: true,
|
|
208095
|
+
continued: false
|
|
208096
|
+
};
|
|
208097
|
+
}
|
|
208098
|
+
var storage = new AsyncLocalStorage();
|
|
208099
|
+
function runWithTraceContext(ctx, fn) {
|
|
208100
|
+
return storage.run(ctx, fn);
|
|
208101
|
+
}
|
|
208102
|
+
function getTraceContext() {
|
|
208103
|
+
return storage.getStore();
|
|
208104
|
+
}
|
|
208105
|
+
function outboundTraceparent() {
|
|
208106
|
+
const ctx = storage.getStore();
|
|
208107
|
+
return ctx ? formatTraceparent(ctx) : void 0;
|
|
208108
|
+
}
|
|
208109
|
+
|
|
208110
|
+
// src/utils/remote-proxy.ts
|
|
208111
|
+
function proxyStatus(result, fallback = 502) {
|
|
208112
|
+
return result.status > 0 ? result.status : fallback;
|
|
208113
|
+
}
|
|
208114
|
+
async function proxyToRemoteAuto(remoteServerId, method, apiPath, body, options) {
|
|
208115
|
+
const rcm = options?.reverseConnectManager;
|
|
208116
|
+
if (rcm && rcm.isConnected(remoteServerId)) {
|
|
208117
|
+
const traceparent = outboundTraceparent();
|
|
208118
|
+
const headers = {
|
|
208119
|
+
...traceparent ? { traceparent } : {},
|
|
208120
|
+
...options?.headers
|
|
208121
|
+
};
|
|
208122
|
+
return rcm.sendHttpRequest(remoteServerId, method, apiPath, body, options?.timeoutMs, headers);
|
|
208123
|
+
}
|
|
208124
|
+
return {
|
|
208125
|
+
ok: false,
|
|
208126
|
+
status: 0,
|
|
208127
|
+
data: { error: "Remote server is not connected" },
|
|
208128
|
+
errorCode: "network_error",
|
|
208129
|
+
requestId: options?.requestId
|
|
208130
|
+
};
|
|
208131
|
+
}
|
|
208132
|
+
|
|
208133
|
+
// src/retention-holds.ts
|
|
208134
|
+
var TIMEOUT_MS = 1e4;
|
|
208135
|
+
var RELEASE_STALE_MAX_SESSIONS = 1e4;
|
|
208136
|
+
var RetentionHoldSync = class {
|
|
208137
|
+
constructor(deps) {
|
|
208138
|
+
this.deps = deps;
|
|
208139
|
+
}
|
|
208140
|
+
deps;
|
|
208141
|
+
tails = /* @__PURE__ */ new Map();
|
|
208142
|
+
releasing = /* @__PURE__ */ new Map();
|
|
208143
|
+
/**
|
|
208144
|
+
* Recompute `sessionId`'s holds and write them where the session lives.
|
|
208145
|
+
* Rejects when the write did not land (worker offline); the caller decides
|
|
208146
|
+
* whether that blocks.
|
|
208147
|
+
*/
|
|
208148
|
+
sync(sessionId) {
|
|
208149
|
+
return this.exclusive(sessionId, (syncNow) => syncNow());
|
|
208150
|
+
}
|
|
208151
|
+
/**
|
|
208152
|
+
* Run `fn` with this session's slot held: no other sync or exclusive block
|
|
208153
|
+
* for the session starts until it settles. `syncNow` syncs inside the slot
|
|
208154
|
+
* (calling `sync` from `fn` would wait on itself).
|
|
208155
|
+
*/
|
|
208156
|
+
exclusive(sessionId, fn) {
|
|
208157
|
+
const prev = this.tails.get(sessionId) ?? Promise.resolve();
|
|
208158
|
+
const run2 = prev.then(() => fn(() => this.syncNow(sessionId)));
|
|
208159
|
+
const tail = run2.catch(() => void 0);
|
|
208160
|
+
this.tails.set(sessionId, tail);
|
|
208161
|
+
void tail.then(() => {
|
|
208162
|
+
if (this.tails.get(sessionId) === tail) this.tails.delete(sessionId);
|
|
208163
|
+
});
|
|
208164
|
+
return run2;
|
|
208165
|
+
}
|
|
208166
|
+
/**
|
|
208167
|
+
* Recompute every session that holds on `remoteServerId` reports. A hold
|
|
208168
|
+
* only ever outlives its schedules when a release failed (worker away, or a
|
|
208169
|
+
* rolled-back create whose push landed after its timeout); this is what
|
|
208170
|
+
* eventually frees those sessions. It only re-derives sessions that already
|
|
208171
|
+
* have holds — schedules that predate holds are deliberately not backfilled.
|
|
208172
|
+
* Never throws; returns how many sessions could not be synced. A call while
|
|
208173
|
+
* one for the same worker is running joins it.
|
|
208174
|
+
*/
|
|
208175
|
+
releaseStale(remoteServerId) {
|
|
208176
|
+
const running = this.releasing.get(remoteServerId);
|
|
208177
|
+
if (running) return running;
|
|
208178
|
+
const run2 = this.releaseStaleNow(remoteServerId).finally(() => this.releasing.delete(remoteServerId));
|
|
208179
|
+
this.releasing.set(remoteServerId, run2);
|
|
208180
|
+
return run2;
|
|
208181
|
+
}
|
|
208182
|
+
async releaseStaleNow(remoteServerId) {
|
|
208183
|
+
const proxy = this.deps.proxy ?? proxyToRemoteAuto;
|
|
208184
|
+
const listed = await proxy(
|
|
208185
|
+
remoteServerId,
|
|
208186
|
+
"GET",
|
|
208187
|
+
"/api/path/retention-holds",
|
|
208188
|
+
void 0,
|
|
208189
|
+
{ reverseConnectManager: this.deps.reverseConnectManager, timeoutMs: TIMEOUT_MS }
|
|
208190
|
+
);
|
|
208191
|
+
const sessionIds = listed.data?.sessionIds;
|
|
208192
|
+
if (!listed.ok || !Array.isArray(sessionIds)) return 1;
|
|
208193
|
+
if (sessionIds.length > RELEASE_STALE_MAX_SESSIONS) {
|
|
208194
|
+
console.warn(`[RetentionHolds] ${remoteServerId} listed ${sessionIds.length} held sessions; checking the first ${RELEASE_STALE_MAX_SESSIONS}`);
|
|
208195
|
+
}
|
|
208196
|
+
let failed = 0;
|
|
208197
|
+
for (const remoteSessionId of sessionIds.slice(0, RELEASE_STALE_MAX_SESSIONS)) {
|
|
208198
|
+
if (typeof remoteSessionId !== "string") continue;
|
|
208199
|
+
try {
|
|
208200
|
+
const mapping = await this.deps.storage.remoteSessionMappings.getByRemote(remoteServerId, remoteSessionId);
|
|
208201
|
+
if (mapping) {
|
|
208202
|
+
await this.sync(mapping.local_session_id);
|
|
208203
|
+
} else {
|
|
208204
|
+
await this.push({ remoteServerId, remoteSessionId }, []);
|
|
208205
|
+
}
|
|
208206
|
+
} catch {
|
|
208207
|
+
failed++;
|
|
208208
|
+
}
|
|
208209
|
+
}
|
|
208210
|
+
return failed;
|
|
208211
|
+
}
|
|
208212
|
+
async syncNow(sessionId) {
|
|
208213
|
+
const holds = [];
|
|
208214
|
+
for (const source of this.deps.sources) {
|
|
208215
|
+
for (const id of await source.listHolders(sessionId)) holds.push({ kind: source.kind, id });
|
|
208216
|
+
}
|
|
208217
|
+
if (!sessionId.startsWith("remote-")) {
|
|
208218
|
+
if (!await this.deps.storage.agentSessions.getById(sessionId)) return;
|
|
208219
|
+
await this.deps.storage.sessionRetentionHolds.replace(sessionId, holds);
|
|
208220
|
+
return;
|
|
208221
|
+
}
|
|
208222
|
+
const remote = await this.resolveRemote(sessionId);
|
|
208223
|
+
if (!remote) return;
|
|
208224
|
+
await this.push(remote, holds);
|
|
208225
|
+
}
|
|
208226
|
+
async push(remote, holds) {
|
|
208227
|
+
const proxy = this.deps.proxy ?? proxyToRemoteAuto;
|
|
208228
|
+
const result = await proxy(
|
|
208229
|
+
remote.remoteServerId,
|
|
208230
|
+
"PUT",
|
|
208231
|
+
`/api/path/retention-holds/${remote.remoteSessionId}`,
|
|
208232
|
+
{ holds },
|
|
208233
|
+
{ reverseConnectManager: this.deps.reverseConnectManager, timeoutMs: TIMEOUT_MS }
|
|
208234
|
+
);
|
|
208235
|
+
if (result.status === 404) return;
|
|
208236
|
+
if (!result.ok) {
|
|
208237
|
+
throw new Error(
|
|
208238
|
+
result.status === 0 ? "The session's machine is not connected" : `Worker responded ${result.status}`
|
|
208239
|
+
);
|
|
208240
|
+
}
|
|
208241
|
+
}
|
|
208242
|
+
async resolveRemote(sessionId) {
|
|
208243
|
+
const live = this.deps.remoteSessionMap.get(sessionId);
|
|
208244
|
+
if (live) return live;
|
|
208245
|
+
const mapping = await this.deps.storage.remoteSessionMappings.getByLocal(sessionId);
|
|
208246
|
+
return mapping ? { remoteServerId: mapping.remote_server_id, remoteSessionId: mapping.remote_session_id } : null;
|
|
208247
|
+
}
|
|
208248
|
+
};
|
|
208249
|
+
function scheduleHoldSource(storage2) {
|
|
208250
|
+
return {
|
|
208251
|
+
kind: "schedule",
|
|
208252
|
+
listHolders: (sessionId) => storage2.scheduledTasks.listIdsBySourceSession(sessionId)
|
|
208253
|
+
};
|
|
208254
|
+
}
|
|
208255
|
+
|
|
207981
208256
|
// src/agent-session-manager.ts
|
|
207982
208257
|
import { spawn as spawn3 } from "child_process";
|
|
207983
208258
|
import { randomUUID } from "crypto";
|
|
@@ -208701,7 +208976,7 @@ function getAllProviders() {
|
|
|
208701
208976
|
}
|
|
208702
208977
|
|
|
208703
208978
|
// src/utils/cross-remote-token.ts
|
|
208704
|
-
import { createHmac as createHmac2, randomBytes as
|
|
208979
|
+
import { createHmac as createHmac2, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
208705
208980
|
var CROSS_REMOTE_SECRET_SETTING = "cross_remote_token_secret";
|
|
208706
208981
|
var CROSS_REMOTE_TOKEN_TTL_MS = 7 * 864e5;
|
|
208707
208982
|
var sign2 = (secret, body) => createHmac2("sha256", secret).update(body).digest("base64url");
|
|
@@ -208773,7 +209048,7 @@ function verifyCrossRemoteTokenDetailed(secret, token, nowMs) {
|
|
|
208773
209048
|
async function getCrossRemoteSecret(storage2) {
|
|
208774
209049
|
return storage2.settings.getOrCreate(
|
|
208775
209050
|
CROSS_REMOTE_SECRET_SETTING,
|
|
208776
|
-
() =>
|
|
209051
|
+
() => randomBytes3(32).toString("hex")
|
|
208777
209052
|
);
|
|
208778
209053
|
}
|
|
208779
209054
|
|
|
@@ -214166,7 +214441,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
214166
214441
|
);
|
|
214167
214442
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
214168
214443
|
}
|
|
214169
|
-
var
|
|
214444
|
+
var VERSION4 = true ? "4.0.15" : "0.0.0-test";
|
|
214170
214445
|
var getOriginalFetch = () => globalThis.fetch;
|
|
214171
214446
|
var getFromApi = async ({
|
|
214172
214447
|
url: url2,
|
|
@@ -214181,7 +214456,7 @@ var getFromApi = async ({
|
|
|
214181
214456
|
method: "GET",
|
|
214182
214457
|
headers: withUserAgentSuffix(
|
|
214183
214458
|
headers,
|
|
214184
|
-
`ai-sdk/provider-utils/${
|
|
214459
|
+
`ai-sdk/provider-utils/${VERSION4}`,
|
|
214185
214460
|
getRuntimeEnvironmentUserAgent()
|
|
214186
214461
|
),
|
|
214187
214462
|
signal: abortSignal
|
|
@@ -215729,7 +216004,7 @@ var postToApi = async ({
|
|
|
215729
216004
|
method: "POST",
|
|
215730
216005
|
headers: withUserAgentSuffix(
|
|
215731
216006
|
headers,
|
|
215732
|
-
`ai-sdk/provider-utils/${
|
|
216007
|
+
`ai-sdk/provider-utils/${VERSION4}`,
|
|
215733
216008
|
getRuntimeEnvironmentUserAgent()
|
|
215734
216009
|
),
|
|
215735
216010
|
body: body.content,
|
|
@@ -217165,7 +217440,7 @@ async function getVercelRequestId() {
|
|
|
217165
217440
|
var _a94;
|
|
217166
217441
|
return (_a94 = (0, import_oidc.getContext)().headers) == null ? void 0 : _a94["x-vercel-id"];
|
|
217167
217442
|
}
|
|
217168
|
-
var
|
|
217443
|
+
var VERSION5 = true ? "3.0.55" : "0.0.0-test";
|
|
217169
217444
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
217170
217445
|
function createGatewayProvider(options = {}) {
|
|
217171
217446
|
var _a94, _b93;
|
|
@@ -217184,7 +217459,7 @@ function createGatewayProvider(options = {}) {
|
|
|
217184
217459
|
[GATEWAY_AUTH_METHOD_HEADER]: auth2.authMethod,
|
|
217185
217460
|
...options.headers
|
|
217186
217461
|
},
|
|
217187
|
-
`ai-sdk/gateway/${
|
|
217462
|
+
`ai-sdk/gateway/${VERSION5}`
|
|
217188
217463
|
);
|
|
217189
217464
|
} catch (error48) {
|
|
217190
217465
|
throw GatewayAuthenticationError.createContextualError({
|
|
@@ -217931,7 +218206,7 @@ function detectMediaType({
|
|
|
217931
218206
|
}
|
|
217932
218207
|
return void 0;
|
|
217933
218208
|
}
|
|
217934
|
-
var
|
|
218209
|
+
var VERSION6 = true ? "6.0.99" : "0.0.0-test";
|
|
217935
218210
|
var download = async ({
|
|
217936
218211
|
url: url2,
|
|
217937
218212
|
maxBytes,
|
|
@@ -217943,7 +218218,7 @@ var download = async ({
|
|
|
217943
218218
|
const response = await fetch(urlText, {
|
|
217944
218219
|
headers: withUserAgentSuffix(
|
|
217945
218220
|
{},
|
|
217946
|
-
`ai-sdk/${
|
|
218221
|
+
`ai-sdk/${VERSION6}`,
|
|
217947
218222
|
getRuntimeEnvironmentUserAgent()
|
|
217948
218223
|
),
|
|
217949
218224
|
signal: abortSignal
|
|
@@ -220616,7 +220891,7 @@ async function generateText({
|
|
|
220616
220891
|
const callSettings = prepareCallSettings(settings);
|
|
220617
220892
|
const headersWithUserAgent = withUserAgentSuffix(
|
|
220618
220893
|
headers != null ? headers : {},
|
|
220619
|
-
`ai/${
|
|
220894
|
+
`ai/${VERSION6}`
|
|
220620
220895
|
);
|
|
220621
220896
|
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
|
220622
220897
|
model,
|
|
@@ -225459,7 +225734,7 @@ var DeepSeekChatLanguageModel = class {
|
|
|
225459
225734
|
};
|
|
225460
225735
|
}
|
|
225461
225736
|
};
|
|
225462
|
-
var
|
|
225737
|
+
var VERSION7 = true ? "2.0.20" : "0.0.0-test";
|
|
225463
225738
|
function createDeepSeek(options = {}) {
|
|
225464
225739
|
var _a26;
|
|
225465
225740
|
const baseURL = withoutTrailingSlash(
|
|
@@ -225474,7 +225749,7 @@ function createDeepSeek(options = {}) {
|
|
|
225474
225749
|
})}`,
|
|
225475
225750
|
...options.headers
|
|
225476
225751
|
},
|
|
225477
|
-
`ai-sdk/deepseek/${
|
|
225752
|
+
`ai-sdk/deepseek/${VERSION7}`
|
|
225478
225753
|
);
|
|
225479
225754
|
const createLanguageModel = (modelId) => {
|
|
225480
225755
|
return new DeepSeekChatLanguageModel(modelId, {
|
|
@@ -226117,7 +226392,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
226117
226392
|
);
|
|
226118
226393
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
226119
226394
|
}
|
|
226120
|
-
var
|
|
226395
|
+
var VERSION8 = true ? "4.0.1" : "0.0.0-test";
|
|
226121
226396
|
function loadApiKey2({
|
|
226122
226397
|
apiKey,
|
|
226123
226398
|
environmentVariableName,
|
|
@@ -227507,7 +227782,7 @@ var postToApi2 = async ({
|
|
|
227507
227782
|
method: "POST",
|
|
227508
227783
|
headers: withUserAgentSuffix2(
|
|
227509
227784
|
headers,
|
|
227510
|
-
`ai-sdk/provider-utils/${
|
|
227785
|
+
`ai-sdk/provider-utils/${VERSION8}`,
|
|
227511
227786
|
getRuntimeEnvironmentUserAgent2()
|
|
227512
227787
|
),
|
|
227513
227788
|
body: body.content,
|
|
@@ -230396,6 +230671,7 @@ async function appendRemoteGrantContext(storage2, sessionId, userId, content) {
|
|
|
230396
230671
|
|
|
230397
230672
|
// src/utils/conversation-title.ts
|
|
230398
230673
|
var TITLE_MAX_CHARS = 60;
|
|
230674
|
+
var VSCHEDULE_BLOCK_RE = /<vschedule(?:\s[^>]*)?>[\s\S]*?<\/vschedule>/g;
|
|
230399
230675
|
var AI_TIMEOUT_MS = 15e3;
|
|
230400
230676
|
var MAX_INPUT_CHARS = 2e3;
|
|
230401
230677
|
var SYSTEM_PROMPT = "You write very short, descriptive titles for chat conversations. Reply with the title only \u2014 no quotes, no trailing punctuation, no markdown, no prefixes like 'Title:'. Use the same language as the user's message. Keep it under 8 words and 50 characters.";
|
|
@@ -230412,7 +230688,7 @@ async function isChatModelConfigured(storage2, userId) {
|
|
|
230412
230688
|
}
|
|
230413
230689
|
function extractUserText(content) {
|
|
230414
230690
|
const text2 = typeof content === "string" ? content : content.filter((p2) => p2.type === "text").map((p2) => p2.text).join(" ");
|
|
230415
|
-
return stripRemoteGrantContext(text2);
|
|
230691
|
+
return stripRemoteGrantContext(text2.replace(VSCHEDULE_BLOCK_RE, ""));
|
|
230416
230692
|
}
|
|
230417
230693
|
function snippetTitle(text2) {
|
|
230418
230694
|
const trimmed = text2.trim();
|
|
@@ -234355,91 +234631,6 @@ var AgentSessionManager = class {
|
|
|
234355
234631
|
// src/chat-session-manager.ts
|
|
234356
234632
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
234357
234633
|
|
|
234358
|
-
// src/trace-context.ts
|
|
234359
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
234360
|
-
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
234361
|
-
var VERSION8 = "00";
|
|
234362
|
-
var INVALID_VERSION = "ff";
|
|
234363
|
-
var ZERO_TRACE_ID = "0".repeat(32);
|
|
234364
|
-
var ZERO_SPAN_ID = "0".repeat(16);
|
|
234365
|
-
var HEX_2 = /^[0-9a-f]{2}$/;
|
|
234366
|
-
var HEX_16 = /^[0-9a-f]{16}$/;
|
|
234367
|
-
var HEX_32 = /^[0-9a-f]{32}$/;
|
|
234368
|
-
function parseTraceparent(value) {
|
|
234369
|
-
const raw = Array.isArray(value) ? value[0] : value;
|
|
234370
|
-
if (typeof raw !== "string") return null;
|
|
234371
|
-
const parts = raw.split("-");
|
|
234372
|
-
if (parts.length < 4) return null;
|
|
234373
|
-
const [version2, traceId, spanId, flags] = parts;
|
|
234374
|
-
if (!HEX_2.test(version2) || version2 === INVALID_VERSION) return null;
|
|
234375
|
-
if (version2 === VERSION8 && parts.length !== 4) return null;
|
|
234376
|
-
if (!HEX_32.test(traceId) || traceId === ZERO_TRACE_ID) return null;
|
|
234377
|
-
if (!HEX_16.test(spanId) || spanId === ZERO_SPAN_ID) return null;
|
|
234378
|
-
if (!HEX_2.test(flags)) return null;
|
|
234379
|
-
return { traceId, spanId, flags };
|
|
234380
|
-
}
|
|
234381
|
-
function formatTraceparent(ctx) {
|
|
234382
|
-
return `${VERSION8}-${ctx.traceId}-${ctx.spanId}-${ctx.sampled ? "01" : "00"}`;
|
|
234383
|
-
}
|
|
234384
|
-
function newTraceId() {
|
|
234385
|
-
return randomBytes3(16).toString("hex");
|
|
234386
|
-
}
|
|
234387
|
-
function newSpanId() {
|
|
234388
|
-
return randomBytes3(8).toString("hex");
|
|
234389
|
-
}
|
|
234390
|
-
function newTraceContext(incoming) {
|
|
234391
|
-
const parsed = parseTraceparent(incoming);
|
|
234392
|
-
if (parsed) {
|
|
234393
|
-
return {
|
|
234394
|
-
traceId: parsed.traceId,
|
|
234395
|
-
spanId: newSpanId(),
|
|
234396
|
-
parentSpanId: parsed.spanId,
|
|
234397
|
-
sampled: (parseInt(parsed.flags, 16) & 1) === 1,
|
|
234398
|
-
continued: true
|
|
234399
|
-
};
|
|
234400
|
-
}
|
|
234401
|
-
return {
|
|
234402
|
-
traceId: newTraceId(),
|
|
234403
|
-
spanId: newSpanId(),
|
|
234404
|
-
sampled: true,
|
|
234405
|
-
continued: false
|
|
234406
|
-
};
|
|
234407
|
-
}
|
|
234408
|
-
var storage = new AsyncLocalStorage();
|
|
234409
|
-
function runWithTraceContext(ctx, fn) {
|
|
234410
|
-
return storage.run(ctx, fn);
|
|
234411
|
-
}
|
|
234412
|
-
function getTraceContext() {
|
|
234413
|
-
return storage.getStore();
|
|
234414
|
-
}
|
|
234415
|
-
function outboundTraceparent() {
|
|
234416
|
-
const ctx = storage.getStore();
|
|
234417
|
-
return ctx ? formatTraceparent(ctx) : void 0;
|
|
234418
|
-
}
|
|
234419
|
-
|
|
234420
|
-
// src/utils/remote-proxy.ts
|
|
234421
|
-
function proxyStatus(result, fallback = 502) {
|
|
234422
|
-
return result.status > 0 ? result.status : fallback;
|
|
234423
|
-
}
|
|
234424
|
-
async function proxyToRemoteAuto(remoteServerId, method, apiPath, body, options) {
|
|
234425
|
-
const rcm = options?.reverseConnectManager;
|
|
234426
|
-
if (rcm && rcm.isConnected(remoteServerId)) {
|
|
234427
|
-
const traceparent = outboundTraceparent();
|
|
234428
|
-
const headers = {
|
|
234429
|
-
...traceparent ? { traceparent } : {},
|
|
234430
|
-
...options?.headers
|
|
234431
|
-
};
|
|
234432
|
-
return rcm.sendHttpRequest(remoteServerId, method, apiPath, body, options?.timeoutMs, headers);
|
|
234433
|
-
}
|
|
234434
|
-
return {
|
|
234435
|
-
ok: false,
|
|
234436
|
-
status: 0,
|
|
234437
|
-
data: { error: "Remote server is not connected" },
|
|
234438
|
-
errorCode: "network_error",
|
|
234439
|
-
requestId: options?.requestId
|
|
234440
|
-
};
|
|
234441
|
-
}
|
|
234442
|
-
|
|
234443
234634
|
// ../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/wrapper.mjs
|
|
234444
234635
|
var import_stream3 = __toESM(require_stream(), 1);
|
|
234445
234636
|
var import_receiver = __toESM(require_receiver(), 1);
|
|
@@ -244611,6 +244802,10 @@ var ReverseConnectManager = class {
|
|
|
244611
244802
|
this.cleanupConnection(remoteServerId, conn);
|
|
244612
244803
|
this.connections.delete(remoteServerId);
|
|
244613
244804
|
}
|
|
244805
|
+
/** Ids of every worker currently connected. */
|
|
244806
|
+
connectedServerIds() {
|
|
244807
|
+
return [...this.connections.keys()];
|
|
244808
|
+
}
|
|
244614
244809
|
isConnected(remoteServerId) {
|
|
244615
244810
|
const conn = this.connections.get(this.resolveId(remoteServerId));
|
|
244616
244811
|
return conn !== void 0 && conn.ws.readyState === 1;
|
|
@@ -247624,6 +247819,12 @@ var RemoteSessionReconciler = class {
|
|
|
247624
247819
|
// src/remote-liveness-reconcile.ts
|
|
247625
247820
|
var RemoteLivenessTracker = class {
|
|
247626
247821
|
byProject = /* @__PURE__ */ new Map();
|
|
247822
|
+
/**
|
|
247823
|
+
* Newest read id whose answer was acted on, per project — baseline or not. A
|
|
247824
|
+
* reconcile of a project the hub never served must still be ordered against
|
|
247825
|
+
* an overlapping one, without inventing a death baseline for it.
|
|
247826
|
+
*/
|
|
247827
|
+
answeredSeq = /* @__PURE__ */ new Map();
|
|
247627
247828
|
seqCounter = 0;
|
|
247628
247829
|
eventBus;
|
|
247629
247830
|
constructor(eventBus = null) {
|
|
@@ -247645,6 +247846,7 @@ var RemoteLivenessTracker = class {
|
|
|
247645
247846
|
const previous = this.byProject.get(projectId);
|
|
247646
247847
|
if (previous && seq < previous.seq) return [];
|
|
247647
247848
|
this.byProject.set(projectId, { remoteServerId, remotePath, sessions, seq });
|
|
247849
|
+
this.markAnswered(projectId, seq);
|
|
247648
247850
|
if (!previous) return [];
|
|
247649
247851
|
const live = new Set(sessions.map((session) => session.remoteSessionId));
|
|
247650
247852
|
const retired = previous.sessions.filter((session) => !live.has(session.remoteSessionId));
|
|
@@ -247676,6 +247878,45 @@ var RemoteLivenessTracker = class {
|
|
|
247676
247878
|
}).filter((session) => session !== null);
|
|
247677
247879
|
return this.accept(projectId, remoteServerId, remotePath, sessions, seq);
|
|
247678
247880
|
}
|
|
247881
|
+
/**
|
|
247882
|
+
* True when an answer claimed with `seq` has been overtaken by a newer
|
|
247883
|
+
* accepted one for this project — it must decide nothing, deaths or status.
|
|
247884
|
+
*/
|
|
247885
|
+
isOvertaken(projectId, seq) {
|
|
247886
|
+
const current = Math.max(this.byProject.get(projectId)?.seq ?? 0, this.answeredSeq.get(projectId) ?? 0);
|
|
247887
|
+
return seq < current;
|
|
247888
|
+
}
|
|
247889
|
+
/** Record that the answer read with `seq` was acted on, without touching the baseline. */
|
|
247890
|
+
markAnswered(projectId, seq) {
|
|
247891
|
+
if (seq > (this.answeredSeq.get(projectId) ?? 0)) this.answeredSeq.set(projectId, seq);
|
|
247892
|
+
}
|
|
247893
|
+
/** Whether a browser read has given this project a death baseline. */
|
|
247894
|
+
hasBaseline(projectId) {
|
|
247895
|
+
return this.byProject.has(projectId);
|
|
247896
|
+
}
|
|
247897
|
+
/**
|
|
247898
|
+
* Announce each session's current status as the worker reports it.
|
|
247899
|
+
*
|
|
247900
|
+
* The worker sends status changes only on each session's own stream, so a
|
|
247901
|
+
* turn that ended while the hub held no stream for it (a hub restart, a
|
|
247902
|
+
* tunnel outage) leaves every browser showing "running" forever. An
|
|
247903
|
+
* authoritative alive answer carries the status, so re-announcing it repairs
|
|
247904
|
+
* those rows. Deliberately independent of stream restoration: once status
|
|
247905
|
+
* moves to a project-level channel this stays as the post-reconnect repair,
|
|
247906
|
+
* while per-session streams only carry conversation content.
|
|
247907
|
+
*/
|
|
247908
|
+
announceStatuses(projectId, sessions) {
|
|
247909
|
+
for (const session of sessions) {
|
|
247910
|
+
if (!session.status) continue;
|
|
247911
|
+
this.eventBus?.emit({
|
|
247912
|
+
type: "session:status",
|
|
247913
|
+
projectId,
|
|
247914
|
+
branch: session.branch,
|
|
247915
|
+
sessionId: session.localSessionId,
|
|
247916
|
+
status: session.status
|
|
247917
|
+
});
|
|
247918
|
+
}
|
|
247919
|
+
}
|
|
247679
247920
|
entriesFor(remoteServerId) {
|
|
247680
247921
|
const rows = [];
|
|
247681
247922
|
for (const [projectId, tracked] of this.byProject) {
|
|
@@ -247694,40 +247935,58 @@ function parseAliveAnswer(data) {
|
|
|
247694
247935
|
if (!entry || typeof entry !== "object") continue;
|
|
247695
247936
|
const row = entry;
|
|
247696
247937
|
if (typeof row.id !== "string") continue;
|
|
247697
|
-
|
|
247938
|
+
const status = row.status === "running" || row.status === "stopped" || row.status === "error" ? row.status : null;
|
|
247939
|
+
rows.push({ id: row.id, branch: typeof row.branch === "string" ? row.branch : null, status });
|
|
247698
247940
|
}
|
|
247699
247941
|
return rows;
|
|
247700
247942
|
}
|
|
247701
247943
|
async function reconcileRemoteLiveness(remoteServerId, deps) {
|
|
247702
247944
|
const dead = [];
|
|
247703
|
-
const
|
|
247945
|
+
const answers = [];
|
|
247946
|
+
const targets = /* @__PURE__ */ new Map();
|
|
247947
|
+
for (const entry of deps.tracker.entriesFor(remoteServerId)) targets.set(entry.projectId, entry.remotePath);
|
|
247948
|
+
if (deps.listProjects) {
|
|
247949
|
+
try {
|
|
247950
|
+
for (const project of await deps.listProjects(remoteServerId)) {
|
|
247951
|
+
if (!targets.has(project.projectId)) targets.set(project.projectId, project.remotePath);
|
|
247952
|
+
}
|
|
247953
|
+
} catch (error48) {
|
|
247954
|
+
console.warn(`[RemoteLiveness] project listing failed for ${remoteServerId}:`, error48);
|
|
247955
|
+
}
|
|
247956
|
+
}
|
|
247704
247957
|
let projects = 0;
|
|
247705
|
-
for (const
|
|
247706
|
-
if (entry.sessions.length === 0) continue;
|
|
247958
|
+
for (const [projectId, remotePath] of targets) {
|
|
247707
247959
|
const seq = deps.tracker.nextReadSeq();
|
|
247708
247960
|
let result;
|
|
247709
247961
|
try {
|
|
247710
|
-
result = await deps.proxy(remoteServerId,
|
|
247962
|
+
result = await deps.proxy(remoteServerId, remotePath);
|
|
247711
247963
|
} catch (error48) {
|
|
247712
|
-
console.warn(`[RemoteLiveness] alive query failed for ${
|
|
247964
|
+
console.warn(`[RemoteLiveness] alive query failed for ${projectId}:`, error48);
|
|
247713
247965
|
continue;
|
|
247714
247966
|
}
|
|
247715
247967
|
if (!result.ok) continue;
|
|
247716
247968
|
const rows = parseAliveAnswer(result.data);
|
|
247717
247969
|
if (!rows) continue;
|
|
247970
|
+
if (deps.tracker.isOvertaken(projectId, seq)) continue;
|
|
247718
247971
|
projects += 1;
|
|
247719
|
-
|
|
247720
|
-
|
|
247721
|
-
|
|
247722
|
-
|
|
247723
|
-
|
|
247724
|
-
|
|
247725
|
-
))
|
|
247972
|
+
const sessions = rows.map((row) => ({
|
|
247973
|
+
localSessionId: `remote-${remoteServerId}-${projectId}-${row.id}`,
|
|
247974
|
+
remoteSessionId: row.id,
|
|
247975
|
+
branch: row.branch,
|
|
247976
|
+
status: row.status
|
|
247977
|
+
}));
|
|
247978
|
+
if (deps.tracker.hasBaseline(projectId)) {
|
|
247979
|
+
dead.push(...deps.tracker.acceptRemoteIds(projectId, remoteServerId, remotePath, rows, seq));
|
|
247980
|
+
} else {
|
|
247981
|
+
deps.tracker.markAnswered(projectId, seq);
|
|
247982
|
+
}
|
|
247983
|
+
deps.tracker.announceStatuses(projectId, sessions);
|
|
247984
|
+
answers.push({ projectId, sessions });
|
|
247726
247985
|
}
|
|
247727
247986
|
if (dead.length > 0) {
|
|
247728
247987
|
console.log(`[RemoteLiveness] ${remoteServerId}: ${dead.length} session(s) lost their process while unobserved`);
|
|
247729
247988
|
}
|
|
247730
|
-
return { projects, dead };
|
|
247989
|
+
return { projects, dead, answers };
|
|
247731
247990
|
}
|
|
247732
247991
|
|
|
247733
247992
|
// src/logger.ts
|
|
@@ -248540,12 +248799,8 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248540
248799
|
await agentSessionManager.restoreSessionsFromDb();
|
|
248541
248800
|
const remoteExecutorMap = /* @__PURE__ */ new Map();
|
|
248542
248801
|
const remoteSessionMap = /* @__PURE__ */ new Map();
|
|
248543
|
-
for (const row of await opts.storage.remoteSessionMappings.
|
|
248544
|
-
|
|
248545
|
-
row.project_id,
|
|
248546
|
-
row.remote_server_id
|
|
248547
|
-
);
|
|
248548
|
-
if (!remote) {
|
|
248802
|
+
for (const row of await opts.storage.remoteSessionMappings.getAllWithLinkState()) {
|
|
248803
|
+
if (!row.linked) {
|
|
248549
248804
|
console.warn(`[SharedServices] Skipping remote_session_mappings row ${row.local_session_id}: project_remotes(${row.project_id}, ${row.remote_server_id}) not found`);
|
|
248550
248805
|
continue;
|
|
248551
248806
|
}
|
|
@@ -248830,6 +249085,25 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248830
249085
|
fastify2.decorate("reverseConnectManager", reverseConnectManager);
|
|
248831
249086
|
fastify2.decorate("browserManager", browserManager);
|
|
248832
249087
|
fastify2.decorate("scheduler", scheduler);
|
|
249088
|
+
const retentionHolds = new RetentionHoldSync({
|
|
249089
|
+
storage: opts.storage,
|
|
249090
|
+
reverseConnectManager,
|
|
249091
|
+
remoteSessionMap,
|
|
249092
|
+
sources: [scheduleHoldSource(opts.storage)]
|
|
249093
|
+
});
|
|
249094
|
+
fastify2.decorate("retentionHolds", retentionHolds);
|
|
249095
|
+
const releaseStaleHolds = (remoteServerId) => {
|
|
249096
|
+
void retentionHolds.releaseStale(remoteServerId).then((failed) => {
|
|
249097
|
+
if (failed > 0) console.warn(`[RetentionHolds] ${failed} session(s) on ${remoteServerId} not re-synced`);
|
|
249098
|
+
});
|
|
249099
|
+
};
|
|
249100
|
+
reverseConnectManager.setStatusChangeHandler((remoteServerId, status) => {
|
|
249101
|
+
if (status === "online") releaseStaleHolds(remoteServerId);
|
|
249102
|
+
});
|
|
249103
|
+
const retentionHoldTimer = setInterval(() => {
|
|
249104
|
+
for (const remoteServerId of reverseConnectManager.connectedServerIds()) releaseStaleHolds(remoteServerId);
|
|
249105
|
+
}, 60 * 60 * 1e3);
|
|
249106
|
+
retentionHoldTimer.unref();
|
|
248833
249107
|
agentSessionManager.setEventBus(eventBus);
|
|
248834
249108
|
void recoverPendingRemoteAgentSessions({
|
|
248835
249109
|
remoteSessionMap,
|
|
@@ -248950,6 +249224,7 @@ var sharedServices = async (fastify2, opts) => {
|
|
|
248950
249224
|
memoryStatsReporter.start();
|
|
248951
249225
|
fastify2.addHook("onClose", async () => {
|
|
248952
249226
|
memoryStatsReporter.close();
|
|
249227
|
+
clearInterval(retentionHoldTimer);
|
|
248953
249228
|
await sessionRetention.close();
|
|
248954
249229
|
await remoteSessionReconciler.close();
|
|
248955
249230
|
scheduler.shutdown();
|
|
@@ -255761,6 +256036,21 @@ var sessionInventoryRoutes = async (fastify2) => {
|
|
|
255761
256036
|
return reply.code(200).send({ sessionIds, complete: true });
|
|
255762
256037
|
}
|
|
255763
256038
|
);
|
|
256039
|
+
fastify2.get("/api/path/retention-holds", async (_req, reply) => {
|
|
256040
|
+
return reply.code(200).send({ sessionIds: await fastify2.storage.sessionRetentionHolds.listSessionIds() });
|
|
256041
|
+
});
|
|
256042
|
+
fastify2.put("/api/path/retention-holds/:sessionId", async (req, reply) => {
|
|
256043
|
+
const raw = req.body?.holds;
|
|
256044
|
+
const validPart = (v2) => typeof v2 === "string" && v2.length > 0 && v2.length <= 200;
|
|
256045
|
+
if (!Array.isArray(raw) || raw.length > 1e3 || !raw.every((h) => h && typeof h === "object" && validPart(h.kind) && validPart(h.id))) {
|
|
256046
|
+
return reply.code(400).send({ error: "holds must be an array of { kind, id }" });
|
|
256047
|
+
}
|
|
256048
|
+
const session = await fastify2.storage.agentSessions.getById(req.params.sessionId);
|
|
256049
|
+
if (!session) return reply.code(404).send({ error: "Session not found" });
|
|
256050
|
+
const holds = raw.map((h) => ({ kind: h.kind, id: h.id }));
|
|
256051
|
+
await fastify2.storage.sessionRetentionHolds.replace(req.params.sessionId, holds);
|
|
256052
|
+
return reply.code(204).send();
|
|
256053
|
+
});
|
|
255764
256054
|
};
|
|
255765
256055
|
var session_inventory_routes_default = sessionInventoryRoutes;
|
|
255766
256056
|
|
|
@@ -259145,6 +259435,13 @@ function resolveRemoteReplayCursor(clientEpoch, cachedEpoch, afterEntryIndex) {
|
|
|
259145
259435
|
replayAfter: epochMatches ? afterEntryIndex ?? -1 : -1
|
|
259146
259436
|
};
|
|
259147
259437
|
}
|
|
259438
|
+
function restoreRunningRemoteStreams(answers, ensure) {
|
|
259439
|
+
for (const { sessions } of answers) {
|
|
259440
|
+
for (const session of sessions) {
|
|
259441
|
+
if (session.status === "running") ensure(session.localSessionId);
|
|
259442
|
+
}
|
|
259443
|
+
}
|
|
259444
|
+
}
|
|
259148
259445
|
var routes25 = async (fastify2) => {
|
|
259149
259446
|
fastify2.reverseConnectManager.setStatusChangeHandler((remoteServerId, status) => {
|
|
259150
259447
|
if (status !== "online") return;
|
|
@@ -259174,8 +259471,29 @@ var routes25 = async (fastify2) => {
|
|
|
259174
259471
|
`/api/path/agent-sessions/alive?path=${encodeURIComponent(remotePath)}`,
|
|
259175
259472
|
void 0,
|
|
259176
259473
|
{ reverseConnectManager: fastify2.reverseConnectManager }
|
|
259177
|
-
)
|
|
259178
|
-
|
|
259474
|
+
),
|
|
259475
|
+
// Same scope as the project `/alive` route: projects whose agent runs on
|
|
259476
|
+
// this worker. No user filter — this is server maintenance.
|
|
259477
|
+
listProjects: async (serverId) => {
|
|
259478
|
+
const projects = (await fastify2.storage.projects.getAll()).filter((project) => project.agent_mode === serverId);
|
|
259479
|
+
const rows = [];
|
|
259480
|
+
for (const project of projects) {
|
|
259481
|
+
const remote = await fastify2.storage.projectRemotes.getByProjectAndServer(project.id, serverId);
|
|
259482
|
+
if (remote) rows.push({ projectId: project.id, remotePath: remote.remote_path });
|
|
259483
|
+
}
|
|
259484
|
+
return rows;
|
|
259485
|
+
}
|
|
259486
|
+
}).then(({ answers }) => restoreRunningRemoteStreams(
|
|
259487
|
+
answers,
|
|
259488
|
+
(localSessionId) => ensureRemoteAgentStream(localSessionId, {
|
|
259489
|
+
remoteSessionMap: fastify2.remoteSessionMap,
|
|
259490
|
+
remotePatchCache: fastify2.remotePatchCache,
|
|
259491
|
+
reverseConnectManager: fastify2.reverseConnectManager,
|
|
259492
|
+
eventBus: fastify2.eventBus,
|
|
259493
|
+
agentSessionManager: fastify2.agentSessionManager,
|
|
259494
|
+
storage: fastify2.storage
|
|
259495
|
+
})
|
|
259496
|
+
)).catch((error48) => console.warn("[RemoteLiveness] reconcile failed:", error48));
|
|
259179
259497
|
});
|
|
259180
259498
|
fastify2.after(() => {
|
|
259181
259499
|
fastify2.get(
|
|
@@ -266849,6 +267167,32 @@ var routes34 = async (fastify2) => {
|
|
|
266849
267167
|
}
|
|
266850
267168
|
return schedule;
|
|
266851
267169
|
};
|
|
267170
|
+
const resolveSourceSessions = async (ids) => {
|
|
267171
|
+
const unique = [...new Set(ids)];
|
|
267172
|
+
const remoteIds = unique.filter((id) => id.startsWith("remote-"));
|
|
267173
|
+
const remoteTitles = await fastify2.storage.searchCache.getCachedSessionTitles(remoteIds);
|
|
267174
|
+
const branchOf2 = async (row) => {
|
|
267175
|
+
if (!row) return null;
|
|
267176
|
+
const registered = row.workspace_checkout_id ? await fastify2.storage.workspaceRegistry.getCheckoutById(row.workspace_checkout_id) : void 0;
|
|
267177
|
+
return (registered ? registered.workspace.branch : row.branch) || null;
|
|
267178
|
+
};
|
|
267179
|
+
const out = /* @__PURE__ */ new Map();
|
|
267180
|
+
await Promise.all(unique.map(async (id) => {
|
|
267181
|
+
if (id.startsWith("remote-")) {
|
|
267182
|
+
const mapping = await fastify2.storage.remoteSessionMappings.getByLocal(id);
|
|
267183
|
+
out.set(id, {
|
|
267184
|
+
id,
|
|
267185
|
+
exists: !!mapping,
|
|
267186
|
+
branch: await branchOf2(mapping),
|
|
267187
|
+
title: remoteTitles.get(id) ?? null
|
|
267188
|
+
});
|
|
267189
|
+
return;
|
|
267190
|
+
}
|
|
267191
|
+
const session = await fastify2.storage.agentSessions.getById(id);
|
|
267192
|
+
out.set(id, { id, exists: !!session, branch: await branchOf2(session), title: session?.title ?? null });
|
|
267193
|
+
}));
|
|
267194
|
+
return out;
|
|
267195
|
+
};
|
|
266852
267196
|
fastify2.get(
|
|
266853
267197
|
"/api/projects/:projectId/schedules",
|
|
266854
267198
|
async (req, reply) => {
|
|
@@ -266858,9 +267202,13 @@ var routes34 = async (fastify2) => {
|
|
|
266858
267202
|
if (!project) return reply.code(404).send({ error: "Project not found" });
|
|
266859
267203
|
const schedules = await fastify2.storage.scheduledTasks.getByProjectId(req.params.projectId);
|
|
266860
267204
|
const lastRuns = await fastify2.storage.scheduledTaskRuns.getLastByScheduleIds(schedules.map((s3) => s3.id));
|
|
267205
|
+
const sources = await resolveSourceSessions(
|
|
267206
|
+
schedules.flatMap((s3) => s3.source_session_id ? [s3.source_session_id] : [])
|
|
267207
|
+
);
|
|
266861
267208
|
return reply.code(200).send({
|
|
266862
267209
|
schedules: schedules.map((s3) => ({
|
|
266863
267210
|
...s3,
|
|
267211
|
+
source_session: s3.source_session_id ? sources.get(s3.source_session_id) ?? null : null,
|
|
266864
267212
|
last_run: lastRuns[s3.id] ?? null,
|
|
266865
267213
|
next_run_at: fastify2.scheduler.nextRunAt(s3.id),
|
|
266866
267214
|
running: fastify2.scheduler.isRunning(s3.id)
|
|
@@ -266908,10 +267256,11 @@ var routes34 = async (fastify2) => {
|
|
|
266908
267256
|
source = { session_id: b2.source.session_id, tool_use_id: b2.source.tool_use_id };
|
|
266909
267257
|
}
|
|
266910
267258
|
const newId = randomUUID29();
|
|
266911
|
-
const
|
|
267259
|
+
const name25 = b2.name.trim();
|
|
267260
|
+
const insert = () => fastify2.storage.scheduledTasks.create({
|
|
266912
267261
|
id: newId,
|
|
266913
267262
|
project_id: req.params.projectId,
|
|
266914
|
-
name:
|
|
267263
|
+
name: name25,
|
|
266915
267264
|
cron_expr: resolved.cron_expr,
|
|
266916
267265
|
timezone: resolved.timezone,
|
|
266917
267266
|
run_type: resolved.run_type,
|
|
@@ -266925,8 +267274,31 @@ var routes34 = async (fastify2) => {
|
|
|
266925
267274
|
target,
|
|
266926
267275
|
source
|
|
266927
267276
|
});
|
|
266928
|
-
|
|
267277
|
+
let schedule;
|
|
267278
|
+
if (source) {
|
|
267279
|
+
try {
|
|
267280
|
+
schedule = await fastify2.retentionHolds.exclusive(source.session_id, async (syncNow) => {
|
|
267281
|
+
const row = await insert();
|
|
267282
|
+
try {
|
|
267283
|
+
await syncNow();
|
|
267284
|
+
return row;
|
|
267285
|
+
} catch (error49) {
|
|
267286
|
+
if (row.id === newId) {
|
|
267287
|
+
await fastify2.storage.scheduledTasks.delete(row.id);
|
|
267288
|
+
await syncNow().catch(() => void 0);
|
|
267289
|
+
}
|
|
267290
|
+
throw error49;
|
|
267291
|
+
}
|
|
267292
|
+
});
|
|
267293
|
+
} catch (error49) {
|
|
267294
|
+
const message = error49 instanceof Error ? error49.message : String(error49);
|
|
267295
|
+
return reply.code(502).send({ error: `Could not protect the source session from retention: ${message}` });
|
|
267296
|
+
}
|
|
267297
|
+
} else {
|
|
267298
|
+
schedule = await insert();
|
|
267299
|
+
}
|
|
266929
267300
|
const created = schedule.id === newId;
|
|
267301
|
+
await fastify2.scheduler.reschedule(schedule.id);
|
|
266930
267302
|
if (created) {
|
|
266931
267303
|
fastify2.eventBus.emit({
|
|
266932
267304
|
type: "schedule:changed",
|
|
@@ -267004,6 +267376,11 @@ var routes34 = async (fastify2) => {
|
|
|
267004
267376
|
scheduleId: req.params.id,
|
|
267005
267377
|
change: "deleted"
|
|
267006
267378
|
});
|
|
267379
|
+
if (existing.source_session_id) {
|
|
267380
|
+
await fastify2.retentionHolds.sync(existing.source_session_id).catch((error48) => {
|
|
267381
|
+
console.warn(`[RetentionHolds] release for ${existing.source_session_id} deferred:`, error48);
|
|
267382
|
+
});
|
|
267383
|
+
}
|
|
267007
267384
|
return reply.code(204).send();
|
|
267008
267385
|
}
|
|
267009
267386
|
);
|
|
@@ -268248,6 +268625,10 @@ var WORKER_CAPABILITIES = {
|
|
|
268248
268625
|
// NOTHING, so an old worker can never look like it deleted its sessions.
|
|
268249
268626
|
"http:PUT /api/settings/session-retention/apply": { since: "0.3.14", summary: "\u4E0B\u53D1\u4F1A\u8BDD\u4FDD\u7559\u5929\u6570" },
|
|
268250
268627
|
"http:GET /api/path/session-ids": { since: "0.3.14", summary: "\u4F1A\u8BDD id \u5168\u91CF\u6E05\u5355(\u5BF9\u8D26\u7528)" },
|
|
268628
|
+
// Hub-computed hold set (schedules proposed from the session) that keeps a
|
|
268629
|
+
// session out of the worker's own retention sweep — retention-holds.ts.
|
|
268630
|
+
"http:PUT /api/path/retention-holds/:param": { since: "0.3.45", summary: "\u4E0B\u53D1\u4F1A\u8BDD\u4FDD\u7559\u9501(\u9632\u4FDD\u7559\u671F\u6E05\u7406)" },
|
|
268631
|
+
"http:GET /api/path/retention-holds": { since: "0.3.45", summary: "\u5217\u51FA\u6301\u6709\u4FDD\u7559\u9501\u7684\u4F1A\u8BDD(\u91CA\u653E\u8FC7\u671F\u9501)" },
|
|
268251
268632
|
// --- Search / notifications / cross-remote ---
|
|
268252
268633
|
"http:GET /api/path/search-catalog": { since: "0.2.0", summary: "\u641C\u7D22\u76EE\u5F55\u5FEB\u7167" },
|
|
268253
268634
|
// Empirically probed: 0.2.15 → 404, 0.2.16 → 400 (route exists).
|