@tarkahq/sdk 0.0.0-stage → 0.3.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 (130) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +69 -0
  3. package/README.md +700 -2
  4. package/api-source.json +38 -0
  5. package/dist/cjs/client.d.ts +114 -0
  6. package/dist/cjs/client.js +174 -0
  7. package/dist/cjs/errors.d.ts +27 -0
  8. package/dist/cjs/errors.js +78 -0
  9. package/dist/cjs/generated/google/api/annotations.d.ts +1 -0
  10. package/dist/cjs/generated/google/api/annotations.js +10 -0
  11. package/dist/cjs/generated/google/api/http.d.ts +395 -0
  12. package/dist/cjs/generated/google/api/http.js +421 -0
  13. package/dist/cjs/generated/google/protobuf/descriptor.d.ts +873 -0
  14. package/dist/cjs/generated/google/protobuf/descriptor.js +3992 -0
  15. package/dist/cjs/generated/google/protobuf/empty.d.ts +35 -0
  16. package/dist/cjs/generated/google/protobuf/empty.js +58 -0
  17. package/dist/cjs/generated/google/protobuf/struct.d.ts +127 -0
  18. package/dist/cjs/generated/google/protobuf/struct.js +529 -0
  19. package/dist/cjs/generated/google/protobuf/timestamp.d.ts +128 -0
  20. package/dist/cjs/generated/google/protobuf/timestamp.js +95 -0
  21. package/dist/cjs/generated/protoc-gen-openapiv2/options/annotations.d.ts +1 -0
  22. package/dist/cjs/generated/protoc-gen-openapiv2/options/annotations.js +10 -0
  23. package/dist/cjs/generated/protoc-gen-openapiv2/options/openapiv2.d.ts +983 -0
  24. package/dist/cjs/generated/protoc-gen-openapiv2/options/openapiv2.js +4874 -0
  25. package/dist/cjs/generated/tarka/access/v1/access.d.ts +322 -0
  26. package/dist/cjs/generated/tarka/access/v1/access.js +2979 -0
  27. package/dist/cjs/generated/tarka/channels/v1/channels.d.ts +370 -0
  28. package/dist/cjs/generated/tarka/channels/v1/channels.js +3603 -0
  29. package/dist/cjs/generated/tarka/gateway/v1/gateway.d.ts +804 -0
  30. package/dist/cjs/generated/tarka/gateway/v1/gateway.js +8081 -0
  31. package/dist/cjs/generated/tarka/iam/v1/iam.d.ts +1291 -0
  32. package/dist/cjs/generated/tarka/iam/v1/iam.js +13207 -0
  33. package/dist/cjs/generated/tarka/inference/v1/inference.d.ts +699 -0
  34. package/dist/cjs/generated/tarka/inference/v1/inference.js +7058 -0
  35. package/dist/cjs/generated/tarka/provisioning/v1/agent_secrets.d.ts +70 -0
  36. package/dist/cjs/generated/tarka/provisioning/v1/agent_secrets.js +603 -0
  37. package/dist/cjs/generated/tarka/provisioning/v1/billing_quote.d.ts +171 -0
  38. package/dist/cjs/generated/tarka/provisioning/v1/billing_quote.js +1588 -0
  39. package/dist/cjs/generated/tarka/provisioning/v1/job.d.ts +168 -0
  40. package/dist/cjs/generated/tarka/provisioning/v1/job.js +1505 -0
  41. package/dist/cjs/generated/tarka/provisioning/v1/provisioning.d.ts +2644 -0
  42. package/dist/cjs/generated/tarka/provisioning/v1/provisioning.js +19501 -0
  43. package/dist/cjs/generated/tarka/provisioning/v1/registry_credentials.d.ts +89 -0
  44. package/dist/cjs/generated/tarka/provisioning/v1/registry_credentials.js +856 -0
  45. package/dist/cjs/generated/tarka/provisioning/v1/sandbox.d.ts +431 -0
  46. package/dist/cjs/generated/tarka/provisioning/v1/sandbox.js +3203 -0
  47. package/dist/cjs/generated/tarka/provisioning/v1/source_builds.d.ts +291 -0
  48. package/dist/cjs/generated/tarka/provisioning/v1/source_builds.js +3920 -0
  49. package/dist/cjs/grpc.d.ts +12 -0
  50. package/dist/cjs/grpc.js +55 -0
  51. package/dist/cjs/index.d.ts +6 -0
  52. package/dist/cjs/index.js +21 -0
  53. package/dist/cjs/package.json +1 -0
  54. package/dist/cjs/resources/inference.d.ts +293 -0
  55. package/dist/cjs/resources/inference.js +451 -0
  56. package/dist/cjs/resources/provisioning.d.ts +389 -0
  57. package/dist/cjs/resources/provisioning.js +552 -0
  58. package/dist/cjs/resources/sandboxes.d.ts +360 -0
  59. package/dist/cjs/resources/sandboxes.js +732 -0
  60. package/dist/cjs/rpc-types.d.ts +36 -0
  61. package/dist/cjs/rpc-types.js +29 -0
  62. package/dist/cjs/runtime.d.ts +99 -0
  63. package/dist/cjs/runtime.js +473 -0
  64. package/dist/cjs/transport.d.ts +60 -0
  65. package/dist/cjs/transport.js +114 -0
  66. package/dist/cjs/types.d.ts +309 -0
  67. package/dist/cjs/types.js +2 -0
  68. package/dist/esm/client.d.ts +114 -0
  69. package/dist/esm/client.js +169 -0
  70. package/dist/esm/errors.d.ts +27 -0
  71. package/dist/esm/errors.js +71 -0
  72. package/dist/esm/generated/google/api/annotations.d.ts +1 -0
  73. package/dist/esm/generated/google/api/annotations.js +7 -0
  74. package/dist/esm/generated/google/api/http.d.ts +395 -0
  75. package/dist/esm/generated/google/api/http.js +418 -0
  76. package/dist/esm/generated/google/protobuf/descriptor.d.ts +873 -0
  77. package/dist/esm/generated/google/protobuf/descriptor.js +3977 -0
  78. package/dist/esm/generated/google/protobuf/empty.d.ts +35 -0
  79. package/dist/esm/generated/google/protobuf/empty.js +55 -0
  80. package/dist/esm/generated/google/protobuf/struct.d.ts +127 -0
  81. package/dist/esm/generated/google/protobuf/struct.js +524 -0
  82. package/dist/esm/generated/google/protobuf/timestamp.d.ts +128 -0
  83. package/dist/esm/generated/google/protobuf/timestamp.js +92 -0
  84. package/dist/esm/generated/protoc-gen-openapiv2/options/annotations.d.ts +1 -0
  85. package/dist/esm/generated/protoc-gen-openapiv2/options/annotations.js +7 -0
  86. package/dist/esm/generated/protoc-gen-openapiv2/options/openapiv2.d.ts +983 -0
  87. package/dist/esm/generated/protoc-gen-openapiv2/options/openapiv2.js +4859 -0
  88. package/dist/esm/generated/tarka/access/v1/access.d.ts +322 -0
  89. package/dist/esm/generated/tarka/access/v1/access.js +2976 -0
  90. package/dist/esm/generated/tarka/channels/v1/channels.d.ts +370 -0
  91. package/dist/esm/generated/tarka/channels/v1/channels.js +3600 -0
  92. package/dist/esm/generated/tarka/gateway/v1/gateway.d.ts +804 -0
  93. package/dist/esm/generated/tarka/gateway/v1/gateway.js +8077 -0
  94. package/dist/esm/generated/tarka/iam/v1/iam.d.ts +1291 -0
  95. package/dist/esm/generated/tarka/iam/v1/iam.js +13203 -0
  96. package/dist/esm/generated/tarka/inference/v1/inference.d.ts +699 -0
  97. package/dist/esm/generated/tarka/inference/v1/inference.js +7055 -0
  98. package/dist/esm/generated/tarka/provisioning/v1/agent_secrets.d.ts +70 -0
  99. package/dist/esm/generated/tarka/provisioning/v1/agent_secrets.js +600 -0
  100. package/dist/esm/generated/tarka/provisioning/v1/billing_quote.d.ts +171 -0
  101. package/dist/esm/generated/tarka/provisioning/v1/billing_quote.js +1585 -0
  102. package/dist/esm/generated/tarka/provisioning/v1/job.d.ts +168 -0
  103. package/dist/esm/generated/tarka/provisioning/v1/job.js +1500 -0
  104. package/dist/esm/generated/tarka/provisioning/v1/provisioning.d.ts +2644 -0
  105. package/dist/esm/generated/tarka/provisioning/v1/provisioning.js +19496 -0
  106. package/dist/esm/generated/tarka/provisioning/v1/registry_credentials.d.ts +89 -0
  107. package/dist/esm/generated/tarka/provisioning/v1/registry_credentials.js +853 -0
  108. package/dist/esm/generated/tarka/provisioning/v1/sandbox.d.ts +431 -0
  109. package/dist/esm/generated/tarka/provisioning/v1/sandbox.js +3192 -0
  110. package/dist/esm/generated/tarka/provisioning/v1/source_builds.d.ts +291 -0
  111. package/dist/esm/generated/tarka/provisioning/v1/source_builds.js +3917 -0
  112. package/dist/esm/grpc.d.ts +12 -0
  113. package/dist/esm/grpc.js +11 -0
  114. package/dist/esm/index.d.ts +6 -0
  115. package/dist/esm/index.js +4 -0
  116. package/dist/esm/resources/inference.d.ts +293 -0
  117. package/dist/esm/resources/inference.js +437 -0
  118. package/dist/esm/resources/provisioning.d.ts +389 -0
  119. package/dist/esm/resources/provisioning.js +531 -0
  120. package/dist/esm/resources/sandboxes.d.ts +360 -0
  121. package/dist/esm/resources/sandboxes.js +718 -0
  122. package/dist/esm/rpc-types.d.ts +36 -0
  123. package/dist/esm/rpc-types.js +26 -0
  124. package/dist/esm/runtime.d.ts +99 -0
  125. package/dist/esm/runtime.js +466 -0
  126. package/dist/esm/transport.d.ts +60 -0
  127. package/dist/esm/transport.js +110 -0
  128. package/dist/esm/types.d.ts +309 -0
  129. package/dist/esm/types.js +1 -0
  130. package/package.json +155 -4
