@sapiom/tools 0.4.0 → 0.6.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 (65) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/README.md +13 -2
  3. package/dist/cjs/client.d.ts +17 -0
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +11 -0
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/content-generation/errors.d.ts +16 -0
  8. package/dist/cjs/content-generation/errors.d.ts.map +1 -0
  9. package/dist/cjs/content-generation/errors.js +36 -0
  10. package/dist/cjs/content-generation/errors.js.map +1 -0
  11. package/dist/cjs/content-generation/index.d.ts +87 -0
  12. package/dist/cjs/content-generation/index.d.ts.map +1 -0
  13. package/dist/cjs/content-generation/index.js +77 -0
  14. package/dist/cjs/content-generation/index.js.map +1 -0
  15. package/dist/cjs/file-storage/errors.d.ts +2 -2
  16. package/dist/cjs/file-storage/errors.js +2 -2
  17. package/dist/cjs/file-storage/index.d.ts +14 -18
  18. package/dist/cjs/file-storage/index.d.ts.map +1 -1
  19. package/dist/cjs/file-storage/index.js +9 -11
  20. package/dist/cjs/file-storage/index.js.map +1 -1
  21. package/dist/cjs/index.d.ts +6 -0
  22. package/dist/cjs/index.d.ts.map +1 -1
  23. package/dist/cjs/index.js +14 -3
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/orchestrations/index.d.ts +101 -0
  26. package/dist/cjs/orchestrations/index.d.ts.map +1 -0
  27. package/dist/cjs/orchestrations/index.js +114 -0
  28. package/dist/cjs/orchestrations/index.js.map +1 -0
  29. package/dist/cjs/stub/index.d.ts.map +1 -1
  30. package/dist/cjs/stub/index.js +55 -4
  31. package/dist/cjs/stub/index.js.map +1 -1
  32. package/dist/esm/client.d.ts +17 -0
  33. package/dist/esm/client.d.ts.map +1 -1
  34. package/dist/esm/client.js +11 -0
  35. package/dist/esm/client.js.map +1 -1
  36. package/dist/esm/content-generation/errors.d.ts +16 -0
  37. package/dist/esm/content-generation/errors.d.ts.map +1 -0
  38. package/dist/esm/content-generation/errors.js +31 -0
  39. package/dist/esm/content-generation/errors.js.map +1 -0
  40. package/dist/esm/content-generation/index.d.ts +87 -0
  41. package/dist/esm/content-generation/index.d.ts.map +1 -0
  42. package/dist/esm/content-generation/index.js +73 -0
  43. package/dist/esm/content-generation/index.js.map +1 -0
  44. package/dist/esm/file-storage/errors.d.ts +2 -2
  45. package/dist/esm/file-storage/errors.js +2 -2
  46. package/dist/esm/file-storage/index.d.ts +14 -18
  47. package/dist/esm/file-storage/index.d.ts.map +1 -1
  48. package/dist/esm/file-storage/index.js +9 -11
  49. package/dist/esm/file-storage/index.js.map +1 -1
  50. package/dist/esm/index.d.ts +6 -0
  51. package/dist/esm/index.d.ts.map +1 -1
  52. package/dist/esm/index.js +7 -0
  53. package/dist/esm/index.js.map +1 -1
  54. package/dist/esm/orchestrations/index.d.ts +101 -0
  55. package/dist/esm/orchestrations/index.d.ts.map +1 -0
  56. package/dist/esm/orchestrations/index.js +108 -0
  57. package/dist/esm/orchestrations/index.js.map +1 -0
  58. package/dist/esm/stub/index.d.ts.map +1 -1
  59. package/dist/esm/stub/index.js +51 -0
  60. package/dist/esm/stub/index.js.map +1 -1
  61. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  62. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  63. package/package.json +6 -1
  64. package/src/content-generation/README.md +61 -0
  65. package/src/file-storage/README.md +12 -15
