@vinaverse/react 0.1.0-alpha.4 → 0.1.0-alpha.6

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/agent.cjs ADDED
@@ -0,0 +1,147 @@
1
+ 'use strict';
2
+
3
+ var agent = require('@vinaverse/client/agent');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ // src/agent.tsx
8
+ var RuntimeContext = /* @__PURE__ */ react.createContext(null);
9
+ function AgentRuntimeProvider(props) {
10
+ return /* @__PURE__ */ jsxRuntime.jsx(RuntimeContext.Provider, { value: props.runtime, children: props.children });
11
+ }
12
+ function useAgentRuntime() {
13
+ const runtime = react.useContext(RuntimeContext);
14
+ if (!runtime)
15
+ throw new Error("Agent hooks render inside <AgentRuntimeProvider>.");
16
+ return runtime;
17
+ }
18
+ function useAgentConversation(key, open = {}) {
19
+ const runtime = useAgentRuntime();
20
+ const keyRef = react.useRef(key);
21
+ keyRef.current = key;
22
+ const k = agent.agentKey(key);
23
+ const read = react.useCallback(() => runtime.peek(keyRef.current), [runtime, k]);
24
+ const conversation = react.useSyncExternalStore(runtime.subscribe, read, read);
25
+ const openRef = react.useRef(open);
26
+ openRef.current = open;
27
+ react.useLayoutEffect(() => conversation.show(openRef.current), [conversation]);
28
+ const { place, entryPoint } = open;
29
+ const screen = place?.screen;
30
+ const entityType = place?.entity?.type;
31
+ const entityId = place?.entity?.id;
32
+ react.useLayoutEffect(() => {
33
+ conversation.tell(openRef.current);
34
+ }, [conversation, screen, entityType, entityId, entryPoint]);
35
+ const state = react.useSyncExternalStore(
36
+ conversation.subscribe,
37
+ conversation.getState,
38
+ conversation.getState
39
+ );
40
+ const startNew = react.useCallback(
41
+ () => runtime.startNew(keyRef.current),
42
+ [runtime]
43
+ );
44
+ return { conversation, state, startNew };
45
+ }
46
+ function useAgentStatus() {
47
+ const runtime = useAgentRuntime();
48
+ react.useEffect(() => {
49
+ runtime.status().catch(() => void 0);
50
+ }, [runtime]);
51
+ return react.useSyncExternalStore(
52
+ runtime.subscribe,
53
+ runtime.getStatus,
54
+ runtime.getStatus
55
+ );
56
+ }
57
+ function useAgentName(fallback) {
58
+ const runtime = useAgentRuntime();
59
+ return react.useSyncExternalStore(runtime.subscribe, runtime.getName, runtime.getName) ?? fallback;
60
+ }
61
+ function useAgentFeatures() {
62
+ const status = useAgentStatus();
63
+ return {
64
+ available: status?.available === true,
65
+ launcher: status?.launcher === true,
66
+ history: status?.features.history === true,
67
+ memory: status?.features.memory === true,
68
+ businessAgent: status?.features.businessAgent === true,
69
+ businessSetup: status?.features.businessSetup === true
70
+ };
71
+ }
72
+ function useAgentProfile(fallback) {
73
+ const status = useAgentStatus();
74
+ return { name: useAgentName(fallback), avatarUrl: status?.avatarUrl ?? null };
75
+ }
76
+ function greetedKey(subject, mode) {
77
+ return `vinaverse.agent.greeted.${subject ?? "guest"}:${mode}`;
78
+ }
79
+ var MEMORY = /* @__PURE__ */ new Map();
80
+ var memory = {
81
+ getItem: (k) => MEMORY.get(k) ?? null,
82
+ setItem: (k, v) => void MEMORY.set(k, v)
83
+ };
84
+ function useAgentLauncher(options) {
85
+ const runtime = useAgentRuntime();
86
+ const status = useAgentStatus();
87
+ const { subject, mode, onOpen } = options;
88
+ const storage = options.storage ?? memory;
89
+ const shows = status?.launcher === true && options.visible !== false;
90
+ const key = (options.storageKey ?? greetedKey)(subject, mode);
91
+ const [greeted, setGreeted] = react.useState(
92
+ null
93
+ );
94
+ const [due, setDue] = react.useState(null);
95
+ react.useEffect(() => {
96
+ let live = true;
97
+ Promise.resolve(storage.getItem(key)).then(
98
+ (value) => {
99
+ if (live) setGreeted({ key, done: value === "1" });
100
+ },
101
+ () => {
102
+ if (live) setGreeted({ key, done: false });
103
+ }
104
+ );
105
+ return () => {
106
+ live = false;
107
+ };
108
+ }, [storage, key]);
109
+ const pending = shows && greeted?.key === key && !greeted.done;
110
+ react.useEffect(() => {
111
+ if (!pending) return;
112
+ const timer = setTimeout(() => {
113
+ setDue(key);
114
+ runtime.emit({ type: "launcher_greeted" });
115
+ }, options.delayMs ?? 1200);
116
+ return () => clearTimeout(timer);
117
+ }, [pending, key, runtime, options.delayMs]);
118
+ const done = react.useCallback(() => {
119
+ setGreeted({ key, done: true });
120
+ void Promise.resolve(storage.setItem(key, "1")).catch(() => void 0);
121
+ }, [storage, key]);
122
+ const open = react.useCallback(() => {
123
+ done();
124
+ runtime.emit({ type: "launcher_opened" });
125
+ onOpen();
126
+ }, [done, runtime, onOpen]);
127
+ const dismiss = react.useCallback(() => {
128
+ done();
129
+ runtime.emit({ type: "greeting_closed" });
130
+ }, [done, runtime]);
131
+ react.useEffect(() => {
132
+ if (shows) runtime.emit({ type: "launcher_shown" });
133
+ }, [shows, runtime]);
134
+ return { shows, greets: pending && due === key, open, dismiss };
135
+ }
136
+
137
+ exports.AgentRuntimeProvider = AgentRuntimeProvider;
138
+ exports.greetedKey = greetedKey;
139
+ exports.useAgentConversation = useAgentConversation;
140
+ exports.useAgentFeatures = useAgentFeatures;
141
+ exports.useAgentLauncher = useAgentLauncher;
142
+ exports.useAgentName = useAgentName;
143
+ exports.useAgentProfile = useAgentProfile;
144
+ exports.useAgentRuntime = useAgentRuntime;
145
+ exports.useAgentStatus = useAgentStatus;
146
+ //# sourceMappingURL=agent.cjs.map
147
+ //# sourceMappingURL=agent.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agent.tsx"],"names":["jsx","useContext","useRef","agentKey","useCallback","useSyncExternalStore","useLayoutEffect","useEffect","useState"],"mappings":";;;;;;;AAwBA,IAAM,cAAA,uCAAoE,IAAI,CAAA;AAGvE,SAAS,qBAAqB,KAAA,EAGvB;AACZ,EAAA,uBACEA,cAAA,CAAC,eAAe,QAAA,EAAf,EAAwB,OAAO,KAAA,CAAM,OAAA,EACnC,gBAAM,QAAA,EACT,CAAA;AAEJ;AAEO,SAAS,eAAA,GAAgC;AAC9C,EAAA,MAAM,OAAA,GAA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AC,CAAA,CAAE,KAAA,CAAM,MAAM,MAAS,CAAA;AAAA,EACvE,CAAA,EAAG,CAAC,OAAA,EAAS,GAAG,CAAC,CAAA;AACjB,EAAA,MAAM,IAAA,GAAOA,kBAAY,MAAM;AAC7B,IAAA,IAAA,EAAK;AACL,IAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,iBAAA,EAAmB,CAAA;AACxC,IAAA,MAAA,EAAO;AAAA,EACT,CAAA,EAAG,CAAC,IAAA,EAAM,OAAA,EAAS,MAAM,CAAC,CAAA;AAC1B,EAAA,MAAM,OAAA,GAAUA,kBAAY,MAAM;AAChC,IAAA,IAAA,EAAK;AACL,IAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,iBAAA,EAAmB,CAAA;AAAA,EAC1C,CAAA,EAAG,CAAC,IAAA,EAAM,OAAO,CAAC,CAAA;AAClB,EAAAG,eAAA,CAAU,MAAM;AACd,IAAA,IAAI,OAAO,OAAA,CAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,kBAAkB,CAAA;AAAA,EACpD,CAAA,EAAG,CAAC,KAAA,EAAO,OAAO,CAAC,CAAA;AACnB,EAAA,OAAO,EAAE,KAAA,EAAO,MAAA,EAAQ,WAAW,GAAA,KAAQ,GAAA,EAAK,MAAM,OAAA,EAAQ;AAChE","file":"agent.cjs","sourcesContent":["// React bindings of the agent runtime (@vinaverse/client/agent): a provider and hooks, thin by design. The runtime holds\n// every rule; these subscribe, show a conversation while a component is mounted, and read the launcher's state. No\n// react-native or DOM import.\nimport type {\n AgentConversation,\n AgentConversationState,\n AgentKey,\n AgentPlace,\n AgentRuntime,\n AgentStatus,\n} from '@vinaverse/client/agent';\nimport { agentKey } from '@vinaverse/client/agent';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\n\nconst RuntimeContext = /* @__PURE__ */ createContext<AgentRuntime | null>(null);\n\n/** The app's agent runtime, made once (module level, or memoized) and given to everything below. */\nexport function AgentRuntimeProvider(props: {\n readonly runtime: AgentRuntime;\n readonly children?: ReactNode;\n}): ReactNode {\n return (\n <RuntimeContext.Provider value={props.runtime}>\n {props.children}\n </RuntimeContext.Provider>\n );\n}\n\nexport function useAgentRuntime(): AgentRuntime {\n const runtime = useContext(RuntimeContext);\n if (!runtime)\n throw new Error('Agent hooks render inside <AgentRuntimeProvider>.');\n return runtime;\n}\n\nexport interface UseAgentConversation {\n readonly conversation: AgentConversation;\n readonly state: AgentConversationState;\n /** A new conversation for this key (the old one let go and forgotten). */\n readonly startNew: () => void;\n}\n\n/**\n * The key's conversation, shown while the component is mounted (kept across screens; released when it unmounts), told\n * the place and the way in as they change. A start over or its end hands the component the key's next conversation.\n */\nexport function useAgentConversation(\n key: AgentKey,\n open: {\n readonly place?: AgentPlace | null;\n readonly entryPoint?: string | null;\n } = {},\n): UseAgentConversation {\n const runtime = useAgentRuntime();\n const keyRef = useRef(key);\n keyRef.current = key;\n const k = agentKey(key);\n // biome-ignore lint/correctness/useExhaustiveDependencies: the key's string reads it again when the key changes\n const read = useCallback(() => runtime.peek(keyRef.current), [runtime, k]);\n const conversation = useSyncExternalStore(runtime.subscribe, read, read);\n const openRef = useRef(open);\n openRef.current = open;\n // Layout effects: they run before any passive effect, a child's included, so a chat below that starts the\n // conversation early (`VinaverseChat`) finds it shown and told the place.\n useLayoutEffect(() => conversation.show(openRef.current), [conversation]);\n const { place, entryPoint } = open;\n const screen = place?.screen;\n const entityType = place?.entity?.type;\n const entityId = place?.entity?.id;\n // biome-ignore lint/correctness/useExhaustiveDependencies: told by value, so a place made again each render is the same\n useLayoutEffect(() => {\n conversation.tell(openRef.current);\n }, [conversation, screen, entityType, entityId, entryPoint]);\n const state = useSyncExternalStore(\n conversation.subscribe,\n conversation.getState,\n conversation.getState,\n );\n const startNew = useCallback(\n () => runtime.startNew(keyRef.current),\n [runtime],\n );\n return { conversation, state, startNew };\n}\n\n/** The agent's status (read once, then at most every few minutes); null until the first read. */\nexport function useAgentStatus(): AgentStatus | null {\n const runtime = useAgentRuntime();\n useEffect(() => {\n runtime.status().catch(() => undefined); // an unread status is no agent: the launcher stays hidden\n }, [runtime]);\n return useSyncExternalStore(\n runtime.subscribe,\n runtime.getStatus,\n runtime.getStatus,\n );\n}\n\n/** The agent's name: the newest session's, else the status's, else `fallback`. */\nexport function useAgentName(fallback: string): string {\n const runtime = useAgentRuntime();\n return (\n useSyncExternalStore(runtime.subscribe, runtime.getName, runtime.getName) ??\n fallback\n );\n}\n\n/** What the agent can do, from the status (all off until it is read, and when the agent is off). */\nexport function useAgentFeatures(): AgentStatus['features'] & {\n readonly available: boolean;\n readonly launcher: boolean;\n} {\n const status = useAgentStatus();\n return {\n available: status?.available === true,\n launcher: status?.launcher === true,\n history: status?.features.history === true,\n memory: status?.features.memory === true,\n businessAgent: status?.features.businessAgent === true,\n businessSetup: status?.features.businessSetup === true,\n };\n}\n\n/** The agent as an entry shows it before any session: its name (`fallback` until known) and avatar. */\nexport function useAgentProfile(fallback: string): {\n readonly name: string;\n readonly avatarUrl: string | null;\n} {\n const status = useAgentStatus();\n return { name: useAgentName(fallback), avatarUrl: status?.avatarUrl ?? null };\n}\n\n/** Where the launcher remembers that it greeted a person in a mode (sync or async; the app's preferences store). */\nexport interface GreetingStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n}\n\n/** Where the greeting is remembered, per person and mode: the default the storage sees, unless the app maps its own. */\nexport function greetedKey(subject: string | null, mode: string): string {\n return `vinaverse.agent.greeted.${subject ?? 'guest'}:${mode}`;\n}\n\nconst MEMORY = new Map<string, string>();\nconst memory: GreetingStorage = {\n getItem: (k) => MEMORY.get(k) ?? null,\n setItem: (k, v) => void MEMORY.set(k, v),\n};\n\nexport interface UseAgentLauncher {\n /** The status offers the launcher, and the app shows it here. */\n readonly shows: boolean;\n /** Its greeting bubble: once per person and mode, a moment after the launcher shows. */\n readonly greets: boolean;\n /** The person opens the agent (the greeting is done too). */\n readonly open: () => void;\n /** The person closes the greeting. */\n readonly dismiss: () => void;\n}\n\n/** The floating launcher's state: whether it shows and greets, and its two actions. */\nexport function useAgentLauncher(options: {\n readonly subject: string | null;\n readonly mode: string;\n /** The app's own rule (the tabs it shows on, no keyboard up…); default true. */\n readonly visible?: boolean;\n readonly storage?: GreetingStorage;\n /** The storage's key for a person and mode, to reuse a record the app already keeps. Default `greetedKey`. */\n readonly storageKey?: (subject: string | null, mode: string) => string;\n /** How long after showing the greeting appears. Default 1200 ms. */\n readonly delayMs?: number;\n readonly onOpen: () => void;\n}): UseAgentLauncher {\n const runtime = useAgentRuntime();\n const status = useAgentStatus();\n const { subject, mode, onOpen } = options;\n const storage = options.storage ?? memory;\n const shows = status?.launcher === true && options.visible !== false;\n const key = (options.storageKey ?? greetedKey)(subject, mode);\n const [greeted, setGreeted] = useState<{ key: string; done: boolean } | null>(\n null,\n );\n const [due, setDue] = useState<string | null>(null);\n useEffect(() => {\n let live = true;\n Promise.resolve(storage.getItem(key)).then(\n (value) => {\n if (live) setGreeted({ key, done: value === '1' });\n },\n () => {\n if (live) setGreeted({ key, done: false });\n },\n );\n return () => {\n live = false;\n };\n }, [storage, key]);\n const pending = shows && greeted?.key === key && !greeted.done;\n useEffect(() => {\n if (!pending) return;\n const timer = setTimeout(() => {\n setDue(key);\n runtime.emit({ type: 'launcher_greeted' });\n }, options.delayMs ?? 1200);\n return () => clearTimeout(timer);\n }, [pending, key, runtime, options.delayMs]);\n const done = useCallback(() => {\n setGreeted({ key, done: true });\n void Promise.resolve(storage.setItem(key, '1')).catch(() => undefined);\n }, [storage, key]);\n const open = useCallback(() => {\n done();\n runtime.emit({ type: 'launcher_opened' });\n onOpen();\n }, [done, runtime, onOpen]);\n const dismiss = useCallback(() => {\n done();\n runtime.emit({ type: 'greeting_closed' });\n }, [done, runtime]);\n useEffect(() => {\n if (shows) runtime.emit({ type: 'launcher_shown' });\n }, [shows, runtime]);\n return { shows, greets: pending && due === key, open, dismiss };\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import { AgentRuntime, AgentConversation, AgentConversationState, AgentKey, AgentPlace, AgentStatus } from '@vinaverse/client/agent';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** The app's agent runtime, made once (module level, or memoized) and given to everything below. */
5
+ declare function AgentRuntimeProvider(props: {
6
+ readonly runtime: AgentRuntime;
7
+ readonly children?: ReactNode;
8
+ }): ReactNode;
9
+ declare function useAgentRuntime(): AgentRuntime;
10
+ interface UseAgentConversation {
11
+ readonly conversation: AgentConversation;
12
+ readonly state: AgentConversationState;
13
+ /** A new conversation for this key (the old one let go and forgotten). */
14
+ readonly startNew: () => void;
15
+ }
16
+ /**
17
+ * The key's conversation, shown while the component is mounted (kept across screens; released when it unmounts), told
18
+ * the place and the way in as they change. A start over or its end hands the component the key's next conversation.
19
+ */
20
+ declare function useAgentConversation(key: AgentKey, open?: {
21
+ readonly place?: AgentPlace | null;
22
+ readonly entryPoint?: string | null;
23
+ }): UseAgentConversation;
24
+ /** The agent's status (read once, then at most every few minutes); null until the first read. */
25
+ declare function useAgentStatus(): AgentStatus | null;
26
+ /** The agent's name: the newest session's, else the status's, else `fallback`. */
27
+ declare function useAgentName(fallback: string): string;
28
+ /** What the agent can do, from the status (all off until it is read, and when the agent is off). */
29
+ declare function useAgentFeatures(): AgentStatus['features'] & {
30
+ readonly available: boolean;
31
+ readonly launcher: boolean;
32
+ };
33
+ /** The agent as an entry shows it before any session: its name (`fallback` until known) and avatar. */
34
+ declare function useAgentProfile(fallback: string): {
35
+ readonly name: string;
36
+ readonly avatarUrl: string | null;
37
+ };
38
+ /** Where the launcher remembers that it greeted a person in a mode (sync or async; the app's preferences store). */
39
+ interface GreetingStorage {
40
+ getItem(key: string): string | null | Promise<string | null>;
41
+ setItem(key: string, value: string): void | Promise<void>;
42
+ }
43
+ /** Where the greeting is remembered, per person and mode: the default the storage sees, unless the app maps its own. */
44
+ declare function greetedKey(subject: string | null, mode: string): string;
45
+ interface UseAgentLauncher {
46
+ /** The status offers the launcher, and the app shows it here. */
47
+ readonly shows: boolean;
48
+ /** Its greeting bubble: once per person and mode, a moment after the launcher shows. */
49
+ readonly greets: boolean;
50
+ /** The person opens the agent (the greeting is done too). */
51
+ readonly open: () => void;
52
+ /** The person closes the greeting. */
53
+ readonly dismiss: () => void;
54
+ }
55
+ /** The floating launcher's state: whether it shows and greets, and its two actions. */
56
+ declare function useAgentLauncher(options: {
57
+ readonly subject: string | null;
58
+ readonly mode: string;
59
+ /** The app's own rule (the tabs it shows on, no keyboard up…); default true. */
60
+ readonly visible?: boolean;
61
+ readonly storage?: GreetingStorage;
62
+ /** The storage's key for a person and mode, to reuse a record the app already keeps. Default `greetedKey`. */
63
+ readonly storageKey?: (subject: string | null, mode: string) => string;
64
+ /** How long after showing the greeting appears. Default 1200 ms. */
65
+ readonly delayMs?: number;
66
+ readonly onOpen: () => void;
67
+ }): UseAgentLauncher;
68
+
69
+ export { AgentRuntimeProvider, type GreetingStorage, type UseAgentConversation, type UseAgentLauncher, greetedKey, useAgentConversation, useAgentFeatures, useAgentLauncher, useAgentName, useAgentProfile, useAgentRuntime, useAgentStatus };
@@ -0,0 +1,69 @@
1
+ import { AgentRuntime, AgentConversation, AgentConversationState, AgentKey, AgentPlace, AgentStatus } from '@vinaverse/client/agent';
2
+ import { ReactNode } from 'react';
3
+
4
+ /** The app's agent runtime, made once (module level, or memoized) and given to everything below. */
5
+ declare function AgentRuntimeProvider(props: {
6
+ readonly runtime: AgentRuntime;
7
+ readonly children?: ReactNode;
8
+ }): ReactNode;
9
+ declare function useAgentRuntime(): AgentRuntime;
10
+ interface UseAgentConversation {
11
+ readonly conversation: AgentConversation;
12
+ readonly state: AgentConversationState;
13
+ /** A new conversation for this key (the old one let go and forgotten). */
14
+ readonly startNew: () => void;
15
+ }
16
+ /**
17
+ * The key's conversation, shown while the component is mounted (kept across screens; released when it unmounts), told
18
+ * the place and the way in as they change. A start over or its end hands the component the key's next conversation.
19
+ */
20
+ declare function useAgentConversation(key: AgentKey, open?: {
21
+ readonly place?: AgentPlace | null;
22
+ readonly entryPoint?: string | null;
23
+ }): UseAgentConversation;
24
+ /** The agent's status (read once, then at most every few minutes); null until the first read. */
25
+ declare function useAgentStatus(): AgentStatus | null;
26
+ /** The agent's name: the newest session's, else the status's, else `fallback`. */
27
+ declare function useAgentName(fallback: string): string;
28
+ /** What the agent can do, from the status (all off until it is read, and when the agent is off). */
29
+ declare function useAgentFeatures(): AgentStatus['features'] & {
30
+ readonly available: boolean;
31
+ readonly launcher: boolean;
32
+ };
33
+ /** The agent as an entry shows it before any session: its name (`fallback` until known) and avatar. */
34
+ declare function useAgentProfile(fallback: string): {
35
+ readonly name: string;
36
+ readonly avatarUrl: string | null;
37
+ };
38
+ /** Where the launcher remembers that it greeted a person in a mode (sync or async; the app's preferences store). */
39
+ interface GreetingStorage {
40
+ getItem(key: string): string | null | Promise<string | null>;
41
+ setItem(key: string, value: string): void | Promise<void>;
42
+ }
43
+ /** Where the greeting is remembered, per person and mode: the default the storage sees, unless the app maps its own. */
44
+ declare function greetedKey(subject: string | null, mode: string): string;
45
+ interface UseAgentLauncher {
46
+ /** The status offers the launcher, and the app shows it here. */
47
+ readonly shows: boolean;
48
+ /** Its greeting bubble: once per person and mode, a moment after the launcher shows. */
49
+ readonly greets: boolean;
50
+ /** The person opens the agent (the greeting is done too). */
51
+ readonly open: () => void;
52
+ /** The person closes the greeting. */
53
+ readonly dismiss: () => void;
54
+ }
55
+ /** The floating launcher's state: whether it shows and greets, and its two actions. */
56
+ declare function useAgentLauncher(options: {
57
+ readonly subject: string | null;
58
+ readonly mode: string;
59
+ /** The app's own rule (the tabs it shows on, no keyboard up…); default true. */
60
+ readonly visible?: boolean;
61
+ readonly storage?: GreetingStorage;
62
+ /** The storage's key for a person and mode, to reuse a record the app already keeps. Default `greetedKey`. */
63
+ readonly storageKey?: (subject: string | null, mode: string) => string;
64
+ /** How long after showing the greeting appears. Default 1200 ms. */
65
+ readonly delayMs?: number;
66
+ readonly onOpen: () => void;
67
+ }): UseAgentLauncher;
68
+
69
+ export { AgentRuntimeProvider, type GreetingStorage, type UseAgentConversation, type UseAgentLauncher, greetedKey, useAgentConversation, useAgentFeatures, useAgentLauncher, useAgentName, useAgentProfile, useAgentRuntime, useAgentStatus };
package/dist/agent.js ADDED
@@ -0,0 +1,137 @@
1
+ import { agentKey } from '@vinaverse/client/agent';
2
+ import { useContext, useRef, useCallback, useSyncExternalStore, useLayoutEffect, useEffect, useState, createContext } from 'react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ // src/agent.tsx
6
+ var RuntimeContext = /* @__PURE__ */ createContext(null);
7
+ function AgentRuntimeProvider(props) {
8
+ return /* @__PURE__ */ jsx(RuntimeContext.Provider, { value: props.runtime, children: props.children });
9
+ }
10
+ function useAgentRuntime() {
11
+ const runtime = useContext(RuntimeContext);
12
+ if (!runtime)
13
+ throw new Error("Agent hooks render inside <AgentRuntimeProvider>.");
14
+ return runtime;
15
+ }
16
+ function useAgentConversation(key, open = {}) {
17
+ const runtime = useAgentRuntime();
18
+ const keyRef = useRef(key);
19
+ keyRef.current = key;
20
+ const k = agentKey(key);
21
+ const read = useCallback(() => runtime.peek(keyRef.current), [runtime, k]);
22
+ const conversation = useSyncExternalStore(runtime.subscribe, read, read);
23
+ const openRef = useRef(open);
24
+ openRef.current = open;
25
+ useLayoutEffect(() => conversation.show(openRef.current), [conversation]);
26
+ const { place, entryPoint } = open;
27
+ const screen = place?.screen;
28
+ const entityType = place?.entity?.type;
29
+ const entityId = place?.entity?.id;
30
+ useLayoutEffect(() => {
31
+ conversation.tell(openRef.current);
32
+ }, [conversation, screen, entityType, entityId, entryPoint]);
33
+ const state = useSyncExternalStore(
34
+ conversation.subscribe,
35
+ conversation.getState,
36
+ conversation.getState
37
+ );
38
+ const startNew = useCallback(
39
+ () => runtime.startNew(keyRef.current),
40
+ [runtime]
41
+ );
42
+ return { conversation, state, startNew };
43
+ }
44
+ function useAgentStatus() {
45
+ const runtime = useAgentRuntime();
46
+ useEffect(() => {
47
+ runtime.status().catch(() => void 0);
48
+ }, [runtime]);
49
+ return useSyncExternalStore(
50
+ runtime.subscribe,
51
+ runtime.getStatus,
52
+ runtime.getStatus
53
+ );
54
+ }
55
+ function useAgentName(fallback) {
56
+ const runtime = useAgentRuntime();
57
+ return useSyncExternalStore(runtime.subscribe, runtime.getName, runtime.getName) ?? fallback;
58
+ }
59
+ function useAgentFeatures() {
60
+ const status = useAgentStatus();
61
+ return {
62
+ available: status?.available === true,
63
+ launcher: status?.launcher === true,
64
+ history: status?.features.history === true,
65
+ memory: status?.features.memory === true,
66
+ businessAgent: status?.features.businessAgent === true,
67
+ businessSetup: status?.features.businessSetup === true
68
+ };
69
+ }
70
+ function useAgentProfile(fallback) {
71
+ const status = useAgentStatus();
72
+ return { name: useAgentName(fallback), avatarUrl: status?.avatarUrl ?? null };
73
+ }
74
+ function greetedKey(subject, mode) {
75
+ return `vinaverse.agent.greeted.${subject ?? "guest"}:${mode}`;
76
+ }
77
+ var MEMORY = /* @__PURE__ */ new Map();
78
+ var memory = {
79
+ getItem: (k) => MEMORY.get(k) ?? null,
80
+ setItem: (k, v) => void MEMORY.set(k, v)
81
+ };
82
+ function useAgentLauncher(options) {
83
+ const runtime = useAgentRuntime();
84
+ const status = useAgentStatus();
85
+ const { subject, mode, onOpen } = options;
86
+ const storage = options.storage ?? memory;
87
+ const shows = status?.launcher === true && options.visible !== false;
88
+ const key = (options.storageKey ?? greetedKey)(subject, mode);
89
+ const [greeted, setGreeted] = useState(
90
+ null
91
+ );
92
+ const [due, setDue] = useState(null);
93
+ useEffect(() => {
94
+ let live = true;
95
+ Promise.resolve(storage.getItem(key)).then(
96
+ (value) => {
97
+ if (live) setGreeted({ key, done: value === "1" });
98
+ },
99
+ () => {
100
+ if (live) setGreeted({ key, done: false });
101
+ }
102
+ );
103
+ return () => {
104
+ live = false;
105
+ };
106
+ }, [storage, key]);
107
+ const pending = shows && greeted?.key === key && !greeted.done;
108
+ useEffect(() => {
109
+ if (!pending) return;
110
+ const timer = setTimeout(() => {
111
+ setDue(key);
112
+ runtime.emit({ type: "launcher_greeted" });
113
+ }, options.delayMs ?? 1200);
114
+ return () => clearTimeout(timer);
115
+ }, [pending, key, runtime, options.delayMs]);
116
+ const done = useCallback(() => {
117
+ setGreeted({ key, done: true });
118
+ void Promise.resolve(storage.setItem(key, "1")).catch(() => void 0);
119
+ }, [storage, key]);
120
+ const open = useCallback(() => {
121
+ done();
122
+ runtime.emit({ type: "launcher_opened" });
123
+ onOpen();
124
+ }, [done, runtime, onOpen]);
125
+ const dismiss = useCallback(() => {
126
+ done();
127
+ runtime.emit({ type: "greeting_closed" });
128
+ }, [done, runtime]);
129
+ useEffect(() => {
130
+ if (shows) runtime.emit({ type: "launcher_shown" });
131
+ }, [shows, runtime]);
132
+ return { shows, greets: pending && due === key, open, dismiss };
133
+ }
134
+
135
+ export { AgentRuntimeProvider, greetedKey, useAgentConversation, useAgentFeatures, useAgentLauncher, useAgentName, useAgentProfile, useAgentRuntime, useAgentStatus };
136
+ //# sourceMappingURL=agent.js.map
137
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agent.tsx"],"names":[],"mappings":";;;;;AAwBA,IAAM,cAAA,iCAAoE,IAAI,CAAA;AAGvE,SAAS,qBAAqB,KAAA,EAGvB;AACZ,EAAA,uBACE,GAAA,CAAC,eAAe,QAAA,EAAf,EAAwB,OAAO,KAAA,CAAM,OAAA,EACnC,gBAAM,QAAA,EACT,CAAA;AAEJ;AAEO,SAAS,eAAA,GAAgC;AAC9C,EAAA,MAAM,OAAA,GAAU,WAAW,cAAc,CAAA;AACzC,EAAA,IAAI,CAAC,OAAA;AACH,IAAA,MAAM,IAAI,MAAM,mDAAmD,CAAA;AACrE,EAAA,OAAO,OAAA;AACT;AAaO,SAAS,oBAAA,CACd,GAAA,EACA,IAAA,GAGI,EAAC,E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CAAK,EAAE,IAAA,EAAM,iBAAA,EAAmB,CAAA;AACxC,IAAA,MAAA,EAAO;AAAA,EACT,CAAA,EAAG,CAAC,IAAA,EAAM,OAAA,EAAS,MAAM,CAAC,CAAA;AAC1B,EAAA,MAAM,OAAA,GAAU,YAAY,MAAM;AAChC,IAAA,IAAA,EAAK;AACL,IAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,iBAAA,EAAmB,CAAA;AAAA,EAC1C,CAAA,EAAG,CAAC,IAAA,EAAM,OAAO,CAAC,CAAA;AAClB,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,OAAO,OAAA,CAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,kBAAkB,CAAA;AAAA,EACpD,CAAA,EAAG,CAAC,KAAA,EAAO,OAAO,CAAC,CAAA;AACnB,EAAA,OAAO,EAAE,KAAA,EAAO,MAAA,EAAQ,WAAW,GAAA,KAAQ,GAAA,EAAK,MAAM,OAAA,EAAQ;AAChE","file":"agent.js","sourcesContent":["// React bindings of the agent runtime (@vinaverse/client/agent): a provider and hooks, thin by design. The runtime holds\n// every rule; these subscribe, show a conversation while a component is mounted, and read the launcher's state. No\n// react-native or DOM import.\nimport type {\n AgentConversation,\n AgentConversationState,\n AgentKey,\n AgentPlace,\n AgentRuntime,\n AgentStatus,\n} from '@vinaverse/client/agent';\nimport { agentKey } from '@vinaverse/client/agent';\nimport {\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\n\nconst RuntimeContext = /* @__PURE__ */ createContext<AgentRuntime | null>(null);\n\n/** The app's agent runtime, made once (module level, or memoized) and given to everything below. */\nexport function AgentRuntimeProvider(props: {\n readonly runtime: AgentRuntime;\n readonly children?: ReactNode;\n}): ReactNode {\n return (\n <RuntimeContext.Provider value={props.runtime}>\n {props.children}\n </RuntimeContext.Provider>\n );\n}\n\nexport function useAgentRuntime(): AgentRuntime {\n const runtime = useContext(RuntimeContext);\n if (!runtime)\n throw new Error('Agent hooks render inside <AgentRuntimeProvider>.');\n return runtime;\n}\n\nexport interface UseAgentConversation {\n readonly conversation: AgentConversation;\n readonly state: AgentConversationState;\n /** A new conversation for this key (the old one let go and forgotten). */\n readonly startNew: () => void;\n}\n\n/**\n * The key's conversation, shown while the component is mounted (kept across screens; released when it unmounts), told\n * the place and the way in as they change. A start over or its end hands the component the key's next conversation.\n */\nexport function useAgentConversation(\n key: AgentKey,\n open: {\n readonly place?: AgentPlace | null;\n readonly entryPoint?: string | null;\n } = {},\n): UseAgentConversation {\n const runtime = useAgentRuntime();\n const keyRef = useRef(key);\n keyRef.current = key;\n const k = agentKey(key);\n // biome-ignore lint/correctness/useExhaustiveDependencies: the key's string reads it again when the key changes\n const read = useCallback(() => runtime.peek(keyRef.current), [runtime, k]);\n const conversation = useSyncExternalStore(runtime.subscribe, read, read);\n const openRef = useRef(open);\n openRef.current = open;\n // Layout effects: they run before any passive effect, a child's included, so a chat below that starts the\n // conversation early (`VinaverseChat`) finds it shown and told the place.\n useLayoutEffect(() => conversation.show(openRef.current), [conversation]);\n const { place, entryPoint } = open;\n const screen = place?.screen;\n const entityType = place?.entity?.type;\n const entityId = place?.entity?.id;\n // biome-ignore lint/correctness/useExhaustiveDependencies: told by value, so a place made again each render is the same\n useLayoutEffect(() => {\n conversation.tell(openRef.current);\n }, [conversation, screen, entityType, entityId, entryPoint]);\n const state = useSyncExternalStore(\n conversation.subscribe,\n conversation.getState,\n conversation.getState,\n );\n const startNew = useCallback(\n () => runtime.startNew(keyRef.current),\n [runtime],\n );\n return { conversation, state, startNew };\n}\n\n/** The agent's status (read once, then at most every few minutes); null until the first read. */\nexport function useAgentStatus(): AgentStatus | null {\n const runtime = useAgentRuntime();\n useEffect(() => {\n runtime.status().catch(() => undefined); // an unread status is no agent: the launcher stays hidden\n }, [runtime]);\n return useSyncExternalStore(\n runtime.subscribe,\n runtime.getStatus,\n runtime.getStatus,\n );\n}\n\n/** The agent's name: the newest session's, else the status's, else `fallback`. */\nexport function useAgentName(fallback: string): string {\n const runtime = useAgentRuntime();\n return (\n useSyncExternalStore(runtime.subscribe, runtime.getName, runtime.getName) ??\n fallback\n );\n}\n\n/** What the agent can do, from the status (all off until it is read, and when the agent is off). */\nexport function useAgentFeatures(): AgentStatus['features'] & {\n readonly available: boolean;\n readonly launcher: boolean;\n} {\n const status = useAgentStatus();\n return {\n available: status?.available === true,\n launcher: status?.launcher === true,\n history: status?.features.history === true,\n memory: status?.features.memory === true,\n businessAgent: status?.features.businessAgent === true,\n businessSetup: status?.features.businessSetup === true,\n };\n}\n\n/** The agent as an entry shows it before any session: its name (`fallback` until known) and avatar. */\nexport function useAgentProfile(fallback: string): {\n readonly name: string;\n readonly avatarUrl: string | null;\n} {\n const status = useAgentStatus();\n return { name: useAgentName(fallback), avatarUrl: status?.avatarUrl ?? null };\n}\n\n/** Where the launcher remembers that it greeted a person in a mode (sync or async; the app's preferences store). */\nexport interface GreetingStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n}\n\n/** Where the greeting is remembered, per person and mode: the default the storage sees, unless the app maps its own. */\nexport function greetedKey(subject: string | null, mode: string): string {\n return `vinaverse.agent.greeted.${subject ?? 'guest'}:${mode}`;\n}\n\nconst MEMORY = new Map<string, string>();\nconst memory: GreetingStorage = {\n getItem: (k) => MEMORY.get(k) ?? null,\n setItem: (k, v) => void MEMORY.set(k, v),\n};\n\nexport interface UseAgentLauncher {\n /** The status offers the launcher, and the app shows it here. */\n readonly shows: boolean;\n /** Its greeting bubble: once per person and mode, a moment after the launcher shows. */\n readonly greets: boolean;\n /** The person opens the agent (the greeting is done too). */\n readonly open: () => void;\n /** The person closes the greeting. */\n readonly dismiss: () => void;\n}\n\n/** The floating launcher's state: whether it shows and greets, and its two actions. */\nexport function useAgentLauncher(options: {\n readonly subject: string | null;\n readonly mode: string;\n /** The app's own rule (the tabs it shows on, no keyboard up…); default true. */\n readonly visible?: boolean;\n readonly storage?: GreetingStorage;\n /** The storage's key for a person and mode, to reuse a record the app already keeps. Default `greetedKey`. */\n readonly storageKey?: (subject: string | null, mode: string) => string;\n /** How long after showing the greeting appears. Default 1200 ms. */\n readonly delayMs?: number;\n readonly onOpen: () => void;\n}): UseAgentLauncher {\n const runtime = useAgentRuntime();\n const status = useAgentStatus();\n const { subject, mode, onOpen } = options;\n const storage = options.storage ?? memory;\n const shows = status?.launcher === true && options.visible !== false;\n const key = (options.storageKey ?? greetedKey)(subject, mode);\n const [greeted, setGreeted] = useState<{ key: string; done: boolean } | null>(\n null,\n );\n const [due, setDue] = useState<string | null>(null);\n useEffect(() => {\n let live = true;\n Promise.resolve(storage.getItem(key)).then(\n (value) => {\n if (live) setGreeted({ key, done: value === '1' });\n },\n () => {\n if (live) setGreeted({ key, done: false });\n },\n );\n return () => {\n live = false;\n };\n }, [storage, key]);\n const pending = shows && greeted?.key === key && !greeted.done;\n useEffect(() => {\n if (!pending) return;\n const timer = setTimeout(() => {\n setDue(key);\n runtime.emit({ type: 'launcher_greeted' });\n }, options.delayMs ?? 1200);\n return () => clearTimeout(timer);\n }, [pending, key, runtime, options.delayMs]);\n const done = useCallback(() => {\n setGreeted({ key, done: true });\n void Promise.resolve(storage.setItem(key, '1')).catch(() => undefined);\n }, [storage, key]);\n const open = useCallback(() => {\n done();\n runtime.emit({ type: 'launcher_opened' });\n onOpen();\n }, [done, runtime, onOpen]);\n const dismiss = useCallback(() => {\n done();\n runtime.emit({ type: 'greeting_closed' });\n }, [done, runtime]);\n useEffect(() => {\n if (shows) runtime.emit({ type: 'launcher_shown' });\n }, [shows, runtime]);\n return { shows, greets: pending && due === key, open, dismiss };\n}\n"]}
package/dist/index.cjs CHANGED
@@ -5,10 +5,10 @@ var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
 
