@proveanything/smartlinks 1.3.15 → 1.3.17
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 +7 -1
- package/dist/api/ai.d.ts +435 -0
- package/dist/api/ai.js +248 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/docs/API_SUMMARY.md +496 -2
- package/dist/docs/ai.md +1565 -0
- package/docs/API_SUMMARY.md +496 -2
- package/docs/ai.md +1565 -0
- package/package.json +1 -1
package/dist/api/ai.js
CHANGED
|
@@ -1,10 +1,257 @@
|
|
|
1
1
|
// src/api/ai.ts
|
|
2
2
|
// AI endpoints: public and admin helpers
|
|
3
|
-
import { post } from "../http";
|
|
3
|
+
import { post, request, del } from "../http";
|
|
4
4
|
export var ai;
|
|
5
5
|
(function (ai) {
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// Chat Completions API (OpenAI-compatible)
|
|
8
|
+
// ============================================================================
|
|
9
|
+
let chat;
|
|
10
|
+
(function (chat) {
|
|
11
|
+
let completions;
|
|
12
|
+
(function (completions) {
|
|
13
|
+
/**
|
|
14
|
+
* Create a chat completion (streaming or non-streaming)
|
|
15
|
+
* @param collectionId - Collection identifier
|
|
16
|
+
* @param request - Chat completion request
|
|
17
|
+
* @returns Chat completion response or async iterable for streaming
|
|
18
|
+
*/
|
|
19
|
+
async function create(collectionId, request) {
|
|
20
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/v1/chat/completions`;
|
|
21
|
+
if (request.stream) {
|
|
22
|
+
// TODO: Implement streaming via SSE
|
|
23
|
+
throw new Error('Streaming not yet implemented');
|
|
24
|
+
}
|
|
25
|
+
return post(path, request);
|
|
26
|
+
}
|
|
27
|
+
completions.create = create;
|
|
28
|
+
})(completions = chat.completions || (chat.completions = {}));
|
|
29
|
+
})(chat = ai.chat || (ai.chat = {}));
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// Models API
|
|
32
|
+
// ============================================================================
|
|
33
|
+
let models;
|
|
34
|
+
(function (models) {
|
|
35
|
+
/**
|
|
36
|
+
* List available AI models
|
|
37
|
+
*/
|
|
38
|
+
async function list(collectionId) {
|
|
39
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/models`;
|
|
40
|
+
return request(path);
|
|
41
|
+
}
|
|
42
|
+
models.list = list;
|
|
43
|
+
/**
|
|
44
|
+
* Get specific model information
|
|
45
|
+
*/
|
|
46
|
+
async function get(collectionId, modelId) {
|
|
47
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/models/${encodeURIComponent(modelId)}`;
|
|
48
|
+
return request(path);
|
|
49
|
+
}
|
|
50
|
+
models.get = get;
|
|
51
|
+
})(models = ai.models || (ai.models = {}));
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// RAG API
|
|
54
|
+
// ============================================================================
|
|
55
|
+
let rag;
|
|
56
|
+
(function (rag) {
|
|
57
|
+
/**
|
|
58
|
+
* Index a document for RAG
|
|
59
|
+
*/
|
|
60
|
+
async function indexDocument(collectionId, request) {
|
|
61
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/indexDocument`;
|
|
62
|
+
return post(path, request);
|
|
63
|
+
}
|
|
64
|
+
rag.indexDocument = indexDocument;
|
|
65
|
+
/**
|
|
66
|
+
* Configure AI assistant behavior
|
|
67
|
+
*/
|
|
68
|
+
async function configureAssistant(collectionId, request) {
|
|
69
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/configureAssistant`;
|
|
70
|
+
return post(path, request);
|
|
71
|
+
}
|
|
72
|
+
rag.configureAssistant = configureAssistant;
|
|
73
|
+
})(rag = ai.rag || (ai.rag = {}));
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Sessions API
|
|
76
|
+
// ============================================================================
|
|
77
|
+
let sessions;
|
|
78
|
+
(function (sessions) {
|
|
79
|
+
/**
|
|
80
|
+
* Get session statistics
|
|
81
|
+
*/
|
|
82
|
+
async function stats(collectionId) {
|
|
83
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/sessions/stats`;
|
|
84
|
+
return request(path);
|
|
85
|
+
}
|
|
86
|
+
sessions.stats = stats;
|
|
87
|
+
})(sessions = ai.sessions || (ai.sessions = {}));
|
|
88
|
+
// ============================================================================
|
|
89
|
+
// Rate Limiting API
|
|
90
|
+
// ============================================================================
|
|
91
|
+
let rateLimit;
|
|
92
|
+
(function (rateLimit) {
|
|
93
|
+
/**
|
|
94
|
+
* Reset rate limit for a user
|
|
95
|
+
*/
|
|
96
|
+
async function reset(collectionId, userId) {
|
|
97
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/rate-limit/${encodeURIComponent(userId)}/reset`;
|
|
98
|
+
return post(path, {});
|
|
99
|
+
}
|
|
100
|
+
rateLimit.reset = reset;
|
|
101
|
+
})(rateLimit = ai.rateLimit || (ai.rateLimit = {}));
|
|
102
|
+
// ============================================================================
|
|
103
|
+
// Podcast API
|
|
104
|
+
// ============================================================================
|
|
105
|
+
let podcast;
|
|
106
|
+
(function (podcast) {
|
|
107
|
+
/**
|
|
108
|
+
* Generate a NotebookLM-style conversational podcast from product documents
|
|
109
|
+
*/
|
|
110
|
+
async function generate(collectionId, request) {
|
|
111
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/generatePodcast`;
|
|
112
|
+
return post(path, request);
|
|
113
|
+
}
|
|
114
|
+
podcast.generate = generate;
|
|
115
|
+
/**
|
|
116
|
+
* Get podcast generation status
|
|
117
|
+
*/
|
|
118
|
+
async function getStatus(collectionId, podcastId) {
|
|
119
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/podcast/${encodeURIComponent(podcastId)}`;
|
|
120
|
+
return request(path);
|
|
121
|
+
}
|
|
122
|
+
podcast.getStatus = getStatus;
|
|
123
|
+
})(podcast = ai.podcast || (ai.podcast = {}));
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// TTS API
|
|
126
|
+
// ============================================================================
|
|
127
|
+
let tts;
|
|
128
|
+
(function (tts) {
|
|
129
|
+
/**
|
|
130
|
+
* Generate text-to-speech audio
|
|
131
|
+
*/
|
|
132
|
+
async function generate(collectionId, request) {
|
|
133
|
+
const path = `/admin/${encodeURIComponent(collectionId)}/ai/tts`;
|
|
134
|
+
// Note: This would need special handling for binary response
|
|
135
|
+
return post(path, request);
|
|
136
|
+
}
|
|
137
|
+
tts.generate = generate;
|
|
138
|
+
})(tts = ai.tts || (ai.tts = {}));
|
|
139
|
+
// ============================================================================
|
|
140
|
+
// Public API (no authentication required)
|
|
141
|
+
// ============================================================================
|
|
142
|
+
let publicApi;
|
|
143
|
+
(function (publicApi) {
|
|
144
|
+
/**
|
|
145
|
+
* Chat with product assistant (RAG)
|
|
146
|
+
*/
|
|
147
|
+
async function chat(collectionId, request) {
|
|
148
|
+
const path = `/${encodeURIComponent(collectionId)}/ai/chat`;
|
|
149
|
+
return post(path, request);
|
|
150
|
+
}
|
|
151
|
+
publicApi.chat = chat;
|
|
152
|
+
/**
|
|
153
|
+
* Get session history
|
|
154
|
+
*/
|
|
155
|
+
async function getSession(collectionId, sessionId) {
|
|
156
|
+
const path = `/${encodeURIComponent(collectionId)}/ai/session/${encodeURIComponent(sessionId)}`;
|
|
157
|
+
return request(path);
|
|
158
|
+
}
|
|
159
|
+
publicApi.getSession = getSession;
|
|
160
|
+
/**
|
|
161
|
+
* Clear session history
|
|
162
|
+
*/
|
|
163
|
+
async function clearSession(collectionId, sessionId) {
|
|
164
|
+
const path = `/${encodeURIComponent(collectionId)}/ai/session/${encodeURIComponent(sessionId)}`;
|
|
165
|
+
return del(path);
|
|
166
|
+
}
|
|
167
|
+
publicApi.clearSession = clearSession;
|
|
168
|
+
/**
|
|
169
|
+
* Check rate limit status
|
|
170
|
+
*/
|
|
171
|
+
async function getRateLimit(collectionId, userId) {
|
|
172
|
+
const path = `/${encodeURIComponent(collectionId)}/ai/rate-limit/${encodeURIComponent(userId)}`;
|
|
173
|
+
return request(path);
|
|
174
|
+
}
|
|
175
|
+
publicApi.getRateLimit = getRateLimit;
|
|
176
|
+
/**
|
|
177
|
+
* Generate ephemeral token for Gemini Live
|
|
178
|
+
*/
|
|
179
|
+
async function getToken(collectionId, request) {
|
|
180
|
+
const path = `/${encodeURIComponent(collectionId)}/ai/token`;
|
|
181
|
+
return post(path, request);
|
|
182
|
+
}
|
|
183
|
+
publicApi.getToken = getToken;
|
|
184
|
+
})(publicApi = ai.publicApi || (ai.publicApi = {}));
|
|
185
|
+
// ============================================================================
|
|
186
|
+
// Voice Helpers (Browser-only)
|
|
187
|
+
// ============================================================================
|
|
188
|
+
let voice;
|
|
189
|
+
(function (voice_1) {
|
|
190
|
+
/**
|
|
191
|
+
* Check if voice is supported in browser
|
|
192
|
+
*/
|
|
193
|
+
function isSupported() {
|
|
194
|
+
if (typeof window === 'undefined')
|
|
195
|
+
return false;
|
|
196
|
+
return ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) && 'speechSynthesis' in window;
|
|
197
|
+
}
|
|
198
|
+
voice_1.isSupported = isSupported;
|
|
199
|
+
/**
|
|
200
|
+
* Listen for voice input
|
|
201
|
+
*/
|
|
202
|
+
async function listen(language = 'en-US') {
|
|
203
|
+
if (typeof window === 'undefined') {
|
|
204
|
+
throw new Error('Voice input is only available in the browser');
|
|
205
|
+
}
|
|
206
|
+
if (!isSupported()) {
|
|
207
|
+
throw new Error('Speech recognition not supported in this browser');
|
|
208
|
+
}
|
|
209
|
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
210
|
+
const recognition = new SpeechRecognition();
|
|
211
|
+
recognition.lang = language;
|
|
212
|
+
recognition.continuous = false;
|
|
213
|
+
recognition.interimResults = false;
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
recognition.onresult = (event) => {
|
|
216
|
+
resolve(event.results[0][0].transcript);
|
|
217
|
+
};
|
|
218
|
+
recognition.onerror = reject;
|
|
219
|
+
recognition.start();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
voice_1.listen = listen;
|
|
223
|
+
/**
|
|
224
|
+
* Speak text
|
|
225
|
+
*/
|
|
226
|
+
async function speak(text, options) {
|
|
227
|
+
if (typeof window === 'undefined') {
|
|
228
|
+
throw new Error('Speech synthesis is only available in the browser');
|
|
229
|
+
}
|
|
230
|
+
if (!('speechSynthesis' in window)) {
|
|
231
|
+
throw new Error('Speech synthesis not supported in this browser');
|
|
232
|
+
}
|
|
233
|
+
const utterance = new SpeechSynthesisUtterance(text);
|
|
234
|
+
if (options === null || options === void 0 ? void 0 : options.rate)
|
|
235
|
+
utterance.rate = options.rate;
|
|
236
|
+
if (options === null || options === void 0 ? void 0 : options.voice) {
|
|
237
|
+
const voices = speechSynthesis.getVoices();
|
|
238
|
+
const voice = voices.find(v => v.name === options.voice);
|
|
239
|
+
if (voice)
|
|
240
|
+
utterance.voice = voice;
|
|
241
|
+
}
|
|
242
|
+
return new Promise((resolve) => {
|
|
243
|
+
utterance.onend = () => resolve();
|
|
244
|
+
speechSynthesis.speak(utterance);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
voice_1.speak = speak;
|
|
248
|
+
})(voice = ai.voice || (ai.voice = {}));
|
|
249
|
+
// ============================================================================
|
|
250
|
+
// Legacy Methods (backwards compatibility)
|
|
251
|
+
// ============================================================================
|
|
6
252
|
/**
|
|
7
253
|
* Generate text/content via AI (admin)
|
|
254
|
+
* @deprecated Use ai.chat.completions.create() instead
|
|
8
255
|
*/
|
|
9
256
|
async function generateContent(collectionId, params, admin = true) {
|
|
10
257
|
const base = admin ? '/admin' : '/public';
|
package/dist/api/index.d.ts
CHANGED
|
@@ -29,4 +29,4 @@ export { location } from "./location";
|
|
|
29
29
|
export * as realtime from "./realtime";
|
|
30
30
|
export { tags } from "./tags";
|
|
31
31
|
export { order } from "./order";
|
|
32
|
-
export type { AIGenerateContentRequest, AIGenerateImageRequest, AISearchPhotosRequest, AISearchPhotosPhoto } from "./ai";
|
|
32
|
+
export type { AIGenerateContentRequest, AIGenerateImageRequest, AISearchPhotosRequest, AISearchPhotosPhoto, ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, ModelList, DocumentChunk, IndexDocumentRequest, IndexDocumentResponse, ConfigureAssistantRequest, ConfigureAssistantResponse, PublicChatRequest, PublicChatResponse, Session, RateLimitStatus, SessionStatistics, VoiceSessionRequest, VoiceSessionResponse, EphemeralTokenRequest, EphemeralTokenResponse, TranscriptionResponse, TTSRequest, GeneratePodcastRequest, GeneratePodcastResponse, PodcastScript, PodcastSegment, PodcastStatus, } from "./ai";
|