totalum-sdk 0.1.0-dev.8 → 1.0.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/_types/{billing.d-C1exPLN6.d.ts → billing.d-BcRcDH4Y.d.ts} +1 -1
  3. package/dist/_types/{coerce.d-RtY2zQyw.d.ts → coerce.d-BXj_o-j6.d.ts} +1 -1
  4. package/dist/_types/{errors.d-yrue1e9O.d.ts → errors.d-Dtt-BIwJ.d.ts} +62 -2
  5. package/dist/_types/{integrations.d-BKPWost0.d.ts → integrations.d-DjOeFaYn.d.ts} +2 -2
  6. package/dist/_types/{ops.d-BOMT9yln.d.ts → ops.d-BKBWL6Qf.d.ts} +2 -2
  7. package/dist/ai/index.d.ts +42 -26
  8. package/dist/ai/index.js +13 -9
  9. package/dist/analytics/index.d.ts +4 -4
  10. package/dist/browser/index.d.ts +114 -5
  11. package/dist/browser/index.js +22 -5
  12. package/dist/cron/index.d.ts +5 -5
  13. package/dist/cron/index.js +2 -10
  14. package/dist/d1/index.d.ts +6 -4
  15. package/dist/d1/lazy.js +21 -3
  16. package/dist/d1/session.js +83 -15
  17. package/dist/deprecate.js +16 -0
  18. package/dist/email/index.d.ts +12 -6
  19. package/dist/email/index.js +4 -3
  20. package/dist/files/index.d.ts +11 -9
  21. package/dist/files/index.js +10 -5
  22. package/dist/index.d.ts +11 -8
  23. package/dist/index.js +3 -0
  24. package/dist/logs/index.d.ts +5 -5
  25. package/dist/payments/index.d.ts +5 -5
  26. package/dist/pdf/index.d.ts +5 -5
  27. package/dist/react/index.d.ts +91 -0
  28. package/dist/react/index.js +178 -0
  29. package/dist/realtime/index.d.ts +2 -2
  30. package/dist/scan/index.d.ts +14 -6
  31. package/dist/scan/index.js +5 -1
  32. package/dist/seo/index.d.ts +4 -4
  33. package/dist/speech/index.d.ts +26 -13
  34. package/dist/speech/index.js +24 -12
  35. package/dist/vectors/index.d.ts +167 -0
  36. package/dist/vectors/index.js +28 -0
  37. package/dist/web/index.d.ts +6 -6
  38. package/dist/web/index.js +1 -1
  39. package/dist/webhooks/index.d.ts +4 -4
  40. package/package.json +24 -4
  41. package/totalum-sdk.md +152 -24
  42. package/totalum-sdk.signatures.json +313 -0
