@m6d/cortex-angular 0.17.0 → 0.18.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.
@@ -3,19 +3,76 @@
3
3
  import * as i0 from '@angular/core';
4
4
  import { Injector, OnInit, Signal, TemplateRef, Type } from '@angular/core';
5
5
  import { MessagePart, ToolCallPart, UIMessage } from '@tanstack/ai';
6
+ import { z } from 'zod';
6
7
 
8
+ declare const runRecordSchema: z.ZodObject<{
9
+ id: z.ZodUUID;
10
+ threadId: z.ZodNullable<z.ZodUUID>;
11
+ inputId: z.ZodNullable<z.ZodUUID>;
12
+ kind: z.ZodEnum<{
13
+ turn: "turn";
14
+ subagent: "subagent";
15
+ tool: "tool";
16
+ }>;
17
+ subagentRunId: z.ZodNullable<z.ZodString>;
18
+ status: z.ZodEnum<{
19
+ running: "running";
20
+ waiting: "waiting";
21
+ completed: "completed";
22
+ failed: "failed";
23
+ cancelled: "cancelled";
24
+ }>;
25
+ reason: z.ZodNullable<z.ZodEnum<{
26
+ cancelled: "cancelled";
27
+ no_output: "no_output";
28
+ invalid_output: "invalid_output";
29
+ stopped: "stopped";
30
+ parent_cancelled: "parent_cancelled";
31
+ lost: "lost";
32
+ timeout: "timeout";
33
+ }>>;
34
+ result: z.ZodUnknown;
35
+ waits: z.ZodArray<z.ZodObject<{
36
+ kind: z.ZodEnum<{
37
+ approval: "approval";
38
+ client_tool: "client_tool";
39
+ }>;
40
+ toolCallId: z.ZodString;
41
+ toolName: z.ZodString;
42
+ input: z.ZodUnknown;
43
+ }, z.core.$strip>>;
44
+ createdAt: z.ZodISODateTime;
45
+ finishedAt: z.ZodNullable<z.ZodISODateTime>;
46
+ }, z.core.$strip>;
47
+ export type RunRecord = z.infer<typeof runRecordSchema>;
7
48
  declare const LOCALES: readonly [
8
49
  "en",
9
50
  "ar"
10
51
  ];
11
52
  export type Locale = (typeof LOCALES)[number];
53
+ declare const TOOL_SURFACES: readonly [
54
+ "inline",
55
+ "modal"
56
+ ];
57
+ export type ToolSurface = (typeof TOOL_SURFACES)[number];
12
58
  declare const MESSAGE_ROLES: readonly [
13
59
  "system",
14
60
  "user",
15
61
  "assistant",
16
- "trigger"
62
+ "event"
17
63
  ];
18
64
  export type MessageRole = (typeof MESSAGE_ROLES)[number];
