@puckeditor/plugin-ai 0.8.3-canary.c9f74a23 → 0.8.3-canary.ccfc525d
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/index.js +54 -1
- package/dist/index.mjs +54 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -4365,7 +4365,7 @@ var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
|
4365
4365
|
var q = (0, import_qler.default)();
|
|
4366
4366
|
var DEFAULT_API_VERSION = "v2";
|
|
4367
4367
|
var BUILD_OP_DEBOUNCE_MS = 1e3 / 60;
|
|
4368
|
-
var PLUGIN_AI_VERSION = true ? "0.8.3-canary.
|
|
4368
|
+
var PLUGIN_AI_VERSION = true ? "0.8.3-canary.ccfc525d" : "unknown";
|
|
4369
4369
|
var BENCHMARK = false;
|
|
4370
4370
|
var prefixedUlid = (prefix = "") => `${prefix ? `${prefix}_` : ""}${(0, import_ulid.ulid)()}`;
|
|
4371
4371
|
var getClassName18 = getClassNameFactory("Chat", styles_module_default);
|
|
@@ -4407,6 +4407,8 @@ function Chat2(props) {
|
|
|
4407
4407
|
const removedAttachmentClientIdsRef = (0, import_react27.useRef)(/* @__PURE__ */ new Set());
|
|
4408
4408
|
const uploadControllersRef = (0, import_react27.useRef)(/* @__PURE__ */ new Map());
|
|
4409
4409
|
const pendingBuildOpsRef = (0, import_react27.useRef)([]);
|
|
4410
|
+
const lastStreamActivityRef = (0, import_react27.useRef)(0);
|
|
4411
|
+
const hiddenSinceRef = (0, import_react27.useRef)(null);
|
|
4410
4412
|
const [toolStatus, setToolStatus] = (0, import_react27.useState)({});
|
|
4411
4413
|
const [subagentState, setSubagentState] = (0, import_react27.useState)({});
|
|
4412
4414
|
const attachmentConfig = (0, import_react27.useMemo)(
|
|
@@ -4519,6 +4521,7 @@ function Chat2(props) {
|
|
|
4519
4521
|
);
|
|
4520
4522
|
const processData = (0, import_react27.useCallback)(
|
|
4521
4523
|
(dataPart) => {
|
|
4524
|
+
lastStreamActivityRef.current = Date.now();
|
|
4522
4525
|
switch (dataPart.type) {
|
|
4523
4526
|
case "data-new-chat-created": {
|
|
4524
4527
|
localChatId.current = dataPart.data.chatId;
|
|
@@ -4745,6 +4748,56 @@ function Chat2(props) {
|
|
|
4745
4748
|
},
|
|
4746
4749
|
[stop]
|
|
4747
4750
|
);
|
|
4751
|
+
const statusRef = (0, import_react27.useRef)(status);
|
|
4752
|
+
(0, import_react27.useEffect)(() => {
|
|
4753
|
+
statusRef.current = status;
|
|
4754
|
+
}, [status]);
|
|
4755
|
+
(0, import_react27.useEffect)(() => {
|
|
4756
|
+
lastStreamActivityRef.current = Date.now();
|
|
4757
|
+
}, [messages]);
|
|
4758
|
+
(0, import_react27.useEffect)(() => {
|
|
4759
|
+
const FROZEN_HIDDEN_MS = 3 * 6e4;
|
|
4760
|
+
const RESUME_GRACE_MS = 12e3;
|
|
4761
|
+
const isStreaming = () => statusRef.current === "streaming" || statusRef.current === "submitted";
|
|
4762
|
+
let graceTimer;
|
|
4763
|
+
const recoverIfSevered = () => {
|
|
4764
|
+
if (!isStreaming()) return;
|
|
4765
|
+
if (Date.now() - lastStreamActivityRef.current < RESUME_GRACE_MS) return;
|
|
4766
|
+
stop();
|
|
4767
|
+
setToolStatus((current) => {
|
|
4768
|
+
let changed = false;
|
|
4769
|
+
const next = {};
|
|
4770
|
+
for (const [id, toolState] of Object.entries(current)) {
|
|
4771
|
+
if (toolState.loading) {
|
|
4772
|
+
changed = true;
|
|
4773
|
+
next[id] = { ...toolState, loading: false, label: "Interrupted" };
|
|
4774
|
+
} else {
|
|
4775
|
+
next[id] = toolState;
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4778
|
+
return changed ? next : current;
|
|
4779
|
+
});
|
|
4780
|
+
};
|
|
4781
|
+
const onVisibilityChange = () => {
|
|
4782
|
+
if (document.hidden) {
|
|
4783
|
+
hiddenSinceRef.current = isStreaming() ? Date.now() : null;
|
|
4784
|
+
return;
|
|
4785
|
+
}
|
|
4786
|
+
const hiddenSince = hiddenSinceRef.current;
|
|
4787
|
+
hiddenSinceRef.current = null;
|
|
4788
|
+
if (graceTimer) clearTimeout(graceTimer);
|
|
4789
|
+
if (hiddenSince === null || Date.now() - hiddenSince < FROZEN_HIDDEN_MS) {
|
|
4790
|
+
return;
|
|
4791
|
+
}
|
|
4792
|
+
lastStreamActivityRef.current = 0;
|
|
4793
|
+
graceTimer = setTimeout(recoverIfSevered, RESUME_GRACE_MS);
|
|
4794
|
+
};
|
|
4795
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
4796
|
+
return () => {
|
|
4797
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
4798
|
+
if (graceTimer) clearTimeout(graceTimer);
|
|
4799
|
+
};
|
|
4800
|
+
}, [stop]);
|
|
4748
4801
|
const [forcedStatus, setForcedStatus] = (0, import_react27.useState)();
|
|
4749
4802
|
const resolvedStatus = (0, import_react27.useMemo)(
|
|
4750
4803
|
() => forcedStatus ?? status,
|
package/dist/index.mjs
CHANGED
|
@@ -4397,7 +4397,7 @@ import { Fragment as Fragment9, jsx as jsx35, jsxs as jsxs20 } from "react/jsx-r
|
|
|
4397
4397
|
var q = qler();
|
|
4398
4398
|
var DEFAULT_API_VERSION = "v2";
|
|
4399
4399
|
var BUILD_OP_DEBOUNCE_MS = 1e3 / 60;
|
|
4400
|
-
var PLUGIN_AI_VERSION = true ? "0.8.3-canary.
|
|
4400
|
+
var PLUGIN_AI_VERSION = true ? "0.8.3-canary.ccfc525d" : "unknown";
|
|
4401
4401
|
var BENCHMARK = false;
|
|
4402
4402
|
var prefixedUlid = (prefix = "") => `${prefix ? `${prefix}_` : ""}${ulid()}`;
|
|
4403
4403
|
var getClassName18 = getClassNameFactory("Chat", styles_module_default);
|
|
@@ -4439,6 +4439,8 @@ function Chat2(props) {
|
|
|
4439
4439
|
const removedAttachmentClientIdsRef = useRef13(/* @__PURE__ */ new Set());
|
|
4440
4440
|
const uploadControllersRef = useRef13(/* @__PURE__ */ new Map());
|
|
4441
4441
|
const pendingBuildOpsRef = useRef13([]);
|
|
4442
|
+
const lastStreamActivityRef = useRef13(0);
|
|
4443
|
+
const hiddenSinceRef = useRef13(null);
|
|
4442
4444
|
const [toolStatus, setToolStatus] = useState16({});
|
|
4443
4445
|
const [subagentState, setSubagentState] = useState16({});
|
|
4444
4446
|
const attachmentConfig = useMemo6(
|
|
@@ -4551,6 +4553,7 @@ function Chat2(props) {
|
|
|
4551
4553
|
);
|
|
4552
4554
|
const processData = useCallback6(
|
|
4553
4555
|
(dataPart) => {
|
|
4556
|
+
lastStreamActivityRef.current = Date.now();
|
|
4554
4557
|
switch (dataPart.type) {
|
|
4555
4558
|
case "data-new-chat-created": {
|
|
4556
4559
|
localChatId.current = dataPart.data.chatId;
|
|
@@ -4777,6 +4780,56 @@ function Chat2(props) {
|
|
|
4777
4780
|
},
|
|
4778
4781
|
[stop]
|
|
4779
4782
|
);
|
|
4783
|
+
const statusRef = useRef13(status);
|
|
4784
|
+
useEffect13(() => {
|
|
4785
|
+
statusRef.current = status;
|
|
4786
|
+
}, [status]);
|
|
4787
|
+
useEffect13(() => {
|
|
4788
|
+
lastStreamActivityRef.current = Date.now();
|
|
4789
|
+
}, [messages]);
|
|
4790
|
+
useEffect13(() => {
|
|
4791
|
+
const FROZEN_HIDDEN_MS = 3 * 6e4;
|
|
4792
|
+
const RESUME_GRACE_MS = 12e3;
|
|
4793
|
+
const isStreaming = () => statusRef.current === "streaming" || statusRef.current === "submitted";
|
|
4794
|
+
let graceTimer;
|
|
4795
|
+
const recoverIfSevered = () => {
|
|
4796
|
+
if (!isStreaming()) return;
|
|
4797
|
+
if (Date.now() - lastStreamActivityRef.current < RESUME_GRACE_MS) return;
|
|
4798
|
+
stop();
|
|
4799
|
+
setToolStatus((current) => {
|
|
4800
|
+
let changed = false;
|
|
4801
|
+
const next = {};
|
|
4802
|
+
for (const [id, toolState] of Object.entries(current)) {
|
|
4803
|
+
if (toolState.loading) {
|
|
4804
|
+
changed = true;
|
|
4805
|
+
next[id] = { ...toolState, loading: false, label: "Interrupted" };
|
|
4806
|
+
} else {
|
|
4807
|
+
next[id] = toolState;
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4810
|
+
return changed ? next : current;
|
|
4811
|
+
});
|
|
4812
|
+
};
|
|
4813
|
+
const onVisibilityChange = () => {
|
|
4814
|
+
if (document.hidden) {
|
|
4815
|
+
hiddenSinceRef.current = isStreaming() ? Date.now() : null;
|
|
4816
|
+
return;
|
|
4817
|
+
}
|
|
4818
|
+
const hiddenSince = hiddenSinceRef.current;
|
|
4819
|
+
hiddenSinceRef.current = null;
|
|
4820
|
+
if (graceTimer) clearTimeout(graceTimer);
|
|
4821
|
+
if (hiddenSince === null || Date.now() - hiddenSince < FROZEN_HIDDEN_MS) {
|
|
4822
|
+
return;
|
|
4823
|
+
}
|
|
4824
|
+
lastStreamActivityRef.current = 0;
|
|
4825
|
+
graceTimer = setTimeout(recoverIfSevered, RESUME_GRACE_MS);
|
|
4826
|
+
};
|
|
4827
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
4828
|
+
return () => {
|
|
4829
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
4830
|
+
if (graceTimer) clearTimeout(graceTimer);
|
|
4831
|
+
};
|
|
4832
|
+
}, [stop]);
|
|
4780
4833
|
const [forcedStatus, setForcedStatus] = useState16();
|
|
4781
4834
|
const resolvedStatus = useMemo6(
|
|
4782
4835
|
() => forcedStatus ?? status,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@puckeditor/plugin-ai",
|
|
3
|
-
"version": "0.8.3-canary.
|
|
3
|
+
"version": "0.8.3-canary.ccfc525d",
|
|
4
4
|
"author": "Chris Villa <chris@puckeditor.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"tsup": "^8.2.4",
|
|
53
53
|
"typescript": "^5.5.4",
|
|
54
54
|
"vitest": "^4.1.0",
|
|
55
|
-
"@puckeditor/ai-types": "0.8.3-canary.
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
55
|
+
"@puckeditor/ai-types": "0.8.3-canary.ccfc525d",
|
|
56
|
+
"@puckeditor/platform-types": "0.8.3-canary.ccfc525d",
|
|
57
|
+
"reducer": "0.8.3-canary.ccfc525d",
|
|
58
|
+
"tsconfig": "0.8.3-canary.ccfc525d",
|
|
59
|
+
"tsup-config": "0.8.3-canary.ccfc525d",
|
|
60
|
+
"eslint-config-custom": "0.8.3-canary.ccfc525d"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@puckeditor/core": "^0",
|