@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.
- package/CHANGELOG.md +7 -1
- package/README.md +13 -2
- package/dist/cjs/client.d.ts +10 -0
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +6 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/content-generation/errors.d.ts +16 -0
- package/dist/cjs/content-generation/errors.d.ts.map +1 -0
- package/dist/cjs/content-generation/errors.js +36 -0
- package/dist/cjs/content-generation/errors.js.map +1 -0
- package/dist/cjs/content-generation/index.d.ts +87 -0
- package/dist/cjs/content-generation/index.d.ts.map +1 -0
- package/dist/cjs/content-generation/index.js +77 -0
- package/dist/cjs/content-generation/index.js.map +1 -0
- package/dist/cjs/file-storage/errors.d.ts +2 -2
- package/dist/cjs/file-storage/errors.js +2 -2
- package/dist/cjs/file-storage/index.d.ts +14 -18
- package/dist/cjs/file-storage/index.d.ts.map +1 -1
- package/dist/cjs/file-storage/index.js +9 -11
- package/dist/cjs/file-storage/index.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/stub/index.d.ts.map +1 -1
- package/dist/cjs/stub/index.js +16 -0
- package/dist/cjs/stub/index.js.map +1 -1
- package/dist/esm/client.d.ts +10 -0
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +6 -0
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/content-generation/errors.d.ts +16 -0
- package/dist/esm/content-generation/errors.d.ts.map +1 -0
- package/dist/esm/content-generation/errors.js +31 -0
- package/dist/esm/content-generation/errors.js.map +1 -0
- package/dist/esm/content-generation/index.d.ts +87 -0
- package/dist/esm/content-generation/index.d.ts.map +1 -0
- package/dist/esm/content-generation/index.js +73 -0
- package/dist/esm/content-generation/index.js.map +1 -0
- package/dist/esm/file-storage/errors.d.ts +2 -2
- package/dist/esm/file-storage/errors.js +2 -2
- package/dist/esm/file-storage/index.d.ts +14 -18
- package/dist/esm/file-storage/index.d.ts.map +1 -1
- package/dist/esm/file-storage/index.js +9 -11
- package/dist/esm/file-storage/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/stub/index.d.ts.map +1 -1
- package/dist/esm/stub/index.js +16 -0
- package/dist/esm/stub/index.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -1
- package/src/content-generation/README.md +61 -0
- 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
|
|
4
|
-
|
|
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
|
|
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
|
|
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
|
-
##
|
|
29
|
+
## You move the bytes
|
|
30
30
|
|
|
31
|
-
`upload()` and `getDownloadUrl()` return **presigned
|
|
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,
|
|
39
|
-
`
|
|
40
|
-
`
|
|
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`
|
|
54
|
-
|
|
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
|
-
- **
|
|
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).
|