@scalar/agent-chat 0.8.0 → 0.9.1

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.
@@ -1,45 +1,46 @@
1
- import { Chat as j } from "@ai-sdk/vue";
2
- import { useModal as k } from "@scalar/components";
3
- import { redirectToProxy as x } from "@scalar/helpers/url/redirect-to-proxy";
4
- import { apiReferenceConfigurationSchema as q } from "@scalar/types/api-reference";
5
- import { useToasts as z } from "@scalar/use-toasts";
6
- import { createWorkspaceStore as H } from "@scalar/workspace-store/client";
7
- import { createWorkspaceEventBus as Q } from "@scalar/workspace-store/events";
8
- import { DefaultChatTransport as J, lastAssistantMessageIsCompleteWithToolCalls as V } from "ai";
9
- import { n as Z } from "neverpanic";
10
- import { ref as D, reactive as K, computed as $, watch as L, inject as tt } from "vue";
11
- import { createApi as ot, createAuthorizationHeaders as et } from "../api.js";
12
- import { executeRequestTool as rt } from "../client-tools/execute-request.js";
13
- import { URLS as R } from "../consts/urls.js";
14
- import { EXECUTE_CLIENT_SIDE_REQUEST_TOOL_NAME as nt } from "../entities/tools/execute-request.js";
15
- import { createDocumentSettings as C } from "../helpers.js";
16
- import { useTermsAndConditions as at } from "../hooks/use-term-and-conditions.js";
17
- import { persistencePlugin as ct } from "../plugins/persistance.js";
18
- import { loadDocument as N } from "../registry/add-documents-to-store.js";
19
- import { createDocumentName as st } from "../registry/create-document-name.js";
20
- import { createError as it } from "../entities/error/helpers.js";
21
- const mt = /* @__PURE__ */ Symbol("STATE_SYMBOL"), { toast: y } = z();
22
- function ut({
1
+ import { Chat as k } from "@ai-sdk/vue";
2
+ import { useModal as q } from "@scalar/components";
3
+ import { redirectToProxy as M } from "@scalar/helpers/url/redirect-to-proxy";
4
+ import { apiReferenceConfigurationSchema as z } from "@scalar/types/api-reference";
5
+ import { useToasts as H } from "@scalar/use-toasts";
6
+ import { createWorkspaceStore as Q } from "@scalar/workspace-store/client";
7
+ import { createWorkspaceEventBus as J } from "@scalar/workspace-store/events";
8
+ import { DefaultChatTransport as V, lastAssistantMessageIsCompleteWithToolCalls as Z } from "ai";
9
+ import { n as K } from "neverpanic";
10
+ import { ref as h, reactive as tt, computed as $, watch as C, inject as ot } from "vue";
11
+ import { createApi as et, createAuthorizationHeaders as rt } from "../api.js";
12
+ import { executeRequestTool as nt } from "../client-tools/execute-request.js";
13
+ import { URLS as N } from "../consts/urls.js";
14
+ import { EXECUTE_CLIENT_SIDE_REQUEST_TOOL_NAME as at } from "../entities/tools/execute-request.js";
15
+ import { createDocumentSettings as x } from "../helpers.js";
16
+ import { useTermsAndConditions as ct } from "../hooks/use-term-and-conditions.js";
17
+ import { removeTmpDocFromLocalStorage as st } from "../hooks/use-upload-tmp-document.js";
18
+ import { persistencePlugin as it } from "../plugins/persistance.js";
19
+ import { loadDocument as I } from "../registry/add-documents-to-store.js";
20
+ import { createDocumentName as mt } from "../registry/create-document-name.js";
21
+ import { createError as ut } from "../entities/error/helpers.js";
22
+ const ft = /* @__PURE__ */ Symbol("STATE_SYMBOL"), { toast: y } = H();
23
+ function dt({
23
24
  registryDocuments: s,
24
25
  workspaceStore: i,
25
- baseUrl: E,
26
+ baseUrl: v,
26
27
  proxyUrl: a,
27
28
  getAccessToken: T,
28
- getAgentKey: w
29
+ getAgentKey: E
29
30
  }) {
30
- const m = new j({
31
- sendAutomaticallyWhen: V,
32
- transport: new J({
33
- api: x(a.value, `${E}/vector/openapi/chat`),
34
- headers: () => et({ getAccessToken: T, getAgentKey: w }),
31
+ const m = new k({
32
+ sendAutomaticallyWhen: Z,
33
+ transport: new V({
34
+ api: M(a.value, `${v}/vector/openapi/chat`),
35
+ headers: () => rt({ getAccessToken: T, getAgentKey: E }),
35
36
  body: () => ({
36
37
  registryDocuments: s.value,
37
- documentSettings: C(i)
38
+ documentSettings: x(i)
38
39
  })
39
40
  }),
40
41
  async onToolCall({ toolCall: r }) {
41
- r.dynamic || r.toolName === nt && r.input.method.toLowerCase() === "get" && await rt({
42
- documentSettings: C(i),
42
+ r.dynamic || r.toolName === at && r.input.method.toLowerCase() === "get" && await nt({
43
+ documentSettings: x(i),
43
44
  input: r.input,
44
45
  toolCallId: r.toolCallId,
45
46
  chat: m,
@@ -49,150 +50,151 @@ function ut({
49
50
  });
50
51
  return m;
51
52
  }
52
- function Ct({
53
+ function It({
53
54
  initialRegistryDocuments: s,
54
55
  registryUrl: i,
55
- dashboardUrl: E,
56
+ dashboardUrl: v,
56
57
  baseUrl: a,
57
58
  mode: T,
58
- isLoggedIn: w,
59
+ isLoggedIn: E,
59
60
  getAccessToken: m,
60
61
  getAgentKey: r,
61
- getActiveDocumentJson: I,
62
- prefilledMessageRef: S,
63
- hideAddApi: M
62
+ getActiveDocumentJson: O,
63
+ prefilledMessageRef: w,
64
+ hideAddApi: G
64
65
  }) {
65
- const v = D(S?.value ?? ""), n = D([]), f = K({}), O = D([]), U = D(R.DEFAULT_PROXY_URL), p = $(() => U.value?.trim() || R.DEFAULT_PROXY_URL), G = D(), b = at(), B = Q(), l = H({
66
+ const D = h(w?.value ?? ""), n = h([]), f = tt({}), B = h([]), U = h(N.DEFAULT_PROXY_URL), d = $(() => U.value?.trim() || N.DEFAULT_PROXY_URL), F = h(), g = ct(), P = J(), p = Q({
66
67
  plugins: [
67
- ct({
68
+ it({
68
69
  persistAuth: !0
69
70
  })
70
71
  ]
71
- }), _ = $(
72
- () => q.parse({
73
- proxyUrl: p.value,
72
+ }), S = $(
73
+ () => z.parse({
74
+ proxyUrl: d.value,
74
75
  persistAuth: !0
75
76
  })
76
- ), c = ut({
77
+ ), c = dt({
77
78
  registryDocuments: n,
78
- workspaceStore: l,
79
+ workspaceStore: p,
79
80
  baseUrl: a,
80
- proxyUrl: p,
81
+ proxyUrl: d,
81
82
  getAccessToken: m,
82
83
  getAgentKey: r
83
- }), A = ot({
84
+ }), _ = et({
84
85
  baseUrl: a,
85
- proxyUrl: p,
86
+ proxyUrl: d,
86
87
  getAccessToken: m,
87
88
  getAgentKey: r
88
- }), P = $(
89
+ }), W = $(
89
90
  () => c.status === "submitted" || c.status === "streaming" && !c.lastMessage?.parts.some((t) => t.type === "text")
90
91
  );
91
- L(
92
+ C(
92
93
  () => c.status,
93
94
  () => {
94
- c.status === "streaming" && (v.value = "");
95
+ c.status === "streaming" && (D.value = "");
95
96
  }
96
- ), S && L(S, async (t) => {
97
- t && (v.value = t, b.accepted.value && await c.sendMessage({ text: v.value }));
97
+ ), w && C(w, async (t) => {
98
+ t && (D.value = t, g.accepted.value && await c.sendMessage({ text: D.value }));
98
99
  });
99
- const W = k();
100
- async function g({
100
+ const Y = q();
101
+ async function L({
101
102
  namespace: t,
102
103
  slug: o,
103
- removable: u = !0
104
+ removable: u = !0,
105
+ tmp: b = !1
104
106
  }) {
105
- if (n.value.find((e) => e.namespace === t && e.slug === o))
107
+ if (n.value.find((R) => R.namespace === t && R.slug === o))
106
108
  return;
107
- const h = `@${t}/${o}`;
108
- f[h] = !0;
109
- const d = await N({
109
+ const l = `@${t}/${o}`;
110
+ f[l] = !0;
111
+ const e = await I({
110
112
  namespace: t,
111
113
  slug: o,
112
- workspaceStore: l,
114
+ workspaceStore: p,
113
115
  registryUrl: i,
114
116
  registryDocuments: n,
115
- config: _.value,
116
- api: A,
117
+ config: S.value,
118
+ api: _,
117
119
  removable: u
118
120
  });
119
- if (f[h] = !1, !d.success)
120
- throw console.warn("[AGENT]: Unable to load document", d.error), y(`Unable to load the document @${t}/${o}`, "warn"), d.error;
121
+ if (f[l] = !1, !e.success)
122
+ throw b ? (st(), e.error) : (console.warn("[AGENT]: Unable to load document", e.error), y(`Unable to load the document @${t}/${o}`, "warn"), e.error);
121
123
  }
122
- async function Y({
124
+ async function X({
123
125
  namespace: t,
124
126
  slug: o,
125
127
  removable: u = !0
126
128
  }) {
127
129
  if (n.value.find((e) => e.namespace === t && e.slug === o))
128
130
  return;
129
- const h = `@${t}/${o}`;
130
- f[h] = !0;
131
- const d = await Z.fromUnsafe(
132
- () => fetch(x(p.value, `${a}/vector/registry/embeddings/${t}/${o}`), {
131
+ const A = `@${t}/${o}`;
132
+ f[A] = !0;
133
+ const l = await K.fromUnsafe(
134
+ () => fetch(M(d.value, `${a}/vector/registry/embeddings/${t}/${o}`), {
133
135
  method: "GET"
134
136
  }),
135
- (e) => it("FAILED_TO_GET_EMBEDDING_STATUS", e)
137
+ (e) => ut("FAILED_TO_GET_EMBEDDING_STATUS", e)
136
138
  );
137
- if (d.success && d.data.ok) {
138
- const e = await N({
139
+ if (l.success && l.data.ok) {
140
+ const e = await I({
139
141
  namespace: t,
140
142
  slug: o,
141
- workspaceStore: l,
143
+ workspaceStore: p,
142
144
  registryUrl: i,
143
145
  registryDocuments: n,
144
- config: _.value,
145
- api: A,
146
+ config: S.value,
147
+ api: _,
146
148
  removable: u
147
149
  });
148
150
  e.success || (console.warn("[AGENT]: Unable to load document", e.error), y(`Unable to load the document @${t}/${o}`, "warn"));
149
151
  } else
150
152
  console.warn("[AGENT]: Document could not be embedded"), y(`Unable to embed the document @${t}/${o}`, "warn");
151
- f[h] = !1;
153
+ f[A] = !1;
152
154
  }
153
- function F({ namespace: t, slug: o }) {
155
+ function j({ namespace: t, slug: o }) {
154
156
  n.value = n.value.filter(
155
157
  (u) => !(u.namespace === t && u.slug === o)
156
- ), l.deleteDocument(st(t, o));
158
+ ), p.deleteDocument(mt(t, o));
157
159
  }
158
- return s.forEach(({ namespace: t, slug: o }) => g({ namespace: t, slug: o, removable: !1 })), {
159
- prompt: v,
160
+ return s.forEach(({ namespace: t, slug: o }) => L({ namespace: t, slug: o, removable: !1 })), {
161
+ prompt: D,
160
162
  chat: c,
161
- workspaceStore: l,
162
- eventBus: B,
163
- loading: P,
164
- settingsModal: W,
165
- config: _,
163
+ workspaceStore: p,
164
+ eventBus: P,
165
+ loading: W,
166
+ settingsModal: Y,
167
+ config: S,
166
168
  registryUrl: i,
167
- dashboardUrl: E,
169
+ dashboardUrl: v,
168
170
  baseUrl: a,
169
171
  registryDocuments: n,
170
172
  pendingDocuments: f,
171
- proxyUrl: p,
173
+ proxyUrl: d,
172
174
  proxyUrlRaw: U,
173
175
  mode: T,
174
- terms: b,
175
- isLoggedIn: w,
176
- addDocument: g,
177
- addDocumentAsync: Y,
178
- removeDocument: F,
176
+ terms: g,
177
+ isLoggedIn: E,
178
+ addDocument: L,
179
+ addDocumentAsync: X,
180
+ removeDocument: j,
179
181
  getAccessToken: m,
180
182
  getAgentKey: r,
181
- api: A,
182
- uploadedTmpDocumentUrl: G,
183
- curatedDocuments: O,
184
- getActiveDocumentJson: I,
185
- hideAddApi: M
183
+ api: _,
184
+ uploadedTmpDocumentUrl: F,
185
+ curatedDocuments: B,
186
+ getActiveDocumentJson: O,
187
+ hideAddApi: G
186
188
  };
187
189
  }
188
- function Nt() {
189
- const s = tt(mt);
190
+ function Mt() {
191
+ const s = ot(ft);
190
192
  if (!s)
191
193
  throw new Error("No state provided.");
192
194
  return s;
193
195
  }
194
196
  export {
195
- mt as STATE_SYMBOL,
196
- Ct as createState,
197
- Nt as useState
197
+ ft as STATE_SYMBOL,
198
+ It as createState,
199
+ Mt as useState
198
200
  };