@aintela/chat 0.2.35 → 0.2.38

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.
@@ -26,22 +26,31 @@ import { Interaction } from '../../../../models/Interaction';
26
26
  */
27
27
  /** Default args shape when a registration omits its generic. */
28
28
  export type UiToolArgs = Record<string, unknown>;
29
- /** Context handed to every renderer. */
30
- export interface UiToolContext {
29
+ /**
30
+ * Context handed to every renderer.
31
+ *
32
+ * Generic over the tool's INPUT payload (`clientOutput`, i.e. the prefill / client data — the `In`
33
+ * param) and its ANSWER (`answer`'s value — the `Ans` param). Both default to `unknown`, so an
34
+ * un-parametrized registration behaves exactly as before; the codegen'd typed builder methods
35
+ * (e.g. `askUpdateProfile`) bind them so a host reads `ctx.clientOutput` and calls `ctx.answer` fully
36
+ * typed with no casts.
37
+ */
38
+ export interface UiToolContext<In = unknown, Ans = unknown> {
31
39
  /** Normalized tool name (`UI_` marker + `{Plugin}-`/`{Plugin}_` qualifier stripped). */
32
40
  name: string;
33
41
  /** This tool call's id — stable across the call's Composing→Executing→Done lifecycle. */
34
42
  callId: string;
35
- /** The tool RESULT, if any. May be an object or a (possibly double-encoded) JSON string. */
43
+ /** The tool RESULT, if any. May be an object or a (possibly double-encoded) JSON string. Kept
44
+ * `unknown`: this is what the tool RETURNED to the model, not necessarily the answer the user gave. */
36
45
  response: unknown;
37
46
  /**
38
- * The tool's CLIENT-ONLY output — the payload it wrote to its SDK `ToolClientOutput` sink,
39
- * already parsed. This is the preferred render source: it arrives correlated to THIS call (by
40
- * id) on the result event (so multiple UI calls never race), the LLM never saw it, and it
41
- * survives reload. `undefined` until the call has responded, or when the tool didn't opt in
42
- * (fall back to `args`). Replaces the old slot-id-correlated tool-event lookup over `parts`.
47
+ * The tool's CLIENT-ONLY output — the payload it wrote to its SDK client-data sink (`SetClientData`)
48
+ * or pushed as an ask-user prefill, already parsed. This is the preferred render source: it arrives
49
+ * correlated to THIS call (by id) on the result event (so multiple UI calls never race), the LLM never
50
+ * saw it, and it survives reload. `undefined` until the call has responded, or when the tool didn't opt
51
+ * in (fall back to `args`). Typed as `In` — the codegen binds it to the server descriptor's input shape.
43
52
  */
44
- clientOutput: unknown;
53
+ clientOutput: In;
45
54
  /** Sibling parts of the same interaction (e.g. present_tsx's compiled-JS event rides here). */
46
55
  parts: ReadonlyArray<InteractionPart>;
47
56
  /** The whole interaction this part belongs to. */
@@ -50,9 +59,16 @@ export interface UiToolContext {
50
59
  onGoing: boolean;
51
60
  /** True during historical replay / preview — actions must NOT re-fire side effects. */
52
61
  preview: boolean;
62
+ /**
63
+ * Submit the user's answer for this parked ask-user call, then let the library deliver it to the agent
64
+ * (via `answerHumanTool`, keyed by {@link callId}). A string is sent verbatim; anything else is
65
+ * JSON-serialized. Typed as `Ans` — the codegen binds it to the server descriptor's answer shape, so a
66
+ * host can't send the wrong payload. A no-op for render/action tools, which never park for an answer.
67
+ */
68
+ answer(value: Ans): void;
53
69
  }
54
70
  /** Context handed to actions — adds the host environment. */
55
- export interface UiToolActionContext extends UiToolContext {
71
+ export interface UiToolActionContext<In = unknown, Ans = unknown> extends UiToolContext<In, Ans> {
56
72
  /**
57
73
  * The host environment from `EnvironmentProvider` (e.g. `refreshDashboard`,
58
74
  * `createDashboardPad`). Empty `{}` when no provider is in scope or during
@@ -61,30 +77,30 @@ export interface UiToolActionContext extends UiToolContext {
61
77
  */
62
78
  env: Record<string, unknown>;
63
79
  }
64
- export type UiToolRenderFn<TArgs> = (args: TArgs, ctx: UiToolContext) => React.ReactNode;
65
- export type UiToolActionFn<TArgs> = (args: TArgs, ctx: UiToolActionContext) => void | Promise<void>;
80
+ export type UiToolRenderFn<TArgs, In = unknown> = (args: TArgs, ctx: UiToolContext<In>) => React.ReactNode;
81
+ export type UiToolActionFn<TArgs, In = unknown> = (args: TArgs, ctx: UiToolActionContext<In>) => void | Promise<void>;
66
82
  /**
67
83
  * The interactive face of an ASK-USER component — a human-in-the-loop prompt drawn in the docked
68
84
  * ask-user drawer (`AskUserSheet`) while the tool call is PARKED, keyed by the component NAME the
69
85
  * server stamps via `[KernelUIComponent]` (`functionDetails.askUserComponent`), not by the wire tool
70
86
  * name. Same `(args, ctx)` shape as a render tool.
71
87
  */
72
- export type UiToolAskUserQuestionFn<TArgs> = (args: TArgs, ctx: UiToolContext) => React.ReactNode;
88
+ export type UiToolAskUserQuestionFn<In = unknown, Ans = unknown> = (args: UiToolArgs, ctx: UiToolContext<In, Ans>) => React.ReactNode;
73
89
  /**
74
90
  * The ANSWERED face of an ask-user component — the locked summary drawn inline in the transcript once
75
91
  * the tool has responded. Receives the tool's response (also available as `ctx.response`), so a host
76
92
  * can render "you answered X" without re-deriving it from args.
77
93
  */
78
- export type UiToolAskUserResponseFn<TArgs> = (args: TArgs, ctx: UiToolContext, response: unknown) => React.ReactNode;
94
+ export type UiToolAskUserResponseFn<In = unknown, Ans = unknown, Res = unknown> = (args: UiToolArgs, ctx: UiToolContext<In, Ans>, response: Res) => React.ReactNode;
79
95
  /**
80
96
  * A host ask-user registration: the interactive `question` (required, drawn while parked) plus an
81
97
  * optional locked `response` summary (drawn inline once answered). Omit `response` to reuse `question`
82
98
  * in both states — the question component then owns its own answered/locked view (as the built-in
83
99
  * `AskUserPart`/`AskAuthPart` do).
84
100
  */
85
- export interface UiToolAskUserRenderers<TArgs> {
86
- question: UiToolAskUserQuestionFn<TArgs>;
87
- response?: UiToolAskUserResponseFn<TArgs>;
101
+ export interface UiToolAskUserRenderers<In = unknown, Ans = unknown, Res = unknown> {
102
+ question: UiToolAskUserQuestionFn<In, Ans>;
103
+ response?: UiToolAskUserResponseFn<In, Ans, Res>;
88
104
  }
89
105
  export interface UiToolRenderOptions<TArgs> {
90
106
  /** Runtime arg guard/coercion. Return `null` to render nothing (treated as invalid args). */
@@ -103,21 +119,21 @@ export interface UiToolActionOptions<TArgs> {
103
119
  export interface UiToolRenderEntry {
104
120
  kind: 'render';
105
121
  name: string;
106
- render: UiToolRenderFn<any>;
122
+ render: UiToolRenderFn<any, any>;
107
123
  parse?: (raw: unknown) => any;
108
124
  }
109
125
  export interface UiToolActionEntry {
110
126
  kind: 'action';
111
127
  name: string;
112
- run: UiToolActionFn<any>;
128
+ run: UiToolActionFn<any, any>;
113
129
  parse?: (raw: unknown) => any;
114
130
  status?: string | ((args: any, ctx: UiToolActionContext) => string | null);
115
131
  }
116
132
  export interface UiToolAskUserEntry {
117
133
  kind: 'askUser';
118
134
  name: string;
119
- question: UiToolAskUserQuestionFn<any>;
120
- response?: UiToolAskUserResponseFn<any>;
135
+ question: UiToolAskUserQuestionFn<any, any>;
136
+ response?: UiToolAskUserResponseFn<any, any, any>;
121
137
  parse?: (raw: unknown) => any;
122
138
  }
123
139
  export type UiToolEntry = UiToolRenderEntry | UiToolActionEntry | UiToolAskUserEntry;
@@ -135,8 +151,8 @@ export interface UiToolRegistry {
135
151
  names(): string[];
136
152
  }
137
153
  export interface UiToolRegistryBuilder {
138
- render<TArgs = UiToolArgs>(name: string, render: UiToolRenderFn<TArgs>, opts?: UiToolRenderOptions<TArgs>): UiToolRegistryBuilder;
139
- action<TArgs = UiToolArgs>(name: string, run: UiToolActionFn<TArgs>, opts?: UiToolActionOptions<TArgs>): UiToolRegistryBuilder;
154
+ render<TArgs = UiToolArgs, In = unknown>(name: string, render: UiToolRenderFn<TArgs, In>, opts?: UiToolRenderOptions<TArgs>): UiToolRegistryBuilder;
155
+ action<TArgs = UiToolArgs, In = unknown>(name: string, run: UiToolActionFn<TArgs, In>, opts?: UiToolActionOptions<TArgs>): UiToolRegistryBuilder;
140
156
  /**
141
157
  * Register an ASK-USER component drawn in the docked drawer (`AskUserSheet`). `componentName` must
142
158
  * match the server's `[KernelUIComponent("…")]` value (arrives as `functionDetails.askUserComponent`).
@@ -144,8 +160,13 @@ export interface UiToolRegistryBuilder {
144
160
  * when unregistered, so consumers only register their own components (e.g. `AskCreateAccount`).
145
161
  * Pass `{ question, response? }`: `question` is the interactive parked form, `response` the optional
146
162
  * locked summary shown once answered.
163
+ *
164
+ * Generic over `In` (the prefill / client-data shape read as `ctx.clientOutput`) and `Ans` (the shape
165
+ * passed to `ctx.answer`). Both default to `unknown`. The codegen'd typed methods (e.g.
166
+ * `askUpdateProfile`) are this method with those generics pre-bound — declaration-merged onto this
167
+ * interface so the fluent chain stays fully typed.
147
168
  */
148
- askUser<TArgs = UiToolArgs>(componentName: string, renderers: UiToolAskUserRenderers<TArgs>, opts?: UiToolRenderOptions<TArgs>): UiToolRegistryBuilder;
169
+ askUser<In = unknown, Ans = unknown, Res = unknown>(componentName: string, renderers: UiToolAskUserRenderers<In, Ans, Res>, opts?: UiToolRenderOptions<UiToolArgs>): UiToolRegistryBuilder;
149
170
  build(): UiToolRegistry;
150
171
  }
151
172
  /**
@@ -18,7 +18,7 @@ export type { FriendlyState, FriendlyToolEntry } from './AiChat/ChatPane/friendl
18
18
  export { classifyPart, DEFAULT_PART_RENDERERS, TextPart, ThoughtPart, FunctionPart, WaitingPart, SuspendedPart, BoxedPart, UiToolDispatcher, } from './AiChat/ChatPane/parts';
19
19
  export type { PartKind, PartRendererProps, PartRenderer, PartRendererMap, } from './AiChat/ChatPane/parts';
20
20
  export { createUiToolRegistry, parseUiArgs, parseClientOutput } from './AiChat/ChatPane/parts';
21
- export type { UiToolRegistry, UiToolRegistryBuilder, UiToolContext, UiToolActionContext, UiToolArgs, UiToolRenderFn, UiToolActionFn, UiToolRenderOptions, UiToolActionOptions, UiToolEntry, UiToolRenderEntry, UiToolActionEntry, } from './AiChat/ChatPane/parts';
21
+ export type { UiToolRegistry, UiToolRegistryBuilder, UiToolContext, UiToolActionContext, UiToolArgs, UiToolRenderFn, UiToolActionFn, UiToolRenderOptions, UiToolActionOptions, UiToolEntry, UiToolRenderEntry, UiToolActionEntry, UiToolAskUserRenderers, UiToolAskUserQuestionFn, UiToolAskUserResponseFn, UiToolAskUserEntry, } from './AiChat/ChatPane/parts';
22
22
  export { useContainerWidth, useContainerRectangle } from '../hooks/useContainerWidth';
23
23
  export { default as Stopwatch } from './Stopwatch';
24
24
  export { default as LoadingDots } from './Library/LoadingDots';
@@ -78,6 +78,15 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
78
78
  * seen any sequenced events yet" (fresh connection).
79
79
  */
80
80
  private lastSeq;
81
+ /**
82
+ * Parked-tool answers that could not be sent because the socket was not OPEN
83
+ * (e.g. the connection idled out while the user was in an IdP sign-in popup).
84
+ * Keyed per tool call (last answer wins) and stamped with the session they
85
+ * belong to; flushed by `onopen` when the socket resumes THAT session. An
86
+ * answer for a session this instance is no longer attached to is dropped —
87
+ * the single-attach policy makes it undeliverable from here anyway.
88
+ */
89
+ private pendingAnswers;
81
90
  /**
82
91
  * True once *any* socket on this instance has received at least one packet.
83
92
  * Used by `onclose` to distinguish a real mid-stream drop (we had a working
@@ -131,8 +140,20 @@ export declare class WebSocketConnecionV2 implements IWebSocketConnection {
131
140
  private persistRefreshedAccessToken;
132
141
  closeStream(): void;
133
142
  suspendStream(): void;
134
- /** Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool). */
135
- answerHumanTool(toolCallId: string, answer: string): void;
143
+ /**
144
+ * Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool).
145
+ *
146
+ * Never throws on a dead socket: the parked tool answer is the one message whose loss
147
+ * strands the whole turn (the askauth popup case — the socket idles out while the user
148
+ * is at the IdP, the token comes back, and a plain send would throw into an unhandled
149
+ * rejection with the answer gone). When the socket is not OPEN the answer is queued and
150
+ * flushed by `onopen` on the next (re)connect of the same session.
151
+ *
152
+ * Returns 'sent' when it went out now, 'queued' when it will go out on reconnect.
153
+ */
154
+ answerHumanTool(toolCallId: string, answer: string): 'sent' | 'queued';
155
+ private queueAnswer;
156
+ private flushPendingAnswers;
136
157
  /**
137
158
  * Send a message to the agent
138
159
  */
@@ -61,9 +61,10 @@ export declare abstract class AgentGatewayService {
61
61
  /**
62
62
  * Send the user's answer to a parked `ask_user` tool call back to the agent.
63
63
  * Default no-op; the WebSocket gateway (AgentGatewayWSAsync) overrides it to emit
64
- * a ChatAction.AnswerHumanTool frame.
64
+ * a ChatAction.AnswerHumanTool frame. Returns 'sent' when it went out immediately,
65
+ * 'queued' when the socket was down and the answer will flush on reconnect.
65
66
  */
66
- answerHumanTool(toolCallId: string, answer: string): void;
67
+ answerHumanTool(toolCallId: string, answer: string): 'sent' | 'queued';
67
68
  constructor(user: User, eventBusService: EventBusService, artifactService: IArtifactService, baseUrl: string, config: AgentContext, sessionStore: AiChatStore, notificationPort: INotificationPort, storageService: IStorageService, sessionId?: string, runMode?: RunMode);
68
69
  getAgentContext(): AgentContext;
69
70
  getModel(): string | undefined;
@@ -37,7 +37,8 @@ export declare class AgentGatewayWSAsync extends AgentGatewayService {
37
37
  finalResponse(interactionId: string, agentInteraction: Interaction, author: string): Promise<void>;
38
38
  stopStream(closeTurn?: boolean): void;
39
39
  suspend(): Promise<boolean>;
40
- answerHumanTool(toolCallId: string, answer: string): void;
40
+ /** Forwards a parked-tool answer; 'queued' means the socket was down and it will flush on reconnect. */
41
+ answerHumanTool(toolCallId: string, answer: string): 'sent' | 'queued';
41
42
  cancelSuspend(): Promise<void>;
42
43
  check(): Promise<boolean>;
43
44
  lastConnectionPromise: Promise<string> | null;
@@ -0,0 +1,309 @@
1
+ var jt = Object.defineProperty;
2
+ var C = (l, i) => jt(l, "name", { value: i, configurable: !0 });
3
+ import { useState as R, useRef as c, useCallback as x, useEffect as j } from "react";
4
+ const pt = /* @__PURE__ */ C(() => ({
5
+ maxLocationConfidence: 0,
6
+ maxPersonConfidence: 0,
7
+ locationGateFired: !1,
8
+ suggestionAccepted: !1,
9
+ ghostShown: !1,
10
+ ghostAccepted: !1,
11
+ atOpened: !1,
12
+ atAccepted: null,
13
+ manualAt: !1
14
+ }), "emptyOutcome"), Dt = /* @__PURE__ */ C(() => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : `s-${Date.now()}-${Math.random()}`, "newSessionId"), Pt = /* @__PURE__ */ C((l, i, p) => {
15
+ var d;
16
+ const s = l.length;
17
+ let r = i;
18
+ for (let h = 0; h < s; h++)
19
+ if (r = (r + p + s) % s, !((d = l[r]) != null && d.disabled)) return r;
20
+ return i;
21
+ }, "nextEnabledIndex"), Qt = /* @__PURE__ */ C((l) => {
22
+ const i = /* @__PURE__ */ new Date();
23
+ i.setDate(i.getDate() + l);
24
+ const p = String(i.getDate()).padStart(2, "0"), s = String(i.getMonth() + 1).padStart(2, "0");
25
+ return `${p}/${s}/${i.getFullYear()}`;
26
+ }, "plusDaysBR");
27
+ function Jt(l, i, p = {}) {
28
+ const [s, r] = R(null), [d, h] = R(null), [F, S] = R(0), [Q, et] = R(0), [z, nt] = R(!1), [rt, H] = R(0), [Et, mt] = R([]), [It, yt] = R([]), [Lt, ot] = R(""), X = c(""), B = c(null), Y = c(l);
29
+ Y.current = l;
30
+ const O = c(i);
31
+ O.current = i;
32
+ const ct = c(p);
33
+ ct.current = p;
34
+ const U = c(null), W = c(null), $t = c(0), Rt = c(0), st = c(null), Z = c(""), K = c(null), it = c(null), lt = c(Dt()), M = c(null);
35
+ M.current = s;
36
+ const at = c(null);
37
+ at.current = d;
38
+ const J = c(0), ut = c(null), Ht = 4, Ot = 0.5, G = c(null), wt = c(""), bt = c(() => {
39
+ }), D = c(pt()), L = c(!1), qt = x(() => r(null), []), Ft = x(() => {
40
+ mt([]), yt([]), ot(""), X.current = "", K.current = null, lt.current = Dt(), D.current = pt(), L.current = !1;
41
+ }, []), dt = x((t) => {
42
+ if (t.disabled) return;
43
+ D.current.suggestionAccepted = !0, t.kind === "location" && (L.current = !0), r(null);
44
+ const n = Y.current, f = n.getTextarea();
45
+ if (!f) return;
46
+ const m = f.selectionStart ?? f.value.length, y = f.value.slice(0, m), P = f.value.slice(m), T = t.kind === "namedLocation" || t.kind === "location";
47
+ let e;
48
+ if (T) {
49
+ const u = wt.current, w = y.replace(/\s+$/, "");
50
+ e = u && w.endsWith(u) ? w.slice(0, w.length - u.length) : y;
51
+ } else {
52
+ const u = y.search(/\S+$/);
53
+ e = u === -1 ? y : y.slice(0, u);
54
+ }
55
+ const g = e.length > 0 && !/\s$/.test(e);
56
+ if (t.kind === "date") {
57
+ const u = `${g ? " " : ""}${t.insert} `, w = `${e}${u}${P}`;
58
+ n.setDraft(w), n.focusCaret(e.length + u.length), Z.current = w, K.current = null, bt.current();
59
+ return;
60
+ }
61
+ if (t.kind === "namedLocation" && t.insert) {
62
+ const u = `@${t.insert.replace(/ /g, " ")}`, w = `${g ? " " : ""}${u} `;
63
+ n.setDraft(`${e}${w}${P}`), n.focusCaret(e.length + w.length);
64
+ return;
65
+ }
66
+ const a = t.kind === "location" ? "@" : "#", k = `${g ? " " : ""}${a}`;
67
+ n.setDraft(`${e}${k}${P}`), n.focusCaret(e.length + k.length), requestAnimationFrame(() => {
68
+ const u = n.getTextarea();
69
+ u && n.syncTrigger(u);
70
+ });
71
+ }, []), ft = x(async () => {
72
+ var y;
73
+ const t = O.current.resolveDates;
74
+ if (!t) return;
75
+ const n = Z.current;
76
+ if (n.trim() === "") {
77
+ K.current = null;
78
+ return;
79
+ }
80
+ if (n === K.current || n.split(" ").length <= 2) return;
81
+ K.current = n, (y = it.current) == null || y.abort();
82
+ const m = new AbortController();
83
+ it.current = m;
84
+ try {
85
+ const { dates: P, locations: T } = await t(n, lt.current, m.signal);
86
+ if (Z.current !== n) return;
87
+ const e = P.filter((a) => a.display).map((a) => ({ text: a.text, display: a.display }));
88
+ yt(e), mt(T.map((a) => a.text).filter((a) => a.trim().length > 0));
89
+ const g = e.map((a) => `${a.text}=${a.display}`).join("|");
90
+ e.length > 0 && g !== X.current && (X.current = g, ot(e[e.length - 1].text), B.current != null && window.clearTimeout(B.current), B.current = window.setTimeout(() => ot(""), 2e3)), e.length === 0 && (X.current = "");
91
+ } catch {
92
+ }
93
+ }, []);
94
+ bt.current = ft;
95
+ const zt = x((t, n, f) => {
96
+ if (Z.current = t, t.split(" ").length <= 2) return;
97
+ const y = O.current.analyze;
98
+ y && (!f || M.current !== null || at.current !== null) && (U.current != null && window.clearTimeout(U.current), U.current = window.setTimeout(async () => {
99
+ var T;
100
+ const P = ++$t.current;
101
+ try {
102
+ const e = await y(t, n);
103
+ if (P !== $t.current) return;
104
+ const g = Y.current, a = g.getTextarea();
105
+ if (!a || a.value !== t) return;
106
+ et(e.personConfidence ?? 0), S(e.locationConfidence ?? 0);
107
+ const k = D.current;
108
+ k.maxPersonConfidence = Math.max(k.maxPersonConfidence, e.personConfidence ?? 0), k.maxLocationConfidence = Math.max(k.maxLocationConfidence, e.locationConfidence ?? 0), h(null);
109
+ const u = (a.selectionStart ?? n) === t.length, w = g.hasAtQuery, vt = g.isPickerOpen(), Ct = e.suggestions ?? [], { enableHashDatePicker: Mt = !1, datePresets: Gt = ["amanhã de manhã", "quarta-feira à noite"] } = ct.current;
110
+ let E = e.category === "location" ? "location" : e.category === "date" ? "date" : e.locationExpected ? "location" : e.dateExpected ? "date" : null;
111
+ if (E !== "location" && e.locationCount < 2 && O.current.suggest && M.current !== null && G.current === "location" && u && /\s$/.test(t) && (E = "location"), ct.current.promptHint && u && !vt) {
112
+ const o = e.personConfidence ?? 0, A = e.locationConfidence ?? 0, N = E === "location" && !(e.locationCount >= 2 && e.locationPartialEmpty), v = o >= Ot && o >= A ? "person" : N ? "location" : null;
113
+ if (v) {
114
+ v !== ut.current && (J.current = 0), ut.current = v, J.current += 1, J.current <= Ht && (h(v), k.ghostShown = !0, v === "location" && (k.locationGateFired = !0)), r(null), G.current = null;
115
+ return;
116
+ }
117
+ ut.current = null, J.current = 0;
118
+ }
119
+ if (E === "location" && e.locationCount >= 2 && e.locationPartialEmpty) {
120
+ r(null), G.current = null;
121
+ return;
122
+ }
123
+ if (E === null || !(u && !vt && (E === "location" ? w : E === "date"))) {
124
+ r(null), G.current = null;
125
+ return;
126
+ }
127
+ const b = E;
128
+ G.current = b, b === "location" && (k.locationGateFired = !0);
129
+ const ht = /* @__PURE__ */ C(() => b === "date" && Mt ? [{ key: "cal", label: `📅 no dia #${Qt(2)}`, kind: "calendar" }] : [], "genericTail"), kt = Ct.filter((o) => o.kind === "location"), xt = Ct.filter((o) => o.kind === "date").map((o) => o.value), I = [];
130
+ if (b === "location") {
131
+ for (const o of kt)
132
+ I.push({ key: `loc:${o.value}`, label: `📍 ${o.label}`, kind: "namedLocation", insert: o.value });
133
+ I.push(...ht());
134
+ } else {
135
+ for (const o of xt.length > 0 ? xt : Gt)
136
+ I.push({ key: `date:${o}`, label: `📅 ${o}`, kind: "date", insert: o });
137
+ I.push(...ht());
138
+ }
139
+ const V = O.current.suggest, Nt = b === "location" ? kt.length > 0 : !0;
140
+ if (b === "location" && !Nt && !V) {
141
+ if (!f && e.locationExpected && e.locationPartialEmpty && e.locationCount < 2 && w && g.currentTriggerChar() !== "@") {
142
+ const o = a.selectionStart ?? t.length, A = t.slice(0, o), N = A.length > 0 && !/\s$/.test(A);
143
+ if (!A.endsWith("@")) {
144
+ const v = N ? " @" : "@";
145
+ L.current = !0, r(null), g.setDraft(`${A}${v}${t.slice(o)}`), g.focusCaret(o + v.length), requestAnimationFrame(() => {
146
+ const tt = g.getTextarea();
147
+ tt && g.syncTrigger(tt);
148
+ });
149
+ }
150
+ return;
151
+ }
152
+ r(null);
153
+ return;
154
+ }
155
+ if (V ? M.current === null && I.length > 0 && (H(0), nt(!0), r(I)) : I.length > 0 ? (H(0), nt(!0), r(I)) : r(null), V) {
156
+ const o = t.slice(0, a.selectionStart ?? t.length), A = o.search(/[ \t\r\n](?=[^ \t\r\n]*$)/), N = A === -1 ? o : o.slice(A + 1), v = b === "location" && e.locationPartial !== void 0 ? e.locationPartial : N;
157
+ b === "location" && (wt.current = v);
158
+ const tt = b === "location" ? [...t.matchAll(/@\(([A-Za-z]{3})\)/g)].map((_) => _[1].toUpperCase()) : void 0, _t = ++Rt.current;
159
+ (T = st.current) == null || T.abort();
160
+ const Tt = new AbortController();
161
+ st.current = Tt;
162
+ try {
163
+ const _ = await V(v, b, Tt.signal, tt);
164
+ if (_t !== Rt.current) return;
165
+ const At = g.getTextarea();
166
+ if (!At || At.value !== t || b === "location" && _.length === 0) return;
167
+ const q = [];
168
+ if (b === "location")
169
+ for (const $ of _)
170
+ q.push({
171
+ key: `loc:${$.insert}`,
172
+ label: `📍 ${$.label}`,
173
+ kind: "namedLocation",
174
+ insert: $.insert,
175
+ hint: [$.iata, $.region, $.country].filter(Boolean).join(" · ") || void 0,
176
+ // parity with the `@` picker
177
+ disabled: $.disabled
178
+ // already in the prompt (same city) — greyed, not pickable
179
+ });
180
+ else
181
+ for (const $ of _)
182
+ q.push({ key: `date:${$.insert}`, label: `📅 ${$.label}`, kind: "date", insert: $.insert });
183
+ if (q.push(...ht()), q.length === 0) {
184
+ r(null);
185
+ return;
186
+ }
187
+ const St = q.findIndex(($) => !$.disabled);
188
+ H(St < 0 ? 0 : St), nt(v.trim() === ""), r(q);
189
+ } catch {
190
+ }
191
+ }
192
+ } catch {
193
+ }
194
+ }, 200)), W.current != null && window.clearTimeout(W.current), W.current = window.setTimeout(() => {
195
+ ft();
196
+ }, 300);
197
+ }, [ft]), Bt = x((t) => {
198
+ var f, m;
199
+ const n = t.trim();
200
+ n && ((m = (f = O.current).commitIntent) == null || m.call(f, n, lt.current, D.current)), D.current = pt(), L.current = !1;
201
+ }, []), Ut = x(() => {
202
+ const t = D.current;
203
+ t.atOpened = !0, L.current ? L.current = !1 : at.current === null && M.current === null && (t.manualAt = !0);
204
+ }, []), Wt = x((t) => {
205
+ D.current.atAccepted = t ?? "location";
206
+ }, []), gt = x(() => {
207
+ D.current.ghostAccepted = !0, L.current = !0, h(null);
208
+ const t = Y.current, n = t.getTextarea();
209
+ if (!n) return;
210
+ const f = n.selectionStart ?? n.value.length, m = n.value.slice(0, f), y = n.value.slice(f), T = `${m.length > 0 && !/\s$/.test(m) ? " " : ""}@`;
211
+ t.setDraft(`${m}${T}${y}`), t.focusCaret(f + T.length), requestAnimationFrame(() => {
212
+ const e = t.getTextarea();
213
+ e && t.syncTrigger(e);
214
+ });
215
+ }, []), Kt = x((t) => {
216
+ if (d !== null && (!s || s.length === 0)) {
217
+ if (t.key === "Tab" || t.key === "ArrowRight")
218
+ return t.preventDefault(), gt(), !0;
219
+ if (t.key === "Escape")
220
+ return t.preventDefault(), h(null), !0;
221
+ }
222
+ if (!s || s.length === 0) return !1;
223
+ if (t.key === "ArrowDown")
224
+ return t.preventDefault(), H((n) => Pt(s, n, 1)), !0;
225
+ if (t.key === "ArrowUp")
226
+ return t.preventDefault(), H((n) => Pt(s, n, -1)), !0;
227
+ if (t.key === "Enter" || t.key === "Tab") {
228
+ t.preventDefault();
229
+ const n = s[rt];
230
+ return n && !n.disabled && dt(n), !0;
231
+ }
232
+ return t.key === "Escape" ? (t.preventDefault(), r(null), !0) : !1;
233
+ }, [s, rt, dt, d, gt]);
234
+ return j(() => () => {
235
+ var t, n;
236
+ U.current != null && window.clearTimeout(U.current), W.current != null && window.clearTimeout(W.current), B.current != null && window.clearTimeout(B.current), (t = it.current) == null || t.abort(), (n = st.current) == null || n.abort();
237
+ }, []), {
238
+ predictions: s,
239
+ predictionsRecents: z,
240
+ predictionHighlight: rt,
241
+ setPredictionHighlight: H,
242
+ applyPrediction: dt,
243
+ clearPredictions: qt,
244
+ hint: d,
245
+ acceptHint: gt,
246
+ resolvedLocations: Et,
247
+ resolvedDates: It,
248
+ forceTooltipText: Lt,
249
+ personConfidence: Q,
250
+ locationConfidence: F,
251
+ scheduleAssist: zt,
252
+ commit: Bt,
253
+ onKeyDown: Kt,
254
+ resetSession: Ft,
255
+ noteAtOpened: Ut,
256
+ noteAtAccepted: Wt
257
+ };
258
+ }
259
+ C(Jt, "usePromptAssist");
260
+ function Vt(l, i) {
261
+ const p = c(l), [s, r] = R(null);
262
+ return j(() => {
263
+ p.current = l;
264
+ }, [l]), j(() => {
265
+ function d() {
266
+ p.current();
267
+ }
268
+ if (C(d, "tick"), i !== null) {
269
+ const h = setInterval(d, i);
270
+ return r(h), () => {
271
+ clearInterval(h);
272
+ };
273
+ }
274
+ }, [i]), s;
275
+ }
276
+ C(Vt, "useInterval");
277
+ function te(l, i, p = 0) {
278
+ const [s, r] = R(p);
279
+ return j(() => {
280
+ const d = l.current;
281
+ if (!d) return;
282
+ const h = new ResizeObserver((F) => {
283
+ const S = F[0];
284
+ S && r(S.contentRect.width);
285
+ });
286
+ return h.observe(d), r(d.getBoundingClientRect().width), () => h.disconnect();
287
+ }, [l, i]), s;
288
+ }
289
+ C(te, "useContainerWidth");
290
+ function ee(l, i, p = 0, s = 0) {
291
+ const [r, d] = R(p), [h, F] = R(s);
292
+ return j(() => {
293
+ const S = l.current;
294
+ if (!S) return;
295
+ const Q = new ResizeObserver((et) => {
296
+ const z = et[0];
297
+ z && (F(z.contentRect.height), d(z.contentRect.width));
298
+ });
299
+ return Q.observe(S), d(S.getBoundingClientRect().width), () => Q.disconnect();
300
+ }, [l, i]), [r, h];
301
+ }
302
+ C(ee, "useContainerRectangle");
303
+ export {
304
+ te as a,
305
+ Vt as b,
306
+ Jt as c,
307
+ ee as u
308
+ };
309
+ //# sourceMappingURL=useContainerWidth-CDv8UQyZ.js.map