@sapiom/tools 0.4.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +13 -2
  3. package/dist/cjs/client.d.ts +10 -0
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +6 -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 +2 -0
  22. package/dist/cjs/index.d.ts.map +1 -1
  23. package/dist/cjs/index.js +4 -1
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/stub/index.d.ts.map +1 -1
  26. package/dist/cjs/stub/index.js +16 -0
  27. package/dist/cjs/stub/index.js.map +1 -1
  28. package/dist/esm/client.d.ts +10 -0
  29. package/dist/esm/client.d.ts.map +1 -1
  30. package/dist/esm/client.js +6 -0
  31. package/dist/esm/client.js.map +1 -1
  32. package/dist/esm/content-generation/errors.d.ts +16 -0
  33. package/dist/esm/content-generation/errors.d.ts.map +1 -0
  34. package/dist/esm/content-generation/errors.js +31 -0
  35. package/dist/esm/content-generation/errors.js.map +1 -0
  36. package/dist/esm/content-generation/index.d.ts +87 -0
  37. package/dist/esm/content-generation/index.d.ts.map +1 -0
  38. package/dist/esm/content-generation/index.js +73 -0
  39. package/dist/esm/content-generation/index.js.map +1 -0
  40. package/dist/esm/file-storage/errors.d.ts +2 -2
  41. package/dist/esm/file-storage/errors.js +2 -2
  42. package/dist/esm/file-storage/index.d.ts +14 -18
  43. package/dist/esm/file-storage/index.d.ts.map +1 -1
  44. package/dist/esm/file-storage/index.js +9 -11
  45. package/dist/esm/file-storage/index.js.map +1 -1
  46. package/dist/esm/index.d.ts +2 -0
  47. package/dist/esm/index.d.ts.map +1 -1
  48. package/dist/esm/index.js +2 -0
  49. package/dist/esm/index.js.map +1 -1
  50. package/dist/esm/stub/index.d.ts.map +1 -1
  51. package/dist/esm/stub/index.js +16 -0
  52. package/dist/esm/stub/index.js.map +1 -1
  53. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  54. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  55. package/package.json +6 -1
  56. package/src/content-generation/README.md +61 -0
  57. package/src/file-storage/README.md +12 -15
@@ -0,0 +1,61 @@
1
+ # contentGeneration
2
+
3
+ Generate media — images today (video and audio to come) — with an optional
4
+ `storage` param that persists each output to Sapiom file storage, so you get a
5
+ durable `fileId` back inline.
6
+
7
+ ```typescript
8
+ import { createClient } from "@sapiom/tools";
9
+ const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
10
+
11
+ const out = await sapiom.contentGeneration.images.create({
12
+ prompt: "a red bicycle",
13
+ storage: { visibility: "private" }, // optional — persist outputs to file storage
14
+ });
15
+
16
+ out.images[0].url; // hosted URL of the generated image
17
+ out.images[0].fileId; // present when `storage` was passed — use with `fileStorage`
18
+ ```
19
+
20
+ Ambient import works too: `import { contentGeneration } from "@sapiom/tools"`.
21
+
22
+ ## The optional `storage` param
23
+
24
+ Pass `storage` and each generated output is persisted to your tenant's file
25
+ storage as it returns — no extra round-trip. Each item in `images` is then
26
+ annotated with its own `fileId`:
27
+
28
+ ```typescript
29
+ const out = await sapiom.contentGeneration.images.create({
30
+ prompt: "four color swatches",
31
+ numImages: 4,
32
+ storage: { visibility: "public" },
33
+ });
34
+ for (const img of out.images ?? []) {
35
+ if (img.fileId) {
36
+ const { downloadUrl } = await sapiom.fileStorage.getDownloadUrl(img.fileId);
37
+ }
38
+ }
39
+ ```
40
+
41
+ Persisting is best-effort per image: if one fails, that image carries a
42
+ `storageError` string instead of a `fileId` while the others still succeed.
43
+
44
+ ## Input
45
+
46
+ - `prompt` (required) — the text prompt.
47
+ - `numImages` (optional) — how many images to generate.
48
+ - `storage` (optional) — persist outputs; `{ visibility: "private" | "public" }`.
49
+ - `model` (optional) — defaults to a fast image model; most callers omit it.
50
+ - `params` (optional) — advanced, model-specific parameters (e.g. `image_size`,
51
+ `seed`, `guidance_scale`).
52
+
53
+ Each returned image is `{ url, contentType?, width?, height?, fileId?,
54
+ storageError? }`; any additional model-specific fields (e.g. `seed`) are returned
55
+ on the result as-is.
56
+
57
+ ## Gotchas
58
+
59
+ - **Failed requests throw `ContentGenerationHttpError`** (carries `status` +
60
+ parsed `body`), exported from `@sapiom/tools`.
61
+ - **`storage` is reserved** — a same-named field in `params` is ignored.
@@ -1,20 +1,20 @@
1
1
  # fileStorage
