@@ -178,8 +178,15 @@ 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- function endpointOf ( method : string , basePath : string , subpath : string ) : string {
182- return `${ method } ${ basePath } ${ subpath } ` . replace ( / \/ \d + (? = \/ | $ ) / g, "/:id" )
181+ /** "METHOD /base/path" with every dynamic segment replaced by ":id". Route words are lowercase
182+ * letters with hyphens or underscores (or a version like v3); anything else — numeric ids,
183+ * uuids, memory and skill public ids — is an identifier and must not reach telemetry. */
184+ export function endpointOf ( method : string , basePath : string , subpath : string ) : string {
185+ const masked = `${ basePath } ${ subpath } `
186+ . split ( "/" )
187+ . map ( ( seg ) => ( seg === "" || / ^ ( v \d + | [ a - z ] [ a - z _ - ] * ) $ / . test ( seg ) ? seg : ":id" ) )
188+ . join ( "/" )
189+ return `${ method } ${ masked } `
183190}
184191
185192function workspaceIdIn ( body : unknown ) : number | undefined {
@@ -192,7 +199,7 @@ function workspaceIdIn(body: unknown): number | undefined {
192199function reportApiError ( input : {
193200 endpoint : string
194201 status ?: number
195- kind : "4xx" | "5xx" | "network" | "timeout"
202+ kind : "4xx" | "5xx" | "network" | "timeout" | "response"
196203 workspaceId ?: number
197204} ) {
198205 const session_id = Telemetry . getContext ( ) . sessionId
@@ -372,7 +379,13 @@ async function req<T>(
372379 `Request to ${ target } timed out after ${ Math . round ( timeoutMs / 1000 ) } s` ,
373380 )
374381 }
375- reportApiError ( { endpoint, kind : "network" , workspaceId : bodyWorkspaceId } )
382+ // A WorkspaceApiError here came from readBounded(): the server answered, the body was
383+ // over the cap. Everything else is transport.
384+ reportApiError ( {
385+ endpoint,
386+ kind : err instanceof WorkspaceApiError ? "response" : "network" ,
387+ workspaceId : bodyWorkspaceId ,
388+ } )
376389 const msg = err instanceof Error ? err . message : String ( err )
377390 throw new WorkspaceApiError ( `Cannot reach ${ target } : ${ msg } ` )
378391 } finally {
@@ -427,6 +440,7 @@ async function req<T>(
427440 // is treated as an empty body too — otherwise ``null as T`` reaches callers
428441 // and .foo throws in a way the typed switches can't classify. (m7 + CR)
429442 if ( json == null && ! opts . allowEmptyBody ) {
443+ reportApiError ( { endpoint, status : res . status , kind : "response" , workspaceId : bodyWorkspaceId } )
430444 throw new WorkspaceApiError (
431445 `Empty ${ res . status } body from ${ target } — expected JSON payload` ,
432446 res . status ,
0 commit comments