@redocly/replay 0.27.0-next.4 → 0.27.0-next.6

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 (63) hide show
  1. package/dist/replay-AiChatProvider-D7E0a83D.js +1006 -0
  2. package/dist/replay-AiChatProvider-p9SioFWy.js +6 -0
  3. package/dist/replay-AiChatSqliteDBStorage-CKQJ5VZi.js +88 -0
  4. package/dist/replay-AiChatSqliteDBStorage-DgGB1XKW.js +1 -0
  5. package/dist/replay-AiPanel-BLkqnlmb.js +849 -0
  6. package/dist/replay-AiPanel-DvOGYsWl.js +2918 -0
  7. package/dist/replay-HistorySqliteDBStorage-BrILW8Fu.js +1 -0
  8. package/dist/replay-HistorySqliteDBStorage-CtF6-vY8.js +113 -0
  9. package/dist/replay-SqliteDBStorage-CNJbZXTw.js +14 -0
  10. package/dist/replay-SqliteDBStorage-D_31Bd3Z.js +2857 -0
  11. package/dist/replay-StepContextSqliteDBStorage-BSepLyBI.js +1 -0
  12. package/dist/replay-StepContextSqliteDBStorage-BfAAKDwA.js +83 -0
  13. package/dist/replay-agent-loop-DklepPbJ.js +1533 -0
  14. package/dist/replay-agent-loop-fKCHgyOD.js +1 -0
  15. package/dist/replay-ai-chat-mappers-D-vUBq2s.js +1 -0
  16. package/dist/replay-ai-chat-mappers-IWtvE0Nl.js +99 -0
  17. package/dist/replay-ai-message-parts.schema-BBdjwldJ.js +1 -0
  18. package/dist/replay-ai-message-parts.schema-E9u9-nqr.js +60 -0
  19. package/dist/replay-create-model-CfrWgdF7.js +38224 -0
  20. package/dist/replay-create-model-xGRAIhcu.js +104 -0
  21. package/dist/replay-db-BtdwaWh3.js +306 -0
  22. package/dist/replay-db-XlueEDU-.js +64 -0
  23. package/dist/replay-defaults-CzR6jw9a.js +32 -0
  24. package/dist/replay-defaults-DVvOnvnR.js +27 -0
  25. package/dist/replay-external-resolver-D6VSVDwt.js +34 -0
  26. package/dist/replay-external-resolver-Skh0OGde.js +2 -0
  27. package/dist/replay-history.schema-5ce6X0R1.js +28 -0
  28. package/dist/replay-history.schema-miM3Etuf.js +1 -0
  29. package/dist/replay-index-BEzVYZeb.js +504 -0
  30. package/dist/{replay-index-DCclzbQl.js → replay-index-BOB__Jm6.js} +1 -1
  31. package/dist/replay-index-C6SJPGDO.js +23 -0
  32. package/dist/{replay-index-D6LeDb4M.js → replay-index-CCvitTKt.js} +6 -6
  33. package/dist/replay-index-CUs62_1f.js +1 -0
  34. package/dist/replay-index-DXnDNeqk.js +93088 -0
  35. package/dist/replay-index-S_wAPmTA.js +6877 -0
  36. package/dist/replay-index-fVC8e5y9.js +1 -0
  37. package/dist/replay-indexes-CfsvVMi_.js +1242 -0
  38. package/dist/replay-indexes-Dqjl8m6C.js +1 -0
  39. package/dist/replay-lint-BCVeL_wb.js +184 -0
  40. package/dist/replay-lint-DjMIgYfF.js +33416 -0
  41. package/dist/{replay-lint-graphql-Cdmm_aJs.js → replay-lint-graphql-Bltv-T6_.js} +2 -2
  42. package/dist/{replay-lint-graphql-8tMA-ttz.js → replay-lint-graphql-bkrdHRy7.js} +5 -5
  43. package/dist/replay-resolve-BhcSceq-.js +3694 -0
  44. package/dist/replay-resolve-CQL6WBG1.js +47 -0
  45. package/dist/{replay-respect-run-DrWWHTWp.js → replay-respect-run-CecN1j9r.js} +1608 -1558
  46. package/dist/replay-respect-run-rJm4W93K.js +78 -0
  47. package/dist/replay-step-context.schema-BuuXkAck.js +1 -0
  48. package/dist/replay-step-context.schema-DBk4jufr.js +21 -0
  49. package/dist/{replay-tauri-path-BIIo3xjJ.js → replay-tauri-path--8KtMkGg.js} +1 -1
  50. package/dist/{replay-tauri-path-BQmCYwRI.js → replay-tauri-path--BfusnkB.js} +4 -4
  51. package/dist/replay-useAiChatQueries-B1-NwsZz.js +213 -0
  52. package/dist/replay-useAiChatQueries-Btd-PmIH.js +3532 -0
  53. package/dist/replay-validate-key-Bk0SFd3-.js +1 -0
  54. package/dist/replay-validate-key-CYsfegSv.js +28 -0
  55. package/dist/replay.cjs +1 -1
  56. package/dist/replay.d.ts +37 -5
  57. package/dist/replay.js +18 -18
  58. package/package.json +4 -4
  59. package/dist/replay-index-BFggGnsX.js +0 -181252
  60. package/dist/replay-index-BWX4r5us.js +0 -8354
  61. package/dist/replay-index-DuAFN7X8.js +0 -21
  62. package/dist/replay-index-tDvNtfHp.js +0 -1
  63. package/dist/replay-respect-run-DGe96SG3.js +0 -78
