|
119 | 119 | suggest(workspace.activeView, workspace.last_capability), |
120 | 120 | ); |
121 | 121 |
|
| 122 | + // Focused entity — the org card open in the Org Workbench, broadcast via |
| 123 | + // augment-it:active-entity + localStorage (race-hardened like the search |
| 124 | + // envelope). Lets didi resolve "this org" without asking. |
| 125 | + const ACTIVE_ENTITY_KEY = 'augment-it:active-entity'; |
| 126 | + type ActiveEntity = { type: 'organization'; org_slug: string; display_name?: string }; |
| 127 | + function readActiveEntity(): ActiveEntity | null { |
| 128 | + try { |
| 129 | + const raw = typeof localStorage !== 'undefined' ? localStorage.getItem(ACTIVE_ENTITY_KEY) : null; |
| 130 | + return raw ? (JSON.parse(raw) as ActiveEntity) : null; |
| 131 | + } catch { |
| 132 | + return null; |
| 133 | + } |
| 134 | + } |
| 135 | + let activeEntity = $state<ActiveEntity | null>(readActiveEntity()); |
| 136 | + $effect(() => { |
| 137 | + const onEntity = (e: Event) => { |
| 138 | + activeEntity = ((e as CustomEvent).detail as ActiveEntity | null) ?? null; |
| 139 | + }; |
| 140 | + window.addEventListener('augment-it:active-entity', onEntity); |
| 141 | + return () => window.removeEventListener('augment-it:active-entity', onEntity); |
| 142 | + }); |
| 143 | +
|
122 | 144 | // Send context — what the user is looking at right now. The server |
123 | 145 | // inlines this in the prompt so the model can pick a record_set_id |
124 | 146 | // for prompt.draft without asking. `client_id` is the active workspace, |
|
128 | 150 | focused_prompt_id?: string; |
129 | 151 | record_set_id?: string; |
130 | 152 | client_id?: string; |
| 153 | + focused_org_slug?: string; |
| 154 | + focused_org_name?: string; |
131 | 155 | } | undefined>( |
132 | 156 | (() => { |
133 | | - const ctx: { record_set_id?: string; client_id?: string } = {}; |
| 157 | + const ctx: { |
| 158 | + record_set_id?: string; |
| 159 | + client_id?: string; |
| 160 | + focused_org_slug?: string; |
| 161 | + focused_org_name?: string; |
| 162 | + } = {}; |
134 | 163 | if (workspace.activeView.kind === 'record_set') { |
135 | 164 | ctx.record_set_id = workspace.activeView.record_set_id; |
136 | 165 | } |
137 | 166 | if (workspace.active_client_id) ctx.client_id = workspace.active_client_id; |
| 167 | + if (activeEntity?.type === 'organization') { |
| 168 | + ctx.focused_org_slug = activeEntity.org_slug; |
| 169 | + if (activeEntity.display_name) ctx.focused_org_name = activeEntity.display_name; |
| 170 | + } |
138 | 171 | return Object.keys(ctx).length ? ctx : undefined; |
139 | 172 | })(), |
140 | 173 | ); |
|
0 commit comments