@opengeni/react 1.2.1-canary.37222965366001 → 1.4.0

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.
Files changed (75) hide show
  1. package/README.md +52 -1
  2. package/dist/artifacts.js +2 -2
  3. package/dist/artifacts.js.map +1 -1
  4. package/dist/{chunk-ERGYJIBB.js → chunk-AWZLIMKX.js} +2 -2
  5. package/dist/{chunk-ERGYJIBB.js.map → chunk-AWZLIMKX.js.map} +1 -1
  6. package/dist/{chunk-FZCP527Y.js → chunk-CJUO7J5Z.js} +2 -2
  7. package/dist/{chunk-742CZ3L3.js → chunk-H5X55XH7.js} +16 -200
  8. package/dist/chunk-H5X55XH7.js.map +1 -0
  9. package/dist/{chunk-4OTO7KBK.js → chunk-LJ2UTJJE.js} +2737 -1580
  10. package/dist/chunk-LJ2UTJJE.js.map +1 -0
  11. package/dist/{chunk-CY7WK5FD.js → chunk-LN6TCXD3.js} +22 -1
  12. package/dist/chunk-LN6TCXD3.js.map +1 -0
  13. package/dist/{chunk-TMYGL6X5.js → chunk-MBMPHOMA.js} +71 -6
  14. package/dist/chunk-MBMPHOMA.js.map +1 -0
  15. package/dist/{chunk-RC6BZ44Q.js → chunk-OA6HFRQP.js} +2 -2
  16. package/dist/{chunk-X34BSY2R.js → chunk-WZMYFJD3.js} +242 -63
  17. package/dist/chunk-WZMYFJD3.js.map +1 -0
  18. package/dist/components/approval-surface.d.ts +11 -13
  19. package/dist/components/composer-transcription-control.d.ts +3 -0
  20. package/dist/components/open-geni-chat.d.ts +26 -7
  21. package/dist/components/session-conversation.d.ts +26 -3
  22. package/dist/components/session-list.d.ts +4 -1
  23. package/dist/components/session-proxy-scope.d.ts +16 -2
  24. package/dist/components/tool-action-review.d.ts +47 -0
  25. package/dist/components/tool-review-history.d.ts +25 -0
  26. package/dist/composer.js +1 -1
  27. package/dist/connect.js +1 -1
  28. package/dist/hooks/use-client-config-flags.d.ts +37 -0
  29. package/dist/index.d.ts +7 -4
  30. package/dist/index.js +27 -11
  31. package/dist/index.js.map +1 -1
  32. package/dist/{latest-question-YTOBHCWR.js → latest-question-GPYM2JNU.js} +3 -3
  33. package/dist/realtime/realtime-control.d.ts +2 -0
  34. package/dist/realtime.js +25 -4
  35. package/dist/realtime.js.map +1 -1
  36. package/dist/session-capability-policy.d.ts +20 -1
  37. package/dist/session-ui.d.ts +4 -1
  38. package/dist/session-ui.js +12 -6
  39. package/dist/session-ui.js.map +1 -1
  40. package/dist/session.js +6 -6
  41. package/dist/timeline/index.d.ts +2 -0
  42. package/dist/timeline/retained-loaders.d.ts +27 -0
  43. package/package.json +3 -3
  44. package/src/components/approval-surface.tsx +368 -239
  45. package/src/components/artifacts/session-artifact-viewer.tsx +4 -2
  46. package/src/components/composer-transcription-control.tsx +14 -0
  47. package/src/components/composer.tsx +1 -0
  48. package/src/components/open-geni-chat.tsx +245 -72
  49. package/src/components/session-conversation.tsx +243 -58
  50. package/src/components/session-list.tsx +9 -2
  51. package/src/components/session-proxy-scope.tsx +47 -7
  52. package/src/components/tool-action-review.tsx +649 -0
  53. package/src/components/tool-review-history.tsx +88 -0
  54. package/src/hooks/use-client-config-flags.ts +102 -0
  55. package/src/hooks/use-session-events.ts +19 -16
  56. package/src/hooks/use-transcription.ts +6 -0
  57. package/src/hooks/use-voice-input.ts +6 -0
  58. package/src/index.ts +18 -1
  59. package/src/realtime/realtime-control.tsx +28 -1
  60. package/src/session-capability-policy.ts +119 -6
  61. package/src/session-ui.ts +9 -1
  62. package/src/timeline/index.ts +10 -0
  63. package/src/timeline/retained-loaders.ts +86 -0
  64. package/src/timeline/tool-display-name.ts +5 -1
  65. package/src/timeline/tool-renderers.tsx +148 -8
  66. package/styles/compiled.css +79 -15
  67. package/styles/tokens.css +1 -1
  68. package/dist/chunk-4OTO7KBK.js.map +0 -1
  69. package/dist/chunk-742CZ3L3.js.map +0 -1
  70. package/dist/chunk-CY7WK5FD.js.map +0 -1
  71. package/dist/chunk-TMYGL6X5.js.map +0 -1
  72. package/dist/chunk-X34BSY2R.js.map +0 -1
  73. /package/dist/{chunk-FZCP527Y.js.map → chunk-CJUO7J5Z.js.map} +0 -0
  74. /package/dist/{chunk-RC6BZ44Q.js.map → chunk-OA6HFRQP.js.map} +0 -0
  75. /package/dist/{latest-question-YTOBHCWR.js.map → latest-question-GPYM2JNU.js.map} +0 -0
