@octavus/react 0.0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Octavus AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,55 @@
1
+ import { OctavusChatOptions, UIMessage, ChatStatus, UserMessageInput } from '@octavus/client-sdk';
2
+ export * from '@octavus/client-sdk';
3
+ export { ChatStatus, OctavusChatOptions, UserMessageInput } from '@octavus/client-sdk';
4
+
5
+ interface UseOctavusChatReturn {
6
+ /** All messages including the currently streaming one */
7
+ messages: UIMessage[];
8
+ /** Current status of the chat */
9
+ status: ChatStatus;
10
+ /** Error if status is 'error' */
11
+ error: Error | null;
12
+ /**
13
+ * Trigger the agent and optionally add a user message to the chat.
14
+ *
15
+ * @param triggerName - The trigger name defined in the agent's protocol.yaml
16
+ * @param input - Input parameters for the trigger (variable substitutions)
17
+ * @param options.userMessage - If provided, adds a user message to the chat before triggering
18
+ */
19
+ send: (triggerName: string, input?: Record<string, unknown>, options?: {
20
+ userMessage?: UserMessageInput;
21
+ }) => Promise<void>;
22
+ /** Stop the current streaming and finalize any partial message */
23
+ stop: () => void;
24
+ }
25
+ /**
26
+ * React hook for interacting with Octavus agents.
27
+ * Provides chat state management and streaming support.
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * function Chat({ sessionId }) {
32
+ * const { messages, status, send } = useOctavusChat({
33
+ * onTrigger: (triggerName, input) =>
34
+ * fetch('/api/trigger', {
35
+ * method: 'POST',
36
+ * body: JSON.stringify({ sessionId, triggerName, input }),
37
+ * }),
38
+ * });
39
+ *
40
+ * return (
41
+ * <div>
42
+ * {messages.map((msg) => (
43
+ * <Message key={msg.id} message={msg} />
44
+ * ))}
45
+ * <button onClick={() => send('user-message', { USER_MESSAGE: 'Hello' })}>
46
+ * Send
47
+ * </button>
48
+ * </div>
49
+ * );
50
+ * }
51
+ * ```
52
+ */
53
+ declare function useOctavusChat(options: OctavusChatOptions): UseOctavusChatReturn;
54
+
55
+ export { type UseOctavusChatReturn, useOctavusChat };
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ // src/hooks/use-octavus-chat.ts
2
+ import { useRef, useCallback, useSyncExternalStore } from "react";
3
+ import {
4
+ OctavusChat
5
+ } from "@octavus/client-sdk";
6
+ function useOctavusChat(options) {
7
+ const chatRef = useRef(null);
8
+ chatRef.current ??= new OctavusChat(options);
9
+ const chat = chatRef.current;
10
+ const subscribe = useCallback((callback) => chat.subscribe(callback), [chat]);
11
+ const getMessagesSnapshot = useCallback(() => chat.messages, [chat]);
12
+ const getStatusSnapshot = useCallback(() => chat.status, [chat]);
13
+ const getErrorSnapshot = useCallback(() => chat.error, [chat]);
14
+ const messages = useSyncExternalStore(subscribe, getMessagesSnapshot, getMessagesSnapshot);
15
+ const status = useSyncExternalStore(subscribe, getStatusSnapshot, getStatusSnapshot);
16
+ const error = useSyncExternalStore(subscribe, getErrorSnapshot, getErrorSnapshot);
17
+ const send = useCallback(
18
+ (triggerName, input, sendOptions) => chat.send(triggerName, input, sendOptions),
19
+ [chat]
20
+ );
21
+ const stop = useCallback(() => chat.stop(), [chat]);
22
+ return {
23
+ messages,
24
+ status,
25
+ error,
26
+ send,
27
+ stop
28
+ };
29
+ }
30
+
31
+ // src/index.ts
32
+ export * from "@octavus/client-sdk";
33
+ export {
34
+ useOctavusChat
35
+ };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-octavus-chat.ts","../src/index.ts"],"sourcesContent":["'use client';\n\nimport { useRef, useCallback, useSyncExternalStore } from 'react';\nimport {\n OctavusChat,\n type OctavusChatOptions,\n type ChatStatus,\n type UserMessageInput,\n type UIMessage,\n} from '@octavus/client-sdk';\n\nexport type { OctavusChatOptions, ChatStatus, UserMessageInput };\n\nexport interface UseOctavusChatReturn {\n /** All messages including the currently streaming one */\n messages: UIMessage[];\n /** Current status of the chat */\n status: ChatStatus;\n /** Error if status is 'error' */\n error: Error | null;\n /**\n * Trigger the agent and optionally add a user message to the chat.\n *\n * @param triggerName - The trigger name defined in the agent's protocol.yaml\n * @param input - Input parameters for the trigger (variable substitutions)\n * @param options.userMessage - If provided, adds a user message to the chat before triggering\n */\n send: (\n triggerName: string,\n input?: Record<string, unknown>,\n options?: { userMessage?: UserMessageInput },\n ) => Promise<void>;\n /** Stop the current streaming and finalize any partial message */\n stop: () => void;\n}\n\n/**\n * React hook for interacting with Octavus agents.\n * Provides chat state management and streaming support.\n *\n * @example\n * ```tsx\n * function Chat({ sessionId }) {\n * const { messages, status, send } = useOctavusChat({\n * onTrigger: (triggerName, input) =>\n * fetch('/api/trigger', {\n * method: 'POST',\n * body: JSON.stringify({ sessionId, triggerName, input }),\n * }),\n * });\n *\n * return (\n * <div>\n * {messages.map((msg) => (\n * <Message key={msg.id} message={msg} />\n * ))}\n * <button onClick={() => send('user-message', { USER_MESSAGE: 'Hello' })}>\n * Send\n * </button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useOctavusChat(options: OctavusChatOptions): UseOctavusChatReturn {\n const chatRef = useRef<OctavusChat | null>(null);\n\n // Create chat instance once (stable reference)\n chatRef.current ??= new OctavusChat(options);\n\n const chat = chatRef.current;\n\n // Subscribe to all state changes using useSyncExternalStore\n // This provides automatic re-renders when state changes and proper SSR support\n const subscribe = useCallback((callback: () => void) => chat.subscribe(callback), [chat]);\n\n // Snapshot getters\n const getMessagesSnapshot = useCallback(() => chat.messages, [chat]);\n const getStatusSnapshot = useCallback(() => chat.status, [chat]);\n const getErrorSnapshot = useCallback(() => chat.error, [chat]);\n\n // Use useSyncExternalStore for each piece of state\n // This hook is available in React 18+ and handles:\n // - Subscription management\n // - Proper re-rendering on state changes\n // - SSR hydration (server snapshot)\n const messages = useSyncExternalStore(subscribe, getMessagesSnapshot, getMessagesSnapshot);\n const status = useSyncExternalStore(subscribe, getStatusSnapshot, getStatusSnapshot);\n const error = useSyncExternalStore(subscribe, getErrorSnapshot, getErrorSnapshot);\n\n // Stable method references\n const send = useCallback(\n (\n triggerName: string,\n input?: Record<string, unknown>,\n sendOptions?: { userMessage?: UserMessageInput },\n ) => chat.send(triggerName, input, sendOptions),\n [chat],\n );\n\n const stop = useCallback(() => chat.stop(), [chat]);\n\n return {\n messages,\n status,\n error,\n send,\n stop,\n };\n}\n","export {\n useOctavusChat,\n type UseOctavusChatReturn,\n type OctavusChatOptions,\n type ChatStatus,\n type UserMessageInput,\n} from './hooks/use-octavus-chat';\n\n// Re-export everything from client-sdk so consumers only need @octavus/react\nexport * from '@octavus/client-sdk';\n"],"mappings":";AAEA,SAAS,QAAQ,aAAa,4BAA4B;AAC1D;AAAA,EACE;AAAA,OAKK;AAuDA,SAAS,eAAe,SAAmD;AAChF,QAAM,UAAU,OAA2B,IAAI;AAG/C,UAAQ,YAAY,IAAI,YAAY,OAAO;AAE3C,QAAM,OAAO,QAAQ;AAIrB,QAAM,YAAY,YAAY,CAAC,aAAyB,KAAK,UAAU,QAAQ,GAAG,CAAC,IAAI,CAAC;AAGxF,QAAM,sBAAsB,YAAY,MAAM,KAAK,UAAU,CAAC,IAAI,CAAC;AACnE,QAAM,oBAAoB,YAAY,MAAM,KAAK,QAAQ,CAAC,IAAI,CAAC;AAC/D,QAAM,mBAAmB,YAAY,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC;AAO7D,QAAM,WAAW,qBAAqB,WAAW,qBAAqB,mBAAmB;AACzF,QAAM,SAAS,qBAAqB,WAAW,mBAAmB,iBAAiB;AACnF,QAAM,QAAQ,qBAAqB,WAAW,kBAAkB,gBAAgB;AAGhF,QAAM,OAAO;AAAA,IACX,CACE,aACA,OACA,gBACG,KAAK,KAAK,aAAa,OAAO,WAAW;AAAA,IAC9C,CAAC,IAAI;AAAA,EACP;AAEA,QAAM,OAAO,YAAY,MAAM,KAAK,KAAK,GAAG,CAAC,IAAI,CAAC;AAElD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ACpGA,cAAc;","names":[]}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@octavus/react",
3
+ "version": "0.0.6",
4
+ "description": "React bindings for Octavus agents",
5
+ "license": "MIT",
6
+ "author": "Octavus AI <hello@octavus.ai>",
7
+ "keywords": [
8
+ "octavus",
9
+ "ai",
10
+ "agents",
11
+ "sdk",
12
+ "react",
13
+ "streaming"
14
+ ],
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "dependencies": {
32
+ "@octavus/client-sdk": "^0.0.6"
33
+ },
34
+ "peerDependencies": {
35
+ "react": ">=18.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/react": "^19.0.0",
39
+ "react": "^19.0.0",
40
+ "tsup": "^8.3.5",
41
+ "typescript": "^5.6.3"
42
+ },
43
+ "scripts": {
44
+ "build": "tsup",
45
+ "dev": "tsup --watch",
46
+ "lint": "eslint src/ --max-warnings 0",
47
+ "lint:fix": "eslint src/ --max-warnings 0 --fix",
48
+ "type-check": "tsc --noEmit",
49
+ "clean": "rm -rf dist .turbo"
50
+ }
51
+ }