@openscout/scout 0.2.48 → 0.2.50

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.
@@ -13642,7 +13642,9 @@ var scoutBrokerPaths = {
13642
13642
  endpoints: "/v1/endpoints",
13643
13643
  conversations: "/v1/conversations",
13644
13644
  invocations: "/v1/invocations",
13645
- activity: "/v1/activity"
13645
+ activity: "/v1/activity",
13646
+ collaborationRecords: "/v1/collaboration/records",
13647
+ collaborationEvents: "/v1/collaboration/events"
13646
13648
  }
13647
13649
  };
13648
13650
 
@@ -14109,12 +14111,38 @@ function compact(p) {
14109
14111
  return null;
14110
14112
  return p.startsWith(HOME) ? `~${p.slice(HOME.length)}` : p;
14111
14113
  }
14114
+ var LATEST_AGENT_ENDPOINT_JOIN = `LEFT JOIN agent_endpoints ep ON ep.id = (
14115
+ SELECT ep2.id
14116
+ FROM agent_endpoints ep2
14117
+ WHERE ep2.agent_id = a.id
14118
+ ORDER BY ep2.updated_at DESC
14119
+ LIMIT 1
14120
+ )`;
14121
+ function queryExecutingAgentIds() {
14122
+ return new Set(db().prepare(`SELECT DISTINCT target_agent_id FROM flights
14123
+ WHERE state = 'running'`).all().map((row) => row.target_agent_id));
14124
+ }
14125
+ function summarizeAgentState(rawState, isWorking) {
14126
+ if (isWorking) {
14127
+ return "working";
14128
+ }
14129
+ return rawState && rawState !== "offline" ? "available" : "offline";
14130
+ }
14131
+ function summarizeAgentStatusLabel(rawState, isWorking) {
14132
+ switch (summarizeAgentState(rawState, isWorking)) {
14133
+ case "working":
14134
+ return "Working";
14135
+ case "available":
14136
+ return "Available";
14137
+ default:
14138
+ return "Offline";
14139
+ }
14140
+ }
14112
14141
  function conversationIdForAgent(agentId) {
14113
14142
  return `dm.operator.${agentId}`;
14114
14143
  }
