@assistant-ui/core 0.1.2 → 0.1.5
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/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +2 -4
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +10 -0
- package/dist/react/AssistantRuntimeProvider.d.ts.map +1 -0
- package/dist/react/AssistantRuntimeProvider.js +16 -0
- package/dist/react/AssistantRuntimeProvider.js.map +1 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts +15 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +154 -0
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -0
- package/dist/react/adapters/TitleGenerationAdapter.d.ts +6 -0
- package/dist/react/adapters/TitleGenerationAdapter.d.ts.map +1 -0
- package/dist/react/adapters/TitleGenerationAdapter.js +15 -0
- package/dist/react/adapters/TitleGenerationAdapter.js.map +1 -0
- package/dist/react/index.d.ts +5 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +8 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/primitive-hooks/index.d.ts +15 -0
- package/dist/react/primitive-hooks/index.d.ts.map +1 -0
- package/dist/react/primitive-hooks/index.js +15 -0
- package/dist/react/primitive-hooks/index.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts +10 -0
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarCopy.js +26 -0
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts +5 -0
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarEdit.js +11 -0
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.d.ts +9 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.js +19 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -0
- package/dist/react/primitive-hooks/useActionBarReload.d.ts +5 -0
- package/dist/react/primitive-hooks/useActionBarReload.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useActionBarReload.js +13 -0
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts +6 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +11 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -0
- package/dist/react/primitive-hooks/useComposerCancel.d.ts +5 -0
- package/dist/react/primitive-hooks/useComposerCancel.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useComposerCancel.js +11 -0
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -0
- package/dist/react/primitive-hooks/useComposerSend.d.ts +5 -0
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useComposerSend.js +11 -0
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.d.ts +4 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.js +10 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerSend.d.ts +5 -0
- package/dist/react/primitive-hooks/useEditComposerSend.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useEditComposerSend.js +11 -0
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -0
- package/dist/react/primitive-hooks/useMessageBranching.d.ts +7 -0
- package/dist/react/primitive-hooks/useMessageBranching.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useMessageBranching.js +15 -0
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -0
- package/dist/react/primitive-hooks/useMessageReload.d.ts +5 -0
- package/dist/react/primitive-hooks/useMessageReload.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useMessageReload.js +11 -0
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts +2 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.js +5 -0
- package/dist/react/primitive-hooks/useThreadIsEmpty.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts +2 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.js +5 -0
- package/dist/react/primitive-hooks/useThreadIsRunning.js.map +1 -0
- package/dist/react/primitive-hooks/useThreadMessages.d.ts +3 -0
- package/dist/react/primitive-hooks/useThreadMessages.d.ts.map +1 -0
- package/dist/react/primitive-hooks/useThreadMessages.js +5 -0
- package/dist/react/primitive-hooks/useThreadMessages.js.map +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +97 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +111 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +115 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +444 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +18 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.js +14 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +5 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +528 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +15 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +83 -0
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts +62 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/auiV0.js +74 -0
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -0
- package/dist/react/runtimes/cloud/index.d.ts +4 -0
- package/dist/react/runtimes/cloud/index.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/index.js +4 -0
- package/dist/react/runtimes/cloud/index.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +13 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +103 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/createMessageConverter.d.ts +17 -0
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -0
- package/dist/react/runtimes/createMessageConverter.js +50 -0
- package/dist/react/runtimes/createMessageConverter.js.map +1 -0
- package/dist/react/runtimes/external-message-converter.d.ts +34 -0
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -0
- package/dist/react/runtimes/external-message-converter.js +309 -0
- package/dist/react/runtimes/external-message-converter.js.map +1 -0
- package/dist/react/runtimes/index.d.ts +11 -0
- package/dist/react/runtimes/index.d.ts.map +1 -0
- package/dist/react/runtimes/index.js +11 -0
- package/dist/react/runtimes/index.js.map +1 -0
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts +4 -0
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useExternalStoreRuntime.js +19 -0
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -0
- package/dist/react/runtimes/useLocalRuntime.d.ts +28 -0
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useLocalRuntime.js +64 -0
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts +4 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +48 -0
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -0
- package/dist/react/runtimes/useToolInvocations.d.ts +38 -0
- package/dist/react/runtimes/useToolInvocations.d.ts.map +1 -0
- package/dist/react/runtimes/useToolInvocations.js +411 -0
- package/dist/react/runtimes/useToolInvocations.js.map +1 -0
- package/dist/react/types/store-augmentation.d.ts +0 -1
- package/dist/react/types/store-augmentation.d.ts.map +1 -1
- package/dist/react/types/store-augmentation.js +1 -1
- package/dist/react/types/store-augmentation.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +2 -0
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -2
- package/dist/store/index.js.map +1 -1
- package/dist/utils/json/is-json-equal.d.ts +2 -0
- package/dist/utils/json/is-json-equal.d.ts.map +1 -0
- package/dist/utils/json/is-json-equal.js +31 -0
- package/dist/utils/json/is-json-equal.js.map +1 -0
- package/dist/utils/json/is-json.d.ts +6 -0
- package/dist/utils/json/is-json.d.ts.map +1 -0
- package/dist/utils/json/is-json.js +33 -0
- package/dist/utils/json/is-json.js.map +1 -0
- package/package.json +11 -10
- package/src/model-context/frame/provider.ts +2 -6
- package/src/react/AssistantRuntimeProvider.tsx +33 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +227 -0
- package/src/react/adapters/TitleGenerationAdapter.ts +20 -0
- package/src/react/index.ts +17 -1
- package/src/react/primitive-hooks/index.ts +20 -0
- package/src/react/primitive-hooks/useActionBarCopy.ts +38 -0
- package/src/react/primitive-hooks/useActionBarEdit.ts +13 -0
- package/src/react/primitive-hooks/useActionBarFeedback.ts +28 -0
- package/src/react/primitive-hooks/useActionBarReload.ts +18 -0
- package/src/react/primitive-hooks/useComposerAddAttachment.ts +17 -0
- package/src/react/primitive-hooks/useComposerCancel.ts +13 -0
- package/src/react/primitive-hooks/useComposerSend.ts +15 -0
- package/src/react/primitive-hooks/useEditComposerCancel.ts +12 -0
- package/src/react/primitive-hooks/useEditComposerSend.ts +13 -0
- package/src/react/primitive-hooks/useMessageBranching.ts +18 -0
- package/src/react/primitive-hooks/useMessageReload.ts +13 -0
- package/src/react/primitive-hooks/useThreadIsEmpty.ts +5 -0
- package/src/react/primitive-hooks/useThreadIsRunning.ts +5 -0
- package/src/react/primitive-hooks/useThreadMessages.ts +6 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +176 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +534 -0
- package/src/react/runtimes/RuntimeAdapterProvider.tsx +40 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +785 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +101 -0
- package/src/react/runtimes/cloud/auiV0.ts +160 -0
- package/src/react/runtimes/cloud/index.ts +3 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +154 -0
- package/src/react/runtimes/createMessageConverter.ts +77 -0
- package/src/react/runtimes/external-message-converter.ts +487 -0
- package/src/react/runtimes/index.ts +36 -0
- package/src/react/runtimes/useExternalStoreRuntime.ts +27 -0
- package/src/react/runtimes/useLocalRuntime.ts +101 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +76 -0
- package/src/react/runtimes/useToolInvocations.ts +594 -0
- package/src/react/types/store-augmentation.ts +0 -2
- package/src/runtime/base/base-composer-runtime-core.ts +2 -0
- package/src/store/index.ts +1 -2
- package/src/tests/no-unsafe-process-env.test.ts +58 -0
- package/src/utils/json/is-json-equal.ts +48 -0
- package/src/utils/json/is-json.ts +58 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { resolve, relative, join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const SRC_DIR = resolve(__dirname, "..");
|
|
6
|
+
|
|
7
|
+
function findFiles(dir: string, ext: string[]): string[] {
|
|
8
|
+
const results: string[] = [];
|
|
9
|
+
for (const entry of readdirSync(dir)) {
|
|
10
|
+
const full = join(dir, entry);
|
|
11
|
+
if (statSync(full).isDirectory()) {
|
|
12
|
+
results.push(...findFiles(full, ext));
|
|
13
|
+
} else if (ext.some((e) => full.endsWith(e))) {
|
|
14
|
+
results.push(full);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return results;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("no unsafe process.env access", () => {
|
|
21
|
+
it("all process.env access for non-NODE_ENV vars must have a typeof process guard", () => {
|
|
22
|
+
const files = findFiles(SRC_DIR, [".ts", ".tsx"]).filter(
|
|
23
|
+
(f) => !f.includes("/tests/") && !f.includes(".test."),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const violations: string[] = [];
|
|
27
|
+
|
|
28
|
+
for (const file of files) {
|
|
29
|
+
const content = readFileSync(file, "utf-8");
|
|
30
|
+
|
|
31
|
+
// Check if file has process.env access beyond NODE_ENV
|
|
32
|
+
// Match process.env, process?.env, process.env?, process?.env?
|
|
33
|
+
const hasNonNodeEnvProcessAccess =
|
|
34
|
+
/process\??\.env\??(?!\.NODE_ENV\b)/.test(
|
|
35
|
+
content.replace(/process\??\.env\??\.NODE_ENV/g, ""),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (!hasNonNodeEnvProcessAccess) continue;
|
|
39
|
+
|
|
40
|
+
// File accesses process.env for non-NODE_ENV vars — must have typeof guard
|
|
41
|
+
const hasTypeofGuard = /typeof process\s*!==\s*["']undefined["']/.test(
|
|
42
|
+
content,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (!hasTypeofGuard) {
|
|
46
|
+
violations.push(relative(SRC_DIR, file));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
violations,
|
|
52
|
+
`These files access process.env (non-NODE_ENV) without a typeof process !== "undefined" guard.\n` +
|
|
53
|
+
`@assistant-ui/core lacks @types/node, so bare process.env access crashes in Vite and other bundlers.\n` +
|
|
54
|
+
`Add: typeof process !== "undefined" ? process.env?.["VAR_NAME"] : undefined\n\n` +
|
|
55
|
+
`Files:\n${violations.map((f) => ` - ${f}`).join("\n")}`,
|
|
56
|
+
).toEqual([]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
2
|
+
import { isJSONValue, isRecord } from "./is-json";
|
|
3
|
+
|
|
4
|
+
const MAX_JSON_DEPTH = 100;
|
|
5
|
+
|
|
6
|
+
const isJSONValueEqualAtDepth = (
|
|
7
|
+
a: ReadonlyJSONValue,
|
|
8
|
+
b: ReadonlyJSONValue,
|
|
9
|
+
currentDepth: number,
|
|
10
|
+
): boolean => {
|
|
11
|
+
if (a === b) return true;
|
|
12
|
+
if (currentDepth > MAX_JSON_DEPTH) return false;
|
|
13
|
+
|
|
14
|
+
if (a == null || b == null) return false;
|
|
15
|
+
|
|
16
|
+
if (Array.isArray(a)) {
|
|
17
|
+
if (!Array.isArray(b) || a.length !== b.length) return false;
|
|
18
|
+
return a.every((item, index) =>
|
|
19
|
+
isJSONValueEqualAtDepth(
|
|
20
|
+
item,
|
|
21
|
+
b[index] as ReadonlyJSONValue,
|
|
22
|
+
currentDepth + 1,
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(b)) return false;
|
|
28
|
+
if (!isRecord(a) || !isRecord(b)) return false;
|
|
29
|
+
|
|
30
|
+
const aKeys = Object.keys(a);
|
|
31
|
+
const bKeys = Object.keys(b);
|
|
32
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
33
|
+
|
|
34
|
+
return aKeys.every(
|
|
35
|
+
(key) =>
|
|
36
|
+
Object.hasOwn(b, key) &&
|
|
37
|
+
isJSONValueEqualAtDepth(
|
|
38
|
+
a[key] as ReadonlyJSONValue,
|
|
39
|
+
b[key] as ReadonlyJSONValue,
|
|
40
|
+
currentDepth + 1,
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const isJSONValueEqual = (a: unknown, b: unknown): boolean => {
|
|
46
|
+
if (!isJSONValue(a) || !isJSONValue(b)) return false;
|
|
47
|
+
return isJSONValueEqualAtDepth(a, b, 0);
|
|
48
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ReadonlyJSONArray,
|
|
3
|
+
ReadonlyJSONObject,
|
|
4
|
+
ReadonlyJSONValue,
|
|
5
|
+
} from "assistant-stream/utils";
|
|
6
|
+
|
|
7
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
8
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isJSONValue(
|
|
12
|
+
value: unknown,
|
|
13
|
+
currentDepth: number = 0,
|
|
14
|
+
): value is ReadonlyJSONValue {
|
|
15
|
+
// Protect against too deep recursion
|
|
16
|
+
if (currentDepth > 100) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
value === null ||
|
|
22
|
+
typeof value === "string" ||
|
|
23
|
+
typeof value === "boolean"
|
|
24
|
+
) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Handle special number cases
|
|
29
|
+
if (typeof value === "number") {
|
|
30
|
+
return !Number.isNaN(value) && Number.isFinite(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
return value.every((item) => isJSONValue(item, currentDepth + 1));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (isRecord(value)) {
|
|
38
|
+
return Object.entries(value).every(
|
|
39
|
+
([key, val]) =>
|
|
40
|
+
typeof key === "string" && isJSONValue(val, currentDepth + 1),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isJSONArray(value: unknown): value is ReadonlyJSONArray {
|
|
48
|
+
return Array.isArray(value) && value.every(isJSONValue);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isJSONObject(value: unknown): value is ReadonlyJSONObject {
|
|
52
|
+
return (
|
|
53
|
+
isRecord(value) &&
|
|
54
|
+
Object.entries(value).every(
|
|
55
|
+
([key, val]) => typeof key === "string" && isJSONValue(val),
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
}
|