@assistant-ui/core 0.3.2 → 0.3.3
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.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -6
- package/dist/internal.js +5 -5
- package/dist/react/primitive-hooks/useActionBarCopy.js +51 -24
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +2 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +24 -2
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +24 -5
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -1
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/internal.d.ts +4 -4
- package/dist/runtime/internal.js +4 -4
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +29 -23
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +101 -89
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/message.d.ts +11 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/getGroupStatus.d.ts +9 -0
- package/dist/utils/getGroupStatus.d.ts.map +1 -0
- package/dist/utils/getGroupStatus.js +15 -0
- package/dist/utils/getGroupStatus.js.map +1 -0
- package/dist/utils/normalizePartStatus.d.ts +8 -0
- package/dist/utils/normalizePartStatus.d.ts.map +1 -0
- package/dist/utils/normalizePartStatus.js +39 -0
- package/dist/utils/normalizePartStatus.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/internal.ts +1 -0
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +109 -14
- package/src/react/primitive-hooks/useActionBarCopy.ts +27 -2
- package/src/react/primitives/message/MessageGroupedParts.tsx +4 -4
- package/src/react/runtimes/cloud/auiV0.ts +51 -12
- package/src/runtime/api/message-runtime.test.ts +140 -0
- package/src/runtime/api/message-runtime.ts +10 -5
- package/src/store/clients/chain-of-thought-client.ts +2 -7
- package/src/store/clients/thread-message-client.test.ts +84 -0
- package/src/store/clients/thread-message-client.ts +14 -4
- package/src/tests/auiV0Encode.test.ts +93 -0
- package/src/types/index.ts +1 -0
- package/src/types/message.ts +19 -0
- package/src/utils/getGroupStatus.test.ts +36 -0
- package/src/utils/getGroupStatus.ts +31 -0
- package/src/utils/normalizePartStatus.test.ts +59 -0
- package/src/utils/normalizePartStatus.ts +55 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { ThreadAssistantMessagePart } from "../types/message";
|
|
3
|
+
import { normalizePartStatus } from "./normalizePartStatus";
|
|
4
|
+
|
|
5
|
+
const partWithStatus = (status: unknown): ThreadAssistantMessagePart =>
|
|
6
|
+
({
|
|
7
|
+
type: "text",
|
|
8
|
+
text: "text",
|
|
9
|
+
status,
|
|
10
|
+
}) as unknown as ThreadAssistantMessagePart;
|
|
11
|
+
|
|
12
|
+
describe("normalizePartStatus", () => {
|
|
13
|
+
it("returns a frozen running status", () => {
|
|
14
|
+
const status = normalizePartStatus(partWithStatus({ type: "running" }));
|
|
15
|
+
|
|
16
|
+
expect(status).toEqual({ type: "running" });
|
|
17
|
+
expect(status).toBe(
|
|
18
|
+
normalizePartStatus(partWithStatus({ type: "running" })),
|
|
19
|
+
);
|
|
20
|
+
expect(Object.isFrozen(status)).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("normalizes a complete status without a reason", () => {
|
|
24
|
+
expect(normalizePartStatus(partWithStatus({ type: "complete" }))).toEqual({
|
|
25
|
+
type: "complete",
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("drops an upstream complete reason", () => {
|
|
30
|
+
expect(
|
|
31
|
+
normalizePartStatus(
|
|
32
|
+
partWithStatus({ type: "complete", reason: "unknown" }),
|
|
33
|
+
),
|
|
34
|
+
).toEqual({ type: "complete" });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it.each(["cancelled", "length", "content-filter", "other", "error"] as const)(
|
|
38
|
+
"preserves the incomplete reason %s",
|
|
39
|
+
(reason) => {
|
|
40
|
+
expect(
|
|
41
|
+
normalizePartStatus(partWithStatus({ type: "incomplete", reason })),
|
|
42
|
+
).toEqual({ type: "incomplete", reason });
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
it("coerces an unrecognized incomplete reason to other", () => {
|
|
47
|
+
expect(
|
|
48
|
+
normalizePartStatus(
|
|
49
|
+
partWithStatus({ type: "incomplete", reason: "unknown" }),
|
|
50
|
+
),
|
|
51
|
+
).toEqual({ type: "incomplete", reason: "other" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("returns undefined for an unknown status type", () => {
|
|
55
|
+
expect(
|
|
56
|
+
normalizePartStatus(partWithStatus({ type: "unknown" })),
|
|
57
|
+
).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
MessagePartStatus,
|
|
3
|
+
MessagePartStreamStatus,
|
|
4
|
+
ThreadAssistantMessagePart,
|
|
5
|
+
ThreadUserMessagePart,
|
|
6
|
+
} from "../types/message";
|
|
7
|
+
|
|
8
|
+
export const COMPLETE_STATUS: MessagePartStatus = Object.freeze({
|
|
9
|
+
type: "complete",
|
|
10
|
+
});
|
|
11
|
+
export const RUNNING_STATUS: MessagePartStatus = Object.freeze({
|
|
12
|
+
type: "running",
|
|
13
|
+
});
|
|
14
|
+
type IncompleteMessagePartStatus = Extract<
|
|
15
|
+
MessagePartStreamStatus,
|
|
16
|
+
{ readonly type: "incomplete" }
|
|
17
|
+
>;
|
|
18
|
+
const INCOMPLETE_STATUSES: Readonly<
|
|
19
|
+
Record<IncompleteMessagePartStatus["reason"], IncompleteMessagePartStatus>
|
|
20
|
+
> = Object.freeze({
|
|
21
|
+
cancelled: Object.freeze({ type: "incomplete", reason: "cancelled" }),
|
|
22
|
+
length: Object.freeze({ type: "incomplete", reason: "length" }),
|
|
23
|
+
"content-filter": Object.freeze({
|
|
24
|
+
type: "incomplete",
|
|
25
|
+
reason: "content-filter",
|
|
26
|
+
}),
|
|
27
|
+
other: Object.freeze({ type: "incomplete", reason: "other" }),
|
|
28
|
+
error: Object.freeze({ type: "incomplete", reason: "error" }),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const normalizePartStatus = (
|
|
32
|
+
part: ThreadUserMessagePart | ThreadAssistantMessagePart,
|
|
33
|
+
): MessagePartStatus | undefined => {
|
|
34
|
+
const status = (part as { readonly status?: unknown }).status;
|
|
35
|
+
if (!status || typeof status !== "object") return undefined;
|
|
36
|
+
|
|
37
|
+
const { type } = status as { readonly type?: unknown };
|
|
38
|
+
if (type === "running") return RUNNING_STATUS;
|
|
39
|
+
if (type === "complete") return COMPLETE_STATUS;
|
|
40
|
+
if (type !== "incomplete") return undefined;
|
|
41
|
+
|
|
42
|
+
const { reason } = status as {
|
|
43
|
+
readonly reason?: unknown;
|
|
44
|
+
};
|
|
45
|
+
const normalizedReason: IncompleteMessagePartStatus["reason"] =
|
|
46
|
+
reason === "cancelled" ||
|
|
47
|
+
reason === "length" ||
|
|
48
|
+
reason === "content-filter" ||
|
|
49
|
+
reason === "other" ||
|
|
50
|
+
reason === "error"
|
|
51
|
+
? reason
|
|
52
|
+
: "other";
|
|
53
|
+
|
|
54
|
+
return INCOMPLETE_STATUSES[normalizedReason];
|
|
55
|
+
};
|