7
7
  // src/index.ts
8
- var CopyContext = react.createContext({
8
+ var CopyContext = /* @__PURE__ */ react.createContext({
9
9
  locale: void 0,
10
10
  direction: "ltr",
11
- t: copy.createTranslate(void 0)
11
+ t: /* @__PURE__ */ copy.createTranslate(void 0)
12
12
  });
13
13
  function CopyProvider(props) {
14
14
  const { locale, copy: copy$1, children } = props;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context.tsx","../src/hooks.ts"],"names":["createContext","createTranslate","copy","useMemo","textDirection","jsx","useContext","useSyncExternalStore","useRef","useCallback"],"mappings":";;;;;;;AAgBA,IAAM,cAAcA,mBAAA,CAAgC;AAAA,EAClD,MAAA,EAAQ,MAAA;AAAA,EACR,SAAA,EAAW,KAAA;AAAA,EACX,CAAA,EAAGC,qBAAgB,MAAS;AAC9B,CAAC,CAAA;AAEM,SAAS,aAAa,KAAA,EAIf;AACZ,EAAA,MAAM,EAAE,MAAA,QAAQC,MAAA,EAAM,QAAA,EAAS,GAAI,KAAA;AACnC,EAAA,MAAM,KAAA,GAAQC,aAAA;AAAA,IACZ,OAAO;AAAA,MACL,MAAA;AAAA,MACA,SAAA,EAAWC,mBAAc,MAAM,CAAA;AAAA,MAC/B,CAAA,EAAGH,oBAAA,CAAgB,MAAA,EAAQC,MAAI;AAAA,KACjC,CAAA;AAAA,IACA,CAAC,QAAQA,MAAI;AAAA,GACf;AACA,EAAA,uBAAOG,cAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD;AAGO,SAAS,OAAA,GAA4B;AAC1C,EAAA,OAAOC,iBAAW,WAAW,CAAA;AAC/B;ACxBO,SAAS,gBAAgB,MAAA,EAA8C;AAC5E,EAAA,OAAOC,0BAAA;AAAA,IACL,MAAA,CAAO,SAAA;AAAA,IACP,MAAA,CAAO,WAAA;AAAA,IACP,MAAA,CAAO;AAAA,GACT;AACF;AAMO,SAAS,uBAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,GAAmC,OAAO,EAAA,EACvC;AACH,EAAA,MAAM,IAAA,GAAOC,aAAoD,IAAI,CAAA;AACrE,EAAA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kBAAA,EAAoB,GAAA,EAAK,GAAG,CAAA;AACjE","file":"index.cjs","sourcesContent":["// The copy a component tree uses, from a provider: the locale's built-in words with the tenant's overrides on top.\n\nimport {\n type CopyOverrides,\n createTranslate,\n type Translate,\n textDirection,\n} from '@vinaverse/tokens/copy';\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\nexport interface CopyContextValue {\n readonly locale: string | undefined;\n readonly direction: 'ltr' | 'rtl';\n readonly t: Translate;\n}\n\nconst CopyContext = createContext<CopyContextValue>({\n locale: undefined,\n direction: 'ltr',\n t: createTranslate(undefined),\n});\n\nexport function CopyProvider(props: {\n readonly locale?: string | undefined;\n readonly copy?: CopyOverrides | undefined;\n readonly children?: ReactNode;\n}): ReactNode {\n const { locale, copy, children } = props;\n const value = useMemo<CopyContextValue>(\n () => ({\n locale,\n direction: textDirection(locale),\n t: createTranslate(locale, copy),\n }),\n [locale, copy],\n );\n return <CopyContext.Provider value={value}>{children}</CopyContext.Provider>;\n}\n\n/** The translator, the locale and its text direction. */\nexport function useCopy(): CopyContextValue {\n return useContext(CopyContext);\n}\n","// The React bindings of the conversation store: thin by design. Every protocol rule lives in @vinaverse/client; these\n// hooks only subscribe, and re-render a component when the slice it reads changed.\n\nimport type {\n ConversationView,\n StreamingText,\n} from '@vinaverse/client/conversation';\nimport { useCallback, useRef, useSyncExternalStore } from 'react';\n\n/** What the hooks read: a conversation store, or anything with the same four members (a test's fake). */\nexport interface ConversationSource {\n getSnapshot(): ConversationView;\n subscribe(listener: () => void): () => void;\n getStreaming(): StreamingText | null;\n subscribeStreaming(listener: () => void): () => void;\n}\n\n/** The whole view; re-renders on every change of it. Prefer `useConversationSelector` in anything drawn often. */\nexport function useConversation(source: ConversationSource): ConversationView {\n return useSyncExternalStore(\n source.subscribe,\n source.getSnapshot,\n source.getSnapshot,\n );\n}\n\n/**\n * A slice of the view; re-renders only when the slice changed by `isEqual` (default `Object.is`). The view is\n * structurally shared, so selecting `items`, one item, or a field compares by identity.\n */\nexport function useConversationSelector<T>(\n source: ConversationSource,\n selector: (view: ConversationView) => T,\n isEqual: (a: T, b: T) => boolean = Object.is,\n): T {\n const last = useRef<{ view: ConversationView; value: T } | null>(null);\n const select = useRef(selector);\n select.current = selector;\n const compare = useRef(isEqual);\n compare.current = isEqual;\n const get = useCallback((): T => {\n const view = source.getSnapshot();\n const held = last.current;\n if (held?.view === view) return held.value;\n const value = select.current(view);\n if (held && compare.current(held.value, value)) {\n last.current = { view, value: held.value };\n return held.value;\n }\n last.current = { view, value };\n return value;\n }, [source]);\n return useSyncExternalStore(source.subscribe, get, get);\n}\n\n/**\n * The streamed text of the message with this `key`, or null when it is not the one streaming: only the streaming\n * bubble calls it, and only it re-renders as the reply arrives (at most once per frame).\n */\nexport function useStreamingText(\n source: ConversationSource,\n key: string,\n): string | null {\n const get = useCallback(() => {\n const streaming = source.getStreaming();\n return streaming?.key === key ? streaming.text : null;\n }, [source, key]);\n return useSyncExternalStore(source.subscribeStreaming, get, get);\n}\n"]}
1
+ {"version":3,"sources":["../src/context.tsx","../src/hooks.ts"],"names":["createContext","copy","useMemo","textDirection","createTranslate","jsx","useContext","useSyncExternalStore","useRef","useCallback"],"mappings":";;;;;;;AAgBA,IAAM,8BAA8BA,mBAAA,CAAgC;AAAA,EAClE,MAAA,EAAQ,MAAA;AAAA,EACR,SAAA,EAAW,KAAA;AAAA,EACX,CAAA,uCAAmC,MAAS;AAC9C,CAAC,CAAA;AAEM,SAAS,aAAa,KAAA,EAIf;AACZ,EAAA,MAAM,EAAE,MAAA,QAAQC,MAAA,EAAM,QAAA,EAAS,GAAI,KAAA;AACnC,EAAA,MAAM,KAAA,GAAQC,aAAA;AAAA,IACZ,OAAO;AAAA,MACL,MAAA;AAAA,MACA,SAAA,EAAWC,mBAAc,MAAM,CAAA;AAAA,MAC/B,CAAA,EAAGC,oBAAA,CAAgB,MAAA,EAAQH,MAAI;AAAA,KACjC,CAAA;AAAA,IACA,CAAC,QAAQA,MAAI;AAAA,GACf;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AAA;AAAA,EACT,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AACX,EAAA,OAAOF,0BAAA,CAAqB,MAAA,CAAO,SAAA,EAAW,GAAA,EAAK,GAAG,CAAA;AACxD;AAMO,SAAS,gBAAA,CACd,QACA,GAAA,EACe;AACf,EAAA,MAAM,GAAA,GAAME,kBAAY,MAAM;AAC5B,IAAA,MAAM,SAAA,GAAY,OAAO,YAAA,EAAa;AACtC,IAAA,OAAO,SAAA,EAAW,GAAA,KAAQ,GAAA,GAAM,SAAA,CAAU,IAAA,GAAO,IAAA;AAAA,EACnD,CAAA,EAAG,CAAC,MAAA,EAAQ,GAAG,CAAC,CAAA;AAChB,EAAA,OAAOF,0BAAA,CAAqB,MAAA,CAAO,kBAAA,EAAoB,GAAA,EAAK,GAAG,CAAA;AACjE","file":"index.cjs","sourcesContent":["// The copy a component tree uses, from a provider: the locale's built-in words with the tenant's overrides on top.\n\nimport {\n type CopyOverrides,\n createTranslate,\n type Translate,\n textDirection,\n} from '@vinaverse/tokens/copy';\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\nexport interface CopyContextValue {\n readonly locale: string | undefined;\n readonly direction: 'ltr' | 'rtl';\n readonly t: Translate;\n}\n\nconst CopyContext = /* @__PURE__ */ createContext<CopyContextValue>({\n locale: undefined,\n direction: 'ltr',\n t: /* @__PURE__ */ createTranslate(undefined),\n});\n\nexport function CopyProvider(props: {\n readonly locale?: string | undefined;\n readonly copy?: CopyOverrides | undefined;\n readonly children?: ReactNode;\n}): ReactNode {\n const { locale, copy, children } = props;\n const value = useMemo<CopyContextValue>(\n () => ({\n locale,\n direction: textDirection(locale),\n t: createTranslate(locale, copy),\n }),\n [locale, copy],\n );\n return <CopyContext.Provider value={value}>{children}</CopyContext.Provider>;\n}\n\n/** The translator, the locale and its text direction. */\nexport function useCopy(): CopyContextValue {\n return useContext(CopyContext);\n}\n","// The React bindings of the conversation store: thin by design. Every protocol rule lives in @vinaverse/client; these\n// hooks only subscribe, and re-render a component when the slice it reads changed.\n\nimport type {\n ConversationView,\n StreamingText,\n} from '@vinaverse/client/conversation';\nimport { useCallback, useRef, useSyncExternalStore } from 'react';\n\n/** What the hooks read: a conversation store, or anything with the same four members (a test's fake). */\nexport interface ConversationSource {\n getSnapshot(): ConversationView;\n subscribe(listener: () => void): () => void;\n getStreaming(): StreamingText | null;\n subscribeStreaming(listener: () => void): () => void;\n}\n\n/** The whole view; re-renders on every change of it. Prefer `useConversationSelector` in anything drawn often. */\nexport function useConversation(source: ConversationSource): ConversationView {\n return useSyncExternalStore(\n source.subscribe,\n source.getSnapshot,\n source.getSnapshot,\n );\n}\n\n/**\n * A slice of the view; re-renders only when the slice changed by `isEqual` (default `Object.is`). The view is\n * structurally shared, so selecting `items`, one item, or a field compares by identity.\n */\nexport function useConversationSelector<T>(\n source: ConversationSource,\n selector: (view: ConversationView) => T,\n isEqual: (a: T, b: T) => boolean = Object.is,\n): T {\n const last = useRef<{ view: ConversationView; value: T } | null>(null);\n const select = useRef(selector);\n select.current = selector;\n const compare = useRef(isEqual);\n compare.current = isEqual;\n const get = useCallback((): T => {\n const view = source.getSnapshot();\n const held = last.current;\n if (held?.view === view) return held.value;\n const value = select.current(view);\n if (held && compare.current(held.value, value)) {\n last.current = { view, value: held.value };\n return held.value;\n }\n last.current = { view, value };\n return value;\n }, [source]);\n return useSyncExternalStore(source.subscribe, get, get);\n}\n\n/**\n * The streamed text of the message with this `key`, or null when it is not the one streaming: only the streaming\n * bubble calls it, and only it re-renders as the reply arrives (at most once per frame).\n */\nexport function useStreamingText(\n source: ConversationSource,\n key: string,\n): string | null {\n const get = useCallback(() => {\n const streaming = source.getStreaming();\n return streaming?.key === key ? streaming.text : null;\n }, [source, key]);\n return useSyncExternalStore(source.subscribeStreaming, get, get);\n}\n"]}
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createTranslate, textDirection } from '@vinaverse/tokens/copy';
2
2
  export { AI_MARK, BANNED_WORDS, COPY, bannedWordsIn, builtInCopy, createTranslate, formatDate, formatMoney, formatTimeRange, textDirection } from '@vinaverse/tokens/copy';
3
- import { createContext, useMemo, useContext, useSyncExternalStore, useRef, useCallback } from 'react';
3
+ import { useMemo, useContext, useSyncExternalStore, useRef, useCallback, createContext } from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
6
  // src/index.ts
7
- var CopyContext = createContext({
7
+ var CopyContext = /* @__PURE__ */ createContext({
8
8
  locale: void 0,
9
9
  direction: "ltr",
10
- t: createTranslate(void 0)
10
+ t: /* @__PURE__ */ createTranslate(void 0)
11
11
  });
12
12
  function CopyProvider(props) {
13
13
  const { locale, copy, children } = props;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/context.tsx","../src/hooks.ts"],"names":[],"mappings":";;;;;;AAgBA,IAAM,cAAc,aAAA,CAAgC;AAAA,EAClD,MAAA,EAAQ,MAAA;AAAA,EACR,SAAA,EAAW,KAAA;AAAA,EACX,CAAA,EAAG,gBAAgB,MAAS;AAC9B,CAAC,CAAA;AAEM,SAAS,aAAa,KAAA,EAIf;AACZ,EAAA,MAAM,EAAE,MAAA,EAAQ,IAAA,EAAM,QAAA,EAAS,GAAI,KAAA;AACnC,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,OAAO;AAAA,MACL,MAAA;AAAA,MACA,SAAA,EAAW,cAAc,MAAM,CAAA;AAAA,MAC/B,CAAA,EAAG,eAAA,CAAgB,MAAA,EAAQ,IAAI;AAAA,KACjC,CAAA;AAAA,IACA,CAAC,QAAQ,IAAI;AAAA,GACf;AACA,EAAA,uBAAO,GAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD;AAGO,SAAS,OAAA,GAA4B;AAC1C,EAAA,OAAO,WAAW,WAAW,CAAA;AAC/B;ACxBO,SAAS,gBAAgB,MAAA,EAA8C;AAC5E,EAAA,OAAO,oBAAA;AAAA,IACL,MAAA,CA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O,YAAA,EAAa;AACtC,IAAA,OAAO,SAAA,EAAW,GAAA,KAAQ,GAAA,GAAM,SAAA,CAAU,IAAA,GAAO,IAAA;AAAA,EACnD,CAAA,EAAG,CAAC,MAAA,EAAQ,GAAG,CAAC,CAAA;AAChB,EAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,kBAAA,EAAoB,GAAA,EAAK,GAAG,CAAA;AACjE","file":"index.js","sourcesContent":["// The copy a component tree uses, from a provider: the locale's built-in words with the tenant's overrides on top.\n\nimport {\n type CopyOverrides,\n createTranslate,\n type Translate,\n textDirection,\n} from '@vinaverse/tokens/copy';\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\nexport interface CopyContextValue {\n readonly locale: string | undefined;\n readonly direction: 'ltr' | 'rtl';\n readonly t: Translate;\n}\n\nconst CopyContext = createContext<CopyContextValue>({\n locale: undefined,\n direction: 'ltr',\n t: createTranslate(undefined),\n});\n\nexport function CopyProvider(props: {\n readonly locale?: string | undefined;\n readonly copy?: CopyOverrides | undefined;\n readonly children?: ReactNode;\n}): ReactNode {\n const { locale, copy, children } = props;\n const value = useMemo<CopyContextValue>(\n () => ({\n locale,\n direction: textDirection(locale),\n t: createTranslate(locale, copy),\n }),\n [locale, copy],\n );\n return <CopyContext.Provider value={value}>{children}</CopyContext.Provider>;\n}\n\n/** The translator, the locale and its text direction. */\nexport function useCopy(): CopyContextValue {\n return useContext(CopyContext);\n}\n","// The React bindings of the conversation store: thin by design. Every protocol rule lives in @vinaverse/client; these\n// hooks only subscribe, and re-render a component when the slice it reads changed.\n\nimport type {\n ConversationView,\n StreamingText,\n} from '@vinaverse/client/conversation';\nimport { useCallback, useRef, useSyncExternalStore } from 'react';\n\n/** What the hooks read: a conversation store, or anything with the same four members (a test's fake). */\nexport interface ConversationSource {\n getSnapshot(): ConversationView;\n subscribe(listener: () => void): () => void;\n getStreaming(): StreamingText | null;\n subscribeStreaming(listener: () => void): () => void;\n}\n\n/** The whole view; re-renders on every change of it. Prefer `useConversationSelector` in anything drawn often. */\nexport function useConversation(source: ConversationSource): ConversationView {\n return useSyncExternalStore(\n source.subscribe,\n source.getSnapshot,\n source.getSnapshot,\n );\n}\n\n/**\n * A slice of the view; re-renders only when the slice changed by `isEqual` (default `Object.is`). The view is\n * structurally shared, so selecting `items`, one item, or a field compares by identity.\n */\nexport function useConversationSelector<T>(\n source: ConversationSource,\n selector: (view: ConversationView) => T,\n isEqual: (a: T, b: T) => boolean = Object.is,\n): T {\n const last = useRef<{ view: ConversationView; value: T } | null>(null);\n const select = useRef(selector);\n select.current = selector;\n const compare = useRef(isEqual);\n compare.current = isEqual;\n const get = useCallback((): T => {\n const view = source.getSnapshot();\n const held = last.current;\n if (held?.view === view) return held.value;\n const value = select.current(view);\n if (held && compare.current(held.value, value)) {\n last.current = { view, value: held.value };\n return held.value;\n }\n last.current = { view, value };\n return value;\n }, [source]);\n return useSyncExternalStore(source.subscribe, get, get);\n}\n\n/**\n * The streamed text of the message with this `key`, or null when it is not the one streaming: only the streaming\n * bubble calls it, and only it re-renders as the reply arrives (at most once per frame).\n */\nexport function useStreamingText(\n source: ConversationSource,\n key: string,\n): string | null {\n const get = useCallback(() => {\n const streaming = source.getStreaming();\n return streaming?.key === key ? streaming.text : null;\n }, [source, key]);\n return useSyncExternalStore(source.subscribeStreaming, get, get);\n}\n"]}
1
+ {"version":3,"sources":["../src/context.tsx","../src/hooks.ts"],"names":[],"mappings":";;;;;;AAgBA,IAAM,8BAA8B,aAAA,CAAgC;AAAA,EAClE,MAAA,EAAQ,MAAA;AAAA,EACR,SAAA,EAAW,KAAA;AAAA,EACX,CAAA,kCAAmC,MAAS;AAC9C,CAAC,CAAA;AAEM,SAAS,aAAa,KAAA,EAIf;AACZ,EAAA,MAAM,EAAE,MAAA,EAAQ,IAAA,EAAM,QAAA,EAAS,GAAI,KAAA;AACnC,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,OAAO;AAAA,MACL,MAAA;AAAA,MACA,SAAA,EAAW,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AAA,OAAO,IAAA,CAAK,KAAA;AAAA,IACd;AACA,IAAA,IAAA,CAAK,OAAA,GAAU,EAAE,IAAA,EAAM,KAAA,EAAM;AAC7B,IAAA,OAAO,KAAA;AAAA,EACT,CAAA,EAAG,CAAC,MAAM,CAAC,CAAA;AACX,EAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,SAAA,EAAW,GAAA,EAAK,GAAG,CAAA;AACxD;AAMO,SAAS,gBAAA,CACd,QACA,GAAA,EACe;AACf,EAAA,MAAM,GAAA,GAAM,YAAY,MAAM;AAC5B,IAAA,MAAM,SAAA,GAAY,OAAO,YAAA,EAAa;AACtC,IAAA,OAAO,SAAA,EAAW,GAAA,KAAQ,GAAA,GAAM,SAAA,CAAU,IAAA,GAAO,IAAA;AAAA,EACnD,CAAA,EAAG,CAAC,MAAA,EAAQ,GAAG,CAAC,CAAA;AAChB,EAAA,OAAO,oBAAA,CAAqB,MAAA,CAAO,kBAAA,EAAoB,GAAA,EAAK,GAAG,CAAA;AACjE","file":"index.js","sourcesContent":["// The copy a component tree uses, from a provider: the locale's built-in words with the tenant's overrides on top.\n\nimport {\n type CopyOverrides,\n createTranslate,\n type Translate,\n textDirection,\n} from '@vinaverse/tokens/copy';\nimport { createContext, type ReactNode, useContext, useMemo } from 'react';\n\nexport interface CopyContextValue {\n readonly locale: string | undefined;\n readonly direction: 'ltr' | 'rtl';\n readonly t: Translate;\n}\n\nconst CopyContext = /* @__PURE__ */ createContext<CopyContextValue>({\n locale: undefined,\n direction: 'ltr',\n t: /* @__PURE__ */ createTranslate(undefined),\n});\n\nexport function CopyProvider(props: {\n readonly locale?: string | undefined;\n readonly copy?: CopyOverrides | undefined;\n readonly children?: ReactNode;\n}): ReactNode {\n const { locale, copy, children } = props;\n const value = useMemo<CopyContextValue>(\n () => ({\n locale,\n direction: textDirection(locale),\n t: createTranslate(locale, copy),\n }),\n [locale, copy],\n );\n return <CopyContext.Provider value={value}>{children}</CopyContext.Provider>;\n}\n\n/** The translator, the locale and its text direction. */\nexport function useCopy(): CopyContextValue {\n return useContext(CopyContext);\n}\n","// The React bindings of the conversation store: thin by design. Every protocol rule lives in @vinaverse/client; these\n// hooks only subscribe, and re-render a component when the slice it reads changed.\n\nimport type {\n ConversationView,\n StreamingText,\n} from '@vinaverse/client/conversation';\nimport { useCallback, useRef, useSyncExternalStore } from 'react';\n\n/** What the hooks read: a conversation store, or anything with the same four members (a test's fake). */\nexport interface ConversationSource {\n getSnapshot(): ConversationView;\n subscribe(listener: () => void): () => void;\n getStreaming(): StreamingText | null;\n subscribeStreaming(listener: () => void): () => void;\n}\n\n/** The whole view; re-renders on every change of it. Prefer `useConversationSelector` in anything drawn often. */\nexport function useConversation(source: ConversationSource): ConversationView {\n return useSyncExternalStore(\n source.subscribe,\n source.getSnapshot,\n source.getSnapshot,\n );\n}\n\n/**\n * A slice of the view; re-renders only when the slice changed by `isEqual` (default `Object.is`). The view is\n * structurally shared, so selecting `items`, one item, or a field compares by identity.\n */\nexport function useConversationSelector<T>(\n source: ConversationSource,\n selector: (view: ConversationView) => T,\n isEqual: (a: T, b: T) => boolean = Object.is,\n): T {\n const last = useRef<{ view: ConversationView; value: T } | null>(null);\n const select = useRef(selector);\n select.current = selector;\n const compare = useRef(isEqual);\n compare.current = isEqual;\n const get = useCallback((): T => {\n const view = source.getSnapshot();\n const held = last.current;\n if (held?.view === view) return held.value;\n const value = select.current(view);\n if (held && compare.current(held.value, value)) {\n last.current = { view, value: held.value };\n return held.value;\n }\n last.current = { view, value };\n return value;\n }, [source]);\n return useSyncExternalStore(source.subscribe, get, get);\n}\n\n/**\n * The streamed text of the message with this `key`, or null when it is not the one streaming: only the streaming\n * bubble calls it, and only it re-renders as the reply arrives (at most once per frame).\n */\nexport function useStreamingText(\n source: ConversationSource,\n key: string,\n): string | null {\n const get = useCallback(() => {\n const streaming = source.getStreaming();\n return streaming?.key === key ? streaming.text : null;\n }, [source, key]);\n return useSyncExternalStore(source.subscribeStreaming, get, get);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinaverse/react",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Vinaverse for React: hooks over the conversation store, and the copy and formatting every Vinaverse React UI shares. No react-native or DOM import.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Vinaverse, Inc.",
@@ -29,6 +29,16 @@
29
29
  "default": "./dist/index.cjs"
30
30
  }
31
31
  },
32
+ "./agent": {
33
+ "import": {
34
+ "types": "./dist/agent.d.ts",
35
+ "default": "./dist/agent.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/agent.d.cts",
39
+ "default": "./dist/agent.cjs"
40
+ }
41
+ },
32
42
  "./package.json": "./package.json"
33
43
  },
34
44
  "main": "./dist/index.cjs",
@@ -38,8 +48,8 @@
38
48
  "dist"
39
49
  ],
40
50
  "dependencies": {
41
- "@vinaverse/client": "0.1.0-alpha.4",
42
- "@vinaverse/tokens": "0.1.0-alpha.4"
51
+ "@vinaverse/client": "0.1.0-alpha.6",
52
+ "@vinaverse/tokens": "0.1.0-alpha.6"
43
53
  },
44
54
  "peerDependencies": {
45
55
  "react": ">=19.1"
@@ -57,11 +67,32 @@
57
67
  "react",
58
68
  "react/jsx-runtime",
59
69
  "@vinaverse/client",
60
- "@vinaverse/tokens/copy"
70
+ "@vinaverse/tokens/copy",
71
+ "@vinaverse/client/agent"
72
+ ],
73
+ "limit": "1.5 kB"
74
+ },
75
+ {
76
+ "name": "@vinaverse/react/agent (ESM, everything; react and the other @vinaverse packages excluded)",
77
+ "path": "dist/agent.js",
78
+ "import": "*",
79
+ "ignore": [
80
+ "react",
81
+ "react/jsx-runtime",
82
+ "@vinaverse/client",
83
+ "@vinaverse/tokens/copy",
84
+ "@vinaverse/client/agent"
61
85
  ],
62
86
  "limit": "1.5 kB"
63
87
  }
64
88
  ],
89
+ "typesVersions": {
90
+ "*": {
91
+ "agent": [
92
+ "./dist/agent.d.cts"
93
+ ]
94
+ }
95
+ },
65
96
  "scripts": {
66
97
  "build": "tsup",
67
98
  "typecheck": "tsc --noEmit -p tsconfig.json",