@pipe0/client 0.0.1 → 0.0.3

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.
@@ -1,5 +0,0 @@
1
- /**
2
- * This file was auto-generated by openapi-typescript.
3
- * Do not make direct changes to the file.
4
- */
5
- export {};
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { Pipe0 } from "./pipe0.js";
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export { Pipe0 } from "./pipe0.js";
package/dist/pipe0.d.ts DELETED
@@ -1,323 +0,0 @@
1
- import { type Client } from "openapi-fetch";
2
- import type { paths } from "./generated/openapi.types.js";
3
- export type PipesRequestPayload = paths["/v1/pipes/run"]["post"]["requestBody"]["content"]["application/json"];
4
- export type PipesResponse = paths["/v1/pipes/check/{run_id}"]["get"]["responses"]["200"]["content"]["application/json"];
5
- export type PiperSearchRequestPayload = paths["/v1/searches/run"]["post"]["requestBody"]["content"]["application/json"];
6
- export type PiperSearchResponse = paths["/v1/searches/check/{run_id}"]["get"]["responses"]["200"]["content"]["application/json"];
7
- export declare class PiperTimeoutError extends Error {
8
- readonly runId?: string | undefined;
9
- constructor(message: string, runId?: string | undefined);
10
- }
11
- export declare class Pipe0AbortError extends Error {
12
- readonly runId?: string | undefined;
13
- constructor(message: string, runId?: string | undefined);
14
- }
15
- export declare class Pipe0BatchError extends Error {
16
- readonly errors: Array<{
17
- batchIndex: number;
18
- error: Error;
19
- }>;
20
- readonly successfulBatches: PipesResponse[];
21
- constructor(message: string, errors: Array<{
22
- batchIndex: number;
23
- error: Error;
24
- }>, successfulBatches: PipesResponse[]);
25
- }
26
- export declare class Pipe0TaskError extends Error {
27
- readonly responseBody?: unknown | undefined;
28
- constructor(message: string, responseBody?: unknown | undefined);
29
- }
30
- export declare class Pipe0ServerError extends Error {
31
- constructor(message: string);
32
- }
33
- export interface BatchOptions {
34
- /**
35
- * Callback invoked on each poll for any batch
36
- */
37
- onPoll?: (_batchIndex: number, _response: PipesResponse) => void;
38
- /**
39
- * Callback invoked when each batch completes
40
- */
41
- onBatchComplete?: (_batchIndex: number, _result: PipesResponse) => void;
42
- /**
43
- * Whether to stop all batches if one fails
44
- * @default true
45
- */
46
- stopOnError?: boolean;
47
- /**
48
- * AbortSignal to cancel all batch operations
49
- */
50
- signal?: AbortSignal;
51
- }
52
- export interface PiperOptions {
53
- apiKey?: string;
54
- baseUrl?: string;
55
- /**
56
- * Default timeout for polling operations in milliseconds
57
- * @default 900000 (15 minutes)
58
- */
59
- pollingTimeoutMs?: number;
60
- /**
61
- * Default polling interval in milliseconds
62
- * @default 1000 (1 second)
63
- */
64
- minPollingIntervalMs?: number;
65
- /**
66
- * Maximum polling interval in milliseconds (for exponential backoff)
67
- * @default 3000 (3 seconds)
68
- */
69
- maxPollingIntervalMs?: number;
70
- /**
71
- * Default batch size for large payloads
72
- * @default 100
73
- */
74
- defaultBatchSize?: number;
75
- /**
76
- * Maximum number of concurrent batch requests
77
- * @default 5
78
- */
79
- maxConcurrentBatches?: number;
80
- }
81
- export declare class Pipe0 {
82
- client: Client<paths, `${string}/${string}`>;
83
- private apiKey?;
84
- private pollingTimeoutMs;
85
- private minPollingIntervalMs;
86
- private maxPollingIntervalMs;
87
- private defaultBatchSize;
88
- private maxConcurrentBatches;
89
- constructor(options?: PiperOptions);
90
- /**
91
- * Centralized logic to poll until a task completes, fails, or times out.
92
- */
93
- private _pollUntilComplete;
94
- pipes: {
95
- /**
96
- * Create and immediately wait for completion (convenience method)
97
- */
98
- pipe: (payload: PipesRequestPayload, options?: {
99
- onPoll?: (_response: PipesResponse) => unknown;
100
- signal?: AbortSignal;
101
- }) => Promise<PipesResponse>;
102
- /**
103
- * Create a pipes task but don't want for it. Use this method if you want to fire and forget.
104
- */
105
- create: (payload: PipesRequestPayload) => Promise<string>;
106
- /**
107
- * Check the status of a pipes task manually.
108
- */
109
- check: (runId: string) => Promise<{
110
- id: string;
111
- organization_id: string;
112
- order: (number | string)[];
113
- field_definitions: {
114
- [key: string]: {
115
- type: "string" | "number" | "boolean" | "json" | "unknown";
116
- label: string;
117
- json_metadata: {
118
- example_value?: unknown;
119
- schema?: unknown;
120
- } | null;
121
- added_by: {
122
- ref: ("prompt:run@1" | "company:newssummary:website@1" | "company:techstack:builtwith@1" | "company:websiteurl:email@1" | "company:funding:leadmagic@1" | "people:workemail:waterfall@1" | "people:email:iswork@1" | "people:name:split@1" | "people:name:join@1" | "people:validate:email:zerobounce@1" | "people:email:validate:zerobounce@2" | "people:mobilenumber:workemail:waterfall@1" | "company:overview@1" | "company:overview@2" | "json:extract@1" | "email:write@1" | "message:write@1" | "email:send:resend@1" | "email:send:gmail@1" | "message:send:slack@1" | "template:fill@1" | "contact:create:resend@1" | "company:identity@2" | "people:phone:profile:waterfall@1" | "people:personalemail:profile:waterfall@1" | "people:profile:waterfall@1" | "people:profileurl:email:waterfall@1" | "people:profileurl:name@1" | "people:email:validate:zerobounce@1" | "people:email:validate:millionverifier@1" | "people:phone:workemail:waterfall@1" | "fields:merge@1" | "website:scrape:firecrawl@1" | "website:scrapelist:firecrawl@1" | "website:extract:firecrawl@1" | "website:maplinks:firecrawl@1" | "sheet:append@1" | "sheet:expandappend@1" | "company:identity@1" | "people:professionalprofile:waterfall@1" | "people:professionalprofileurl:name@1" | "people:professionalprofileurl:email:waterfall@1" | "people:mobilenumber:professionalprofile:waterfall@1") | "input";
123
- config_hash: string | null;
124
- pipe_index: number | null;
125
- };
126
- format: "json_object" | "json_list" | "json_list_string" | "url" | "website_url" | "profile_url" | "email" | "datetime" | "currency" | "date" | "phone" | "markdown" | "text" | "int" | "decimal" | "address_line_1" | "zip_code" | "percent" | null;
127
- };
128
- };
129
- errors: {
130
- code: string;
131
- message: string;
132
- path?: string;
133
- }[];
134
- records: {
135
- [key: string]: {
136
- id: number | string;
137
- fields: {
138
- [key: string]: {
139
- value: string | number | boolean | null | {
140
- [key: string]: unknown;
141
- } | unknown[];
142
- status: "completed" | "failed" | "pending" | "queued" | "processing" | "no_result" | "skipped";
143
- type: "string" | "number" | "boolean" | "json" | "unknown";
144
- reason: {
145
- code: string;
146
- summary: string;
147
- message: string;
148
- } | null;
149
- claimed_by: {
150
- ref: "prompt:run@1" | "company:newssummary:website@1" | "company:techstack:builtwith@1" | "company:websiteurl:email@1" | "company:funding:leadmagic@1" | "people:workemail:waterfall@1" | "people:email:iswork@1" | "people:name:split@1" | "people:name:join@1" | "people:validate:email:zerobounce@1" | "people:email:validate:zerobounce@2" | "people:mobilenumber:workemail:waterfall@1" | "company:overview@1" | "company:overview@2" | "json:extract@1" | "email:write@1" | "message:write@1" | "email:send:resend@1" | "email:send:gmail@1" | "message:send:slack@1" | "template:fill@1" | "contact:create:resend@1" | "company:identity@2" | "people:phone:profile:waterfall@1" | "people:personalemail:profile:waterfall@1" | "people:profile:waterfall@1" | "people:profileurl:email:waterfall@1" | "people:profileurl:name@1" | "people:email:validate:zerobounce@1" | "people:email:validate:millionverifier@1" | "people:phone:workemail:waterfall@1" | "fields:merge@1" | "website:scrape:firecrawl@1" | "website:scrapelist:firecrawl@1" | "website:extract:firecrawl@1" | "website:maplinks:firecrawl@1" | "sheet:append@1" | "sheet:expandappend@1" | "company:identity@1" | "people:professionalprofile:waterfall@1" | "people:professionalprofileurl:name@1" | "people:professionalprofileurl:email:waterfall@1" | "people:mobilenumber:professionalprofile:waterfall@1" | "input" | null;
151
- config_hash: string | null;
152
- };
153
- resolved_by: {
154
- ref: "prompt:run@1" | "company:newssummary:website@1" | "company:techstack:builtwith@1" | "company:websiteurl:email@1" | "company:funding:leadmagic@1" | "people:workemail:waterfall@1" | "people:email:iswork@1" | "people:name:split@1" | "people:name:join@1" | "people:validate:email:zerobounce@1" | "people:email:validate:zerobounce@2" | "people:mobilenumber:workemail:waterfall@1" | "company:overview@1" | "company:overview@2" | "json:extract@1" | "email:write@1" | "message:write@1" | "email:send:resend@1" | "email:send:gmail@1" | "message:send:slack@1" | "template:fill@1" | "contact:create:resend@1" | "company:identity@2" | "people:phone:profile:waterfall@1" | "people:personalemail:profile:waterfall@1" | "people:profile:waterfall@1" | "people:profileurl:email:waterfall@1" | "people:profileurl:name@1" | "people:email:validate:zerobounce@1" | "people:email:validate:millionverifier@1" | "people:phone:workemail:waterfall@1" | "fields:merge@1" | "website:scrape:firecrawl@1" | "website:scrapelist:firecrawl@1" | "website:extract:firecrawl@1" | "website:maplinks:firecrawl@1" | "sheet:append@1" | "sheet:expandappend@1" | "company:identity@1" | "people:professionalprofile:waterfall@1" | "people:professionalprofileurl:name@1" | "people:professionalprofileurl:email:waterfall@1" | "people:mobilenumber:professionalprofile:waterfall@1" | "input" | "system" | null;
155
- environment: "production" | "sandbox" | null;
156
- config_hash: string | null;
157
- input_hash: string | null;
158
- } | null;
159
- widgets?: {
160
- display_value?: {
161
- label?: string;
162
- };
163
- entity_logo?: {
164
- image_url: string;
165
- entity: string;
166
- };
167
- location_indicator?: {
168
- emoji: string;
169
- };
170
- avatar?: {
171
- image_url: string;
172
- name: string;
173
- };
174
- waterfall?: {
175
- attempted_providers: {
176
- provider: "pipe0" | "findymail" | "zerobounce" | "millionverifier" | "googlemaps" | "gemini" | "leadmagic" | "builtwith" | "perplexity" | "serper" | "icypeas" | "prospeo" | "clado" | "resend" | "slack" | "gmail" | "firecrawl" | "exa" | "openai";
177
- }[];
178
- available_providers: ("pipe0" | "findymail" | "zerobounce" | "millionverifier" | "googlemaps" | "gemini" | "leadmagic" | "builtwith" | "perplexity" | "serper" | "icypeas" | "prospeo" | "clado" | "resend" | "slack" | "gmail" | "firecrawl" | "exa" | "openai")[];
179
- successful_provider?: "pipe0" | "findymail" | "zerobounce" | "millionverifier" | "googlemaps" | "gemini" | "leadmagic" | "builtwith" | "perplexity" | "serper" | "icypeas" | "prospeo" | "clado" | "resend" | "slack" | "gmail" | "firecrawl" | "exa" | "openai";
180
- };
181
- icon?: {
182
- key: "linkedin" | "job";
183
- };
184
- action_summary?: {
185
- result_status: "completed" | "failed";
186
- };
187
- sources?: {
188
- list: {
189
- source: string;
190
- description?: string;
191
- url: string;
192
- }[];
193
- };
194
- confidence?: {
195
- numeric: number;
196
- };
197
- };
198
- format: "json_object" | "json_list" | "json_list_string" | "url" | "website_url" | "profile_url" | "email" | "datetime" | "currency" | "date" | "phone" | "markdown" | "text" | "int" | "decimal" | "address_line_1" | "zip_code" | "percent" | null;
199
- };
200
- };
201
- };
202
- };
203
- status: "completed" | "failed" | "pending" | "processing";
204
- }>;
205
- waitUntilComplete: (runId: string | Promise<string>, options?: {
206
- /**
207
- * Callback invoked on each poll with the current status
208
- */
209
- onPoll?: (_response: PipesResponse) => unknown;
210
- /**
211
- * AbortSignal to cancel the polling operation
212
- */
213
- signal?: AbortSignal;
214
- }) => Promise<PipesResponse>;
215
- /**
216
- * Process a large payload by batching the input array
217
- * @param payload - The pipe request payload with a large input array
218
- * @param options - Batching options
219
- * @returns Array of completed batch responses
220
- */
221
- pipeInBatches: (payload: PipesRequestPayload, { stopOnError, ...options }?: BatchOptions) => Promise<PipesResponse[]>;
222
- };
223
- searches: {
224
- /**
225
- * Create and immediately wait for completion (convenience method)
226
- */
227
- search: (payload: PiperSearchRequestPayload, options?: {
228
- onPoll?: (_response: PiperSearchResponse) => unknown;
229
- signal?: AbortSignal;
230
- }) => Promise<PiperSearchResponse>;
231
- /**
232
- * Create a searches task but don't wait for it.
233
- * Use this if you want fire and forget.
234
- */
235
- create: (payload: PiperSearchRequestPayload) => Promise<string>;
236
- /**
237
- * Check the status of a search task manually.
238
- */
239
- check: (runId: string) => Promise<{
240
- id: string;
241
- status: "completed" | "failed" | "pending" | "processing";
242
- results: {
243
- [key: string]: {
244
- value: string | number | boolean | null | {
245
- [key: string]: unknown;
246
- } | unknown[];
247
- status: "completed" | "failed" | "pending" | "queued" | "processing" | "no_result" | "skipped";
248
- type?: "string" | "number" | "boolean" | "json" | "unknown";
249
- format?: "json_object" | "json_list" | "json_list_string" | "url" | "website_url" | "profile_url" | "email" | "datetime" | "currency" | "date" | "phone" | "markdown" | "text" | "int" | "decimal" | "address_line_1" | "zip_code" | "percent" | null;
250
- widgets?: {
251
- display_value?: {
252
- label?: string;
253
- };
254
- entity_logo?: {
255
- image_url: string;
256
- entity: string;
257
- };
258
- location_indicator?: {
259
- emoji: string;
260
- };
261
- avatar?: {
262
- image_url: string;
263
- name: string;
264
- };
265
- waterfall?: {
266
- attempted_providers: {
267
- provider: "pipe0" | "findymail" | "zerobounce" | "millionverifier" | "googlemaps" | "gemini" | "leadmagic" | "builtwith" | "perplexity" | "serper" | "icypeas" | "prospeo" | "clado" | "resend" | "slack" | "gmail" | "firecrawl" | "exa" | "openai";
268
- }[];
269
- available_providers: ("pipe0" | "findymail" | "zerobounce" | "millionverifier" | "googlemaps" | "gemini" | "leadmagic" | "builtwith" | "perplexity" | "serper" | "icypeas" | "prospeo" | "clado" | "resend" | "slack" | "gmail" | "firecrawl" | "exa" | "openai")[];
270
- successful_provider?: "pipe0" | "findymail" | "zerobounce" | "millionverifier" | "googlemaps" | "gemini" | "leadmagic" | "builtwith" | "perplexity" | "serper" | "icypeas" | "prospeo" | "clado" | "resend" | "slack" | "gmail" | "firecrawl" | "exa" | "openai";
271
- };
272
- icon?: {
273
- key: "linkedin" | "job";
274
- };
275
- action_summary?: {
276
- result_status: "completed" | "failed";
277
- };
278
- sources?: {
279
- list: {
280
- source: string;
281
- description?: string;
282
- url: string;
283
- }[];
284
- };
285
- confidence?: {
286
- numeric: number;
287
- };
288
- };
289
- } | null;
290
- }[];
291
- search_statuses: {
292
- search: {
293
- ref: "people:profiles:icypeas@1" | "companies:profiles:icypeas@1" | "people:profiles:clado@1" | "people:profiles:clado@2" | "people:employees:leadmagic@1" | "companies:profiles:exa@1" | "people:profiles:exa@1";
294
- };
295
- status: "pending" | "processing" | "failed" | "completed";
296
- errors: {
297
- code: string;
298
- message: string;
299
- path?: string;
300
- }[];
301
- meta: {
302
- providers?: {
303
- clado?: {
304
- pagination: {
305
- search_id?: string;
306
- offset?: number;
307
- };
308
- };
309
- };
310
- };
311
- }[];
312
- organizationId: string;
313
- }>;
314
- /**
315
- * Poll until the search completes or fails.
316
- */
317
- waitUntilComplete: (runId: string | Promise<string>, options?: {
318
- onPoll?: (_response: PiperSearchResponse) => unknown;
319
- signal?: AbortSignal;
320
- }) => Promise<PiperSearchResponse>;
321
- };
322
- private sleep;
323
- }
package/dist/pipe0.js DELETED
@@ -1,271 +0,0 @@
1
- import createFetchClient, {} from "openapi-fetch";
2
- export class PiperTimeoutError extends Error {
3
- runId;
4
- constructor(message, runId) {
5
- super(message);
6
- this.runId = runId;
7
- this.name = "PiperTimeoutError";
8
- this.runId = runId;
9
- }
10
- }
11
- export class Pipe0AbortError extends Error {
12
- runId;
13
- constructor(message, runId) {
14
- super(message);
15
- this.runId = runId;
16
- this.name = "PiperAbortError";
17
- this.runId = runId;
18
- }
19
- }
20
- export class Pipe0BatchError extends Error {
21
- errors;
22
- successfulBatches;
23
- constructor(message, errors, successfulBatches) {
24
- super(message);
25
- this.errors = errors;
26
- this.successfulBatches = successfulBatches;
27
- this.name = "PiperBatchError";
28
- this.errors = errors;
29
- this.successfulBatches = successfulBatches;
30
- }
31
- }
32
- export class Pipe0TaskError extends Error {
33
- responseBody;
34
- constructor(message, responseBody) {
35
- super(message);
36
- this.responseBody = responseBody;
37
- this.name = "PiperTaskError";
38
- this.responseBody = responseBody;
39
- }
40
- }
41
- export class Pipe0ServerError extends Error {
42
- constructor(message) {
43
- super(message);
44
- this.name = "PiperServerError";
45
- }
46
- }
47
- export class Pipe0 {
48
- client;
49
- apiKey;
50
- pollingTimeoutMs;
51
- minPollingIntervalMs;
52
- maxPollingIntervalMs;
53
- defaultBatchSize;
54
- maxConcurrentBatches;
55
- constructor(options = {}) {
56
- // eslint-disable-next-line turbo/no-undeclared-env-vars
57
- this.apiKey = options.apiKey ?? process.env.PIPE0_API_KEY;
58
- this.pollingTimeoutMs = options.pollingTimeoutMs ?? 900000;
59
- this.minPollingIntervalMs = options.minPollingIntervalMs ?? 1000;
60
- this.maxPollingIntervalMs =
61
- options.maxPollingIntervalMs ?? this.minPollingIntervalMs * 3;
62
- this.defaultBatchSize = options.defaultBatchSize ?? 100;
63
- this.maxConcurrentBatches = options.maxConcurrentBatches ?? 5;
64
- const headers = {};
65
- if (this.apiKey) {
66
- headers.Authorization = `Bearer ${this.apiKey}`;
67
- }
68
- this.client = createFetchClient({
69
- baseUrl: options.baseUrl ?? "https://api.pipe0.com",
70
- credentials: "include",
71
- headers,
72
- });
73
- }
74
- /**
75
- * Centralized logic to poll until a task completes, fails, or times out.
76
- */
77
- async _pollUntilComplete(runId, checkFn, taskType, options = {}) {
78
- const resolvedRunId = await runId;
79
- const timeout = this.pollingTimeoutMs;
80
- const initialInterval = this.minPollingIntervalMs;
81
- const maxInterval = this.maxPollingIntervalMs;
82
- // We can hardcode backoff for simplicity since it's the only logic
83
- const useBackoff = true;
84
- const startTime = Date.now();
85
- let currentInterval = initialInterval;
86
- while (true) {
87
- if (Date.now() - startTime >= timeout) {
88
- throw new PiperTimeoutError(`${taskType} polling timed out after ${timeout}ms`, resolvedRunId);
89
- }
90
- if (options.signal?.aborted) {
91
- throw new Pipe0AbortError(`${taskType} polling was aborted`, resolvedRunId);
92
- }
93
- const polledResponse = await checkFn(resolvedRunId);
94
- if (options.onPoll) {
95
- await options.onPoll(polledResponse);
96
- }
97
- if (polledResponse.status === "completed") {
98
- return polledResponse;
99
- }
100
- if (polledResponse.status === "failed") {
101
- throw new Pipe0TaskError(`${taskType} failed with status: ${polledResponse.status}`, polledResponse);
102
- }
103
- await this.sleep(currentInterval, options.signal);
104
- if (useBackoff) {
105
- currentInterval = Math.min(currentInterval * 1.1, maxInterval);
106
- }
107
- }
108
- }
109
- pipes = {
110
- /**
111
- * Create and immediately wait for completion (convenience method)
112
- */
113
- pipe: async (payload, options = {}) => {
114
- return this.pipes.waitUntilComplete(await this.pipes.create(payload), options);
115
- },
116
- /**
117
- * Create a pipes task but don't want for it. Use this method if you want to fire and forget.
118
- */
119
- create: async (payload) => {
120
- const response = await this.client.POST("/v1/pipes/run", {
121
- body: payload,
122
- });
123
- if (response.error) {
124
- throw new Pipe0ServerError(JSON.stringify(response.error));
125
- }
126
- return response.data.id;
127
- },
128
- /**
129
- * Check the status of a pipes task manually.
130
- */
131
- check: async (runId) => {
132
- const response = await this.client.GET("/v1/pipes/check/{run_id}", {
133
- params: { path: { run_id: runId } },
134
- });
135
- if (response.error) {
136
- throw new Pipe0ServerError(JSON.stringify(response.error));
137
- }
138
- return response.data;
139
- },
140
- waitUntilComplete: async (runId, options = {}) => {
141
- return this._pollUntilComplete(runId, this.pipes.check, "Pipe", options);
142
- },
143
- /**
144
- * Process a large payload by batching the input array
145
- * @param payload - The pipe request payload with a large input array
146
- * @param options - Batching options
147
- * @returns Array of completed batch responses
148
- */
149
- pipeInBatches: async (payload, { stopOnError = true, ...options } = {}) => {
150
- const batchSize = this.defaultBatchSize;
151
- const maxConcurrency = this.maxConcurrentBatches;
152
- // Extract and validate input array
153
- if (!Array.isArray(payload.input)) {
154
- throw new Error("payload.input must be an array for batched operations");
155
- }
156
- const inputArray = payload.input;
157
- const totalItems = inputArray.length;
158
- // Create batches
159
- const batches = [];
160
- for (let i = 0; i < totalItems; i += batchSize) {
161
- const batchInput = inputArray.slice(i, i + batchSize);
162
- batches.push({
163
- ...payload,
164
- input: batchInput,
165
- });
166
- }
167
- // Process batches with concurrency control
168
- const resultsArr = [];
169
- const errors = [];
170
- for (let i = 0; i < batches.length; i += maxConcurrency) {
171
- if (options.signal?.aborted) {
172
- throw new Pipe0AbortError("Batch operation was aborted");
173
- }
174
- const batchGroup = batches.slice(i, i + maxConcurrency);
175
- const batchPromises = batchGroup.map(async (batch, groupIndex) => {
176
- const batchIndex = i + groupIndex;
177
- try {
178
- // Create and wait for batch
179
- const runId = await this.pipes.create(batch);
180
- const result = await this.pipes.waitUntilComplete(runId, {
181
- signal: options.signal,
182
- onPoll: options.onPoll
183
- ? (response) => options.onPoll(batchIndex, response)
184
- : undefined,
185
- });
186
- if (options.onBatchComplete) {
187
- options.onBatchComplete(batchIndex, result);
188
- }
189
- return { batchIndex, result };
190
- }
191
- catch (error) {
192
- const err = error instanceof Error ? error : new Error(String(error));
193
- errors.push({ batchIndex, error: err });
194
- if (stopOnError) {
195
- throw new Pipe0BatchError(`Batch ${batchIndex} failed and stopOnError is enabled`, errors, resultsArr);
196
- }
197
- return { batchIndex, result: null };
198
- }
199
- });
200
- const batchResults = await Promise.all(batchPromises);
201
- // Collect results in order
202
- for (const { result } of batchResults) {
203
- if (result) {
204
- resultsArr.push(result);
205
- }
206
- }
207
- }
208
- // If any errors occurred and stopOnError wasn't enabled, throw at the end
209
- if (errors.length > 0) {
210
- throw new Pipe0BatchError(`${errors.length} batch(es) failed out of ${batches.length} total`, errors, resultsArr);
211
- }
212
- return resultsArr;
213
- },
214
- };
215
- searches = {
216
- /**
217
- * Create and immediately wait for completion (convenience method)
218
- */
219
- search: async (payload, options = {}) => {
220
- return this.searches.waitUntilComplete(await this.searches.create(payload), options);
221
- },
222
- /**
223
- * Create a searches task but don't wait for it.
224
- * Use this if you want fire and forget.
225
- */
226
- create: async (payload) => {
227
- const response = await this.client.POST("/v1/searches/run", {
228
- body: payload,
229
- });
230
- if (response.error) {
231
- throw new Pipe0ServerError(JSON.stringify(response.error));
232
- }
233
- return response.data.id;
234
- },
235
- /**
236
- * Check the status of a search task manually.
237
- */
238
- check: async (runId) => {
239
- const response = await this.client.GET("/v1/searches/check/{run_id}", {
240
- params: { path: { run_id: runId } },
241
- });
242
- if (response.error) {
243
- throw new Pipe0ServerError(JSON.stringify(response.error));
244
- }
245
- return response.data;
246
- },
247
- /**
248
- * Poll until the search completes or fails.
249
- */
250
- waitUntilComplete: async (runId, options = {}) => {
251
- return this._pollUntilComplete(runId, this.searches.check, "Search", options);
252
- },
253
- };
254
- sleep(ms, signal) {
255
- return new Promise((resolve, reject) => {
256
- const timeout = setTimeout(resolve, ms);
257
- if (signal) {
258
- const onAbort = () => {
259
- clearTimeout(timeout);
260
- reject(new Pipe0AbortError("Sleep was aborted"));
261
- };
262
- if (signal.aborted) {
263
- clearTimeout(timeout);
264
- reject(new Pipe0AbortError("Sleep was aborted"));
265
- return;
266
- }
267
- signal.addEventListener("abort", onAbort, { once: true });
268
- }
269
- });
270
- }
271
- }