@meandr/chat-sdk 0.0.1 → 0.0.3

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/dist/sse.d.ts CHANGED
@@ -5,13 +5,13 @@ export interface SSEEvent {
5
5
  export declare class SSETooLarge extends Error {
6
6
  }
7
7
  export declare class SSEParser {
8
- private readonly maxEvent;
9
- private buf;
10
- private data;
11
- private type;
12
- private started;
13
- private skipLF;
14
- constructor(maxEvent?: number);
8
+ private readonly maxEvent_;
9
+ private buf_;
10
+ private data_;
11
+ private type_;
12
+ private started_;
13
+ private skipLF_;
14
+ constructor(maxEvent_?: number);
15
15
  push(chunk: string): SSEEvent[];
16
- private line;
16
+ private line_;
17
17
  }
package/dist/token.d.ts CHANGED
@@ -3,15 +3,15 @@ import type { ChatOptions, TokenSource } from "./types.js";
3
3
  export type Secret = () => string;
4
4
  export declare function hide(token: string): Secret;
5
5
  export type Way = {
6
- kind: "none";
6
+ kind_: "none";
7
7
  } | {
8
- kind: "token";
8
+ kind_: "token";
9
9
  token: Secret | null;
10
10
  } | {
11
- kind: "url";
11
+ kind_: "url";
12
12
  url: string;
13
13
  } | {
14
- kind: "fn";
14
+ kind_: "fn";
15
15
  fn: TokenSource;
16
16
  };
17
17
  export declare function wayOf(o: ChatOptions): Way;
@@ -20,7 +20,7 @@ export declare function renews(way: Way): boolean;
20
20
  export declare function userToken(way: Way, fetchFn: Fetch, signal: AbortSignal, expired: boolean): Promise<string | null | undefined>;
21
21
  export interface Claims {
22
22
  aud: string[];
23
- who: string;
23
+ who_: string;
24
24
  }
25
25
  export declare function claimsOf(token: string): Claims | null;
26
26
  export declare function originOf(url: string): string | null;
package/dist/types.d.ts CHANGED
@@ -3,19 +3,36 @@ export interface Conversation {
3
3
  id: string;
4
4
  createdAt: string;
5
5
  updatedAt: string;
6
+ endedAt: string | null;
7
+ title?: string;
6
8
  }
7
9
  export interface Message {
8
10
  id: number;
9
11
  role: "user" | "assistant";
10
12
  text: string;
11
13
  tools?: string[];
14
+ toolTitles?: Record<string, string>;
15
+ files?: ChatFile[];
12
16
  createdAt: string;
13
17
  }
18
+ export interface ChatFile {
19
+ id: string;
20
+ name: string;
21
+ type: string;
22
+ size: number;
23
+ createdAt: string;
24
+ }
25
+ export interface FileLimits {
26
+ types: string[];
27
+ maxBytes: number;
28
+ perMessage: number;
29
+ }
14
30
  export type Stop = "end" | "max_tokens" | "refusal" | "paused" | (string & {});
15
31
  export type ToolStatus = "started" | "done" | "failed" | (string & {});
16
32
  export interface ToolProgress {
17
33
  name: string;
18
34
  status: ToolStatus;
35
+ title: string;
19
36
  }
20
37
  export interface Answer {
21
38
  text: string;
@@ -31,12 +48,15 @@ export interface ChatState {
31
48
  readonly anonymous: boolean | null;
32
49
  readonly conversation: Conversation | null;
33
50
  readonly messages: readonly Message[];
51
+ readonly hasOlder: boolean;
34
52
  readonly outgoing: string | null;
35
53
  readonly answer: Answer | null;
36
54
  readonly answering: boolean;
37
55
  readonly waiting: Waiting | null;
38
56
  readonly stop: Stop | null;
39
57
  readonly error: ChatError | null;
58
+ readonly files: FileLimits | null;
59
+ readonly conversationList: boolean | null;
40
60
  }
41
61
  export type SendResult = {
42
62
  ok: true;
@@ -46,17 +66,81 @@ export type SendResult = {
46
66
  ok: false;
47
67
  error: ChatError;
48
68
  };
69
+ export type AttachResult = {
70
+ ok: true;
71
+ file: ChatFile;
72
+ } | {
73
+ ok: false;
74
+ error: ChatError;
75
+ };
76
+ export type ReadFileResult = {
77
+ ok: true;
78
+ blob: Blob;
79
+ } | {
80
+ ok: false;
81
+ error: ChatError;
82
+ };
83
+ export type ListConversationsResult = {
84
+ ok: true;
85
+ conversations: Conversation[];
86
+ hasMore: boolean;
87
+ } | {
88
+ ok: false;
89
+ error: ChatError;
90
+ };
91
+ export type OpenConversationResult = {
92
+ ok: true;
93
+ conversation: Conversation;
94
+ } | {
95
+ ok: false;
96
+ error: ChatError;
97
+ };
98
+ export type DeleteConversationResult = {
99
+ ok: true;
100
+ } | {
101
+ ok: false;
102
+ error: ChatError;
103
+ };
104
+ export type LoadOlderResult = {
105
+ ok: true;
106
+ messages: Message[];
107
+ } | {
108
+ ok: false;
109
+ error: ChatError;
110
+ };
111
+ export interface SendOptions {
112
+ files?: ReadonlyArray<ChatFile | string>;
113
+ }
114
+ export interface AttachOptions {
115
+ name?: string;
116
+ onProgress?: (sent: number, total: number) => void;
117
+ signal?: AbortSignal;
118
+ }
119
+ export interface ReadFileOptions {
120
+ signal?: AbortSignal;
121
+ }
122
+ export interface ListConversationsOptions {
123
+ before?: Conversation | string;
124
+ signal?: AbortSignal;
125
+ }
49
126
  export interface TokenRequest {
50
127
  expired: boolean;
51
128
  signal: AbortSignal;
52
129
  }
53
130
  export type TokenSource = (request: TokenRequest) => string | null | Promise<string | null>;
131
+ export interface PageContext {
132
+ url?: string;
133
+ title?: string;
134
+ timezone?: string;
135
+ [key: string]: unknown;
136
+ }
54
137
  export interface ChatOptions {
55
138
  url: string;
56
139
  token?: string | null;
57
140
  tokenUrl?: string;
58
141
  getToken?: TokenSource;
59
142
  fetch?: typeof fetch;
143
+ context?: () => PageContext | undefined | Promise<PageContext | undefined>;
60
144
  }
61
145
  export interface ReopenOptions {
62
146
  token?: string | null;
@@ -65,10 +149,25 @@ export interface Chat {
65
149
  getState(): ChatState;
66
150
  subscribe(listener: (state: ChatState) => void): () => void;
67
151
  open(): Promise<ChatState>;
68
- send(text: string): Promise<SendResult>;
152
+ send(text: string, options?: SendOptions): Promise<SendResult>;
153
+ /** Uploads a file for a message of the visitor's within the hour; with onProgress, through XMLHttpRequest. */
154
+ attach(file: Blob, options?: AttachOptions): Promise<AttachResult>;
155
+ /** Fetches a file the visitor attached, with the session's credentials, for an object URL. */
156
+ readFile(file: ChatFile | string, options?: ReadFileOptions): Promise<ReadFileResult>;
69
157
  /** Has the assistant speak first, as the chat's start instructions say: the page can't supply them. */
70
158
  start(): Promise<SendResult>;
159
+ /** Ends the conversation shown and forgets it at once; before the session opens, the one it opens on. Never rejects. */
160
+ endConversation(): Promise<void>;
161
+ /** Ends the conversation shown, as endConversation does: the next message or start begins a new one. */
71
162
  newConversation(): void;
163
+ /** Lists the user's conversations, 20 at a time, most recently active first; before goes on after that one. */
164
+ listConversations(options?: ListConversationsOptions): Promise<ListConversationsResult>;
165
+ /** Shows that conversation, its last 20 messages, once read, in place of the current one, which it doesn't end. */
166
+ openConversation(conversation: Conversation | string): Promise<OpenConversationResult>;
167
+ /** Deletes that conversation with its messages and files, where the chat lists them; one already gone counts. */
168
+ deleteConversation(conversation: Conversation | string): Promise<DeleteConversationResult>;
169
+ /** Adds the 20 messages before the oldest shown, while hasOlder; calls while one runs share it. */
170
+ loadOlder(): Promise<LoadOlderResult>;
72
171
  reopen(options?: ReopenOptions): Promise<ChatState>;
73
172
  signOut(): Promise<void>;
74
173
  destroy(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meandr/chat-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Meandr Chat's JavaScript client: the visitor's session, their messages and the streamed answers, and safe Markdown for them.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {