@franyerhiguerey/ai-chat-client 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +18 -2
- package/dist/index.d.ts +63 -0
- package/dist/index.js +141 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Franyer Higuerey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @franyerhiguerey/ai-chat-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The browser client for an [ai-chat](https://github.com/FranyerHiguerey/ai-chat) endpoint, with zero dependencies. The `<ai-chat>` widget uses it; you only need it directly to build your own UI.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { streamChat, submitLead } from '@franyerhiguerey/ai-chat-client';
|
|
7
|
+
|
|
8
|
+
for await (const event of streamChat({ endpoint: '/api/chat', messages, lang: 'es' })) {
|
|
9
|
+
if (event.type === 'delta') append(event.text);
|
|
10
|
+
else if (event.type === 'card')
|
|
11
|
+
showCard(event); // items, handoff, lead_form
|
|
12
|
+
else if (event.type === 'suggestions') showChips(event.items);
|
|
13
|
+
else if (event.type === 'error') showError(event.message);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await submitLead({ endpoint: '/api/chat', lead: { name: 'Ana', email: 'ana@example.com' } });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Every failure arrives as one `error` event, and unknown events are skipped, so newer servers don't break older clients. The events are listed in [docs/protocol.md](https://github.com/FranyerHiguerey/ai-chat/blob/main/docs/protocol.md).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ServerEvent, StreamErrorCode, RequestErrorCode, ChatMessage, Language, LeadRequestBody } from '@franyerhiguerey/ai-chat-core/protocol';
|
|
2
|
+
export { Card, CardItem, ChatMessage, HandoffChannel, Language, LeadFields, RequestErrorCode, ServerEvent, StreamErrorCode } from '@franyerhiguerey/ai-chat-core/protocol';
|
|
3
|
+
|
|
4
|
+
interface SSEMessage {
|
|
5
|
+
event: string;
|
|
6
|
+
data: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parses a Server-Sent Events byte stream into messages, following the HTML
|
|
10
|
+
* spec's rules: lines may end in \n, \r\n or \r, chunks may split anywhere
|
|
11
|
+
* (even inside a UTF-8 character), `data:` lines accumulate, comments are skipped.
|
|
12
|
+
*/
|
|
13
|
+
declare function parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEMessage>;
|
|
14
|
+
|
|
15
|
+
/** Failures detected in the browser rather than reported by the server. */
|
|
16
|
+
type ClientErrorCode = 'network' | 'bad_response';
|
|
17
|
+
type ErrorCode = StreamErrorCode | RequestErrorCode | ClientErrorCode;
|
|
18
|
+
/**
|
|
19
|
+
* Every event `streamChat` yields. Errors from any source arrive as one `error`
|
|
20
|
+
* event, so a UI handles them in one place. Its `message` is already localized
|
|
21
|
+
* when it came from the server; for client errors, localize by `code`.
|
|
22
|
+
*/
|
|
23
|
+
type ChatEvent = Exclude<ServerEvent, {
|
|
24
|
+
type: 'error';
|
|
25
|
+
}> | {
|
|
26
|
+
type: 'error';
|
|
27
|
+
code: ErrorCode;
|
|
28
|
+
message: string;
|
|
29
|
+
};
|
|
30
|
+
interface StreamChatOptions {
|
|
31
|
+
/** URL of the site's ai-chat endpoint, e.g. `/api/chat`. */
|
|
32
|
+
endpoint: string;
|
|
33
|
+
messages: ChatMessage[];
|
|
34
|
+
lang?: Language;
|
|
35
|
+
/** Abort to stop the reply (a Stop button). The generator then just ends. */
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
/** Extra request headers. */
|
|
38
|
+
headers?: Record<string, string>;
|
|
39
|
+
/** Override fetch (tests, custom transports). */
|
|
40
|
+
fetch?: typeof fetch;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sends a conversation to an ai-chat endpoint and yields its events as they
|
|
44
|
+
* arrive. Unknown events are skipped, so newer servers don't break older clients.
|
|
45
|
+
*/
|
|
46
|
+
declare function streamChat(options: StreamChatOptions): AsyncGenerator<ChatEvent>;
|
|
47
|
+
interface SubmitLeadOptions extends LeadRequestBody {
|
|
48
|
+
/** The same endpoint the chat uses. */
|
|
49
|
+
endpoint: string;
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
fetch?: typeof fetch;
|
|
52
|
+
}
|
|
53
|
+
type SubmitLeadResult = {
|
|
54
|
+
ok: true;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
code: ErrorCode;
|
|
58
|
+
message: string;
|
|
59
|
+
};
|
|
60
|
+
/** Sends the lead form to the site's endpoint, which forwards it to the site's webhook. */
|
|
61
|
+
declare function submitLead(options: SubmitLeadOptions): Promise<SubmitLeadResult>;
|
|
62
|
+
|
|
63
|
+
export { type ChatEvent, type ClientErrorCode, type ErrorCode, type SSEMessage, type StreamChatOptions, type SubmitLeadOptions, type SubmitLeadResult, parseSSE, streamChat, submitLead };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/sse.ts
|
|
2
|
+
async function* parseSSE(stream) {
|
|
3
|
+
const reader = stream.getReader();
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
let buffer = "";
|
|
6
|
+
let event = "";
|
|
7
|
+
let data = [];
|
|
8
|
+
let finished = false;
|
|
9
|
+
function* processLines(final) {
|
|
10
|
+
for (; ; ) {
|
|
11
|
+
const match = /\r\n|\r|\n/.exec(buffer);
|
|
12
|
+
if (!match || match[0] === "\r" && match.index === buffer.length - 1 && !final) return;
|
|
13
|
+
const line = buffer.slice(0, match.index);
|
|
14
|
+
buffer = buffer.slice(match.index + match[0].length);
|
|
15
|
+
if (line === "") {
|
|
16
|
+
if (data.length > 0) yield { event: event || "message", data: data.join("\n") };
|
|
17
|
+
event = "";
|
|
18
|
+
data = [];
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (line.startsWith(":")) continue;
|
|
22
|
+
const colon = line.indexOf(":");
|
|
23
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
24
|
+
let value = colon === -1 ? "" : line.slice(colon + 1);
|
|
25
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
26
|
+
if (field === "event") event = value;
|
|
27
|
+
else if (field === "data") data.push(value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
for (; ; ) {
|
|
32
|
+
const { done, value } = await reader.read();
|
|
33
|
+
if (done) break;
|
|
34
|
+
buffer += decoder.decode(value, { stream: true });
|
|
35
|
+
yield* processLines(false);
|
|
36
|
+
}
|
|
37
|
+
buffer += decoder.decode();
|
|
38
|
+
yield* processLines(true);
|
|
39
|
+
finished = true;
|
|
40
|
+
} finally {
|
|
41
|
+
if (!finished) await reader.cancel().catch(() => {
|
|
42
|
+
});
|
|
43
|
+
reader.releaseLock();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/index.ts
|
|
48
|
+
var KNOWN_EVENTS = /* @__PURE__ */ new Set([
|
|
49
|
+
"start",
|
|
50
|
+
"delta",
|
|
51
|
+
"replace",
|
|
52
|
+
"suggestions",
|
|
53
|
+
"card",
|
|
54
|
+
"done",
|
|
55
|
+
"error"
|
|
56
|
+
]);
|
|
57
|
+
async function* streamChat(options) {
|
|
58
|
+
const { endpoint, messages, lang, signal, headers, fetch: doFetch = fetch } = options;
|
|
59
|
+
let response;
|
|
60
|
+
try {
|
|
61
|
+
response = await doFetch(endpoint, {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { "Content-Type": "application/json", Accept: "text/event-stream", ...headers },
|
|
64
|
+
body: JSON.stringify({ messages, lang }),
|
|
65
|
+
signal
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (signal?.aborted) return;
|
|
69
|
+
yield { type: "error", code: "network", message: errorMessage(error) };
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
yield await requestError(response);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (!response.body || !response.headers.get("content-type")?.includes("text/event-stream")) {
|
|
77
|
+
yield { type: "error", code: "bad_response", message: "Expected an event stream" };
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let finished = false;
|
|
81
|
+
try {
|
|
82
|
+
for await (const { event, data } of parseSSE(response.body)) {
|
|
83
|
+
if (!KNOWN_EVENTS.has(event)) continue;
|
|
84
|
+
let payload;
|
|
85
|
+
try {
|
|
86
|
+
payload = JSON.parse(data);
|
|
87
|
+
} catch {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const chatEvent = { ...payload, type: event };
|
|
91
|
+
yield chatEvent;
|
|
92
|
+
if (event === "done" || event === "error") finished = true;
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (signal?.aborted) return;
|
|
96
|
+
yield { type: "error", code: "network", message: errorMessage(error) };
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!finished && !signal?.aborted) {
|
|
100
|
+
yield {
|
|
101
|
+
type: "error",
|
|
102
|
+
code: "network",
|
|
103
|
+
message: "The connection closed before the reply ended"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function submitLead(options) {
|
|
108
|
+
const { endpoint, headers, fetch: doFetch = fetch, ...body } = options;
|
|
109
|
+
let response;
|
|
110
|
+
try {
|
|
111
|
+
response = await doFetch(endpoint, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "Content-Type": "application/json", Accept: "application/json", ...headers },
|
|
114
|
+
body: JSON.stringify(body)
|
|
115
|
+
});
|
|
116
|
+
} catch (error) {
|
|
117
|
+
return { ok: false, code: "network", message: errorMessage(error) };
|
|
118
|
+
}
|
|
119
|
+
if (response.ok) return { ok: true };
|
|
120
|
+
const failure = await requestError(response);
|
|
121
|
+
return failure.type === "error" ? { ok: false, code: failure.code, message: failure.message } : { ok: false, code: "bad_response", message: `HTTP ${response.status}` };
|
|
122
|
+
}
|
|
123
|
+
async function requestError(response) {
|
|
124
|
+
try {
|
|
125
|
+
const body = await response.json();
|
|
126
|
+
if (body.error?.code && body.error.message) {
|
|
127
|
+
return { type: "error", code: body.error.code, message: body.error.message };
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
return { type: "error", code: "bad_response", message: `HTTP ${response.status}` };
|
|
132
|
+
}
|
|
133
|
+
function errorMessage(error) {
|
|
134
|
+
return error instanceof Error ? error.message : String(error);
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
parseSSE,
|
|
138
|
+
streamChat,
|
|
139
|
+
submitLead
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sse.ts","../src/index.ts"],"sourcesContent":["export interface SSEMessage {\n event: string;\n data: string;\n}\n\n/**\n * Parses a Server-Sent Events byte stream into messages, following the HTML\n * spec's rules: lines may end in \\n, \\r\\n or \\r, chunks may split anywhere\n * (even inside a UTF-8 character), `data:` lines accumulate, comments are skipped.\n */\nexport async function* parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEMessage> {\n const reader = stream.getReader();\n const decoder = new TextDecoder();\n let buffer = '';\n let event = '';\n let data: string[] = [];\n let finished = false;\n\n function* processLines(final: boolean): Generator<SSEMessage> {\n for (;;) {\n const match = /\\r\\n|\\r|\\n/.exec(buffer);\n // A trailing \\r might be the first half of \\r\\n: wait for more input.\n if (!match || (match[0] === '\\r' && match.index === buffer.length - 1 && !final)) return;\n\n const line = buffer.slice(0, match.index);\n buffer = buffer.slice(match.index + match[0].length);\n\n if (line === '') {\n if (data.length > 0) yield { event: event || 'message', data: data.join('\\n') };\n event = '';\n data = [];\n continue;\n }\n if (line.startsWith(':')) continue;\n\n const colon = line.indexOf(':');\n const field = colon === -1 ? line : line.slice(0, colon);\n let value = colon === -1 ? '' : line.slice(colon + 1);\n if (value.startsWith(' ')) value = value.slice(1);\n\n if (field === 'event') event = value;\n else if (field === 'data') data.push(value);\n }\n }\n\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n yield* processLines(false);\n }\n buffer += decoder.decode();\n yield* processLines(true);\n finished = true;\n } finally {\n // Stopped early (consumer broke out, or an error): release the connection.\n if (!finished) await reader.cancel().catch(() => {});\n reader.releaseLock();\n }\n}\n","import type {\n Card,\n CardItem,\n ChatMessage,\n HandoffChannel,\n Language,\n LeadFields,\n LeadRequestBody,\n RequestErrorBody,\n RequestErrorCode,\n ServerEvent,\n StreamErrorCode,\n} from '@franyerhiguerey/ai-chat-core/protocol';\nimport { parseSSE } from './sse.js';\n\nexport { parseSSE, type SSEMessage } from './sse.js';\nexport type {\n Card,\n CardItem,\n ChatMessage,\n HandoffChannel,\n Language,\n LeadFields,\n ServerEvent,\n StreamErrorCode,\n RequestErrorCode,\n};\n\n/** Failures detected in the browser rather than reported by the server. */\nexport type ClientErrorCode = 'network' | 'bad_response';\n\nexport type ErrorCode = StreamErrorCode | RequestErrorCode | ClientErrorCode;\n\n/**\n * Every event `streamChat` yields. Errors from any source arrive as one `error`\n * event, so a UI handles them in one place. Its `message` is already localized\n * when it came from the server; for client errors, localize by `code`.\n */\nexport type ChatEvent =\n Exclude<ServerEvent, { type: 'error' }> | { type: 'error'; code: ErrorCode; message: string };\n\nexport interface StreamChatOptions {\n /** URL of the site's ai-chat endpoint, e.g. `/api/chat`. */\n endpoint: string;\n messages: ChatMessage[];\n lang?: Language;\n /** Abort to stop the reply (a Stop button). The generator then just ends. */\n signal?: AbortSignal;\n /** Extra request headers. */\n headers?: Record<string, string>;\n /** Override fetch (tests, custom transports). */\n fetch?: typeof fetch;\n}\n\nconst KNOWN_EVENTS = new Set<string>([\n 'start',\n 'delta',\n 'replace',\n 'suggestions',\n 'card',\n 'done',\n 'error',\n]);\n\n/**\n * Sends a conversation to an ai-chat endpoint and yields its events as they\n * arrive. Unknown events are skipped, so newer servers don't break older clients.\n */\nexport async function* streamChat(options: StreamChatOptions): AsyncGenerator<ChatEvent> {\n const { endpoint, messages, lang, signal, headers, fetch: doFetch = fetch } = options;\n\n let response: Response;\n try {\n response = await doFetch(endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream', ...headers },\n body: JSON.stringify({ messages, lang }),\n signal,\n });\n } catch (error) {\n if (signal?.aborted) return;\n yield { type: 'error', code: 'network', message: errorMessage(error) };\n return;\n }\n\n if (!response.ok) {\n yield await requestError(response);\n return;\n }\n if (!response.body || !response.headers.get('content-type')?.includes('text/event-stream')) {\n yield { type: 'error', code: 'bad_response', message: 'Expected an event stream' };\n return;\n }\n\n let finished = false;\n try {\n for await (const { event, data } of parseSSE(response.body)) {\n if (!KNOWN_EVENTS.has(event)) continue;\n let payload: unknown;\n try {\n payload = JSON.parse(data);\n } catch {\n continue;\n }\n const chatEvent = { ...(payload as object), type: event } as ChatEvent;\n yield chatEvent;\n if (event === 'done' || event === 'error') finished = true;\n }\n } catch (error) {\n if (signal?.aborted) return;\n yield { type: 'error', code: 'network', message: errorMessage(error) };\n return;\n }\n\n // The connection closed without `done` or `error`: the reply is incomplete.\n if (!finished && !signal?.aborted) {\n yield {\n type: 'error',\n code: 'network',\n message: 'The connection closed before the reply ended',\n };\n }\n}\n\nexport interface SubmitLeadOptions extends LeadRequestBody {\n /** The same endpoint the chat uses. */\n endpoint: string;\n headers?: Record<string, string>;\n fetch?: typeof fetch;\n}\n\nexport type SubmitLeadResult = { ok: true } | { ok: false; code: ErrorCode; message: string };\n\n/** Sends the lead form to the site's endpoint, which forwards it to the site's webhook. */\nexport async function submitLead(options: SubmitLeadOptions): Promise<SubmitLeadResult> {\n const { endpoint, headers, fetch: doFetch = fetch, ...body } = options;\n let response: Response;\n try {\n response = await doFetch(endpoint, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', Accept: 'application/json', ...headers },\n body: JSON.stringify(body),\n });\n } catch (error) {\n return { ok: false, code: 'network', message: errorMessage(error) };\n }\n if (response.ok) return { ok: true };\n const failure = await requestError(response);\n return failure.type === 'error'\n ? { ok: false, code: failure.code, message: failure.message }\n : { ok: false, code: 'bad_response', message: `HTTP ${response.status}` };\n}\n\nasync function requestError(response: Response): Promise<ChatEvent> {\n try {\n const body = (await response.json()) as Partial<RequestErrorBody>;\n if (body.error?.code && body.error.message) {\n return { type: 'error', code: body.error.code, message: body.error.message };\n }\n } catch {\n // Not JSON: fall through.\n }\n return { type: 'error', code: 'bad_response', message: `HTTP ${response.status}` };\n}\n\nfunction errorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n"],"mappings":";AAUA,gBAAuB,SAAS,QAAgE;AAC9F,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,UAAU,IAAI,YAAY;AAChC,MAAI,SAAS;AACb,MAAI,QAAQ;AACZ,MAAI,OAAiB,CAAC;AACtB,MAAI,WAAW;AAEf,YAAU,aAAa,OAAuC;AAC5D,eAAS;AACP,YAAM,QAAQ,aAAa,KAAK,MAAM;AAEtC,UAAI,CAAC,SAAU,MAAM,CAAC,MAAM,QAAQ,MAAM,UAAU,OAAO,SAAS,KAAK,CAAC,MAAQ;AAElF,YAAM,OAAO,OAAO,MAAM,GAAG,MAAM,KAAK;AACxC,eAAS,OAAO,MAAM,MAAM,QAAQ,MAAM,CAAC,EAAE,MAAM;AAEnD,UAAI,SAAS,IAAI;AACf,YAAI,KAAK,SAAS,EAAG,OAAM,EAAE,OAAO,SAAS,WAAW,MAAM,KAAK,KAAK,IAAI,EAAE;AAC9E,gBAAQ;AACR,eAAO,CAAC;AACR;AAAA,MACF;AACA,UAAI,KAAK,WAAW,GAAG,EAAG;AAE1B,YAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,YAAM,QAAQ,UAAU,KAAK,OAAO,KAAK,MAAM,GAAG,KAAK;AACvD,UAAI,QAAQ,UAAU,KAAK,KAAK,KAAK,MAAM,QAAQ,CAAC;AACpD,UAAI,MAAM,WAAW,GAAG,EAAG,SAAQ,MAAM,MAAM,CAAC;AAEhD,UAAI,UAAU,QAAS,SAAQ;AAAA,eACtB,UAAU,OAAQ,MAAK,KAAK,KAAK;AAAA,IAC5C;AAAA,EACF;AAEA,MAAI;AACF,eAAS;AACP,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1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AAQ,KAAK,MAAM,SAAS;AAC1C,aAAO,EAAE,MAAM,SAAS,MAAM,KAAK,MAAM,MAAM,SAAS,KAAK,MAAM,QAAQ;AAAA,IAC7E;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO,EAAE,MAAM,SAAS,MAAM,gBAAgB,SAAS,QAAQ,SAAS,MAAM,GAAG;AACnF;AAEA,SAAS,aAAa,OAAwB;AAC5C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC9D;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@franyerhiguerey/ai-chat-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Browser client for ai-chat: streams replies from an ai-chat endpoint",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chatbot",
|
|
7
|
+
"sse",
|
|
8
|
+
"streaming",
|
|
9
|
+
"browser"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Franyer Higuerey (https://github.com/FranyerHiguerey)",
|
|
13
|
+
"homepage": "https://github.com/FranyerHiguerey/ai-chat/tree/main/packages/client#readme",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/FranyerHiguerey/ai-chat.git",
|
|
17
|
+
"directory": "packages/client"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/FranyerHiguerey/ai-chat/issues"
|
|
21
|
+
},
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@franyerhiguerey/ai-chat-core": "^0.1.3"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@franyerhiguerey/ai-chat-core": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"tsup": "^8.3.5",
|
|
48
|
+
"typescript": "^5.7.3",
|
|
49
|
+
"vitest": "^3.0.0",
|
|
50
|
+
"@franyerhiguerey/ai-chat-core": "0.1.3"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup",
|
|
54
|
+
"dev": "tsup --watch",
|
|
55
|
+
"lint": "eslint .",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"test": "vitest run"
|
|
58
|
+
}
|
|
6
59
|
}
|