@volter/supercode-teams 0.2.138 → 0.2.140
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/package.json +1 -1
- package/server/harness-routes.mjs +7 -5
- package/worker/index.mjs +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.140",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A machine daemon serving this machine's doors, and a local or remote Teams server for shared session discovery, OpenTelemetry ingestion and access to enrolled machines.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -197,14 +197,15 @@ async function listSessions(api,res,auth,url,requestId,search){
|
|
|
197
197
|
}
|
|
198
198
|
/** A report older than this (four missed heartbeats) says nothing about what the session is doing now. */
|
|
199
199
|
const ACTIVITY_FRESH_MS=60000;
|
|
200
|
-
/**
|
|
201
|
-
async function
|
|
200
|
+
/** The connector's latest fresh native turn report; stale or unrecognized reports remain unknown. */
|
|
201
|
+
async function activityOf(api,teamId,sessionId){
|
|
202
202
|
const row=await api.store.one('SELECT a.turn,a.since,a.observed_at FROM session_activity a JOIN origins o ON o.team_id=a.team_id AND o.source_id=a.source_id AND o.harness=a.harness AND o.native_id=a.native_id WHERE a.team_id=? AND o.deleted_at IS NULL AND o.session_id IN (SELECT id FROM sessions WHERE team_id=? AND (id=? OR canonical_id=?)) ORDER BY a.observed_at DESC LIMIT 1',[teamId,teamId,sessionId,sessionId]);
|
|
203
|
-
return row&&row.turn
|
|
203
|
+
return row&&['working','idle','needs_input'].includes(row.turn)&&api.clock.nowMs()-row.observed_at<ACTIVITY_FRESH_MS?{state:row.turn,since:row.since??row.observed_at,observedAt:row.observed_at}:{state:'unknown'};
|
|
204
204
|
}
|
|
205
205
|
async function sessionDescriptor(api,res,auth,id,requestId){
|
|
206
206
|
const row=await api.store.authorizedSession({teamId:auth.team_id,principalId:auth.principal_id,credentialId:auth.credential_id,ref:id,now:api.clock.nowMs(),bound:auth.bound});
|
|
207
|
-
|
|
207
|
+
const activity=await activityOf(api,auth.team_id,row.id);
|
|
208
|
+
send(res,200,result(api,auth,{...JSON.parse(row.descriptor_json),turnActivity:activity,working:activity.state==='working'?{since:activity.since}:null}),requestId,{ETag:`"${row.revision}"`});
|
|
208
209
|
}
|
|
209
210
|
async function correlateRoute(api,req,res,auth,path,requestId){
|
|
210
211
|
if(!['user','service'].includes(auth.kind)||auth.role==='viewer')fail(403,'forbidden','credential cannot correlate sessions');
|
|
@@ -230,7 +231,8 @@ async function readSession(api,res,auth,id,url,requestId){
|
|
|
230
231
|
const {rows,beforeCursor,revision}=snapshot;
|
|
231
232
|
const messages=rows.map(row=>({id:row.id,source_id:row.source_id,native_key:row.native_key,recorded_at:row.recorded_at,value:JSON.parse(row.value_json)}));
|
|
232
233
|
const descriptor=JSON.parse(snapshot.descriptor_json);
|
|
233
|
-
|
|
234
|
+
const activity=await activityOf(api,auth.team_id,descriptor.id);
|
|
235
|
+
send(res,200,{version:1,context:{server_id:api.serverId,team_id:auth.team_id,principal_id:auth.principal_id},descriptor,turnActivity:activity,working:activity.state==='working'?{since:activity.since}:null,names:await sessionNames(api,auth.team_id,descriptor),messages,before_cursor:beforeCursor,event_cursor:snapshot.eventCursor,revision,display:{returned:messages.length,total:snapshot.total,truncated_fields:0}},requestId);
|
|
234
236
|
}
|
|
235
237
|
async function readArtifact(api,req,res,auth,id,uploadId,requestId){
|
|
236
238
|
const artifact=await api.store.readArtifact({teamId:auth.team_id,principalId:auth.principal_id,credentialId:auth.credential_id,ref:id,uploadId,now:api.clock.nowMs()}),bytes=Buffer.from(artifact.bytes),range=req.headers.range;
|
package/worker/index.mjs
CHANGED
|
@@ -92,7 +92,8 @@ function logStorageBreakdown(sql) {
|
|
|
92
92
|
}
|
|
93
93
|
try {
|
|
94
94
|
const now = Date.now();
|
|
95
|
-
const rows = sql.exec(`WITH
|
|
95
|
+
const rows = sql.exec(`WITH chunk_sizes AS MATERIALIZED (SELECT team_id,upload_id,COUNT(*) chunks,SUM(length(bytes)) bytes FROM artifact_chunks GROUP BY team_id,upload_id),
|
|
96
|
+
staging AS MATERIALIZED (SELECT team_id,begin_json FROM captures WHERE state='staging'),
|
|
96
97
|
classified AS MATERIALIZED (SELECT u.team_id,u.id,u.created_at,
|
|
97
98
|
CASE WHEN EXISTS (SELECT 1 FROM session_artifacts a WHERE a.team_id=u.team_id AND a.upload_id=u.id) THEN 'version-referenced'
|
|
98
99
|
WHEN EXISTS (SELECT 1 FROM continuations c WHERE c.team_id=u.team_id AND instr(c.value_json,u.id)>0) THEN 'continuation-referenced'
|
|
@@ -100,9 +101,9 @@ function logStorageBreakdown(sql) {
|
|
|
100
101
|
WHEN u.created_at+86400000>? THEN 'unreferenced-under-one-day'
|
|
101
102
|
WHEN u.committed=1 THEN 'eligible-committed' ELSE 'expired-staging' END category
|
|
102
103
|
FROM uploads u)
|
|
103
|
-
SELECT u.category,COUNT(
|
|
104
|
+
SELECT u.category,COUNT(*) uploads,SUM(c.chunks) chunks,SUM(c.bytes) blob_bytes,
|
|
104
105
|
MIN(u.created_at) oldest_at,MAX(u.created_at) newest_at
|
|
105
|
-
FROM
|
|
106
|
+
FROM chunk_sizes c LEFT JOIN classified u ON u.team_id=c.team_id AND u.id=c.upload_id GROUP BY u.category`, now);
|
|
106
107
|
for (const row of rows) console.log(`storage uploads: ${JSON.stringify(row)}`);
|
|
107
108
|
} catch (error) { console.log(`storage upload classification: ${error.message}`); }
|
|
108
109
|
}
|