@djangocfg/widget-assistant 0.2.9 → 0.3.7
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 +31 -1
- package/package.json +7 -7
- package/src/AssistantChat.tsx +18 -6
- package/src/composer/ComposerBehaviour.tsx +17 -0
- package/src/composer/ComposerHelp.tsx +4 -1
- package/src/composer/earcons.ts +49 -0
- package/src/composer/handoff.ts +26 -0
- package/src/i18n/index.ts +3 -0
- package/src/i18n/locales/ar.ts +3 -3
- package/src/i18n/locales/da.ts +3 -3
- package/src/i18n/locales/de.ts +3 -3
- package/src/i18n/locales/en.ts +3 -3
- package/src/i18n/locales/es.ts +3 -3
- package/src/i18n/locales/fr.ts +3 -3
- package/src/i18n/locales/it.ts +3 -3
- package/src/i18n/locales/ja.ts +3 -3
- package/src/i18n/locales/ko.ts +3 -3
- package/src/i18n/locales/nl.ts +3 -3
- package/src/i18n/locales/no.ts +3 -3
- package/src/i18n/locales/pl.ts +3 -3
- package/src/i18n/locales/pt-BR.ts +3 -3
- package/src/i18n/locales/ru.ts +3 -3
- package/src/i18n/locales/sv.ts +3 -3
- package/src/i18n/locales/tr.ts +3 -3
- package/src/i18n/locales/zh.ts +3 -3
- package/src/i18n/types.ts +4 -4
- package/src/index.ts +7 -4
- package/src/sessions/SessionsMenu.tsx +82 -0
- package/src/shell/AssistantFrame.tsx +11 -12
- package/src/shell/AssistantLocked.tsx +12 -4
- package/src/shell/ChatDock.tsx +16 -27
- package/src/stream/adapter.ts +8 -1
- package/src/stream/sessions.ts +58 -0
- package/src/stream/useSession.ts +111 -34
- package/src/wire/stored.ts +9 -0
- package/src/wire/transport.ts +13 -3
package/src/wire/transport.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { decodeFrame, IDLE_MS, type ChatContext, type Frame } from './frames';
|
|
|
2
2
|
import { parseSSE, StreamLostError } from './parseSSE';
|
|
3
3
|
|
|
4
4
|
/** Problem codes the API answers before a stream starts (CONTRACT.md "Auth and errors"). */
|
|
5
|
-
export type RejectCode = 'unauthorized' | 'busy' | 'invalid' | 'rate_limited' | 'unavailable' | 'failed';
|
|
5
|
+
export type RejectCode = 'unauthorized' | 'busy' | 'invalid' | 'rate_limited' | 'unavailable' | 'not_found' | 'failed';
|
|
6
6
|
|
|
7
7
|
/** The request was refused before any frame: nothing ran, so a retry with the same `client_id` is safe. */
|
|
8
8
|
export class ChatHttpError extends Error {
|
|
@@ -19,6 +19,13 @@ export class ChatHttpError extends Error {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** The session is not there (never was, or it is someone else's: the API answers both with a 404). The host forgets the remembered id. */
|
|
23
|
+
export class ThreadNotFoundError extends Error {
|
|
24
|
+
constructor() {
|
|
25
|
+
super('chat thread not found');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
/** No answer at all (offline, DNS, reset before the response): nothing is known to have run. */
|
|
23
30
|
export class ChatNetworkError extends Error {
|
|
24
31
|
constructor() {
|
|
@@ -27,6 +34,8 @@ export class ChatNetworkError extends Error {
|
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
export interface SendInput {
|
|
37
|
+
/** The session this message goes to (set by the session layer; read by `streamUrl`). Absent for an anonymous host. */
|
|
38
|
+
threadId?: string;
|
|
30
39
|
text: string;
|
|
31
40
|
clientId: string;
|
|
32
41
|
context?: ChatContext;
|
|
@@ -41,7 +50,7 @@ export interface ChatTransport {
|
|
|
41
50
|
export interface TransportConfig {
|
|
42
51
|
/** API origin, no trailing slash; prefixes a relative `streamUrl`. The stream is called directly, never through a Next rewrite. */
|
|
43
52
|
baseUrl: string;
|
|
44
|
-
/** Where one run is opened: a path or URL, or a function read per request (a thread id in the path). Absent: the legacy `/apix/chat/v1/stream` (
|
|
53
|
+
/** Where one run is opened: a path or URL, or a function read per request (a thread id in the path). Absent: the legacy `/apix/chat/v1/stream` (anonymous hosts only; a signed-in host with sessions always sets this). */
|
|
45
54
|
streamUrl?: string | ((input: SendInput) => string);
|
|
46
55
|
/** The request body. Absent: `{text, client_id, context?}`. */
|
|
47
56
|
buildBody?: (input: SendInput) => unknown;
|
|
@@ -58,7 +67,7 @@ export interface TransportConfig {
|
|
|
58
67
|
fetch?: typeof fetch;
|
|
59
68
|
}
|
|
60
69
|
|
|
61
|
-
const CODES: readonly string[] = ['unauthorized', 'busy', 'invalid', 'rate_limited', 'unavailable'];
|
|
70
|
+
const CODES: readonly string[] = ['unauthorized', 'busy', 'invalid', 'rate_limited', 'unavailable', 'not_found'];
|
|
62
71
|
/** A server may name a bad request its own way; these read as `invalid`. */
|
|
63
72
|
const INVALID: readonly string[] = ['validation_error'];
|
|
64
73
|
|
|
@@ -67,6 +76,7 @@ function rejectCode(status: number, body: unknown): RejectCode {
|
|
|
67
76
|
if (typeof code === 'string' && CODES.includes(code)) return code as RejectCode;
|
|
68
77
|
if (typeof code === 'string' && INVALID.includes(code)) return 'invalid';
|
|
69
78
|
if (status === 401) return 'unauthorized';
|
|
79
|
+
if (status === 404) return 'not_found';
|
|
70
80
|
if (status === 409) return 'busy';
|
|
71
81
|
if (status === 400 || status === 422) return 'invalid';
|
|
72
82
|
if (status === 429) return 'rate_limited';
|