@@ -0,0 +1,87 @@
1
+ /**
2
+ * `contentGeneration` capability — generate media (images today; video and audio
3
+ * to come), with an optional `storage` param that persists each output to Sapiom
4
+ * file storage so you get a durable `fileId` back inline.
5
+ *
6
+ * import { contentGeneration } from "@sapiom/tools"; // ambient auth
7
+ * const out = await contentGeneration.images.create({
8
+ * prompt: "a red bicycle",
9
+ * storage: { visibility: "private" }, // optional — persist outputs
10
+ * });
11
+ * out.images[0].url; // hosted URL of the generated image
12
+ * out.images[0].fileId; // present when `storage` was passed → use with fileStorage
13
+ *
14
+ * Or via an explicit client: `createClient({ apiKey }).contentGeneration.images.create(...)`.
15
+ */
16
+ import { Transport } from "../_client/index.js";
17
+ import { ContentGenerationHttpError } from "./errors.js";
18
+ export { ContentGenerationHttpError };
19
+ export interface StorageOptions {
20
+ /**
21
+ * Visibility of the persisted output.
22
+ * - "private" — download requires the owning tenant (default).
23
+ * - "public" — download URL is reachable by any tenant.
24
+ */
25
+ visibility?: "private" | "public";
26
+ }
27
+ export interface ImageCreateInput {
28
+ /** Text prompt describing the image to generate. */
29
+ prompt: string;
30
+ /** Number of images to generate. */
31
+ numImages?: number;
32
+ /**
33
+ * Optional model selector. Defaults to a fast image model; most callers omit it.
34
+ * (Model identifiers are an advanced, evolving surface.)
35
+ */
36
+ model?: string;
37
+ /**
38
+ * Optional: persist each generated output to Sapiom file storage. When set, every
39
+ * item in `images` comes back annotated with `fileId` (or `storageError` if
40
+ * persisting that one failed).
41
+ */
42
+ storage?: StorageOptions;
43
+ /**
44
+ * Advanced: extra model-specific parameters, forwarded verbatim
45
+ * (e.g. `image_size`, `seed`, `guidance_scale`).
46
+ */
47
+ params?: Record<string, unknown>;
48
+ }
49
+ export interface GeneratedImage {
50
+ /** Hosted URL of the generated image. */
51
+ url: string;
52
+ /** MIME type, when reported. */
53
+ contentType?: string;
54
+ width?: number;
55
+ height?: number;
56
+ /**
57
+ * Present when `storage` was requested and this output was persisted — pass to
58
+ * `fileStorage.getDownloadUrl(fileId)` to retrieve it.
59
+ */
60
+ fileId?: string;
61
+ /**
62
+ * Present when `storage` was requested but persisting THIS output failed
63
+ * (best-effort: other images in the same response may still carry `fileId`).
64
+ */
65
+ storageError?: string;
66
+ }
67
+ export interface ImageGenerationResult {
68
+ /** Generated images. */
69
+ images?: GeneratedImage[];
70
+ /** Additional model-specific fields (e.g. `seed`, `timings`), returned as-is. */
71
+ [key: string]: unknown;
72
+ }
73
+ /**
74
+ * Generate one or more images from a prompt. Pass `storage` to persist each output
75
+ * (the returned images then carry `fileId`). Failed requests throw
76
+ * {@link ContentGenerationHttpError}.
77
+ */
78
+ export declare function createImage(input: ImageCreateInput, transport?: Transport, baseUrl?: string): Promise<ImageGenerationResult>;
79
+ /**
80
+ * The `images` sub-namespace, so `contentGeneration.images.create(...)` reads the
81
+ * same whether imported from the barrel or used on a client. Video and audio will
82
+ * land here as sibling sub-namespaces.
83
+ */
84
+ export declare const images: {
85
+ create: typeof createImage;
86
+ };
87
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAY,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAUtC,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;CACnC;AAED,MAAM,WAAW,gBAAgB;IAC/B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,wBAAwB;IACxB,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;IAC1B,iFAAiF;IACjF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AA2CD;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,gBAAgB,EACvB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,qBAAqB,CAAC,CAqBhC;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM;;CAA0B,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `contentGeneration` capability — generate media (images today; video and audio
3
+ * to come), with an optional `storage` param that persists each output to Sapiom
4
+ * file storage so you get a durable `fileId` back inline.
5
+ *
6
+ * import { contentGeneration } from "@sapiom/tools"; // ambient auth
7
+ * const out = await contentGeneration.images.create({
8
+ * prompt: "a red bicycle",
9
+ * storage: { visibility: "private" }, // optional — persist outputs
10
+ * });
11
+ * out.images[0].url; // hosted URL of the generated image
12
+ * out.images[0].fileId; // present when `storage` was passed → use with fileStorage
13
+ *
14
+ * Or via an explicit client: `createClient({ apiKey }).contentGeneration.images.create(...)`.
15
+ */
16
+ import { defaultTransport } from "../_client/index.js";
17
+ import { ensureOk, ContentGenerationHttpError } from "./errors.js";
18
+ export { ContentGenerationHttpError };
19
+ const DEFAULT_BASE_URL = process.env.SAPIOM_CONTENT_GENERATION_URL || "https://fal.services.sapiom.ai";
20
+ /** Default image model when the caller doesn't pick one — a fast, low-cost model. */
21
+ const DEFAULT_IMAGE_MODEL = "fal-ai/flux/schnell";
22
+ function mapImage(raw) {
23
+ return {
24
+ url: raw.url,
25
+ ...(raw.content_type !== undefined && { contentType: raw.content_type }),
26
+ ...(raw.width !== undefined && { width: raw.width }),
27
+ ...(raw.height !== undefined && { height: raw.height }),
28
+ ...(raw.file_id !== undefined && { fileId: raw.file_id }),
29
+ ...(raw.storage_error !== undefined && { storageError: raw.storage_error }),
30
+ };
31
+ }
32
+ function mapResult(raw) {
33
+ const { images, ...rest } = raw;
34
+ return images === undefined
35
+ ? { ...rest }
36
+ : { ...rest, images: images.map(mapImage) };
37
+ }
38
+ // ----- Capability operations -----
39
+ /** Encode a model id into a URL path, preserving its `/` separators. */
40
+ function modelToPath(model) {
41
+ return model.split("/").filter(Boolean).map(encodeURIComponent).join("/");
42
+ }
43
+ /**
44
+ * Generate one or more images from a prompt. Pass `storage` to persist each output
45
+ * (the returned images then carry `fileId`). Failed requests throw
46
+ * {@link ContentGenerationHttpError}.
47
+ */
48
+ export async function createImage(input, transport = defaultTransport(), baseUrl = DEFAULT_BASE_URL) {
49
+ const path = modelToPath(input.model || DEFAULT_IMAGE_MODEL);
50
+ const body = {
51
+ prompt: input.prompt,
52
+ ...input.params,
53
+ };
54
+ if (input.numImages !== undefined)
55
+ body.num_images = input.numImages;
56
+ // Truthy check (not `!== undefined`) so a caller passing `storage: null` is
57
+ // treated as "no storage" rather than sending a null field.
58
+ if (input.storage)
59
+ body.storage = input.storage;
60
+ const res = await ensureOk(await transport.fetch(`${baseUrl}/run/${path}`, {
61
+ method: "POST",
62
+ headers: { "content-type": "application/json" },
63
+ body: JSON.stringify(body),
64
+ }), "Failed to generate image");
65
+ return mapResult((await res.json()));
66
+ }
67
+ /**
68
+ * The `images` sub-namespace, so `contentGeneration.images.create(...)` reads the
69
+ * same whether imported from the barrel or used on a client. Video and audio will
70
+ * land here as sibling sub-namespaces.
71
+ */
72
+ export const images = { create: createImage };
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAa,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,aA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AAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5E,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAuB,EACvB,YAAuB,gBAAgB,EAAE,EACzC,OAAO,GAAG,gBAAgB;IAE1B,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,IAAI,mBAAmB,CAAC,CAAC;IAE7D,MAAM,IAAI,GAA4B;QACpC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,GAAG,KAAK,CAAC,MAAM;KAChB,CAAC;IACF,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;QAAE,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC;IACrE,4EAA4E;IAC5E,4DAA4D;IAC5D,IAAI,KAAK,CAAC,OAAO;QAAE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAEhD,MAAM,GAAG,GAAG,MAAM,QAAQ,CACxB,MAAM,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,IAAI,EAAE,EAAE;QAC9C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,EACF,0BAA0B,CAC3B,CAAC;IACF,OAAO,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAmB,CAAC,CAAC;AACzD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC"}
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Error thrown by the file-storage capability when the gateway returns a non-2xx
3
- * response. Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
2
+ * Error thrown by the file-storage capability when a request fails (non-2xx
3
+ * response). Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
4
4
  * raw text when the body isn't JSON) for programmatic inspection.
