@ahmedramez-org/chat 0.8.0-beta.3 → 0.8.0-beta.5

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.
@@ -37,7 +37,7 @@ const userName = (raw) => {
37
37
  };
38
38
  /** An intent with exactly the fields its type needs, or `undefined`. */
39
39
  function intent(raw) {
40
- const { surface, type, pickerId, canvasId, id, query, title, sessionId, files, more, value } = Object(raw);
40
+ const { surface, type, pickerId, canvasId, id, query, title, sessionId, files, more, value, origin, } = Object(raw);
41
41
  if (surface === 'header') {
42
42
  if (type === 'newChat' || type === 'openHistory')
43
43
  return { surface, type };
@@ -64,6 +64,14 @@ function intent(raw) {
64
64
  return { surface, type };
65
65
  return type === 'select' && text(value) ? { surface, type, value } : undefined;
66
66
  }
67
+ if (surface === 'artifacts') {
68
+ if (type === 'open' || type === 'dismiss' || type === 'more')
69
+ return { surface, type };
70
+ if (type === 'origin') {
71
+ return origin === 'output' || origin === 'input' ? { surface, type, origin } : undefined;
72
+ }
73
+ return type === 'select' && text(id) ? { surface, type, id } : undefined;
74
+ }
67
75
  if (surface === 'history') {
68
76
  if (type === 'open' || type === 'dismiss' || type === 'more')
69
77
  return { surface, type };
@@ -124,6 +132,7 @@ const SURFACE_LISTS = {
124
132
  history: ['rows'],
125
133
  model: ['options'],
126
134
  canvas: ['actions'],
135
+ artifacts: ['rows'],
127
136
  };
128
137
  const isObject = (value) => typeof value === 'object' && value !== null;
129
138
  /** Keeps each surface that is an object with its lists of objects; drops the others (absent: closed). */
@@ -521,14 +521,73 @@ export type ModelIntent = {
521
521
  surface: 'model';
522
522
  type: 'dismiss';
523
523
  };
524
+ /** A file type's colour, as the chat's own cards tint it (red for PDF, green for sheets…). */
525
+ export type ArtifactAccent = 'red' | 'green' | 'blue' | 'orange' | 'amber' | 'purple' | 'cyan' | 'slate' | 'indigo';
526
+ /** One file of the conversation's artifacts list, as the chat's own card shows it. */
527
+ export interface ArtifactRow {
528
+ /** Opaque: the chat maps it back to its own file. */
529
+ id: string;
530
+ title: string;
531
+ /** A report opens as a page; a file as its preview (or a line saying it has none). */
532
+ kind: 'report' | 'file';
533
+ accent: ArtifactAccent;
534
+ /** The type on the card's badge: "Report", "PDF", "Markdown". In the chat's locale. */
535
+ badge: string;
536
+ /** "340 KB", when known. */
537
+ size?: string;
538
+ }
539
+ /**
540
+ * The conversation's artifacts (the topbar's Artifacts list), for a host that draws it: present
541
+ * while a conversation is on screen, absent on the greeting. The host opens it with `open`; the
542
+ * rows cross only while open, newest first, paged with `more`, for one origin at a time.
543
+ */
544
+ export interface ArtifactsState {
545
+ open: boolean;
546
+ /** While open: a new number each time it opens, as `ModelState.openId`. */
547
+ openId?: number;
548
+ /** `output`: what the chat made; `input`: what the user uploaded. Each opening starts on `output`. */
549
+ origin: 'output' | 'input';
550
+ rows: readonly ArtifactRow[];
551
+ loading: boolean;
552
+ hasMore: boolean;
553
+ /**
554
+ * Nothing yet (in place of rows), or could not load: a failed page ends the paging, the rows
555
+ * loaded stay and this follows them; the next opening asks again. In the chat's locale.
556
+ */
557
+ notice?: string;
558
+ /** Under an empty list's notice: what will show here. In the chat's locale. */
559
+ hint?: string;
560
+ }
561
+ /**
562
+ * What the user did in a host-drawn artifacts list. `select` names a row the chat published:
563
+ * the list closes and the canvas opens the file, as a tap on the chat's own card does.
564
+ */
565
+ export type ArtifactsIntent = {
566
+ surface: 'artifacts';
567
+ type: 'open';
568
+ } | {
569
+ surface: 'artifacts';
570
+ type: 'dismiss';
571
+ } | {
572
+ surface: 'artifacts';
573
+ type: 'more';
574
+ } | {
575
+ surface: 'artifacts';
576
+ type: 'origin';
577
+ origin: 'output' | 'input';
578
+ } | {
579
+ surface: 'artifacts';
580
+ type: 'select';
581
+ id: string;
582
+ };
524
583
  /**
525
584
  * The chat's controls a host may draw itself instead (a native app's nav bar,
526
- * history drawer, attach sheet and model chooser). For each one the host owns, the chat hides its own, publishes the
585
+ * history drawer, attach sheet, model chooser and artifacts list). For each one the host owns, the chat hides its own, publishes the
527
586
  * control's state through `handle.surfaces` and takes the user's actions back as
528
587
  * intents. Absent or empty: the chat draws everything, as before.
529
588
  */
530
589
  export type SurfaceName = (typeof SURFACE_NAMES)[number];
531
- export declare const SURFACE_NAMES: readonly ["header", "picker", "history", "model", "canvas"];
590
+ export declare const SURFACE_NAMES: readonly ["header", "picker", "history", "model", "canvas", "artifacts"];
532
591
  /** The conversation header: its title and what its controls may do now. */
533
592
  export interface HeaderState {
534
593
  /** The backend conversation; absent while it is unsent. */
@@ -539,6 +598,12 @@ export interface HeaderState {
539
598
  switching: boolean;
540
599
  /** An answer is being produced. */
541
600
  answering: boolean;
601
+ /**
602
+ * Answers that completed in this conversation since the page loaded (a failed one, or one
603
+ * stopped before it finished, does not count): a host gives its own sign as it grows (the
604
+ * app, a haptic). Absent: none yet (and from a chat before it).
605
+ */
606
+ answered?: number;
542
607
  canStartNewChat: boolean;
543
608
  canRename: boolean;
544
609
  canDelete: boolean;
@@ -643,7 +708,7 @@ export type CanvasIntent = {
643
708
  type: 'action';
644
709
  id: string;
645
710
  };
646
- export type SurfaceIntent = PickerIntent | HeaderIntent | HistoryIntent | ModelIntent | CanvasIntent;
711
+ export type SurfaceIntent = PickerIntent | HeaderIntent | HistoryIntent | ModelIntent | CanvasIntent | ArtifactsIntent;
647
712
  /** The state of each surface the host owns. */
648
713
  export interface SurfaceState {
649
714
  header?: HeaderState;
@@ -651,6 +716,7 @@ export interface SurfaceState {
651
716
  history?: HistoryState;
652
717
  model?: ModelState;
653
718
  canvas?: CanvasState;
719
+ artifacts?: ArtifactsState;
654
720
  }
655
721
  /** The surfaces a host draws, on a mount's handle. */
656
722
  export interface ChatSurfaces {
package/contract/index.js CHANGED
@@ -55,7 +55,14 @@ export function artifactMatchesSchema(artifact, supportedVersion, options) {
55
55
  return options?.acceptUnversioned ?? false;
56
56
  return artifact.schemaVersion === supportedVersion;
57
57
  }
58
- export const SURFACE_NAMES = ['header', 'picker', 'history', 'model', 'canvas'];
58
+ export const SURFACE_NAMES = [
59
+ 'header',
60
+ 'picker',
61
+ 'history',
62
+ 'model',
63
+ 'canvas',
64
+ 'artifacts',
65
+ ];
59
66
  export class ChatError extends Error {
60
67
  code;
61
68
  constructor(code, message, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahmedramez-org/chat",
3
- "version": "0.8.0-beta.3",
3
+ "version": "0.8.0-beta.5",
4
4
  "description": "Incorta's chat for any app: a connector and React component that load the prebuilt chat from IncortaCopilot (or a pinned copy), and the host contract types and checks.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {