@m6d/cortex-angular 0.14.0 → 0.15.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.
- package/README.md +12 -7
- package/fesm2022/m6d-cortex-angular.mjs +4691 -4497
- package/package.json +2 -9
- package/types/m6d-cortex-angular.d.ts +346 -214
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
4
|
import { Injector, OnInit, Signal, TemplateRef, Type } from '@angular/core';
|
|
5
|
-
import { ToolCallPart, UIMessage } from '@tanstack/ai';
|
|
6
|
-
import { Observable } from 'rxjs';
|
|
5
|
+
import { MessagePart, ToolCallPart, UIMessage } from '@tanstack/ai';
|
|
7
6
|
|
|
8
7
|
declare const LOCALES: readonly [
|
|
9
8
|
"en",
|
|
10
9
|
"ar"
|
|
11
10
|
];
|
|
12
11
|
export type Locale = (typeof LOCALES)[number];
|
|
12
|
+
declare const MESSAGE_ROLES: readonly [
|
|
13
|
+
"system",
|
|
14
|
+
"user",
|
|
15
|
+
"assistant",
|
|
16
|
+
"trigger"
|
|
17
|
+
];
|
|
18
|
+
export type MessageRole = (typeof MESSAGE_ROLES)[number];
|
|
13
19
|
declare const ATTACHMENT_STATUSES: readonly [
|
|
14
20
|
"pending",
|
|
15
21
|
"described",
|
|
@@ -55,6 +61,20 @@ export type ThreadSummary = {
|
|
|
55
61
|
export type CreateThreadRequest = {
|
|
56
62
|
variables?: Record<string, string | number | boolean>;
|
|
57
63
|
};
|
|
64
|
+
export type TokenUsage = {
|
|
65
|
+
input: {
|
|
66
|
+
noCache: number;
|
|
67
|
+
cacheRead: number;
|
|
68
|
+
cacheWrite: number;
|
|
69
|
+
total: number;
|
|
70
|
+
};
|
|
71
|
+
output: {
|
|
72
|
+
reasoning: number;
|
|
73
|
+
text: number;
|
|
74
|
+
total: number;
|
|
75
|
+
};
|
|
76
|
+
total: number;
|
|
77
|
+
};
|
|
58
78
|
/**
|
|
59
79
|
* What Cortex offers this agent's clients, fetched once at widget startup.
|
|
60
80
|
* The widget hides UI for anything absent; Cortex enforces each.
|
|
@@ -79,6 +99,17 @@ export type AgentCapabilities = {
|
|
|
79
99
|
*/
|
|
80
100
|
debug: boolean;
|
|
81
101
|
};
|
|
102
|
+
export type MessageMetadata = {
|
|
103
|
+
/** ISO time Cortex stored the message; stamped from the row when a transcript is served. */
|
|
104
|
+
createdAt?: string;
|
|
105
|
+
modelId?: string;
|
|
106
|
+
providerMetadata?: unknown;
|
|
107
|
+
isAborted?: boolean;
|
|
108
|
+
tokenUsage?: TokenUsage;
|
|
109
|
+
attachments?: AttachmentSummary[];
|
|
110
|
+
/** Set on `trigger` messages: the firing that wrote them. */
|
|
111
|
+
trigger?: TriggerFiringSummary;
|
|
112
|
+
};
|
|
82
113
|
/**
|
|
83
114
|
* One landing-page chip: the widget shows `title` and sends `prompt` as the
|
|
84
115
|
* first message when clicked. The two may be the same text.
|
|
@@ -90,6 +121,52 @@ export type Suggestion = {
|
|
|
90
121
|
/** The manifest's suggestion and greeting schemas are built from these. */
|
|
91
122
|
export type Suggestions = Record<Locale, Suggestion[]>;
|
|
92
123
|
export type Greeting = Record<Locale, string>;
|
|
124
|
+
export type TriggerFiringSummary = {
|
|
125
|
+
name: string;
|
|
126
|
+
firingId: string;
|
|
127
|
+
firedAt: string;
|
|
128
|
+
payload: unknown;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* A stored message as it is persisted and served: the SDK's parts plus the
|
|
132
|
+
* envelope Cortex derives for the UIs, carried in the SDK message's own
|
|
133
|
+
* `metadata` bag so it travels with the message over the stream and the
|
|
134
|
+
* transcript alike.
|
|
135
|
+
*
|
|
136
|
+
* `TPart` stays generic so this file keeps its zero dependencies — both
|
|
137
|
+
* sides substitute the SDK's `MessagePart`.
|
|
138
|
+
*/
|
|
139
|
+
export type CortexMessage<TPart = unknown> = {
|
|
140
|
+
id: string;
|
|
141
|
+
/** `trigger` rows carry a firing's instructions; the UIs render them as an event, not a bubble. */
|
|
142
|
+
role: MessageRole;
|
|
143
|
+
parts: TPart[];
|
|
144
|
+
metadata?: MessageMetadata;
|
|
145
|
+
};
|
|
146
|
+
declare const TRIGGER_DROP_REASONS: readonly [
|
|
147
|
+
"busy",
|
|
148
|
+
"approval_pending",
|
|
149
|
+
"budget",
|
|
150
|
+
"rate_limited"
|
|
151
|
+
];
|
|
152
|
+
export type TriggerDropReason = (typeof TRIGGER_DROP_REASONS)[number];
|
|
153
|
+
/**
|
|
154
|
+
* Body of a `POST /chat` the thread did not take: 409 while a run holds the
|
|
155
|
+
* thread or a call on it waits for a decision, or when the answers it
|
|
156
|
+
* carried fit no open call, were already applied, or answer a call whose
|
|
157
|
+
* origin is out of reach (`no_turn`); 429 once the agent's request bucket is
|
|
158
|
+
* spent, with `Retry-After`.
|
|
159
|
+
*/
|
|
160
|
+
export type ChatDropped = {
|
|
161
|
+
outcome: "dropped";
|
|
162
|
+
reason: Exclude<TriggerDropReason, "budget"> | "no_turn";
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* The drop a widget tells its user about by name: a call on the thread waits
|
|
166
|
+
* for approval, so the message goes back to the composer. Any other drop
|
|
167
|
+
* shows as a failed turn.
|
|
168
|
+
*/
|
|
169
|
+
export type SendRefusal = Extract<ChatDropped["reason"], "approval_pending">;
|
|
93
170
|
export type CortexHeaders = Record<string, string>;
|
|
94
171
|
/**
|
|
95
172
|
* How the widget reaches Cortex. `baseUrl` may be a thunk so a consumer with
|
|
@@ -98,7 +175,12 @@ export type CortexHeaders = Record<string, string>;
|
|
|
98
175
|
*/
|
|
99
176
|
export type CortexTransport = {
|
|
100
177
|
baseUrl: string | (() => string);
|
|
101
|
-
|
|
178
|
+
/**
|
|
179
|
+
* The headers every call carries, usually the end user's bearer. Left out
|
|
180
|
+
* for an anonymous agent: the widget signs in as a visitor, and Cortex
|
|
181
|
+
* gives this browser an id it keeps and sends from then on.
|
|
182
|
+
*/
|
|
183
|
+
getHeaders?: () => CortexHeaders | Promise<CortexHeaders>;
|
|
102
184
|
/**
|
|
103
185
|
* Sent with every thread the widget creates. The console's playground puts
|
|
104
186
|
* a test thread's variables here; Cortex honours it only from a verified
|
|
@@ -262,8 +344,12 @@ export type CortexSlotContexts<View> = {
|
|
|
262
344
|
landing: LandingContext<View>;
|
|
263
345
|
threadList: CortexThreadListContext;
|
|
264
346
|
};
|
|
265
|
-
/**
|
|
266
|
-
|
|
347
|
+
/**
|
|
348
|
+
* Why Cortex left a read unanswered: it could not be reached (or failed),
|
|
349
|
+
* it refused the caller's sign-in (401), the agent's reCAPTCHA check
|
|
350
|
+
* refused the visitor, or it serves no such agent (404).
|
|
351
|
+
*/
|
|
352
|
+
export type Unanswered = "unreachable" | "refused" | "unverified" | "missing";
|
|
267
353
|
/** Why the composer refused a file before uploading it: the attachment policy's reason, or one file too many. */
|
|
268
354
|
export type AttachmentRefusal = Exclude<ReturnType<typeof checkAttachmentPolicy>, "ok"> | "count";
|
|
269
355
|
export type QueuedAttachment = {
|
|
@@ -276,21 +362,86 @@ export type QueuedAttachment = {
|
|
|
276
362
|
attachmentId?: string;
|
|
277
363
|
summary?: AttachmentSummary;
|
|
278
364
|
};
|
|
279
|
-
/**
|
|
280
|
-
* Why Cortex left a read unanswered: it could not be reached (or failed),
|
|
281
|
-
* it refused the caller's sign-in (401), or it serves no such agent (404).
|
|
282
|
-
*/
|
|
283
|
-
export type Unanswered = "unreachable" | "refused" | "missing";
|
|
284
365
|
/**
|
|
285
366
|
* A turn shown as failed, with Cortex's reason when it gave one (a message
|
|
286
367
|
* that never got out has none). The reason may name the model provider's
|
|
287
|
-
* answer, so
|
|
288
|
-
* message Cortex refused names why instead.
|
|
368
|
+
* answer, so the widget's state keeps it only where Cortex sends the debug
|
|
369
|
+
* view. A message Cortex refused names why instead.
|
|
289
370
|
*/
|
|
290
371
|
export type TurnFailure = {
|
|
291
372
|
reason: string | undefined;
|
|
292
373
|
refusal?: SendRefusal;
|
|
293
374
|
};
|
|
375
|
+
/** The open conversation, as a widget draws it. */
|
|
376
|
+
export type ChatSessionState = {
|
|
377
|
+
/** Each carries Cortex's envelope (usage, model id, attachments, time) in its `metadata`. */
|
|
378
|
+
messages: UIMessage[];
|
|
379
|
+
isAgentWorking: boolean;
|
|
380
|
+
isLoadingMessages: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* A call is owed an answer. Only while no stream is open: mid-turn an open
|
|
383
|
+
* call is a tool Cortex is running. Read off the transcript, so the composer
|
|
384
|
+
* comes back the moment an answer settles its call, long before the
|
|
385
|
+
* continuation it sends ends.
|
|
386
|
+
*/
|
|
387
|
+
hasPendingToolCalls: boolean;
|
|
388
|
+
/** A call waits for the user to approve or deny it: no message may go out until it is decided. */
|
|
389
|
+
awaitsApproval: boolean;
|
|
390
|
+
/** The last turn failed: Cortex said its run failed, or the message never got out. */
|
|
391
|
+
turnFailure: TurnFailure | undefined;
|
|
392
|
+
};
|
|
393
|
+
/** Everything a widget draws, the same for every framework. */
|
|
394
|
+
export type CortexWidgetState = {
|
|
395
|
+
/** Newest first; undefined until the first list read lands or Cortex refuses it. */
|
|
396
|
+
threads: ThreadSummary[] | undefined;
|
|
397
|
+
/** The open thread, as the list has it now; undefined on a blank chat. */
|
|
398
|
+
selected: ThreadSummary | undefined;
|
|
399
|
+
/**
|
|
400
|
+
* The open thread's conversation; blank while none is open. A failed
|
|
401
|
+
* turn's reason may name the model provider's answer, so it is here only
|
|
402
|
+
* where Cortex sends this caller the debug view.
|
|
403
|
+
*/
|
|
404
|
+
session: ChatSessionState;
|
|
405
|
+
/** What Cortex offers this agent's clients; undefined until the handshake answers. */
|
|
406
|
+
capabilities: AgentCapabilities | undefined;
|
|
407
|
+
/** Why the handshake has not answered yet, once a try has failed. */
|
|
408
|
+
unanswered: Unanswered | undefined;
|
|
409
|
+
/** The files held for the next message. */
|
|
410
|
+
attachments: QueuedAttachment[];
|
|
411
|
+
/** A thread is being created for the message on its way out; the composer waits for it. */
|
|
412
|
+
creating: boolean;
|
|
413
|
+
screen: "chat" | "threads";
|
|
414
|
+
/** Full mode's history sidebar, slid in on a narrow viewport. */
|
|
415
|
+
sidebarOpen: boolean;
|
|
416
|
+
/** The reader's debug toggle; on only while the handshake offers the debug view. */
|
|
417
|
+
debugMode: boolean;
|
|
418
|
+
/**
|
|
419
|
+
* What the header, landing and history are drawn from: one object until
|
|
420
|
+
* one of its fields changes, which a streamed chunk does only as the turn
|
|
421
|
+
* starts and stops working, so a framework redraws them only then.
|
|
422
|
+
*/
|
|
423
|
+
parts: Pick<CortexWidgetState, "threads" | "selected" | "capabilities" | "debugMode"> & {
|
|
424
|
+
isWorking: boolean;
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
export type CortexAngularConfig = CortexConfig & {
|
|
428
|
+
toolComponents?: Record<string, Type<CortexToolComponentInputs>>;
|
|
429
|
+
injector?: Injector;
|
|
430
|
+
};
|
|
431
|
+
/** The landing's context, its composer a template to place with `ngTemplateOutlet`. */
|
|
432
|
+
export type CortexLandingContext = LandingContext<TemplateRef<unknown>>;
|
|
433
|
+
/** Each part of the widget a consumer can draw itself, with the context it receives. */
|
|
434
|
+
export type CortexAngularSlotContexts = CortexSlotContexts<TemplateRef<unknown>>;
|
|
435
|
+
declare const LOCALES$1: readonly [
|
|
436
|
+
"en",
|
|
437
|
+
"ar"
|
|
438
|
+
];
|
|
439
|
+
type Locale$1 = (typeof LOCALES$1)[number];
|
|
440
|
+
declare const TOOL_SURFACES: readonly [
|
|
441
|
+
"inline",
|
|
442
|
+
"modal"
|
|
443
|
+
];
|
|
444
|
+
export type ToolSurface = (typeof TOOL_SURFACES)[number];
|
|
294
445
|
declare const ATTACHMENT_STATUSES$1: readonly [
|
|
295
446
|
"pending",
|
|
296
447
|
"described",
|
|
@@ -312,234 +463,215 @@ export type AttachmentSummary$1 = {
|
|
|
312
463
|
origin: AttachmentOrigin$1;
|
|
313
464
|
description: string | null;
|
|
314
465
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Response of `POST /chat/:threadId/abort`. `aborted: false` means there was no
|
|
468
|
+
* live run to abort — the turn had already committed — so the caller must not
|
|
469
|
+
* present the turn as aborted and should read the settled state back instead.
|
|
470
|
+
*/
|
|
471
|
+
export type AbortRunResult$1 = {
|
|
472
|
+
aborted: boolean;
|
|
318
473
|
};
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
private readonly flags;
|
|
326
|
-
readonly uploading: import("@angular/core").Signal<boolean>;
|
|
327
|
-
readonly busy: import("@angular/core").Signal<boolean>;
|
|
328
|
-
readonly hasReady: import("@angular/core").Signal<boolean>;
|
|
329
|
-
private readonly chatService;
|
|
330
|
-
readonly store: {
|
|
331
|
-
getState: () => QueuedAttachment[];
|
|
332
|
-
subscribe: (listener: () => void) => () => void;
|
|
333
|
-
accept: (files: File[]) => void;
|
|
334
|
-
remove: (localId: string) => void;
|
|
335
|
-
clear: (threadId: string | undefined) => void;
|
|
336
|
-
consumeReady: () => {
|
|
337
|
-
status: "ready";
|
|
338
|
-
summary: AttachmentSummary$1;
|
|
339
|
-
localId: string;
|
|
340
|
-
filename: string;
|
|
341
|
-
refusal?: "type" | "size" | "name" | "count";
|
|
342
|
-
threadId?: string;
|
|
343
|
-
attachmentId?: string;
|
|
344
|
-
}[];
|
|
345
|
-
restoreConsumed: (threadId: string | undefined) => void;
|
|
346
|
-
discardConsumed: () => void;
|
|
474
|
+
type TokenUsage$1 = {
|
|
475
|
+
input: {
|
|
476
|
+
noCache: number;
|
|
477
|
+
cacheRead: number;
|
|
478
|
+
cacheWrite: number;
|
|
479
|
+
total: number;
|
|
347
480
|
};
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
481
|
+
output: {
|
|
482
|
+
reasoning: number;
|
|
483
|
+
text: number;
|
|
484
|
+
total: number;
|
|
485
|
+
};
|
|
486
|
+
total: number;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* What Cortex offers this agent's clients, fetched once at widget startup.
|
|
490
|
+
* The widget hides UI for anything absent; Cortex enforces each.
|
|
491
|
+
*/
|
|
492
|
+
export type AgentCapabilities$1 = {
|
|
493
|
+
attachments: boolean;
|
|
353
494
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* only answers for a thread the list has not caught up with yet.
|
|
495
|
+
* False when this caller may not send to the chat: the agent's `message`
|
|
496
|
+
* trigger is off, or the caller only reads (`readOnly`). The widget hides
|
|
497
|
+
* its composer and answers no tool call.
|
|
358
498
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
499
|
+
messages: boolean;
|
|
500
|
+
/** True when the caller only reads, as an operator inspecting a user's thread does. */
|
|
501
|
+
readOnly: boolean;
|
|
502
|
+
/** Prompt chips on the blank-chat landing per locale; clicking one sends its `prompt` as the first message. */
|
|
503
|
+
suggestions: Suggestions$1;
|
|
504
|
+
/** Headline of the blank-chat landing per locale; "" falls back to the widget's built-in copy. */
|
|
505
|
+
greeting: Greeting$1;
|
|
365
506
|
/**
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
* straight from the SDK's signals is what brings the composer back the
|
|
369
|
-
* instant `addToolResult` settles the call part — the SDK's delivery promise
|
|
370
|
-
* only resolves once the continuation turn ends, far too late to gate UI on.
|
|
507
|
+
* Whether this caller gets the debug view: tool inputs and outputs, reasoning,
|
|
508
|
+
* model calls. Cortex sends anyone else only what the widget's normal UI draws.
|
|
371
509
|
*/
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
510
|
+
debug: boolean;
|
|
511
|
+
};
|
|
512
|
+
type Suggestion$1 = {
|
|
513
|
+
title: string;
|
|
514
|
+
prompt: string;
|
|
515
|
+
};
|
|
516
|
+
type Suggestions$1 = Record<Locale$1, Suggestion$1[]>;
|
|
517
|
+
type Greeting$1 = Record<Locale$1, string>;
|
|
518
|
+
/**
|
|
519
|
+
* Response of `POST /chat/:threadId/tools/:toolCallId/initiate` for a pending
|
|
520
|
+
* call stamped with an embed. The payload is for the widget only; it never
|
|
521
|
+
* reaches the LLM.
|
|
522
|
+
*/
|
|
523
|
+
export type ClientToolInitiateResult$1 = {
|
|
524
|
+
embedUrl: string;
|
|
525
|
+
surface: ToolSurface;
|
|
526
|
+
embedOrigin: string;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* One model call of the turn that wrote a message, raw, in the order the
|
|
530
|
+
* turn ran them: `GET /threads/:threadId/messages/:messageId/llm-requests`
|
|
531
|
+
* answers a list, for the request inspector.
|
|
532
|
+
*/
|
|
533
|
+
export type LlmRequest$1 = {
|
|
534
|
+
id: string;
|
|
535
|
+
prompt: string;
|
|
536
|
+
output: string | null;
|
|
537
|
+
tokenUsage: TokenUsage$1 | null;
|
|
538
|
+
};
|
|
539
|
+
/** A message as Cortex serves it: SDK parts plus Cortex's metadata envelope. */
|
|
540
|
+
export type CortexChatMessage = CortexMessage<MessagePart>;
|
|
541
|
+
declare class CortexChatService {
|
|
542
|
+
readonly widget: {
|
|
543
|
+
api: {
|
|
544
|
+
onVisitorReplaced(heard: () => void): () => void;
|
|
545
|
+
retrySignIn(): void;
|
|
546
|
+
getCapabilities(): Promise<AgentCapabilities$1>;
|
|
547
|
+
listThreads(): Promise<ThreadSummary[]>;
|
|
548
|
+
createThread(): Promise<ThreadSummary>;
|
|
549
|
+
deleteThread(threadId: string): Promise<void>;
|
|
550
|
+
listMessages(threadId: string): Promise<CortexChatMessage[]>;
|
|
551
|
+
listLlmRequests(threadId: string, messageId: string): Promise<LlmRequest$1[]>;
|
|
552
|
+
abortStream(threadId: string): Promise<AbortRunResult$1>;
|
|
553
|
+
initiateToolCall(threadId: string, toolCallId: string): Promise<ClientToolInitiateResult$1>;
|
|
554
|
+
uploadAttachment(threadId: string, file: File): Promise<AttachmentSummary$1>;
|
|
555
|
+
deleteAttachment(id: string): Promise<void>;
|
|
556
|
+
downloadAttachment(id: string): Promise<{
|
|
557
|
+
blob: Blob;
|
|
558
|
+
name: string;
|
|
559
|
+
}>;
|
|
560
|
+
resolveHeaders: () => Promise<{
|
|
561
|
+
[x: string]: string;
|
|
562
|
+
}>;
|
|
563
|
+
resolveUrl: (path: string) => string;
|
|
564
|
+
readVisitorAnswer: (response: Response, sent: HeadersInit | undefined) => "refused" | "stale" | undefined;
|
|
565
|
+
};
|
|
566
|
+
getState: () => CortexWidgetState;
|
|
567
|
+
getDraft: () => string;
|
|
568
|
+
subscribe: (listener: () => void) => () => void;
|
|
569
|
+
start: () => void;
|
|
570
|
+
stop: () => void;
|
|
571
|
+
setDraft: (text: string) => void;
|
|
572
|
+
submit: (text: string) => Promise<{
|
|
573
|
+
readonly sent: false;
|
|
574
|
+
readonly text: string;
|
|
575
|
+
} | {
|
|
576
|
+
readonly sent: true;
|
|
577
|
+
}>;
|
|
578
|
+
sendDraft: (launch: (text: string) => void) => void;
|
|
579
|
+
abort: () => Promise<void>;
|
|
580
|
+
addToolResult: (toolCallId: string, toolName: string, output: unknown) => Promise<void>;
|
|
581
|
+
respondToApproval: (call: import("@tanstack/ai").ToolCallPart, approved: boolean) => Promise<void>;
|
|
582
|
+
openThread: (thread: ThreadSummary) => void;
|
|
583
|
+
newChat: () => void;
|
|
584
|
+
deleteThread: (threadId: string) => Promise<void>;
|
|
585
|
+
attachFiles: (files: File[]) => void;
|
|
586
|
+
removeAttachment: (localId: string) => void;
|
|
587
|
+
openHistory: () => void;
|
|
588
|
+
closeHistory: () => void;
|
|
589
|
+
toggleDebug: () => void;
|
|
590
|
+
retry: () => void;
|
|
591
|
+
};
|
|
592
|
+
private readonly snapshot;
|
|
593
|
+
private readonly text;
|
|
594
|
+
readonly state: import("@angular/core").Signal<CortexWidgetState>;
|
|
595
|
+
readonly draft: import("@angular/core").Signal<string>;
|
|
596
|
+
readonly selectedThread: import("@angular/core").Signal<ThreadSummary | undefined>;
|
|
597
|
+
readonly messages: import("@angular/core").Signal<import("@tanstack/ai").UIMessage<unknown>[]>;
|
|
598
|
+
readonly isAgentWorking: import("@angular/core").Signal<boolean>;
|
|
599
|
+
readonly debugMode: import("@angular/core").Signal<boolean>;
|
|
600
|
+
readonly turnFailure: import("@angular/core").Signal<TurnFailure | undefined>;
|
|
601
|
+
/** What the header, landing and history are drawn from: a streamed chunk leaves it as it was. */
|
|
602
|
+
readonly parts: import("@angular/core").Signal<Pick<CortexWidgetState, "threads" | "capabilities" | "debugMode" | "selected"> & {
|
|
603
|
+
isWorking: boolean;
|
|
604
|
+
}>;
|
|
398
605
|
constructor();
|
|
399
|
-
/**
|
|
400
|
-
* Kicked off by the widget once its `config` input is bound. This cannot happen in
|
|
401
|
-
* the constructor: the widget builds its children during its creation pass, which
|
|
402
|
-
* Angular runs before it binds inputs, so the transport is not knowable yet.
|
|
403
|
-
*/
|
|
404
|
-
start(): void;
|
|
405
|
-
/**
|
|
406
|
-
* Capability-gated controls stay hidden until the handshake answers, so it
|
|
407
|
-
* is asked until it does, and afresh after every reconnect: the old answer
|
|
408
|
-
* may be stale (a trigger toggled while the socket was down), so it is
|
|
409
|
-
* forgotten first. Why it has not answered is shown until an answer arrives.
|
|
410
|
-
*/
|
|
411
|
-
private loadCapabilities;
|
|
412
|
-
get events$(): Observable<"onError" | "onFinish" | "onThreadSelected" | "onSend">;
|
|
413
|
-
selectThread(thread: ThreadSummary, options?: {
|
|
414
|
-
skipLoadingMessages?: boolean;
|
|
415
|
-
}): Observable<ThreadSummary>;
|
|
416
|
-
deselectThread(): void;
|
|
417
|
-
/**
|
|
418
|
-
* The id of the thread the next message belongs to, creating it when the widget is
|
|
419
|
-
* still on a blank chat.
|
|
420
|
-
*/
|
|
421
|
-
ensureThread(): Observable<string>;
|
|
422
|
-
send(prompt: string, attachments?: AttachmentSummary[]): Observable<void>;
|
|
423
|
-
/** Answers a tool call on behalf of a tool component or the client tool
|
|
424
|
-
* embed. Returns the delivery, which fails when the answer did not reach
|
|
425
|
-
* Cortex, so the caller can ask for it again instead of stranding the call. */
|
|
426
|
-
addToolResult(toolCallId: string, toolName: string, output: unknown): Promise<void>;
|
|
427
|
-
/** The user's decision on a call the run parked on; the run resumes once delivered. */
|
|
428
|
-
respondToApproval(approvalId: string, approved: boolean): Promise<void>;
|
|
429
|
-
abort(): Promise<void>;
|
|
430
|
-
deleteThread(threadId: string): Observable<void>;
|
|
431
|
-
/**
|
|
432
|
-
* Points the widget at a thread with a chat client of its own. Cortex owns
|
|
433
|
-
* the transcript: on mount the client asks it for the transcript and for
|
|
434
|
-
* whatever run is still generating, so selecting a thread, reloading the page
|
|
435
|
-
* and a second tab all re-attach through one path.
|
|
436
|
-
*/
|
|
437
|
-
private mountChat;
|
|
438
|
-
/**
|
|
439
|
-
* Re-mounts the current thread's chat so its hydration re-reads the transcript
|
|
440
|
-
* and re-attaches to whatever run is live now. This is how a run another tab
|
|
441
|
-
* started, and a websocket that dropped and came back, land in this widget.
|
|
442
|
-
* A caller passes the thread when it holds fresher state than the list.
|
|
443
|
-
*/
|
|
444
|
-
private reattach;
|
|
445
|
-
private createConnection;
|
|
446
|
-
private refreshMessages;
|
|
447
|
-
private readBackMessages;
|
|
448
|
-
private subscribeToWsEvents;
|
|
449
|
-
/**
|
|
450
|
-
* Only what these events mean for the open conversation — their list-shaped
|
|
451
|
-
* side is CortexThreadService's, which absorbs them on its own subscription.
|
|
452
|
-
*/
|
|
453
|
-
private onWsEvent;
|
|
454
|
-
private subscribeToWsConnections;
|
|
455
606
|
static ɵfac: i0.ɵɵFactoryDeclaration<CortexChatService, never>;
|
|
456
607
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
457
608
|
}
|
|
458
609
|
/** The chat widget: the thread list, the open conversation and its composer, for the agent `config` points at. */
|
|
459
610
|
export declare class CortexChatWidgetComponent implements OnInit {
|
|
460
611
|
readonly config: import("@angular/core").InputSignal<CortexAngularConfig>;
|
|
461
|
-
protected readonly
|
|
462
|
-
/**
|
|
463
|
-
* Whether this caller may start and delete conversations: only once the
|
|
464
|
-
* handshake says so, like every capability-gated control, and never for a
|
|
465
|
-
* caller that only reads, as an operator inspecting a thread does.
|
|
466
|
-
*/
|
|
467
|
-
private readonly writes;
|
|
468
|
-
protected readonly screen: import("@angular/core").WritableSignal<"chat" | "threads">;
|
|
469
|
-
protected readonly sidebarOpen: import("@angular/core").WritableSignal<boolean>;
|
|
470
|
-
protected readonly viewMode: import("@angular/core").Signal<CortexViewMode>;
|
|
471
|
-
private readonly composer;
|
|
612
|
+
protected readonly direction: import("@angular/core").Signal<"ltr" | "rtl">;
|
|
472
613
|
private readonly landingComposer;
|
|
473
614
|
/** The consumer's own parts by slot; each replaces the widget's default and gets the same context. */
|
|
474
615
|
private readonly slotDirectives;
|
|
475
616
|
protected readonly slots: import("@angular/core").Signal<Map<keyof CortexAngularSlotContexts, TemplateRef<{
|
|
476
617
|
$implicit: CortexHeaderContext | CortexThreadListContext | LandingContext<TemplateRef<unknown>>;
|
|
477
618
|
}>>>;
|
|
478
|
-
|
|
479
|
-
protected readonly
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
619
|
+
protected chat: CortexChatService;
|
|
620
|
+
protected readonly parts: import("@angular/core").Signal<{
|
|
621
|
+
chatHeader: {
|
|
622
|
+
screen: "chat" | "threads";
|
|
623
|
+
viewMode: CortexViewMode;
|
|
624
|
+
title: string | null;
|
|
625
|
+
agentName: string | undefined;
|
|
626
|
+
threadCount: number | undefined;
|
|
627
|
+
isWorking: boolean;
|
|
628
|
+
debug: {
|
|
629
|
+
shown: boolean;
|
|
630
|
+
on: boolean;
|
|
631
|
+
};
|
|
632
|
+
newChat: (() => void) | undefined;
|
|
633
|
+
openHistory: () => void;
|
|
634
|
+
closeHistory: () => void;
|
|
635
|
+
toggleDebug: () => void;
|
|
494
636
|
};
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
637
|
+
threadsHeader: {
|
|
638
|
+
screen: "chat" | "threads";
|
|
639
|
+
viewMode: CortexViewMode;
|
|
640
|
+
title: string | null;
|
|
641
|
+
agentName: string | undefined;
|
|
642
|
+
threadCount: number | undefined;
|
|
643
|
+
isWorking: boolean;
|
|
644
|
+
debug: {
|
|
645
|
+
shown: boolean;
|
|
646
|
+
on: boolean;
|
|
647
|
+
};
|
|
648
|
+
newChat: (() => void) | undefined;
|
|
649
|
+
openHistory: () => void;
|
|
650
|
+
closeHistory: () => void;
|
|
651
|
+
toggleDebug: () => void;
|
|
652
|
+
};
|
|
653
|
+
landing: {
|
|
654
|
+
threads: ThreadSummary[] | undefined;
|
|
655
|
+
composer: TemplateRef<unknown>;
|
|
656
|
+
openThread: (thread: ThreadSummary) => void;
|
|
657
|
+
openHistory: () => void;
|
|
658
|
+
greeting: string;
|
|
659
|
+
suggestions: Suggestion[];
|
|
660
|
+
send: (prompt: string) => void;
|
|
661
|
+
};
|
|
662
|
+
threadList: {
|
|
663
|
+
newChat?: (() => void) | undefined;
|
|
664
|
+
deleteThread?: ((threadId: string) => undefined) | undefined;
|
|
665
|
+
threads: ThreadSummary[] | undefined;
|
|
666
|
+
selectedThreadId: string | undefined;
|
|
667
|
+
openThread: (thread: ThreadSummary) => void;
|
|
510
668
|
};
|
|
511
669
|
}>;
|
|
512
|
-
protected readonly
|
|
513
|
-
threads: ThreadSummary[] | undefined;
|
|
514
|
-
composer: TemplateRef<unknown>;
|
|
515
|
-
openThread: (thread: ThreadSummary) => void;
|
|
516
|
-
openHistory: () => void;
|
|
517
|
-
greeting: string;
|
|
518
|
-
suggestions: Suggestion[];
|
|
519
|
-
send: (prompt: string) => void;
|
|
520
|
-
}>;
|
|
521
|
-
protected readonly threadList: import("@angular/core").Signal<{
|
|
522
|
-
deleteThread?: ((threadId: string) => import("rxjs").Subscription) | undefined;
|
|
523
|
-
newChat?: (() => void) | undefined;
|
|
524
|
-
threads: ThreadSummary[] | undefined;
|
|
525
|
-
selectedThreadId: string | undefined;
|
|
526
|
-
openThread: (thread: ThreadSummary) => void;
|
|
527
|
-
}>;
|
|
528
|
-
protected chatService: CortexChatService;
|
|
529
|
-
protected queue: AttachmentQueueService;
|
|
530
|
-
private threadService;
|
|
670
|
+
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>;
|
|
531
671
|
private readonly injector;
|
|
532
|
-
private readonly destroyRef;
|
|
533
672
|
ngOnInit(): void;
|
|
534
|
-
private headerContext;
|
|
535
|
-
protected closeSidebar(): void;
|
|
536
|
-
private toggleDebugMode;
|
|
537
|
-
private selectThread;
|
|
538
|
-
private openHistory;
|
|
539
|
-
private closeHistory;
|
|
540
673
|
protected onWidgetDragOver(event: DragEvent): void;
|
|
541
674
|
protected onWidgetDrop(event: DragEvent): void;
|
|
542
|
-
private newChat;
|
|
543
675
|
static ɵfac: i0.ɵɵFactoryDeclaration<CortexChatWidgetComponent, never>;
|
|
544
676
|
static ɵcmp: i0.ɵɵComponentDeclaration<CortexChatWidgetComponent, "cortex-chat-widget", never, {
|
|
545
677
|
"config": {
|