@aurabase/aurabase-js 0.3.1 → 0.4.0
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 +26 -795
- package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts → dist/AuraClient-BcFE8u1v.d.cts} +1 -1
- package/{packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts → dist/AuraClient-BcFE8u1v.d.ts} +1 -1
- package/{packages/aurabase/dist → dist}/index.d.cts +1 -1
- package/{packages/aurabase/dist → dist}/index.d.ts +1 -1
- package/{packages/aurabase/dist → dist}/ssr.d.cts +1 -1
- package/{packages/aurabase/dist → dist}/ssr.d.ts +1 -1
- package/package.json +72 -82
- package/.changeset/config.json +0 -11
- package/CHANGELOG.md +0 -30
- package/packages/ai/LICENSE +0 -21
- package/packages/ai/README.md +0 -106
- package/packages/ai/dist/index.cjs +0 -229
- package/packages/ai/dist/index.d.cts +0 -139
- package/packages/ai/dist/index.d.ts +0 -139
- package/packages/ai/dist/index.js +0 -226
- package/packages/ai/package.json +0 -61
- package/packages/aurabase/LICENSE +0 -21
- package/packages/aurabase/README.md +0 -64
- package/packages/aurabase/package.json +0 -80
- package/packages/aurabase/vitest.e2e.config.ts +0 -9
- package/packages/auth/LICENSE +0 -21
- package/packages/auth/README.md +0 -215
- package/packages/auth/dist/index.cjs +0 -1175
- package/packages/auth/dist/index.d.cts +0 -397
- package/packages/auth/dist/index.d.ts +0 -397
- package/packages/auth/dist/index.js +0 -1170
- package/packages/auth/package.json +0 -61
- package/packages/core/LICENSE +0 -21
- package/packages/core/README.md +0 -132
- package/packages/core/dist/index.cjs +0 -695
- package/packages/core/dist/index.d.cts +0 -1137
- package/packages/core/dist/index.d.ts +0 -1137
- package/packages/core/dist/index.js +0 -673
- package/packages/core/package.json +0 -57
- package/packages/db/LICENSE +0 -21
- package/packages/db/README.md +0 -152
- package/packages/db/VENDORED.md +0 -93
- package/packages/db/dist/index.cjs +0 -544
- package/packages/db/dist/index.d.cts +0 -1111
- package/packages/db/dist/index.d.ts +0 -1111
- package/packages/db/dist/index.js +0 -541
- package/packages/db/package.json +0 -62
- package/packages/functions/LICENSE +0 -21
- package/packages/functions/README.md +0 -96
- package/packages/functions/dist/index.cjs +0 -173
- package/packages/functions/dist/index.d.cts +0 -81
- package/packages/functions/dist/index.d.ts +0 -81
- package/packages/functions/dist/index.js +0 -168
- package/packages/functions/package.json +0 -60
- package/packages/gen/LICENSE +0 -21
- package/packages/gen/README.md +0 -84
- package/packages/gen/dist/cli.cjs +0 -334
- package/packages/gen/dist/cli.d.cts +0 -1
- package/packages/gen/dist/cli.d.ts +0 -1
- package/packages/gen/dist/cli.js +0 -332
- package/packages/gen/dist/index.cjs +0 -257
- package/packages/gen/dist/index.d.cts +0 -12
- package/packages/gen/dist/index.d.ts +0 -12
- package/packages/gen/dist/index.js +0 -255
- package/packages/gen/package.json +0 -66
- package/packages/notifications/LICENSE +0 -21
- package/packages/notifications/README.md +0 -134
- package/packages/notifications/dist/index.cjs +0 -128
- package/packages/notifications/dist/index.d.cts +0 -81
- package/packages/notifications/dist/index.d.ts +0 -81
- package/packages/notifications/dist/index.js +0 -125
- package/packages/notifications/package.json +0 -60
- package/packages/realtime/LICENSE +0 -21
- package/packages/realtime/README.md +0 -183
- package/packages/realtime/dist/index.cjs +0 -977
- package/packages/realtime/dist/index.d.cts +0 -259
- package/packages/realtime/dist/index.d.ts +0 -259
- package/packages/realtime/dist/index.js +0 -973
- package/packages/realtime/package.json +0 -60
- package/packages/storage/LICENSE +0 -21
- package/packages/storage/README.md +0 -141
- package/packages/storage/dist/index.cjs +0 -333
- package/packages/storage/dist/index.d.cts +0 -185
- package/packages/storage/dist/index.d.ts +0 -185
- package/packages/storage/dist/index.js +0 -329
- package/packages/storage/package.json +0 -60
- /package/{packages/aurabase/dist → dist}/index.cjs +0 -0
- /package/{packages/aurabase/dist → dist}/index.js +0 -0
- /package/{packages/aurabase/dist → dist}/ssr.cjs +0 -0
- /package/{packages/aurabase/dist → dist}/ssr.js +0 -0
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { BaseService, AuraClientLike, ChatMessage, AuraResponse, ChatResponse, EmbedRequest, EmbedResponse, RagRequest, RagResponse, RagIngestRequest, RagIngestResponse, SemanticSearchResult } from '@aurabase/core';
|
|
2
|
-
export { AuraResponse, ChatMessage, ChatResponse, EmbedRequest, EmbedResponse, RagIngestRequest, RagIngestResponse, RagRequest, RagResponse, SemanticSearchResult } from '@aurabase/core';
|
|
3
|
-
|
|
4
|
-
/** Un message SSE dispatché : nom d'event (`message` par défaut) + données jointes. */
|
|
5
|
-
interface SSEMessage {
|
|
6
|
-
event: string;
|
|
7
|
-
data: string;
|
|
8
|
-
}
|
|
9
|
-
/** Chunk de streaming de chat : un delta de tokens incrémental. */
|
|
10
|
-
interface ChatStreamChunk {
|
|
11
|
-
delta: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Parse un flux SSE en `AsyncGenerator<SSEMessage>`.
|
|
15
|
-
*
|
|
16
|
-
* Conforme au protocole EventSource :
|
|
17
|
-
* - événements séparés par une ligne vide (`\n\n`) ;
|
|
18
|
-
* - champs `event:` / `data:` (espace optionnel après le `:`), autres champs ignorés ;
|
|
19
|
-
* - plusieurs `data:` d'un même event sont jointes par `\n` ;
|
|
20
|
-
* - lignes commençant par `:` = commentaires/keep-alive → ignorées ;
|
|
21
|
-
* - CRLF toléré (le `\r` de fin de ligne est retiré).
|
|
22
|
-
*
|
|
23
|
-
* Gère les trames partielles : un event scindé sur plusieurs chunks est
|
|
24
|
-
* bufferisé jusqu'à réception de la ligne vide. Un éventuel event final non
|
|
25
|
-
* terminé par une ligne vide est tout de même livré à la fermeture du flux.
|
|
26
|
-
*/
|
|
27
|
-
declare function parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEMessage>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Un namespace RAG. Le backend (`GET /rag/namespaces` → `Vec<String>`) renvoie
|
|
31
|
-
* de simples chaînes ; le type reste un alias pour documenter l'intention et
|
|
32
|
-
* autoriser une évolution ultérieure vers un objet sans casser les appelants.
|
|
33
|
-
*/
|
|
34
|
-
type RagNamespace = string;
|
|
35
|
-
/**
|
|
36
|
-
* Réponse de `DELETE /rag/{namespace}` — forme réelle du handler
|
|
37
|
-
* (`rag_delete_namespace` → `{ "deleted": <count> }`).
|
|
38
|
-
*/
|
|
39
|
-
interface RagDeleteResponse {
|
|
40
|
-
/** Nombre d'entrées supprimées du namespace. */
|
|
41
|
-
deleted: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Réponse de `POST /rag/{namespace}/reindex` — forme réelle du handler
|
|
45
|
-
* (`ReindexResponse` dans `services/aura-ai/src/rag/mod.rs`).
|
|
46
|
-
*/
|
|
47
|
-
interface RagReindexResponse {
|
|
48
|
-
/** Nombre de chunks ré-embeddés sous le modèle courant. */
|
|
49
|
-
reindexed: number;
|
|
50
|
-
/** Modèle d'embedding désormais appliqué au namespace. */
|
|
51
|
-
embedding_model: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare class AiService extends BaseService {
|
|
55
|
-
constructor(client: AuraClientLike);
|
|
56
|
-
private get prefix();
|
|
57
|
-
/**
|
|
58
|
-
* Send a chat completion request.
|
|
59
|
-
*/
|
|
60
|
-
chat(messages: ChatMessage[], options?: {
|
|
61
|
-
model?: string;
|
|
62
|
-
temperature?: number;
|
|
63
|
-
max_tokens?: number;
|
|
64
|
-
}): Promise<AuraResponse<ChatResponse>>;
|
|
65
|
-
/**
|
|
66
|
-
* Chat completion streamé (SSE). Renvoie un `AsyncIterable` de deltas de tokens,
|
|
67
|
-
* consommable par `for await (const { delta } of ai.chatStream(msgs)) { … }`.
|
|
68
|
-
*
|
|
69
|
-
* Court-circuite volontairement le pipeline JSON (`@aurabase/core/fetch.ts`) et
|
|
70
|
-
* emprunte le chemin transport BRUT `client.fetchFn` (patron `StorageService.download`) :
|
|
71
|
-
* - refresh proactif du token expiré (même règle que `download`, marge 30 s) ;
|
|
72
|
-
* - pose manuelle de `Authorization: Bearer` + `apikey`, `Accept: text/event-stream` ;
|
|
73
|
-
* - lecture de `res.body` via `parseSSE`, mapping des events serveur :
|
|
74
|
-
* `delta` (`{ content }`) → `yield { delta }`, `error` (`{ error }`) → lève une
|
|
75
|
-
* `AuraError`, `done` → termine l'itération.
|
|
76
|
-
*
|
|
77
|
-
* `options.signal` interrompt proprement le flux (annulation du `fetch` + fin
|
|
78
|
-
* d'itération sans throw). Sur `!res.ok`, lève `AuraError(res.status)`.
|
|
79
|
-
*
|
|
80
|
-
* Backend route: POST /v1/ai/{project_id}/chat/stream
|
|
81
|
-
*/
|
|
82
|
-
chatStream(messages: ChatMessage[], options?: {
|
|
83
|
-
model?: string;
|
|
84
|
-
temperature?: number;
|
|
85
|
-
max_tokens?: number;
|
|
86
|
-
signal?: AbortSignal;
|
|
87
|
-
}): AsyncGenerator<ChatStreamChunk>;
|
|
88
|
-
/**
|
|
89
|
-
* Generate embeddings for the given input(s).
|
|
90
|
-
*/
|
|
91
|
-
embed(req: EmbedRequest): Promise<AuraResponse<EmbedResponse>>;
|
|
92
|
-
/**
|
|
93
|
-
* Retrieval-Augmented Generation: query a collection and get an answer.
|
|
94
|
-
*/
|
|
95
|
-
rag(req: RagRequest): Promise<AuraResponse<RagResponse>>;
|
|
96
|
-
/**
|
|
97
|
-
* Ingest a document into a RAG namespace.
|
|
98
|
-
*/
|
|
99
|
-
ragIngest(req: RagIngestRequest): Promise<AuraResponse<RagIngestResponse>>;
|
|
100
|
-
/**
|
|
101
|
-
* Liste les namespaces RAG du projet.
|
|
102
|
-
* Backend route: GET /v1/ai/{project_id}/rag/namespaces (→ `Vec<String>`).
|
|
103
|
-
*/
|
|
104
|
-
listNamespaces(): Promise<AuraResponse<RagNamespace[]>>;
|
|
105
|
-
/**
|
|
106
|
-
* Supprime un namespace RAG (et son corpus). Le segment `namespace` est
|
|
107
|
-
* URL-encodé (anti-injection de chemin).
|
|
108
|
-
* Backend route: DELETE /v1/ai/{project_id}/rag/{namespace} (→ `{ deleted }`).
|
|
109
|
-
*/
|
|
110
|
-
deleteNamespace(namespace: string): Promise<AuraResponse<RagDeleteResponse>>;
|
|
111
|
-
/**
|
|
112
|
-
* Ré-indexe un namespace RAG avec le modèle d'embedding courant (remédiation
|
|
113
|
-
* après un changement de modèle/dimension). Le segment `namespace` est URL-encodé.
|
|
114
|
-
* Backend route: POST /v1/ai/{project_id}/rag/{namespace}/reindex (→ `ReindexResponse`).
|
|
115
|
-
*/
|
|
116
|
-
reindexNamespace(namespace: string): Promise<AuraResponse<RagReindexResponse>>;
|
|
117
|
-
/**
|
|
118
|
-
* Semantic search over an embedding namespace.
|
|
119
|
-
*/
|
|
120
|
-
semanticSearch(query: string, namespace: string, options?: {
|
|
121
|
-
top_k?: number;
|
|
122
|
-
threshold?: number;
|
|
123
|
-
}): Promise<AuraResponse<SemanticSearchResult[]>>;
|
|
124
|
-
/**
|
|
125
|
-
* Natural-language to SQL: convert a question into a SQL query.
|
|
126
|
-
*/
|
|
127
|
-
nl2sql(question: string, schema: string, options?: {
|
|
128
|
-
dialect?: string;
|
|
129
|
-
examples?: Array<{
|
|
130
|
-
question: string;
|
|
131
|
-
sql: string;
|
|
132
|
-
}>;
|
|
133
|
-
}): Promise<AuraResponse<{
|
|
134
|
-
sql: string;
|
|
135
|
-
explanation: string;
|
|
136
|
-
}>>;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export { AiService, type ChatStreamChunk, type RagDeleteResponse, type RagNamespace, type RagReindexResponse, type SSEMessage, parseSSE };
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { BaseService, AuraClientLike, ChatMessage, AuraResponse, ChatResponse, EmbedRequest, EmbedResponse, RagRequest, RagResponse, RagIngestRequest, RagIngestResponse, SemanticSearchResult } from '@aurabase/core';
|
|
2
|
-
export { AuraResponse, ChatMessage, ChatResponse, EmbedRequest, EmbedResponse, RagIngestRequest, RagIngestResponse, RagRequest, RagResponse, SemanticSearchResult } from '@aurabase/core';
|
|
3
|
-
|
|
4
|
-
/** Un message SSE dispatché : nom d'event (`message` par défaut) + données jointes. */
|
|
5
|
-
interface SSEMessage {
|
|
6
|
-
event: string;
|
|
7
|
-
data: string;
|
|
8
|
-
}
|
|
9
|
-
/** Chunk de streaming de chat : un delta de tokens incrémental. */
|
|
10
|
-
interface ChatStreamChunk {
|
|
11
|
-
delta: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Parse un flux SSE en `AsyncGenerator<SSEMessage>`.
|
|
15
|
-
*
|
|
16
|
-
* Conforme au protocole EventSource :
|
|
17
|
-
* - événements séparés par une ligne vide (`\n\n`) ;
|
|
18
|
-
* - champs `event:` / `data:` (espace optionnel après le `:`), autres champs ignorés ;
|
|
19
|
-
* - plusieurs `data:` d'un même event sont jointes par `\n` ;
|
|
20
|
-
* - lignes commençant par `:` = commentaires/keep-alive → ignorées ;
|
|
21
|
-
* - CRLF toléré (le `\r` de fin de ligne est retiré).
|
|
22
|
-
*
|
|
23
|
-
* Gère les trames partielles : un event scindé sur plusieurs chunks est
|
|
24
|
-
* bufferisé jusqu'à réception de la ligne vide. Un éventuel event final non
|
|
25
|
-
* terminé par une ligne vide est tout de même livré à la fermeture du flux.
|
|
26
|
-
*/
|
|
27
|
-
declare function parseSSE(stream: ReadableStream<Uint8Array>): AsyncGenerator<SSEMessage>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Un namespace RAG. Le backend (`GET /rag/namespaces` → `Vec<String>`) renvoie
|
|
31
|
-
* de simples chaînes ; le type reste un alias pour documenter l'intention et
|
|
32
|
-
* autoriser une évolution ultérieure vers un objet sans casser les appelants.
|
|
33
|
-
*/
|
|
34
|
-
type RagNamespace = string;
|
|
35
|
-
/**
|
|
36
|
-
* Réponse de `DELETE /rag/{namespace}` — forme réelle du handler
|
|
37
|
-
* (`rag_delete_namespace` → `{ "deleted": <count> }`).
|
|
38
|
-
*/
|
|
39
|
-
interface RagDeleteResponse {
|
|
40
|
-
/** Nombre d'entrées supprimées du namespace. */
|
|
41
|
-
deleted: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Réponse de `POST /rag/{namespace}/reindex` — forme réelle du handler
|
|
45
|
-
* (`ReindexResponse` dans `services/aura-ai/src/rag/mod.rs`).
|
|
46
|
-
*/
|
|
47
|
-
interface RagReindexResponse {
|
|
48
|
-
/** Nombre de chunks ré-embeddés sous le modèle courant. */
|
|
49
|
-
reindexed: number;
|
|
50
|
-
/** Modèle d'embedding désormais appliqué au namespace. */
|
|
51
|
-
embedding_model: string;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare class AiService extends BaseService {
|
|
55
|
-
constructor(client: AuraClientLike);
|
|
56
|
-
private get prefix();
|
|
57
|
-
/**
|
|
58
|
-
* Send a chat completion request.
|
|
59
|
-
*/
|
|
60
|
-
chat(messages: ChatMessage[], options?: {
|
|
61
|
-
model?: string;
|
|
62
|
-
temperature?: number;
|
|
63
|
-
max_tokens?: number;
|
|
64
|
-
}): Promise<AuraResponse<ChatResponse>>;
|
|
65
|
-
/**
|
|
66
|
-
* Chat completion streamé (SSE). Renvoie un `AsyncIterable` de deltas de tokens,
|
|
67
|
-
* consommable par `for await (const { delta } of ai.chatStream(msgs)) { … }`.
|
|
68
|
-
*
|
|
69
|
-
* Court-circuite volontairement le pipeline JSON (`@aurabase/core/fetch.ts`) et
|
|
70
|
-
* emprunte le chemin transport BRUT `client.fetchFn` (patron `StorageService.download`) :
|
|
71
|
-
* - refresh proactif du token expiré (même règle que `download`, marge 30 s) ;
|
|
72
|
-
* - pose manuelle de `Authorization: Bearer` + `apikey`, `Accept: text/event-stream` ;
|
|
73
|
-
* - lecture de `res.body` via `parseSSE`, mapping des events serveur :
|
|
74
|
-
* `delta` (`{ content }`) → `yield { delta }`, `error` (`{ error }`) → lève une
|
|
75
|
-
* `AuraError`, `done` → termine l'itération.
|
|
76
|
-
*
|
|
77
|
-
* `options.signal` interrompt proprement le flux (annulation du `fetch` + fin
|
|
78
|
-
* d'itération sans throw). Sur `!res.ok`, lève `AuraError(res.status)`.
|
|
79
|
-
*
|
|
80
|
-
* Backend route: POST /v1/ai/{project_id}/chat/stream
|
|
81
|
-
*/
|
|
82
|
-
chatStream(messages: ChatMessage[], options?: {
|
|
83
|
-
model?: string;
|
|
84
|
-
temperature?: number;
|
|
85
|
-
max_tokens?: number;
|
|
86
|
-
signal?: AbortSignal;
|
|
87
|
-
}): AsyncGenerator<ChatStreamChunk>;
|
|
88
|
-
/**
|
|
89
|
-
* Generate embeddings for the given input(s).
|
|
90
|
-
*/
|
|
91
|
-
embed(req: EmbedRequest): Promise<AuraResponse<EmbedResponse>>;
|
|
92
|
-
/**
|
|
93
|
-
* Retrieval-Augmented Generation: query a collection and get an answer.
|
|
94
|
-
*/
|
|
95
|
-
rag(req: RagRequest): Promise<AuraResponse<RagResponse>>;
|
|
96
|
-
/**
|
|
97
|
-
* Ingest a document into a RAG namespace.
|
|
98
|
-
*/
|
|
99
|
-
ragIngest(req: RagIngestRequest): Promise<AuraResponse<RagIngestResponse>>;
|
|
100
|
-
/**
|
|
101
|
-
* Liste les namespaces RAG du projet.
|
|
102
|
-
* Backend route: GET /v1/ai/{project_id}/rag/namespaces (→ `Vec<String>`).
|
|
103
|
-
*/
|
|
104
|
-
listNamespaces(): Promise<AuraResponse<RagNamespace[]>>;
|
|
105
|
-
/**
|
|
106
|
-
* Supprime un namespace RAG (et son corpus). Le segment `namespace` est
|
|
107
|
-
* URL-encodé (anti-injection de chemin).
|
|
108
|
-
* Backend route: DELETE /v1/ai/{project_id}/rag/{namespace} (→ `{ deleted }`).
|
|
109
|
-
*/
|
|
110
|
-
deleteNamespace(namespace: string): Promise<AuraResponse<RagDeleteResponse>>;
|
|
111
|
-
/**
|
|
112
|
-
* Ré-indexe un namespace RAG avec le modèle d'embedding courant (remédiation
|
|
113
|
-
* après un changement de modèle/dimension). Le segment `namespace` est URL-encodé.
|
|
114
|
-
* Backend route: POST /v1/ai/{project_id}/rag/{namespace}/reindex (→ `ReindexResponse`).
|
|
115
|
-
*/
|
|
116
|
-
reindexNamespace(namespace: string): Promise<AuraResponse<RagReindexResponse>>;
|
|
117
|
-
/**
|
|
118
|
-
* Semantic search over an embedding namespace.
|
|
119
|
-
*/
|
|
120
|
-
semanticSearch(query: string, namespace: string, options?: {
|
|
121
|
-
top_k?: number;
|
|
122
|
-
threshold?: number;
|
|
123
|
-
}): Promise<AuraResponse<SemanticSearchResult[]>>;
|
|
124
|
-
/**
|
|
125
|
-
* Natural-language to SQL: convert a question into a SQL query.
|
|
126
|
-
*/
|
|
127
|
-
nl2sql(question: string, schema: string, options?: {
|
|
128
|
-
dialect?: string;
|
|
129
|
-
examples?: Array<{
|
|
130
|
-
question: string;
|
|
131
|
-
sql: string;
|
|
132
|
-
}>;
|
|
133
|
-
}): Promise<AuraResponse<{
|
|
134
|
-
sql: string;
|
|
135
|
-
explanation: string;
|
|
136
|
-
}>>;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export { AiService, type ChatStreamChunk, type RagDeleteResponse, type RagNamespace, type RagReindexResponse, type SSEMessage, parseSSE };
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { BaseService, isTokenExpired, refreshOnce, AuraError, isAbortError } from '@aurabase/core';
|
|
2
|
-
|
|
3
|
-
// src/AiService.ts
|
|
4
|
-
|
|
5
|
-
// src/sse.ts
|
|
6
|
-
async function* parseSSE(stream) {
|
|
7
|
-
const reader = stream.getReader();
|
|
8
|
-
const decoder = new TextDecoder();
|
|
9
|
-
let buffer = "";
|
|
10
|
-
let eventName = "message";
|
|
11
|
-
let dataLines = [];
|
|
12
|
-
const consumeLine = (raw) => {
|
|
13
|
-
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
|
|
14
|
-
if (line === "") {
|
|
15
|
-
if (dataLines.length === 0) {
|
|
16
|
-
eventName = "message";
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const msg = { event: eventName, data: dataLines.join("\n") };
|
|
20
|
-
eventName = "message";
|
|
21
|
-
dataLines = [];
|
|
22
|
-
return msg;
|
|
23
|
-
}
|
|
24
|
-
if (line.startsWith(":")) return null;
|
|
25
|
-
const colon = line.indexOf(":");
|
|
26
|
-
let field;
|
|
27
|
-
let value;
|
|
28
|
-
if (colon === -1) {
|
|
29
|
-
field = line;
|
|
30
|
-
value = "";
|
|
31
|
-
} else {
|
|
32
|
-
field = line.slice(0, colon);
|
|
33
|
-
value = line.slice(colon + 1);
|
|
34
|
-
if (value.startsWith(" ")) value = value.slice(1);
|
|
35
|
-
}
|
|
36
|
-
if (field === "event") eventName = value;
|
|
37
|
-
else if (field === "data") dataLines.push(value);
|
|
38
|
-
return null;
|
|
39
|
-
};
|
|
40
|
-
try {
|
|
41
|
-
for (; ; ) {
|
|
42
|
-
const { done, value } = await reader.read();
|
|
43
|
-
if (done) break;
|
|
44
|
-
buffer += decoder.decode(value, { stream: true });
|
|
45
|
-
let idx;
|
|
46
|
-
while ((idx = buffer.indexOf("\n")) !== -1) {
|
|
47
|
-
const raw = buffer.slice(0, idx);
|
|
48
|
-
buffer = buffer.slice(idx + 1);
|
|
49
|
-
const msg = consumeLine(raw);
|
|
50
|
-
if (msg) yield msg;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
buffer += decoder.decode();
|
|
54
|
-
if (buffer.length > 0) {
|
|
55
|
-
const msg = consumeLine(buffer);
|
|
56
|
-
if (msg) yield msg;
|
|
57
|
-
}
|
|
58
|
-
if (dataLines.length > 0) {
|
|
59
|
-
yield { event: eventName, data: dataLines.join("\n") };
|
|
60
|
-
}
|
|
61
|
-
} finally {
|
|
62
|
-
reader.releaseLock();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// src/AiService.ts
|
|
67
|
-
var AiService = class extends BaseService {
|
|
68
|
-
constructor(client) {
|
|
69
|
-
super(client);
|
|
70
|
-
}
|
|
71
|
-
get prefix() {
|
|
72
|
-
return `/v1/ai/${this.client.projectId}`;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Send a chat completion request.
|
|
76
|
-
*/
|
|
77
|
-
async chat(messages, options) {
|
|
78
|
-
return this.request("POST", `${this.prefix}/chat`, {
|
|
79
|
-
messages,
|
|
80
|
-
...options
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Chat completion streamé (SSE). Renvoie un `AsyncIterable` de deltas de tokens,
|
|
85
|
-
* consommable par `for await (const { delta } of ai.chatStream(msgs)) { … }`.
|
|
86
|
-
*
|
|
87
|
-
* Court-circuite volontairement le pipeline JSON (`@aurabase/core/fetch.ts`) et
|
|
88
|
-
* emprunte le chemin transport BRUT `client.fetchFn` (patron `StorageService.download`) :
|
|
89
|
-
* - refresh proactif du token expiré (même règle que `download`, marge 30 s) ;
|
|
90
|
-
* - pose manuelle de `Authorization: Bearer` + `apikey`, `Accept: text/event-stream` ;
|
|
91
|
-
* - lecture de `res.body` via `parseSSE`, mapping des events serveur :
|
|
92
|
-
* `delta` (`{ content }`) → `yield { delta }`, `error` (`{ error }`) → lève une
|
|
93
|
-
* `AuraError`, `done` → termine l'itération.
|
|
94
|
-
*
|
|
95
|
-
* `options.signal` interrompt proprement le flux (annulation du `fetch` + fin
|
|
96
|
-
* d'itération sans throw). Sur `!res.ok`, lève `AuraError(res.status)`.
|
|
97
|
-
*
|
|
98
|
-
* Backend route: POST /v1/ai/{project_id}/chat/stream
|
|
99
|
-
*/
|
|
100
|
-
async *chatStream(messages, options) {
|
|
101
|
-
const client = this.client;
|
|
102
|
-
const store = client.authStore;
|
|
103
|
-
if (store.token && store.refreshToken && isTokenExpired(store.token, 30)) {
|
|
104
|
-
await refreshOnce(client);
|
|
105
|
-
}
|
|
106
|
-
const headers = {
|
|
107
|
-
"Content-Type": "application/json",
|
|
108
|
-
Accept: "text/event-stream"
|
|
109
|
-
};
|
|
110
|
-
if (store.token) headers["Authorization"] = `Bearer ${store.token}`;
|
|
111
|
-
if (client.apiKey) headers["apikey"] = client.apiKey;
|
|
112
|
-
const body = JSON.stringify({
|
|
113
|
-
messages,
|
|
114
|
-
model: options?.model,
|
|
115
|
-
temperature: options?.temperature,
|
|
116
|
-
max_tokens: options?.max_tokens
|
|
117
|
-
});
|
|
118
|
-
try {
|
|
119
|
-
const res = await client.fetchFn(this.url(`${this.prefix}/chat/stream`), {
|
|
120
|
-
method: "POST",
|
|
121
|
-
headers,
|
|
122
|
-
body,
|
|
123
|
-
signal: options?.signal
|
|
124
|
-
});
|
|
125
|
-
if (!res.ok) {
|
|
126
|
-
let parsed = null;
|
|
127
|
-
try {
|
|
128
|
-
parsed = await res.json();
|
|
129
|
-
} catch {
|
|
130
|
-
}
|
|
131
|
-
throw new AuraError(res.status, parsed);
|
|
132
|
-
}
|
|
133
|
-
if (!res.body) {
|
|
134
|
-
throw new AuraError(0, {
|
|
135
|
-
error: { code: "invalid_response", message: "chatStream: la r\xE9ponse SSE n'a pas de corps lisible" }
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
for await (const msg of parseSSE(res.body)) {
|
|
139
|
-
if (msg.event === "delta") {
|
|
140
|
-
let content = "";
|
|
141
|
-
try {
|
|
142
|
-
content = JSON.parse(msg.data).content ?? "";
|
|
143
|
-
} catch {
|
|
144
|
-
content = "";
|
|
145
|
-
}
|
|
146
|
-
if (content) yield { delta: content };
|
|
147
|
-
} else if (msg.event === "error") {
|
|
148
|
-
let message = "AI stream error";
|
|
149
|
-
try {
|
|
150
|
-
message = JSON.parse(msg.data).error ?? message;
|
|
151
|
-
} catch {
|
|
152
|
-
}
|
|
153
|
-
throw new AuraError(0, { error: { code: "ai_stream_error", message } });
|
|
154
|
-
} else if (msg.event === "done") {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} catch (err) {
|
|
159
|
-
if (options?.signal?.aborted || isAbortError(err)) return;
|
|
160
|
-
throw err;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Generate embeddings for the given input(s).
|
|
165
|
-
*/
|
|
166
|
-
async embed(req) {
|
|
167
|
-
return this.request("POST", `${this.prefix}/embed`, req);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Retrieval-Augmented Generation: query a collection and get an answer.
|
|
171
|
-
*/
|
|
172
|
-
async rag(req) {
|
|
173
|
-
return this.request("POST", `${this.prefix}/rag/query`, req);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Ingest a document into a RAG namespace.
|
|
177
|
-
*/
|
|
178
|
-
async ragIngest(req) {
|
|
179
|
-
return this.request("POST", `${this.prefix}/rag/ingest`, req);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Liste les namespaces RAG du projet.
|
|
183
|
-
* Backend route: GET /v1/ai/{project_id}/rag/namespaces (→ `Vec<String>`).
|
|
184
|
-
*/
|
|
185
|
-
async listNamespaces() {
|
|
186
|
-
return this.request("GET", `${this.prefix}/rag/namespaces`);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Supprime un namespace RAG (et son corpus). Le segment `namespace` est
|
|
190
|
-
* URL-encodé (anti-injection de chemin).
|
|
191
|
-
* Backend route: DELETE /v1/ai/{project_id}/rag/{namespace} (→ `{ deleted }`).
|
|
192
|
-
*/
|
|
193
|
-
async deleteNamespace(namespace) {
|
|
194
|
-
return this.request("DELETE", `${this.prefix}/rag/${encodeURIComponent(namespace)}`);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Ré-indexe un namespace RAG avec le modèle d'embedding courant (remédiation
|
|
198
|
-
* après un changement de modèle/dimension). Le segment `namespace` est URL-encodé.
|
|
199
|
-
* Backend route: POST /v1/ai/{project_id}/rag/{namespace}/reindex (→ `ReindexResponse`).
|
|
200
|
-
*/
|
|
201
|
-
async reindexNamespace(namespace) {
|
|
202
|
-
return this.request("POST", `${this.prefix}/rag/${encodeURIComponent(namespace)}/reindex`);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Semantic search over an embedding namespace.
|
|
206
|
-
*/
|
|
207
|
-
async semanticSearch(query, namespace, options) {
|
|
208
|
-
const params = new URLSearchParams({ query, namespace });
|
|
209
|
-
if (options?.top_k !== void 0) params.set("top_k", String(options.top_k));
|
|
210
|
-
if (options?.threshold !== void 0) params.set("threshold", String(options.threshold));
|
|
211
|
-
return this.request("GET", `${this.prefix}/search?${params.toString()}`);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Natural-language to SQL: convert a question into a SQL query.
|
|
215
|
-
*/
|
|
216
|
-
async nl2sql(question, schema, options) {
|
|
217
|
-
return this.request("POST", `${this.prefix}/nl2sql`, {
|
|
218
|
-
question,
|
|
219
|
-
schema,
|
|
220
|
-
dialect: options?.dialect,
|
|
221
|
-
examples: options?.examples
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
export { AiService, parseSSE };
|
package/packages/ai/package.json
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@aurabase/ai",
|
|
3
|
-
"version": "0.3.0",
|
|
4
|
-
"description": "Service IA du SDK Aurabase (chat, embeddings, RAG, recherche sémantique, NL2SQL)",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.cjs",
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"default": "./dist/index.js"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "./dist/index.d.cts",
|
|
17
|
-
"default": "./dist/index.cjs"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"sideEffects": false,
|
|
22
|
-
"files": [
|
|
23
|
-
"dist",
|
|
24
|
-
"README.md",
|
|
25
|
-
"LICENSE"
|
|
26
|
-
],
|
|
27
|
-
"engines": {
|
|
28
|
-
"node": ">=20.0.0"
|
|
29
|
-
},
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"author": "Aurabase",
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/daylami555/aurabase.git",
|
|
35
|
-
"directory": "aurabase-js/packages/ai"
|
|
36
|
-
},
|
|
37
|
-
"homepage": "https://github.com/daylami555/aurabase/tree/main/aurabase-js/packages/ai#readme",
|
|
38
|
-
"bugs": {
|
|
39
|
-
"url": "https://github.com/daylami555/aurabase/issues"
|
|
40
|
-
},
|
|
41
|
-
"keywords": [
|
|
42
|
-
"aurabase",
|
|
43
|
-
"baas",
|
|
44
|
-
"sdk",
|
|
45
|
-
"ai",
|
|
46
|
-
"chat"
|
|
47
|
-
],
|
|
48
|
-
"scripts": {
|
|
49
|
-
"build": "tsup",
|
|
50
|
-
"test": "vitest run --passWithNoTests",
|
|
51
|
-
"typecheck": "tsc --noEmit"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"@aurabase/core": "workspace:*"
|
|
55
|
-
},
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"tsup": "catalog:",
|
|
58
|
-
"typescript": "catalog:",
|
|
59
|
-
"vitest": "catalog:"
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Aurabase
|
|
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.
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# aurabase
|
|
2
|
-
|
|
3
|
-
Client JavaScript/TypeScript officiel d'Aurabase : point d'entrée principal du SDK, agrégeant les 8 packages de service (`@aurabase/*`) derrière `createClient`/`createAdminClient` et l'export `aurabase/ssr`.
|
|
4
|
-
|
|
5
|
-
 
|
|
6
|
-
|
|
7
|
-
> Pre-release — pas encore publié sur npm.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm i aurabase
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Rôle
|
|
16
|
-
|
|
17
|
-
Ce package ne réimplémente aucune logique de service : il compose `AuthService`, `DatabaseService`, `StorageService`, `RealtimeService`, `FunctionsService`, `AiService` et `NotificationsService` (chacun dans son propre package `@aurabase/*`) derrière un seul client.
|
|
18
|
-
|
|
19
|
-
- `createClient(baseUrl, projectId, apiKey, options?)` — client applicatif standard.
|
|
20
|
-
- `createAdminClient(baseUrl, projectId, serviceRoleKey, options?)` — client serveur avec `authAdmin` (clé `service_role`, jamais côté navigateur).
|
|
21
|
-
- `aurabase/ssr` — `createServerClient`/`createBrowserClient` pour Next.js et frameworks SSR (cookies, session partagée serveur/navigateur).
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import { createClient } from 'aurabase'
|
|
27
|
-
|
|
28
|
-
const aura = createClient(
|
|
29
|
-
'http://localhost:8080',
|
|
30
|
-
'00000000-0000-0000-0000-000000000001',
|
|
31
|
-
'aura_anon_xxx',
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
const { data, error } = await aura.db
|
|
35
|
-
.from('posts')
|
|
36
|
-
.select('id,title,published')
|
|
37
|
-
.eq('published', true)
|
|
38
|
-
.order('created_at', 'desc')
|
|
39
|
-
.limit(10)
|
|
40
|
-
|
|
41
|
-
if (error) {
|
|
42
|
-
console.error(error.code, error.message)
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Sous-packages
|
|
47
|
-
|
|
48
|
-
| Package | Contenu |
|
|
49
|
-
|---|---|
|
|
50
|
-
| [`@aurabase/core`](../core) | fetch, erreurs, types, stores, `BaseService`, interface `AuraClientLike` |
|
|
51
|
-
| [`@aurabase/auth`](../auth) | `AuthService`, `AuthAdminService` |
|
|
52
|
-
| [`@aurabase/db`](../db) | `DatabaseService`, `QueryBuilder` |
|
|
53
|
-
| [`@aurabase/storage`](../storage) | `StorageService` |
|
|
54
|
-
| [`@aurabase/realtime`](../realtime) | `RealtimeService`, `AuraChannel`, `HeartbeatManager` |
|
|
55
|
-
| [`@aurabase/functions`](../functions) | `FunctionsService` |
|
|
56
|
-
| [`@aurabase/ai`](../ai) | `AiService` |
|
|
57
|
-
| [`@aurabase/notifications`](../notifications) | `NotificationsService`, `NotificationsAdminService` |
|
|
58
|
-
| [`@aurabase/gen`](../gen) | générateur CLI de types `Database` (dev-dependency, non inclus dans `aurabase`) |
|
|
59
|
-
|
|
60
|
-
Tous ces packages (hors `@aurabase/gen`) sont des dépendances directes de `aurabase` : les installer séparément n'est utile que pour du tree-shaking ciblé ou pour composer votre propre client.
|
|
61
|
-
|
|
62
|
-
## Documentation
|
|
63
|
-
|
|
64
|
-
Cette page ne couvre que le rôle du package d'agrégation. Documentation de référence complète : voir le [README du dépôt](../../README.md).
|