refactor: distribute types from crm-types.ts to owning composables

Each composable now owns its types and exports them. Other composables
import types from the owning composable. Deleted centralized crm-types.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ruslan Bakiev
2026-02-24 15:21:30 +07:00
parent a4d8d81de9
commit d892d0c604
14 changed files with 425 additions and 435 deletions

View File

@@ -12,17 +12,85 @@ import {
import { Chat as AiChat } from "@ai-sdk/vue";
import { DefaultChatTransport, isTextUIPart, type UIMessage } from "ai";
import { isVoiceCaptureSupported, transcribeAudioBlob } from "~/composables/useVoiceTranscription";
import type {
PilotMessage,
ChatConversation,
ContextScope,
PilotContextPayload,
CalendarView,
Contact,
CalendarEvent,
Deal,
} from "~/composables/crm-types";
import { safeTrim } from "~/composables/crm-types";
import type { Contact } from "~/composables/useContacts";
import type { CalendarView, CalendarEvent } from "~/composables/useCalendar";
import type { Deal } from "~/composables/useDeals";
export type PilotChangeItem = {
id: string;
entity: string;
entityId?: string | null;
action: string;
title: string;
before: string;
after: string;
rolledBack?: boolean;
};
export type PilotMessage = {
id: string;
role: "user" | "assistant" | "system";
text: string;
messageKind?: string | null;
requestId?: string | null;
eventType?: string | null;
phase?: string | null;
transient?: boolean | null;
thinking?: string[] | null;
tools?: string[] | null;
toolRuns?: Array<{
name: string;
status: "ok" | "error";
input: string;
output: string;
at: string;
}> | null;
changeSetId?: string | null;
changeStatus?: "pending" | "confirmed" | "rolled_back" | null;
changeSummary?: string | null;
changeItems?: PilotChangeItem[] | null;
createdAt?: string;
_live?: boolean;
};
export type ContextScope = "summary" | "deal" | "message" | "calendar";
export type PilotContextPayload = {
scopes: ContextScope[];
summary?: {
contactId: string;
name: string;
};
deal?: {
dealId: string;
title: string;
contact: string;
};
message?: {
contactId?: string;
contact?: string;
intent: "add_message_or_reminder";
};
calendar?: {
view: CalendarView;
period: string;
selectedDateKey: string;
focusedEventId?: string;
eventIds: string[];
};
};
export type ChatConversation = {
id: string;
title: string;
createdAt: string;
updatedAt: string;
lastMessageAt?: string | null;
lastMessageText?: string | null;
};
function safeTrim(value: unknown) { return String(value ?? "").trim(); }
export function usePilotChat(opts: {
apolloAuthReady: ComputedRef<boolean>;