65
+ declare const WHILE_BUSY: readonly [
66
+ "refuse",
67
+ "queue",
68
+ "steer"
69
+ ];
70
+ export type WhileBusy = (typeof WHILE_BUSY)[number];
71
+ declare const MESSAGE_BUSY: readonly [
72
+ "queue",
73
+ "steer"
74
+ ];
75
+ export type MessageBusy = (typeof MESSAGE_BUSY)[number];
19
76
  declare const ATTACHMENT_STATUSES: readonly [
20
77
  "pending",
21
78
  "described",
@@ -61,6 +118,14 @@ export type ThreadSummary = {
61
118
  export type CreateThreadRequest = {
62
119
  variables?: Record<string, string | number | boolean>;
63
120
  };
121
+ /**
122
+ * Response of `POST /chat/:threadId/abort`. `aborted: false` means there was no
123
+ * live run to abort — the turn had already committed — so the caller must not
124
+ * present the turn as aborted and should read the settled state back instead.
125
+ */
126
+ export type AbortRunResult = {
127
+ aborted: boolean;
128
+ };
64
129
  export type TokenUsage = {
65
130
  input: {
66
131
  noCache: number;
@@ -75,6 +140,17 @@ export type TokenUsage = {
75
140
  };
76
141
  total: number;
77
142
  };
143
+ /**
144
+ * Response of `GET /connections/:server?call=<toolCallId>`: where the
145
+ * caller's own account stands with the agent's MCP server of that name, for
146
+ * the card of that `connectAccount` call. `connected` with all a sign-in
147
+ * may ask for; `pending` while it is not connected, or lacks access a
148
+ * sign-in may still grant; `refused` once the card's own sign-in came back
149
+ * without it, or no sign-in may ask again.
150
+ */
151
+ export type AccountConnection = {
152
+ status: "connected" | "pending" | "refused";
153
+ };
78
154
  /**
79
155
  * What Cortex offers this agent's clients, fetched once at widget startup.
80
156
  * The widget hides UI for anything absent; Cortex enforces each.
@@ -91,6 +167,8 @@ export type AgentCapabilities = {
91
167
  messages: boolean;
92
168
  /** True when the caller only reads, as an operator inspecting a user's thread does. */
93
169
  readOnly: boolean;
170
+ /** What a message sent while a run holds the thread does; under `refuse`, nothing sends until the run ends. */
171
+ whileBusy: WhileBusy;
94
172
  /** Prompt chips on the blank-chat landing per locale; clicking one sends its `prompt` as the first message. */
95
173
  suggestions: Suggestions;
96
174
  /** Headline of the blank-chat landing per locale; "" falls back to the widget's built-in copy. */
@@ -109,8 +187,8 @@ export type MessageMetadata = {
109
187
  isAborted?: boolean;
110
188
  tokenUsage?: TokenUsage;
111
189
  attachments?: AttachmentSummary[];
112
- /** Set on `trigger` messages: the firing that wrote them. */
113
- trigger?: TriggerFiringSummary;
190
+ /** Set on `event` messages: what happened, and the input that brought it. */
191
+ event?: EventSummary;
114
192
  };
115
193
  /**
116
194
  * One landing-page chip: the widget shows `title` and sends `prompt` as the
@@ -125,11 +203,16 @@ export type Suggestions = Record<Locale, Suggestion[]>;
125
203
  export type Greeting = Record<Locale, string>;
126
204
  /** Author-written copy the widget shows verbatim, one string per locale. */
127
205
  export type LocalizedText = Record<Locale, string>;
128
- export type TriggerFiringSummary = {
206
+ /** An event that entered a conversation: a trigger fired, a schedule came due, a run finished. */
207
+ export type EventSummary = {
208
+ source: "trigger" | "schedule" | "run";
209
+ /** The trigger's name, or what the schedule or run was for. */
129
210
  name: string;
130
- firingId: string;
131
- firedAt: string;
211
+ inputId: string;
212
+ at: string;
132
213
  payload: unknown;
214
+ /** What a trigger that leaves a note tells the thread, for its user to read. */
215
+ note?: string;
133
216
  };
134
217
  /**
135
218
  * A stored message as it is persisted and served: the SDK's parts plus the
@@ -142,35 +225,53 @@ export type TriggerFiringSummary = {
142
225
  */
143
226
  export type CortexMessage<TPart = unknown> = {
144
227
  id: string;
145
- /** `trigger` rows carry a firing's instructions; the UIs render them as an event, not a bubble. */
228
+ /** `event` rows carry what happened; the UIs render them as an event, not a bubble. */
146
229
  role: MessageRole;
147
230
  parts: TPart[];
148
231
  metadata?: MessageMetadata;
149
232
  };
150
- declare const TRIGGER_DROP_REASONS: readonly [
151
- "busy",
152
- "approval_pending",
153
- "budget",
154
- "rate_limited"
155
- ];
156
- export type TriggerDropReason = (typeof TRIGGER_DROP_REASONS)[number];
157
233
  /**
158
- * Body of a `POST /chat` the thread did not take: 409 while a run holds the
159
- * thread or a call on it waits for a decision, or when the answers it
160
- * carried fit no open call, were already applied, or answer a call whose
161
- * origin is out of reach (`no_turn`); 429 once the agent's request bucket is
162
- * spent, with `Retry-After`.
234
+ * Response of `POST /chat/:threadId/tools/:toolCallId/initiate` for a pending
235
+ * call stamped with an embed. The payload is for the widget only; it never
236
+ * reaches the LLM.
163
237
  */
164
- export type ChatDropped = {
165
- outcome: "dropped";
166
- reason: Exclude<TriggerDropReason, "budget"> | "no_turn";
238
+ export type ClientToolInitiateResult = {
239
+ embedUrl: string;
240
+ surface: ToolSurface;
241
+ embedOrigin: string;
167
242
  };
168
243
  /**
169
- * The drop a widget tells its user about by name: a call on the thread waits
170
- * for approval, so the message goes back to the composer. Any other drop
171
- * shows as a failed turn.
244
+ * One input waiting on a thread, in the order dispatch takes them, in
245
+ * `GET /threads/:threadId/inputs`: the user message as it will be stored
246
+ * once a run takes it up, and how it waits: to steer the running turn, or
247
+ * for a turn of its own. `DELETE /threads/:threadId/inputs/:inputId`
248
+ * cancels it and `PATCH` (`{ busy }`) moves it to steer or queue, unless a
249
+ * run already took it in (404).
250
+ */
251
+ export type WaitingInput<TPart = unknown> = {
252
+ inputId: string;
253
+ delivery: "prompt" | "steer" | "followUp" | "answer" | "note";
254
+ message: CortexMessage<TPart>;
255
+ /** Whether it is text alone, which a running turn may take in as a steer; one with files waits for a turn of its own. */
256
+ textOnly: boolean;
257
+ };
258
+ /**
259
+ * The refusal a widget tells its user about by name: a call on the thread
260
+ * waits for approval, so the message goes back to the composer. Any other
261
+ * refusal shows as a failed turn.
262
+ */
263
+ export type SendRefusal = "approval_pending";
264
+ /**
265
+ * One model call of the turn that wrote a message, raw, in the order the
266
+ * turn ran them: `GET /threads/:threadId/messages/:messageId/llm-requests`
267
+ * answers a list, for the request inspector.
172
268
  */
173
- export type SendRefusal = Extract<ChatDropped["reason"], "approval_pending">;
269
+ export type LlmRequest = {
270
+ id: string;
271
+ prompt: string;
272
+ output: string | null;
273
+ tokenUsage: TokenUsage | null;
274
+ };
174
275
  export type CortexHeaders = Record<string, string>;
175
276
  /**
176
277
  * How the widget reaches Cortex. `baseUrl` may be a thunk so a consumer with
@@ -192,6 +293,8 @@ export type CortexTransport = {
192
293
  */
193
294
  threadBody?: CreateThreadRequest;
194
295
  };
296
+ /** A message as Cortex serves it: SDK parts plus Cortex's metadata envelope. */
297
+ export type CortexChatMessage = CortexMessage<MessagePart>;
195
298
  export type ColorScheme = "light" | "dark";
196
299
  export type MediaRenderContext = {
197
300
  scheme: ColorScheme;
@@ -386,6 +489,16 @@ export type ChatSessionState = {
386
489
  awaitsApproval: boolean;
387
490
  /** The last turn failed: Cortex said its run failed, or the message never got out. */
388
491
  turnFailure: TurnFailure | undefined;
492
+ /**
493
+ * Messages sent while a run worked that wait on the thread, in the order
494
+ * Cortex takes them, each with its input to cancel it by and how it
495
+ * waits; one leaves once the transcript holds it.
496
+ */
497
+ queued: QueuedItem[];
498
+ };
499
+ /** A message waiting on the thread, the input it waits as, and how. */
500
+ export type QueuedItem = Omit<WaitingInput, "message"> & {
501
+ message: UIMessage;
389
502
  };
390
503
  /** Everything a widget draws, the same for every framework. */
391
504
  export type CortexWidgetState = {
@@ -413,7 +526,23 @@ export type CortexWidgetState = {
413
526
  attachments: QueuedAttachment[];
414
527
  /** A thread is being created for the message on its way out; the composer waits for it. */
415
528
  creating: boolean;
416
- screen: "chat" | "threads";
529
+ /** Where the reader picked to send the message being written while a run works; unset, the agent's busy rule (`composerBusy`). It lasts for one message, and ends with its run or on leaving the thread. */
530
+ busyPick: MessageBusy | undefined;
531
+ /** What the widget read of the copies the transcript's cards name: each one's latest run, by subagent run id. */
532
+ copies: Readonly<Record<string, RunRecord>>;
533
+ /** The check-backs the reader cancelled here, by their input id, so their lines say so (`checkBackLine`). */
534
+ cancelledCheckBacks: readonly string[];
535
+ /**
536
+ * The copy whose own thread this state has open, on the state its screen
537
+ * draws (`copyScreen`): its subagent run id, and whether its composer
538
+ * takes focus as the screen opens. Unset on the widget's own state.
539
+ */
540
+ copy: {
541
+ id: string;
542
+ focus: boolean;
543
+ } | undefined;
544
+ /** `copy`: a copy's screen covers the chat it was opened from (`openCopy`). */
545
+ screen: "chat" | "threads" | "copy";
417
546
  /** Full mode's history sidebar, slid in on a narrow viewport. */
418
547
  sidebarOpen: boolean;
419
548
  /** The reader's debug toggle; on only while the handshake offers the debug view. */
@@ -427,149 +556,83 @@ export type CortexWidgetState = {
427
556
  isWorking: boolean;
428
557
  };
429
558
  };
430
- export type CortexAngularConfig = CortexConfig & {
431
- toolComponents?: Record<string, Type<CortexToolComponentInputs>>;
432
- injector?: Injector;
433
- };
434
- /** The landing's context, its composer a template to place with `ngTemplateOutlet`. */
435
- export type CortexLandingContext = LandingContext<TemplateRef<unknown>>;
436
- /** Each part of the widget a consumer can draw itself, with the context it receives. */
437
- export type CortexAngularSlotContexts = CortexSlotContexts<TemplateRef<unknown>>;
438
- declare const LOCALES$1: readonly [
439
- "en",
440
- "ar"
441
- ];
442
- type Locale$1 = (typeof LOCALES$1)[number];
443
- declare const TOOL_SURFACES: readonly [
444
- "inline",
445
- "modal"
446
- ];
447
- export type ToolSurface = (typeof TOOL_SURFACES)[number];
448
- declare const ATTACHMENT_STATUSES$1: readonly [
449
- "pending",
450
- "described",
451
- "failed",
452
- "skipped"
453
- ];
454
- type AttachmentStatus$1 = (typeof ATTACHMENT_STATUSES$1)[number];
455
- declare const ATTACHMENT_ORIGINS$1: readonly [
456
- "upload",
457
- "tool"
458
- ];
459
- type AttachmentOrigin$1 = (typeof ATTACHMENT_ORIGINS$1)[number];
460
- export type AttachmentSummary$1 = {
461
- id: string;
462
- filename: string;
463
- contentType: string;
464
- sizeBytes: number;
465
- status: AttachmentStatus$1;
466
- origin: AttachmentOrigin$1;
467
- description: string | null;
468
- };
469
- /**
470
- * Response of `POST /chat/:threadId/abort`. `aborted: false` means there was no
471
- * live run to abort — the turn had already committed — so the caller must not
472
- * present the turn as aborted and should read the settled state back instead.
473
- */
474
- export type AbortRunResult$1 = {
475
- aborted: boolean;
476
- };
477
- type TokenUsage$1 = {
478
- input: {
479
- noCache: number;
480
- cacheRead: number;
481
- cacheWrite: number;
482
- total: number;
483
- };
484
- output: {
485
- reasoning: number;
486
- text: number;
487
- total: number;
488
- };
489
- total: number;
490
- };
491
- /**
492
- * Response of `GET /connections/:server?call=<toolCallId>`: where the
493
- * caller's own account stands with the agent's MCP server of that name, for
494
- * the card of that `connectAccount` call. `connected` with all a sign-in
495
- * may ask for; `pending` while it is not connected, or lacks access a
496
- * sign-in may still grant; `refused` once the card's own sign-in came back
497
- * without it, or no sign-in may ask again.
498
- */
499
- export type AccountConnection$1 = {
500
- status: "connected" | "pending" | "refused";
501
- };
502
- /**
503
- * What Cortex offers this agent's clients, fetched once at widget startup.
504
- * The widget hides UI for anything absent; Cortex enforces each.
505
- */
506
- export type AgentCapabilities$1 = {
507
- /** The agent's display name per locale, which titles a new chat; `{}` for an agent without one. */
508
- displayName: Partial<LocalizedText$1>;
509
- attachments: boolean;
510
- /**
511
- * False when this caller may not send to the chat: the agent's `message`
512
- * trigger is off, or the caller only reads (`readOnly`). The widget hides
513
- * its composer and answers no tool call.
514
- */
515
- messages: boolean;
516
- /** True when the caller only reads, as an operator inspecting a user's thread does. */
517
- readOnly: boolean;
518
- /** Prompt chips on the blank-chat landing per locale; clicking one sends its `prompt` as the first message. */
519
- suggestions: Suggestions$1;
520
- /** Headline of the blank-chat landing per locale; "" falls back to the widget's built-in copy. */
521
- greeting: Greeting$1;
522
- /**
523
- * Whether this caller gets the debug view: tool inputs and outputs, reasoning,
524
- * model calls. Cortex sends anyone else only what the widget's normal UI draws.
525
- */
526
- debug: boolean;
527
- };
528
- type Suggestion$1 = {
529
- title: string;
530
- prompt: string;
531
- };
532
- type Suggestions$1 = Record<Locale$1, Suggestion$1[]>;
533
- type Greeting$1 = Record<Locale$1, string>;
534
- type LocalizedText$1 = Record<Locale$1, string>;
535
- /**
536
- * Response of `POST /chat/:threadId/tools/:toolCallId/initiate` for a pending
537
- * call stamped with an embed. The payload is for the widget only; it never
538
- * reaches the LLM.
539
- */
540
- export type ClientToolInitiateResult$1 = {
541
- embedUrl: string;
542
- surface: ToolSurface;
543
- embedOrigin: string;
544
- };
545
- /**
546
- * One model call of the turn that wrote a message, raw, in the order the
547
- * turn ran them: `GET /threads/:threadId/messages/:messageId/llm-requests`
548
- * answers a list, for the request inspector.
549
- */
550
- export type LlmRequest$1 = {
551
- id: string;
552
- prompt: string;
553
- output: string | null;
554
- tokenUsage: TokenUsage$1 | null;
555
- };
556
- /** A message as Cortex serves it: SDK parts plus Cortex's metadata envelope. */
557
- export type CortexChatMessage = CortexMessage<MessagePart>;
558
- declare class CortexChatService {
559
- readonly widget: {
559
+ declare function createCortexWidget(options: {
560
+ /** The consumer's config, read at each use so a change lands. */
561
+ getConfig: () => CortexConfig;
562
+ }): {
563
+ copyScreen: {
564
+ getState: () => CortexWidgetState;
565
+ getDraft: () => string;
566
+ setDraft: (next: string) => void;
567
+ submit: (text: string) => Promise<{
568
+ readonly sent: false;
569
+ readonly text: string;
570
+ } | {
571
+ readonly sent: true;
572
+ }>;
573
+ sendDraft: (launch: (text: string) => void) => void;
574
+ abort: () => Promise<void>;
575
+ cancelQueued: (inputId: string) => Promise<void>;
576
+ sendQueuedNow: (inputId: string) => Promise<void>;
577
+ addToolResult: () => Promise<void>;
578
+ respondToApproval: () => Promise<void>;
579
+ /** Cortex's API for this widget's agent, reading the transport off the config at every call. */
560
580
  api: {
561
581
  onVisitorReplaced(heard: () => void): () => void;
562
582
  retrySignIn(): void;
563
- getCapabilities(): Promise<AgentCapabilities$1>;
583
+ getCapabilities(): Promise<AgentCapabilities>;
564
584
  listThreads(): Promise<ThreadSummary[]>;
565
585
  createThread(): Promise<ThreadSummary>;
566
586
  deleteThread(threadId: string): Promise<void>;
567
587
  listMessages(threadId: string): Promise<CortexChatMessage[]>;
568
- listLlmRequests(threadId: string, messageId: string): Promise<LlmRequest$1[]>;
569
- abortStream(threadId: string): Promise<AbortRunResult$1>;
570
- initiateToolCall(threadId: string, toolCallId: string): Promise<ClientToolInitiateResult$1>;
571
- accountConnection(server: string, toolCallId: string, signal?: AbortSignal): Promise<AccountConnection$1>;
572
- uploadAttachment(threadId: string, file: File): Promise<AttachmentSummary$1>;
588
+ listLlmRequests(threadId: string, messageId: string): Promise<LlmRequest[]>;
589
+ abortStream(threadId: string): Promise<AbortRunResult>;
590
+ queueMessage(threadId: string, runId: string, message: {
591
+ id: string;
592
+ content: string;
593
+ metadata: MessageMetadata;
594
+ }, busy?: MessageBusy): Promise<{
595
+ inputId: string;
596
+ state: "waiting";
597
+ delivery: "prompt" | "steer" | "followUp" | "answer" | "note";
598
+ } | {
599
+ inputId: string | null;
600
+ state: "refused";
601
+ reason: "busy" | "approval_pending" | "conflict" | "rate_limited" | "budget" | "full" | "not_waiting";
602
+ } | {
603
+ inputId: string;
604
+ state: "cancelled";
605
+ reason: "stopped";
606
+ } | {
607
+ readonly state: "started";
608
+ }>;
609
+ listInputs(threadId: string): Promise<WaitingInput<import("@tanstack/ai").MessagePart>[]>;
610
+ cancelInput(threadId: string, inputId: string): Promise<void>;
611
+ moveInput(threadId: string, inputId: string, busy: MessageBusy): Promise<void>;
612
+ getRun(id: string): Promise<{
613
+ id: string;
614
+ threadId: string | null;
615
+ inputId: string | null;
616
+ kind: "turn" | "subagent" | "tool";
617
+ subagentRunId: string | null;
618
+ status: "running" | "waiting" | "completed" | "failed" | "cancelled";
619
+ reason: "cancelled" | "no_output" | "invalid_output" | "stopped" | "parent_cancelled" | "lost" | "timeout" | null;
620
+ result: unknown;
621
+ waits: {
622
+ kind: "approval" | "client_tool";
623
+ toolCallId: string;
624
+ toolName: string;
625
+ input: unknown;
626
+ }[];
627
+ createdAt: string;
628
+ finishedAt: string | null;
629
+ }>;
630
+ cancelRun(id: string): Promise<{
631
+ cancelled: boolean;
632
+ }>;
633
+ initiateToolCall(threadId: string, toolCallId: string): Promise<ClientToolInitiateResult>;
634
+ accountConnection(server: string, toolCallId: string, signal?: AbortSignal): Promise<AccountConnection>;
635
+ uploadAttachment(threadId: string, file: File): Promise<AttachmentSummary>;
573
636
  deleteAttachment(id: string): Promise<void>;
574
637
  downloadAttachment(id: string): Promise<{
575
638
  blob: Blob;
@@ -581,22 +644,39 @@ declare class CortexChatService {
581
644
  resolveUrl: (path: string) => string;
582
645
  readVisitorAnswer: (response: Response, sent: HeadersInit | undefined) => "refused" | "stale" | undefined;
583
646
  };
584
- getState: () => CortexWidgetState;
585
- getDraft: () => string;
586
647
  subscribe: (listener: () => void) => () => void;
587
648
  start: () => void;
588
649
  stop: () => void;
589
- setDraft: (text: string) => void;
590
- submit: (text: string) => Promise<{
591
- readonly sent: false;
592
- readonly text: string;
593
- } | {
594
- readonly sent: true;
595
- }>;
596
- sendDraft: (launch: (text: string) => void) => void;
597
- abort: () => Promise<void>;
598
- addToolResult: (toolCallId: string, toolName: string, output: unknown) => Promise<void>;
599
- respondToApproval: (call: import("@tanstack/ai").ToolCallPart, approved: boolean) => Promise<void>;
650
+ /**
651
+ * Cancels a check-back the agent scheduled on the open thread, by its
652
+ * input id: its line says so at once, and again as it was once Cortex
653
+ * refuses (the check-back came due first).
654
+ */
655
+ cancelCheckBack(inputId: string): Promise<void>;
656
+ /** Picks where the message being written goes while a run works (`composerBusy`). */
657
+ pickBusy: (busy: MessageBusy) => void;
658
+ /** Reads a copy's run, as its card asks (`subagentCard`'s `readsRun`). */
659
+ readCopy: (id: string) => Promise<{
660
+ id: string;
661
+ threadId: string | null;
662
+ inputId: string | null;
663
+ kind: "turn" | "subagent" | "tool";
664
+ subagentRunId: string | null;
665
+ status: "running" | "waiting" | "completed" | "failed" | "cancelled";
666
+ reason: "cancelled" | "no_output" | "invalid_output" | "stopped" | "parent_cancelled" | "lost" | "timeout" | null;
667
+ result: unknown;
668
+ waits: {
669
+ kind: "approval" | "client_tool";
670
+ toolCallId: string;
671
+ toolName: string;
672
+ input: unknown;
673
+ }[];
674
+ createdAt: string;
675
+ finishedAt: string | null;
676
+ } | undefined>;
677
+ cancelCopy: (id: string) => Promise<void>;
678
+ openCopy: (id: string, focus?: boolean) => void;
679
+ closeCopy: () => void;
600
680
  openThread: (thread: ThreadSummary) => void;
601
681
  newChat: () => void;
602
682
  deleteThread: (threadId: string) => Promise<void>;
@@ -605,8 +685,150 @@ declare class CortexChatService {
605
685
  openHistory: () => void;
606
686
  closeHistory: () => void;
607
687
  toggleDebug: () => void;
688
+ /** Asks Cortex everything again now, signing in afresh, as a visitor the reCAPTCHA check refused does on "Try again". */
608
689
  retry: () => void;
609
690
  };
691
+ /** Cortex's API for this widget's agent, reading the transport off the config at every call. */
692
+ api: {
693
+ onVisitorReplaced(heard: () => void): () => void;
694
+ retrySignIn(): void;
695
+ getCapabilities(): Promise<AgentCapabilities>;
696
+ listThreads(): Promise<ThreadSummary[]>;
697
+ createThread(): Promise<ThreadSummary>;
698
+ deleteThread(threadId: string): Promise<void>;
699
+ listMessages(threadId: string): Promise<CortexChatMessage[]>;
700
+ listLlmRequests(threadId: string, messageId: string): Promise<LlmRequest[]>;
701
+ abortStream(threadId: string): Promise<AbortRunResult>;
702
+ queueMessage(threadId: string, runId: string, message: {
703
+ id: string;
704
+ content: string;
705
+ metadata: MessageMetadata;
706
+ }, busy?: MessageBusy): Promise<{
707
+ inputId: string;
708
+ state: "waiting";
709
+ delivery: "prompt" | "steer" | "followUp" | "answer" | "note";
710
+ } | {
711
+ inputId: string | null;
712
+ state: "refused";
713
+ reason: "busy" | "approval_pending" | "conflict" | "rate_limited" | "budget" | "full" | "not_waiting";
714
+ } | {
715
+ inputId: string;
716
+ state: "cancelled";
717
+ reason: "stopped";
718
+ } | {
719
+ readonly state: "started";
720
+ }>;
721
+ listInputs(threadId: string): Promise<WaitingInput<import("@tanstack/ai").MessagePart>[]>;
722
+ cancelInput(threadId: string, inputId: string): Promise<void>;
723
+ moveInput(threadId: string, inputId: string, busy: MessageBusy): Promise<void>;
724
+ getRun(id: string): Promise<{
725
+ id: string;
726
+ threadId: string | null;
727
+ inputId: string | null;
728
+ kind: "turn" | "subagent" | "tool";
729
+ subagentRunId: string | null;
730
+ status: "running" | "waiting" | "completed" | "failed" | "cancelled";
731
+ reason: "cancelled" | "no_output" | "invalid_output" | "stopped" | "parent_cancelled" | "lost" | "timeout" | null;
732
+ result: unknown;
733
+ waits: {
734
+ kind: "approval" | "client_tool";
735
+ toolCallId: string;
736
+ toolName: string;
737
+ input: unknown;
738
+ }[];
739
+ createdAt: string;
740
+ finishedAt: string | null;
741
+ }>;
742
+ cancelRun(id: string): Promise<{
743
+ cancelled: boolean;
744
+ }>;
745
+ initiateToolCall(threadId: string, toolCallId: string): Promise<ClientToolInitiateResult>;
746
+ accountConnection(server: string, toolCallId: string, signal?: AbortSignal): Promise<AccountConnection>;
747
+ uploadAttachment(threadId: string, file: File): Promise<AttachmentSummary>;
748
+ deleteAttachment(id: string): Promise<void>;
749
+ downloadAttachment(id: string): Promise<{
750
+ blob: Blob;
751
+ name: string;
752
+ }>;
753
+ resolveHeaders: () => Promise<{
754
+ [x: string]: string;
755
+ }>;
756
+ resolveUrl: (path: string) => string;
757
+ readVisitorAnswer: (response: Response, sent: HeadersInit | undefined) => "refused" | "stale" | undefined;
758
+ };
759
+ getState: () => CortexWidgetState;
760
+ getDraft: () => string;
761
+ subscribe: (listener: () => void) => () => void;
762
+ start: () => void;
763
+ stop: () => void;
764
+ setDraft: (next: string) => void;
765
+ submit: (text: string, busy?: MessageBusy) => Promise<{
766
+ readonly sent: false;
767
+ readonly text: string;
768
+ } | {
769
+ readonly sent: true;
770
+ }>;
771
+ sendDraft: (launch: (text: string) => void) => void;
772
+ abort: () => Promise<void>;
773
+ /** Cancels a message waiting on the open thread. */
774
+ cancelQueued: (inputId: string) => Promise<void>;
775
+ /**
776
+ * Cancels a check-back the agent scheduled on the open thread, by its
777
+ * input id: its line says so at once, and again as it was once Cortex
778
+ * refuses (the check-back came due first).
779
+ */
780
+ cancelCheckBack(inputId: string): Promise<void>;
781
+ /** Sends a message queued on the open thread now, into the running turn. */
782
+ sendQueuedNow: (inputId: string) => Promise<void>;
783
+ /** Picks where the message being written goes while a run works (`composerBusy`). */
784
+ pickBusy: (busy: MessageBusy) => void;
785
+ /** Reads a copy's run, as its card asks (`subagentCard`'s `readsRun`). */
786
+ readCopy: (id: string) => Promise<{
787
+ id: string;
788
+ threadId: string | null;
789
+ inputId: string | null;
790
+ kind: "turn" | "subagent" | "tool";
791
+ subagentRunId: string | null;
792
+ status: "running" | "waiting" | "completed" | "failed" | "cancelled";
793
+ reason: "cancelled" | "no_output" | "invalid_output" | "stopped" | "parent_cancelled" | "lost" | "timeout" | null;
794
+ result: unknown;
795
+ waits: {
796
+ kind: "approval" | "client_tool";
797
+ toolCallId: string;
798
+ toolName: string;
799
+ input: unknown;
800
+ }[];
801
+ createdAt: string;
802
+ finishedAt: string | null;
803
+ } | undefined>;
804
+ cancelCopy: (id: string) => Promise<void>;
805
+ openCopy: (id: string, focus?: boolean) => void;
806
+ closeCopy: () => void;
807
+ addToolResult: (toolCallId: string, toolName: string, output: unknown) => Promise<void>;
808
+ respondToApproval: (call: ToolCallPart, approved: boolean) => Promise<void>;
809
+ openThread: (thread: ThreadSummary) => void;
810
+ newChat: () => void;
811
+ deleteThread: (threadId: string) => Promise<void>;
812
+ attachFiles: (files: File[]) => void;
813
+ removeAttachment: (localId: string) => void;
814
+ openHistory: () => void;
815
+ closeHistory: () => void;
816
+ toggleDebug: () => void;
817
+ /** Asks Cortex everything again now, signing in afresh, as a visitor the reCAPTCHA check refused does on "Try again". */
818
+ retry: () => void;
819
+ };
820
+ /** The widget as a screen draws it: its own, or as a copy's screen has it (`copyScreen`). */
821
+ export type CortexWidget = Omit<ReturnType<typeof createCortexWidget>, "copyScreen">;
822
+ export type CortexAngularConfig = CortexConfig & {
823
+ toolComponents?: Record<string, Type<CortexToolComponentInputs>>;
824
+ injector?: Injector;
825
+ };
826
+ /** The landing's context, its composer a template to place with `ngTemplateOutlet`. */
827
+ export type CortexLandingContext = LandingContext<TemplateRef<unknown>>;
828
+ /** Each part of the widget a consumer can draw itself, with the context it receives. */
829
+ export type CortexAngularSlotContexts = CortexSlotContexts<TemplateRef<unknown>>;
830
+ declare class CortexChatService {
831
+ readonly widget: CortexWidget;
610
832
  private readonly snapshot;
611
833
  private readonly text;
612
834
  readonly state: import("@angular/core").Signal<CortexWidgetState>;
@@ -685,7 +907,6 @@ export declare class CortexChatWidgetComponent implements OnInit {
685
907
  openThread: (thread: ThreadSummary) => void;
686
908
  };
687
909
  }>;
688
- protected readonly composerSlot: import("@angular/core").Signal<"translate_access_refused" | "translate_visitor_unverified" | "translate_agent_unreachable" | "translate_agent_missing" | "composer" | "translate_read_only" | "translate_messages_disabled" | undefined>;
689
910
  private readonly injector;
690
911
  constructor();
691
912
  ngOnInit(): void;