5
5
  */
6
6
  export declare class FileStorageHttpError extends Error {
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Error thrown by the file-storage capability when the gateway returns a non-2xx
3
- * response. Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
2
+ * Error thrown by the file-storage capability when a request fails (non-2xx
3
+ * response). Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
4
4
  * raw text when the body isn't JSON) for programmatic inspection.
5
5
  */
6
6
  export class FileStorageHttpError extends Error {
@@ -1,8 +1,8 @@
1
1
  /**
2
- * `fileStorage` capability — tenant-scoped object storage on presigned GCS URLs.
2
+ * `fileStorage` capability — tenant-scoped object storage with presigned URLs.
3
3
  *
4
- * The control plane only: `upload` hands back a presigned URL you PUT the bytes to
5
- * yourself (so you own streaming / progress / resumable uploads), and
4
+ * You transfer the bytes yourself: `upload` hands back a presigned URL you PUT the
5
+ * bytes to (so you own streaming / progress / resumable uploads), and
6
6
  * `getDownloadUrl` hands back a presigned URL you GET. `list`, `setVisibility`, and
7
7
  * `delete` round out the lifecycle.
8
8
  *
@@ -15,9 +15,8 @@
15
15
  *
16
16
  * Or via an explicit client: `createClient({ apiKey }).fileStorage.upload(...)`.
17
17
  *
18
- * Wire fields are snake_case; this module maps them to the camelCase SDK surface.
19
- * Byte counts are int64 the gateway serializes them as strings (precision-safe),
20
- * so `expectedFileSize` / `actualFileSize` on returned metadata are `string | null`.
18
+ * Byte-size fields (`expectedFileSize` / `actualFileSize` on returned metadata) are
19
+ * returned as `string | null` to stay precise for large files.
21
20
  */
22
21
  import { Transport } from "../_client/index.js";
23
22
  import { FileStorageHttpError } from "./errors.js";
@@ -33,13 +32,13 @@ export interface UploadInput {
33
32
  * - "public" — download URL is unauthenticated.
34
33
  */
35
34
  visibility?: "private" | "public";
36
- /** Expected file size in bytes. Used to pre-allocate storage. */
35
+ /** Expected file size in bytes. */
37
36
  expectedFileSize?: number;
38
37
  }
39
38
  export interface UploadResponse {
40
39
  /** Unique file identifier. Use this in subsequent calls. */
41
40
  fileId: string;
42
- /** GCS presigned upload URL. PUT the file bytes here directly. Expires at `expiresAt`. */
41
+ /** Presigned upload URL. PUT the file bytes here directly. Expires at `expiresAt`. */
43
42
  uploadUrl: string;
44
43
  /** ISO-8601 timestamp when the upload URL expires. */
45
44
  expiresAt: string;
@@ -47,7 +46,7 @@ export interface UploadResponse {
47
46
  requiredHeaders: Record<string, string>;
48
47
  }
49
48
  export interface DownloadUrlResponse {
50
- /** Presigned GCS download URL. Expires at `expiresAt`. */
49
+ /** Presigned download URL. Expires at `expiresAt`. */
51
50
  downloadUrl: string;
52
51
  /** ISO-8601 timestamp when the download URL expires. */
53
52
  expiresAt: string;
@@ -63,12 +62,9 @@ export interface FileMetadata {
63
62
  visibility: "private" | "public";
64
63
  /** Upload lifecycle status (e.g. "pending_upload", "uploaded", "deleted"). */
65
64
  status: string;
66
- /**
67
- * Expected (client-declared) size in bytes — a string (int64, precision-safe),
68
- * `null` when not declared.
69
- */
65
+ /** Expected (client-declared) size in bytes — a string, `null` when not declared. */
70
66
  expectedFileSize?: string | null;
71
- /** Actual size in bytes after upload (string; `null` until the verify sweep records it). */
67
+ /** Actual size in bytes after upload (string; `null` until the upload is verified). */
72
68
  actualFileSize?: string | null;
73
69
  /** ISO-8601 timestamp when the record was created. */
74
70
  createdAt: string;
@@ -96,8 +92,8 @@ export interface ListResponse {
96
92
  hasMore: boolean;
97
93
  }
98
94
  /**
99
- * Initiate an upload. Returns a presigned GCS URL; PUT the bytes to `uploadUrl`
100
- * with `requiredHeaders` yourself (this capability owns only the control plane).
95
+ * Initiate an upload. Returns a presigned URL; PUT the bytes to `uploadUrl` with
96
+ * `requiredHeaders` yourself.
101
97
  */
102
98
  export declare function upload(input: UploadInput, transport?: Transport, baseUrl?: string): Promise<UploadResponse>;
103
99
  /** Generate a presigned download URL for a file. */
@@ -107,8 +103,8 @@ export declare function list(opts?: ListOptions, transport?: Transport, baseUrl?
107
103
  /** Update a file's visibility. */
108
104
  export declare function setVisibility(fileId: string, visibility: "private" | "public", transport?: Transport, baseUrl?: string): Promise<FileMetadata>;
109
105
  /**
110
- * Delete a file. Idempotent on the gateway (deleting an already-deleted file is a
111
- * no-op success). Exported as `delete`:
106
+ * Delete a file. Idempotent (deleting an already-deleted file is a no-op success).
107
+ * Exported as `delete`:
112
108
  * `import { fileStorage } from "@sapiom/tools"; await fileStorage.delete(id)`.
113
109
  */
114
110
  declare function deleteFile(fileId: string, transport?: Transport, baseUrl?: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/file-storage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAY,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAShC,MAAM,WAAW,WAAW;IAC1B,2EAA2E;IAC3E,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;IAClC,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,0FAA0F;IAC1F,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YA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M,EAAE,MAAM,EACd,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAO9B;AAED,oDAAoD;AACpD,wBAAsB,IAAI,CACxB,IAAI,CAAC,EAAE,WAAW,EAClB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,YAAY,CAAC,CAmBvB;AAED,kCAAkC;AAClC,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,SAAS,GAAG,QAAQ,EAChC,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,YAAY,CAAC,CAWvB;AAED;;;;GAIG;AACH,iBAAe,UAAU,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,CAAC"}
@@ -1,8 +1,8 @@
1
1
  /**
2
- * `fileStorage` capability — tenant-scoped object storage on presigned GCS URLs.
2
+ * `fileStorage` capability — tenant-scoped object storage with presigned URLs.
3
3
  *
4
- * The control plane only: `upload` hands back a presigned URL you PUT the bytes to
5
- * yourself (so you own streaming / progress / resumable uploads), and
4
+ * You transfer the bytes yourself: `upload` hands back a presigned URL you PUT the
5
+ * bytes to (so you own streaming / progress / resumable uploads), and
6
6
  * `getDownloadUrl` hands back a presigned URL you GET. `list`, `setVisibility`, and
7
7
  * `delete` round out the lifecycle.
8
8
  *
@@ -15,14 +15,12 @@
15
15
  *
16
16
  * Or via an explicit client: `createClient({ apiKey }).fileStorage.upload(...)`.
17
17
  *
18
- * Wire fields are snake_case; this module maps them to the camelCase SDK surface.
19
- * Byte counts are int64 the gateway serializes them as strings (precision-safe),
20
- * so `expectedFileSize` / `actualFileSize` on returned metadata are `string | null`.
18
+ * Byte-size fields (`expectedFileSize` / `actualFileSize` on returned metadata) are
19
+ * returned as `string | null` to stay precise for large files.
21
20
  */
22
21
  import { defaultTransport } from "../_client/index.js";
23
22
  import { ensureOk, FileStorageHttpError } from "./errors.js";
24
23
  export { FileStorageHttpError };
25
- /** Object storage service. Host routing is an internal detail — override via SAPIOM_FILE_STORAGE_URL. */
26
24
  const DEFAULT_BASE_URL = process.env.SAPIOM_FILE_STORAGE_URL ||
27
25
  "https://file-storage.services.sapiom.ai";
28
26
  function mapFileMetadata(raw) {
@@ -46,8 +44,8 @@ function mapFileMetadata(raw) {
46
44
  }
47
45
  // ----- capability operations -----
48
46
  /**
49
- * Initiate an upload. Returns a presigned GCS URL; PUT the bytes to `uploadUrl`
50
- * with `requiredHeaders` yourself (this capability owns only the control plane).
47
+ * Initiate an upload. Returns a presigned URL; PUT the bytes to `uploadUrl` with
48
+ * `requiredHeaders` yourself.
51
49
  */
52
50
  export async function upload(input, transport = defaultTransport(), baseUrl = DEFAULT_BASE_URL) {
53
51
  const body = { content_type: input.contentType };
@@ -106,8 +104,8 @@ export async function setVisibility(fileId, visibility, transport = defaultTrans
106
104
  return mapFileMetadata(raw);
107
105
  }
108
106
  /**
109
- * Delete a file. Idempotent on the gateway (deleting an already-deleted file is a
110
- * no-op success). Exported as `delete`:
107
+ * Delete a file. Idempotent (deleting an already-deleted file is a no-op success).
108
+ * Exported as `delete`:
111
109
  * `import { fileStorage } from "@sapiom/tools"; await fileStorage.delete(id)`.
112
110
  */
113
111
  async function deleteFile(fileId, transport = defaultTransport(), baseUrl = DEFAULT_BASE_URL) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/file-storage/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAa,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,yGAAyG;AACzG,MA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AE,OAAO;QACf,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC;KACrC,CAAC,EACF,sCAAsC,MAAM,GAAG,CAChD,CAAC;IACF,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAoB,CAAC;IAClD,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,UAAU,CACvB,MAAc,EACd,YAAuB,gBAAgB,EAAE,EACzC,OAAO,GAAG,gBAAgB;IAE1B,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,KAAK,CAC/B,GAAG,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,EAC1C,EAAE,MAAM,EAAE,QAAQ,EAAE,CACrB,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9C,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,oBAAoB,CAC5B,0BAA0B,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,EAC1D,GAAG,CAAC,MAAM,EACV,MAAM,CACP,CAAC;IACJ,CAAC;IACD,qCAAqC;AACvC,CAAC;AAED,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,CAAC"}
@@ -23,6 +23,12 @@ export * as agent from "./agent/index.js";
23
23
  export { CODING_RESULT_SIGNAL } from "./agent/index.js";
24
24
  export type { CodingResultPayload, ExecutionEnvironmentRef, } from "./agent/index.js";
25
25
  export { codingResultSchema, CodingResultSchemaError, toResumePayload, EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX, } from "./agent/index.js";
26
+ export * as orchestrations from "./orchestrations/index.js";
27
+ export { ORCHESTRATIONS_RESULT_SIGNAL } from "./orchestrations/index.js";
28
+ export type { OrchestrationRunResultPayload } from "./orchestrations/index.js";
29
+ export { orchestrationResultSchema, OrchestrationResultSchemaError } from "./orchestrations/index.js";
26
30
  export * as fileStorage from "./file-storage/index.js";
27
31
  export { FileStorageHttpError } from "./file-storage/index.js";
32
+ export * as contentGeneration from "./content-generation/index.js";
33
+ export { ContentGenerationHttpError } from "./content-generation/index.js";
28
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAIvE,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,YAAY,EACV,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;A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C;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/esm/index.js CHANGED
@@ -22,6 +22,13 @@ export { CODING_RESULT_SIGNAL } from "./agent/index.js";
22
22
  // Validate / build a `CodingResultPayload`, and the env `type` whose `id` is a
23
23
  // sandbox name for `sandboxes.attach(id)`.
24
24
  export { codingResultSchema, CodingResultSchemaError, toResumePayload, EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX, } from "./agent/index.js";
25
+ export * as orchestrations from "./orchestrations/index.js";
26
+ // Surfaced top-level for the static `pause: { signal }` decl on a workflow step.
27
+ export { ORCHESTRATIONS_RESULT_SIGNAL } from "./orchestrations/index.js";
28
+ // Validate an OrchestrationRunResultPayload at the resume boundary.
29
+ export { orchestrationResultSchema, OrchestrationResultSchemaError } from "./orchestrations/index.js";
25
30
  export * as fileStorage from "./file-storage/index.js";
26
31
  export { FileStorageHttpError } from "./file-storage/index.js";
32
+ export * as contentGeneration from "./content-generation/index.js";
33
+ export { ContentGenerationHttpError } from "./content-generation/index.js";
27
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQhE,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,iFAAiF;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAOxD,+EAA+E;AAC/E,2CAA2C;AAC3C,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAQhE,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,YAAY,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAC;AAC1C,iFAAiF;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAOxD,+EAA+E;AAC/E,2CAA2C;AAC3C,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,eAAe,EACf,oCAAoC,GACrC,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,cAAc,MAAM,2BAA2B,CAAC;AAC5D,iFAAiF;AACjF,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAIzE,oEAAoE;AACpE,OAAO,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAEtG,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * `orchestrations` capability — run a deployed orchestration, and (the headline
3
+ * use) dispatch one FROM a step and pause until it finishes.
4
+ *
5
+ * import { orchestrations } from "@sapiom/tools";
6
+ * // dispatch another orchestration and pause this step on its result:
7
+ * const child = await orchestrations.launch({ definition: "enrich-lead", input });
8
+ * return pauseUntilSignal(child, { resumeStep: "use-result" });
9
+ * // the resumed step receives an OrchestrationRunResultPayload
10
+ *
11
+ * `launch` returns a handle to pass straight to `pauseUntilSignal` (the waiting
12
+ * step resumes when the run finishes) or to `wait()` inline for standalone use.
13
+ * `run` is `launch` + `wait` — it blocks until the run reaches a terminal state, so
14
+ * use it for inline standalone calls, NOT to pause a step (it returns a result, not
15
+ * a pausable handle). An orchestration is addressed by its **slug** (its stable handle).
16
+ */
17
+ import { Transport } from "../_client/index.js";
18
+ import type { DispatchHandle } from "../dispatch.js";
19
+ /**
20
+ * Signal a run fires when it reaches a terminal state (completed OR failed — the
21
+ * payload carries which, the resumed step branches). A step paused on an
22
+ * orchestration handle resumes on this; it is the value carried in the handle's
23
+ * `dispatch.resultSignal`.
24
+ */
25
+ export declare const ORCHESTRATIONS_RESULT_SIGNAL = "orchestrations.result";
26
+ /** Run lifecycle status. */
27
+ export type ExecutionStatus = "running" | "paused" | "completed" | "failed" | "cancelled";
28
+ export interface OrchestrationRunSpec {
29
+ /** Slug of the deployed orchestration to run (its stable handle). */
30
+ definition: string;
31
+ /** Input passed to the orchestration's entry step. */
32
+ input?: Record<string, unknown>;
33
+ /** Optional idempotency key — a repeat with the same key returns the existing run. */
34
+ idempotencyKey?: string;
35
+ }
36
+ /** A live, awaited run (the standalone `run()`/`wait()` result). */
37
+ export interface OrchestrationRunResult {
38
+ executionId: string;
39
+ status: ExecutionStatus;
40
+ output: unknown;
41
+ error: unknown;
42
+ }
43
+ /**
44
+ * The typed result delivered to the step resumed from `pauseUntilSignal(handle, …)`
45
+ * — the payload that step receives as its `input`. Discriminated on `status` so a
46
+ * FAILURE is data the author branches on, not an exception.
47
+ *
48
+ * const useResult = defineStep({
49
+ * name: "use-result",
50
+ * async run(result: OrchestrationRunResultPayload, ctx) {
51
+ * if (result.status === "failed") { … }
52
+ * },
53
+ * });
54
+ */
55
+ export type OrchestrationRunResultPayload<TOutput = unknown> = {
56
+ status: "completed";
57
+ executionId: string;
58
+ definition: string;
59
+ version: string;
60
+ output: TOutput;
61
+ startedAt: string;
62
+ finishedAt: string;
63
+ } | {
64
+ status: "failed";
65
+ executionId: string;
66
+ definition: string;
67
+ version: string;
68
+ error: unknown;
69
+ startedAt: string;
70
+ finishedAt: string;
71
+ };
72
+ /** Thrown by {@link orchestrationResultSchema}.parse on a malformed resume payload. */
73
+ export declare class OrchestrationResultSchemaError extends Error {
74
+ }
75
+ /**
76
+ * Runtime validator for {@link OrchestrationRunResultPayload}. `parse` returns the
77
+ * value typed on success and throws an {@link OrchestrationResultSchemaError} on any
78
+ * divergence. Generic in the caller's expected `output` type — the shape of
79
+ * `output` itself is the child orchestration's contract, not validated here.
80
+ */
81
+ export declare const orchestrationResultSchema: {
82
+ parse<TOutput = unknown>(value: unknown): OrchestrationRunResultPayload<TOutput>;
83
+ };
84
+ /**
85
+ * A launched-but-not-awaited child run. Satisfies {@link DispatchHandle}, so it can
86
+ * be handed straight to `pauseUntilSignal(handle, { resumeStep })` to suspend the
87
+ * step until the child finishes — or `wait()`-ed inline for standalone use.
88
+ */
89
+ export interface RunHandle extends DispatchHandle {
90
+ executionId: string;
91
+ /** Fetch the current status without blocking. */
92
+ status(): Promise<ExecutionStatus>;
93
+ /** Poll to a terminal state and resolve the run result. */
94
+ wait(opts?: {
95
+ timeoutMs?: number;
96
+ pollMs?: number;
97
+ }): Promise<OrchestrationRunResult>;
98
+ }
99
+ export declare function launch(spec: OrchestrationRunSpec, transport?: Transport, baseUrl?: string): Promise<RunHandle>;
100
+ export declare function run(spec: OrchestrationRunSpec, transport?: Transport, baseUrl?: string): Promise<OrchestrationRunResult>;
101
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/orchestrations/index.ts"],"names":[],"mappings":"AA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,KAAK;CAAG;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB;UAC9B,OAAO,mBAAmB,OAAO,GAAG,6BAA6B,CAAC,OAAO,CAAC;CAuBjF,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,SAAU,SAAQ,cAAc;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,MAAM,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IACnC,2DAA2D;IAC3D,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CACvF;AA4BD,wBAAsB,MAAM,CAC1B,IAAI,EAAE,oBAAoB,EAC1B,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,SAAS,CAAC,CAyCpB;AAED,wBAAsB,GAAG,CACvB,IAAI,EAAE,oBAAoB,EAC1B,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAGjC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * `orchestrations` capability — run a deployed orchestration, and (the headline
3
+ * use) dispatch one FROM a step and pause until it finishes.
4
+ *
5
+ * import { orchestrations } from "@sapiom/tools";
6
+ * // dispatch another orchestration and pause this step on its result:
7
+ * const child = await orchestrations.launch({ definition: "enrich-lead", input });
8
+ * return pauseUntilSignal(child, { resumeStep: "use-result" });
9
+ * // the resumed step receives an OrchestrationRunResultPayload
10
+ *
11
+ * `launch` returns a handle to pass straight to `pauseUntilSignal` (the waiting
12
+ * step resumes when the run finishes) or to `wait()` inline for standalone use.
13
+ * `run` is `launch` + `wait` — it blocks until the run reaches a terminal state, so
14
+ * use it for inline standalone calls, NOT to pause a step (it returns a result, not
15
+ * a pausable handle). An orchestration is addressed by its **slug** (its stable handle).
16
+ */
17
+ import { defaultTransport } from "../_client/index.js";
18
+ const DEFAULT_BASE_URL = process.env.SAPIOM_WORKFLOWS_URL || "https://workflows.services.sapiom.ai";
19
+ /**
20
+ * Signal a run fires when it reaches a terminal state (completed OR failed — the
21
+ * payload carries which, the resumed step branches). A step paused on an
22
+ * orchestration handle resumes on this; it is the value carried in the handle's
23
+ * `dispatch.resultSignal`.
24
+ */
25
+ export const ORCHESTRATIONS_RESULT_SIGNAL = "orchestrations.result";
26
+ const TERMINAL = new Set(["completed", "failed", "cancelled"]);
27
+ /** Thrown by {@link orchestrationResultSchema}.parse on a malformed resume payload. */
28
+ export class OrchestrationResultSchemaError extends Error {
29
+ }
30
+ /**
31
+ * Runtime validator for {@link OrchestrationRunResultPayload}. `parse` returns the
32
+ * value typed on success and throws an {@link OrchestrationResultSchemaError} on any
33
+ * divergence. Generic in the caller's expected `output` type — the shape of
34
+ * `output` itself is the child orchestration's contract, not validated here.
35
+ */
36
+ export const orchestrationResultSchema = {
37
+ parse(value) {
38
+ const fail = (msg) => {
39
+ throw new OrchestrationResultSchemaError(`invalid orchestration result payload: ${msg}`);
40
+ };
41
+ if (!value || typeof value !== "object")
42
+ fail("not an object");
43
+ const v = value;
44
+ if (v.status !== "completed" && v.status !== "failed")
45
+ fail("status must be 'completed' or 'failed'");
46
+ if (typeof v.executionId !== "string")
47
+ fail("executionId must be a string");
48
+ if (typeof v.definition !== "string")
49
+ fail("definition must be a string");
50
+ if (typeof v.version !== "string")
51
+ fail("version must be a string");
52
+ if (typeof v.startedAt !== "string")
53
+ fail("startedAt must be a string");
54
+ if (typeof v.finishedAt !== "string")
55
+ fail("finishedAt must be a string");
56
+ if (v.status === "completed" && !("output" in v))
57
+ fail("a completed result must carry `output`");
58
+ if (v.status === "failed" && !("error" in v))
59
+ fail("a failed result must carry `error`");
60
+ return value;
61
+ },
62
+ };
63
+ /**
64
+ * Inside a Sapiom workflow a resume token is provided via the environment;
65
+ * forwarding it (as a header, not a body field) lets the run resume the waiting
66
+ * step when it finishes. Outside a workflow there's no token, so nothing is sent.
67
+ */
68
+ function workflowResumeHeaders() {
69
+ const token = process.env.SAPIOM_CAPABILITY_RESUME_TOKEN;
70
+ return token ? { "x-sapiom-workflow-token": token } : {};
71
+ }
72
+ export async function launch(spec, transport = defaultTransport(), baseUrl = DEFAULT_BASE_URL) {
73
+ const res = await transport.request(`${baseUrl}/v1/workflows/${encodeURIComponent(spec.definition)}/executions`, {
74
+ method: "POST",
75
+ body: JSON.stringify({ input: spec.input ?? {}, idempotencyKey: spec.idempotencyKey }),
76
+ headers: workflowResumeHeaders(),
77
+ });
78
+ const executionId = res.executionId;
79
+ const fetchDoc = () => transport.request(`${baseUrl}/v1/workflows/executions/${encodeURIComponent(executionId)}`);
80
+ return {
81
+ executionId,
82
+ // Framework plumbing for `pauseUntilSignal` — see DispatchHandle. correlationId
83
+ // is this run's id (the resume's correlation key).
84
+ dispatch: { correlationId: executionId, resultSignal: ORCHESTRATIONS_RESULT_SIGNAL },
85
+ async status() {
86
+ return (await fetchDoc()).status;
87
+ },
88
+ async wait({ timeoutMs = 60 * 60000, pollMs = 3000 } = {}) {
89
+ const deadline = Date.now() + timeoutMs;
90
+ // eslint-disable-next-line no-constant-condition
91
+ while (true) {
92
+ const d = await fetchDoc();
93
+ if (TERMINAL.has(d.status)) {
94
+ return { executionId, status: d.status, output: d.output ?? null, error: d.error ?? null };
95
+ }
96
+ if (Date.now() > deadline) {
97
+ throw new Error(`orchestration ${executionId} timed out after ${timeoutMs}ms (last status: ${d.status})`);
98
+ }
99
+ await new Promise((r) => setTimeout(r, pollMs));
100
+ }
101
+ },
102
+ };
103
+ }
104
+ export async function run(spec, transport = defaultTransport(), baseUrl = DEFAULT_BASE_URL) {
105
+ const handle = await launch(spec, transport, baseUrl);
106
+ return handle.wait();
107
+ }
108
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/orchestrations/index.ts"],"names":[],"mappings":"AAAA;;;;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