@@ -0,0 +1,437 @@
1
+ import { required, requireText, TarkaError } from "../errors.js";
2
+ function chatRequest(input, stream) {
3
+ requireText(input?.model, "model");
4
+ const { prompt, system, messages, ...settings } = input;
5
+ if (prompt !== undefined) {
6
+ if (typeof prompt !== "string" ||
7
+ messages !== undefined ||
8
+ (system !== undefined && typeof system !== "string")) {
9
+ throw new TypeError("Provide a text prompt with an optional system instruction, or messages");
10
+ }
11
+ return {
12
+ ...settings,
13
+ stream,
14
+ messages: [
15
+ ...(system === undefined ? [] : [{ role: "system", content: system }]),
16
+ { role: "user", content: prompt },
17
+ ],
18
+ };
19
+ }
20
+ if (!Array.isArray(messages) || !messages.length || system !== undefined) {
21
+ throw new TypeError("Provide a prompt or a non-empty messages array");
22
+ }
23
+ for (const message of messages)
24
+ requireText(message.role, "message.role");
25
+ return { ...settings, stream, messages };
26
+ }
27
+ /** Inference model discovery. Access through `client.models`. */
28
+ export class Models {
29
+ #rpc;
30
+ constructor(rpc) {
31
+ this.#rpc = rpc;
32
+ }
33
+ /**
34
+ * List the models visible to your inference credential.
35
+ *
36
+ * @returns Model records directly as an array.
37
+ * @example
38
+ * const models = await client.models.list();
39
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
40
+ */
41
+ async list(options) {
42
+ return (await this.#rpc.listModels(options)).data;
43
+ }
44
+ /**
45
+ * Retrieve one inference model.
46
+ *
47
+ * @param id - Model identifier or alias returned by `models.list()`.
48
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
49
+ */
50
+ async get(id, options) {
51
+ requireText(id, "model id");
52
+ return this.#rpc.retrieveModel({ model: id }, options);
53
+ }
54
+ }
55
+ /** Control plane model catalog, including provisioning information. Access through `client.catalog`. */
56
+ export class Catalog {
57
+ #rpc;
58
+ constructor(rpc) {
59
+ this.#rpc = rpc;
60
+ }
61
+ /**
62
+ * List catalog models, optionally filtered by modality.
63
+ *
64
+ * @param filter - Optional modality filter. Pass `undefined` when supplying only request settings.
65
+ * @returns Catalog records directly as an array; inference discovery is available through `client.models`.
66
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
67
+ */
68
+ async list(filter = {}, options) {
69
+ return (await this.#rpc.listModels(filter, options)).models;
70
+ }
71
+ }
72
+ /** OpenAI-compatible JSON chat. Access through `client.chat.json` when you need fields outside the typed chat API. */
73
+ export class JsonChat {
74
+ #rpc;
75
+ constructor(rpc) {
76
+ this.#rpc = rpc;
77
+ }
78
+ /**
79
+ * Create a chat completion from an OpenAI-compatible JSON body.
80
+ *
81
+ * @param body - Ordinary JSON with OpenAI field names, such as `max_tokens`. The SDK sets `stream: false`.
82
+ * @returns The response body directly, without a `body` envelope.
83
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
84
+ */
85
+ async create(body, options) {
86
+ return required((await this.#rpc.createOpenAIChatCompletion({ body: { ...body, stream: false } }, options)).body, "body");
87
+ }
88
+ /**
89
+ * Stream OpenAI-compatible JSON chat events.
90
+ *
91
+ * @param body - Ordinary JSON with OpenAI field names. The SDK sets `stream: true`.
92
+ * @returns A lazy iterable of `{ type, data }` events. Breaking iteration cancels the RPC.
93
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
94
+ */
95
+ async *stream(body, options) {
96
+ for await (const event of this.#rpc.streamOpenAIChatCompletion({ body: { ...body, stream: true } }, options)) {
97
+ yield { type: event.type, data: required(event.data, "data") };
98
+ }
99
+ }
100
+ }
101
+ /** Typed chat completions and text helpers. Access through `client.chat`. */
102
+ export class Chat {
103
+ #rpc;
104
+ /** OpenAI-compatible JSON requests and events for fields outside the typed chat API. */
105
+ json;
106
+ constructor(rpc) {
107
+ this.#rpc = rpc;
108
+ this.json = new JsonChat(rpc);
109
+ }
110
+ /**
111
+ * Generate a full chat completion, including usage and tool calls.
112
+ *
113
+ * @param input - Model and either a text `prompt` with optional `system`, or a non-empty `messages` array.
114
+ * @returns The complete response. Use `text()` when you only need the first choice's text.
115
+ * @example
116
+ * const completion = await client.chat.create({ model, prompt: "Hello" });
117
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
118
+ */
119
+ async create(input, options) {
120
+ return this.#rpc.createChatCompletion(chatRequest(input, false), options);
121
+ }
122
+ /**
123
+ * Stream full chat chunks, including tool-call deltas and usage when provided.
124
+ *
125
+ * @param input - Model and a prompt or messages. Streaming is selected by this method.
126
+ * @returns A lazy iterable. Breaking iteration cancels the RPC; timeouts cover the whole stream.
127
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
128
+ */
129
+ async *stream(input, options) {
130
+ yield* this.#rpc.streamChatCompletion(chatRequest(input, true), options);
131
+ }
132
+ /**
133
+ * Generate the text from choice 0 of a chat completion.
134
+ *
135
+ * @param input - Model and either a text `prompt` with optional `system`, or a non-empty `messages` array.
136
+ * @throws TarkaError with `failed_precondition` if choice 0 has no text. Use `create()` for tool calls or full results.
137
+ * @example
138
+ * const text = await client.chat.text({ model, prompt: "Say hello" });
139
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
140
+ */
141
+ async text(input, options) {
142
+ const result = await this.create(input, options);
143
+ const content = result.choices.find((choice) => choice.index === 0)?.message
144
+ ?.content;
145
+ if (typeof content !== "string")
146
+ throw new TarkaError("The first choice did not contain text; use chat.create() to inspect the full completion", "failed_precondition");
147
+ return content;
148
+ }
149
+ /**
150
+ * Stream only non-empty text deltas from choice 0.
151
+ *
152
+ * Tool-call deltas and usage-only chunks are omitted. Use `stream()` to receive complete chunks.
153
+ * @param input - Model and a prompt or messages.
154
+ * @returns A lazy iterable of strings; breaking iteration cancels the RPC.
155
+ * @example
156
+ * for await (const text of client.chat.streamText({ model, prompt: "Hello" })) {
157
+ * process.stdout.write(text);
158
+ * }
159
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
160
+ */
161
+ async *streamText(input, options) {
162
+ for await (const chunk of this.stream(input, options)) {
163
+ const text = chunk.choices.find((choice) => choice.index === 0)?.delta
164
+ ?.content;
165
+ if (typeof text === "string" && text.length)
166
+ yield text;
167
+ }
168
+ }
169
+ }
170
+ /** OpenAI-compatible Responses API with unwrapped JSON results. Access through `client.responses`. */
171
+ export class Responses {
172
+ #rpc;
173
+ constructor(rpc) {
174
+ this.#rpc = rpc;
175
+ }
176
+ /**
177
+ * Create a response and return its JSON body directly.
178
+ *
179
+ * @param body - OpenAI-compatible JSON with original field names. The SDK sets `stream: false`.
180
+ * @example
181
+ * const response = await client.responses.create({ model, input: "Hello" });
182
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
183
+ */
184
+ async create(body, options) {
185
+ return required((await this.#rpc.createResponse({ body: { ...body, stream: false } }, options)).body, "body");
186
+ }
187
+ /**
188
+ * Stream response events as `{ type, data }`.
189
+ *
190
+ * @param body - OpenAI-compatible JSON. The SDK sets `stream: true`.
191
+ * @returns A lazy iterable. Breaking iteration cancels the RPC; a partial stream is never automatically replayed.
192
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
193
+ */
194
+ async *stream(body, options) {
195
+ for await (const event of this.#rpc.streamResponse({ body: { ...body, stream: true } }, options)) {
196
+ yield { type: event.type, data: required(event.data, "data") };
197
+ }
198
+ }
199
+ /**
200
+ * Retrieve the JSON body of a stored response.
201
+ *
202
+ * @param id - Response identifier returned by creation.
203
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
204
+ */
205
+ async get(id, options) {
206
+ requireText(id, "response id");
207
+ return required((await this.#rpc.retrieveResponse({ responseId: id }, options)).body, "body");
208
+ }
209
+ /**
210
+ * Request cancellation of a response.
211
+ *
212
+ * @param id - Response identifier.
213
+ * @returns The updated response body.
214
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
215
+ */
216
+ async cancel(id, options) {
217
+ requireText(id, "response id");
218
+ return required((await this.#rpc.cancelResponse({ responseId: id }, options)).body, "body");
219
+ }
220
+ /**
221
+ * Delete a stored response.
222
+ *
223
+ * @param id - Response identifier.
224
+ * @returns Resolves without a value after the server acknowledges deletion.
225
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
226
+ */
227
+ async delete(id, options) {
228
+ requireText(id, "response id");
229
+ await this.#rpc.deleteResponse({ responseId: id }, options);
230
+ }
231
+ }
232
+ /** Image text recognition and streaming. Access through `client.ocr`. */
233
+ export class Ocr {
234
+ #rpc;
235
+ constructor(rpc) {
236
+ this.#rpc = rpc;
237
+ }
238
+ request(input, stream) {
239
+ requireText(input?.model, "model");
240
+ if (input.image !== undefined) {
241
+ requireText(input.image, "image");
242
+ if (input.images !== undefined)
243
+ throw new TypeError("Provide image or images, not both");
244
+ }
245
+ else {
246
+ if (!Array.isArray(input.images) || !input.images.length)
247
+ throw new TypeError("images must not be empty");
248
+ for (const image of input.images)
249
+ requireText(image, "image");
250
+ }
251
+ return { ...input, stream };
252
+ }
253
+ /**
254
+ * Recognize text and return the full OCR result.
255
+ *
256
+ * @param input - OCR model and either one `image` or a non-empty `images` array, in a format supported by the model.
257
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
258
+ */
259
+ async create(input, options) {
260
+ return this.#rpc.createOCR(this.request(input, false), options);
261
+ }
262
+ /**
263
+ * Recognize text and return only the result's `text` field.
264
+ *
265
+ * @param input - OCR model and either `image` or `images`.
266
+ * @example
267
+ * const text = await client.ocr.text({ model, image: imageUrl });
268
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
269
+ */
270
+ async text(input, options) {
271
+ return (await this.create(input, options)).text;
272
+ }
273
+ /**
274
+ * Stream full OCR chunks.
275
+ *
276
+ * @param input - OCR model and either `image` or `images`.
277
+ * @returns A lazy iterable. Breaking iteration cancels the RPC.
278
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
279
+ */
280
+ async *stream(input, options) {
281
+ yield* this.#rpc.streamOCR(this.request(input, true), options);
282
+ }
283
+ /**
284
+ * Stream non-empty text fields from OCR chunks.
285
+ *
286
+ * @param input - OCR model and either `image` or `images`.
287
+ * @returns Text chunks in server order. Use `stream()` for the other result fields.
288
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
289
+ */
290
+ async *streamText(input, options) {
291
+ for await (const chunk of this.stream(input, options))
292
+ if (chunk.text)
293
+ yield chunk.text;
294
+ }
295
+ }
296
+ /** Speech-to-text transcription. Access through `client.audio.transcriptions`. */
297
+ export class Transcriptions {
298
+ #rpc;
299
+ constructor(rpc) {
300
+ this.#rpc = rpc;
301
+ }
302
+ /**
303
+ * Transcribe audio and return the full text response, including metadata when provided.
304
+ *
305
+ * @param input - Transcription model, audio bytes as a Buffer, and optional filename, content type, and model settings.
306
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
307
+ */
308
+ async create(input, options) {
309
+ return this.#rpc.createTranscription(input, options);
310
+ }
311
+ /**
312
+ * Transcribe audio and return only the recognized text.
313
+ *
314
+ * @param input - Transcription model and audio bytes as a Buffer.
315
+ * @example
316
+ * const text = await client.audio.transcriptions.text({ model, file: audioBuffer });
317
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
318
+ */
319
+ async text(input, options) {
320
+ return (await this.create(input, options)).text;
321
+ }
322
+ }
323
+ /** Audio translation. Access through `client.audio.translations`. */
324
+ export class Translations {
325
+ #rpc;
326
+ constructor(rpc) {
327
+ this.#rpc = rpc;
328
+ }
329
+ /**
330
+ * Translate audio and return the full text response.
331
+ *
332
+ * @param input - Translation model, audio bytes as a Buffer, and optional file metadata and model settings.
333
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
334
+ */
335
+ async create(input, options) {
336
+ return this.#rpc.createTranslation(input, options);
337
+ }
338
+ /**
339
+ * Translate audio and return only the translated text.
340
+ *
341
+ * @param input - Translation model and audio bytes as a Buffer.
342
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
343
+ */
344
+ async text(input, options) {
345
+ return (await this.create(input, options)).text;
346
+ }
347
+ }
348
+ /** Speech generation as a collected Buffer or a stream. Access through `client.audio.speech`. */
349
+ export class Speech {
350
+ #rpc;
351
+ constructor(rpc) {
352
+ this.#rpc = rpc;
353
+ }
354
+ /**
355
+ * Generate speech as a stream of audio chunks.
356
+ *
357
+ * @param input - Speech model, text in `input`, and optional voice and output settings.
358
+ * @returns A lazy iterable of `{ data: Buffer, contentType }`. Breaking iteration cancels the RPC.
359
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
360
+ */
361
+ async *stream(input, options) {
362
+ yield* this.#rpc.createSpeech(input, options);
363
+ }
364
+ /**
365
+ * Generate speech and collect all audio into one Buffer.
366
+ *
367
+ * @param input - Speech model, text in `input`, and optional voice and output settings.
368
+ * @returns `{ data: Buffer, contentType }`. Use `stream()` to avoid buffering a large response.
369
+ * @example
370
+ * const audio = await client.audio.speech.create({ model, input: "Hello" });
371
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
372
+ */
373
+ async create(input, options) {
374
+ const chunks = [];
375
+ let contentType = "";
376
+ for await (const chunk of this.stream(input, options)) {
377
+ chunks.push(chunk.data);
378
+ contentType = chunk.contentType || contentType;
379
+ }
380
+ return { data: Buffer.concat(chunks), contentType };
381
+ }
382
+ }
383
+ /** Voice cloning with explicit consent metadata. Access through `client.audio.voices`. */
384
+ export class Voices {
385
+ #rpc;
386
+ constructor(rpc) {
387
+ this.#rpc = rpc;
388
+ }
389
+ /**
390
+ * Create a voice clone from an audio sample and consent information.
391
+ *
392
+ * @param input - Model, voice name, sample Buffer, consent signer and date, plus optional file metadata.
393
+ * @returns The created voice record; inspect its `status` for the server-reported state.
394
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
395
+ */
396
+ async create(input, options) {
397
+ return this.#rpc.createVoiceClone(input, options);
398
+ }
399
+ /**
400
+ * Retrieve a voice clone and its current state.
401
+ *
402
+ * @param id - Voice identifier.
403
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
404
+ */
405
+ async get(id, options) {
406
+ requireText(id, "voice id");
407
+ return this.#rpc.getVoiceClone({ voiceId: id }, options);
408
+ }
409
+ /**
410
+ * Delete a voice clone.
411
+ *
412
+ * @param id - Voice identifier.
413
+ * @returns Resolves without a value after acknowledgement.
414
+ * @param options - Per-call timeout in milliseconds, cancellation signal, and metadata.
415
+ */
416
+ async delete(id, options) {
417
+ requireText(id, "voice id");
418
+ await this.#rpc.deleteVoiceClone({ voiceId: id }, options);
419
+ }
420
+ }
421
+ /** Audio transcription, translation, generation, and voice cloning. Access through `client.audio`. */
422
+ export class Audio {
423
+ /** Transcribe audio into text, with full-result and text-only methods. */
424
+ transcriptions;
425
+ /** Translate audio into text, with full-result and text-only methods. */
426
+ translations;
427
+ /** Generate audio as a collected Buffer or a stream of chunks. */
428
+ speech;
429
+ /** Create, retrieve, and delete voice clones. */
430
+ voices;
431
+ constructor(rpc) {
432
+ this.transcriptions = new Transcriptions(rpc);
433
+ this.translations = new Translations(rpc);
434
+ this.speech = new Speech(rpc);
435
+ this.voices = new Voices(rpc);
436
+ }
437
+ }