@@ -0,0 +1,178 @@
1
+ import { useEffect, useMemo, useSyncExternalStore } from 'react';
2
+ const HEARTBEAT_MS = 30_000;
3
+ const STALE_MS = 75_000;
4
+ const PRESENCE = 'presence:';
5
+ /** One room, one socket; framework-free (the hook below is a thin wrapper). */
6
+ export class RealtimeChannel {
7
+ room;
8
+ options;
9
+ ws;
10
+ stopped = true;
11
+ attempt = 0;
12
+ timer;
13
+ heartbeat;
14
+ peers = new Map();
15
+ listeners = new Set();
16
+ connectionId = crypto.randomUUID();
17
+ snapshot = { status: 'closed', messages: [], others: [] };
18
+ constructor(room, options = {}) {
19
+ this.room = room;
20
+ this.options = options;
21
+ }
22
+ subscribe = (listener) => {
23
+ this.listeners.add(listener);
24
+ return () => this.listeners.delete(listener);
25
+ };
26
+ getSnapshot = () => this.snapshot;
27
+ connect() {
28
+ if (!this.stopped)
29
+ return;
30
+ this.stopped = false;
31
+ this.set({ status: 'connecting' });
32
+ void this.open();
33
+ if (this.options.presence)
34
+ this.heartbeat = setInterval(() => {
35
+ this.send(`${PRESENCE}here`, this.options.presence);
36
+ this.expire();
37
+ }, HEARTBEAT_MS);
38
+ }
39
+ /** Sends `data` to everyone in the room (you included); `false` when the socket is not open. */
40
+ publish = (data, event = 'message') => this.send(event, data);
41
+ close() {
42
+ if (this.options.presence)
43
+ this.send(`${PRESENCE}leave`, null);
44
+ this.stopped = true;
45
+ clearTimeout(this.timer);
46
+ clearInterval(this.heartbeat);
47
+ this.ws?.close(1000, 'closed');
48
+ this.ws = undefined;
49
+ this.peers.clear();
50
+ this.set({ status: 'closed', others: [] });
51
+ }
52
+ async open() {
53
+ try {
54
+ const { url } = await this.ticket();
55
+ if (this.stopped)
56
+ return;
57
+ const ws = new (this.options.WebSocket ?? WebSocket)(url);
58
+ this.ws = ws;
59
+ ws.addEventListener('open', () => {
60
+ this.attempt = 0;
61
+ this.set({ status: 'open' });
62
+ if (this.options.presence)
63
+ this.send(`${PRESENCE}join`, this.options.presence);
64
+ });
65
+ ws.addEventListener('message', (e) => {
66
+ this.receive(String(e.data));
67
+ });
68
+ ws.addEventListener('close', () => {
69
+ if (this.ws === ws)
70
+ this.retry();
71
+ });
72
+ }
73
+ catch {
74
+ this.retry();
75
+ }
76
+ }
77
+ async ticket() {
78
+ if (this.options.getTicket)
79
+ return this.options.getTicket(this.room);
80
+ const res = await fetch(this.options.ticketUrl ?? '/api/realtime/ticket', {
81
+ method: 'POST',
82
+ headers: { 'content-type': 'application/json' },
83
+ body: JSON.stringify({ room: this.room }),
84
+ });
85
+ if (!res.ok)
86
+ throw new Error(`ticket ${String(res.status)}`);
87
+ const body = await res.json();
88
+ const { url, data } = body;
89
+ return { url: url ?? data?.url ?? '' };
90
+ }
91
+ /** A drop is normal (every deploy drops every socket): re-ticket and reconnect, 0.5 s … 30 s apart. */
92
+ retry() {
93
+ this.ws = undefined;
94
+ if (this.stopped)
95
+ return;
96
+ this.peers.clear();
97
+ this.set({ status: 'reconnecting', others: [] });
98
+ const delay = Math.min(30_000, 500 * 2 ** this.attempt++) * (0.75 + Math.random() / 2);
99
+ this.timer = setTimeout(() => void this.open(), delay);
100
+ }
101
+ send(event, data) {
102
+ if (this.ws?.readyState !== 1)
103
+ return false;
104
+ const payload = event.startsWith(PRESENCE) ? { connectionId: this.connectionId, meta: data } : data;
105
+ this.ws.send(JSON.stringify({ type: 'publish', event, data: payload }));
106
+ return true;
107
+ }
108
+ receive(raw) {
109
+ let frame;
110
+ try {
111
+ frame = JSON.parse(raw);
112
+ }
113
+ catch {
114
+ return;
115
+ }
116
+ if (frame.type !== 'message' || !frame.event || !frame.identity)
117
+ return;
118
+ if (!frame.event.startsWith(PRESENCE)) {
119
+ const keep = this.options.keep ?? 100;
120
+ this.set({ messages: [...this.snapshot.messages, frame].slice(-keep) });
121
+ return;
122
+ }
123
+ const { connectionId, meta } = (frame.data ?? {});
124
+ if (!this.options.presence || !connectionId || connectionId === this.connectionId)
125
+ return;
126
+ if (frame.event === `${PRESENCE}leave`)
127
+ this.peers.delete(connectionId);
128
+ else {
129
+ // a newcomer learns who is already here
130
+ if (frame.event === `${PRESENCE}join`)
131
+ this.send(`${PRESENCE}here`, this.options.presence);
132
+ this.peers.set(connectionId, {
133
+ connectionId,
134
+ identity: frame.identity,
135
+ meta: meta,
136
+ seen: Date.now(),
137
+ });
138
+ }
139
+ this.expire();
140
+ }
141
+ /** Peers whose socket dropped without a goodbye disappear after 75 s of silence. */
142
+ expire() {
143
+ for (const [id, peer] of this.peers)
144
+ if (Date.now() - peer.seen > STALE_MS)
145
+ this.peers.delete(id);
146
+ const others = [...this.peers.values()].map(({ connectionId, identity, meta }) => ({
147
+ connectionId,
148
+ identity,
149
+ meta,
150
+ }));
151
+ this.set({ others });
152
+ }
153
+ set(patch) {
154
+ this.snapshot = { ...this.snapshot, ...patch };
155
+ for (const listener of this.listeners)
156
+ listener();
157
+ }
158
+ }
159
+ const SERVER = { status: 'connecting', messages: [], others: [] };
160
+ /**
161
+ * A room in a client component: `status`, the `messages` received since it opened, `others` (with `presence`), and
162
+ * `publish(data, event?)`. Render `status === 'reconnecting'` as an ordinary state, not an error.
163
+ *
164
+ * @example
165
+ * const { messages, others, publish, status } = useRealtimeChannel(`chat:${roomId}`, { presence: { name } });
166
+ */
167
+ export function useRealtimeChannel(room, options = {}) {
168
+ // one channel per room; the options of its first render are the ones it keeps
169
+ const channel = useMemo(() => new RealtimeChannel(room, options), [room]);
170
+ useEffect(() => {
171
+ channel.connect();
172
+ return () => {
173
+ channel.close();
174
+ };
175
+ }, [channel]);
176
+ const snapshot = useSyncExternalStore(channel.subscribe, channel.getSnapshot, () => SERVER);
177
+ return { ...snapshot, publish: channel.publish };
178
+ }
@@ -1,5 +1,5 @@
1
- import { Z as ZodObject, c as ZodOptional, d as ZodString, g as ZodUnknown, m as $strip, o as output, t as ZodISODateTime, l as ZodInt, h as ZodRecord, j as ZodBoolean, T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
2
- export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
1
+ import { Z as ZodObject, c as ZodOptional, d as ZodString, g as ZodUnknown, m as $strip, o as output, u as ZodISODateTime, l as ZodInt, h as ZodRecord, j as ZodBoolean, T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
2
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
3
3
 
4
4
  /** `POST /v1/realtime/tickets` (scope `realtime`). `ttl` is the join window in seconds, not the session length. */
5
5
  declare const RealtimeTicketInput: ZodObject<{
@@ -1,10 +1,13 @@
1
- import { S as ScanDocumentInput, s as ScanOcrInput } from '../_types/integrations.d-BKPWost0.js';
2
- export { t as ScanOcrOutput } from '../_types/integrations.d-BKPWost0.js';
3
- import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
4
- export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
5
- import '../_types/coerce.d-RtY2zQyw.js';
1
+ import { S as ScanDocumentInput, s as ScanOcrInput } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { t as ScanOcrOutput } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
- /** The v1 scan result: the extracted fields (one set per page with `processEveryPdfPageAsDifferentScan`) + `metadata`. */
7
+ /**
8
+ * The v1 scan result: the extracted fields (one set per page with `processEveryPdfPageAsDifferentScan`), the v1
9
+ * `metadata`, and `usage` like every other paid call.
10
+ */
8
11
  interface ScanDocumentResult {
9
12
  data: Record<string, unknown> | Record<string, unknown>[];
10
13
  metadata: {
@@ -14,6 +17,11 @@ interface ScanDocumentResult {
14
17
  provider: string;
15
18
  credits: number;
16
19
  };
20
+ usage: {
21
+ credits: number;
22
+ vendor?: string | undefined;
23
+ units?: number | undefined;
24
+ };
17
25
  }
18
26
  /** `totalum.scan` (plan 05 §6.7) over `/v1/scan/*` (scope `scan`): a vision model through Totalum's AI gateway. */
19
27
  declare function totalumScan(options?: TotalumClientOptions): {
@@ -5,7 +5,11 @@ export function totalumScan(options = {}) {
5
5
  const call = envelopeClient(options);
6
6
  return {
7
7
  /** Extracts the fields described by `properties` from a document or image (one set per page on request). */
8
- document: async (input) => (await call('POST', '/v1/scan/document', input)),
8
+ document: async (input) => {
9
+ const envelope = await call('POST', '/v1/scan/document', input);
10
+ const { usage } = withUsage({ ...envelope, data: {} });
11
+ return { data: envelope.data, metadata: envelope.metadata, usage };
12
+ },
9
13
  /** The text of a document or image, per page as Markdown. */
10
14
  ocr: async (input) => withUsage(await call('POST', '/v1/scan/ocr', input)),
11
15
  };
@@ -1,7 +1,7 @@
1
- export { w as SeoIndexNowKey, x as SeoNotifyOutput } from '../_types/integrations.d-BKPWost0.js';
2
- import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
3
- export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
4
- import '../_types/coerce.d-RtY2zQyw.js';
1
+ export { w as SeoIndexNowKey, x as SeoNotifyOutput } from '../_types/integrations.d-DjOeFaYn.js';
2
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
3
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ import '../_types/coerce.d-BXj_o-j6.js';
5
5
 
6
6
  /** `totalum.seo` (plan 05 §6.10) over SDK-API `/v1/seo/*` (scope `seo`): IndexNow for verified custom domains, free. */
7
7
  declare function totalumSeo(options?: TotalumClientOptions): {
@@ -1,12 +1,25 @@
1
- import { T as TranscribeInput, y as SpeakInput, z as StoredMedia } from '../_types/integrations.d-BKPWost0.js';
2
- export { A as TranscribeOutput } from '../_types/integrations.d-BKPWost0.js';
3
- import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
4
- export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
5
- import '../_types/coerce.d-RtY2zQyw.js';
1
+ import { T as TranscribeInput, y as SpeakInput, z as StoredMedia } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { A as TranscribeOutput } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
+ /** The audio bytes of `synthesize` without `store`, and what the call cost (`usage.credits`, the call's hold). */
8
+ interface SpeechAudio {
9
+ audio: ArrayBuffer;
10
+ contentType: string;
11
+ usage: {
12
+ credits: number;
13
+ };
14
+ /** @deprecated Since 1.0.0: use `usage.credits` (the same number). */
15
+ readonly credits: number;
16
+ }
7
17
  /** `totalum.speech` (plan 05 §6.8) over `/v1/speech/*` (scope `speech`): OpenRouter speech through Totalum. */
8
18
  declare function totalumSpeech(options?: TotalumClientOptions): {
9
- /** Speech to text from `audioBase64` or a `url`; optional language, word timestamps and speakers. */
19
+ /**
20
+ * Speech to text from `audioBase64` (+ `filename` with its extension) or a `url` — a public one, or a file this
21
+ * project stored; optional language, word timestamps and speakers.
22
+ */
10
23
  transcribe: (input: TranscribeInput) => Promise<{
11
24
  text: string;
12
25
  durationSec: number;
@@ -28,14 +41,14 @@ declare function totalumSpeech(options?: TotalumClientOptions): {
28
41
  end: number;
29
42
  }[] | undefined;
30
43
  }>;
31
- /** The audio bytes, or with `store: true` the stored file `{key, url, usage}`; `credits` is the call's hold. */
32
- synthesize: (input: SpeakInput) => Promise<StoredMedia | {
33
- audio: ArrayBuffer;
34
- contentType: string;
35
- credits: number;
36
- }>;
44
+ synthesize: {
45
+ (input: SpeakInput & {
46
+ store: true;
47
+ }): Promise<StoredMedia>;
48
+ (input: SpeakInput): Promise<StoredMedia | SpeechAudio>;
49
+ };
37
50
  };
38
51
  type TotalumSpeech = ReturnType<typeof totalumSpeech>;
39
52
 
40
53
  export { SpeakInput, StoredMedia, TotalumClientOptions, TranscribeInput, totalumSpeech };
41
- export type { TotalumSpeech };
54
+ export type { SpeechAudio, TotalumSpeech };
@@ -1,22 +1,34 @@
1
+ import { deprecated } from '../deprecate.js';
1
2
  import { jsonClient, rawClient } from '../http.js';
2
3
  export { TotalumError, isTotalumError } from '../errors.js';
3
4
  /** `totalum.speech` (plan 05 §6.8) over `/v1/speech/*` (scope `speech`): OpenRouter speech through Totalum. */
4
5
  export function totalumSpeech(options = {}) {
5
6
  const call = jsonClient(options);
6
7
  const raw = rawClient(options);
8
+ async function synthesize(input) {
9
+ if (input.store)
10
+ return call('POST', '/v1/speech/speak', input);
11
+ const res = await raw('/v1/speech/speak', input);
12
+ const credits = Number(res.headers.get('x-totalum-credits') ?? 0);
13
+ const audio = {
14
+ audio: await res.arrayBuffer(),
15
+ contentType: res.headers.get('content-type') ?? 'audio/mpeg',
16
+ usage: { credits },
17
+ };
18
+ return Object.defineProperty(audio, 'credits', {
19
+ enumerable: true,
20
+ get() {
21
+ deprecated('speech.synthesize().credits', 'speech.synthesize().usage.credits');
22
+ return credits;
23
+ },
24
+ });
25
+ }
7
26
  return {
8
- /** Speech to text from `audioBase64` or a `url`; optional language, word timestamps and speakers. */
27
+ /**
28
+ * Speech to text from `audioBase64` (+ `filename` with its extension) or a `url` — a public one, or a file this
29
+ * project stored; optional language, word timestamps and speakers.
30
+ */
9
31
  transcribe: (input) => call('POST', '/v1/speech/transcribe', input),
10
- /** The audio bytes, or with `store: true` the stored file `{key, url, usage}`; `credits` is the call's hold. */
11
- synthesize: async (input) => {
12
- if (input.store)
13
- return call('POST', '/v1/speech/speak', input);
14
- const res = await raw('/v1/speech/speak', input);
15
- return {
16
- audio: await res.arrayBuffer(),
17
- contentType: res.headers.get('content-type') ?? 'audio/mpeg',
18
- credits: Number(res.headers.get('x-totalum-credits') ?? 0),
19
- };
20
- },
32
+ synthesize,
21
33
  };
22
34
  }
@@ -0,0 +1,167 @@
1
+ import { Z as ZodObject, d as ZodString, c as ZodOptional, e as ZodArray, k as ZodNumber, f as ZodEnum, h as ZodRecord, n as ZodUnion, j as ZodBoolean, m as $strip, o as output, l as ZodInt, q as $partial, x as $strict, T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
2
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
3
+
4
+ /** `text` = the `embed` preset's space; `image` = the `embed-image` preset's text+image space. */
5
+ declare const VectorSpace: ZodEnum<{
6
+ text: "text";
7
+ image: "image";
8
+ }>;
9
+ type VectorSpace = output<typeof VectorSpace>;
10
+ /** ≤ 9 KiB as JSON (Vectorize keeps 10 KiB); keys starting with `_` are reserved. */
11
+ declare const VectorMetadata: ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodArray<ZodString>]>>;
12
+ type VectorMetadata = output<typeof VectorMetadata>;
13
+ declare const VectorUpsertItem: ZodObject<{
14
+ id: ZodString;
15
+ values: ZodOptional<ZodArray<ZodNumber>>;
16
+ text: ZodOptional<ZodString>;
17
+ image: ZodOptional<ZodString>;
18
+ space: ZodOptional<ZodEnum<{
19
+ text: "text";
20
+ image: "image";
21
+ }>>;
22
+ metadata: ZodOptional<ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodArray<ZodString>]>>>;
23
+ }, $strip>;
24
+ type VectorUpsertItem = output<typeof VectorUpsertItem>;
25
+ /** A Vectorize metadata filter on `VECTOR_FILTER_KEYS` only. */
26
+ declare const VectorFilter: ZodRecord<ZodEnum<{
27
+ type: "type";
28
+ source: "source";
29
+ page: "page";
30
+ tag: "tag";
31
+ group: "group";
32
+ }> & $partial, ZodUnion<readonly [ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>, ZodObject<{
33
+ $eq: ZodOptional<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
34
+ $ne: ZodOptional<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
35
+ $in: ZodOptional<ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>>;
36
+ $nin: ZodOptional<ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>>;
37
+ $lt: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
38
+ $lte: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
39
+ $gt: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
40
+ $gte: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
41
+ }, $strict>]>>;
42
+ type VectorFilter = output<typeof VectorFilter>;
43
+ /**
44
+ * `POST /v1/vectors/query`: one of `text`, `values` or `image`. `space: 'image'` searches the images (with `text`,
45
+ * the words are embedded by `embed-image`: image search by text); an `image` query is always in the image space.
46
+ */
47
+ declare const VectorsQueryInput: ZodObject<{
48
+ text: ZodOptional<ZodString>;
49
+ values: ZodOptional<ZodArray<ZodNumber>>;
50
+ image: ZodOptional<ZodString>;
51
+ space: ZodOptional<ZodEnum<{
52
+ text: "text";
53
+ image: "image";
54
+ }>>;
55
+ topK: ZodOptional<ZodInt>;
56
+ filter: ZodOptional<ZodRecord<ZodEnum<{
57
+ type: "type";
58
+ source: "source";
59
+ page: "page";
60
+ tag: "tag";
61
+ group: "group";
62
+ }> & $partial, ZodUnion<readonly [ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>, ZodObject<{
63
+ $eq: ZodOptional<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
64
+ $ne: ZodOptional<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>;
65
+ $in: ZodOptional<ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>>;
66
+ $nin: ZodOptional<ZodArray<ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean]>>>;
67
+ $lt: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
68
+ $lte: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
69
+ $gt: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
70
+ $gte: ZodOptional<ZodUnion<readonly [ZodNumber, ZodString]>>;
71
+ }, $strict>]>>>;
72
+ includeValues: ZodOptional<ZodBoolean>;
73
+ }, $strip>;
74
+ type VectorsQueryInput = output<typeof VectorsQueryInput>;
75
+ declare const VectorMatch: ZodObject<{
76
+ id: ZodString;
77
+ score: ZodNumber;
78
+ space: ZodEnum<{
79
+ text: "text";
80
+ image: "image";
81
+ }>;
82
+ metadata: ZodOptional<ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodArray<ZodString>]>>>;
83
+ values: ZodOptional<ZodArray<ZodNumber>>;
84
+ }, $strip>;
85
+ type VectorMatch = output<typeof VectorMatch>;
86
+ declare const VectorRecord: ZodObject<{
87
+ id: ZodString;
88
+ space: ZodEnum<{
89
+ text: "text";
90
+ image: "image";
91
+ }>;
92
+ values: ZodArray<ZodNumber>;
93
+ metadata: ZodOptional<ZodRecord<ZodString, ZodUnion<readonly [ZodString, ZodNumber, ZodBoolean, ZodArray<ZodString>]>>>;
94
+ }, $strip>;
95
+ type VectorRecord = output<typeof VectorRecord>;
96
+
97
+ /**
98
+ * `totalum.vectors` over `/v1/vectors/*` (scope `vectors`; server-side code only: it needs the project key). Every
99
+ * project environment has its own private vector store: ids, namespaces and indexes are Totalum's, never yours to
100
+ * name, and `x-totalum-env` (the `env` option) keeps dev and live apart. Vectors are 1,024 numbers; `text` is
101
+ * embedded with the `embed` model and `image` (a project file key, a files URL, an https URL or a data URL) with the
102
+ * `embed-image` model, whose space also embeds text: search images by words with `space: 'image'`. Filter on the
103
+ * metadata keys `source`, `type`, `tag`, `group` (strings) and `page` (number).
104
+ */
105
+ declare function totalumVectors(options?: TotalumClientOptions): {
106
+ /** Inserts or replaces up to 100 vectors (≤ 8 images) from `values`, `text` or `image`, with optional metadata. */
107
+ upsert: (vectors: VectorUpsertItem[]) => Promise<Omit<{
108
+ upserted: number;
109
+ count: number;
110
+ usage: {
111
+ credits: number;
112
+ vendor?: string | undefined;
113
+ units?: number | undefined;
114
+ vendorCostUsd?: number | undefined;
115
+ };
116
+ }, "usage"> & {
117
+ usage: {
118
+ vendor?: string | undefined;
119
+ units?: number | undefined;
120
+ credits: number;
121
+ };
122
+ }>;
123
+ /** The `topK` (≤ 50, default 5) closest vectors to `text`, `values` or `image`, with their metadata. */
124
+ query: (input: VectorsQueryInput) => Promise<{
125
+ matches: VectorMatch[];
126
+ } & {
127
+ usage: {
128
+ vendor?: string | undefined;
129
+ units?: number | undefined;
130
+ credits: number;
131
+ };
132
+ }>;
133
+ /** The stored vectors (values and metadata) of up to 100 ids; unknown ids are left out. */
134
+ get: (ids: string[]) => Promise<{
135
+ id: string;
136
+ space: "text" | "image";
137
+ values: number[];
138
+ metadata?: Record<string, string | number | boolean | string[]> | undefined;
139
+ }[]>;
140
+ /** Deletes up to 1,000 ids; answers how many existed and how many are left. */
141
+ delete: (ids: string[]) => Promise<Omit<{
142
+ deleted: number;
143
+ count: number;
144
+ usage: {
145
+ credits: number;
146
+ vendor?: string | undefined;
147
+ units?: number | undefined;
148
+ vendorCostUsd?: number | undefined;
149
+ };
150
+ }, "usage"> & {
151
+ usage: {
152
+ vendor?: string | undefined;
153
+ units?: number | undefined;
154
+ credits: number;
155
+ };
156
+ }>;
157
+ /** How many vectors this environment stores (free). */
158
+ count: () => Promise<{
159
+ count: number;
160
+ text: number;
161
+ image: number;
162
+ }>;
163
+ };
164
+ type TotalumVectors = ReturnType<typeof totalumVectors>;
165
+
166
+ export { TotalumClientOptions, VectorFilter, VectorMatch, VectorMetadata, VectorRecord, VectorSpace, VectorUpsertItem, VectorsQueryInput, totalumVectors };
167
+ export type { TotalumVectors };
@@ -0,0 +1,28 @@
1
+ import { envelopeClient, jsonClient, withUsage } from '../http.js';
2
+ export { TotalumError, isTotalumError } from '../errors.js';
3
+ /**
4
+ * `totalum.vectors` over `/v1/vectors/*` (scope `vectors`; server-side code only: it needs the project key). Every
5
+ * project environment has its own private vector store: ids, namespaces and indexes are Totalum's, never yours to
6
+ * name, and `x-totalum-env` (the `env` option) keeps dev and live apart. Vectors are 1,024 numbers; `text` is
7
+ * embedded with the `embed` model and `image` (a project file key, a files URL, an https URL or a data URL) with the
8
+ * `embed-image` model, whose space also embeds text: search images by words with `space: 'image'`. Filter on the
9
+ * metadata keys `source`, `type`, `tag`, `group` (strings) and `page` (number).
10
+ */
11
+ export function totalumVectors(options = {}) {
12
+ const call = envelopeClient(options);
13
+ const data = jsonClient(options);
14
+ return {
15
+ /** Inserts or replaces up to 100 vectors (≤ 8 images) from `values`, `text` or `image`, with optional metadata. */
16
+ upsert: async (vectors) => withUsage(await call('POST', '/v1/vectors/upsert', {
17
+ vectors,
18
+ })),
19
+ /** The `topK` (≤ 50, default 5) closest vectors to `text`, `values` or `image`, with their metadata. */
20
+ query: async (input) => withUsage(await call('POST', '/v1/vectors/query', input)),
21
+ /** The stored vectors (values and metadata) of up to 100 ids; unknown ids are left out. */
22
+ get: async (ids) => (await data('POST', '/v1/vectors/get', { ids })).vectors,
23
+ /** Deletes up to 1,000 ids; answers how many existed and how many are left. */
24
+ delete: async (ids) => withUsage(await call('POST', '/v1/vectors/delete', { ids })),
25
+ /** How many vectors this environment stores (free). */
26
+ count: () => data('GET', '/v1/vectors/count'),
27
+ };
28
+ }
@@ -1,12 +1,12 @@
1
- import { G as WebScrapeInput, H as WebSearchInput, I as WebMapInput, K as WebCrawlInput, u as ScreenshotInput } from '../_types/integrations.d-BKPWost0.js';
2
- export { J as JobCreated, v as ScreenshotOutput, W as WebJob, B as WebScrapeOutput, D as WebSearchOutput } from '../_types/integrations.d-BKPWost0.js';
3
- import { T as TotalumClientOptions } from '../_types/errors.d-yrue1e9O.js';
4
- export { a as TotalumError, i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
5
- import '../_types/coerce.d-RtY2zQyw.js';
1
+ import { G as WebScrapeInput, H as WebSearchInput, I as WebMapInput, K as WebCrawlInput, u as ScreenshotInput } from '../_types/integrations.d-DjOeFaYn.js';
2
+ export { J as JobCreated, v as ScreenshotOutput, W as WebJob, B as WebScrapeOutput, D as WebSearchOutput } from '../_types/integrations.d-DjOeFaYn.js';
3
+ import { T as TotalumClientOptions } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { a as TotalumError, b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
+ import '../_types/coerce.d-BXj_o-j6.js';
6
6
 
7
7
  /**
8
8
  * `totalum.web` (plan 05 §6.2) over SDK-API `/v1/web/*` (scope `web`): Firecrawl scrape/search/map/crawl and Browser
9
- * Run screenshots, charged provider cost × 28 — every result carries `usage.credits`.
9
+ * Run screenshots, charged provider cost × 4 / $0.07 — every result carries `usage.credits`.
10
10
  */
11
11
  declare function totalumWeb(options?: TotalumClientOptions): {
12
12
  /**
package/dist/web/index.js CHANGED
@@ -2,7 +2,7 @@ import { envelopeClient, withUsage } from '../http.js';
2
2
  export { TotalumError, isTotalumError } from '../errors.js';
3
3
  /**
4
4
  * `totalum.web` (plan 05 §6.2) over SDK-API `/v1/web/*` (scope `web`): Firecrawl scrape/search/map/crawl and Browser
5
- * Run screenshots, charged provider cost × 28 — every result carries `usage.credits`.
5
+ * Run screenshots, charged provider cost × 4 / $0.07 — every result carries `usage.credits`.
6
6
  */
7
7
  export function totalumWeb(options = {}) {
8
8
  const call = envelopeClient(options);
@@ -1,7 +1,7 @@
1
- import { a as WebhookEvent } from '../_types/billing.d-C1exPLN6.js';
2
- export { W as WebhookConfig, b as WebhookSecretOutput } from '../_types/billing.d-C1exPLN6.js';
3
- import { T as TotalumClientOptions, a as TotalumError } from '../_types/errors.d-yrue1e9O.js';
4
- export { i as isTotalumError } from '../_types/errors.d-yrue1e9O.js';
1
+ import { a as WebhookEvent } from '../_types/billing.d-BcRcDH4Y.js';
2
+ export { W as WebhookConfig, b as WebhookSecretOutput } from '../_types/billing.d-BcRcDH4Y.js';
3
+ import { T as TotalumClientOptions, a as TotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
4
+ export { b as TotalumErrorCode, i as isTotalumError } from '../_types/errors.d-Dtt-BIwJ.js';
5
5
 
6
6
  /** A webhook refusal (plan 05 §7.2): the codes never travel, the app answers 400. */
7
7
  declare class TotalumWebhookError extends TotalumError {