@fazpi-ai/sdk 0.2.0 → 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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @fazpi-ai/sdk
2
2
 
3
- TypeScript and JavaScript client for Node.js 20+. Version 0.2.0. No browser SDK or UI.
3
+ TypeScript and JavaScript client for Node.js 20+. Version 0.3.0. No browser SDK or UI.
4
4
 
5
5
  ```js
6
6
  import { Fazpi } from '@fazpi-ai/sdk';
@@ -13,7 +13,7 @@ for await (const event of client.runs.stream(run.id)) {
13
13
  }
14
14
  ```
15
15
 
16
- Install with `npm install @fazpi-ai/sdk@0.2.0` or `pnpm add @fazpi-ai/sdk@0.2.0`. For the deployed API, use base URL `https://api.fazpi.ai/v2/api/v1`. Applications import the package by name; source-checkout examples use the local build.
16
+ Install with `npm install @fazpi-ai/sdk@0.3.0` or `pnpm add @fazpi-ai/sdk@0.3.0`. For the deployed API, use base URL `https://api.fazpi.ai/v2/api/v1`. Applications import the package by name; source-checkout examples use the local build.
17
17
 
18
18
  Persist `conversation.id` and retrieve it in another process to continue without resending history. Both Go and Node clients use the same conversation IDs. For a group, use target type `group`.
19
19
 
