@@ -178,23 +178,35 @@ async function creds(): Promise<{ url: string; instance: string; apiKey: string
178178// `workspace_api_error` (or `workspace_auth_expired` on 401/403) with the endpoint masked of
179179// ids; the link lifecycle functions below report linked / created / switched / unlinked on the
180180// success response and `workspace_link_failed` with a reason class otherwise.
181- /** The static segments of the routes the workspace clients call. Anything not in this list —
182- * numeric ids, uuids, memory ids, skill public ids however they are spelled — is replaced by
183- * ":id" in telemetry. A new static word that is missing here is masked too, which only costs
184- * detail; the list must never be widened with a dynamic value. */
181+ /** Endpoint labels mask by ROUTE POSITION, not by spelling. The routers whose subpaths start
182+ * with a static word are listed here; on every other base (``/skills``, ``/datamates/memory``)
183+ * the first subpath segment is an identifier and is masked whatever it is spelled like — a
184+ * public id equal to a route word must not reach telemetry. Segments after that, and the
185+ * segments of the base itself, are kept only when they are known static words; an unknown
186+ * static word is masked too, which only costs detail. A new router with a static first segment
187+ * is added here; a new identifier-first router needs nothing. */
188+ const STATIC_FIRST_SEGMENT_BASES = new Set ( [ "/datamate-project-bindings" , "/datamates" , "/users" ] )
185189const ROUTE_WORDS = new Set ( [
186190 "datamate-project-bindings" , "bind" , "by-remote" , "by-path" , "datamates" , "users" , "me" ,
187191 "memory" , "blocks" , "skills" , "files" , "list" , "attach" , "publish" , "sync" , "status" , "search" ,
188192 "versions" , "lessons" , "learned-lessons" , "content" , "download" ,
189193] )
190194
191- /** "METHOD /base/path" with every dynamic segment replaced by ":id" (see ROUTE_WORDS ). */
195+ /** "METHOD /base/path" with every dynamic segment replaced by ":id" (see the note above ). */
192196export function endpointOf ( method : string , basePath : string , subpath : string ) : string {
193- const masked = `${ basePath } ${ subpath } `
197+ const word = ( seg : string ) => ( seg === "" || ROUTE_WORDS . has ( seg ) ? seg : ":id" )
198+ const base = basePath . split ( "/" ) . map ( word ) . join ( "/" )
199+ let first = true
200+ const sub = subpath
194201 . split ( "/" )
195- . map ( ( seg ) => ( seg === "" || ROUTE_WORDS . has ( seg ) ? seg : ":id" ) )
202+ . map ( ( seg ) => {
203+ if ( seg === "" ) return seg
204+ const idPosition = first && ! STATIC_FIRST_SEGMENT_BASES . has ( basePath )
205+ first = false
206+ return idPosition ? ":id" : word ( seg )
207+ } )
196208 . join ( "/" )
197- return `${ method } ${ masked } `
209+ return `${ method } ${ base } ${ sub } `
198210}
199211
200212function workspaceIdIn ( body : unknown ) : number | undefined {
@@ -384,7 +396,15 @@ async function req<T>(
384396 // The abort fires equally when it kills the fetch OR the body read. (m8)
385397 const name = ( err as { name ?: string } | undefined ) ?. name
386398 if ( name === "AbortError" ) {
387- reportApiError ( { endpoint, kind : "timeout" , workspaceId : bodyWorkspaceId } )
399+ // A timeout after the server answered (the body stalled) keeps the answer's status:
400+ // a 500 whose body never arrives is still a 5xx row; a 2xx whose body never arrives
401+ // stays a timeout, with the status attached.
402+ reportApiError ( {
403+ endpoint,
404+ ...( answered !== undefined ? { status : answered } : { } ) ,
405+ kind : answered === undefined ? "timeout" : answered >= 500 ? "5xx" : answered >= 400 ? "4xx" : "timeout" ,
406+ workspaceId : bodyWorkspaceId ,
407+ } )
388408 throw new WorkspaceApiError (
389409 `Request to ${ target } timed out after ${ Math . round ( timeoutMs / 1000 ) } s` ,
390410 )
0 commit comments