totalum-sdk 1.10.5 → 1.11.1
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/CHANGELOG.md +19 -0
- package/dist/_types/{coerce.d-Dgx5wOUv.d.ts → coerce.d-D_rylvPs.d.ts} +1 -1
- package/dist/_types/{errors.d-CIkIZmY-.d.ts → errors.d-BPpY5QKu.d.ts} +32 -2
- package/dist/_types/{integrations.d-B3Ea8Iuc.d.ts → integrations.d-BTZHy48D.d.ts} +2 -2
- package/dist/_types/{ops.d-G13QAhKA.d.ts → ops.d-Ce5zJyX0.d.ts} +2 -2
- package/dist/ai/index.d.ts +275 -23
- package/dist/ai/index.js +305 -24
- package/dist/analytics/index.d.ts +58 -12
- package/dist/analytics/index.js +46 -3
- package/dist/browser/index.d.ts +228 -20
- package/dist/browser/index.js +122 -13
- package/dist/connections/index.d.ts +601 -0
- package/dist/connections/index.js +353 -0
- package/dist/cron/index.d.ts +147 -20
- package/dist/cron/index.js +157 -15
- package/dist/d1/errors.js +15 -0
- package/dist/d1/index.d.ts +254 -10
- package/dist/d1/index.js +24 -4
- package/dist/d1/session.js +26 -2
- package/dist/email/index.d.ts +65 -10
- package/dist/email/index.js +60 -5
- package/dist/errors.js +17 -0
- package/dist/files/index.d.ts +243 -20
- package/dist/files/index.js +247 -14
- package/dist/index.d.ts +28 -10
- package/dist/index.js +22 -5
- package/dist/logs/index.d.ts +48 -10
- package/dist/logs/index.js +39 -4
- package/dist/payments/index.d.ts +221 -23
- package/dist/payments/index.js +216 -18
- package/dist/pdf/index.d.ts +59 -9
- package/dist/pdf/index.js +54 -4
- package/dist/react/index.d.ts +78 -6
- package/dist/react/index.js +51 -5
- package/dist/realtime/index.d.ts +55 -8
- package/dist/realtime/index.js +53 -6
- package/dist/scan/index.d.ts +78 -10
- package/dist/scan/index.js +63 -3
- package/dist/seo/index.d.ts +43 -7
- package/dist/seo/index.js +39 -3
- package/dist/speech/index.d.ts +34 -10
- package/dist/speech/index.js +25 -5
- package/dist/vectors/index.d.ts +96 -9
- package/dist/vectors/index.js +93 -7
- package/dist/web/index.d.ts +168 -15
- package/dist/web/index.js +163 -10
- package/dist/webhooks/index.d.ts +122 -15
- package/dist/webhooks/index.js +119 -13
- package/package.json +6 -1
- package/totalum-sdk.md +8900 -664
- package/totalum-sdk.signatures.json +61 -1
package/CHANGELOG.md
CHANGED
|
@@ -20,6 +20,25 @@ regenerated), plus the request each call sends to SDK-API (`compat/requests/*.js
|
|
|
20
20
|
- **Dist-tags:** `next` is the newest release; `latest` moves only by a decision at launch. `dev` holds the old
|
|
21
21
|
`0.1.0-dev.N` prereleases.
|
|
22
22
|
|
|
23
|
+
## 1.11.1 — 2026-10-11
|
|
24
|
+
|
|
25
|
+
- Documentation only: `totalum-sdk.md` is rewritten as a readable reference — a quick start, a table of contents, an
|
|
26
|
+
overview per module, and for every method a plain-language description, a parameters table (type, required, meaning,
|
|
27
|
+
allowed values), the result field by field, its errors and a real example with its result; every exported type has
|
|
28
|
+
a field table, and the browser session's 67 commands a table. `pnpm docs:coverage` (CI) fails when any exported
|
|
29
|
+
symbol, method, parameter, returned field, type field or browser command is undocumented. JSDoc only in `src/`: no
|
|
30
|
+
runtime, public type or request change; `totalum-sdk.signatures.json` keeps its rows.
|
|
31
|
+
|
|
32
|
+
## 1.11.0 — 2026-10-11
|
|
33
|
+
|
|
34
|
+
- **New namespace `totalum.connections`** (`totalum-sdk/connections`): your app's users connect their own accounts of
|
|
35
|
+
~1,500 apps (Google Calendar, Gmail, Drive, Outlook, OneDrive, Slack, Dropbox, HubSpot, Notion, Stripe, Airtable, …)
|
|
36
|
+
on a hosted page — they sign in at the provider or type their own API key there; no OAuth app of yours — and your
|
|
37
|
+
server runs actions on them and receives their events: `connectUrl`, `list`, `isConnected`, `disconnect`,
|
|
38
|
+
`execute`, `actions`, `action`; discovery `toolkits`, `toolkit`, `triggers`, `trigger`; events `subscribe`,
|
|
39
|
+
`subscriptions`, `unsubscribe`, `verifyEvent` (the delivered `ConnectionEvent`, signed with
|
|
40
|
+
`TOTALUM_WEBHOOK_SECRET`).
|
|
41
|
+
|
|
23
42
|
## 1.10.5 — 2026-10-09
|
|
24
43
|
|
|
25
44
|
- Documentation only: `files.getUploadUrl` states the real largest file per plan — 50 MB on Free, 500 MB on
|
|
@@ -2339,8 +2339,14 @@ declare const ErrorCode: ZodEnum<{
|
|
|
2339
2339
|
FEATURE_LIMIT_REACHED: "FEATURE_LIMIT_REACHED";
|
|
2340
2340
|
FEATURE_DISABLED: "FEATURE_DISABLED";
|
|
2341
2341
|
VECTORS_LIMIT_REACHED: "VECTORS_LIMIT_REACHED";
|
|
2342
|
+
CONNECTION_REQUIRED: "CONNECTION_REQUIRED";
|
|
2343
|
+
CONNECTION_ACTION_FAILED: "CONNECTION_ACTION_FAILED";
|
|
2344
|
+
TOOLKIT_NOT_AVAILABLE: "TOOLKIT_NOT_AVAILABLE";
|
|
2345
|
+
TOOLKIT_NEEDS_OWN_APP: "TOOLKIT_NEEDS_OWN_APP";
|
|
2342
2346
|
AGENT_ALREADY_RUNNING: "AGENT_ALREADY_RUNNING";
|
|
2343
2347
|
IMPORT_IN_PROGRESS: "IMPORT_IN_PROGRESS";
|
|
2348
|
+
MIGRATION_TOO_LARGE: "MIGRATION_TOO_LARGE";
|
|
2349
|
+
MIGRATION_START_FAILED: "MIGRATION_START_FAILED";
|
|
2344
2350
|
TOO_MANY_RUN_REQUESTS: "TOO_MANY_RUN_REQUESTS";
|
|
2345
2351
|
PROMPT_SECURITY_VIOLATION: "PROMPT_SECURITY_VIOLATION";
|
|
2346
2352
|
NO_PROCESS_RUNNING: "NO_PROCESS_RUNNING";
|
|
@@ -2754,8 +2760,14 @@ declare const ErrorBody: ZodObject<{
|
|
|
2754
2760
|
FEATURE_LIMIT_REACHED: "FEATURE_LIMIT_REACHED";
|
|
2755
2761
|
FEATURE_DISABLED: "FEATURE_DISABLED";
|
|
2756
2762
|
VECTORS_LIMIT_REACHED: "VECTORS_LIMIT_REACHED";
|
|
2763
|
+
CONNECTION_REQUIRED: "CONNECTION_REQUIRED";
|
|
2764
|
+
CONNECTION_ACTION_FAILED: "CONNECTION_ACTION_FAILED";
|
|
2765
|
+
TOOLKIT_NOT_AVAILABLE: "TOOLKIT_NOT_AVAILABLE";
|
|
2766
|
+
TOOLKIT_NEEDS_OWN_APP: "TOOLKIT_NEEDS_OWN_APP";
|
|
2757
2767
|
AGENT_ALREADY_RUNNING: "AGENT_ALREADY_RUNNING";
|
|
2758
2768
|
IMPORT_IN_PROGRESS: "IMPORT_IN_PROGRESS";
|
|
2769
|
+
MIGRATION_TOO_LARGE: "MIGRATION_TOO_LARGE";
|
|
2770
|
+
MIGRATION_START_FAILED: "MIGRATION_START_FAILED";
|
|
2759
2771
|
TOO_MANY_RUN_REQUESTS: "TOO_MANY_RUN_REQUESTS";
|
|
2760
2772
|
PROMPT_SECURITY_VIOLATION: "PROMPT_SECURITY_VIOLATION";
|
|
2761
2773
|
NO_PROCESS_RUNNING: "NO_PROCESS_RUNNING";
|
|
@@ -3132,17 +3144,18 @@ type ErrorBody = output<typeof ErrorBody>;
|
|
|
3132
3144
|
interface TotalumClientOptions {
|
|
3133
3145
|
/** Project key `tlm_pk_…`; default `TOTALUM_PROJECT_KEY`. Server-side only. */
|
|
3134
3146
|
key?: string;
|
|
3135
|
-
/**
|
|
3147
|
+
/** The Totalum API's URL: default `TOTALUM_SDK_API_URL`, else `https://sdk-api.totalum.app`. */
|
|
3136
3148
|
apiUrl?: string;
|
|
3137
3149
|
/** Sent as `x-totalum-env` on every call (the database it targets, and dev vs live usage); default `TOTALUM_ENV`, else `live`. */
|
|
3138
3150
|
env?: 'dev' | 'live';
|
|
3139
3151
|
}
|
|
3140
3152
|
/** What a call was charged, in Totalum credits: the only usage Totalum shows (never a vendor, units or a cost). */
|
|
3141
3153
|
interface Usage {
|
|
3154
|
+
/** Credits charged for this call. */
|
|
3142
3155
|
credits: number;
|
|
3143
3156
|
}
|
|
3144
3157
|
|
|
3145
|
-
/** Every code a `TotalumError` can carry: the Totalum API's frozen codes plus the client-side ones. */
|
|
3158
|
+
/** Every code a `TotalumError` can carry: the Totalum API's frozen codes plus the client-side ones (see Errors). */
|
|
3146
3159
|
type TotalumErrorCode = ErrorCode | SdkClientErrorCode;
|
|
3147
3160
|
/**
|
|
3148
3161
|
* The one error every `totalum-sdk` call throws: the Totalum API envelope's frozen `errorCode`, the HTTP
|
|
@@ -3150,10 +3163,13 @@ type TotalumErrorCode = ErrorCode | SdkClientErrorCode;
|
|
|
3150
3163
|
* extend it, so one `isTotalumError(e)` check covers the whole package.
|
|
3151
3164
|
*/
|
|
3152
3165
|
declare class TotalumError extends Error {
|
|
3166
|
+
/** `'TotalumError'` (or the subclass's name). */
|
|
3153
3167
|
name: string;
|
|
3168
|
+
/** The frozen error code (`FILE_NOT_FOUND`, `INSUFFICIENT_CREDITS`, …): branch on it, never on `message`. */
|
|
3154
3169
|
readonly errorCode: TotalumErrorCode;
|
|
3155
3170
|
/** HTTP status; 0 for network errors, 500 for client-side refusals. */
|
|
3156
3171
|
readonly status: number;
|
|
3172
|
+
/** Extra data about the failure (`maxBytes`, `retryAfterMs`, the field that failed validation), when any. */
|
|
3157
3173
|
readonly details: Record<string, unknown> | undefined;
|
|
3158
3174
|
/** the Totalum API's request id, for support and the logs explorer. */
|
|
3159
3175
|
readonly requestId: string | undefined;
|
|
@@ -3163,6 +3179,20 @@ declare class TotalumError extends Error {
|
|
|
3163
3179
|
/** Every field a log or `Response.json` needs (undefined ones drop out); workerd's tail logs an Error through this. */
|
|
3164
3180
|
toJSON(): Record<string, unknown>;
|
|
3165
3181
|
}
|
|
3182
|
+
/**
|
|
3183
|
+
* Whether `e` is an error thrown by `totalum-sdk` (`TotalumError` or a subclass): then `e.errorCode`, `e.status`,
|
|
3184
|
+
* `e.details` and `e.requestId` are typed.
|
|
3185
|
+
*
|
|
3186
|
+
* @param e - Anything caught.
|
|
3187
|
+
* @returns `true` for a `TotalumError`.
|
|
3188
|
+
* @example
|
|
3189
|
+
* try {
|
|
3190
|
+
* await totalum.email.send(msg);
|
|
3191
|
+
* } catch (e) {
|
|
3192
|
+
* if (isTotalumError(e) && e.errorCode === 'INSUFFICIENT_CREDITS') return Response.json({ error: 'Out of credits' }, { status: 402 });
|
|
3193
|
+
* throw e;
|
|
3194
|
+
* }
|
|
3195
|
+
*/
|
|
3166
3196
|
declare function isTotalumError(e: unknown): e is TotalumError;
|
|
3167
3197
|
|
|
3168
3198
|
export { ErrorBody as E, ZodObject as Z, TotalumError as a, ZodOptional as c, ZodString as d, ZodArray as e, ZodEnum as f, ZodUnknown as g, ZodRecord as h, isTotalumError as i, ZodBoolean as j, ZodNumber as k, ZodUnion as n, ZodURL as p, ZodLiteral as r, ZodType as s, ZodISODateTime as u, ZodNullable as w, ZodEmail as y };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZodObject, d as ZodString, c as ZodOptional, f as ZodEnum, k as ZodNumber, j as ZodBoolean, m as $strip, o as output, p as ZodURL, e as ZodArray, n as ZodUnion, l as ZodInt, h as ZodRecord, w as ZodNullable, u as ZodISODateTime, y as ZodEmail, r as ZodLiteral, g as ZodUnknown } from './errors.d-
|
|
2
|
-
import { Z as ZodCoercedNumber } from './coerce.d-
|
|
1
|
+
import { Z as ZodObject, d as ZodString, c as ZodOptional, f as ZodEnum, k as ZodNumber, j as ZodBoolean, m as $strip, o as output, p as ZodURL, e as ZodArray, n as ZodUnion, l as ZodInt, h as ZodRecord, w as ZodNullable, u as ZodISODateTime, y as ZodEmail, r as ZodLiteral, g as ZodUnknown } from './errors.d-BPpY5QKu.js';
|
|
2
|
+
import { Z as ZodCoercedNumber } from './coerce.d-D_rylvPs.js';
|
|
3
3
|
|
|
4
4
|
/** `202` of every async integration call; `estimatedCredits` = the reserved estimate (settled to the real cost). */
|
|
5
5
|
declare const JobCreated: ZodObject<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Z as ZodObject, c as ZodOptional, e as ZodArray, u as ZodISODateTime, v as $catchall, k as ZodNumber, d as ZodString, f as ZodEnum, m as $strip, r as ZodLiteral, j as ZodBoolean, o as output, w as ZodNullable, l as ZodInt } from './errors.d-
|
|
2
|
-
import { Z as ZodCoercedNumber } from './coerce.d-
|
|
1
|
+
import { Z as ZodObject, c as ZodOptional, e as ZodArray, u as ZodISODateTime, v as $catchall, k as ZodNumber, d as ZodString, f as ZodEnum, m as $strip, r as ZodLiteral, j as ZodBoolean, o as output, w as ZodNullable, l as ZodInt } from './errors.d-BPpY5QKu.js';
|
|
2
|
+
import { Z as ZodCoercedNumber } from './coerce.d-D_rylvPs.js';
|
|
3
3
|
|
|
4
4
|
declare const SiteMetric: ZodEnum<{
|
|
5
5
|
bytes: "bytes";
|
package/dist/ai/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SpeechAudio } from '../speech/index.js';
|
|
2
|
-
import { Z as ZodObject, c as ZodOptional, d as ZodString, e as ZodArray, f as ZodEnum, g as ZodUnknown, $ as $loose, h as ZodRecord, j as ZodBoolean, k as ZodNumber, l as ZodInt, m as $strip, o as output, n as ZodUnion, p as ZodURL, q as $partial, r as ZodLiteral, T as TotalumClientOptions, U as Usage } from '../_types/errors.d-
|
|
3
|
-
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-
|
|
2
|
+
import { Z as ZodObject, c as ZodOptional, d as ZodString, e as ZodArray, f as ZodEnum, g as ZodUnknown, $ as $loose, h as ZodRecord, j as ZodBoolean, k as ZodNumber, l as ZodInt, m as $strip, o as output, n as ZodUnion, p as ZodURL, q as $partial, r as ZodLiteral, T as TotalumClientOptions, U as Usage } from '../_types/errors.d-BPpY5QKu.js';
|
|
3
|
+
export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-BPpY5QKu.js';
|
|
4
4
|
import { SpeakInput, StoredMedia, TranscribeInput } from '../index.js';
|
|
5
|
-
import '../_types/coerce.d-
|
|
5
|
+
import '../_types/coerce.d-D_rylvPs.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Named model presets: the Totalum API resolves each to an model id refreshed from the model catalogue to the newest non-deprecated model of the preset's family. A `model`
|
|
@@ -203,12 +203,14 @@ declare const AiModelsOutput: ZodObject<{
|
|
|
203
203
|
}, $strip>;
|
|
204
204
|
type AiModelsOutput = output<typeof AiModelsOutput>;
|
|
205
205
|
|
|
206
|
+
/** The options of `totalumAi()`: the client options plus the AI gateway URL `gatewayConfig()` returns. */
|
|
206
207
|
interface TotalumAiOptions extends TotalumClientOptions {
|
|
207
208
|
/** The OpenAI-compatible AI gateway `gatewayConfig()` returns; default `TOTALUM_AI_BASE_URL`, else `https://ai.totalum.app/api/v1`. */
|
|
208
209
|
aiBaseUrl?: string;
|
|
209
210
|
}
|
|
210
211
|
/** What a call was charged, in Totalum credits — the only usage Totalum shows (no tokens). */
|
|
211
212
|
interface ChatUsage {
|
|
213
|
+
/** Credits charged for this call. */
|
|
212
214
|
credits: number;
|
|
213
215
|
/** @deprecated Since 1.1.0: always 0 — Totalum shows only `credits`. */
|
|
214
216
|
inputTokens: number;
|
|
@@ -216,45 +218,117 @@ interface ChatUsage {
|
|
|
216
218
|
outputTokens: number;
|
|
217
219
|
}
|
|
218
220
|
interface ToolCall {
|
|
221
|
+
/** The call's id: send the tool's answer back as a `tool` message with this `tool_call_id`. */
|
|
219
222
|
id: string;
|
|
223
|
+
/** Always `function`. */
|
|
220
224
|
type: string;
|
|
225
|
+
/** The function the model wants to call. */
|
|
221
226
|
function: {
|
|
227
|
+
/** The tool's name, as you declared it in `tools`. */
|
|
222
228
|
name: string;
|
|
229
|
+
/** Its arguments as a JSON string: `JSON.parse` it. */
|
|
223
230
|
arguments: string;
|
|
224
231
|
};
|
|
225
232
|
}
|
|
226
233
|
/** `ai.chat()`: the first choice read out, the raw completion kept. */
|
|
227
234
|
interface ChatResult {
|
|
235
|
+
/** The completion's id. */
|
|
228
236
|
id: string;
|
|
237
|
+
/** The model that answered (a preset resolves to the model it currently points to). */
|
|
229
238
|
model: string;
|
|
239
|
+
/** The answer's text (empty when the model only called tools). */
|
|
230
240
|
text: string;
|
|
241
|
+
/** The tools the model asks you to call (with `tools`); empty otherwise. */
|
|
231
242
|
toolCalls: ToolCall[];
|
|
243
|
+
/** Why it stopped: `stop` (finished), `length` (hit `maxTokens`), `tool_calls`, `content_filter`, or `null`. */
|
|
232
244
|
finishReason: string | null;
|
|
245
|
+
/** What the call cost. */
|
|
233
246
|
usage: ChatUsage;
|
|
247
|
+
/** The whole OpenAI-format completion, as received. */
|
|
234
248
|
raw: unknown;
|
|
235
249
|
}
|
|
236
250
|
/** `ai.chat.stream()`: the OpenAI-format SSE (`raw`), its text deltas, and the result once it ends. */
|
|
237
251
|
interface ChatStream {
|
|
252
|
+
/**
|
|
253
|
+
* The OpenAI-format server-sent events, as received: return them from a route (`new Response(stream.raw)`) to
|
|
254
|
+
* stream to the browser. Read either `raw` or `text()`, not both.
|
|
255
|
+
*/
|
|
238
256
|
readonly raw: ReadableStream<Uint8Array>;
|
|
257
|
+
/**
|
|
258
|
+
* The answer's text pieces as they arrive (one pass): `for await (const piece of stream.text())`.
|
|
259
|
+
*
|
|
260
|
+
* @returns An async iterable of text pieces.
|
|
261
|
+
* @example
|
|
262
|
+
* const stream = await totalum.ai.chat.stream({ model: 'fast', messages: [{ role: 'user', content: 'Count 1 to 3.' }] });
|
|
263
|
+
* for await (const piece of stream.text()) process.stdout.write(piece);
|
|
264
|
+
* //=>
|
|
265
|
+
* "1" ", " "2" ", " "3" "."
|
|
266
|
+
*/
|
|
239
267
|
text(): AsyncIterable<string>;
|
|
268
|
+
/**
|
|
269
|
+
* The final result once the stream ends, with its credits (reads the rest of the stream if needed).
|
|
270
|
+
*
|
|
271
|
+
* @returns The same result `chat()` returns; `raw` holds the accumulated text.
|
|
272
|
+
* @throws AI_STREAM_ERROR (502) The stream broke before the end.
|
|
273
|
+
* @example
|
|
274
|
+
* const stream = await totalum.ai.chat.stream({ model: 'fast', messages: [{ role: 'user', content: 'Count 1 to 3.' }] });
|
|
275
|
+
* const result = await stream.result();
|
|
276
|
+
* //=>
|
|
277
|
+
* {
|
|
278
|
+
* "id": "gen-1791740371-wfMT8WhpKYrAEa1s9XKT",
|
|
279
|
+
* "model": "openai/gpt-6-luna",
|
|
280
|
+
* "text": "1, 2, 3.",
|
|
281
|
+
* "toolCalls": [],
|
|
282
|
+
* "finishReason": "stop",
|
|
283
|
+
* "usage": { "credits": 0.0005, "inputTokens": 0, "outputTokens": 0 },
|
|
284
|
+
* "raw": { "id": "gen-1791740371-wfMT8WhpKYrAEa1s9XKT", "model": "openai/gpt-6-luna", "text": "1, 2, 3.", "choices": [{ "message": { "content": "1, 2, 3." }, "finish_reason": "stop" }] }
|
|
285
|
+
* }
|
|
286
|
+
*/
|
|
240
287
|
result(): Promise<ChatResult>;
|
|
241
288
|
}
|
|
242
289
|
/**
|
|
243
|
-
* `
|
|
290
|
+
* Creates the `ai` namespace (the same object as `totalum.ai`, scope `ai`): a `model` is a preset (`fast`,
|
|
244
291
|
* `smart`, `reasoning`, `vision`, `image`, `image-edit`, `video`, `tts`, `stt`, `embed` — each follows the newest model
|
|
245
|
-
* of its family, resolved by Totalum) or a pinned model id; every call
|
|
246
|
-
*
|
|
247
|
-
*
|
|
292
|
+
* of its family, resolved by Totalum) or a pinned model id; every call returns the Totalum credits it was charged
|
|
293
|
+
* (`usage.credits`, never tokens). There is no `ai.agent()`: an agent loop runs on an OpenAI-compatible library (the
|
|
294
|
+
* template's `src/agents/` uses the Vercel AI SDK) pointed at `gatewayConfig()`, which reaches the same models with the
|
|
295
|
+
* same key, billed in credits. Vector search is `totalum.vectors`.
|
|
248
296
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
297
|
+
* @param options - The project key, API URL, environment and AI gateway URL; each falls back to its environment
|
|
298
|
+
* variable.
|
|
299
|
+
* @returns The `ai` namespace: the methods below.
|
|
300
|
+
* @example
|
|
301
|
+
* import { totalumAi } from 'totalum-sdk/ai';
|
|
302
|
+
*
|
|
303
|
+
* const ai = totalumAi();
|
|
304
|
+
* const { text } = await ai.chat({ messages: [{ role: 'user', content: 'Hello' }] });
|
|
252
305
|
*/
|
|
253
306
|
declare function totalumAi(options?: TotalumAiOptions): {
|
|
254
307
|
chat: ((req: Omit<AiChatInput, "stream">) => Promise<ChatResult>) & {
|
|
255
308
|
/**
|
|
256
|
-
* The same request streamed:
|
|
257
|
-
* `
|
|
309
|
+
* The same request, streamed: the answer arrives piece by piece, for a chat UI that types as it goes. `raw` is
|
|
310
|
+
* the OpenAI-format server-sent events (return it from a route), `text()` the text pieces, `result()` the final
|
|
311
|
+
* result with its credits.
|
|
312
|
+
*
|
|
313
|
+
* @param req - The same input as `chat()`.
|
|
314
|
+
* @returns The stream handle: `raw`, `text()` and `result()`.
|
|
315
|
+
* @throws AI_STREAM_ERROR (502) The model returned no stream.
|
|
316
|
+
* @throws AI_MODEL_UNKNOWN (400) No such preset or model id.
|
|
317
|
+
* @throws AI_MODEL_NOT_ALLOWED (403) The model is not available on this plan.
|
|
318
|
+
* @example
|
|
319
|
+
* // src/app/api/chat/route.ts — stream the answer to the browser
|
|
320
|
+
* export async function POST(request: Request) {
|
|
321
|
+
* const { messages } = await request.json();
|
|
322
|
+
* const stream = await totalum.ai.chat.stream({ model: 'fast', messages });
|
|
323
|
+
* return new Response(stream.raw, { headers: { 'content-type': 'text/event-stream' } });
|
|
324
|
+
* }
|
|
325
|
+
* @example
|
|
326
|
+
* const stream = await totalum.ai.chat.stream({ model: 'fast', messages: [{ role: 'user', content: 'Count 1 to 3.' }] });
|
|
327
|
+
* let text = '';
|
|
328
|
+
* for await (const piece of stream.text()) text += piece;
|
|
329
|
+
* const { usage } = await stream.result();
|
|
330
|
+
* //=>
|
|
331
|
+
* text = "1, 2, 3." usage = { credits: 0.0005, inputTokens: 0, outputTokens: 0 }
|
|
258
332
|
*/
|
|
259
333
|
stream: (req: Omit<AiChatInput, "stream">) => Promise<ChatStream>;
|
|
260
334
|
};
|
|
@@ -265,19 +339,54 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
265
339
|
model?: string;
|
|
266
340
|
healing?: boolean;
|
|
267
341
|
}) => Promise<{
|
|
342
|
+
/** The JSON object, matching `schema`. */
|
|
268
343
|
object: unknown;
|
|
344
|
+
/** What the call cost. */
|
|
269
345
|
usage: Usage;
|
|
270
346
|
}>;
|
|
271
|
-
/**
|
|
347
|
+
/**
|
|
348
|
+
* Picks one label out of your list for an input — route a support ticket, tag a review, detect a language. Sugar
|
|
349
|
+
* over `generateObject`.
|
|
350
|
+
*
|
|
351
|
+
* @param req - The input, the labels and optional instructions.
|
|
352
|
+
* @param req.input - The text to classify.
|
|
353
|
+
* @param req.options - The labels to choose from.
|
|
354
|
+
* @param req.model - A preset or model id. Default `smart`.
|
|
355
|
+
* @param req.instructions - How to choose, in words. Default: "Classify the input into exactly one label."
|
|
356
|
+
* @returns `{ label }`: one of `options` (or `''` if the model gave none).
|
|
357
|
+
* @throws AI_INVALID_SCHEMA (502) The model did not answer a label.
|
|
358
|
+
* @throws AI_MODEL_UNKNOWN (400) No such preset or model id.
|
|
359
|
+
* @example
|
|
360
|
+
* const { label } = await totalum.ai.classify({
|
|
361
|
+
* input: 'My card was charged twice',
|
|
362
|
+
* options: ['billing', 'bug', 'other'],
|
|
363
|
+
* model: 'fast',
|
|
364
|
+
* });
|
|
365
|
+
* //=>
|
|
366
|
+
* { "label": "billing" }
|
|
367
|
+
*/
|
|
272
368
|
classify(req: {
|
|
273
369
|
input: string;
|
|
274
370
|
options: readonly string[];
|
|
275
371
|
model?: string;
|
|
276
372
|
instructions?: string;
|
|
277
373
|
}): Promise<{
|
|
374
|
+
/** The chosen label: one of `options`, or `''` when the model gave none. */
|
|
278
375
|
label: string;
|
|
279
376
|
}>;
|
|
280
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* Turns texts into embedding vectors (lists of numbers whose distance measures meaning). To store and search them,
|
|
379
|
+
* `totalum.vectors` does the embedding for you; use this for your own similarity maths.
|
|
380
|
+
*
|
|
381
|
+
* @param req - The texts and the model.
|
|
382
|
+
* @returns One vector per input, in order, and what it cost.
|
|
383
|
+
* @throws AI_MODEL_UNKNOWN (400) No such preset or model id.
|
|
384
|
+
* @throws AI_PROVIDER_UNAVAILABLE (502) The model did not answer; retry.
|
|
385
|
+
* @example
|
|
386
|
+
* const { embeddings } = await totalum.ai.embed({ input: ['red shoes', 'blue sandals'] });
|
|
387
|
+
* //=>
|
|
388
|
+
* { "embeddings": [[0.0138, -0.0121, 0.0125, …], [0.0042, -0.0337, 0.0198, …]], "usage": { "credits": 0.0001 } }
|
|
389
|
+
*/
|
|
281
390
|
embed: (req: AiEmbedInput) => Promise<{
|
|
282
391
|
embeddings: number[][];
|
|
283
392
|
usage: {
|
|
@@ -285,7 +394,30 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
285
394
|
};
|
|
286
395
|
}>;
|
|
287
396
|
image: {
|
|
288
|
-
/**
|
|
397
|
+
/**
|
|
398
|
+
* Generates images from a prompt — illustrations, product shots, avatars, hero images — and stores each one as a
|
|
399
|
+
* public project file. Generate once and save the `key`: never generate on every page view.
|
|
400
|
+
*
|
|
401
|
+
* @param req - The prompt, the model, the size and how many.
|
|
402
|
+
* @returns The stored images and what they cost.
|
|
403
|
+
* @throws AI_MODEL_UNKNOWN (400) No such preset or model id.
|
|
404
|
+
* @throws AI_MODEL_NOT_ALLOWED (403) The model is not available on this plan.
|
|
405
|
+
* @throws AI_PROVIDER_UNAVAILABLE (502) The model returned no image; retry or change the prompt.
|
|
406
|
+
* @example
|
|
407
|
+
* const { images } = await totalum.ai.image.generate({
|
|
408
|
+
* prompt: 'A watercolor fox reading a book, warm light',
|
|
409
|
+
* aspectRatio: '16:9',
|
|
410
|
+
* });
|
|
411
|
+
* //=>
|
|
412
|
+
* {
|
|
413
|
+
* "images": [
|
|
414
|
+
* { "key": "p/acme-crm/01M4P1J2K3L4M5N6P7Q8R9S0TV.png", "url": "https://files.totalum-project.com/p/acme-crm/01M4P1J2K3L4M5N6P7Q8R9S0TV.png", "mediaType": "image/png", "width": 1344, "height": 768 }
|
|
415
|
+
* ],
|
|
416
|
+
* "usage": { "credits": 0.2741 },
|
|
417
|
+
* "fileName": "01M4P1J2K3L4M5N6P7Q8R9S0TV.png",
|
|
418
|
+
* "imageUrl": "https://files.totalum-project.com/p/acme-crm/01M4P1J2K3L4M5N6P7Q8R9S0TV.png"
|
|
419
|
+
* }
|
|
420
|
+
*/
|
|
289
421
|
generate: (req: AiImageInput) => Promise<{
|
|
290
422
|
images: {
|
|
291
423
|
key: string;
|
|
@@ -300,7 +432,28 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
300
432
|
fileName?: string | undefined;
|
|
301
433
|
imageUrl?: string | undefined;
|
|
302
434
|
}>;
|
|
303
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* Edits images with a prompt — remove a background, change a colour, put a product in a new scene — and stores
|
|
437
|
+
* the result as a public project file.
|
|
438
|
+
*
|
|
439
|
+
* @param req - The instruction and the images to edit.
|
|
440
|
+
* @returns The stored result image(s) and what they cost.
|
|
441
|
+
* @throws AI_MODEL_UNKNOWN (400) No such preset or model id.
|
|
442
|
+
* @throws FILE_NOT_FOUND (404) An input image key does not exist.
|
|
443
|
+
* @throws AI_PROVIDER_UNAVAILABLE (502) The model returned no image; retry.
|
|
444
|
+
* @example
|
|
445
|
+
* const { images } = await totalum.ai.image.edit({
|
|
446
|
+
* prompt: 'Put this sneaker on a white marble pedestal, studio light',
|
|
447
|
+
* images: [product.photo.url],
|
|
448
|
+
* });
|
|
449
|
+
* //=>
|
|
450
|
+
* {
|
|
451
|
+
* "images": [{ "key": "p/acme-crm/01M4P1K3L4M5N6P7Q8R9S0T1UW.png", "url": "https://files.totalum-project.com/p/acme-crm/01M4P1K3L4M5N6P7Q8R9S0T1UW.png", "mediaType": "image/png" }],
|
|
452
|
+
* "usage": { "credits": 0.3012 },
|
|
453
|
+
* "fileName": "01M4P1K3L4M5N6P7Q8R9S0T1UW.png",
|
|
454
|
+
* "imageUrl": "https://files.totalum-project.com/p/acme-crm/01M4P1K3L4M5N6P7Q8R9S0T1UW.png"
|
|
455
|
+
* }
|
|
456
|
+
*/
|
|
304
457
|
edit: (req: AiImageEditInput) => Promise<{
|
|
305
458
|
images: {
|
|
306
459
|
key: string;
|
|
@@ -317,13 +470,31 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
317
470
|
}>;
|
|
318
471
|
};
|
|
319
472
|
video: {
|
|
320
|
-
/**
|
|
473
|
+
/**
|
|
474
|
+
* Starts generating a video clip (up to 30 s) from a prompt, optionally from a first/last frame or reference
|
|
475
|
+
* images. It takes minutes: store the `jobId` and read `get(jobId)` later (a page refresh, a cron job); the clip
|
|
476
|
+
* is stored as a project file when it completes.
|
|
477
|
+
*
|
|
478
|
+
* @param req - The prompt, the duration and the look.
|
|
479
|
+
* @returns The job id and the credits reserved for it (settled when it ends).
|
|
480
|
+
* @throws AI_MODEL_UNKNOWN (400) No such preset or model id.
|
|
481
|
+
* @throws AI_VIDEO_FAILED (502) The video could not be started.
|
|
482
|
+
* @throws AI_MEDIA_PAUSED_THIS_HOUR (429) Image, video and speech AI are paused until the hour ends.
|
|
483
|
+
* @example
|
|
484
|
+
* const job = await totalum.ai.video.generate({
|
|
485
|
+
* prompt: 'A paper boat sailing down a rainy street, cinematic',
|
|
486
|
+
* durationSec: 5,
|
|
487
|
+
* aspectRatio: '16:9',
|
|
488
|
+
* });
|
|
489
|
+
* // save job.jobId on the row, then read ai.video.get(jobId) later
|
|
490
|
+
* //=>
|
|
491
|
+
* { "jobId": "vid_8m2k4n6p8q0r", "status": "queued", "estimatedCredits": 21.5 }
|
|
492
|
+
*/
|
|
321
493
|
generate: (req: AiVideoInput) => Promise<{
|
|
322
494
|
jobId: string;
|
|
323
495
|
status: "queued";
|
|
324
496
|
estimatedCredits: number;
|
|
325
497
|
}>;
|
|
326
|
-
/** The video job: `status`, and the stored clip once completed. */
|
|
327
498
|
get: (jobId: string) => Promise<{
|
|
328
499
|
jobId: string;
|
|
329
500
|
status: "queued" | "running" | "completed" | "failed" | "cancelled" | "expired";
|
|
@@ -342,8 +513,23 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
342
513
|
}>;
|
|
343
514
|
/**
|
|
344
515
|
* ⚠ NODE-ONLY: polls `get(jobId)` until the job leaves `queued`/`running` (default every 5 s, at most 45 min —
|
|
345
|
-
* the longest clip, 30 s at 1080p, renders in about 22 min).
|
|
346
|
-
*
|
|
516
|
+
* the longest clip, 30 s at 1080p, renders in about 22 min). For scripts (`npx tsx scripts/…`); in a Worker (the
|
|
517
|
+
* preview and the published app) it throws `NODE_ONLY` — store the `jobId` and read `get(jobId)` later instead.
|
|
518
|
+
*
|
|
519
|
+
* @param jobId - The `jobId` from `video.generate()`.
|
|
520
|
+
* @param opts - How often and how long to poll.
|
|
521
|
+
* @param opts.intervalMs - Milliseconds between polls. Default 5000.
|
|
522
|
+
* @param opts.timeoutMs - Stop polling after this long and return the job as it is. Default 2700000 (45 min).
|
|
523
|
+
* @returns The job once it finished (or when the timeout passed).
|
|
524
|
+
* @throws NODE_ONLY Called inside a Worker; `details.replacement` says what to do instead.
|
|
525
|
+
* @throws AI_VIDEO_JOB_NOT_FOUND (404) No such job in this project.
|
|
526
|
+
* @example
|
|
527
|
+
* // scripts/make-intro-video.ts, run with: npx tsx scripts/make-intro-video.ts
|
|
528
|
+
* const { jobId } = await totalum.ai.video.generate({ prompt: 'Logo reveal on black', durationSec: 5 });
|
|
529
|
+
* const job = await totalum.ai.video.wait(jobId);
|
|
530
|
+
* console.log(job.status, job.video?.url);
|
|
531
|
+
* //=>
|
|
532
|
+
* completed https://files.totalum-project.com/p/acme-crm/01M4P1M5N6P7Q8R9S0T1U2V3WX.mp4
|
|
347
533
|
*/
|
|
348
534
|
wait(jobId: string, opts?: {
|
|
349
535
|
intervalMs?: number;
|
|
@@ -351,7 +537,23 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
351
537
|
}): Promise<AiVideoJob>;
|
|
352
538
|
};
|
|
353
539
|
vision: {
|
|
354
|
-
/**
|
|
540
|
+
/**
|
|
541
|
+
* Describes an image in words, or answers a question about it — alt text, moderation, reading a chart, checking a
|
|
542
|
+
* photo. The image can be a project file key, a files URL, an `https://` URL or a data URL.
|
|
543
|
+
*
|
|
544
|
+
* @param req - The image, the question and the model.
|
|
545
|
+
* @returns The answer's text and what it cost.
|
|
546
|
+
* @throws FILE_NOT_FOUND (404) The image key does not exist.
|
|
547
|
+
* @throws AI_PROVIDER_UNAVAILABLE (502) The model could not read the image (for example the URL refused the
|
|
548
|
+
* download); retry with a project file.
|
|
549
|
+
* @example
|
|
550
|
+
* const { text } = await totalum.ai.vision.describe({
|
|
551
|
+
* image: 'p/acme-crm/01M4P1J2K3L4M5N6P7Q8R9S0TV.png',
|
|
552
|
+
* prompt: 'Write alt text for this image in one sentence.',
|
|
553
|
+
* });
|
|
554
|
+
* //=>
|
|
555
|
+
* { "text": "A watercolor fox sits under a lamp reading an open book.", "usage": { "credits": 0.0019 } }
|
|
556
|
+
*/
|
|
355
557
|
describe: (req: AiVisionDescribeInput) => Promise<{
|
|
356
558
|
text: string;
|
|
357
559
|
usage: {
|
|
@@ -389,7 +591,35 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
389
591
|
}>;
|
|
390
592
|
};
|
|
391
593
|
models: {
|
|
392
|
-
/**
|
|
594
|
+
/**
|
|
595
|
+
* Each preset's current model and the catalogue of models this project may call (their ids, names, inputs and
|
|
596
|
+
* context sizes) — to let an admin pick a model, or to pin one. Free.
|
|
597
|
+
*
|
|
598
|
+
* @returns The presets and the model catalogue.
|
|
599
|
+
* @throws AI_PROVIDER_UNAVAILABLE (503) The model catalogue is unavailable; retry.
|
|
600
|
+
* @example
|
|
601
|
+
* const { presets, models } = await totalum.ai.models.list();
|
|
602
|
+
* //=>
|
|
603
|
+
* {
|
|
604
|
+
* "presets": {
|
|
605
|
+
* "fast": "openai/gpt-6-luna",
|
|
606
|
+
* "smart": "openai/gpt-6.1-sol",
|
|
607
|
+
* "reasoning": "anthropic/claude-opus-5.5",
|
|
608
|
+
* "vision": "openai/gpt-6-luna",
|
|
609
|
+
* "image": "microsoft/mai-image-2.6-flash",
|
|
610
|
+
* "image-edit": "microsoft/mai-image-2.6-flash",
|
|
611
|
+
* "video": "alibaba/wan-3.0",
|
|
612
|
+
* "tts": "microsoft/mai-voice-2.1-flash",
|
|
613
|
+
* "stt": "openai/whisper-large-v3-turbo",
|
|
614
|
+
* "embed": "openai/text-embedding-3-small",
|
|
615
|
+
* "embed-image": "google/gemini-embedding-2"
|
|
616
|
+
* },
|
|
617
|
+
* "models": [
|
|
618
|
+
* { "slug": "anthropic/claude-haiku-5.5", "name": "Anthropic: Claude Haiku 5.5", "inputModalities": ["text", "image", "file"], "pricing": {}, "contextLength": 1000000 },
|
|
619
|
+
* …
|
|
620
|
+
* ]
|
|
621
|
+
* }
|
|
622
|
+
*/
|
|
393
623
|
list: () => Promise<{
|
|
394
624
|
presets: Partial<Record<"fast" | "reasoning" | "video" | "image" | "smart" | "vision" | "image-edit" | "tts" | "stt" | "embed" | "embed-image", string>>;
|
|
395
625
|
models: {
|
|
@@ -402,9 +632,31 @@ declare function totalumAi(options?: TotalumAiOptions): {
|
|
|
402
632
|
denylist?: string[] | undefined;
|
|
403
633
|
}>;
|
|
404
634
|
};
|
|
405
|
-
/**
|
|
635
|
+
/**
|
|
636
|
+
* The URL and key of Totalum's OpenAI-compatible AI gateway, for any library that takes an OpenAI client: the
|
|
637
|
+
* Vercel AI SDK, `openai`, LangChain. Same models, same key, billed in credits. Server-side only: the key is the
|
|
638
|
+
* project key. No request is made.
|
|
639
|
+
*
|
|
640
|
+
* @returns `{ baseURL, apiKey }` to pass to the client.
|
|
641
|
+
* @throws SDK_NOT_CONFIGURED No project key is set.
|
|
642
|
+
* @example
|
|
643
|
+
* import OpenAI from 'openai';
|
|
644
|
+
*
|
|
645
|
+
* const openai = new OpenAI(totalum.ai.gatewayConfig());
|
|
646
|
+
* const r = await openai.chat.completions.create({ model: 'fast', messages: [{ role: 'user', content: 'Hi' }] });
|
|
647
|
+
* @example
|
|
648
|
+
* import { createOpenAI } from '@ai-sdk/openai';
|
|
649
|
+
* import { generateText } from 'ai';
|
|
650
|
+
*
|
|
651
|
+
* const gateway = createOpenAI(totalum.ai.gatewayConfig());
|
|
652
|
+
* const { text } = await generateText({ model: gateway('smart'), prompt: 'Write a haiku about Mondays' });
|
|
653
|
+
* //=>
|
|
654
|
+
* { "baseURL": "https://ai.totalum.app/api/v1", "apiKey": "tlm_pk_…" }
|
|
655
|
+
*/
|
|
406
656
|
gatewayConfig: () => {
|
|
657
|
+
/** The gateway's OpenAI-compatible base URL: `TOTALUM_AI_BASE_URL`, else `https://ai.totalum.app/api/v1`. */
|
|
407
658
|
baseURL: string;
|
|
659
|
+
/** The project key, used as the API key. */
|
|
408
660
|
apiKey: string;
|
|
409
661
|
};
|
|
410
662
|
};
|