@caltra/assistant-ui 0.0.0-stage → 0.1.0

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/README.md CHANGED
@@ -1,3 +1,29 @@
1
- # Temporary Holding Version
1
+ # @caltra/assistant-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The React adapter for a framework-neutral `CaltraSessionRuntime`. Imports no CSS and owns no transport lifecycle. Install `@caltra/client`, `@caltra/assistant-ui`, React, React DOM, and the supported `@assistant-ui/react` peer dependency.
4
+
5
+ ```tsx
6
+ import { useEffect, useState } from "react";
7
+ import { AssistantRuntimeProvider } from "@assistant-ui/react";
8
+ import { useAssistantUiRuntime } from "@caltra/assistant-ui";
9
+ import type { CaltraClient } from "@caltra/client";
10
+
11
+ function Chat({ client, sessionId }: { client: CaltraClient; sessionId: string }) {
12
+ const [session] = useState(() => client.createSessionRuntime({ sessionId }));
13
+ useEffect(() => {
14
+ void session.start().catch(() => undefined); // Observe session.getSnapshot().error for UI feedback.
15
+ return () => { void session.stop(); };
16
+ }, [session]);
17
+ const runtime = useAssistantUiRuntime(session);
18
+ return <AssistantRuntimeProvider runtime={runtime}>
19
+ {/* Compose your own ThreadPrimitive, MessagePrimitive and ComposerPrimitive UI. */}
20
+ </AssistantRuntimeProvider>;
21
+ }
22
+ // Remount Chat when client identity or sessionId changes, e.g. a keyed boundary.
23
+ ```
24
+
25
+ The caller starts and stops the Caltra runtime. Multiple adapters or chats may observe that same runtime without opening extra event streams; removing an adapter does not stop it. Each adapter owns its assistant-ui presentation state (including its composer draft), while messages and connection state come from the shared Caltra runtime. Treat a runtime identity change as a component remount boundary to discard previous assistant-ui message/composer state immediately.
26
+
27
+ Use upstream `useAui`, `useAuiState` and primitives directly inside `AssistantRuntimeProvider`. The adapter maps messages, tools, loading, send and cancellation. It does not enable unsupported server features: attachments, editing/regeneration, tool answers and branch persistence require corresponding Caltra backend support.
28
+
29
+ The adapter forwards the session runtime's authoritative turn state. `isRunning` remains true between messages and tools until the persisted turn completes, fails, or is cancelled. Servers without `is_running` retain legacy message-activity behavior. Turn completion does not prove a larger application workflow finished. For custom threads, use `scrollToBottomOnRunStart={false}` to preserve reading position when a new turn begins; CaltraChat applies this default automatically.
@@ -0,0 +1,5 @@
1
+ import { type AssistantRuntime } from "@assistant-ui/react";
2
+ import type { CaltraSessionRuntime } from "@caltra/client";
3
+ /** Maps an already-started Caltra session runtime into assistant-ui. Never starts or stops it. */
4
+ export declare function useAssistantUiRuntime(store: CaltraSessionRuntime): AssistantRuntime;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,gBAAgB,EAItB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,GAAG,gBAAgB,CAkDnF"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ "use client";
2
+ import { ExportedMessageRepository, useExternalStoreRuntime, } from "@assistant-ui/react";
3
+ import { useCallback, useMemo, useSyncExternalStore } from "react";
4
+ /** Maps an already-started Caltra session runtime into assistant-ui. Never starts or stops it. */
5
+ export function useAssistantUiRuntime(store) {
6
+ const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
7
+ const onNew = useCallback(async (message) => {
8
+ const text = message.content
9
+ .filter((part) => part.type === "text")
10
+ .map((part) => part.text)
11
+ .join("\n");
12
+ if (text === "")
13
+ throw new Error("Caltra currently accepts text messages only.");
14
+ await store.send(text);
15
+ }, [store]);
16
+ const messages = useMemo(() => snapshot.messages.map((message) => ({
17
+ content: [
18
+ ...(message.text ? [{ type: "text", text: message.text }] : []),
19
+ ...(message.tool_calls ?? []).map(tool => ({ type: "tool-call", toolCallId: tool.id, toolName: tool.name,
20
+ args: tool.arguments, argsText: JSON.stringify(tool.arguments),
21
+ ...(tool.status === "running" ? {} : { result: tool.result ?? null }),
22
+ isError: tool.status === "failed" || tool.status === "cancelled",
23
+ // Keep per-tool lifecycle distinct from the enclosing assistant message.
24
+ artifact: { caltraToolStatus: tool.status }, })),
25
+ ],
26
+ createdAt: new Date(message.created_at),
27
+ id: message.id,
28
+ role: message.role,
29
+ ...(message.role === "assistant" ? {
30
+ status: message.status === "streaming"
31
+ ? { type: "running" }
32
+ : message.status === "completed"
33
+ ? { type: "complete", reason: "stop" }
34
+ : { type: "incomplete", reason: message.status === "cancelled" ? "cancelled" : "error" },
35
+ } : {}),
36
+ })), [snapshot.messages]);
37
+ // Caltra owns a linear transcript. Replace the repository so removed optimistic
38
+ // IDs cannot survive as phantom edit/regeneration branches in assistant-ui.
39
+ const messageRepository = useMemo(() => ExportedMessageRepository.fromArray(messages), [messages]);
40
+ const runtime = useExternalStoreRuntime({
41
+ isLoading: !snapshot.historyLoaded,
42
+ isRunning: snapshot.isRunning,
43
+ isSendDisabled: snapshot.connection !== "connected",
44
+ messageRepository,
45
+ onNew,
46
+ // assistant-ui calls this from its native Cancel primitive. The store exposes
47
+ // failures via the existing alert; avoid an unhandled event-handler rejection.
48
+ onCancel: async () => { await store.cancel().catch(() => undefined); },
49
+ });
50
+ return runtime;
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,yBAAyB,EAKzB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACnE,kGAAkG;AAClG,MAAM,UAAU,qBAAqB,CAAC,KAA2B;IAC/D,MAAM,QAAQ,GAAG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a;QAClC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,cAAc,EAAE,QAAQ,CAAC,UAAU,KAAK,WAAW;QACnD,iBAAiB;QACjB,KAAK;QACL,8EAA8E;QAC9E,+EAA+E;QAC/E,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;KACvE,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
+ "type": "module",
3
+ "license": "MIT",
4
+ "engines": {
5
+ "node": ">=24.0.0"
6
+ },
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "registry": "https://registry.npmjs.org"
10
+ },
2
11
  "name": "@caltra/assistant-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
