@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.
- package/dist/App.vue.d.ts +1 -0
- package/dist/App.vue.d.ts.map +1 -1
- package/dist/Chat.vue.d.ts.map +1 -1
- package/dist/Chat.vue.js +6 -5
- package/dist/components/PaymentSection.vue.js +2 -2
- package/dist/components/PaymentSection.vue2.js +10 -10
- package/dist/helpers.d.ts +16 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/hooks/use-upload-tmp-document.d.ts +1 -0
- package/dist/hooks/use-upload-tmp-document.d.ts.map +1 -1
- package/dist/hooks/use-upload-tmp-document.js +33 -28
- package/dist/package.json +1 -1
- package/dist/state/state.d.ts +1 -0
- package/dist/state/state.d.ts.map +1 -1
- package/dist/state/state.js +105 -103
- package/dist/style.css +1 -1
- package/package.json +7 -7
package/dist/state/state.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
import { Chat as
|
|
2
|
-
import { useModal as
|
|
3
|
-
import { redirectToProxy as
|
|
4
|
-
import { apiReferenceConfigurationSchema as
|
|
5
|
-
import { useToasts as
|
|
6
|
-
import { createWorkspaceStore as
|
|
7
|
-
import { createWorkspaceEventBus as
|
|
8
|
-
import { DefaultChatTransport as
|
|
9
|
-
import { n as
|
|
10
|
-
import { ref as
|
|
11
|
-
import { createApi as
|
|
12
|
-
import { executeRequestTool as
|
|
13
|
-
import { URLS as
|
|
14
|
-
import { EXECUTE_CLIENT_SIDE_REQUEST_TOOL_NAME as
|
|
15
|
-
import { createDocumentSettings as
|
|
16
|
-
import { useTermsAndConditions as
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
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:
|
|
26
|
+
baseUrl: v,
|
|
26
27
|
proxyUrl: a,
|
|
27
28
|
getAccessToken: T,
|
|
28
|
-
getAgentKey:
|
|
29
|
+
getAgentKey: E
|
|
29
30
|
}) {
|
|
30
|
-
const m = new
|
|
31
|
-
sendAutomaticallyWhen:
|
|
32
|
-
transport: new
|
|
33
|
-
api:
|
|
34
|
-
headers: () =>
|
|
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:
|
|
38
|
+
documentSettings: x(i)
|
|
38
39
|
})
|
|
39
40
|
}),
|
|
40
41
|
async onToolCall({ toolCall: r }) {
|
|
41
|
-
r.dynamic || r.toolName ===
|
|
42
|
-
documentSettings:
|
|
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
|
|
53
|
+
function It({
|
|
53
54
|
initialRegistryDocuments: s,
|
|
54
55
|
registryUrl: i,
|
|
55
|
-
dashboardUrl:
|
|
56
|
+
dashboardUrl: v,
|
|
56
57
|
baseUrl: a,
|
|
57
58
|
mode: T,
|
|
58
|
-
isLoggedIn:
|
|
59
|
+
isLoggedIn: E,
|
|
59
60
|
getAccessToken: m,
|
|
60
61
|
getAgentKey: r,
|
|
61
|
-
getActiveDocumentJson:
|
|
62
|
-
prefilledMessageRef:
|
|
63
|
-
hideAddApi:
|
|
62
|
+
getActiveDocumentJson: O,
|
|
63
|
+
prefilledMessageRef: w,
|
|
64
|
+
hideAddApi: G
|
|
64
65
|
}) {
|
|
65
|
-
const
|
|
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
|
-
|
|
68
|
+
it({
|
|
68
69
|
persistAuth: !0
|
|
69
70
|
})
|
|
70
71
|
]
|
|
71
|
-
}),
|
|
72
|
-
() =>
|
|
73
|
-
proxyUrl:
|
|
72
|
+
}), S = $(
|
|
73
|
+
() => z.parse({
|
|
74
|
+
proxyUrl: d.value,
|
|
74
75
|
persistAuth: !0
|
|
75
76
|
})
|
|
76
|
-
), c =
|
|
77
|
+
), c = dt({
|
|
77
78
|
registryDocuments: n,
|
|
78
|
-
workspaceStore:
|
|
79
|
+
workspaceStore: p,
|
|
79
80
|
baseUrl: a,
|
|
80
|
-
proxyUrl:
|
|
81
|
+
proxyUrl: d,
|
|
81
82
|
getAccessToken: m,
|
|
82
83
|
getAgentKey: r
|
|
83
|
-
}),
|
|
84
|
+
}), _ = et({
|
|
84
85
|
baseUrl: a,
|
|
85
|
-
proxyUrl:
|
|
86
|
+
proxyUrl: d,
|
|
86
87
|
getAccessToken: m,
|
|
87
88
|
getAgentKey: r
|
|
88
|
-
}),
|
|
89
|
+
}), W = $(
|
|
89
90
|
() => c.status === "submitted" || c.status === "streaming" && !c.lastMessage?.parts.some((t) => t.type === "text")
|
|
90
91
|
);
|
|
91
|
-
|
|
92
|
+
C(
|
|
92
93
|
() => c.status,
|
|
93
94
|
() => {
|
|
94
|
-
c.status === "streaming" && (
|
|
95
|
+
c.status === "streaming" && (D.value = "");
|
|
95
96
|
}
|
|
96
|
-
),
|
|
97
|
-
t && (
|
|
97
|
+
), w && C(w, async (t) => {
|
|
98
|
+
t && (D.value = t, g.accepted.value && await c.sendMessage({ text: D.value }));
|
|
98
99
|
});
|
|
99
|
-
const
|
|
100
|
-
async function
|
|
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((
|
|
107
|
+
if (n.value.find((R) => R.namespace === t && R.slug === o))
|
|
106
108
|
return;
|
|
107
|
-
const
|
|
108
|
-
f[
|
|
109
|
-
const
|
|
109
|
+
const l = `@${t}/${o}`;
|
|
110
|
+
f[l] = !0;
|
|
111
|
+
const e = await I({
|
|
110
112
|
namespace: t,
|
|
111
113
|
slug: o,
|
|
112
|
-
workspaceStore:
|
|
114
|
+
workspaceStore: p,
|
|
113
115
|
registryUrl: i,
|
|
114
116
|
registryDocuments: n,
|
|
115
|
-
config:
|
|
116
|
-
api:
|
|
117
|
+
config: S.value,
|
|
118
|
+
api: _,
|
|
117
119
|
removable: u
|
|
118
120
|
});
|
|
119
|
-
if (f[
|
|
120
|
-
throw console.warn("[AGENT]: Unable to load document",
|
|
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
|
|
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
|
|
130
|
-
f[
|
|
131
|
-
const
|
|
132
|
-
() => fetch(
|
|
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) =>
|
|
137
|
+
(e) => ut("FAILED_TO_GET_EMBEDDING_STATUS", e)
|
|
136
138
|
);
|
|
137
|
-
if (
|
|
138
|
-
const e = await
|
|
139
|
+
if (l.success && l.data.ok) {
|
|
140
|
+
const e = await I({
|
|
139
141
|
namespace: t,
|
|
140
142
|
slug: o,
|
|
141
|
-
workspaceStore:
|
|
143
|
+
workspaceStore: p,
|
|
142
144
|
registryUrl: i,
|
|
143
145
|
registryDocuments: n,
|
|
144
|
-
config:
|
|
145
|
-
api:
|
|
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[
|
|
153
|
+
f[A] = !1;
|
|
152
154
|
}
|
|
153
|
-
function
|
|
155
|
+
function j({ namespace: t, slug: o }) {
|
|
154
156
|
n.value = n.value.filter(
|
|
155
157
|
(u) => !(u.namespace === t && u.slug === o)
|
|
156
|
-
),
|
|
158
|
+
), p.deleteDocument(mt(t, o));
|
|
157
159
|
}
|
|
158
|
-
return s.forEach(({ namespace: t, slug: o }) =>
|
|
159
|
-
prompt:
|
|
160
|
+
return s.forEach(({ namespace: t, slug: o }) => L({ namespace: t, slug: o, removable: !1 })), {
|
|
161
|
+
prompt: D,
|
|
160
162
|
chat: c,
|
|
161
|
-
workspaceStore:
|
|
162
|
-
eventBus:
|
|
163
|
-
loading:
|
|
164
|
-
settingsModal:
|
|
165
|
-
config:
|
|
163
|
+
workspaceStore: p,
|
|
164
|
+
eventBus: P,
|
|
165
|
+
loading: W,
|
|
166
|
+
settingsModal: Y,
|
|
167
|
+
config: S,
|
|
166
168
|
registryUrl: i,
|
|
167
|
-
dashboardUrl:
|
|
169
|
+
dashboardUrl: v,
|
|
168
170
|
baseUrl: a,
|
|
169
171
|
registryDocuments: n,
|
|
170
172
|
pendingDocuments: f,
|
|
171
|
-
proxyUrl:
|
|
173
|
+
proxyUrl: d,
|
|
172
174
|
proxyUrlRaw: U,
|
|
173
175
|
mode: T,
|
|
174
|
-
terms:
|
|
175
|
-
isLoggedIn:
|
|
176
|
-
addDocument:
|
|
177
|
-
addDocumentAsync:
|
|
178
|
-
removeDocument:
|
|
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:
|
|
182
|
-
uploadedTmpDocumentUrl:
|
|
183
|
-
curatedDocuments:
|
|
184
|
-
getActiveDocumentJson:
|
|
185
|
-
hideAddApi:
|
|
183
|
+
api: _,
|
|
184
|
+
uploadedTmpDocumentUrl: F,
|
|
185
|
+
curatedDocuments: B,
|
|
186
|
+
getActiveDocumentJson: O,
|
|
187
|
+
hideAddApi: G
|
|
186
188
|
};
|
|
187
189
|
}
|
|
188
|
-
function
|
|
189
|
-
const s =
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
ft as STATE_SYMBOL,
|
|
198
|
+
It as createState,
|
|
199
|
+
Mt as useState
|
|
198
200
|
};
|