@redocly/replay 0.27.0-next.3 → 0.27.0-next.5

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 (62) hide show
  1. package/dist/replay-AiChatProvider-BGXsZqW2.js +6 -0
  2. package/dist/replay-AiChatProvider-CVvR1kSd.js +1004 -0
  3. package/dist/replay-AiChatSqliteDBStorage-BFHRKFlk.js +88 -0
  4. package/dist/replay-AiChatSqliteDBStorage-DVJ9f2EK.js +1 -0
  5. package/dist/replay-AiPanel-CynVcVmm.js +2873 -0
  6. package/dist/replay-AiPanel-qVp_s4gD.js +849 -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-CSz7NYH4.js +2857 -0
  10. package/dist/replay-SqliteDBStorage-eRBPh4E8.js +14 -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-C60p47KY.js +1 -0
  14. package/dist/replay-agent-loop-CEZz1kj-.js +1533 -0
  15. package/dist/replay-ai-chat-mappers-BAHU6JIc.js +99 -0
  16. package/dist/replay-ai-chat-mappers-Dqg-QVZy.js +1 -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-C2NQtDcL.js +38224 -0
  20. package/dist/replay-create-model-CUL-l-eX.js +104 -0
  21. package/dist/replay-db-C4jAfGtc.js +64 -0
  22. package/dist/replay-db-Dw-X2WGx.js +306 -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-DAkLV0nr.js +34 -0
  26. package/dist/replay-external-resolver-DN_PWq_2.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-BmX1FPBL.js +6877 -0
  30. package/dist/replay-index-DR1uVBvc.js +503 -0
  31. package/dist/replay-index-DSKZHOXq.js +1 -0
  32. package/dist/{replay-index-gw_CfN4i.js → replay-index-DT5gdiBA.js} +1 -1
  33. package/dist/replay-index-O_Pq5an3.js +92924 -0
  34. package/dist/{replay-index-CiP3e-cc.js → replay-index-m00jnWFr.js} +6 -6
  35. package/dist/replay-index-qZlgEmbq.js +1 -0
  36. package/dist/replay-index-rRWvC2pp.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-CcVVykW7.js +33217 -0
  40. package/dist/replay-lint-ON47l7Vu.js +184 -0
  41. package/dist/{replay-lint-graphql-DV4sCSe6.js → replay-lint-graphql-5cGt2KR_.js} +5 -5
  42. package/dist/{replay-lint-graphql-Cbptkd8N.js → replay-lint-graphql-DlD7bblx.js} +2 -2
  43. package/dist/replay-resolve-BTzo-fSv.js +47 -0
  44. package/dist/replay-resolve-Ca3DUbGq.js +3683 -0
  45. package/dist/{replay-respect-run-ChMawzhr.js → replay-respect-run-BtC2agF9.js} +54 -54
  46. package/dist/{replay-respect-run-BscBAlnT.js → replay-respect-run-eSRzH2dk.js} +447 -447
  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-BMmQuI9X.js → replay-tauri-path-C-oxFOHe.js} +4 -4
  50. package/dist/{replay-tauri-path-kR-IXn3X.js → replay-tauri-path-CKcvIl_h.js} +1 -1
  51. package/dist/replay-useAiChatQueries-CVTxcu2Z.js +192 -0
  52. package/dist/replay-useAiChatQueries-vdKvbmp2.js +3413 -0
  53. package/dist/replay-validate-key-CwIopif3.js +28 -0
  54. package/dist/replay-validate-key-VkgZoK1f.js +1 -0
  55. package/dist/replay.cjs +1 -1
  56. package/dist/replay.d.ts +2 -0
  57. package/dist/replay.js +21 -21
  58. package/package.json +22 -25
  59. package/dist/replay-index-CUY_5IyO.js +0 -8308
  60. package/dist/replay-index-CUdCFVnz.js +0 -178626
  61. package/dist/replay-index-D8qtqDhF.js +0 -1
  62. package/dist/replay-index-DgjC0DLq.js +0 -1
