@blocknote/xl-ai 0.44.1 → 0.44.2
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 +1 -1
- package/dist/blocknote-xl-ai.cjs.map +1 -1
- package/dist/blocknote-xl-ai.js +370 -369
- package/dist/blocknote-xl-ai.js.map +1 -1
- package/dist/{client-C4uaJa77.js → client-ChPl2nQr.js} +42 -24
- package/dist/client-ChPl2nQr.js.map +1 -0
- package/dist/client-wMB2zJXh.cjs +36 -0
- package/dist/client-wMB2zJXh.cjs.map +1 -0
- package/dist/server.cjs +1 -1
- package/dist/server.js +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +5 -5
- package/src/AIExtension.ts +6 -2
- package/src/prosemirror/rebaseTool.ts +1 -1
- package/src/streamTool/filterValidOperations.ts +1 -0
- package/src/streamTool/preprocess.test.ts +32 -66
- package/src/streamTool/preprocess.ts +8 -38
- package/src/streamTool/toValidatedOperations.ts +12 -0
- package/src/streamTool/vercelAiSdk/util/chatHandlers.ts +2 -0
- package/src/testUtil/suggestChangesTestUtil.ts +1 -1
- package/types/src/streamTool/preprocess.d.ts +0 -13
- package/dist/client-C4uaJa77.js.map +0 -1
- package/dist/client-DrruPiJu.cjs +0 -36
- package/dist/client-DrruPiJu.cjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var ke = Object.defineProperty;
|
|
2
2
|
var we = (t, e, o) => e in t ? ke(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
|
|
3
|
-
var
|
|
4
|
-
import { jsonSchema as N, parsePartialJson as ue, asSchema as Z, tool as ge, generateObject as Te, convertToModelMessages as
|
|
5
|
-
import { getErrorMessage as
|
|
3
|
+
var L = (t, e, o) => we(t, typeof e != "symbol" ? e + "" : e, o);
|
|
4
|
+
import { jsonSchema as N, parsePartialJson as ue, asSchema as Z, tool as ge, generateObject as Te, convertToModelMessages as U, streamObject as ve, streamText as Pe, isToolUIPart as Oe } from "ai";
|
|
5
|
+
import { getErrorMessage as $ } from "@ai-sdk/provider-utils";
|
|
6
6
|
import G from "lodash.merge";
|
|
7
7
|
import Ee from "lodash.isequal";
|
|
8
8
|
import { getPmSchema as xe, UnreachableCaseError as Be, getNodeById as Ce, updateBlockTr as Ie, insertBlocks as Ne, trackPosition as K, removeAndInsertBlocks as Me, getBlock as de, defaultProps as pe, isStyledTextInlineContent as _e, isLinkInlineContent as Ae } from "@blocknote/core";
|
|
@@ -10,11 +10,11 @@ import { Slice as je } from "prosemirror-model";
|
|
|
10
10
|
import { TextSelection as $e } from "prosemirror-state";
|
|
11
11
|
import { Transform as E, Mapping as fe, ReplaceStep as v, ReplaceAroundStep as De } from "prosemirror-transform";
|
|
12
12
|
import { ChangeSet as Q, simplifyChanges as Le } from "prosemirror-changeset";
|
|
13
|
-
import { applySuggestions as
|
|
13
|
+
import { applySuggestions as Ue } from "@handlewithcare/prosemirror-suggest-changes";
|
|
14
14
|
function J(t) {
|
|
15
15
|
return (t.type === "paragraph" || !t.type) && !t.content || Array.isArray(t.content) && t.content.length === 0;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function qe(t, e, o = !0, r = !0) {
|
|
18
18
|
let n = 0, a = t.length;
|
|
19
19
|
if (o)
|
|
20
20
|
for (; n < a && e(t[n]); )
|
|
@@ -25,14 +25,14 @@ function Ue(t, e, o = !0, r = !0) {
|
|
|
25
25
|
return t.slice(n, a);
|
|
26
26
|
}
|
|
27
27
|
function P(t, e) {
|
|
28
|
-
return
|
|
28
|
+
return qe(
|
|
29
29
|
t,
|
|
30
30
|
(r) => J(r) && (e == null ? void 0 : e.cursorBlockId) !== r.id,
|
|
31
31
|
(e == null ? void 0 : e.trimStart) ?? !1,
|
|
32
32
|
(e == null ? void 0 : e.trimEnd) ?? !0
|
|
33
33
|
);
|
|
34
34
|
}
|
|
35
|
-
async function
|
|
35
|
+
async function qt(t) {
|
|
36
36
|
const {
|
|
37
37
|
useSelection: e,
|
|
38
38
|
deleteEmptyCursorBlock: o,
|
|
@@ -121,7 +121,7 @@ function ze(t) {
|
|
|
121
121
|
class R extends Error {
|
|
122
122
|
constructor(o, r, n) {
|
|
123
123
|
super(o, n);
|
|
124
|
-
|
|
124
|
+
L(this, "aborted");
|
|
125
125
|
this.chunk = r, this.name = "ChunkExecutionError", this.aborted = (n == null ? void 0 : n.aborted) ?? !1;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -131,7 +131,7 @@ class He {
|
|
|
131
131
|
* @param abortSignal - Optional AbortSignal to cancel ongoing operations
|
|
132
132
|
*/
|
|
133
133
|
constructor(e, o) {
|
|
134
|
-
|
|
134
|
+
L(this, "stream");
|
|
135
135
|
this.streamTools = e, this.abortSignal = o, this.stream = this.createStream();
|
|
136
136
|
}
|
|
137
137
|
createStream() {
|
|
@@ -171,7 +171,7 @@ class He {
|
|
|
171
171
|
} catch (c) {
|
|
172
172
|
r.error(
|
|
173
173
|
new R(
|
|
174
|
-
`Tool execution failed: ${
|
|
174
|
+
`Tool execution failed: ${$(c)}`,
|
|
175
175
|
o,
|
|
176
176
|
{
|
|
177
177
|
cause: c,
|
|
@@ -360,7 +360,7 @@ function We(t, e) {
|
|
|
360
360
|
case "error":
|
|
361
361
|
n.enqueue({
|
|
362
362
|
type: "error",
|
|
363
|
-
errorText:
|
|
363
|
+
errorText: $(r.error)
|
|
364
364
|
});
|
|
365
365
|
break;
|
|
366
366
|
default: {
|
|
@@ -461,7 +461,7 @@ class Jt {
|
|
|
461
461
|
model: r,
|
|
462
462
|
mode: "tool",
|
|
463
463
|
system: this.opts.systemPrompt,
|
|
464
|
-
messages:
|
|
464
|
+
messages: U(q(e)),
|
|
465
465
|
...ee(r),
|
|
466
466
|
...n ?? {}
|
|
467
467
|
});
|
|
@@ -482,7 +482,7 @@ class Jt {
|
|
|
482
482
|
model: r,
|
|
483
483
|
mode: "tool",
|
|
484
484
|
system: this.opts.systemPrompt,
|
|
485
|
-
messages:
|
|
485
|
+
messages: U(q(e)),
|
|
486
486
|
...ee(r),
|
|
487
487
|
...n ?? {}
|
|
488
488
|
});
|
|
@@ -501,7 +501,7 @@ class Jt {
|
|
|
501
501
|
return Pe({
|
|
502
502
|
model: r,
|
|
503
503
|
system: this.opts.systemPrompt,
|
|
504
|
-
messages:
|
|
504
|
+
messages: U(q(e)),
|
|
505
505
|
tools: o,
|
|
506
506
|
toolChoice: "required",
|
|
507
507
|
// extra options for streamObject
|
|
@@ -641,6 +641,18 @@ async function* tt(t, e) {
|
|
|
641
641
|
}
|
|
642
642
|
async function* ot(t, e) {
|
|
643
643
|
for await (const o of t) {
|
|
644
|
+
if (!o.partialOperation.type) {
|
|
645
|
+
yield {
|
|
646
|
+
operation: {
|
|
647
|
+
ok: !1,
|
|
648
|
+
error: "The `type` property of an operation is required."
|
|
649
|
+
},
|
|
650
|
+
isUpdateToPreviousOperation: o.isUpdateToPreviousOperation,
|
|
651
|
+
isPossiblyPartial: o.isPossiblyPartial,
|
|
652
|
+
metadata: o.metadata
|
|
653
|
+
};
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
644
656
|
const r = e.find(
|
|
645
657
|
(a) => a.name === o.partialOperation.type
|
|
646
658
|
);
|
|
@@ -673,7 +685,13 @@ async function* rt(t, e) {
|
|
|
673
685
|
o,
|
|
674
686
|
(n) => {
|
|
675
687
|
if (!n.isPossiblyPartial)
|
|
676
|
-
throw new R(
|
|
688
|
+
throw new R(
|
|
689
|
+
`Invalid operation. ${$(n.operation.error)}`,
|
|
690
|
+
n,
|
|
691
|
+
{
|
|
692
|
+
cause: n.operation.error
|
|
693
|
+
}
|
|
694
|
+
);
|
|
677
695
|
}
|
|
678
696
|
);
|
|
679
697
|
}
|
|
@@ -740,7 +758,7 @@ async function st(t, e, o, r) {
|
|
|
740
758
|
toolCallId: m[y].toolCallId,
|
|
741
759
|
state: "output-error",
|
|
742
760
|
errorText: JSON.stringify(
|
|
743
|
-
h ? { status: "error", error:
|
|
761
|
+
h ? { status: "error", error: $(p) } : { status: "not-executed-previous-tool-errored" }
|
|
744
762
|
)
|
|
745
763
|
}) : e.addToolOutput({
|
|
746
764
|
state: "output-available",
|
|
@@ -1107,7 +1125,7 @@ const te = (t, e) => {
|
|
|
1107
1125
|
compareTokens: (i, s) => i === s
|
|
1108
1126
|
};
|
|
1109
1127
|
};
|
|
1110
|
-
function
|
|
1128
|
+
function D(t, e, o = !1, r, n) {
|
|
1111
1129
|
const a = Ce(t.id, e), i = new E(e);
|
|
1112
1130
|
Ie(
|
|
1113
1131
|
i,
|
|
@@ -1299,7 +1317,7 @@ function V(t) {
|
|
|
1299
1317
|
const f = d.blocks[l], p = e.prosemirrorState.tr;
|
|
1300
1318
|
let b = [];
|
|
1301
1319
|
if (l < n.length) {
|
|
1302
|
-
const m = await t.rebaseTool(n[l], e), y =
|
|
1320
|
+
const m = await t.rebaseTool(n[l], e), y = D(
|
|
1303
1321
|
{
|
|
1304
1322
|
id: n[l],
|
|
1305
1323
|
block: f
|
|
@@ -1422,7 +1440,7 @@ function Y(t) {
|
|
|
1422
1440
|
});
|
|
1423
1441
|
if (!p)
|
|
1424
1442
|
return !0;
|
|
1425
|
-
const b =
|
|
1443
|
+
const b = D(
|
|
1426
1444
|
p,
|
|
1427
1445
|
u.doc,
|
|
1428
1446
|
s.isPossiblyPartial,
|
|
@@ -1529,7 +1547,7 @@ function oe(t) {
|
|
|
1529
1547
|
}
|
|
1530
1548
|
function A(t) {
|
|
1531
1549
|
let e;
|
|
1532
|
-
if (
|
|
1550
|
+
if (Ue(t.prosemirrorState, (o) => {
|
|
1533
1551
|
e = o;
|
|
1534
1552
|
}), !e)
|
|
1535
1553
|
throw new Error("applySuggestionsTr is not set");
|
|
@@ -1581,7 +1599,7 @@ async function re(t, e) {
|
|
|
1581
1599
|
if (window.__TEST_OPTIONS && (window.__TEST_OPTIONS.mockID = a), i.length !== 1)
|
|
1582
1600
|
throw new Error("html diff invalid block count");
|
|
1583
1601
|
const s = i[0];
|
|
1584
|
-
if (s.id = t,
|
|
1602
|
+
if (s.id = t, D(
|
|
1585
1603
|
{
|
|
1586
1604
|
id: t,
|
|
1587
1605
|
block: s
|
|
@@ -2048,7 +2066,7 @@ IF there is no selection active in the latest state, first, determine what part
|
|
|
2048
2066
|
)
|
|
2049
2067
|
};
|
|
2050
2068
|
async function ie(t, e) {
|
|
2051
|
-
const o = A(e), r = await e.blocksToMarkdownLossy([de(o.doc, t)]), n = await e.tryParseMarkdownToBlocks(r), a =
|
|
2069
|
+
const o = A(e), r = await e.blocksToMarkdownLossy([de(o.doc, t)]), n = await e.tryParseMarkdownToBlocks(r), a = D(
|
|
2052
2070
|
{
|
|
2053
2071
|
id: t,
|
|
2054
2072
|
block: n[0]
|
|
@@ -2207,7 +2225,7 @@ export {
|
|
|
2207
2225
|
Ze as P,
|
|
2208
2226
|
He as S,
|
|
2209
2227
|
le as a,
|
|
2210
|
-
|
|
2228
|
+
qt as b,
|
|
2211
2229
|
Ht as c,
|
|
2212
2230
|
Re as d,
|
|
2213
2231
|
ze as e,
|
|
@@ -2225,4 +2243,4 @@ export {
|
|
|
2225
2243
|
Rt as s,
|
|
2226
2244
|
Ye as t
|
|
2227
2245
|
};
|
|
2228
|
-
//# sourceMappingURL=client-
|
|
2246
|
+
//# sourceMappingURL=client-ChPl2nQr.js.map
|