segmind 0.3.0 → 0.5.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/dist/index.d.cts CHANGED
@@ -251,10 +251,20 @@ interface RequestRecord {
251
251
  latency_ms?: number | null;
252
252
  model_created?: string;
253
253
  error?: string | null;
254
+ /** What sent the request, such as `API`, `API_V2`, `SDK_JS_V2` or `WEBPROD_V2`. */
255
+ initiator?: string | null;
256
+ /** The last 6 characters of the API key that made the request; null when no key did. */
257
+ key_mask?: string | null;
258
+ user_id?: string | null;
259
+ /** Inside a team, whose request it was. Empty when the lookup failed. */
260
+ user_email?: string | null;
254
261
  [key: string]: unknown;
255
262
  }
256
263
  interface GenerationsListOptions {
257
264
  page?: number;
265
+ /** 1–100. Default 10. */
266
+ perPage?: number;
267
+ /** Substring match on the model slug. */
258
268
  modelName?: string;
259
269
  /** YYYY-MM-DD. */
260
270
  startDate?: string;
@@ -262,6 +272,8 @@ interface GenerationsListOptions {
262
272
  endDate?: string;
263
273
  /** Inside a team, any member's user id; otherwise only your own. */
264
274
  userId?: string;
275
+ /** Same as `userId`, by email. Pass one or the other. */
276
+ userEmail?: string;
265
277
  signal?: AbortSignal;
266
278
  }
267
279
  interface HistoryOptions {
@@ -275,6 +287,17 @@ interface HistoryOptions {
275
287
  /** Substring match on the model slug. */
276
288
  modelName?: string;
277
289
  status?: 'COMPLETED' | 'FAILED' | 'PENDING';
290
+ /**
291
+ * Only requests from these sources; a list matches any of them. Either
292
+ * spelling works, `API_V2` or `API-V2`. An unknown source is refused (400).
293
+ */
294
+ initiator?: string | string[];
295
+ /**
296
+ * Only one key's requests, by the last 6 characters of the key, lowercase:
297
+ * the `key_mask` on each row. The full key is never sent, because a URL ends
298
+ * up in access logs.
299
+ */
300
+ keySuffix?: string;
278
301
  /** Inside a team, any member's user id; otherwise only your own. */
279
302
  userId?: string;
280
303
  /** Same as `userId`, by email. Pass one or the other. */
@@ -416,7 +439,7 @@ declare class PixelflowJob {
416
439
  type WebhookEventType = 'PIXELFLOW' | 'WORKFLOW' | 'INFERENCE' | 'FINETUNE' | (string & {});
417
440
  /** A webhook registration, as the API returns it. */
418
441
  interface Webhook {
419
- /** Pass to `update`, `delete` and `logs`. */
442
+ /** Pass to `update`, `delete`, `logs` and `test`. */
420
443
  id: string;
421
444
  user_id: string;
422
445
  webhook_url: string;
@@ -427,6 +450,22 @@ interface Webhook {
427
450
  created_ts: string;
428
451
  [key: string]: unknown;
429
452
  }
453
+ /** One delivery to a registration, as `logs` lists it. */
454
+ interface WebhookDelivery {
455
+ /** Pass to `resend`. */
456
+ id: string;
457
+ webhook_url: string;
458
+ request_id: string;
459
+ event_type: string;
460
+ payload: unknown;
461
+ /** Your endpoint's HTTP status; null when it never answered. */
462
+ status_code: number | null;
463
+ /** The start of your endpoint's reply. */
464
+ response_body: string | null;
465
+ success: boolean;
466
+ created_ts: string;
467
+ [key: string]: unknown;
468
+ }
430
469
  /** Your webhook registrations. One active registration per set of event types. */
431
470
  declare class Webhooks {
432
471
  private readonly client;
@@ -456,10 +495,30 @@ declare class Webhooks {
456
495
  delete(webhookId: string, options?: {
457
496
  signal?: AbortSignal;
458
497
  }): Promise<Record<string, unknown>>;
459
- /** Delivery history for one registration. */
498
+ /** Every delivery made to one registration. */
460
499
  logs(webhookId: string, options?: {
461
500
  signal?: AbortSignal;
462
- }): Promise<Record<string, unknown>>;
501
+ }): Promise<WebhookDelivery[]>;
502
+ /**
503
+ * Sends a `WEBHOOK_TEST` delivery to an active registration. It goes out in
504
+ * the background after this returns, so read `logs` to see how your endpoint
505
+ * answered. Not retried: each attempt is another delivery.
506
+ */
507
+ test(webhookId: string, options?: {
508
+ signal?: AbortSignal;
509
+ }): Promise<{
510
+ message: string;
511
+ }>;
512
+ /**
513
+ * Sends a past delivery's payload again, by its `id` from `logs`. Refused
514
+ * (406) when the registration is no longer active. Not retried: each
515
+ * attempt is another delivery.
516
+ */
517
+ resend(deliveryId: string, options?: {
518
+ signal?: AbortSignal;
519
+ }): Promise<{
520
+ message: string;
521
+ }>;
463
522
  private call;
464
523
  }
465
524
 
@@ -752,7 +811,7 @@ declare class InferenceTimeout extends SegmindError {
752
811
  constructor(requestId: string, elapsedMs: number);
753
812
  }
754
813
 
755
- declare const VERSION = "0.3.0";
814
+ declare const VERSION = "0.5.0";
756
815
 
757
816
  /** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
758
817
  declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
@@ -784,9 +843,9 @@ declare const files: Pick<Files, 'upload'>;
784
843
  /** `new Segmind().generations` with the key from `SEGMIND_API_KEY`. */
785
844
  declare const generations: Pick<Generations, 'list' | 'recent' | 'history' | 'get'>;
786
845
  /** `new Segmind().webhooks` with the key from `SEGMIND_API_KEY`. */
787
- declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs'>;
846
+ declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs' | 'test' | 'resend'>;
788
847
  /** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
789
848
  declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
790
849
 
791
850
  export { APIConnectionError, Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, InferenceFailed, InferenceTimeout, InsufficientCredits, Job, Models, PixelFlows, PixelflowJob, RateLimited, Segmind, SegmindError, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
792
- export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookEventType };
851
+ export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -251,10 +251,20 @@ interface RequestRecord {
251
251
  latency_ms?: number | null;
252
252
  model_created?: string;
253
253
  error?: string | null;
254
+ /** What sent the request, such as `API`, `API_V2`, `SDK_JS_V2` or `WEBPROD_V2`. */
255
+ initiator?: string | null;
256
+ /** The last 6 characters of the API key that made the request; null when no key did. */
257
+ key_mask?: string | null;
258
+ user_id?: string | null;
259
+ /** Inside a team, whose request it was. Empty when the lookup failed. */
260
+ user_email?: string | null;
254
261
  [key: string]: unknown;
255
262
  }
256
263
  interface GenerationsListOptions {
257
264
  page?: number;
265
+ /** 1–100. Default 10. */
266
+ perPage?: number;
267
+ /** Substring match on the model slug. */
258
268
  modelName?: string;
259
269
  /** YYYY-MM-DD. */
260
270
  startDate?: string;
@@ -262,6 +272,8 @@ interface GenerationsListOptions {
262
272
  endDate?: string;
263
273
  /** Inside a team, any member's user id; otherwise only your own. */
264
274
  userId?: string;
275
+ /** Same as `userId`, by email. Pass one or the other. */
276
+ userEmail?: string;
265
277
  signal?: AbortSignal;
266
278
  }
267
279
  interface HistoryOptions {
@@ -275,6 +287,17 @@ interface HistoryOptions {
275
287
  /** Substring match on the model slug. */
276
288
  modelName?: string;
277
289
  status?: 'COMPLETED' | 'FAILED' | 'PENDING';
290
+ /**
291
+ * Only requests from these sources; a list matches any of them. Either
292
+ * spelling works, `API_V2` or `API-V2`. An unknown source is refused (400).
293
+ */
294
+ initiator?: string | string[];
295
+ /**
296
+ * Only one key's requests, by the last 6 characters of the key, lowercase:
297
+ * the `key_mask` on each row. The full key is never sent, because a URL ends
298
+ * up in access logs.
299
+ */
300
+ keySuffix?: string;
278
301
  /** Inside a team, any member's user id; otherwise only your own. */
279
302
  userId?: string;
280
303
  /** Same as `userId`, by email. Pass one or the other. */
@@ -416,7 +439,7 @@ declare class PixelflowJob {
416
439
  type WebhookEventType = 'PIXELFLOW' | 'WORKFLOW' | 'INFERENCE' | 'FINETUNE' | (string & {});
417
440
  /** A webhook registration, as the API returns it. */
418
441
  interface Webhook {
419
- /** Pass to `update`, `delete` and `logs`. */
442
+ /** Pass to `update`, `delete`, `logs` and `test`. */
420
443
  id: string;
421
444
  user_id: string;
422
445
  webhook_url: string;
@@ -427,6 +450,22 @@ interface Webhook {
427
450
  created_ts: string;
428
451
  [key: string]: unknown;
429
452
  }
453
+ /** One delivery to a registration, as `logs` lists it. */
454
+ interface WebhookDelivery {
455
+ /** Pass to `resend`. */
456
+ id: string;
457
+ webhook_url: string;
458
+ request_id: string;
459
+ event_type: string;
460
+ payload: unknown;
461
+ /** Your endpoint's HTTP status; null when it never answered. */
462
+ status_code: number | null;
463
+ /** The start of your endpoint's reply. */
464
+ response_body: string | null;
465
+ success: boolean;
466
+ created_ts: string;
467
+ [key: string]: unknown;
468
+ }
430
469
  /** Your webhook registrations. One active registration per set of event types. */
431
470
  declare class Webhooks {
432
471
  private readonly client;
@@ -456,10 +495,30 @@ declare class Webhooks {
456
495
  delete(webhookId: string, options?: {
457
496
  signal?: AbortSignal;
458
497
  }): Promise<Record<string, unknown>>;
459
- /** Delivery history for one registration. */
498
+ /** Every delivery made to one registration. */
460
499
  logs(webhookId: string, options?: {
461
500
  signal?: AbortSignal;
462
- }): Promise<Record<string, unknown>>;
501
+ }): Promise<WebhookDelivery[]>;
502
+ /**
503
+ * Sends a `WEBHOOK_TEST` delivery to an active registration. It goes out in
504
+ * the background after this returns, so read `logs` to see how your endpoint
505
+ * answered. Not retried: each attempt is another delivery.
506
+ */
507
+ test(webhookId: string, options?: {
508
+ signal?: AbortSignal;
509
+ }): Promise<{
510
+ message: string;
511
+ }>;
512
+ /**
513
+ * Sends a past delivery's payload again, by its `id` from `logs`. Refused
514
+ * (406) when the registration is no longer active. Not retried: each
515
+ * attempt is another delivery.
516
+ */
517
+ resend(deliveryId: string, options?: {
518
+ signal?: AbortSignal;
519
+ }): Promise<{
520
+ message: string;
521
+ }>;
463
522
  private call;
464
523
  }
465
524
 
@@ -752,7 +811,7 @@ declare class InferenceTimeout extends SegmindError {
752
811
  constructor(requestId: string, elapsedMs: number);
753
812
  }
754
813
 
755
- declare const VERSION = "0.3.0";
814
+ declare const VERSION = "0.5.0";
756
815
 
757
816
  /** `new Segmind().run(...)` with the key from `SEGMIND_API_KEY`. */
758
817
  declare const run: (slug: string, params?: Params, options?: RunOptions) => Promise<RunResult>;
@@ -784,9 +843,9 @@ declare const files: Pick<Files, 'upload'>;
784
843
  /** `new Segmind().generations` with the key from `SEGMIND_API_KEY`. */
785
844
  declare const generations: Pick<Generations, 'list' | 'recent' | 'history' | 'get'>;
786
845
  /** `new Segmind().webhooks` with the key from `SEGMIND_API_KEY`. */
787
- declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs'>;
846
+ declare const webhooks: Pick<Webhooks, 'get' | 'add' | 'update' | 'delete' | 'logs' | 'test' | 'resend'>;
788
847
  /** `new Segmind().pixelflows` with the key from `SEGMIND_API_KEY`. */
789
848
  declare const pixelflows: Pick<PixelFlows, 'run' | 'submit' | 'getStatus' | 'poll'>;
790
849
 
791
850
  export { APIConnectionError, Accounts, ChatResponse, DEFAULT_BASE_URL, DEFAULT_CONSOLE_URL, DEFAULT_SPOT_URL, DEFAULT_WAIT_INTERVAL_MS, DEFAULT_WAIT_TIMEOUT_MS, Files, Generations, InferenceFailed, InferenceTimeout, InsufficientCredits, Job, Models, PixelFlows, PixelflowJob, RateLimited, Segmind, SegmindError, VERSION, Webhooks, accounts, chat, chatSync, files, generations, imageUrl, job, models, pixelflows, run, runSync, submit, submitChat, webhooks };
792
- export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookEventType };
851
+ export type { AccountCredits, CallOptions, ChatMessage, ChatParams, ClientOptions, FileInput, Generation, GenerationsListOptions, HistoryOptions, ImageInput, ImageUrlPart, Initiator, InitiatorOptions, JobState, JobStatus, ModelInfo, ModelInput, ModelListParams, ModelOutput, ModelSort, ModelsPage, Page, Params, PixelflowStatus, PixelflowSubmitOptions, PixelflowWaitOptions, PollInterval, RequestRecord, RunOptions, RunResult, SubmitOptions, SubmitResponse, TokenProvider, UploadOptions, UploadedFile, WaitOptions, Webhook, WebhookDelivery, WebhookEventType };
package/dist/index.js CHANGED
@@ -575,10 +575,12 @@ var Generations = class {
575
575
  async list(options = {}) {
576
576
  return this.read("/inference-request/generations", options.signal, {
577
577
  page: options.page ?? 1,
578
+ per_page: options.perPage,
578
579
  model_name: options.modelName,
579
580
  start_date: options.startDate,
580
581
  end_date: options.endDate,
581
- user_id: options.userId
582
+ user_id: options.userId,
583
+ user_email: options.userEmail
582
584
  });
583
585
  }
584
586
  /** The newest generations for one model. */
@@ -598,6 +600,8 @@ var Generations = class {
598
600
  to_date: options.toDate,
599
601
  model_name: options.modelName,
600
602
  status: options.status,
603
+ initiator: [options.initiator ?? []].flat().join(",") || void 0,
604
+ key_suffix: options.keySuffix,
601
605
  user_id: options.userId,
602
606
  user_email: options.userEmail,
603
607
  sort_by: options.sortBy,
@@ -802,7 +806,7 @@ function failureDetail(body) {
802
806
  }
803
807
 
804
808
  // src/version.ts
805
- var VERSION = "0.3.0";
809
+ var VERSION = "0.5.0";
806
810
 
807
811
  // src/webhooks.ts
808
812
  var Webhooks = class {
@@ -842,10 +846,26 @@ var Webhooks = class {
842
846
  async delete(webhookId, options = {}) {
843
847
  return this.call("DELETE", "/inactive", { query: { webhook_id: webhookId }, signal: options.signal });
844
848
  }
845
- /** Delivery history for one registration. */
849
+ /** Every delivery made to one registration. */
846
850
  async logs(webhookId, options = {}) {
847
851
  return this.call("GET", "/dispatch-logs", { query: { webhook_id: webhookId }, signal: options.signal, retry: true });
848
852
  }
853
+ /**
854
+ * Sends a `WEBHOOK_TEST` delivery to an active registration. It goes out in
855
+ * the background after this returns, so read `logs` to see how your endpoint
856
+ * answered. Not retried: each attempt is another delivery.
857
+ */
858
+ async test(webhookId, options = {}) {
859
+ return this.call("POST", "/test", { body: { webhook_id: webhookId }, signal: options.signal });
860
+ }
861
+ /**
862
+ * Sends a past delivery's payload again, by its `id` from `logs`. Refused
863
+ * (406) when the registration is no longer active. Not retried: each
864
+ * attempt is another delivery.
865
+ */
866
+ async resend(deliveryId, options = {}) {
867
+ return this.call("POST", "/resend", { body: { webhook_dispatch_id: deliveryId }, signal: options.signal });
868
+ }
849
869
  call(method, path2, req) {
850
870
  return this.client.http.json({ method, url: `${this.client.spotURL}/webhook${path2}`, ...req });
851
871
  }
@@ -1186,7 +1206,9 @@ var webhooks = {
1186
1206
  add: (webhookUrl, eventTypes, options) => client().webhooks.add(webhookUrl, eventTypes, options),
1187
1207
  update: (webhookId, webhookUrl, eventTypes, options) => client().webhooks.update(webhookId, webhookUrl, eventTypes, options),
1188
1208
  delete: (webhookId, options) => client().webhooks.delete(webhookId, options),
1189
- logs: (webhookId, options) => client().webhooks.logs(webhookId, options)
1209
+ logs: (webhookId, options) => client().webhooks.logs(webhookId, options),
1210
+ test: (webhookId, options) => client().webhooks.test(webhookId, options),
1211
+ resend: (deliveryId, options) => client().webhooks.resend(deliveryId, options)
1190
1212
  };
1191
1213
  var pixelflows = {
1192
1214
  run: (slug, inputs, options) => client().pixelflows.run(slug, inputs, options),