14115
14144
  function queryMobileAgents(limit = 50) {
14116
- const workingAgentIds = new Set(db().prepare(`SELECT DISTINCT target_agent_id FROM flights
14117
- WHERE state NOT IN ('completed','failed','cancelled')`).all().map((r) => r.target_agent_id));
14145
+ const executingAgentIds = queryExecutingAgentIds();
14118
14146
  const lastMessageAt = new Map(db().prepare(`SELECT actor_id, MAX(created_at) AS last_at FROM messages GROUP BY actor_id`).all().map((r) => [r.actor_id, r.last_at]));
14119
14147
  const rows = db().prepare(`SELECT
14120
14148
  a.id,
@@ -14129,17 +14157,17 @@ function queryMobileAgents(limit = 50) {
14129
14157
  ep.updated_at
14130
14158
  FROM agents a
14131
14159
  JOIN actors ac ON ac.id = a.id
14132
- LEFT JOIN agent_endpoints ep ON ep.agent_id = a.id
14133
- ORDER BY ep.updated_at DESC NULLS LAST
14160
+ ${LATEST_AGENT_ENDPOINT_JOIN}
14161
+ ORDER BY COALESCE(ep.updated_at, 0) DESC, ac.display_name ASC
14134
14162
  LIMIT ?`).all(limit);
14135
14163
  return rows.map((r) => {
14136
14164
  let meta = {};
14137
14165
  try {
14138
14166
  meta = r.metadata_json ? JSON.parse(r.metadata_json) : {};
14139
14167
  } catch {}
14140
- const isWorking = workingAgentIds.has(r.id);
14141
- const state = isWorking ? "working" : r.state && r.state !== "offline" ? "available" : "offline";
14142
- const statusLabel = isWorking ? "Working" : r.state === "active" ? "Available" : r.state ?? "Offline";
14168
+ const isWorking = executingAgentIds.has(r.id);
14169
+ const state = summarizeAgentState(r.state, isWorking);
14170
+ const statusLabel = summarizeAgentStatusLabel(r.state, isWorking);
14143
14171
  return {
14144
14172
  id: r.id,
14145
14173
  title: r.display_name,
@@ -14149,7 +14177,7 @@ function queryMobileAgents(limit = 50) {
14149
14177
  harness: r.harness,
14150
14178
  transport: r.transport,
14151
14179
  state,
14152
- statusLabel: statusLabel.charAt(0).toUpperCase() + statusLabel.slice(1),
14180
+ statusLabel,
14153
14181
  sessionId: conversationIdForAgent(r.id),
14154
14182
  lastActiveAt: lastMessageAt.get(r.id) ?? null
14155
14183
  };
@@ -14271,7 +14299,7 @@ function queryMobileAgentDetail(agentId) {
14271
14299
  ep.updated_at
14272
14300
  FROM agents a
14273
14301
  JOIN actors ac ON ac.id = a.id
14274
- LEFT JOIN agent_endpoints ep ON ep.agent_id = a.id
14302
+ ${LATEST_AGENT_ENDPOINT_JOIN}
14275
14303
  WHERE a.id = ?`).get(agentId);
14276
14304
  if (!row)
14277
14305
  return null;
@@ -14283,8 +14311,7 @@ function queryMobileAgentDetail(agentId) {
14283
14311
  try {
14284
14312
  capabilities = row.capabilities_json ? JSON.parse(row.capabilities_json) : [];
14285
14313
  } catch {}
14286
- const workingAgentIds = new Set(db().prepare(`SELECT DISTINCT target_agent_id FROM flights
14287
- WHERE state NOT IN ('completed','failed','cancelled')`).all().map((r) => r.target_agent_id));
14314
+ const executingAgentIds = queryExecutingAgentIds();
14288
14315
  const activeFlights = db().prepare(`SELECT id, state, summary, started_at
14289
14316
  FROM flights
14290
14317
  WHERE target_agent_id = ? AND state NOT IN ('completed','failed','cancelled')
@@ -14308,9 +14335,9 @@ function queryMobileAgentDetail(agentId) {
14308
14335
  const msgRow = db().prepare(`SELECT COUNT(*) AS cnt FROM messages WHERE conversation_id = ?`).get(conversationIdForAgent(agentId));
14309
14336
  const messageCount = msgRow?.cnt ?? 0;
14310
14337
  const lastMessageAt = db().prepare(`SELECT MAX(created_at) AS last_at FROM messages WHERE actor_id = ?`).get(agentId)?.last_at ?? null;
14311
- const isWorking = workingAgentIds.has(row.id);
14312
- const state = isWorking ? "working" : row.state && row.state !== "offline" ? "available" : "offline";
14313
- const statusLabel = isWorking ? "Working" : row.state === "active" ? "Available" : row.state ?? "Offline";
14338
+ const isWorking = executingAgentIds.has(row.id);
14339
+ const state = summarizeAgentState(row.state, isWorking);
14340
+ const statusLabel = summarizeAgentStatusLabel(row.state, isWorking);
14314
14341
  return {
14315
14342
  id: row.id,
14316
14343
  title: row.display_name,
@@ -14320,7 +14347,7 @@ function queryMobileAgentDetail(agentId) {
14320
14347
  harness: row.harness,
14321
14348
  transport: row.transport,
14322
14349
  state,
14323
- statusLabel: statusLabel.charAt(0).toUpperCase() + statusLabel.slice(1),
14350
+ statusLabel,
14324
14351
  sessionId: conversationIdForAgent(row.id),
14325
14352
  lastActiveAt: lastMessageAt,
14326
14353
  cwd: compact(row.cwd),
@@ -14429,7 +14456,7 @@ function endpointForAgent(snapshot, agentId) {
14429
14456
  function buildMobileAgentSummary(snapshot, agent) {
14430
14457
  const endpoint = endpointForAgent(snapshot, agent.id);
14431
14458
  const flights = Object.values(snapshot.flights).filter((flight) => flight.targetAgentId === agent.id);
14432
- const hasWorkingFlight = flights.some((flight) => !["completed", "failed", "cancelled"].includes(flight.state));
14459
+ const hasWorkingFlight = flights.some((flight) => flight.state === "running");
14433
14460
  const lastAuthoredMessageAt = Object.values(snapshot.messages).filter((message) => message.actorId === agent.id).reduce((latest, message) => {
14434
14461
  const createdAt = normalizeTimestamp(message.createdAt);
14435
14462
  return typeof createdAt === "number" && (!latest || createdAt > latest) ? createdAt : latest;
@@ -14444,7 +14471,7 @@ function buildMobileAgentSummary(snapshot, agent) {
14444
14471
  harness: endpoint?.harness ?? null,
14445
14472
  transport: endpoint?.transport ?? null,
14446
14473
  state,
14447
- statusLabel: hasWorkingFlight ? "Working" : endpoint?.state === "active" ? "Available" : endpoint?.state ?? "Offline",
14474
+ statusLabel: state === "working" ? "Working" : state === "available" ? "Available" : "Offline",
14448
14475
  sessionId: endpoint?.sessionId ?? null,
14449
14476
  lastActiveAt: lastAuthoredMessageAt
14450
14477
  };