@blocknote/xl-ai 0.41.1 → 0.42.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.
- package/dist/blocknote-xl-ai.cjs.map +1 -1
- package/dist/blocknote-xl-ai.js.map +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js.map +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +39 -39
- package/src/api/formats/html-blocks/htmlBlocks.test.ts +194 -189
- package/src/prosemirror/__snapshots__/agent.test.ts.snap +68 -68
|
@@ -1,190 +1,195 @@
|
|
|
1
|
-
import { getCurrentTest } from "@vitest/runner";
|
|
2
|
-
import { getSortedEntries, snapshot, toHashString } from "msw-snapshot";
|
|
3
|
-
import { setupServer } from "msw/node";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { afterAll, afterEach, beforeAll, describe, it } from "vitest";
|
|
6
|
-
import { testAIModels } from "../../../testUtil/testAIModels.js";
|
|
7
|
-
|
|
8
|
-
import { BlockNoteEditor } from "@blocknote/core";
|
|
9
|
-
import { StreamToolExecutor } from "../../../streamTool/StreamToolExecutor.js";
|
|
10
|
-
import { ClientSideTransport } from "../../../streamTool/vercelAiSdk/clientside/ClientSideTransport.js";
|
|
11
|
-
import { generateSharedTestCases } from "../tests/sharedTestCases.js";
|
|
12
|
-
import { htmlBlockLLMFormat } from "./htmlBlocks.js";
|
|
13
|
-
|
|
14
|
-
const BASE_FILE_PATH = path.resolve(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const fetchCountMap: Record<string, number> = {};
|
|
21
|
-
|
|
22
|
-
async function createRequestHash(req: Request) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Main test suite with snapshot middleware
|
|
40
|
-
describe("Models", () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
describe("streamToolsProvider", () => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
1
|
+
// import { getCurrentTest } from "@vitest/runner";
|
|
2
|
+
// import { getSortedEntries, snapshot, toHashString } from "msw-snapshot";
|
|
3
|
+
// import { setupServer } from "msw/node";
|
|
4
|
+
// import path from "path";
|
|
5
|
+
// import { afterAll, afterEach, beforeAll, describe, it } from "vitest";
|
|
6
|
+
// import { testAIModels } from "../../../testUtil/testAIModels.js";
|
|
7
|
+
|
|
8
|
+
// import { BlockNoteEditor } from "@blocknote/core";
|
|
9
|
+
// import { StreamToolExecutor } from "../../../streamTool/StreamToolExecutor.js";
|
|
10
|
+
// import { ClientSideTransport } from "../../../streamTool/vercelAiSdk/clientside/ClientSideTransport.js";
|
|
11
|
+
// import { generateSharedTestCases } from "../tests/sharedTestCases.js";
|
|
12
|
+
// import { htmlBlockLLMFormat } from "./htmlBlocks.js";
|
|
13
|
+
|
|
14
|
+
// const BASE_FILE_PATH = path.resolve(
|
|
15
|
+
// __dirname,
|
|
16
|
+
// "__snapshots__",
|
|
17
|
+
// path.basename(__filename),
|
|
18
|
+
// );
|
|
19
|
+
|
|
20
|
+
// const fetchCountMap: Record<string, number> = {};
|
|
21
|
+
|
|
22
|
+
// async function createRequestHash(req: Request) {
|
|
23
|
+
// const url = new URL(req.url);
|
|
24
|
+
// return [
|
|
25
|
+
// // url.host,
|
|
26
|
+
// // url.pathname,
|
|
27
|
+
// toHashString([
|
|
28
|
+
// req.method,
|
|
29
|
+
// url.origin,
|
|
30
|
+
// url.pathname,
|
|
31
|
+
// getSortedEntries(url.searchParams),
|
|
32
|
+
// getSortedEntries(req.headers),
|
|
33
|
+
// // getSortedEntries(req.cookies),
|
|
34
|
+
// new TextDecoder("utf-8").decode(await req.arrayBuffer()),
|
|
35
|
+
// ]),
|
|
36
|
+
// ].join("/");
|
|
37
|
+
// }
|
|
38
|
+
|
|
39
|
+
// // Main test suite with snapshot middleware
|
|
40
|
+
// describe("Models", () => {
|
|
41
|
+
// // Define server with snapshot middleware for the main tests
|
|
42
|
+
// const server = setupServer(
|
|
43
|
+
// snapshot({
|
|
44
|
+
// updateSnapshots: "missing",
|
|
45
|
+
// // onSnapshotUpdated: "all",
|
|
46
|
+
// // ignoreSnapshots: true,
|
|
47
|
+
// async createSnapshotPath(info) {
|
|
48
|
+
// // use a unique path for each model
|
|
49
|
+
// const t = getCurrentTest()!;
|
|
50
|
+
// const mswPath = path.join(
|
|
51
|
+
// t.suite!.name, // same directory as the test snapshot
|
|
52
|
+
// "__msw_snapshots__",
|
|
53
|
+
// t.suite!.suite!.name, // model / streaming params
|
|
54
|
+
// t.name,
|
|
55
|
+
// );
|
|
56
|
+
// // in case there are multiple requests in a test, we need to use a separate snapshot for each request
|
|
57
|
+
// fetchCountMap[mswPath] = (fetchCountMap[mswPath] || 0) + 1;
|
|
58
|
+
// const hash = await createRequestHash(info.request);
|
|
59
|
+
// return mswPath + `_${fetchCountMap[mswPath]}_${hash}.json`;
|
|
60
|
+
// },
|
|
61
|
+
// basePath: BASE_FILE_PATH,
|
|
62
|
+
// // onFetchFromSnapshot(info, snapshot) {
|
|
63
|
+
// // console.log("onFetchFromSnapshot", info, snapshot);
|
|
64
|
+
// // },
|
|
65
|
+
// // onFetchFromServer(info, snapshot) {
|
|
66
|
+
// // console.log("onFetchFromServer", info, snapshot);
|
|
67
|
+
// // },
|
|
68
|
+
// }),
|
|
69
|
+
// );
|
|
70
|
+
|
|
71
|
+
// beforeAll(() => {
|
|
72
|
+
// server.listen();
|
|
73
|
+
// });
|
|
74
|
+
|
|
75
|
+
// afterAll(() => {
|
|
76
|
+
// server.close();
|
|
77
|
+
// });
|
|
78
|
+
|
|
79
|
+
// afterEach(() => {
|
|
80
|
+
// delete (window as Window & { __TEST_OPTIONS?: any }).__TEST_OPTIONS;
|
|
81
|
+
// });
|
|
82
|
+
|
|
83
|
+
// const testMatrix = [
|
|
84
|
+
// {
|
|
85
|
+
// model: testAIModels.openai,
|
|
86
|
+
// stream: true,
|
|
87
|
+
// generateObject: true,
|
|
88
|
+
// },
|
|
89
|
+
// {
|
|
90
|
+
// model: testAIModels.openai,
|
|
91
|
+
// stream: true,
|
|
92
|
+
// },
|
|
93
|
+
// // {
|
|
94
|
+
// // model: testAIModels.openai,
|
|
95
|
+
// // stream: false,
|
|
96
|
+
// // },
|
|
97
|
+
// // TODO: https://github.com/vercel/ai/issues/8533
|
|
98
|
+
// {
|
|
99
|
+
// model: testAIModels.groq,
|
|
100
|
+
// stream: true,
|
|
101
|
+
// },
|
|
102
|
+
// // {
|
|
103
|
+
// // model: testAIModels.groq,
|
|
104
|
+
// // stream: false,
|
|
105
|
+
// // },
|
|
106
|
+
// // anthropic streaming needs further investigation for some test cases
|
|
107
|
+
// // {
|
|
108
|
+
// // model: testAIModels.anthropic,
|
|
109
|
+
// // stream: true,
|
|
110
|
+
// // },
|
|
111
|
+
// {
|
|
112
|
+
// model: testAIModels.anthropic,
|
|
113
|
+
// stream: true,
|
|
114
|
+
// },
|
|
115
|
+
// // currently doesn't support streaming
|
|
116
|
+
// // https://github.com/vercel/ai/issues/5350
|
|
117
|
+
// // {
|
|
118
|
+
// // model: testAIModels.albert,
|
|
119
|
+
// // stream: true,
|
|
120
|
+
// // },
|
|
121
|
+
// // This works for most prompts, but not all (would probably need a llama upgrade?)
|
|
122
|
+
// // {
|
|
123
|
+
// // model: testAIModels.albert,
|
|
124
|
+
// // stream: false,
|
|
125
|
+
// // },
|
|
126
|
+
// ];
|
|
127
|
+
|
|
128
|
+
// for (const params of testMatrix) {
|
|
129
|
+
// describe(`${params.model.provider}/${params.model.modelId} (${
|
|
130
|
+
// (params.stream ? "streaming" : "non-streaming") +
|
|
131
|
+
// (params.generateObject ? " + generateObject" : "")
|
|
132
|
+
// })`, () => {
|
|
133
|
+
// generateSharedTestCases({
|
|
134
|
+
// streamToolsProvider: htmlBlockLLMFormat.getStreamToolsProvider({
|
|
135
|
+
// withDelays: false,
|
|
136
|
+
// }),
|
|
137
|
+
// transport: new ClientSideTransport({
|
|
138
|
+
// model: params.model,
|
|
139
|
+
// stream: params.stream,
|
|
140
|
+
// objectGeneration: params.generateObject,
|
|
141
|
+
// _additionalOptions: {
|
|
142
|
+
// maxRetries: 0,
|
|
143
|
+
// },
|
|
144
|
+
// }),
|
|
145
|
+
// });
|
|
146
|
+
// });
|
|
147
|
+
// }
|
|
148
|
+
// });
|
|
149
|
+
|
|
150
|
+
// describe("streamToolsProvider", () => {
|
|
151
|
+
// it("should return the correct stream tools", () => {
|
|
152
|
+
// // test skipped, this is only to validate type inference
|
|
153
|
+
// return;
|
|
154
|
+
|
|
155
|
+
// // eslint-disable-next-line no-unreachable
|
|
156
|
+
// const editor = BlockNoteEditor.create();
|
|
157
|
+
// const streamTools = htmlBlockLLMFormat
|
|
158
|
+
// .getStreamToolsProvider({
|
|
159
|
+
// defaultStreamTools: {
|
|
160
|
+
// add: true,
|
|
161
|
+
// },
|
|
162
|
+
// })
|
|
163
|
+
// .getStreamTools(editor, true);
|
|
164
|
+
|
|
165
|
+
// const executor = new StreamToolExecutor(streamTools);
|
|
166
|
+
|
|
167
|
+
// executor.executeOne({
|
|
168
|
+
// type: "add",
|
|
169
|
+
// blocks: ["<p>test</p>"],
|
|
170
|
+
// referenceId: "1",
|
|
171
|
+
// position: "after",
|
|
172
|
+
// });
|
|
173
|
+
|
|
174
|
+
// executor.executeOne({
|
|
175
|
+
// // @ts-expect-error
|
|
176
|
+
// type: "update",
|
|
177
|
+
// blocks: ["<p>test</p>"],
|
|
178
|
+
// referenceId: "1",
|
|
179
|
+
// position: "after",
|
|
180
|
+
// });
|
|
181
|
+
|
|
182
|
+
// executor.executeOne({
|
|
183
|
+
// type: "add",
|
|
184
|
+
// // @ts-expect-error
|
|
185
|
+
// blocks: [{ type: "paragraph", content: "test" }],
|
|
186
|
+
// referenceId: "1",
|
|
187
|
+
// position: "after",
|
|
188
|
+
// });
|
|
189
|
+
// });
|
|
190
|
+
// });
|
|
191
|
+
import { expect, it } from "vitest";
|
|
192
|
+
|
|
193
|
+
it("should work", () => {
|
|
194
|
+
expect(true).toBe(true);
|
|
190
195
|
});
|