@meandr/chat-sdk 0.0.1 → 0.0.2
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 +96 -10
- package/dist/api.d.ts +4 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +659 -421
- package/dist/index.js.map +3 -3
- package/dist/markdown.js +112 -112
- package/dist/markdown.js.map +3 -3
- package/dist/meandr-chat.js +9 -9
- package/dist/meandr-chat.js.map +3 -3
- package/dist/sse.d.ts +8 -8
- package/dist/token.d.ts +5 -5
- package/dist/types.d.ts +53 -1
- package/package.json +1 -1
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
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
constructor(
|
|
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
|
|
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
|
-
|
|
6
|
+
kind_: "none";
|
|
7
7
|
} | {
|
|
8
|
-
|
|
8
|
+
kind_: "token";
|
|
9
9
|
token: Secret | null;
|
|
10
10
|
} | {
|
|
11
|
-
|
|
11
|
+
kind_: "url";
|
|
12
12
|
url: string;
|
|
13
13
|
} | {
|
|
14
|
-
|
|
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
|
-
|
|
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
|
@@ -9,13 +9,28 @@ export interface Message {
|
|
|
9
9
|
role: "user" | "assistant";
|
|
10
10
|
text: string;
|
|
11
11
|
tools?: string[];
|
|
12
|
+
toolTitles?: Record<string, string>;
|
|
13
|
+
files?: ChatFile[];
|
|
12
14
|
createdAt: string;
|
|
13
15
|
}
|
|
16
|
+
export interface ChatFile {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
size: number;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface FileLimits {
|
|
24
|
+
types: string[];
|
|
25
|
+
maxBytes: number;
|
|
26
|
+
perMessage: number;
|
|
27
|
+
}
|
|
14
28
|
export type Stop = "end" | "max_tokens" | "refusal" | "paused" | (string & {});
|
|
15
29
|
export type ToolStatus = "started" | "done" | "failed" | (string & {});
|
|
16
30
|
export interface ToolProgress {
|
|
17
31
|
name: string;
|
|
18
32
|
status: ToolStatus;
|
|
33
|
+
title: string;
|
|
19
34
|
}
|
|
20
35
|
export interface Answer {
|
|
21
36
|
text: string;
|
|
@@ -37,6 +52,7 @@ export interface ChatState {
|
|
|
37
52
|
readonly waiting: Waiting | null;
|
|
38
53
|
readonly stop: Stop | null;
|
|
39
54
|
readonly error: ChatError | null;
|
|
55
|
+
readonly files: FileLimits | null;
|
|
40
56
|
}
|
|
41
57
|
export type SendResult = {
|
|
42
58
|
ok: true;
|
|
@@ -46,17 +62,49 @@ export type SendResult = {
|
|
|
46
62
|
ok: false;
|
|
47
63
|
error: ChatError;
|
|
48
64
|
};
|
|
65
|
+
export type AttachResult = {
|
|
66
|
+
ok: true;
|
|
67
|
+
file: ChatFile;
|
|
68
|
+
} | {
|
|
69
|
+
ok: false;
|
|
70
|
+
error: ChatError;
|
|
71
|
+
};
|
|
72
|
+
export type ReadFileResult = {
|
|
73
|
+
ok: true;
|
|
74
|
+
blob: Blob;
|
|
75
|
+
} | {
|
|
76
|
+
ok: false;
|
|
77
|
+
error: ChatError;
|
|
78
|
+
};
|
|
79
|
+
export interface SendOptions {
|
|
80
|
+
files?: ReadonlyArray<ChatFile | string>;
|
|
81
|
+
}
|
|
82
|
+
export interface AttachOptions {
|
|
83
|
+
name?: string;
|
|
84
|
+
onProgress?: (sent: number, total: number) => void;
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
export interface ReadFileOptions {
|
|
88
|
+
signal?: AbortSignal;
|
|
89
|
+
}
|
|
49
90
|
export interface TokenRequest {
|
|
50
91
|
expired: boolean;
|
|
51
92
|
signal: AbortSignal;
|
|
52
93
|
}
|
|
53
94
|
export type TokenSource = (request: TokenRequest) => string | null | Promise<string | null>;
|
|
95
|
+
export interface PageContext {
|
|
96
|
+
url?: string;
|
|
97
|
+
title?: string;
|
|
98
|
+
timezone?: string;
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
}
|
|
54
101
|
export interface ChatOptions {
|
|
55
102
|
url: string;
|
|
56
103
|
token?: string | null;
|
|
57
104
|
tokenUrl?: string;
|
|
58
105
|
getToken?: TokenSource;
|
|
59
106
|
fetch?: typeof fetch;
|
|
107
|
+
context?: () => PageContext | undefined | Promise<PageContext | undefined>;
|
|
60
108
|
}
|
|
61
109
|
export interface ReopenOptions {
|
|
62
110
|
token?: string | null;
|
|
@@ -65,7 +113,11 @@ export interface Chat {
|
|
|
65
113
|
getState(): ChatState;
|
|
66
114
|
subscribe(listener: (state: ChatState) => void): () => void;
|
|
67
115
|
open(): Promise<ChatState>;
|
|
68
|
-
send(text: string): Promise<SendResult>;
|
|
116
|
+
send(text: string, options?: SendOptions): Promise<SendResult>;
|
|
117
|
+
/** Uploads a file for a message of the visitor's within the hour; with onProgress, through XMLHttpRequest. */
|
|
118
|
+
attach(file: Blob, options?: AttachOptions): Promise<AttachResult>;
|
|
119
|
+
/** Fetches a file the visitor attached, with the session's credentials, for an object URL. */
|
|
120
|
+
readFile(file: ChatFile | string, options?: ReadFileOptions): Promise<ReadFileResult>;
|
|
69
121
|
/** Has the assistant speak first, as the chat's start instructions say: the page can't supply them. */
|
|
70
122
|
start(): Promise<SendResult>;
|
|
71
123
|
newConversation(): void;
|
package/package.json
CHANGED