@@ -0,0 +1,1006 @@
1
+ import { jsx as te } from "react/jsx-runtime";
2
+ import { useRef as R, useCallback as f, useSyncExternalStore as re, useEffect as b, useMemo as w, useState as z } from "react";
3
+ import { a as S, A as ce, g as Re, I as xe, T as $e, b as x, c as Pe, d as De, u as Te, e as We, f as Be, h as Oe, i as Ue, j as Ae, k as se, l as ue, m as ye, n as Fe, o as Le, p as Se, t as ge, q as je, R as ne, r as Ne, s as ae, v as qe, w as Ke } from "./replay-index-DXnDNeqk.js";
4
+ import { A as Qe, D as Ve, l as Ge } from "./replay-create-model-CfrWgdF7.js";
5
+ import { AgentLoop as He } from "./replay-agent-loop-DklepPbJ.js";
6
+ import { s as ze } from "./replay-db-BtdwaWh3.js";
7
+ import { r as Ye, g as Je, a as Xe, o as Ze, s as et, w as tt, m as nt, b as st, u as rt, c as ot, d as at, e as it, f as lt, h as ct, i as ut, A as dt, j as ht, k as pt } from "./replay-useAiChatQueries-Btd-PmIH.js";
8
+ import { useQueryClient as de, useMutation as he } from "@tanstack/react-query";
9
+ import { b as be, g as me } from "./replay-ai-chat-mappers-IWtvE0Nl.js";
10
+ class ft {
11
+ handlers = /* @__PURE__ */ new Map();
12
+ middlewares;
13
+ constructor(t) {
14
+ this.middlewares = t?.middlewares ?? [];
15
+ }
16
+ register(t) {
17
+ this.handlers.set(t.name, t);
18
+ }
19
+ getToolSet() {
20
+ const t = {};
21
+ for (const [n, s] of this.handlers)
22
+ t[n] = this.buildTool(s);
23
+ return t;
24
+ }
25
+ buildTool(t) {
26
+ return {
27
+ ...t.definition,
28
+ execute: this.wrapExecutor(t)
29
+ };
30
+ }
31
+ wrapExecutor(t) {
32
+ const n = (o, r) => ({
33
+ isError: !0,
34
+ error: { message: o, details: r }
35
+ }), s = this.applyMiddlewares(t.name, t.execute);
36
+ return (o, r) => {
37
+ if (r.abortSignal?.aborted)
38
+ return n("Tool execution was aborted.");
39
+ try {
40
+ const a = s(o, r);
41
+ return typeof a == "object" && a !== null && "then" in a ? a.then(
42
+ (i) => i,
43
+ (i) => n(
44
+ i instanceof Error ? i.message : "Unknown tool execution error"
45
+ )
46
+ ) : a;
47
+ } catch (a) {
48
+ return n(
49
+ a instanceof Error ? a.message : "Unknown tool execution error"
50
+ );
51
+ }
52
+ };
53
+ }
54
+ applyMiddlewares(t, n) {
55
+ return this.middlewares.length === 0 ? n : this.middlewares.reduceRight((s, o) => o(t, s), n);
56
+ }
57
+ }
58
+ function ke() {
59
+ const e = de();
60
+ return he({
61
+ async mutationFn(t) {
62
+ const n = be(t);
63
+ await ce.getInstance().upsert(n);
64
+ },
65
+ onSuccess() {
66
+ e.invalidateQueries({ queryKey: S.all() });
67
+ },
68
+ onError(t) {
69
+ console.error("Failed to upsert ai chat item:", t);
70
+ }
71
+ });
72
+ }
73
+ function gt(e) {
74
+ const t = de(), n = S.detailTitle(e ?? "");
75
+ return he({
76
+ mutationKey: n,
77
+ async mutationFn(s) {
78
+ if (t.isMutating({ mutationKey: n, exact: !0 }) > 1) return;
79
+ const o = be(s);
80
+ await ce.getInstance().upsert(o);
81
+ },
82
+ onSuccess() {
83
+ t.invalidateQueries({ queryKey: S.all() });
84
+ },
85
+ onError(s) {
86
+ console.error("Failed to upsert ai chat item:", s);
87
+ }
88
+ });
89
+ }
90
+ function mt() {
91
+ const e = de();
92
+ return he({
93
+ async mutationFn(t) {
94
+ await ce.getInstance().remove(t);
95
+ },
96
+ onMutate: async (t) => {
97
+ await e.cancelQueries({ queryKey: S.all() });
98
+ const n = e.getQueryData(S.all());
99
+ n && e.setQueryData(
100
+ S.all(),
101
+ n.filter((s) => s.id !== t)
102
+ ), e.setQueryData(S.detail(t), null), e.setQueriesData(
103
+ { queryKey: S.infiniteHistories() },
104
+ (s) => s && {
105
+ ...s,
106
+ pages: s.pages.map((o) => ({
107
+ ...o,
108
+ items: o.items.filter((r) => r.id !== t)
109
+ }))
110
+ }
111
+ );
112
+ },
113
+ onError(t) {
114
+ console.error("Failed to remove ai chat:", t);
115
+ },
116
+ onSettled() {
117
+ e.invalidateQueries({ queryKey: S.all() });
118
+ }
119
+ });
120
+ }
121
+ var oe, ve;
122
+ function vt() {
123
+ if (ve) return oe;
124
+ ve = 1;
125
+ function e(t, n) {
126
+ if (typeof t != "function")
127
+ throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof t}\`.`);
128
+ let s, o = 0;
129
+ return function(...a) {
130
+ clearTimeout(s);
131
+ const i = Date.now(), l = i - o, u = n - l;
132
+ u <= 0 ? (o = i, t.apply(this, a)) : s = setTimeout(() => {
133
+ o = Date.now(), t.apply(this, a);
134
+ }, u);
135
+ };
136
+ }
137
+ return oe = e, oe;
138
+ }
139
+ var wt = /* @__PURE__ */ vt();
140
+ const Ct = /* @__PURE__ */ Re(wt);
141
+ var Me = (e, t, n) => {
142
+ if (!t.has(e))
143
+ throw TypeError("Cannot " + n);
144
+ }, d = (e, t, n) => (Me(e, t, "read from private field"), n ? n.call(e) : t.get(e)), A = (e, t, n) => {
145
+ if (t.has(e))
146
+ throw TypeError("Cannot add the same private member more than once");
147
+ t instanceof WeakSet ? t.add(e) : t.set(e, n);
148
+ }, _ = (e, t, n, s) => (Me(e, t, "write to private field"), t.set(e, n), n);
149
+ function It(e, t) {
150
+ return t != null ? Ct(e, t) : e;
151
+ }
152
+ var v, Z, ee, V, G, H, j, ie, le, Tt = class {
153
+ constructor(e = []) {
154
+ A(this, v, void 0), A(this, Z, "ready"), A(this, ee, void 0), A(this, V, /* @__PURE__ */ new Set()), A(this, G, /* @__PURE__ */ new Set()), A(this, H, /* @__PURE__ */ new Set()), this.pushMessage = (t) => {
155
+ _(this, v, d(this, v).concat(t)), d(this, j).call(this);
156
+ }, this.popMessage = () => {
157
+ _(this, v, d(this, v).slice(0, -1)), d(this, j).call(this);
158
+ }, this.replaceMessage = (t, n) => {
159
+ _(this, v, [
160
+ ...d(this, v).slice(0, t),
161
+ // We deep clone the message here to ensure the new React Compiler (currently in RC) detects deeply nested parts/metadata changes:
162
+ this.snapshot(n),
163
+ ...d(this, v).slice(t + 1)
164
+ ]), d(this, j).call(this);
165
+ }, this.snapshot = (t) => structuredClone(t), this["~registerMessagesCallback"] = (t, n) => {
166
+ const s = n ? It(t, n) : t;
167
+ return d(this, V).add(s), () => {
168
+ d(this, V).delete(s);
169
+ };
170
+ }, this["~registerStatusCallback"] = (t) => (d(this, G).add(t), () => {
171
+ d(this, G).delete(t);
172
+ }), this["~registerErrorCallback"] = (t) => (d(this, H).add(t), () => {
173
+ d(this, H).delete(t);
174
+ }), A(this, j, () => {
175
+ d(this, V).forEach((t) => t());
176
+ }), A(this, ie, () => {
177
+ d(this, G).forEach((t) => t());
178
+ }), A(this, le, () => {
179
+ d(this, H).forEach((t) => t());
180
+ }), _(this, v, e);
181
+ }
182
+ get status() {
183
+ return d(this, Z);
184
+ }
185
+ set status(e) {
186
+ _(this, Z, e), d(this, ie).call(this);
187
+ }
188
+ get error() {
189
+ return d(this, ee);
190
+ }
191
+ set error(e) {
192
+ _(this, ee, e), d(this, le).call(this);
193
+ }
194
+ get messages() {
195
+ return d(this, v);
196
+ }
197
+ set messages(e) {
198
+ _(this, v, [...e]), d(this, j).call(this);
199
+ }
200
+ };
201
+ v = /* @__PURE__ */ new WeakMap();
202
+ Z = /* @__PURE__ */ new WeakMap();
203
+ ee = /* @__PURE__ */ new WeakMap();
204
+ V = /* @__PURE__ */ new WeakMap();
205
+ G = /* @__PURE__ */ new WeakMap();
206
+ H = /* @__PURE__ */ new WeakMap();
207
+ j = /* @__PURE__ */ new WeakMap();
208
+ ie = /* @__PURE__ */ new WeakMap();
209
+ le = /* @__PURE__ */ new WeakMap();
210
+ var N, we = class extends Qe {
211
+ constructor({ messages: e, ...t }) {
212
+ const n = new Tt(e);
213
+ super({ ...t, state: n }), A(this, N, void 0), this["~registerMessagesCallback"] = (s, o) => d(this, N)["~registerMessagesCallback"](s, o), this["~registerStatusCallback"] = (s) => d(this, N)["~registerStatusCallback"](s), this["~registerErrorCallback"] = (s) => d(this, N)["~registerErrorCallback"](s), _(this, N, n);
214
+ }
215
+ };
216
+ N = /* @__PURE__ */ new WeakMap();
217
+ function At({
218
+ experimental_throttle: e,
219
+ resume: t = !1,
220
+ ...n
221
+ } = {}) {
222
+ const s = R(
223
+ "chat" in n ? {} : {
224
+ onToolCall: n.onToolCall,
225
+ onData: n.onData,
226
+ onFinish: n.onFinish,
227
+ onError: n.onError,
228
+ sendAutomaticallyWhen: n.sendAutomaticallyWhen
229
+ }
230
+ );
231
+ "chat" in n || (s.current = {
232
+ onToolCall: n.onToolCall,
233
+ onData: n.onData,
234
+ onFinish: n.onFinish,
235
+ onError: n.onError,
236
+ sendAutomaticallyWhen: n.sendAutomaticallyWhen
237
+ });
238
+ const o = {
239
+ ...n,
240
+ onToolCall: (c) => {
241
+ var p, h;
242
+ return (h = (p = s.current).onToolCall) == null ? void 0 : h.call(p, c);
243
+ },
244
+ onData: (c) => {
245
+ var p, h;
246
+ return (h = (p = s.current).onData) == null ? void 0 : h.call(p, c);
247
+ },
248
+ onFinish: (c) => {
249
+ var p, h;
250
+ return (h = (p = s.current).onFinish) == null ? void 0 : h.call(p, c);
251
+ },
252
+ onError: (c) => {
253
+ var p, h;
254
+ return (h = (p = s.current).onError) == null ? void 0 : h.call(p, c);
255
+ },
256
+ sendAutomaticallyWhen: (c) => {
257
+ var p, h, $;
258
+ return ($ = (h = (p = s.current).sendAutomaticallyWhen) == null ? void 0 : h.call(p, c)) != null ? $ : !1;
259
+ }
260
+ }, r = R(
261
+ "chat" in n ? n.chat : new we(o)
262
+ );
263
+ ("chat" in n && n.chat !== r.current || "id" in n && n.id != null && r.current.id !== n.id) && (r.current = "chat" in n ? n.chat : new we(o));
264
+ const i = f(
265
+ (c) => r.current["~registerMessagesCallback"](c, e),
266
+ // `chatRef.current.id` is required to trigger re-subscription when the chat ID changes
267
+ // eslint-disable-next-line react-hooks/exhaustive-deps
268
+ [e, r.current.id]
269
+ ), l = re(
270
+ i,
271
+ () => r.current.messages,
272
+ () => r.current.messages
273
+ ), u = re(
274
+ r.current["~registerStatusCallback"],
275
+ () => r.current.status,
276
+ () => r.current.status
277
+ ), C = re(
278
+ r.current["~registerErrorCallback"],
279
+ () => r.current.error,
280
+ () => r.current.error
281
+ ), I = f(
282
+ (c) => {
283
+ typeof c == "function" && (c = c(r.current.messages)), r.current.messages = c;
284
+ },
285
+ [r]
286
+ );
287
+ return b(() => {
288
+ t && r.current.resumeStream();
289
+ }, [t, r]), {
290
+ id: r.current.id,
291
+ messages: l,
292
+ setMessages: I,
293
+ sendMessage: r.current.sendMessage,
294
+ regenerate: r.current.regenerate,
295
+ clearError: r.current.clearError,
296
+ stop: r.current.stop,
297
+ error: C,
298
+ resumeStream: r.current.resumeStream,
299
+ status: u,
300
+ /**
301
+ * @deprecated Use `addToolOutput` instead.
302
+ */
303
+ addToolResult: r.current.addToolOutput,
304
+ addToolOutput: r.current.addToolOutput,
305
+ addToolApprovalResponse: r.current.addToolApprovalResponse
306
+ };
307
+ }
308
+ const yt = 20;
309
+ function St(e) {
310
+ if (e.length === 0)
311
+ return "No OpenAPI specs loaded.";
312
+ const t = e.slice(0, yt), n = t.map(bt), s = e.length - t.length;
313
+ return s > 0 && n.push(` …and ${s} more API(s) not shown.`), [`Loaded APIs (${e.length}):`, ...n].join(`
314
+ `);
315
+ }
316
+ function bt(e) {
317
+ return [
318
+ ` apiId="${e.apiId}"`,
319
+ `title="${e.title}"`,
320
+ e.version ? `version="${e.version}"` : null,
321
+ e.primaryServer ? `server="${e.primaryServer}"` : null
322
+ ].filter(Boolean).join(" ");
323
+ }
324
+ const kt = 30;
325
+ function Mt(e) {
326
+ if (e.length === 0)
327
+ return "No Arazzo collections loaded.";
328
+ const t = [`Arazzo collections (${e.length}):`];
329
+ let n = kt, s = 0, o = 0;
330
+ for (const a of e) {
331
+ if (n <= 0) {
332
+ s += a.workflows.length, o++;
333
+ continue;
334
+ }
335
+ if (t.push(Et(a)), n--, a.workflows.length === 0)
336
+ t.push(" (no workflows)");
337
+ else if (n >= 2) {
338
+ t.push(` workflows (${a.workflows.length}):`), n--;
339
+ for (const i of a.workflows)
340
+ n > 0 ? (t.push(` ${_t(i)}`), n--) : s++;
341
+ } else
342
+ s += a.workflows.length;
343
+ }
344
+ const r = [
345
+ s > 0 ? `${s} more workflow(s)` : null,
346
+ o > 0 ? `${o} more collection(s)` : null
347
+ ].filter(Boolean);
348
+ return r.length > 0 && t.push(` …and ${r.join(", plus ")} not shown.`), t.join(`
349
+ `);
350
+ }
351
+ function Et(e) {
352
+ const t = e.sourceApiIds.length > 0 ? ` apis=[${e.sourceApiIds.join(", ")}]` : "";
353
+ return ` collectionId="${e.collectionId}" title="${e.title}"${t}`;
354
+ }
355
+ function _t(e) {
356
+ const t = `id="${e.workflowId}"`, n = e.summary ? `label="${e.summary}"` : null, s = `[${e.stepCount} step${e.stepCount !== 1 ? "s" : ""}]`;
357
+ return [t, n, s].filter(Boolean).join(" ");
358
+ }
359
+ const Rt = 20;
360
+ function xt(e) {
361
+ if (e.length === 0)
362
+ return "No environments configured.";
363
+ const t = e.slice(0, Rt), n = t.map($t), s = e.length - t.length;
364
+ return s > 0 && n.push(` …and ${s} more environment(s) not shown.`), [`Environments (${e.length}); * marks the active environment:`, ...n].join(
365
+ `
366
+ `
367
+ );
368
+ }
369
+ function $t(e) {
370
+ return [
371
+ `${e.isActive ? "*" : " "} name="${e.name}"`,
372
+ `inputs=${e.inputCount}`,
373
+ `servers=${e.serverCount}`
374
+ ].join(" ");
375
+ }
376
+ const Pt = 30;
377
+ function Dt(e) {
378
+ if (e.length === 0)
379
+ return "No tabs are open.";
380
+ const t = e.slice(0, Pt), n = t.map(Wt), s = e.length - t.length;
381
+ return s > 0 && n.push(` …and ${s} more tab(s) not shown.`), [
382
+ `Open tabs (${e.length}), listed by tabIndex; * marks the active (focused) tab:`,
383
+ ...n
384
+ ].join(`
385
+ `);
386
+ }
387
+ function Wt(e) {
388
+ const t = [
389
+ e.collectionId ? `collectionId="${e.collectionId}"` : null,
390
+ e.workflowId ? `workflowId="${e.workflowId}"` : null,
391
+ e.stepId ? `stepId="${e.stepId}"` : null,
392
+ e.operationId ? `operationId="${e.operationId}"` : null
393
+ ].filter(Boolean), n = [
394
+ e.isPreview ? "preview" : null,
395
+ e.isDraft ? "draft" : null,
396
+ e.isHistory ? "history" : null
397
+ ].filter(Boolean);
398
+ return [
399
+ `${e.isActive ? "*" : " "} ${e.tabIndex}.`,
400
+ `type="${e.type}"`,
401
+ `label="${e.label}"`,
402
+ ...t,
403
+ n.length > 0 ? `(${n.join(", ")})` : null
404
+ ].filter(Boolean).join(" ");
405
+ }
406
+ const Bt = "Auto-attached snapshot of the user's current Replay UI state. Generated by Replay before each step; not written by the user. It is a shallow summary — use tools to read detailed tab contents when needed.";
407
+ function Ot(e) {
408
+ const t = `
409
+ `.repeat(2), n = [
410
+ Bt,
411
+ t,
412
+ Dt(e.tabs),
413
+ t,
414
+ St(e.apis),
415
+ t,
416
+ Mt(e.collections),
417
+ t,
418
+ xt(e.environments)
419
+ ].join("");
420
+ return ze("active_state", n);
421
+ }
422
+ function Ut(e) {
423
+ return e.apis.get({ noproxy: !0 }).map(Ft);
424
+ }
425
+ function Ft(e) {
426
+ return {
427
+ apiId: e.id,
428
+ title: e.info?.title ?? "Untitled API",
429
+ version: e.info?.version,
430
+ primaryServer: e.servers?.[0]?.url
431
+ };
432
+ }
433
+ function Lt(e) {
434
+ return e.collections.get({ noproxy: !0 }).map(jt);
435
+ }
436
+ function jt(e) {
437
+ const t = (e.workflows ?? []).map((s) => ({
438
+ workflowId: s.workflowId,
439
+ summary: s.summary,
440
+ stepCount: s.steps?.length ?? 0
441
+ })), n = (e.sourceDescriptions ?? []).map((s) => s.apiId).filter(Boolean);
442
+ return {
443
+ collectionId: e.id,
444
+ title: e.info?.title ?? "Untitled Collection",
445
+ workflows: t,
446
+ sourceApiIds: n
447
+ };
448
+ }
449
+ function Nt(e) {
450
+ const t = e.environments.get({ noproxy: !0 }), n = e.activeEnvironmentId.get({ noproxy: !0 });
451
+ return t.filter((s) => s.state !== xe.Draft).map((s) => ({
452
+ name: s.name,
453
+ isActive: s.name === n,
454
+ inputCount: s.inputs.length,
455
+ serverCount: s.servers.length
456
+ }));
457
+ }
458
+ function qt(e) {
459
+ const t = e.tabsState.tabs.get({ noproxy: !0 }), n = e.tabsState.activeTabIdx.get({ noproxy: !0 });
460
+ return t.map(
461
+ (s, o) => Kt(e, s, o, o === n)
462
+ );
463
+ }
464
+ function Kt(e, t, n, s) {
465
+ const o = {
466
+ tabIndex: n,
467
+ type: t.data.type,
468
+ isActive: s,
469
+ isPreview: t.state === $e.Preview
470
+ };
471
+ switch (t.data.type) {
472
+ case x.Collection: {
473
+ const { collectionId: r } = t.data;
474
+ return {
475
+ ...o,
476
+ label: Qt(e, r) ?? r,
477
+ collectionId: r
478
+ };
479
+ }
480
+ case x.Workflow: {
481
+ const { collectionId: r, workflowId: a } = t.data;
482
+ return { ...o, label: a, collectionId: r, workflowId: a };
483
+ }
484
+ case x.WorkflowRun: {
485
+ const { collectionId: r, workflowId: a, historyId: i, label: l } = t.data;
486
+ return {
487
+ ...o,
488
+ label: l ?? `${a} run`,
489
+ collectionId: r,
490
+ workflowId: a,
491
+ isHistory: i != null
492
+ };
493
+ }
494
+ case x.Step: {
495
+ const r = t.data;
496
+ return {
497
+ ...o,
498
+ label: Vt(r),
499
+ collectionId: r.collectionId,
500
+ workflowId: r.workflowId,
501
+ stepId: r.stepId,
502
+ operationId: r.draftStep?.operation?.operationId ?? null,
503
+ isDraft: !r.collectionId && !r.workflowId,
504
+ isHistory: r.historyId != null
505
+ };
506
+ }
507
+ }
508
+ }
509
+ function Qt(e, t) {
510
+ return e.collections.find((s) => s.id.get() === t)?.info.title.get();
511
+ }
512
+ function Vt(e) {
513
+ if (e.stepId)
514
+ return e.stepId;
515
+ if (e.draftStep) {
516
+ const t = [Pe(e.draftStep), De(e.draftStep)].filter(Boolean).join(" ");
517
+ if (t)
518
+ return t;
519
+ }
520
+ return "New Request";
521
+ }
522
+ function Gt(e) {
523
+ return {
524
+ tabs: qt(e),
525
+ apis: Ut(e),
526
+ collections: Lt(e),
527
+ environments: Nt(e)
528
+ };
529
+ }
530
+ function Ht() {
531
+ const { getCollection: e } = Te(), { getWorkflow: t } = We(), { getStep: n } = Be(), { tab: s } = Oe(), o = s?.data.get();
532
+ return w(() => {
533
+ if (!o)
534
+ return null;
535
+ switch (o.type) {
536
+ case x.Collection:
537
+ const a = e(o.collectionId);
538
+ return {
539
+ ...o,
540
+ collection: a ? a.get() : null
541
+ };
542
+ case x.Workflow:
543
+ const i = t({
544
+ collectionId: o.collectionId,
545
+ workflowId: o.workflowId
546
+ });
547
+ return {
548
+ ...o,
549
+ workflow: i ? i.get() : null
550
+ };
551
+ case x.Step:
552
+ const l = n({
553
+ collectionId: o.collectionId,
554
+ workflowId: o.workflowId,
555
+ stepId: o.stepId
556
+ });
557
+ return {
558
+ ...o,
559
+ step: l ? l.get() : null
560
+ };
561
+ case x.WorkflowRun:
562
+ const u = t({
563
+ collectionId: o.collectionId,
564
+ workflowId: o.workflowId
565
+ });
566
+ return {
567
+ ...o,
568
+ workflow: u ? u.get() : null
569
+ };
570
+ }
571
+ }, [o, e, t, n]);
572
+ }
573
+ function zt(e) {
574
+ if (!e || typeof e != "object" || !("changes" in e) || !Array.isArray(e.changes))
575
+ return e;
576
+ const t = e.changes.filter(
577
+ (s) => s && typeof s == "object" && "approved" in s && s.approved === !0
578
+ ), n = "meta" in e && typeof e.meta == "object" ? e.meta : {};
579
+ return {
580
+ ...e,
581
+ changes: t,
582
+ meta: {
583
+ ...n,
584
+ totalChanges: e.changes.length,
585
+ approvedChanges: t.length
586
+ }
587
+ };
588
+ }
589
+ function Yt() {
590
+ return (e, t) => (n, s) => t(zt(n), s);
591
+ }
592
+ function Jt() {
593
+ const { getApiOperation: e } = Ue(), t = Ae();
594
+ return w(
595
+ () => ({
596
+ getApiOperation: e,
597
+ ...t
598
+ }),
599
+ [e, t]
600
+ );
601
+ }
602
+ function Xt(e) {
603
+ const { convertOperationToReplayValue: t } = se(), n = Ht(), s = Jt(), o = ue(), r = ye(), { attachApiToCollection: a } = Te(), { handleCloseByDataId: i } = Ae(), l = Fe(), u = R(n);
604
+ return u.current = n, { tools: w(() => {
605
+ const I = new ft({
606
+ middlewares: [Yt()]
607
+ });
608
+ return Ye(I, {
609
+ [lt.name]: void 0,
610
+ [it.name]: { store: r, settingsState: o },
611
+ [at.name]: { store: r, runWorkflow: l },
612
+ [ot.name]: { store: r },
613
+ [rt.name]: { store: r },
614
+ [st.name]: {
615
+ store: r,
616
+ attachApiToCollection: a,
617
+ handleCloseByDataId: i,
618
+ convertOperationToReplayValue: t
619
+ },
620
+ [nt.name]: { store: r },
621
+ [tt.name]: { model: e },
622
+ [et.name]: { store: r },
623
+ [Ze.name]: { store: r, context: s },
624
+ [Xe.name]: {
625
+ getActiveTabDetailedData: () => u.current
626
+ },
627
+ [Je.name]: { store: r }
628
+ }), I.getToolSet();
629
+ }, [
630
+ a,
631
+ t,
632
+ i,
633
+ e,
634
+ s,
635
+ l,
636
+ o,
637
+ r
638
+ ]) };
639
+ }
640
+ function Zt(e) {
641
+ const { children: t, chatId: n, model: s, initialMessages: o, onChatFinish: r, onChatMessagesUpdated: a } = e, i = ue(), { getReuniteAuth: l } = se(), { tools: u } = Xt(s), { sendEvent: C } = Le(), I = R(u), c = R(s), { isOpen: p, openPanel: h, closePanel: $ } = Se(), P = R(void 0), q = ye(), y = R(q);
642
+ I.current = u, c.current = s, y.current = q;
643
+ const m = w(() => {
644
+ P.current?.end();
645
+ const M = ge.getTracer("replay-ai-chat").startSpan("ai.chat.session", { attributes: { conversation_id: n } });
646
+ P.current = M;
647
+ const E = ge.setSpan(je.active(), M);
648
+ return new He({
649
+ activeConversationId: n,
650
+ model: c.current,
651
+ tools: I.current,
652
+ sendEvent: C,
653
+ parentCtx: E,
654
+ getActiveStateMessage: () => Ot(Gt(y.current))
655
+ });
656
+ }, [n, C]);
657
+ b(() => () => P.current?.end(), []);
658
+ const F = w(() => {
659
+ if (m)
660
+ return new Ve({ agent: m.getAgent() });
661
+ }, [m]);
662
+ b(() => {
663
+ m.setModel(s);
664
+ }, [m, s]), b(() => {
665
+ m.registerTools(u);
666
+ }, [m, u]);
667
+ const {
668
+ messages: k,
669
+ setMessages: D,
670
+ sendMessage: K,
671
+ status: W,
672
+ error: Y,
673
+ stop: B,
674
+ addToolApprovalResponse: O
675
+ } = At({
676
+ id: n,
677
+ messages: o,
678
+ transport: F,
679
+ sendAutomaticallyWhen: Ge,
680
+ onFinish(M) {
681
+ if (!r || !m) return;
682
+ r({ agentLoop: m, chat: this }, M);
683
+ }
684
+ }), U = w(() => W === "streaming" || W === "submitted", [W]), Q = f(() => {
685
+ i.aiEnabled.get() === !0 && h();
686
+ }, [h, i.aiEnabled]), J = f(() => {
687
+ $();
688
+ }, [$]), g = f(
689
+ async (M) => {
690
+ const E = M.trim();
691
+ if (!(!E || !F)) {
692
+ if (s.provider === ne) {
693
+ const T = await l?.();
694
+ T?.baseUrl && T?.accessToken && m.setModel({
695
+ provider: ne,
696
+ baseUrl: T.baseUrl,
697
+ accessToken: T.accessToken
698
+ });
699
+ }
700
+ D(
701
+ (T) => ct(T) ? ut(T) : T
702
+ ), K({ text: E });
703
+ }
704
+ },
705
+ [m, l, s.provider, K, D, F]
706
+ ), L = f(() => {
707
+ U && B();
708
+ }, [U, B]);
709
+ b(() => () => {
710
+ B();
711
+ }, [n, B]);
712
+ const pe = f(
713
+ (M) => {
714
+ const E = M(k), T = E.map((X) => X.message), fe = [...k];
715
+ for (const X of E)
716
+ fe[X.index] = X.message;
717
+ D(fe), a?.(T);
718
+ },
719
+ [k, a, D]
720
+ ), Ee = w(
721
+ () => ({
722
+ messages: k,
723
+ isStreaming: U,
724
+ chatStatus: W,
725
+ chatError: Y,
726
+ sendMessage: g,
727
+ updateMessages: pe,
728
+ stopGeneration: L,
729
+ addToolApprovalResponse: O
730
+ }),
731
+ [
732
+ O,
733
+ Y,
734
+ U,
735
+ k,
736
+ g,
737
+ W,
738
+ L,
739
+ pe
740
+ ]
741
+ ), _e = w(
742
+ () => ({
743
+ isOpen: p,
744
+ openPanel: Q,
745
+ closePanel: J
746
+ }),
747
+ [p, Q, J]
748
+ );
749
+ return /* @__PURE__ */ te(dt.Provider, { value: Ee, children: /* @__PURE__ */ te(Ne.Provider, { value: _e, children: t }) });
750
+ }
751
+ function en(e) {
752
+ return e.slice(-2);
753
+ }
754
+ function tn(e, t) {
755
+ return !!(e || t < 1);
756
+ }
757
+ function nn(e) {
758
+ return f(
759
+ async (t, n) => {
760
+ if (tn(e, n.messages.length))
761
+ return null;
762
+ const s = n.messages[0], o = ht(s.parts);
763
+ try {
764
+ return (await t.agentLoop.generateTitle(o)).trim();
765
+ } catch (r) {
766
+ return console.error("Unable to generate chat title", r), null;
767
+ }
768
+ },
769
+ [e]
770
+ );
771
+ }
772
+ function sn({
773
+ chatId: e,
774
+ model: t,
775
+ existingTitle: n
776
+ }) {
777
+ const { mutate: s } = gt(e), o = nn(n);
778
+ return f(
779
+ async (...r) => {
780
+ const a = await o(...r);
781
+ a !== null && a.length !== 0 && s({
782
+ id: e,
783
+ model: t,
784
+ messages: [],
785
+ title: a
786
+ });
787
+ },
788
+ [o, t, e, s]
789
+ );
790
+ }
791
+ function rn({ chatId: e, model: t }) {
792
+ const { mutate: n } = ke();
793
+ return f(
794
+ (s, o) => {
795
+ const r = en(
796
+ o.messages
797
+ );
798
+ n({
799
+ id: e,
800
+ model: t,
801
+ messages: r
802
+ });
803
+ },
804
+ [t, e, n]
805
+ );
806
+ }
807
+ function on({ chatId: e, model: t }) {
808
+ const { mutate: n } = ke();
809
+ return f(
810
+ (s) => {
811
+ s.length !== 0 && n({
812
+ id: e,
813
+ model: t,
814
+ messages: s
815
+ });
816
+ },
817
+ [t, e, n]
818
+ );
819
+ }
820
+ function an(e) {
821
+ return w(() => {
822
+ const t = [ae];
823
+ if (e) {
824
+ for (const [n, s] of Object.entries(e))
825
+ if (s.enabled && s.apiKey) {
826
+ const o = s.models.map((r) => ({
827
+ ...r,
828
+ provider: n
829
+ }));
830
+ t.push(...o);
831
+ }
832
+ }
833
+ return t;
834
+ }, [e]);
835
+ }
836
+ function Ce(e) {
837
+ return typeof e == "function" ? e() : e;
838
+ }
839
+ function Ie(e, t) {
840
+ try {
841
+ const n = globalThis.localStorage.getItem(e);
842
+ return n === null ? Ce(t) : n;
843
+ } catch {
844
+ return Ce(t);
845
+ }
846
+ }
847
+ function ln(e, t) {
848
+ try {
849
+ globalThis.localStorage.setItem(e, t);
850
+ } catch {
851
+ console.error("Failed to write to localStorage", { key: e, value: t });
852
+ }
853
+ }
854
+ function cn(e, t) {
855
+ const [n, s] = z(() => Ie(e, t)), o = R(t);
856
+ o.current = t, b(() => {
857
+ s(Ie(e, o.current));
858
+ }, [e]);
859
+ const r = f(
860
+ (a) => {
861
+ s((i) => {
862
+ const l = a instanceof Function ? a(i) : a;
863
+ return ln(e, l), l;
864
+ });
865
+ },
866
+ [e]
867
+ );
868
+ return [n, r];
869
+ }
870
+ const un = "replay:ai:selectedModelId";
871
+ function dn(e) {
872
+ const { availableModels: t, aiProviders: n, reuniteAuth: s } = e, [o, r] = cn(
873
+ un,
874
+ ae.id
875
+ );
876
+ return b(() => {
877
+ t.find((l) => l.id === o) || r(ae.id);
878
+ }, [t, o, r]), { model: w(() => {
879
+ const i = {
880
+ provider: ne,
881
+ baseUrl: s.baseUrl,
882
+ accessToken: s.accessToken
883
+ }, l = t.find((C) => C.id === o);
884
+ if (!l || l.provider === ne)
885
+ return i;
886
+ const u = n?.[l.provider];
887
+ return !u || !u.apiKey || !u.enabled ? i : {
888
+ provider: l.provider,
889
+ modelId: l.id,
890
+ apiKey: u.apiKey
891
+ };
892
+ }, [o, t, n, s]), selectedModelId: o, selectModel: r };
893
+ }
894
+ function hn() {
895
+ const [e, t] = z({
896
+ baseUrl: "",
897
+ accessToken: ""
898
+ }), { getReuniteAuth: n } = se();
899
+ return b(() => {
900
+ let s = !1;
901
+ async function o() {
902
+ const r = await n?.();
903
+ s || t({
904
+ baseUrl: r?.baseUrl ?? "",
905
+ accessToken: r?.accessToken ?? ""
906
+ });
907
+ }
908
+ return o().catch(() => {
909
+ s || t({
910
+ baseUrl: "",
911
+ accessToken: ""
912
+ });
913
+ }), () => {
914
+ s = !0;
915
+ };
916
+ }, [n]), e;
917
+ }
918
+ function An(e) {
919
+ const { children: t } = e, [n, s] = z(me), [o, r] = z(n), [a, i] = z(null), l = ue(), u = se(), { openPanel: C } = Se(), I = o !== n, c = f(() => {
920
+ const g = me();
921
+ r(g), s(g);
922
+ }, []), p = f((g) => {
923
+ r(g);
924
+ }, []), { data: h } = pt(o), $ = hn(), P = an(u.aiProviders), { selectedModelId: q, model: y, selectModel: m } = dn({
925
+ availableModels: P,
926
+ aiProviders: u.aiProviders,
927
+ reuniteAuth: $
928
+ }), F = mt(), k = rn({ chatId: n, model: y }), D = on({ chatId: n, model: y }), K = sn({
929
+ chatId: n,
930
+ model: y,
931
+ existingTitle: h?.title
932
+ }), W = f(
933
+ (g, L) => {
934
+ L.isAbort || (k(g, L), K(g, L));
935
+ },
936
+ [k, K]
937
+ ), Y = f(
938
+ (...g) => {
939
+ D(...g);
940
+ },
941
+ [D]
942
+ ), B = f(
943
+ (g) => {
944
+ (o === g || n === g) && c(), F.mutate(g);
945
+ },
946
+ [c, n, F, o]
947
+ ), O = h?.id;
948
+ b(() => {
949
+ O && O !== n && s(O);
950
+ }, [O, o, n]);
951
+ const U = f(() => {
952
+ i(null);
953
+ }, []), Q = f(
954
+ (g) => {
955
+ l.aiEnabled.get() && (c(), i(g), C());
956
+ },
957
+ [C, c, l.aiEnabled]
958
+ ), J = w(
959
+ () => ({
960
+ chatId: n,
961
+ model: y,
962
+ availableModels: P,
963
+ selectedModelId: q,
964
+ selectModel: m,
965
+ onSettingsOpen: u.onSettingsOpen,
966
+ title: h?.title ?? qe.title,
967
+ isLoading: I,
968
+ selectChat: p,
969
+ removeChat: B,
970
+ createNewChat: c,
971
+ openAiChatWithPresetInput: Q,
972
+ pendingComposerPreset: a,
973
+ clearPendingComposerPreset: U
974
+ }),
975
+ [
976
+ n,
977
+ P,
978
+ h?.title,
979
+ y,
980
+ I,
981
+ p,
982
+ B,
983
+ c,
984
+ Q,
985
+ a,
986
+ U,
987
+ q,
988
+ m,
989
+ u.onSettingsOpen
990
+ ]
991
+ );
992
+ return /* @__PURE__ */ te(Ke.Provider, { value: J, children: /* @__PURE__ */ te(
993
+ Zt,
994
+ {
995
+ chatId: n,
996
+ model: y,
997
+ initialMessages: h?.messages,
998
+ onChatFinish: W,
999
+ onChatMessagesUpdated: Y,
1000
+ children: t
1001
+ }
1002
+ ) });
1003
+ }
1004
+ export {
1005
+ An as AiChatProvider
1006
+ };