@@ -1,15 +1,10 @@
1
1
  import {
2
2
  useDebouncedCallback,
3
3
  useMutationRunner,
4
- usePageLiveActivity,
5
4
  usePolledValue,
6
5
  useSessionEventTrigger
7
6
  } from "./chunk-YQEAA6LT.js";
8
7
  import {
9
- normalizeError
10
- } from "./chunk-UGLEYEMP.js";
11
- import {
12
- useEmbeddedGoal,
13
8
  useEmbeddedSessionLineage,
14
9
  useEmbeddedSessionMcpApprovalPolicy
15
10
  } from "./chunk-TKOTKRWY.js";
@@ -81,185 +76,8 @@ function createEmbeddedSessionClient(base, options = {}) {
81
76
  return client;
82
77
  }
83
78
 
84
- // src/hooks/use-goal.ts
85
- import { OpenGeniApiError } from "@opengeni/sdk";
86
- import { useCallback, useEffect, useRef, useState } from "react";
87
- function isGoalEvent(event) {
88
- return event.type.startsWith("goal.");
89
- }
90
- function isGoalRefreshEvent(event) {
91
- const type = event.type;
92
- return isGoalEvent(event) || type.startsWith("turn.") || type.startsWith("session.") || type.startsWith("system.update.") || type.startsWith("workspace.inference.") || type.startsWith("user.");
93
- }
94
- function useGoal(sessionId, options = {}) {
95
- const { client, workspaceId } = useEmbeddedGoal(options);
96
- const enabled = (options.enabled ?? true) && Boolean(sessionId);
97
- const sharedEvents = options.events;
98
- const sharedFeed = sharedEvents !== void 0;
99
- const pageLive = usePageLiveActivity();
100
- const [goal, setGoal] = useState(null);
101
- const [loading, setLoading] = useState(enabled);
102
- const [error, setError] = useState(null);
103
- const { run, mutating, mutationError, clearMutationError } = useMutationRunner();
104
- const generation = useRef(0);
105
- const targetKeyRef = useRef(null);
106
- const loadAbort = useRef(null);
107
- const retireLoads = useCallback(() => {
108
- generation.current += 1;
109
- loadAbort.current?.abort();
110
- loadAbort.current = null;
111
- }, []);
112
- const load = useCallback(async () => {
113
- if (!sessionId) {
114
- return;
115
- }
116
- const ticket = ++generation.current;
117
- loadAbort.current?.abort();
118
- const controller = new AbortController();
119
- loadAbort.current = controller;
120
- try {
121
- const fetched = await client.getGoal(workspaceId, sessionId, {
122
- signal: controller.signal
123
- });
124
- if (ticket === generation.current) {
125
- setGoal(fetched);
126
- setError(null);
127
- setLoading(false);
128
- }
129
- } catch (cause) {
130
- if (ticket !== generation.current) {
131
- return;
132
- }
133
- if (cause instanceof OpenGeniApiError && cause.status === 404) {
134
- setGoal(null);
135
- setError(null);
136
- } else {
137
- setError(normalizeError(cause));
138
- }
139
- setLoading(false);
140
- } finally {
141
- if (loadAbort.current === controller) loadAbort.current = null;
142
- }
143
- }, [client, workspaceId, sessionId]);
144
- useEffect(() => {
145
- const targetKey = `${workspaceId} ${sessionId ?? ""}`;
146
- if (targetKeyRef.current !== targetKey) {
147
- targetKeyRef.current = targetKey;
148
- setGoal(null);
149
- setError(null);
150
- }
151
- if (!enabled || !pageLive) {
152
- retireLoads();
153
- setLoading(false);
154
- return;
155
- }
156
- if (sharedFeed) {
157
- setLoading(true);
158
- void load();
159
- return () => {
160
- retireLoads();
161
- };
162
- }
163
- setLoading(true);
164
- const pollIntervalMs = options.pollIntervalMs;
165
- if (pollIntervalMs === void 0 || pollIntervalMs <= 0) {
166
- void load();
167
- return () => {
168
- retireLoads();
169
- };
170
- }
171
- let cancelled = false;
172
- let timer = null;
173
- const schedule = () => {
174
- if (cancelled) return;
175
- timer = setTimeout(() => {
176
- timer = null;
177
- void load().finally(schedule);
178
- }, pollIntervalMs);
179
- };
180
- void load().finally(schedule);
181
- return () => {
182
- cancelled = true;
183
- if (timer !== null) clearTimeout(timer);
184
- retireLoads();
185
- };
186
- }, [
187
- load,
188
- enabled,
189
- pageLive,
190
- workspaceId,
191
- sessionId,
192
- options.pollIntervalMs,
193
- retireLoads,
194
- sharedFeed
195
- ]);
196
- const scheduleRefresh = useDebouncedCallback(() => void load());
197
- useSessionEventTrigger(client, workspaceId, sessionId, isGoalRefreshEvent, scheduleRefresh, {
198
- enabled,
199
- ...sharedEvents !== void 0 ? { events: sharedEvents } : {}
200
- });
201
- const pause = useCallback(
202
- async (rationale) => {
203
- if (!sessionId) {
204
- return null;
205
- }
206
- const result = await run(
207
- () => client.updateGoal(workspaceId, sessionId, {
208
- status: "paused",
209
- ...rationale !== void 0 ? { rationale } : {}
210
- })
211
- );
212
- if (result) {
213
- setGoal(result);
214
- }
215
- return result;
216
- },
217
- [client, workspaceId, sessionId, run]
218
- );
219
- const resume = useCallback(async () => {
220
- if (!sessionId) {
221
- return null;
222
- }
223
- const result = await run(() => client.updateGoal(workspaceId, sessionId, { status: "active" }));
224
- if (result) {
225
- setGoal(result);
226
- }
227
- return result;
228
- }, [client, workspaceId, sessionId, run]);
229
- const clearGoal = useCallback(async () => {
230
- if (!sessionId) {
231
- return;
232
- }
233
- const ok = await run(async () => {
234
- await client.deleteGoal(workspaceId, sessionId);
235
- return true;
236
- });
237
- if (ok) {
238
- retireLoads();
239
- setGoal(null);
240
- setError(null);
241
- }
242
- }, [client, workspaceId, sessionId, run, retireLoads]);
243
- return {
244
- goal,
245
- isActive: goal?.status === "active",
246
- isPaused: goal?.status === "paused",
247
- isCompleted: goal?.status === "completed",
248
- loading,
249
- error,
250
- refresh: load,
251
- pause,
252
- resume,
253
- clearGoal,
254
- deleteGoal: clearGoal,
255
- updating: mutating,
256
- mutationError,
257
- clearMutationError
258
- };
259
- }
260
-
261
79
  // src/hooks/use-session-mcp-approval-policy.ts