@@ -0,0 +1,1004 @@
1
+ import { jsx as te } from "react/jsx-runtime";
2
+ import { useRef as _, useCallback as f, useSyncExternalStore as re, useEffect as S, useMemo as C, useState as z } from "react";
3
+ import { a as y, A as ce, g as Re, I as xe, T as $e, b as R, c as Pe, d as De, u as Te, e as We, f as Oe, h as Ue, i as Be, j as Ae, k as se, l as ue, m as ye, n as Fe, o as Se, t as ge, p as Le, R as ne, q as je, r as ae, s as Ne, v as qe } from "./replay-index-O_Pq5an3.js";
4
+ import { A as Ke, D as Qe, l as Ve } from "./replay-create-model-C2NQtDcL.js";
5
+ import { AgentLoop as Ge } from "./replay-agent-loop-CEZz1kj-.js";
6
+ import { s as He } from "./replay-db-Dw-X2WGx.js";
7
+ import { r as ze, g as Ye, a as Je, o as Xe, s as Ze, w as et, m as tt, b as nt, u as st, c as rt, d as ot, e as at, h as it, f as lt, A as ct, i as ut, j as dt } from "./replay-useAiChatQueries-vdKvbmp2.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-BAHU6JIc.js";
10
+ class ht {
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: y.all() });
67
+ },
68
+ onError(t) {
69
+ console.error("Failed to upsert ai chat item:", t);
70
+ }
71
+ });
72
+ }
73
+ function pt(e) {
74
+ const t = de(), n = y.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: y.all() });
84
+ },
85
+ onError(s) {
86
+ console.error("Failed to upsert ai chat item:", s);
87
+ }
88
+ });
89
+ }
90
+ function ft() {
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: y.all() });
98
+ const n = e.getQueryData(y.all());
99
+ n && e.setQueryData(
100
+ y.all(),
101
+ n.filter((s) => s.id !== t)
102
+ ), e.setQueryData(y.detail(t), null), e.setQueriesData(
103
+ { queryKey: y.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: y.all() });
118
+ }
119
+ });
120
+ }
121
+ var oe, ve;
122
+ function gt() {
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, d = n - l;
132
+ d <= 0 ? (o = i, t.apply(this, a)) : s = setTimeout(() => {
133
+ o = Date.now(), t.apply(this, a);
134
+ }, d);
135
+ };
136
+ }
137
+ return oe = e, oe;
138
+ }
139
+ var mt = /* @__PURE__ */ gt();
140
+ const vt = /* @__PURE__ */ Re(mt);
141
+ var Me = (e, t, n) => {
142
+ if (!t.has(e))
143
+ throw TypeError("Cannot " + n);
144
+ }, u = (e, t, n) => (Me(e, t, "read from private field"), n ? n.call(e) : t.get(e)), T = (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 = (e, t, n, s) => (Me(e, t, "write to private field"), t.set(e, n), n);
149
+ function wt(e, t) {
150
+ return t != null ? vt(e, t) : e;
151
+ }
152
+ var w, Z, ee, V, G, H, j, ie, le, Ct = class {
153
+ constructor(e = []) {
154
+ T(this, w, void 0), T(this, Z, "ready"), T(this, ee, void 0), T(this, V, /* @__PURE__ */ new Set()), T(this, G, /* @__PURE__ */ new Set()), T(this, H, /* @__PURE__ */ new Set()), this.pushMessage = (t) => {
155
+ E(this, w, u(this, w).concat(t)), u(this, j).call(this);
156
+ }, this.popMessage = () => {
157
+ E(this, w, u(this, w).slice(0, -1)), u(this, j).call(this);
158
+ }, this.replaceMessage = (t, n) => {
159
+ E(this, w, [
160
+ ...u(this, w).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
+ ...u(this, w).slice(t + 1)
164
+ ]), u(this, j).call(this);
165
+ }, this.snapshot = (t) => structuredClone(t), this["~registerMessagesCallback"] = (t, n) => {
166
+ const s = n ? wt(t, n) : t;
167
+ return u(this, V).add(s), () => {
168
+ u(this, V).delete(s);
169
+ };
170
+ }, this["~registerStatusCallback"] = (t) => (u(this, G).add(t), () => {
171
+ u(this, G).delete(t);
172
+ }), this["~registerErrorCallback"] = (t) => (u(this, H).add(t), () => {
173
+ u(this, H).delete(t);
174
+ }), T(this, j, () => {
175
+ u(this, V).forEach((t) => t());
176
+ }), T(this, ie, () => {
177
+ u(this, G).forEach((t) => t());
178
+ }), T(this, le, () => {
179
+ u(this, H).forEach((t) => t());
180
+ }), E(this, w, e);
181
+ }
182
+ get status() {
183
+ return u(this, Z);
184
+ }
185
+ set status(e) {
186
+ E(this, Z, e), u(this, ie).call(this);
187
+ }
188
+ get error() {
189
+ return u(this, ee);
190
+ }
191
+ set error(e) {
192
+ E(this, ee, e), u(this, le).call(this);
193
+ }
194
+ get messages() {
195
+ return u(this, w);
196
+ }
197
+ set messages(e) {
198
+ E(this, w, [...e]), u(this, j).call(this);
199
+ }
200
+ };
201
+ w = /* @__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 Ke {
211
+ constructor({ messages: e, ...t }) {
212
+ const n = new Ct(e);
213
+ super({ ...t, state: n }), T(this, N, void 0), this["~registerMessagesCallback"] = (s, o) => u(this, N)["~registerMessagesCallback"](s, o), this["~registerStatusCallback"] = (s) => u(this, N)["~registerStatusCallback"](s), this["~registerErrorCallback"] = (s) => u(this, N)["~registerErrorCallback"](s), E(this, N, n);
214
+ }
215
+ };
216
+ N = /* @__PURE__ */ new WeakMap();
217
+ function It({
218
+ experimental_throttle: e,
219
+ resume: t = !1,
220
+ ...n
221
+ } = {}) {
222
+ const s = _(
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 = _(
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
+ ), d = re(
274
+ r.current["~registerStatusCallback"],
275
+ () => r.current.status,
276
+ () => r.current.status
277
+ ), v = re(
278
+ r.current["~registerErrorCallback"],
279
+ () => r.current.error,
280
+ () => r.current.error
281
+ ), x = f(
282
+ (c) => {
283
+ typeof c == "function" && (c = c(r.current.messages)), r.current.messages = c;
284
+ },
285
+ [r]
286
+ );
287
+ return S(() => {
288
+ t && r.current.resumeStream();
289
+ }, [t, r]), {
290
+ id: r.current.id,
291
+ messages: l,
292
+ setMessages: x,
293
+ sendMessage: r.current.sendMessage,
294
+ regenerate: r.current.regenerate,
295
+ clearError: r.current.clearError,
296
+ stop: r.current.stop,
297
+ error: v,
298
+ resumeStream: r.current.resumeStream,
299
+ status: d,
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 Tt = 20;
309
+ function At(e) {
310
+ if (e.length === 0)
311
+ return "No OpenAPI specs loaded.";
312
+ const t = e.slice(0, Tt), n = t.map(yt), 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 yt(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 St = 30;
325
+ function bt(e) {
326
+ if (e.length === 0)
327
+ return "No Arazzo collections loaded.";
328
+ const t = [`Arazzo collections (${e.length}):`];
329
+ let n = St, 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(kt(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(` ${Mt(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 kt(e) {
352
+ const t = e.sourceApiIds.length > 0 ? ` apis=[${e.sourceApiIds.join(", ")}]` : "";
353
+ return ` collectionId="${e.collectionId}" title="${e.title}"${t}`;
354
+ }
355
+ function Mt(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 Et = 20;
360
+ function _t(e) {
361
+ if (e.length === 0)
362
+ return "No environments configured.";
363
+ const t = e.slice(0, Et), n = t.map(Rt), 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 Rt(e) {
370
+ return [
371
+ `${e.isActive ? "*" : " "} name="${e.name}"`,
372
+ `inputs=${e.inputCount}`,
373
+ `servers=${e.serverCount}`
374
+ ].join(" ");
375
+ }
376
+ const xt = 30;
377
+ function $t(e) {
378
+ if (e.length === 0)
379
+ return "No tabs are open.";
380
+ const t = e.slice(0, xt), n = t.map(Pt), 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 Pt(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 Dt = "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 Wt(e) {
408
+ const t = `
409
+ `.repeat(2), n = [
410
+ Dt,
411
+ t,
412
+ $t(e.tabs),
413
+ t,
414
+ At(e.apis),
415
+ t,
416
+ bt(e.collections),
417
+ t,
418
+ _t(e.environments)
419
+ ].join("");
420
+ return He("active_state", n);
421
+ }
422
+ function Ot(e) {
423
+ return e.apis.get({ noproxy: !0 }).map(Ut);
424
+ }
425
+ function Ut(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 Bt(e) {
434
+ return e.collections.get({ noproxy: !0 }).map(Ft);
435
+ }
436
+ function Ft(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 Lt(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 jt(e) {
459
+ const t = e.tabsState.tabs.get({ noproxy: !0 }), n = e.tabsState.activeTabIdx.get({ noproxy: !0 });
460
+ return t.map(
461
+ (s, o) => Nt(e, s, o, o === n)
462
+ );
463
+ }
464
+ function Nt(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 R.Collection: {
473
+ const { collectionId: r } = t.data;
474
+ return {
475
+ ...o,
476
+ label: qt(e, r) ?? r,
477
+ collectionId: r
478
+ };
479
+ }
480
+ case R.Workflow: {
481
+ const { collectionId: r, workflowId: a } = t.data;
482
+ return { ...o, label: a, collectionId: r, workflowId: a };
483
+ }
484
+ case R.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 R.Step: {
495
+ const r = t.data;
496
+ return {
497
+ ...o,
498
+ label: Kt(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 Kt(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 Qt(e) {
523
+ return {
524
+ tabs: jt(e),
525
+ apis: Ot(e),
526
+ collections: Bt(e),
527
+ environments: Lt(e)
528
+ };
529
+ }
530
+ function Vt() {
531
+ const { getCollection: e } = Te(), { getWorkflow: t } = We(), { getStep: n } = Oe(), { tab: s } = Ue(), o = s?.data.get();
532
+ return C(() => {
533
+ if (!o)
534
+ return null;
535
+ switch (o.type) {
536
+ case R.Collection:
537
+ const a = e(o.collectionId);
538
+ return {
539
+ ...o,
540
+ collection: a ? a.get() : null
541
+ };
542
+ case R.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 R.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 R.WorkflowRun:
562
+ const d = t({
563
+ collectionId: o.collectionId,
564
+ workflowId: o.workflowId
565
+ });
566
+ return {
567
+ ...o,
568
+ workflow: d ? d.get() : null
569
+ };
570
+ }
571
+ }, [o, e, t, n]);
572
+ }
573
+ function Gt(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 Ht() {
590
+ return (e, t) => (n, s) => t(Gt(n), s);
591
+ }
592
+ function zt() {
593
+ const { getApiOperation: e } = Be(), t = Ae();
594
+ return C(
595
+ () => ({
596
+ getApiOperation: e,
597
+ ...t
598
+ }),
599
+ [e, t]
600
+ );
601
+ }
602
+ function Yt(e) {
603
+ const { convertOperationToReplayValue: t } = se(), n = Vt(), s = zt(), o = ue(), r = ye(), { attachApiToCollection: a } = Te(), { handleCloseByDataId: i } = Ae(), l = _(n);
604
+ return l.current = n, { tools: C(() => {
605
+ const v = new ht({
606
+ middlewares: [Ht()]
607
+ });
608
+ return ze(v, {
609
+ [at.name]: void 0,
610
+ [ot.name]: { store: r, settingsState: o },
611
+ [rt.name]: { store: r },
612
+ [st.name]: { store: r },
613
+ [nt.name]: {
614
+ store: r,
615
+ attachApiToCollection: a,
616
+ handleCloseByDataId: i,
617
+ convertOperationToReplayValue: t
618
+ },
619
+ [tt.name]: { store: r },
620
+ [et.name]: { model: e },
621
+ [Ze.name]: { store: r },
622
+ [Xe.name]: { store: r, context: s },
623
+ [Je.name]: {
624
+ getActiveTabDetailedData: () => l.current
625
+ },
626
+ [Ye.name]: { store: r }
627
+ }), v.getToolSet();
628
+ }, [
629
+ a,
630
+ t,
631
+ i,
632
+ e,
633
+ s,
634
+ o,
635
+ r
636
+ ]) };
637
+ }
638
+ function Jt(e) {
639
+ const { children: t, chatId: n, model: s, initialMessages: o, onChatFinish: r, onChatMessagesUpdated: a } = e, i = ue(), { getReuniteAuth: l } = se(), { tools: d } = Yt(s), { sendEvent: v } = Fe(), x = _(d), c = _(s), { isOpen: p, openPanel: h, closePanel: $ } = Se(), P = _(void 0), q = ye(), A = _(q);
640
+ x.current = d, c.current = s, A.current = q;
641
+ const m = C(() => {
642
+ P.current?.end();
643
+ const k = ge.getTracer("replay-ai-chat").startSpan("ai.chat.session", { attributes: { conversation_id: n } });
644
+ P.current = k;
645
+ const M = ge.setSpan(Le.active(), k);
646
+ return new Ge({
647
+ activeConversationId: n,
648
+ model: c.current,
649
+ tools: x.current,
650
+ sendEvent: v,
651
+ parentCtx: M,
652
+ getActiveStateMessage: () => Wt(Qt(A.current))
653
+ });
654
+ }, [n, v]);
655
+ S(() => () => P.current?.end(), []);
656
+ const F = C(() => {
657
+ if (m)
658
+ return new Qe({ agent: m.getAgent() });
659
+ }, [m]);
660
+ S(() => {
661
+ m.setModel(s);
662
+ }, [m, s]), S(() => {
663
+ m.registerTools(d);
664
+ }, [m, d]);
665
+ const {
666
+ messages: b,
667
+ setMessages: D,
668
+ sendMessage: K,
669
+ status: W,
670
+ error: Y,
671
+ stop: O,
672
+ addToolApprovalResponse: U
673
+ } = It({
674
+ id: n,
675
+ messages: o,
676
+ transport: F,
677
+ sendAutomaticallyWhen: Ve,
678
+ onFinish(k) {
679
+ if (!r || !m) return;
680
+ r({ agentLoop: m, chat: this }, k);
681
+ }
682
+ }), B = C(() => W === "streaming" || W === "submitted", [W]), Q = f(() => {
683
+ i.aiEnabled.get() === !0 && h();
684
+ }, [h, i.aiEnabled]), J = f(() => {
685
+ $();
686
+ }, [$]), g = f(
687
+ async (k) => {
688
+ const M = k.trim();
689
+ if (!(!M || !F)) {
690
+ if (s.provider === ne) {
691
+ const I = await l?.();
692
+ I?.baseUrl && I?.accessToken && m.setModel({
693
+ provider: ne,
694
+ baseUrl: I.baseUrl,
695
+ accessToken: I.accessToken
696
+ });
697
+ }
698
+ D(
699
+ (I) => it(I) ? lt(I) : I
700
+ ), K({ text: M });
701
+ }
702
+ },
703
+ [m, l, s.provider, K, D, F]
704
+ ), L = f(() => {
705
+ B && O();
706
+ }, [B, O]);
707
+ S(() => () => {
708
+ O();
709
+ }, [n, O]);
710
+ const pe = f(
711
+ (k) => {
712
+ const M = k(b), I = M.map((X) => X.message), fe = [...b];
713
+ for (const X of M)
714
+ fe[X.index] = X.message;
715
+ D(fe), a?.(I);
716
+ },
717
+ [b, a, D]
718
+ ), Ee = C(
719
+ () => ({
720
+ messages: b,
721
+ isStreaming: B,
722
+ chatStatus: W,
723
+ chatError: Y,
724
+ sendMessage: g,
725
+ updateMessages: pe,
726
+ stopGeneration: L,
727
+ addToolApprovalResponse: U
728
+ }),
729
+ [
730
+ U,
731
+ Y,
732
+ B,
733
+ b,
734
+ g,
735
+ W,
736
+ L,
737
+ pe
738
+ ]
739
+ ), _e = C(
740
+ () => ({
741
+ isOpen: p,
742
+ openPanel: Q,
743
+ closePanel: J
744
+ }),
745
+ [p, Q, J]
746
+ );
747
+ return /* @__PURE__ */ te(ct.Provider, { value: Ee, children: /* @__PURE__ */ te(je.Provider, { value: _e, children: t }) });
748
+ }
749
+ function Xt(e) {
750
+ return e.slice(-2);
751
+ }
752
+ function Zt(e, t) {
753
+ return !!(e || t < 1);
754
+ }
755
+ function en(e) {
756
+ return f(
757
+ async (t, n) => {
758
+ if (Zt(e, n.messages.length))
759
+ return null;
760
+ const s = n.messages[0], o = ut(s.parts);
761
+ try {
762
+ return (await t.agentLoop.generateTitle(o)).trim();
763
+ } catch (r) {
764
+ return console.error("Unable to generate chat title", r), null;
765
+ }
766
+ },
767
+ [e]
768
+ );
769
+ }
770
+ function tn({
771
+ chatId: e,
772
+ model: t,
773
+ existingTitle: n
774
+ }) {
775
+ const { mutate: s } = pt(e), o = en(n);
776
+ return f(
777
+ async (...r) => {
778
+ const a = await o(...r);
779
+ a !== null && a.length !== 0 && s({
780
+ id: e,
781
+ model: t,
782
+ messages: [],
783
+ title: a
784
+ });
785
+ },
786
+ [o, t, e, s]
787
+ );
788
+ }
789
+ function nn({ chatId: e, model: t }) {
790
+ const { mutate: n } = ke();
791
+ return f(
792
+ (s, o) => {
793
+ const r = Xt(
794
+ o.messages
795
+ );
796
+ n({
797
+ id: e,
798
+ model: t,
799
+ messages: r
800
+ });
801
+ },
802
+ [t, e, n]
803
+ );
804
+ }
805
+ function sn({ chatId: e, model: t }) {
806
+ const { mutate: n } = ke();
807
+ return f(
808
+ (s) => {
809
+ s.length !== 0 && n({
810
+ id: e,
811
+ model: t,
812
+ messages: s
813
+ });
814
+ },
815
+ [t, e, n]
816
+ );
817
+ }
818
+ function rn(e) {
819
+ return C(() => {
820
+ const t = [ae];
821
+ if (e) {
822
+ for (const [n, s] of Object.entries(e))
823
+ if (s.enabled && s.apiKey) {
824
+ const o = s.models.map((r) => ({
825
+ ...r,
826
+ provider: n
827
+ }));
828
+ t.push(...o);
829
+ }
830
+ }
831
+ return t;
832
+ }, [e]);
833
+ }
834
+ function Ce(e) {
835
+ return typeof e == "function" ? e() : e;
836
+ }
837
+ function Ie(e, t) {
838
+ try {
839
+ const n = globalThis.localStorage.getItem(e);
840
+ return n === null ? Ce(t) : n;
841
+ } catch {
842
+ return Ce(t);
843
+ }
844
+ }
845
+ function on(e, t) {
846
+ try {
847
+ globalThis.localStorage.setItem(e, t);
848
+ } catch {
849
+ console.error("Failed to write to localStorage", { key: e, value: t });
850
+ }
851
+ }
852
+ function an(e, t) {
853
+ const [n, s] = z(() => Ie(e, t)), o = _(t);
854
+ o.current = t, S(() => {
855
+ s(Ie(e, o.current));
856
+ }, [e]);
857
+ const r = f(
858
+ (a) => {
859
+ s((i) => {
860
+ const l = a instanceof Function ? a(i) : a;
861
+ return on(e, l), l;
862
+ });
863
+ },
864
+ [e]
865
+ );
866
+ return [n, r];
867
+ }
868
+ const ln = "replay:ai:selectedModelId";
869
+ function cn(e) {
870
+ const { availableModels: t, aiProviders: n, reuniteAuth: s } = e, [o, r] = an(
871
+ ln,
872
+ ae.id
873
+ );
874
+ return S(() => {
875
+ t.find((l) => l.id === o) || r(ae.id);
876
+ }, [t, o, r]), { model: C(() => {
877
+ const i = {
878
+ provider: ne,
879
+ baseUrl: s.baseUrl,
880
+ accessToken: s.accessToken
881
+ }, l = t.find((v) => v.id === o);
882
+ if (!l || l.provider === ne)
883
+ return i;
884
+ const d = n?.[l.provider];
885
+ return !d || !d.apiKey || !d.enabled ? i : {
886
+ provider: l.provider,
887
+ modelId: l.id,
888
+ apiKey: d.apiKey
889
+ };
890
+ }, [o, t, n, s]), selectedModelId: o, selectModel: r };
891
+ }
892
+ function un() {
893
+ const [e, t] = z({
894
+ baseUrl: "",
895
+ accessToken: ""
896
+ }), { getReuniteAuth: n } = se();
897
+ return S(() => {
898
+ let s = !1;
899
+ async function o() {
900
+ const r = await n?.();
901
+ s || t({
902
+ baseUrl: r?.baseUrl ?? "",
903
+ accessToken: r?.accessToken ?? ""
904
+ });
905
+ }
906
+ return o().catch(() => {
907
+ s || t({
908
+ baseUrl: "",
909
+ accessToken: ""
910
+ });
911
+ }), () => {
912
+ s = !0;
913
+ };
914
+ }, [n]), e;
915
+ }
916
+ function In(e) {
917
+ const { children: t } = e, [n, s] = z(me), [o, r] = z(n), [a, i] = z(null), l = ue(), d = se(), { openPanel: v } = Se(), x = o !== n, c = f(() => {
918
+ const g = me();
919
+ r(g), s(g);
920
+ }, []), p = f((g) => {
921
+ r(g);
922
+ }, []), { data: h } = dt(o), $ = un(), P = rn(d.aiProviders), { selectedModelId: q, model: A, selectModel: m } = cn({
923
+ availableModels: P,
924
+ aiProviders: d.aiProviders,
925
+ reuniteAuth: $
926
+ }), F = ft(), b = nn({ chatId: n, model: A }), D = sn({ chatId: n, model: A }), K = tn({
927
+ chatId: n,
928
+ model: A,
929
+ existingTitle: h?.title
930
+ }), W = f(
931
+ (g, L) => {
932
+ L.isAbort || (b(g, L), K(g, L));
933
+ },
934
+ [b, K]
935
+ ), Y = f(
936
+ (...g) => {
937
+ D(...g);
938
+ },
939
+ [D]
940
+ ), O = f(
941
+ (g) => {
942
+ (o === g || n === g) && c(), F.mutate(g);
943
+ },
944
+ [c, n, F, o]
945
+ ), U = h?.id;
946
+ S(() => {
947
+ U && U !== n && s(U);
948
+ }, [U, o, n]);
949
+ const B = f(() => {
950
+ i(null);
951
+ }, []), Q = f(
952
+ (g) => {
953
+ l.aiEnabled.get() && (c(), i(g), v());
954
+ },
955
+ [v, c, l.aiEnabled]
956
+ ), J = C(
957
+ () => ({
958
+ chatId: n,
959
+ model: A,
960
+ availableModels: P,
961
+ selectedModelId: q,
962
+ selectModel: m,
963
+ onSettingsOpen: d.onSettingsOpen,
964
+ title: h?.title ?? Ne.title,
965
+ isLoading: x,
966
+ selectChat: p,
967
+ removeChat: O,
968
+ createNewChat: c,
969
+ openAiChatWithPresetInput: Q,
970
+ pendingComposerPreset: a,
971
+ clearPendingComposerPreset: B
972
+ }),
973
+ [
974
+ n,
975
+ P,
976
+ h?.title,
977
+ A,
978
+ x,
979
+ p,
980
+ O,
981
+ c,
982
+ Q,
983
+ a,
984
+ B,
985
+ q,
986
+ m,
987
+ d.onSettingsOpen
988
+ ]
989
+ );
990
+ return /* @__PURE__ */ te(qe.Provider, { value: J, children: /* @__PURE__ */ te(
991
+ Jt,
992
+ {
993
+ chatId: n,
994
+ model: A,
995
+ initialMessages: h?.messages,
996
+ onChatFinish: W,
997
+ onChatMessagesUpdated: Y,
998
+ children: t
999
+ }
1000
+ ) });
1001
+ }
1002
+ export {
1003
+ In as AiChatProvider
1004
+ };