2
2
 
3
- Tenant-scoped object storage on top of presigned GCS URLs. The same file-storage
4
- capability your agents call over MCP, callable directly from your code.
3
+ Tenant-scoped object storage with presigned URLs. The same file-storage capability
4
+ your agents call over MCP, callable directly from your code.
5
5
 
6
6
  ```typescript
7
7
  import { createClient } from "@sapiom/tools";
8
8
  const sapiom = createClient({ apiKey: process.env.SAPIOM_API_KEY });
9
9
 
10
- // 1. Ask for a presigned upload URL (control plane).
10
+ // 1. Ask for a presigned upload URL.
11
11
  const { fileId, uploadUrl, requiredHeaders } = await sapiom.fileStorage.upload({
12
12
  contentType: "image/png",
13
13
  fileName: "photo.png",
14
14
  visibility: "private", // or "public"
15
15
  });
16
16
 
17
- // 2. PUT the bytes straight to GCS yourself.
17
+ // 2. PUT the bytes to the upload URL yourself.
18
18
  await fetch(uploadUrl, { method: "PUT", headers: requiredHeaders, body: bytes });
19
19
 
20
20
  // 3. Later: a presigned download URL, list, visibility, delete.
@@ -26,18 +26,18 @@ await sapiom.fileStorage.delete(fileId);
26
26
 
27
27
  Ambient import works too: `import { fileStorage } from "@sapiom/tools"`.
28
28
 
29
- ## Control plane only — you move the bytes
29
+ ## You move the bytes
30
30
 
31
- `upload()` and `getDownloadUrl()` return **presigned GCS URLs**; this client never
31
+ `upload()` and `getDownloadUrl()` return **presigned URLs**; this client never
32
32
  transfers file bytes. You `PUT` to the upload URL and `GET` from the download URL
33
33
  yourself, so you own streaming, progress, and resumable-upload behavior. `upload()`
34
34
  returns `requiredHeaders` you **must** include on the `PUT` (notably `Content-Type`).
35
35
 
36
36
  ## Lifecycle
37
37
 
38
- After you `PUT` the bytes, a gateway sweep verifies the object and flips its
39
- `status` from `pending_upload` → `uploaded` (usually within seconds) and records
40
- `actualFileSize`. Until then, `getDownloadUrl()` on a still-pending file is rejected.
38
+ After you `PUT` the bytes, the file's `status` moves from `pending_upload`
39
+ `uploaded` (usually within seconds) and `actualFileSize` is recorded. Until then,
40
+ `getDownloadUrl()` on a still-pending file is rejected.
41
41
 
42
42
  ## Visibility
43
43
 
@@ -50,12 +50,9 @@ files; another tenant cannot read your private files.
50
50
  ## Gotchas
51
51
 
52
52
  - **Sizes are strings.** `expectedFileSize` / `actualFileSize` on returned metadata
53
- are `string | null` the gateway serializes int64 byte counts as strings to
54
- avoid JS `Number` precision loss on large files. (`expectedFileSize` on the
55
- `upload()` *input* is a regular `number`.)
53
+ are `string | null` to avoid JS `Number` precision loss on large files.
54
+ (`expectedFileSize` on the `upload()` *input* is a regular `number`.)
56
55
  - **`delete` is idempotent** — deleting an already-deleted file resolves without
57
56
  error.
58
- - **Non-2xx responses throw `FileStorageHttpError`** (carries `status` + parsed
57
+ - **Failed requests throw `FileStorageHttpError`** (carries `status` + parsed
59
58
  `body`), exported from `@sapiom/tools`.
60
- - **Base URL** defaults to the production gateway; override with the
61
- `SAPIOM_FILE_STORAGE_URL` env var (e.g. to target a staging gateway).