@volter/supercode-teams 0.2.38 → 0.2.39
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 +10 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/supercode-teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.39",
|
|
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",
|
|
@@ -172,9 +172,16 @@ async function listSessions(api,res,auth,url,requestId,search){
|
|
|
172
172
|
if(search)body.coverage={scope:'retained_text',indexed_at:boundaryNow,indexed_revision:team.journal_revision};
|
|
173
173
|
send(res,200,body,requestId);
|
|
174
174
|
}
|
|
175
|
+
/** A report older than this (four missed heartbeats) says nothing about what the session is doing now. */
|
|
176
|
+
const ACTIVITY_FRESH_MS=60000;
|
|
177
|
+
/** `{since}` while the session's harness is working on a turn, by its connector's latest fresh report; else null. */
|
|
178
|
+
async function workingOf(api,teamId,sessionId){
|
|
179
|
+
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]);
|
|
180
|
+
return row&&row.turn==='working'&&api.clock.nowMs()-row.observed_at<ACTIVITY_FRESH_MS?{since:row.since??row.observed_at}:null;
|
|
181
|
+
}
|
|
175
182
|
async function sessionDescriptor(api,res,auth,id,requestId){
|
|
176
183
|
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});
|
|
177
|
-
send(res,200,result(api,auth,JSON.parse(row.descriptor_json)),requestId,{ETag:`"${row.revision}"`});
|
|
184
|
+
send(res,200,result(api,auth,{...JSON.parse(row.descriptor_json),working:await workingOf(api,auth.team_id,row.id)}),requestId,{ETag:`"${row.revision}"`});
|
|
178
185
|
}
|
|
179
186
|
async function correlateRoute(api,req,res,auth,path,requestId){
|
|
180
187
|
if(!['user','service'].includes(auth.kind)||auth.role==='viewer')fail(403,'forbidden','credential cannot correlate sessions');
|
|
@@ -198,7 +205,8 @@ async function readSession(api,res,auth,id,url,requestId){
|
|
|
198
205
|
const snapshot=await api.store.readSessionSnapshot({teamId:auth.team_id,principalId:auth.principal_id,credentialId:auth.credential_id,ref:id,now:api.clock.nowMs(),bound:auth.bound,beforeHash:query.before?cursorHash(query.before):null,requestedRevision:query.revision,tail,nextCursorHash:cursorHash(nextCursor),nextCursorToken:nextCursor});
|
|
199
206
|
const {rows,beforeCursor,revision}=snapshot;
|
|
200
207
|
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)}));
|
|
201
|
-
|
|
208
|
+
const descriptor=JSON.parse(snapshot.descriptor_json);
|
|
209
|
+
send(res,200,{version:1,context:{server_id:api.serverId,team_id:auth.team_id,principal_id:auth.principal_id},descriptor,working:await workingOf(api,auth.team_id,descriptor.id),messages,before_cursor:beforeCursor,event_cursor:snapshot.eventCursor,revision,display:{returned:messages.length,total:snapshot.total,truncated_fields:0}},requestId);
|
|
202
210
|
}
|
|
203
211
|
async function readArtifact(api,req,res,auth,id,uploadId,requestId){
|
|
204
212
|
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;
|