@meandr/chat-sdk 0.0.0-stage → 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/LICENSE +201 -0
- package/README.md +338 -2
- package/dist/api.d.ts +24 -0
- package/dist/client.d.ts +2 -0
- package/dist/errors.d.ts +18 -0
- package/dist/global.d.ts +3 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1585 -0
- package/dist/index.js.map +7 -0
- package/dist/markdown.d.ts +17 -0
- package/dist/markdown.js +927 -0
- package/dist/markdown.js.map +7 -0
- package/dist/meandr-chat.js +11 -0
- package/dist/meandr-chat.js.map +7 -0
- package/dist/sse.d.ts +17 -0
- package/dist/token.d.ts +26 -0
- package/dist/types.d.ts +127 -0
- package/package.json +53 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { ChatError } from "./errors.js";
|
|
2
|
+
export interface Conversation {
|
|
3
|
+
id: string;
|
|
4
|
+
createdAt: string;
|
|
5
|
+
updatedAt: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Message {
|
|
8
|
+
id: number;
|
|
9
|
+
role: "user" | "assistant";
|
|
10
|
+
text: string;
|
|
11
|
+
tools?: string[];
|
|
12
|
+
toolTitles?: Record<string, string>;
|
|
13
|
+
files?: ChatFile[];
|
|
14
|
+
createdAt: string;
|
|
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
|
+
}
|
|
28
|
+
export type Stop = "end" | "max_tokens" | "refusal" | "paused" | (string & {});
|
|
29
|
+
export type ToolStatus = "started" | "done" | "failed" | (string & {});
|
|
30
|
+
export interface ToolProgress {
|
|
31
|
+
name: string;
|
|
32
|
+
status: ToolStatus;
|
|
33
|
+
title: string;
|
|
34
|
+
}
|
|
35
|
+
export interface Answer {
|
|
36
|
+
text: string;
|
|
37
|
+
tools: readonly ToolProgress[];
|
|
38
|
+
}
|
|
39
|
+
export type ChatStatus = "idle" | "opening" | "ready" | "error";
|
|
40
|
+
export interface Waiting {
|
|
41
|
+
code: "rate_limited" | "overloaded" | "not_connected" | "busy" | "network" | (string & {});
|
|
42
|
+
until: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ChatState {
|
|
45
|
+
readonly status: ChatStatus;
|
|
46
|
+
readonly anonymous: boolean | null;
|
|
47
|
+
readonly conversation: Conversation | null;
|
|
48
|
+
readonly messages: readonly Message[];
|
|
49
|
+
readonly outgoing: string | null;
|
|
50
|
+
readonly answer: Answer | null;
|
|
51
|
+
readonly answering: boolean;
|
|
52
|
+
readonly waiting: Waiting | null;
|
|
53
|
+
readonly stop: Stop | null;
|
|
54
|
+
readonly error: ChatError | null;
|
|
55
|
+
readonly files: FileLimits | null;
|
|
56
|
+
}
|
|
57
|
+
export type SendResult = {
|
|
58
|
+
ok: true;
|
|
59
|
+
message: Message;
|
|
60
|
+
stop: Stop | null;
|
|
61
|
+
} | {
|
|
62
|
+
ok: false;
|
|
63
|
+
error: ChatError;
|
|
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
|
+
}
|
|
90
|
+
export interface TokenRequest {
|
|
91
|
+
expired: boolean;
|
|
92
|
+
signal: AbortSignal;
|
|
93
|
+
}
|
|
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
|
+
}
|
|
101
|
+
export interface ChatOptions {
|
|
102
|
+
url: string;
|
|
103
|
+
token?: string | null;
|
|
104
|
+
tokenUrl?: string;
|
|
105
|
+
getToken?: TokenSource;
|
|
106
|
+
fetch?: typeof fetch;
|
|
107
|
+
context?: () => PageContext | undefined | Promise<PageContext | undefined>;
|
|
108
|
+
}
|
|
109
|
+
export interface ReopenOptions {
|
|
110
|
+
token?: string | null;
|
|
111
|
+
}
|
|
112
|
+
export interface Chat {
|
|
113
|
+
getState(): ChatState;
|
|
114
|
+
subscribe(listener: (state: ChatState) => void): () => void;
|
|
115
|
+
open(): Promise<ChatState>;
|
|
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>;
|
|
121
|
+
/** Has the assistant speak first, as the chat's start instructions say: the page can't supply them. */
|
|
122
|
+
start(): Promise<SendResult>;
|
|
123
|
+
newConversation(): void;
|
|
124
|
+
reopen(options?: ReopenOptions): Promise<ChatState>;
|
|
125
|
+
signOut(): Promise<void>;
|
|
126
|
+
destroy(): void;
|
|
127
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meandr/chat-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Meandr Chat's JavaScript client: the visitor's session, their messages and the streamed answers, and safe Markdown for them.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/meandr-inc/meandr-chat-sdk.git"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"meandr",
|
|
12
|
+
"chat",
|
|
13
|
+
"mcp"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./markdown": {
|
|
22
|
+
"types": "./dist/markdown.d.ts",
|
|
23
|
+
"default": "./dist/markdown.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"unpkg": "./dist/meandr-chat.js",
|
|
30
|
+
"jsdelivr": "./dist/meandr-chat.js",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"sideEffects": [
|
|
35
|
+
"./dist/meandr-chat.js"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "node build.mjs",
|
|
39
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"check": "npm run typecheck && npm test && npm run build",
|
|
42
|
+
"prepack": "npm run check"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"provenance": true
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "26.6.6",
|
|
50
|
+
"esbuild": "0.28.2",
|
|
51
|
+
"happy-dom": "21.0.4",
|
|
52
|
+
"typescript": "7.0.2",
|
|
53
|
+
"vitest": "5.1.0"
|
|
54
|
+
}
|
|
55
|
+
}
|