12
+ "version": "0.1.0",
13
+ "description": "assistant-ui adapter for framework-neutral Caltra session runtimes",
14
+ "sideEffects": false,
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "build": "tsc -p tsconfig.json",
26
+ "prebuild": "npm run build --workspace=@caltra/client",
27
+ "test": "vitest run tests",
28
+ "pretest": "npm run build --workspace=@caltra/client",
29
+ "typecheck": "tsc -p tsconfig.json --noEmit",
30
+ "pretypecheck": "npm run build --workspace=@caltra/client"
31
+ },
32
+ "dependencies": {
33
+ "@caltra/client": "0.10.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@assistant-ui/react": "^0.15.16",
37
+ "react": "^18.0.0 || ^19.0.0",
38
+ "react-dom": "^18.0.0 || ^19.0.0"
39
+ },
40
+ "devDependencies": {
41
+ "@assistant-ui/react": "0.15.16",
42
+ "@testing-library/react": "16.3.2",
43
+ "@types/react": "19.2.17",
44
+ "@types/react-dom": "19.2.3",
45
+ "jsdom": "30.0.1",
46
+ "react": "19.2.8",
47
+ "react-dom": "19.2.8",
48
+ "typescript": "5.9.3",
49
+ "vitest": "4.1.11"
50
+ },
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/caltra-dev/caltra-sdk.git",
54
+ "directory": "packages/assistant-ui"
55
+ }
56
+ }