From 5275bc55fca9ebb8538e450fd23f065abdbc0ce8 Mon Sep 17 00:00:00 2001 From: Naiyuan Qing <145280634+NevilleQingNY@users.noreply.github.com> Date: Mon, 2 Feb 2026 10:45:20 +0800 Subject: [PATCH] refactor(store): migrate device-id hook to @multica/store - Move useDeviceId from apps/web to packages/store/src/device-id.ts - Update imports in chat.tsx and use-gateway.ts to use @multica/store - Add uuid dependency to @multica/store Co-Authored-By: Claude Opus 4.5 --- apps/web/app/components/chat.tsx | 2 +- apps/web/app/hooks/use-gateway.ts | 2 +- packages/store/package.json | 1 + .../hooks/use-device-id.ts => packages/store/src/device-id.ts | 2 ++ packages/store/src/index.ts | 1 + packages/ui/src/components/hub-sidebar.tsx | 2 +- pnpm-lock.yaml | 3 +++ 7 files changed, 10 insertions(+), 3 deletions(-) rename apps/web/app/hooks/use-device-id.ts => packages/store/src/device-id.ts (97%) diff --git a/apps/web/app/components/chat.tsx b/apps/web/app/components/chat.tsx index 943274d9..e819c7e8 100644 --- a/apps/web/app/components/chat.tsx +++ b/apps/web/app/components/chat.tsx @@ -12,7 +12,7 @@ import { toast } from "@multica/ui/components/ui/sonner"; import { useMessages } from "../hooks/use-messages"; import { useGateway } from "../hooks/use-gateway"; import { useHubStore } from "@multica/store"; -import { useDeviceId } from "../hooks/use-device-id"; +import { useDeviceId } from "@multica/store"; import { useScrollFade } from "../hooks/use-scroll-fade"; import { cn } from "@multica/ui/lib/utils"; diff --git a/apps/web/app/hooks/use-gateway.ts b/apps/web/app/hooks/use-gateway.ts index bda4fa0f..74169676 100644 --- a/apps/web/app/hooks/use-gateway.ts +++ b/apps/web/app/hooks/use-gateway.ts @@ -1,6 +1,6 @@ import { useEffect, useRef, useState, useCallback } from "react" import { GatewayClient, type ConnectionState, type RoutedMessage } from "@multica/sdk" -import { useDeviceId } from "./use-device-id" +import { useDeviceId } from "@multica/store" import { GATEWAY_URL } from "../lib/config" interface UseGatewayOptions { diff --git a/packages/store/package.json b/packages/store/package.json index c5b323df..c9518c97 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -10,6 +10,7 @@ "dependencies": { "@multica/fetch": "workspace:*", "react": "catalog:", + "uuid": "^13.0.0", "zustand": "catalog:" }, "devDependencies": { diff --git a/apps/web/app/hooks/use-device-id.ts b/packages/store/src/device-id.ts similarity index 97% rename from apps/web/app/hooks/use-device-id.ts rename to packages/store/src/device-id.ts index 842d4551..7f88fc64 100644 --- a/apps/web/app/hooks/use-device-id.ts +++ b/packages/store/src/device-id.ts @@ -1,3 +1,5 @@ +"use client" + import { useSyncExternalStore } from "react" import { v7 as uuidv7 } from "uuid" diff --git a/packages/store/src/index.ts b/packages/store/src/index.ts index 052edefc..0f6fe37b 100644 --- a/packages/store/src/index.ts +++ b/packages/store/src/index.ts @@ -1,3 +1,4 @@ export { useHubStore } from "./hub" export type { HubInfo, Agent, HubStatus, HubStore } from "./hub" export { useHubInit } from "./hub-init" +export { useDeviceId } from "./device-id" diff --git a/packages/ui/src/components/hub-sidebar.tsx b/packages/ui/src/components/hub-sidebar.tsx index 99e34f4f..dbbd4df8 100644 --- a/packages/ui/src/components/hub-sidebar.tsx +++ b/packages/ui/src/components/hub-sidebar.tsx @@ -68,7 +68,7 @@ export function HubSidebar() { Agents createAgent()} title="Create agent"> - + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 87608cd1..d06f54bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -285,6 +285,9 @@ importers: react: specifier: 'catalog:' version: 19.2.3 + uuid: + specifier: ^13.0.0 + version: 13.0.0 zustand: specifier: 'catalog:' version: 5.0.10(@types/react@19.2.10)(react@19.2.3)(use-sync-external-store@1.6.0(react@19.2.3))