From 41bb749ddef785740c9911d97a03249337b3856d Mon Sep 17 00:00:00 2001 From: Surajsm60720 <1ds22is166@dsce.edu.in> Date: Thu, 19 Nov 2026 07:11:48 +0530 Subject: [PATCH 1/4] feat(kin): ask an agent about a task or project The task sheet and the project page, on web and mobile, now offer to ask an agent the viewer can message. One agent is asked directly; several are picked from a menu. The chat opens with the record's key and name drafted, so a project no longer starts an empty ask. Co-Authored-By: Claude Opus 5.5 --- .../src/features/chats/KinProjectScreen.tsx | 6 +- .../src/features/chats/KinWorkItemScreen.tsx | 6 +- .../features/chats/state/useKinAskRecord.ts | 54 ++++++++++++ apps/web/src/kin/KinAskRecord.tsx | 62 ++++++++++++++ apps/web/src/kin/KinWorkItemSheet.tsx | 16 +++- apps/web/src/kin/KinWorkProjects.tsx | 82 +++++++++++-------- packages/client-runtime/package.json | 4 + .../src/kin/kinAskRecord.test.ts | 41 ++++++++++ .../client-runtime/src/kin/kinAskRecord.ts | 48 +++++++++++ 9 files changed, 279 insertions(+), 40 deletions(-) create mode 100644 apps/mobile/src/features/chats/state/useKinAskRecord.ts create mode 100644 apps/web/src/kin/KinAskRecord.tsx create mode 100644 packages/client-runtime/src/kin/kinAskRecord.test.ts create mode 100644 packages/client-runtime/src/kin/kinAskRecord.ts diff --git a/apps/mobile/src/features/chats/KinProjectScreen.tsx b/apps/mobile/src/features/chats/KinProjectScreen.tsx index 39ee207892958..b5c6835a975cc 100644 --- a/apps/mobile/src/features/chats/KinProjectScreen.tsx +++ b/apps/mobile/src/features/chats/KinProjectScreen.tsx @@ -58,6 +58,7 @@ import { KinPlaceLists } from "./KinPlaceLists"; import { KinDocsUnder } from "./KinDocsList"; import { KinProjectPeopleSection } from "./KinProjectPeopleScreen"; import { kinClient } from "./state/kinClient"; +import { useKinAskRecord } from "./state/useKinAskRecord"; import { kinHostConnected, useKinGate } from "./state/useKinHost"; import { useKinProjectPage, @@ -212,6 +213,7 @@ function KinProjectBody( if (outcome.problem.kind === "conflict") props.onRefresh(); } }; + const asker = useKinAskRecord(props, { key: view.key, title: view.name }); const openTask = (task: KinRecordKey) => openRecord("KinWorkItem", { environmentId, orgId, task }); return ( @@ -229,6 +231,7 @@ function KinProjectBody( bar: canChange ? { actions: [ + ...asker.actions, { accessibilityLabel: KIN_PROJECTS.edit, icon: "pencil", @@ -242,6 +245,7 @@ function KinProjectBody( }, ], menus: [ + ...asker.menus, { title: "More", icon: "ellipsis", @@ -273,7 +277,7 @@ function KinProjectBody( }, ], } - : {}, + : asker, header: ( <> navigation.goBack(); + const task = state._tag === "ready" && state.item.list === undefined ? state.item : null; + const asker = useKinAskRecord(props, task === null ? null : { key: task.key, title: task.title }); if (state._tag !== "ready") { return ( @@ -648,7 +651,8 @@ function KinWorkItemBody(props: ItemTarget) { diff --git a/apps/mobile/src/features/chats/state/useKinAskRecord.ts b/apps/mobile/src/features/chats/state/useKinAskRecord.ts new file mode 100644 index 0000000000000..47210a5d6921b --- /dev/null +++ b/apps/mobile/src/features/chats/state/useKinAskRecord.ts @@ -0,0 +1,54 @@ +import { useAtomValue } from "@effect/atom-react"; +import { + KIN_ASK_RECORD, + kinAskAgents, + kinAskRecordDraft, +} from "@t3tools/client-runtime/kin/kinAskRecord"; +import * as Option from "effect/Option"; +import { AsyncResult } from "effect/reactivity"; + +import type { AppBarAction, AppBarMenu } from "../../../components/ui/AppBar"; +import { kinClient } from "./kinClient"; +import { useKinOpenChat } from "./useKinOpenChat"; +import type { KinWorkTarget } from "./useKinWork"; + +/** + * Ask an agent about a task or project, as app bar items: one agent is a button that asks it, several + * are a menu to pick from, none is nothing. The chat opens with the record named in its box. + */ +export function useKinAskRecord( + { environmentId, orgId }: KinWorkTarget, + record: { readonly key: string; readonly title: string } | null, +): { readonly actions: ReadonlyArray; readonly menus: ReadonlyArray } { + const openChat = useKinOpenChat(); + const result = useAtomValue(kinClient.leads({ environmentId, input: { orgId } })); + const agents = record === null ? [] : kinAskAgents(Option.getOrNull(AsyncResult.value(result))); + const [only] = agents; + if (record === null || only === undefined) return { actions: [], menus: [] }; + const draft = kinAskRecordDraft(record); + if (agents.length === 1) + return { + actions: [ + { + accessibilityLabel: KIN_ASK_RECORD.ask(only.name), + icon: "bubble.left", + onPress: () => openChat(environmentId, orgId, only.chatId, draft), + }, + ], + menus: [], + }; + return { + actions: [], + menus: [ + { + title: KIN_ASK_RECORD.askWho, + icon: "bubble.left", + items: agents.map((agent) => ({ + id: `ask-${agent.agentId}`, + title: agent.name, + onPress: () => openChat(environmentId, orgId, agent.chatId, draft), + })), + }, + ], + }; +} diff --git a/apps/web/src/kin/KinAskRecord.tsx b/apps/web/src/kin/KinAskRecord.tsx new file mode 100644 index 0000000000000..90a04378c3217 --- /dev/null +++ b/apps/web/src/kin/KinAskRecord.tsx @@ -0,0 +1,62 @@ +import { useAtomValue } from "@effect/atom-react"; +import { + KIN_ASK_RECORD, + kinAskAgents, + kinAskRecordDraft, + type KinAskAgent, +} from "@t3tools/client-runtime/kin/kinAskRecord"; +import * as Option from "effect/Option"; +import { AsyncResult } from "effect/reactivity"; +import { ChevronDownIcon, MessageSquareIcon } from "lucide-react"; + +import { Button } from "../components/ui/button"; +import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../components/ui/menu"; +import { kinClient } from "./kinClient"; +import { useKinOpenChat } from "./useKinOpenChat"; +import type { KinWorkTarget } from "./useKinWork"; + +/** + * Ask an agent about a task or project, with the record named in the chat's box. One agent is asked + * directly; several are picked from a menu. Nothing shows when the viewer can message no agent. + */ +export function KinAskRecord( + props: KinWorkTarget & { + readonly record: { readonly key: string; readonly title: string }; + readonly disabled?: boolean; + readonly onOpen?: () => void; + }, +) { + const { environmentId, orgId } = props; + const openChat = useKinOpenChat(); + const result = useAtomValue(kinClient.leads({ environmentId, input: { orgId } })); + const agents = kinAskAgents(Option.getOrNull(AsyncResult.value(result))); + const ask = (agent: KinAskAgent) => { + props.onOpen?.(); + openChat(environmentId, orgId, agent.chatId, kinAskRecordDraft(props.record)); + }; + const [only] = agents; + if (only === undefined) return null; + if (agents.length === 1) + return ( + + ); + return ( + + }> + + {KIN_ASK_RECORD.askWho} + + + + {agents.map((agent) => ( + ask(agent)}> + {agent.name} + + ))} + + + ); +} diff --git a/apps/web/src/kin/KinWorkItemSheet.tsx b/apps/web/src/kin/KinWorkItemSheet.tsx index 128fd1b013567..adbf3f61179da 100644 --- a/apps/web/src/kin/KinWorkItemSheet.tsx +++ b/apps/web/src/kin/KinWorkItemSheet.tsx @@ -132,6 +132,7 @@ import { KinWorkAudienceRow } from "./KinWorkShareRow"; import { KinWorkRow } from "./KinWorkTasks"; import { KinWorkSection as Section } from "./KinWorkParts"; import { KinWorkStateIcon } from "./KinWorkStateIcon"; +import { KinAskRecord } from "./KinAskRecord"; import { kinClient } from "./kinClient"; import { openDestination } from "./KinNotifications"; import { useNowMinuteMs } from "./useKinClock"; @@ -569,8 +570,15 @@ function KinWorkItem( {KIN_WORK_COPY.saving} ) : null} - {!more ? null : ( -
+
+ + {!more ? null : ( -
- )} + )} +
{edit !== null ? null : {view.title}} {view.remarks.map((remark) => ( diff --git a/apps/web/src/kin/KinWorkProjects.tsx b/apps/web/src/kin/KinWorkProjects.tsx index c91557ef6c7a3..810cf156fca74 100644 --- a/apps/web/src/kin/KinWorkProjects.tsx +++ b/apps/web/src/kin/KinWorkProjects.tsx @@ -42,6 +42,7 @@ import { } from "../components/ui/sheet"; import { Switch } from "../components/ui/switch"; import { useAtomCommand } from "../state/use-atom-command"; +import { KinAskRecord } from "./KinAskRecord"; import { KinAttentionSection } from "./KinAttention"; import { KinDocsUnder } from "./KinDocsList"; import { KinProjectNoteSection } from "./KinProjectNote"; @@ -205,42 +206,55 @@ function ProjectPage(

{view.terms}

)} - {canChange ? ( -
- - - - } +
+ + {canChange ? ( + <> + + + + } + > + + + + {view.closed === null ? ( + <> + void change({ state: "done" })}> + {KIN_PROJECTS.done} + + void change({ state: "dropped" })} + > + {KIN_PROJECTS.drop} + + + ) : ( + void change({ state: "open" })}> + {KIN_PROJECTS.reopen} - - ) : ( - void change({ state: "open" })}> - {KIN_PROJECTS.reopen} - - )} - - -
- ) : null} + )} + +
+ + ) : null} +
{view.why.length === 0 ? null : (

{view.why.join(" ")}

diff --git a/packages/client-runtime/package.json b/packages/client-runtime/package.json index a89b1caaca668..e5423b6c9f8ed 100644 --- a/packages/client-runtime/package.json +++ b/packages/client-runtime/package.json @@ -663,6 +663,10 @@ "types": "./src/kin/kinAnswers.ts", "default": "./src/kin/kinAnswers.ts" }, + "./kin/kinAskRecord": { + "types": "./src/kin/kinAskRecord.ts", + "default": "./src/kin/kinAskRecord.ts" + }, "./kin/kinAttention": { "types": "./src/kin/kinAttention.ts", "default": "./src/kin/kinAttention.ts" diff --git a/packages/client-runtime/src/kin/kinAskRecord.test.ts b/packages/client-runtime/src/kin/kinAskRecord.test.ts new file mode 100644 index 0000000000000..ea64f9341c5fb --- /dev/null +++ b/packages/client-runtime/src/kin/kinAskRecord.test.ts @@ -0,0 +1,41 @@ +import { KinChatId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { kinAskAgents, kinAskRecordDraft } from "./kinAskRecord.ts"; + +describe("kinAskRecordDraft", () => { + it.each([ + [ + "a task", + { key: "T-12", title: "Fix the payments test" }, + "About T-12 (Fix the payments test): ", + ], + // The canvas drafted nothing for a project, which had no card to name. + ["a project", { key: "P-3", title: "Website relaunch" }, "About P-3 (Website relaunch): "], + ["a record with no name", { key: "P-4", title: " " }, "About P-4: "], + ])("names %s by key and name", (_name, record, expected) => { + expect(kinAskRecordDraft(record)).toBe(expected); + }); +}); + +describe("kinAskAgents", () => { + const lead = (agentId: string, retired?: true) => ({ + agentId, + name: agentId, + ownerChatId: KinChatId.make(`own-${agentId}`), + ...(retired ? { retired: { at: "2026-01-01T00:00:00.000Z" } } : {}), + }); + const contact = (agentId: string) => ({ + agentId, + name: agentId, + chatId: KinChatId.make(`mine-${agentId}`), + }); + + it("reaches live own agents and teammates' agents in the viewer's own chats", () => { + const result = { + leads: [lead("ops"), lead("old", true)], + contacts: [contact("ops"), contact("sales")], + }; + expect(kinAskAgents(result).map((agent) => agent.chatId)).toEqual(["own-ops", "mine-sales"]); + }); +}); diff --git a/packages/client-runtime/src/kin/kinAskRecord.ts b/packages/client-runtime/src/kin/kinAskRecord.ts new file mode 100644 index 0000000000000..759f82841e583 --- /dev/null +++ b/packages/client-runtime/src/kin/kinAskRecord.ts @@ -0,0 +1,48 @@ +import type { KinChatId } from "@t3tools/contracts"; + +export const KIN_ASK_RECORD = { + askWho: "Ask an agent", + ask: (name: string) => `Ask ${name}`, +} as const; + +/** An agent the viewer can message, and the viewer's own chat with it. */ +export interface KinAskAgent { + readonly agentId: string; + readonly name: string; + readonly chatId: KinChatId; +} + +/** + * Who an Ask can go to: the viewer's own live agents, then the teammates' agents they may message, + * each in the viewer's own chat with it. + */ +export function kinAskAgents( + result: { + readonly leads: ReadonlyArray<{ + readonly agentId: string; + readonly name: string; + readonly ownerChatId: KinChatId; + readonly retired?: unknown; + }>; + readonly contacts?: ReadonlyArray | undefined; + } | null, +): ReadonlyArray { + if (result === null) return []; + const own = result.leads + .filter((lead) => lead.retired === undefined) + .map((lead) => ({ agentId: lead.agentId, name: lead.name, chatId: lead.ownerChatId })); + const seen = new Set(own.map((agent) => agent.agentId)); + const others = (result.contacts ?? []) + .filter((contact) => !seen.has(contact.agentId)) + .map((contact) => ({ agentId: contact.agentId, name: contact.name, chatId: contact.chatId })); + return [...own, ...others]; +} + +/** + * What an Ask about a task or a project starts with in the agent's composer: its key, which the + * agent looks it up by, and its name, so the person sees what they are asking about. + */ +export function kinAskRecordDraft(record: { readonly key: string; readonly title: string }) { + const title = record.title.trim(); + return title === "" ? `About ${record.key}: ` : `About ${record.key} (${title}): `; +} From 997f578a1d40f5d56f175282696bc58683430331 Mon Sep 17 00:00:00 2001 From: Surajsm60720 <1ds22is166@dsce.edu.in> Date: Thu, 19 Nov 2026 07:20:02 +0530 Subject: [PATCH 2/4] fix(kin): project actions wrap under the name on narrow screens Co-Authored-By: Claude Opus 5.5 --- apps/web/src/kin/KinWorkProjects.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/kin/KinWorkProjects.tsx b/apps/web/src/kin/KinWorkProjects.tsx index 810cf156fca74..544e4edfa987b 100644 --- a/apps/web/src/kin/KinWorkProjects.tsx +++ b/apps/web/src/kin/KinWorkProjects.tsx @@ -173,8 +173,8 @@ function ProjectPage( const summary = (
-
-
+
+

{view.name}

{view.health === null ? null : } From 3239f94c9a701730d3a77fdbb3a86ed7cf9ffe44 Mon Sep 17 00:00:00 2001 From: Surajsm60720 <1ds22is166@dsce.edu.in> Date: Thu, 19 Nov 2026 07:59:08 +0530 Subject: [PATCH 3/4] fix(kin): a long agent name in Ask stays inside the header Co-Authored-By: Claude Opus 5.5 --- apps/web/src/kin/KinAskRecord.tsx | 3 ++- packages/client-runtime/src/kin/kinAskRecord.test.ts | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/apps/web/src/kin/KinAskRecord.tsx b/apps/web/src/kin/KinAskRecord.tsx index 90a04378c3217..e3c3054ccafa2 100644 --- a/apps/web/src/kin/KinAskRecord.tsx +++ b/apps/web/src/kin/KinAskRecord.tsx @@ -40,7 +40,8 @@ export function KinAskRecord( return ( ); return ( diff --git a/packages/client-runtime/src/kin/kinAskRecord.test.ts b/packages/client-runtime/src/kin/kinAskRecord.test.ts index ea64f9341c5fb..3838538994cf0 100644 --- a/packages/client-runtime/src/kin/kinAskRecord.test.ts +++ b/packages/client-runtime/src/kin/kinAskRecord.test.ts @@ -5,12 +5,6 @@ import { kinAskAgents, kinAskRecordDraft } from "./kinAskRecord.ts"; describe("kinAskRecordDraft", () => { it.each([ - [ - "a task", - { key: "T-12", title: "Fix the payments test" }, - "About T-12 (Fix the payments test): ", - ], - // The canvas drafted nothing for a project, which had no card to name. ["a project", { key: "P-3", title: "Website relaunch" }, "About P-3 (Website relaunch): "], ["a record with no name", { key: "P-4", title: " " }, "About P-4: "], ])("names %s by key and name", (_name, record, expected) => { From 1bc86b19965a5fd8cee7b247f518d16b60fe8baf Mon Sep 17 00:00:00 2001 From: Surajsm60720 <1ds22is166@dsce.edu.in> Date: Thu, 19 Nov 2026 08:04:54 +0530 Subject: [PATCH 4/4] fix(mobile): a project's bar has one Ask, about the project The task list's own Ask stayed beside the new one on the owner's project screen: two identical buttons, the title squeezed to one letter. Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/features/chats/KinTasksList.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/mobile/src/features/chats/KinTasksList.tsx b/apps/mobile/src/features/chats/KinTasksList.tsx index 9aad4407ace3c..ee11937e1edfb 100644 --- a/apps/mobile/src/features/chats/KinTasksList.tsx +++ b/apps/mobile/src/features/chats/KinTasksList.tsx @@ -272,16 +272,14 @@ export function KinTasksList( title={props.title} refresh={{ accessibilityLabel: "Refresh", onPress: refresh }} actions={[ - ...(agent === null + // Inside a project, the project's own bar asks about the project instead. + ...(agent === null || within !== undefined ? [] : [ { accessibilityLabel: `Ask ${agent.name}`, icon: "bubble.left" as const, - onPress: () => - agent.ask( - kinWorkAskDraft("tasks", within === undefined ? narrowed : props.title), - ), + onPress: () => agent.ask(kinWorkAskDraft("tasks", narrowed)), }, ]), ...(add === null