@sixb/client 0.1.18 → 0.1.19

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/src/file.ts CHANGED
@@ -207,9 +207,11 @@ async function putDirectUpload(input: {
207
207
  readonly url: string
208
208
  readonly signal?: AbortSignal
209
209
  }): Promise<void> {
210
+ // Browser fetch rejects an arbitrary receiver; invoke it as a standalone function.
211
+ const fetch = input.fetch
210
212
  let response: Response
211
213
  try {
212
- response = await input.fetch(input.url, {
214
+ response = await fetch(input.url, {
213
215
  method: input.method,
214
216
  headers: input.headers,
215
217
  body: input.file,
@@ -236,6 +238,7 @@ async function uploadMultipartFile(input: {
236
238
  readonly uploadId: string
237
239
  readonly signal?: AbortSignal
238
240
  }): Promise<Array<{ partNumber: number; etag?: string }>> {
241
+ const fetch = input.fetch
239
242
  const parts: Array<{ partNumber: number; etag?: string }> = []
240
243
  let partNumber = 1
241
244
 
@@ -250,7 +253,7 @@ async function uploadMultipartFile(input: {
250
253
 
251
254
  let response: Response
252
255
  try {
253
- response = await input.fetch(signedPart.url, {
256
+ response = await fetch(signedPart.url, {
254
257
  method: signedPart.method,
255
258
  headers: signedPart.headers,
256
259
  body: input.file.slice(offset, Math.min(input.file.size, offset + input.partSizeBytes)),
@@ -3681,6 +3681,8 @@ export const getActionOptions = (options: Options<GetActionData>) =>
3681
3681
 
3682
3682
  /**
3683
3683
  * Request an action
3684
+ *
3685
+ * Runs the action and returns its terminal run. A run that fails is returned with status `failed`. Its effects run after the response, which does not wait for them. An error response usually means no run was requested, but a 500 can follow a run that started: request again with the same `runId` to get its record if it was written. A `runId` that was already recorded returns that run, and 409 while this server still runs it. 503 means the server is stopping and started nothing.
3684
3686
  */
3685
3687
  export const requestActionMutation = (
3686
3688
  options?: Partial<Options<RequestActionData>>
@@ -2228,6 +2228,8 @@ export const getAction = <ThrowOnError extends boolean = false>(
2228
2228
 
2229
2229
  /**
2230
2230
  * Request an action
2231
+ *
2232
+ * Runs the action and returns its terminal run. A run that fails is returned with status `failed`. Its effects run after the response, which does not wait for them. An error response usually means no run was requested, but a 500 can follow a run that started: request again with the same `runId` to get its record if it was written. A `runId` that was already recorded returns that run, and 409 while this server still runs it. 503 means the server is stopping and started nothing.
2231
2233
  */
2232
2234
  export const requestAction = <ThrowOnError extends boolean = false>(
2233
2235
  options: Options<RequestActionData, ThrowOnError>
@@ -9268,19 +9268,193 @@ export type RequestActionErrors = {
9268
9268
  404: {
9269
9269
  error: string
9270
9270
  }
9271
+ /**
9272
+ * Response for status 409
9273
+ */
9274
+ 409: {
9275
+ error: string
9276
+ /**
9277
+ * Stable machine-readable failure code for programmatic handling.
9278
+ */
9279
+ code: "action.run_in_progress"
9280
+ }
9281
+ /**
9282
+ * Response for status 500
9283
+ */
9284
+ 500: {
9285
+ error: string
9286
+ /**
9287
+ * Stable machine-readable failure code for programmatic handling.
9288
+ */
9289
+ code:
9290
+ | "action.phase_failed"
9291
+ | "action.read_conflict"
9292
+ | "action.run_in_progress"
9293
+ | "action.timeout"
9294
+ | "agent.execution_failed"
9295
+ | "ai.usage_limit_exceeded"
9296
+ | "ai.usage_limit_unavailable"
9297
+ | "connector.adapter_invalid"
9298
+ | "connector.authorization_invalid"
9299
+ | "connector.authorization_required"
9300
+ | "connector.configuration_invalid"
9301
+ | "connector.credentials_unavailable"
9302
+ | "connector.not_found"
9303
+ | "connector.operation_conflict"
9304
+ | "connector.operation_in_progress"
9305
+ | "connector.provider_failed"
9306
+ | "connector.provider_unavailable"
9307
+ | "connector.replacement_required"
9308
+ | "connector.revocation_pending"
9309
+ | "dataset.not_found"
9310
+ | "dataset.version_incompatible"
9311
+ | "dataset.version_not_found"
9312
+ | "dataset.version_read_inconsistent"
9313
+ | "event.delivery_failed"
9314
+ | "internal.unexpected"
9315
+ | "queue.enqueue_failed"
9316
+ | "pipeline.step_failed"
9317
+ | "projection.definition_invalid"
9318
+ | "projection.execution_failed"
9319
+ | "projection.not_found"
9320
+ | "projection.run_already_terminal"
9321
+ | "projection.run_identity_mismatch"
9322
+ | "runtime.cancelled"
9323
+ | "runtime.stopping"
9324
+ | "vector.model_unavailable"
9325
+ | "vector.response_invalid"
9326
+ | "vector.outcome_unknown"
9327
+ | "storage.unavailable"
9328
+ | "sync.execution_failed"
9329
+ | "webhook.delivery_failed"
9330
+ | "webhook.delivery_rejected"
9331
+ | "workflow.node_failed"
9332
+ }
9333
+ /**
9334
+ * Response for status 503
9335
+ */
9336
+ 503: {
9337
+ error: string
9338
+ /**
9339
+ * Stable machine-readable failure code for programmatic handling.
9340
+ */
9341
+ code: "runtime.stopping"
9342
+ }
9271
9343
  }
9272
9344
 
9273
9345
  export type RequestActionError = RequestActionErrors[keyof RequestActionErrors]
9274
9346
 
9275
9347
  export type RequestActionResponses = {
9276
9348
  /**
9277
- * Response for status 202
9349
+ * Response for status 200
9278
9350
  */
9279
- 202: {
9280
- runId: string
9281
- queuedAt: string
9282
- jobId?: string
9283
- created: boolean
9351
+ 200: {
9352
+ id: string
9353
+ projectId: string
9354
+ actionId: string
9355
+ subject:
9356
+ | {
9357
+ kind: "none"
9358
+ }
9359
+ | {
9360
+ kind: "object"
9361
+ objectTypeId: string
9362
+ primaryId: string
9363
+ }
9364
+ status: "succeeded" | "failed"
9365
+ phase: "validation" | "writeback" | "edits" | "commit" | "effects"
9366
+ startedAt: string
9367
+ finishedAt: string
9368
+ error?: {
9369
+ code:
9370
+ | "internal.unexpected"
9371
+ | "runtime.cancelled"
9372
+ | "action.phase_failed"
9373
+ | "action.read_conflict"
9374
+ | "action.timeout"
9375
+ message: string
9376
+ retryable: boolean
9377
+ at: string
9378
+ details: {
9379
+ actionId: string
9380
+ runId: string
9381
+ phase: "validation" | "writeback" | "edits" | "commit" | "effects"
9382
+ }
9383
+ httpStatus?: number
9384
+ redacted?: true
9385
+ truncated?: true
9386
+ }
9387
+ params: {
9388
+ [key: string]: unknown
9389
+ }
9390
+ writeback?:
9391
+ | {
9392
+ status: "succeeded"
9393
+ completedAt: string
9394
+ /**
9395
+ * Any JSON-compatible value.
9396
+ */
9397
+ result:
9398
+ | string
9399
+ | number
9400
+ | boolean
9401
+ | Array<unknown>
9402
+ | {
9403
+ [key: string]: unknown
9404
+ }
9405
+ | null
9406
+ }
9407
+ | {
9408
+ status: "failed"
9409
+ completedAt: string
9410
+ error: {
9411
+ code:
9412
+ | "internal.unexpected"
9413
+ | "runtime.cancelled"
9414
+ | "action.phase_failed"
9415
+ | "action.read_conflict"
9416
+ | "action.timeout"
9417
+ message: string
9418
+ retryable: boolean
9419
+ at: string
9420
+ details: {
9421
+ actionId: string
9422
+ runId: string
9423
+ phase: "writeback"
9424
+ }
9425
+ httpStatus?: number
9426
+ redacted?: true
9427
+ truncated?: true
9428
+ }
9429
+ }
9430
+ effects?:
9431
+ | {
9432
+ status: "succeeded"
9433
+ completedAt: string
9434
+ }
9435
+ | {
9436
+ status: "failed"
9437
+ completedAt: string
9438
+ error: {
9439
+ code:
9440
+ | "internal.unexpected"
9441
+ | "runtime.cancelled"
9442
+ | "action.phase_failed"
9443
+ | "action.read_conflict"
9444
+ | "action.timeout"
9445
+ message: string
9446
+ retryable: boolean
9447
+ at: string
9448
+ details: {
9449
+ actionId: string
9450
+ runId: string
9451
+ phase: "effects"
9452
+ }
9453
+ httpStatus?: number
9454
+ redacted?: true
9455
+ truncated?: true
9456
+ }
9457
+ }
9284
9458
  }
9285
9459
  }
9286
9460
 
@@ -9426,6 +9600,12 @@ export type UploadFileContentErrors = {
9426
9600
  410: {
9427
9601
  error: string
9428
9602
  }
9603
+ /**
9604
+ * Response for status 413
9605
+ */
9606
+ 413: {
9607
+ error: string
9608
+ }
9429
9609
  /**
9430
9610
  * Response for status 501
9431
9611
  */
@@ -9638,7 +9818,7 @@ export type ListActionRunsData = {
9638
9818
  path?: never
9639
9819
  query?: {
9640
9820
  actionId?: string
9641
- status?: "queued" | "running" | "succeeded" | "failed" | "cancelled"
9821
+ status?: "succeeded" | "failed"
9642
9822
  objectTypeId?: string
9643
9823
  primaryId?: string
9644
9824
  startedAfter?: string
@@ -9685,41 +9865,24 @@ export type ListActionRunsResponses = {
9685
9865
  objectTypeId: string
9686
9866
  primaryId: string
9687
9867
  }
9688
- status: "queued" | "running" | "succeeded" | "failed" | "cancelled"
9689
- phase?:
9690
- | "request"
9691
- | "enqueue"
9692
- | "validation"
9693
- | "writeback"
9694
- | "edits"
9695
- | "commit"
9696
- | "effects"
9697
- | "cancelled"
9698
- queuedAt: string
9699
- startedAt?: string
9700
- finishedAt?: string
9868
+ status: "succeeded" | "failed"
9869
+ phase: "validation" | "writeback" | "edits" | "commit" | "effects"
9870
+ startedAt: string
9871
+ finishedAt: string
9701
9872
  error?: {
9702
9873
  code:
9703
9874
  | "internal.unexpected"
9704
9875
  | "runtime.cancelled"
9705
- | "queue.enqueue_failed"
9706
9876
  | "action.phase_failed"
9707
9877
  | "action.read_conflict"
9878
+ | "action.timeout"
9708
9879
  message: string
9709
9880
  retryable: boolean
9710
9881
  at: string
9711
9882
  details: {
9712
9883
  actionId: string
9713
9884
  runId: string
9714
- phase:
9715
- | "request"
9716
- | "enqueue"
9717
- | "validation"
9718
- | "writeback"
9719
- | "edits"
9720
- | "commit"
9721
- | "effects"
9722
- | "cancelled"
9885
+ phase: "validation" | "writeback" | "edits" | "commit" | "effects"
9723
9886
  }
9724
9887
  httpStatus?: number
9725
9888
  redacted?: true
@@ -9782,41 +9945,24 @@ export type GetActionRunResponses = {
9782
9945
  objectTypeId: string
9783
9946
  primaryId: string
9784
9947
  }
9785
- status: "queued" | "running" | "succeeded" | "failed" | "cancelled"
9786
- phase?:
9787
- | "request"
9788
- | "enqueue"
9789
- | "validation"
9790
- | "writeback"
9791
- | "edits"
9792
- | "commit"
9793
- | "effects"
9794
- | "cancelled"
9795
- queuedAt: string
9796
- startedAt?: string
9797
- finishedAt?: string
9948
+ status: "succeeded" | "failed"
9949
+ phase: "validation" | "writeback" | "edits" | "commit" | "effects"
9950
+ startedAt: string
9951
+ finishedAt: string
9798
9952
  error?: {
9799
9953
  code:
9800
9954
  | "internal.unexpected"
9801
9955
  | "runtime.cancelled"
9802
- | "queue.enqueue_failed"
9803
9956
  | "action.phase_failed"
9804
9957
  | "action.read_conflict"
9958
+ | "action.timeout"
9805
9959
  message: string
9806
9960
  retryable: boolean
9807
9961
  at: string
9808
9962
  details: {
9809
9963
  actionId: string
9810
9964
  runId: string
9811
- phase:
9812
- | "request"
9813
- | "enqueue"
9814
- | "validation"
9815
- | "writeback"
9816
- | "edits"
9817
- | "commit"
9818
- | "effects"
9819
- | "cancelled"
9965
+ phase: "validation" | "writeback" | "edits" | "commit" | "effects"
9820
9966
  }
9821
9967
  httpStatus?: number
9822
9968
  redacted?: true
@@ -9849,9 +9995,9 @@ export type GetActionRunResponses = {
9849
9995
  code:
9850
9996
  | "internal.unexpected"
9851
9997
  | "runtime.cancelled"
9852
- | "queue.enqueue_failed"
9853
9998
  | "action.phase_failed"
9854
9999
  | "action.read_conflict"
10000
+ | "action.timeout"
9855
10001
  message: string
9856
10002
  retryable: boolean
9857
10003
  at: string
@@ -9877,9 +10023,9 @@ export type GetActionRunResponses = {
9877
10023
  code:
9878
10024
  | "internal.unexpected"
9879
10025
  | "runtime.cancelled"
9880
- | "queue.enqueue_failed"
9881
10026
  | "action.phase_failed"
9882
10027
  | "action.read_conflict"
10028
+ | "action.timeout"
9883
10029
  message: string
9884
10030
  retryable: boolean
9885
10031
  at: string
@@ -11998,7 +12144,6 @@ export type ListEventsData = {
11998
12144
  | "objects"
11999
12145
  | "telemetry"
12000
12146
  | "links"
12001
- | "actions"
12002
12147
  | "schedules"
12003
12148
  | "syncs"
12004
12149
  | "pipelines"
@@ -12013,9 +12158,6 @@ export type ListEventsData = {
12013
12158
  | "link.created"
12014
12159
  | "link.updated"
12015
12160
  | "link.deleted"
12016
- | "action.requested"
12017
- | "action.completed"
12018
- | "action.failed"
12019
12161
  | "schedule.triggered"
12020
12162
  | "sync.run.started"
12021
12163
  | "sync.run.finished"
@@ -13201,9 +13343,6 @@ export type ListEventsResponses = {
13201
13343
  | null
13202
13344
  }
13203
13345
  type:
13204
- | "action.requested"
13205
- | "action.completed"
13206
- | "action.failed"
13207
13346
  | "schedule.triggered"
13208
13347
  | "sync.run.started"
13209
13348
  | "sync.run.finished"
@@ -13229,7 +13368,6 @@ export type ListEventsResponses = {
13229
13368
  | "objects"
13230
13369
  | "telemetry"
13231
13370
  | "links"
13232
- | "actions"
13233
13371
  | "schedules"
13234
13372
  | "syncs"
13235
13373
  | "pipelines"
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // Generated SDK surface (modern)
2
2
 
3
- export * from "./actions"
3
+ export type { ActionRunDetail } from "./actions"
4
+ export { ActionRunFailedError } from "./actions"
4
5
  export * from "./agent-streams"
5
6
  export * from "./api"
6
7
  export type {
@@ -30,13 +30,7 @@ import {
30
30
  useQueryClient,
31
31
  } from "@tanstack/react-query"
32
32
  import { useMemo } from "react"
33
- import {
34
- type ActionRunDetail,
35
- ActionRunFailedError,
36
- type ActionWaitOptions,
37
- type RequestActionAndWaitInput,
38
- requestActionAndWait,
39
- } from "./actions"
33
+ import { type ActionRunDetail, ActionRunFailedError, isFailedActionRun } from "./actions"
40
34
  import { SixbProvider, useSixbProviderClient } from "./client-provider"
41
35
  import { type SixbFileUploadError, type UploadFileInput, uploadFile } from "./file"
42
36
  import {
@@ -45,7 +39,12 @@ import {
45
39
  listActionRunsQueryKey,
46
40
  } from "./generated/@tanstack/react-query.gen"
47
41
  import type { Client } from "./generated/client"
48
- import { getBulkTelemetryHistory, getTelemetryHistory, type Options } from "./generated/sdk.gen"
42
+ import {
43
+ getBulkTelemetryHistory,
44
+ getTelemetryHistory,
45
+ type Options,
46
+ requestAction,
47
+ } from "./generated/sdk.gen"
49
48
  import type {
50
49
  GetBulkTelemetryHistoryData,
51
50
  GetTelemetryHistoryData,
@@ -323,20 +322,19 @@ export type ActionRunMutationObjectSubject<
323
322
 
324
323
  export type ActionRunMutationSubject = ActionRunMutationWireSubject | ActionRunMutationObjectSubject
325
324
 
326
- type ActionRunMutationRequestBody = Omit<RequestActionAndWaitInput["body"], "subject"> & {
325
+ type ActionRunMutationRequestBody = Omit<RequestActionData["body"], "subject"> & {
327
326
  readonly subject?: ActionRunMutationSubject
328
327
  }
329
328
 
330
- export type ActionRunMutationRequest = Omit<RequestActionAndWaitInput, "body"> & {
329
+ export type ActionRunMutationRequest = Omit<Options<RequestActionData>, "body"> & {
331
330
  readonly body: ActionRunMutationRequestBody
332
331
  }
333
332
 
334
333
  export interface ActionRunMutationBaseOptions<TVariables, TContext>
335
- extends ActionWaitOptions,
336
- Omit<UseMutationOptions<ActionRunDetail, Error, TVariables, TContext>, "mutationFn"> {
334
+ extends Omit<UseMutationOptions<ActionRunDetail, Error, TVariables, TContext>, "mutationFn"> {
337
335
  /** hey-api client override. Defaults to the nearest SixbProvider client, then the global client. */
338
336
  readonly client?: Client
339
- /** Invalidate action-run caches, and object-query caches when the terminal run committed changes. */
337
+ /** Invalidate action-run caches, and object-query caches when the run committed its edits. */
340
338
  readonly invalidateOnCommit?: boolean
341
339
  /** Override used by tests and non-hook option factory consumers. */
342
340
  readonly queryClient?: QueryClient
@@ -389,11 +387,6 @@ function createActionRunMutationOptions<TVariables, TContext>(
389
387
  actionId,
390
388
  subject,
391
389
  runId,
392
- timeoutMs,
393
- fallbackPollIntervalMs,
394
- disconnectedPollIntervalMs,
395
- signal,
396
- rejectOnTerminalFailure,
397
390
  client,
398
391
  invalidateOnCommit = false,
399
392
  queryClient,
@@ -402,26 +395,20 @@ function createActionRunMutationOptions<TVariables, TContext>(
402
395
  ...mutationOptions
403
396
  } = options ?? {}
404
397
 
405
- const waitOptions: ActionWaitOptions = {
406
- timeoutMs,
407
- fallbackPollIntervalMs,
408
- disconnectedPollIntervalMs,
409
- signal,
410
- rejectOnTerminalFailure,
411
- }
412
-
413
398
  return {
414
399
  ...mutationOptions,
415
- mutationFn: (variables) =>
416
- requestActionAndWait(
417
- buildActionRunMutationRequest(variables, {
418
- actionId,
419
- subject,
420
- runId,
421
- client,
422
- waitOptions,
423
- })
424
- ),
400
+ mutationFn: async (variables) => {
401
+ // The API answers with the terminal run. A failed or cancelled run is the mutation's error,
402
+ // and any other answer throws the API's error response.
403
+ const { data: run } = await requestAction<true>({
404
+ ...buildActionRunMutationRequest(variables, { actionId, subject, runId, client }),
405
+ throwOnError: true,
406
+ })
407
+ if (isFailedActionRun(run)) {
408
+ throw new ActionRunFailedError(run)
409
+ }
410
+ return run
411
+ },
425
412
  onSuccess: async (run, variables, context, mutation) => {
426
413
  if (invalidateOnCommit && queryClient) {
427
414
  await invalidateActionRunMutationCaches(queryClient, run)
@@ -467,14 +454,12 @@ function buildActionRunMutationRequest<TVariables>(
467
454
  readonly subject?: ActionRunMutationSubject
468
455
  readonly runId?: string
469
456
  readonly client?: Client
470
- readonly waitOptions: ActionWaitOptions
471
457
  }
472
- ): RequestActionAndWaitInput {
458
+ ): Options<RequestActionData> {
473
459
  if (options.actionId) {
474
460
  const params = variables === undefined ? undefined : (variables as Record<string, unknown>)
475
461
  const subject = normalizeActionRunMutationSubject(options.subject)
476
462
  return {
477
- ...options.waitOptions,
478
463
  client: options.client,
479
464
  path: { actionId: options.actionId },
480
465
  body: {
@@ -488,7 +473,6 @@ function buildActionRunMutationRequest<TVariables>(
488
473
  if (isActionRunMutationRequest(variables)) {
489
474
  const subject = normalizeActionRunMutationSubject(variables.body.subject)
490
475
  return {
491
- ...options.waitOptions,
492
476
  client: options.client,
493
477
  ...variables,
494
478
  body: {
@@ -544,10 +528,11 @@ async function invalidateActionRunMutationCaches(
544
528
  queryClient.invalidateQueries({ queryKey: listActionRunsInfiniteQueryKey() }),
545
529
  ]
546
530
 
547
- // A run that reached the commit phase may have changed any object the action touched. The run
548
- // record no longer carries a per-object diff — object changes live in the authoritative ontology
549
- // commit — so object reads are invalidated wholesale.
550
- if (run.phase === "commit" || run.phase === "effects") {
531
+ // A run that succeeded in its commit phase, or went on to its effects, committed its edits with
532
+ // its record, and may have changed any object the action touched. A run that failed committed
533
+ // nothing. The record carries no per-object diff — object changes live in the authoritative
534
+ // ontology commit — so object reads are invalidated wholesale.
535
+ if (run.status === "succeeded" && (run.phase === "commit" || run.phase === "effects")) {
551
536
  invalidations.push(
552
537
  invalidateObjectQueries(queryClient),
553
538
  queryClient.invalidateQueries({ predicate: isGeneratedObjectRead })