@@ -9,7 +9,12 @@ import {
99} from "lucide-solid" ;
1010
1111import Button from "../components/button" ;
12- import { createOpenworkServerClient , OpenworkServerError } from "../lib/openwork-server" ;
12+ import {
13+ buildOpenworkWorkspaceBaseUrl ,
14+ createOpenworkServerClient ,
15+ OpenworkServerError ,
16+ parseOpenworkWorkspaceIdFromUrl ,
17+ } from "../lib/openwork-server" ;
1318import type {
1419 OpenworkOwpenbotHealthSnapshot ,
1520 OpenworkOwpenbotIdentityItem ,
@@ -122,21 +127,34 @@ export default function IdentitiesView(props: IdentitiesViewProps) {
122127
123128 const [ expandedChannel , setExpandedChannel ] = createSignal < string | null > ( null ) ;
124129
125- const openworkServerClient = createMemo ( ( ) => {
130+ const workspaceId = createMemo ( ( ) => {
131+ const explicitId = props . openworkServerWorkspaceId ?. trim ( ) ?? "" ;
132+ if ( explicitId ) return explicitId ;
133+ return parseOpenworkWorkspaceIdFromUrl ( props . openworkServerUrl ) ?? "" ;
134+ } ) ;
135+
136+ const scopedOpenworkBaseUrl = createMemo ( ( ) => {
126137 const baseUrl = props . openworkServerUrl . trim ( ) ;
138+ if ( ! baseUrl ) return "" ;
139+ return buildOpenworkWorkspaceBaseUrl ( baseUrl , workspaceId ( ) ) ?? baseUrl ;
140+ } ) ;
141+
142+ const openworkServerClient = createMemo ( ( ) => {
143+ const baseUrl = scopedOpenworkBaseUrl ( ) . trim ( ) ;
127144 const localBaseUrl = props . openworkServerHostInfo ?. baseUrl ?. trim ( ) ?? "" ;
145+ const localScopedBaseUrl = buildOpenworkWorkspaceBaseUrl ( localBaseUrl , workspaceId ( ) ) ?? localBaseUrl ;
128146 const hostToken = props . openworkServerHostInfo ?. hostToken ?. trim ( ) ?? "" ;
129147 const clientToken = props . openworkServerHostInfo ?. clientToken ?. trim ( ) ?? "" ;
130148 const settingsToken = props . openworkServerSettings . token ?. trim ( ) ?? "" ;
131149
132- const isLocalServer = localBaseUrl && baseUrl === localBaseUrl ;
150+ const isLocalServer = Boolean ( localBaseUrl ) && ( baseUrl === localBaseUrl || baseUrl === localScopedBaseUrl ) ;
133151 const token = isLocalServer ? ( clientToken || settingsToken ) : ( settingsToken || clientToken ) ;
134152 if ( ! baseUrl || ! token ) return null ;
135153 return createOpenworkServerClient ( { baseUrl, token, hostToken : isLocalServer ? hostToken : undefined } ) ;
136154 } ) ;
137155
138156 const serverReady = createMemo ( ( ) => props . openworkServerStatus === "connected" && Boolean ( openworkServerClient ( ) ) ) ;
139- const workspaceId = createMemo ( ( ) => props . openworkServerWorkspaceId ?. trim ( ) || "" ) ;
157+ const scopedWorkspaceReady = createMemo ( ( ) => Boolean ( workspaceId ( ) ) ) ;
140158
141159 let lastResetKey = "" ;
142160
@@ -167,21 +185,29 @@ export default function IdentitiesView(props: IdentitiesViewProps) {
167185 if ( ! serverReady ( ) ) return ;
168186 const client = openworkServerClient ( ) ;
169187 if ( ! client ) return ;
188+ const id = workspaceId ( ) ;
170189
171190 setRefreshing ( true ) ;
172191 try {
173192 setHealthError ( null ) ;
174193 setTelegramIdentitiesError ( null ) ;
175194 setSlackIdentitiesError ( null ) ;
176195
196+ if ( ! id ) {
197+ setHealth ( null ) ;
198+ setTelegramIdentities ( [ ] ) ;
199+ setSlackIdentities ( [ ] ) ;
200+ setHealthError ( "Workspace scope unavailable. Reconnect using a workspace URL or switch to a known workspace." ) ;
201+ setTelegramIdentitiesError ( "Workspace scope unavailable." ) ;
202+ setSlackIdentitiesError ( "Workspace scope unavailable." ) ;
203+ setLastUpdatedAt ( null ) ;
204+ return ;
205+ }
206+
177207 const [ healthRes , tgRes , slackRes ] = await Promise . all ( [
178208 client . owpenbotHealth ( ) ,
179- workspaceId ( )
180- ? client . getOwpenbotTelegramIdentities ( workspaceId ( ) )
181- : client . owpenbotTelegramIdentities ( ) . then ( ( raw ) => raw . json as unknown ) ,
182- workspaceId ( )
183- ? client . getOwpenbotSlackIdentities ( workspaceId ( ) )
184- : client . owpenbotSlackIdentities ( ) . then ( ( raw ) => raw . json as unknown ) ,
209+ client . getOwpenbotTelegramIdentities ( id ) ,
210+ client . getOwpenbotSlackIdentities ( id ) ,
185211 ] ) ;
186212
187213 if ( isOwpenbotSnapshot ( healthRes . json ) ) {
@@ -359,7 +385,7 @@ export default function IdentitiesView(props: IdentitiesViewProps) {
359385 } ;
360386
361387 createEffect ( ( ) => {
362- const baseUrl = props . openworkServerUrl . trim ( ) ;
388+ const baseUrl = scopedOpenworkBaseUrl ( ) . trim ( ) ;
363389 const id = workspaceId ( ) ;
364390 const nextKey = `${ baseUrl } |${ id } ` ;
365391 if ( nextKey === lastResetKey ) return ;
@@ -405,6 +431,9 @@ export default function IdentitiesView(props: IdentitiesViewProps) {
405431 Let people reach your worker through messaging apps. Connect a channel and
406432 your worker will automatically read and respond to messages.
407433 </ p >
434+ < div class = "mt-1.5 text-[11px] text-gray-8 font-mono truncate" >
435+ Workspace scope: { scopedOpenworkBaseUrl ( ) . trim ( ) || props . openworkServerUrl . trim ( ) || "Not set" }
436+ </ div >
408437 </ div >
409438
410439 { /* ---- Not connected to server ---- */ }
@@ -418,6 +447,11 @@ export default function IdentitiesView(props: IdentitiesViewProps) {
418447 </ Show >
419448
420449 < Show when = { serverReady ( ) } >
450+ < Show when = { ! scopedWorkspaceReady ( ) } >
451+ < div class = "rounded-xl border border-amber-7/20 bg-amber-1/30 px-3 py-2 text-xs text-amber-12" >
452+ Workspace ID is required to manage identities. Reconnect with a workspace URL (for example: < code class = "text-[11px]" > /w/<workspace-id></ code > ) or select a workspace mapped on this host.
453+ </ div >
454+ </ Show >
421455
422456 { /* ---- Worker status card ---- */ }
423457 < div class = "rounded-xl border border-gray-4 bg-gray-1 p-4 space-y-3.5" >
0 commit comments