262
- import { useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo, useRef as useRef2, useState as useState2 } from "react";
80
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
263
81
  function isSessionMcpApprovalPolicyEvent(event, serverId) {
264
82
  if (event.type !== "session.mcp.approval_policy.updated") {
265
83
  return false;
@@ -273,16 +91,16 @@ function isSessionMcpApprovalPolicyEvent(event, serverId) {
273
91
  function useSessionMcpApprovalPolicy(sessionId, serverId, options = {}) {
274
92
  const { client, workspaceId } = useEmbeddedSessionMcpApprovalPolicy(options);
275
93
  const enabled = (options.enabled ?? true) && Boolean(sessionId && serverId);
276
- const [override, setOverride] = useState2(null);
94
+ const [override, setOverride] = useState(null);
277
95
  const targetKey = `${workspaceId}\0${sessionId ?? ""}\0${serverId ?? ""}`;
278
- const authoritativeGeneration = useRef2(0);
96
+ const authoritativeGeneration = useRef(0);
279
97
  const mutationIdentity = useMemo(() => ({ client, targetKey }), [client, targetKey]);
280
98
  const { run, mutating, mutationError, clearMutationError } = useMutationRunner(mutationIdentity);
281
99
  useLayoutEffect(() => {
282
100
  authoritativeGeneration.current += 1;
283
101
  setOverride(null);
284
102
  }, [client, targetKey]);
285
- const load = useCallback2(async () => {
103
+ const load = useCallback(async () => {
286
104
  const generation = authoritativeGeneration.current;
287
105
  if (!sessionId || !serverId) {
288
106
  return { targetKey, generation, server: null };
@@ -307,13 +125,13 @@ function useSessionMcpApprovalPolicy(sessionId, serverId, options = {}) {
307
125
  enabled,
308
126
  pollIntervalMs: options.pollIntervalMs
309
127
  });
310
- useEffect2(() => {
128
+ useEffect(() => {
311
129
  if (data?.targetKey === targetKey && data.generation === authoritativeGeneration.current) {
312
130
  setOverride(null);
313
131
  }
314
132
  }, [data, targetKey]);
315
133
  const scheduleRefresh = useDebouncedCallback(() => void refresh());
316
- const matchesPolicyEvent = useCallback2(
134
+ const matchesPolicyEvent = useCallback(
317
135
  (event) => isSessionMcpApprovalPolicyEvent(event, serverId ?? void 0),
318
136
  [serverId]
319
137
  );
@@ -329,7 +147,7 @@ function useSessionMcpApprovalPolicy(sessionId, serverId, options = {}) {
329
147
  },
330
148
  async () => await refresh()
331
149
  );
332
- const update = useCallback2(
150
+ const update = useCallback(
333
151
  async (policy) => {
334
152
  if (!sessionId || !serverId) {
335
153
  return null;
@@ -364,7 +182,7 @@ function useSessionMcpApprovalPolicy(sessionId, serverId, options = {}) {
364
182
  }
365
183
 
366
184
  // src/hooks/use-session-lineage.ts
367
- import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef3 } from "react";
185
+ import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2 } from "react";
368
186
  function isLineageRefreshEvent(event) {
369
187
  if (event.type === "session.status.changed" || event.type === "session.created") {
370
188
  return true;
@@ -387,9 +205,9 @@ function isSessionCreateToolCallCreated(event) {
387
205
  function useSessionLineage(sessionId, options = {}) {
388
206
  const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } = useEmbeddedSessionLineage(options);
389
207
  const enabled = (options.enabled ?? true) && Boolean(sessionId);
390
- const nextReadGeneration = useRef3(0);
208
+ const nextReadGeneration = useRef2(0);
391
209
  const beginRead = options.beginRead;
392
- const load = useCallback3(
210
+ const load = useCallback2(
393
211
  async (signal) => {
394
212
  if (!sessionId) {
395
213
  return {
@@ -413,16 +231,16 @@ function useSessionLineage(sessionId, options = {}) {
413
231
  );
414
232
  const state = usePolledValue(load, { pollIntervalMs: options.pollIntervalMs, enabled });
415
233
  const refresh = state.refresh;
416
- useEffect3(() => {
234
+ useEffect2(() => {
417
235
  if (enabled && workspaceControlEvent) void refresh();
418
236
  }, [enabled, refresh, workspaceControlEvent]);
419
- useEffect3(() => {
237
+ useEffect2(() => {
420
238
  if (!sessionId || !enabled) return;
421
239
  return registerSessionReconciler(sessionId, "lineage", refresh);
422
240
  }, [enabled, refresh, registerSessionReconciler, sessionId]);
423
241
  const refreshSoon = useDebouncedCallback(() => void refresh(), 150);
424
- const delayedChildRefreshRef = useRef3(null);
425
- useEffect3(() => {
242
+ const delayedChildRefreshRef = useRef2(null);
243
+ useEffect2(() => {
426
244
  return () => {
427
245
  if (delayedChildRefreshRef.current !== null) {
428
246
  clearTimeout(delayedChildRefreshRef.current);
@@ -430,7 +248,7 @@ function useSessionLineage(sessionId, options = {}) {
430
248
  }
431
249
  };
432
250
  }, [sessionId, workspaceId]);
433
- const refreshAfterChildCreate = useCallback3(() => {
251
+ const refreshAfterChildCreate = useCallback2(() => {
434
252
  void refresh();
435
253
  if (delayedChildRefreshRef.current !== null) {
436
254
  clearTimeout(delayedChildRefreshRef.current);
@@ -471,11 +289,9 @@ function useSessionLineage(sessionId, options = {}) {
471
289
 
472
290
  export {
473
291
  createEmbeddedSessionClient,
474
- isGoalEvent,
475
- useGoal,
476
292
  isSessionMcpApprovalPolicyEvent,
477
293
  useSessionMcpApprovalPolicy,
478
294
  isLineageRefreshEvent,
479
295
  useSessionLineage
480
296
  };
481
- //# sourceMappingURL=chunk-742CZ3L3.js.map
297
+ //# sourceMappingURL=chunk-H5X55XH7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/embedded-session-client.ts","../src/hooks/use-session-mcp-approval-policy.ts","../src/hooks/use-session-lineage.ts"],"sourcesContent":["import type { ComposerDraft } from \"@opengeni/sdk\";\nimport type { EmbeddedSessionClientLike } from \"./client\";\n\nexport type ComposerDraftMapContext = {\n operation: \"read\" | \"save\" | \"submit\";\n workspaceId: string;\n sessionId: string;\n};\n\nexport type CreateEmbeddedSessionClientOptions = {\n /**\n * Explicit host-owned method replacements. Methods inherited from `base`\n * retain `base` as their receiver; overrides retain this object as theirs.\n */\n overrides?: Partial<EmbeddedSessionClientLike> | undefined;\n /** Presentation/policy projection for every draft entering the React layer. */\n mapComposerDraft?:\n | ((draft: ComposerDraft, context: ComposerDraftMapContext) => ComposerDraft)\n | undefined;\n};\n\nconst requiredMethods = [\n \"getSession\",\n \"listEvents\",\n \"streamEvents\",\n \"getComposerDraft\",\n \"saveComposerDraft\",\n \"submitComposerDraft\",\n \"sendMessage\",\n \"steerMessage\",\n \"getQueue\",\n \"moveQueueItem\",\n \"editQueueItem\",\n \"steerQueueItem\",\n \"deleteQueueItem\",\n \"pauseSession\",\n \"resumeSession\",\n \"sendApprovalDecision\",\n] as const satisfies readonly (keyof EmbeddedSessionClientLike)[];\n\n/**\n * Build the exact client required by `@opengeni/react/session` from a full SDK\n * client or host proxy. The constructor binds every delegated method once,\n * supports a host-owned atomic composer-submit override, and fails at creation\n * time instead of waiting for a missing method to be exercised by a hook.\n */\nexport function createEmbeddedSessionClient(\n base: EmbeddedSessionClientLike,\n options: CreateEmbeddedSessionClientOptions = {},\n): EmbeddedSessionClientLike {\n const overrides = options.overrides ?? {};\n const client = {} as EmbeddedSessionClientLike;\n for (const key of requiredMethods) {\n const override = overrides[key];\n const method = override ?? base[key];\n if (typeof method !== \"function\") {\n throw new TypeError(`Embedded session client method is required: ${key}`);\n }\n client[key] = method.bind(override === undefined ? base : overrides) as never;\n }\n\n const inferenceOverride = overrides.setWorkspaceInferenceState;\n const inferenceBase = base.setWorkspaceInferenceState;\n const inferenceMethod = inferenceOverride ?? inferenceBase;\n if (typeof inferenceMethod === \"function\") {\n client.setWorkspaceInferenceState = inferenceMethod.bind(\n inferenceOverride === undefined ? base : overrides,\n );\n }\n\n const mapDraft = options.mapComposerDraft;\n if (!mapDraft) return client;\n\n const getComposerDraft = client.getComposerDraft;\n client.getComposerDraft = async (workspaceId, sessionId) =>\n mapDraft(await getComposerDraft(workspaceId, sessionId), {\n operation: \"read\",\n workspaceId,\n sessionId,\n });\n\n const saveComposerDraft = client.saveComposerDraft;\n client.saveComposerDraft = async (workspaceId, sessionId, request) =>\n mapDraft(await saveComposerDraft(workspaceId, sessionId, request), {\n operation: \"save\",\n workspaceId,\n sessionId,\n });\n\n const submitComposerDraft = client.submitComposerDraft;\n client.submitComposerDraft = async (workspaceId, sessionId, request) => {\n const response = await submitComposerDraft(workspaceId, sessionId, request);\n return {\n ...response,\n draft: mapDraft(response.draft, {\n operation: \"submit\",\n workspaceId,\n sessionId,\n }),\n };\n };\n\n return client;\n}\n","import type {\n SessionEvent,\n SessionMcpApprovalPolicy,\n SessionMcpApprovalPolicyTarget,\n UpdateSessionMcpApprovalPolicyResponse,\n} from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport {\n useEmbeddedSessionMcpApprovalPolicy,\n type EmbeddedSessionMcpApprovalPolicyClientOverride,\n} from \"../session-context\";\nimport {\n useDebouncedCallback,\n useMutationRunner,\n usePolledValue,\n useSessionEventTrigger,\n type SessionEventFeedOptions,\n} from \"./internal\";\n\nexport function isSessionMcpApprovalPolicyEvent(\n event: Pick<SessionEvent, \"type\" | \"payload\">,\n serverId?: string,\n): boolean {\n if (event.type !== \"session.mcp.approval_policy.updated\") {\n return false;\n }\n if (serverId === undefined) {\n return true;\n }\n const payload = event.payload as { serverId?: unknown } | null;\n return payload?.serverId === serverId;\n}\n\nexport type UseSessionMcpApprovalPolicyOptions = EmbeddedSessionMcpApprovalPolicyClientOverride &\n SessionEventFeedOptions & {\n /** Optional safety-net polling (ms). Off by default; policy events drive refreshes. */\n pollIntervalMs?: number | undefined;\n };\n\nexport type UseSessionMcpApprovalPolicyResult = {\n server: SessionMcpApprovalPolicyTarget | null;\n policy: SessionMcpApprovalPolicy | null;\n loading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n update: (\n policy: SessionMcpApprovalPolicy,\n ) => Promise<UpdateSessionMcpApprovalPolicyResponse | null>;\n updating: boolean;\n clearError: () => void;\n};\n\n/**\n * Read and update one existing session MCP server's approval policy. Updates\n * become effective for the next claimed attempt; current work is unchanged.\n */\nexport function useSessionMcpApprovalPolicy(\n sessionId: string | null | undefined,\n serverId: string | null | undefined,\n options: UseSessionMcpApprovalPolicyOptions = {},\n): UseSessionMcpApprovalPolicyResult {\n const { client, workspaceId } = useEmbeddedSessionMcpApprovalPolicy(options);\n const enabled = (options.enabled ?? true) && Boolean(sessionId && serverId);\n const [override, setOverride] = useState<SessionMcpApprovalPolicyTarget | null>(null);\n const targetKey = `${workspaceId}\\u0000${sessionId ?? \"\"}\\u0000${serverId ?? \"\"}`;\n const authoritativeGeneration = useRef(0);\n const mutationIdentity = useMemo(() => ({ client, targetKey }), [client, targetKey]);\n const { run, mutating, mutationError, clearMutationError } = useMutationRunner(mutationIdentity);\n\n useLayoutEffect(() => {\n authoritativeGeneration.current += 1;\n setOverride(null);\n }, [client, targetKey]);\n\n type PolicyRead = {\n targetKey: string;\n generation: number;\n server: SessionMcpApprovalPolicyTarget | null;\n };\n const load = useCallback(async (): Promise<PolicyRead> => {\n const generation = authoritativeGeneration.current;\n if (!sessionId || !serverId) {\n return { targetKey, generation, server: null };\n }\n const session = await client.getSession(workspaceId, sessionId);\n return {\n targetKey,\n generation,\n server:\n session.mcpServers.find((server) => server.id === serverId) ??\n (session.mcpApprovalPolicies && Object.hasOwn(session.mcpApprovalPolicies, serverId)\n ? {\n id: serverId,\n source: \"workspace\",\n requireApproval: session.mcpApprovalPolicies[serverId]!,\n }\n : null),\n };\n }, [client, serverId, sessionId, targetKey, workspaceId]);\n const {\n data,\n loading,\n error: loadError,\n refresh,\n } = usePolledValue(load, {\n enabled,\n pollIntervalMs: options.pollIntervalMs,\n });\n useEffect(() => {\n if (data?.targetKey === targetKey && data.generation === authoritativeGeneration.current) {\n setOverride(null);\n }\n }, [data, targetKey]);\n\n const scheduleRefresh = useDebouncedCallback(() => void refresh());\n const matchesPolicyEvent = useCallback(\n (event: Pick<SessionEvent, \"type\" | \"payload\">) =>\n isSessionMcpApprovalPolicyEvent(event, serverId ?? undefined),\n [serverId],\n );\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n matchesPolicyEvent,\n scheduleRefresh,\n {\n enabled,\n ...(options.events !== undefined ? { events: options.events } : {}),\n },\n async () => await refresh(),\n );\n\n const update = useCallback(\n async (\n policy: SessionMcpApprovalPolicy,\n ): Promise<UpdateSessionMcpApprovalPolicyResponse | null> => {\n if (!sessionId || !serverId) {\n return null;\n }\n const response = await run(() =>\n client.updateSessionMcpApprovalPolicy(workspaceId, sessionId, serverId, {\n requireApproval: policy,\n }),\n );\n if (response) {\n authoritativeGeneration.current += 1;\n setOverride(response.server);\n void refresh();\n }\n return response;\n },\n [client, refresh, run, serverId, sessionId, workspaceId],\n );\n\n const server = override ?? data?.server ?? null;\n return {\n server,\n policy: server?.requireApproval ?? null,\n loading,\n error: mutationError ?? loadError,\n refresh: async () => {\n await refresh();\n },\n update,\n updating: mutating,\n clearError: clearMutationError,\n };\n}\n","import type { SessionEvent, SessionLineageResponse } from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport {\n useEmbeddedSessionLineage,\n type EmbeddedSessionLineageClientOverride,\n} from \"../session-context\";\nimport { useDebouncedCallback, usePolledValue, useSessionEventTrigger } from \"./internal\";\n\nexport type UseSessionLineageOptions = EmbeddedSessionLineageClientOverride & {\n events?: SessionEvent[] | undefined;\n /** Refresh interval (ms). Off by default. */\n pollIntervalMs?: number | undefined;\n enabled?: boolean | undefined;\n /** Optional shared causal clock invoked when each network read starts. */\n beginRead?: (() => number) | undefined;\n};\n\nexport type UseSessionLineageResult = {\n lineage: SessionLineageResponse | null;\n loading: boolean;\n error: Error | null;\n /** Causal generation captured when the accepted lineage read started. */\n readGeneration: number;\n refresh: () => Promise<void>;\n};\n\nexport function isLineageRefreshEvent(event: SessionEvent): boolean {\n if (event.type === \"session.status.changed\" || event.type === \"session.created\") {\n return true;\n }\n // A child's creation never appears on the PARENT's stream as session.created —\n // the parent sees its own spawn as an agent.toolCall.* for session_create.\n // Created events are handled separately so they can refresh immediately and\n // once after the child row has had time to commit.\n if (event.type === \"agent.toolCall.output\") {\n const payload = event.payload as { name?: unknown; toolName?: unknown } | null | undefined;\n const name =\n typeof payload?.name === \"string\"\n ? payload.name\n : typeof payload?.toolName === \"string\"\n ? payload.toolName\n : \"\";\n return name === \"session_create\" || name.endsWith(\"__session_create\");\n }\n return false;\n}\n\nfunction isSessionCreateToolCallCreated(event: SessionEvent): boolean {\n if (event.type !== \"agent.toolCall.created\") {\n return false;\n }\n const payload = event.payload as { name?: unknown; toolName?: unknown } | null | undefined;\n const name =\n typeof payload?.name === \"string\"\n ? payload.name\n : typeof payload?.toolName === \"string\"\n ? payload.toolName\n : \"\";\n return name === \"session_create\" || name.endsWith(\"__session_create\");\n}\n\n/** Read the ancestors + descendant tree for one session. Data-only; no UI state. */\nexport function useSessionLineage(\n sessionId: string | null | undefined,\n options: UseSessionLineageOptions = {},\n): UseSessionLineageResult {\n const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } =\n useEmbeddedSessionLineage(options);\n const enabled = (options.enabled ?? true) && Boolean(sessionId);\n const nextReadGeneration = useRef(0);\n const beginRead = options.beginRead;\n const load = useCallback(\n async (signal?: AbortSignal) => {\n if (!sessionId) {\n return {\n lineage: { ancestors: [], children: [], truncated: false },\n readGeneration: 0,\n };\n }\n let readGeneration = 0;\n const lineage = await client.getSessionLineage(workspaceId, sessionId, {\n signal,\n onRequestStart: (sharedReadGeneration) => {\n readGeneration = sharedReadGeneration ?? beginRead?.() ?? ++nextReadGeneration.current;\n },\n });\n return {\n lineage,\n readGeneration,\n };\n },\n [beginRead, client, workspaceId, sessionId],\n );\n const state = usePolledValue(load, { pollIntervalMs: options.pollIntervalMs, enabled });\n const refresh = state.refresh;\n useEffect(() => {\n if (enabled && workspaceControlEvent) void refresh();\n }, [enabled, refresh, workspaceControlEvent]);\n useEffect(() => {\n if (!sessionId || !enabled) return;\n return registerSessionReconciler(sessionId, \"lineage\", refresh);\n }, [enabled, refresh, registerSessionReconciler, sessionId]);\n const refreshSoon = useDebouncedCallback(() => void refresh(), 150);\n const delayedChildRefreshRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n // Clear a pending delayed refresh on session/workspace SWITCH (not just\n // unmount): otherwise a timer scheduled for the previous session can fire\n // ~2.5s later and commit that session's lineage onto the new one.\n useEffect(() => {\n return () => {\n if (delayedChildRefreshRef.current !== null) {\n clearTimeout(delayedChildRefreshRef.current);\n delayedChildRefreshRef.current = null;\n }\n };\n }, [sessionId, workspaceId]);\n const refreshAfterChildCreate = useCallback(() => {\n void refresh();\n if (delayedChildRefreshRef.current !== null) {\n clearTimeout(delayedChildRefreshRef.current);\n }\n delayedChildRefreshRef.current = setTimeout(() => {\n delayedChildRefreshRef.current = null;\n void refresh();\n }, 2500);\n }, [refresh]);\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n isLineageRefreshEvent,\n refreshSoon,\n // SHARED-FEED ONLY: without a caller-provided events log the trigger would\n // open its OWN streamEvents tail — a second live SSE connection next to the\n // session route's useSessionEvents. A caller with no feed opts into polling\n // (pollIntervalMs), never a duplicate stream.\n { events: options.events, enabled: enabled && options.events !== undefined },\n );\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n isSessionCreateToolCallCreated,\n refreshAfterChildCreate,\n { events: options.events, enabled: enabled && options.events !== undefined },\n );\n return {\n lineage: state.data?.lineage ?? null,\n loading: state.loading,\n error: state.error,\n readGeneration: state.data?.readGeneration ?? 0,\n refresh,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAqBA,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAQO,SAAS,4BACd,MACA,UAA8C,CAAC,GACpB;AAC3B,QAAM,YAAY,QAAQ,aAAa,CAAC;AACxC,QAAM,SAAS,CAAC;AAChB,aAAW,OAAO,iBAAiB;AACjC,UAAM,WAAW,UAAU,GAAG;AAC9B,UAAM,SAAS,YAAY,KAAK,GAAG;AACnC,QAAI,OAAO,WAAW,YAAY;AAChC,YAAM,IAAI,UAAU,+CAA+C,GAAG,EAAE;AAAA,IAC1E;AACA,WAAO,GAAG,IAAI,OAAO,KAAK,aAAa,SAAY,OAAO,SAAS;AAAA,EACrE;AAEA,QAAM,oBAAoB,UAAU;AACpC,QAAM,gBAAgB,KAAK;AAC3B,QAAM,kBAAkB,qBAAqB;AAC7C,MAAI,OAAO,oBAAoB,YAAY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