@@ -27,7 +27,7 @@ Errors are typed: `APIError` includes status, code and requestID; `TransportErro
27
27
 
28
28
  See the repository root README and `RELEASING.md` for runnable Go/Node examples, tests, local API setup, limitations and verification evidence. The SDK is backend-only and requires an authorized Fazpi integration key.
29
29
 
30
- ## PDF attachments (0.2.0)
30
+ ## PDF attachments (0.3.0)
31
31
 
32
32
  Send `files: [{ name: "documento.pdf", content_base64: pdf.toString("base64") }]`
33
33
  with `conversations.messages.create`. Up to five PDFs, 10 MiB per PDF and 20 MiB
package/dist/client.d.ts CHANGED
@@ -11,8 +11,15 @@ declare class Messages {
11
11
  create(conversationID: string, body: CreateMessage, options?: RequestOptions): Promise<Run>;
12
12
  list(conversationID: string, params?: MessageListParams, options?: RequestOptions): Promise<MessagePage>;
13
13
  }
14
+ declare class Files {
15
+ private readonly transport;
16
+ constructor(transport: Transport);
17
+ /** Download a published output file as bounded bytes; credentials stay on the backend. */
18
+ download(conversationID: string, fileID: string, options?: RequestOptions): Promise<Uint8Array>;
19
+ }
14
20
  declare class Conversations {
15
21
  private readonly transport;
22
+ readonly files: Files;
16
23
  readonly messages: Messages;
17
24
  constructor(transport: Transport);
18
25
  create(body: CreateConversation, options?: RequestOptions): Promise<Conversation>;
package/dist/client.js CHANGED
@@ -19,12 +19,24 @@ class Messages {
19
19
  return this.transport.request('GET', path, undefined, options, true, query);
20
20
  }
21
21
  }
22
+ class Files {
23
+ transport;
24
+ constructor(transport) {
25
+ this.transport = transport;
26
+ }
27
+ /** Download a published output file as bounded bytes; credentials stay on the backend. */
28
+ download(conversationID, fileID, options) {
29
+ return this.transport.request('GET', `/conversations/${resourceID(conversationID)}/files/${resourceID(fileID)}`, undefined, options, true, undefined, false, true);
30
+ }
31
+ }
22
32
  class Conversations {
23
33
  transport;
34
+ files;
24
35
  messages;
25
36
  constructor(transport) {
26
37
  this.transport = transport;
27
38
  this.messages = new Messages(transport);
39
+ this.files = new Files(transport);
28
40
  }
29
41
  create(body, options = {}) {
30
42
  return this.transport.request('POST', '/conversations', body, { ...options, idempotencyKey: operationKey(options.idempotencyKey) });
@@ -28,5 +28,5 @@ export declare class Transport {
28
28
  private readonly credential;
29
29
  private readonly fetcher;
30
30
  constructor(options: ClientOptions);
31
- request<T>(method: string, path: string, body: unknown, options?: RequestOptions, safe?: boolean, query?: URLSearchParams, stream?: boolean): Promise<T>;
31
+ request<T>(method: string, path: string, body: unknown, options?: RequestOptions, safe?: boolean, query?: URLSearchParams, stream?: boolean, binary?: boolean): Promise<T>;
32
32
  }
package/dist/transport.js CHANGED
@@ -119,7 +119,7 @@ export class Transport {
119
119
  this.maxRetries = integer(options.maxRetries ?? 2, 0, 5, 'maxRetries');
120
120
  this.maxResponseBytes = integer(options.maxResponseBytes ?? 8 * 1024 * 1024, 1, 64 * 1024 * 1024, 'maxResponseBytes');
121
121
  }
122
- async request(method, path, body, options = {}, safe = method === 'GET', query, stream = false) {
122
+ async request(method, path, body, options = {}, safe = method === 'GET', query, stream = false, binary = false) {
123
123
  const timeout = integer(options.timeoutMs ?? this.timeoutMs, 1, 3_600_000, 'timeoutMs');
124
124
  const retries = integer(options.maxRetries ?? this.maxRetries, 0, 5, 'maxRetries');
125
125
  const url = new URL(this.baseURL);
@@ -138,7 +138,7 @@ export class Transport {
138
138
  throw options.signal?.aborted ? new AbortError('Request aborted.') : new TimeoutError('Request timed out.');
139
139
  try {
140
140
  const response = await this.fetcher(url, { method, redirect: 'manual', signal: scope.signal, headers: {
141
- Authorization: `Bearer ${this.credential}`, Accept: stream ? 'text/event-stream' : 'application/json', 'X-Fazpi-SDK': 'typescript/0.2.0',
141
+ Authorization: `Bearer ${this.credential}`, Accept: stream ? 'text/event-stream' : binary ? 'application/octet-stream' : 'application/json', 'X-Fazpi-SDK': 'typescript/0.3.0',
142
142
  ...(serialized === undefined ? {} : { 'Content-Type': 'application/json' }),
143
143
  ...(key === undefined ? {} : { 'Idempotency-Key': key }),
144
144
  }, ...(serialized === undefined ? {} : { body: serialized }) });
@@ -150,6 +150,8 @@ export class Transport {
150
150
  handedOff = true;
151
151
  return { response, close: scope.close };
152
152
  }
153
+ if (binary && response.ok)
154
+ return await readBinary(response, 20 * 1024 * 1024);
153
155
  const text = await readLimited(response, this.maxResponseBytes);
154
156
  let value;
155
157
  try {
@@ -195,3 +197,33 @@ export class Transport {
195
197
  }
196
198
  }
197
199
  }
200
+ async function readBinary(response, limit) {
201
+ if (!response.body)
202
+ return new Uint8Array();
203
+ const reader = response.body.getReader();
204
+ const chunks = [];
205
+ let total = 0;
206
+ try {
207
+ for (;;) {
208
+ const { done, value } = await reader.read();
209
+ if (done)
210
+ break;
211
+ total += value.byteLength;
212
+ if (total > limit) {
213
+ await reader.cancel();
214
+ throw new ProtocolError('Download exceeds 20 MiB.');
215
+ }
216
+ chunks.push(value);
217
+ }
218
+ }
219
+ finally {
220
+ reader.releaseLock();
221
+ }
222
+ const result = new Uint8Array(total);
223
+ let offset = 0;
224
+ for (const chunk of chunks) {
225
+ result.set(chunk, offset);
226
+ offset += chunk.byteLength;
227
+ }
228
+ return result;
229
+ }
package/dist/types.d.ts CHANGED
@@ -19,6 +19,7 @@ export interface File {
19
19
  size: number;
20
20
  }
21
21
  export interface Message {
22
+ run_id?: string;
22
23
  files?: File[];
23
24
  incomplete?: boolean;
24
25
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fazpi-ai/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [