@sapiom/tools 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/CHANGELOG.md +17 -1
- package/README.md +13 -2
- package/dist/cjs/agent/index.d.ts +43 -10
- package/dist/cjs/agent/index.d.ts.map +1 -1
- package/dist/cjs/agent/index.js +93 -1
- package/dist/cjs/agent/index.js.map +1 -1
- 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 +4 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +13 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/stub/index.d.ts.map +1 -1
- package/dist/cjs/stub/index.js +31 -14
- package/dist/cjs/stub/index.js.map +1 -1
- package/dist/esm/agent/index.d.ts +43 -10
- package/dist/esm/agent/index.d.ts.map +1 -1
- package/dist/esm/agent/index.js +90 -0
- package/dist/esm/agent/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 +4 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -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 +32 -15
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @sapiom/tools
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5c974b1: Add the `contentGeneration` capability — media generation (images today; video and audio to come) with an optional `storage` param that persists each output to Sapiom file storage (each generated image comes back annotated with its own `fileId`, or `storageError`). Exposes `contentGeneration.images.create({ prompt, numImages?, storage? })` via `createClient()`, the ambient `contentGeneration` namespace, or the `@sapiom/tools/content-generation` subpath. Failed requests throw `ContentGenerationHttpError`. Pairs with `fileStorage` — pass `storage` to persist outputs with no extra plumbing.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- e17b2d1: **BREAKING (`@sapiom/tools`):** align the coding-run resume payload with the shape a resumed step actually receives. `CodingResultPayload` now carries `executionEnvironment: { type, id } | null` instead of `sandbox: { name, workspaceRoot }`. Re-attach a resumed run's sandbox with `ctx.sapiom.sandboxes.attach(result.executionEnvironment.id)` (for a `blaxel_sandbox`).
|
|
14
|
+
|
|
15
|
+
Adds `codingResultSchema` (runtime validation of the resume payload), `toResumePayload`, `ExecutionEnvironmentRef`, and `EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX`. The stub client now emits the same payload shape a resumed step receives, so a step written against the local loop runs identically once deployed.
|
|
16
|
+
|
|
17
|
+
The `coding-pause` template and its guidance are updated to the new shape.
|
|
18
|
+
|
|
3
19
|
## 0.3.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -18,7 +34,7 @@
|
|
|
18
34
|
|
|
19
35
|
### Minor Changes
|
|
20
36
|
|
|
21
|
-
- 7f6859e: Add the `fileStorage` capability — tenant-scoped object storage
|
|
37
|
+
- 7f6859e: Add the `fileStorage` capability — tenant-scoped object storage with presigned URLs. Exposes `upload`, `getDownloadUrl`, `list`, `setVisibility`, and `delete` via `createClient().fileStorage`, the ambient `fileStorage` namespace, or the `@sapiom/tools/file-storage` subpath. Failed requests throw `FileStorageHttpError`. You transfer the bytes yourself via the presigned URLs.
|
|
22
38
|
|
|
23
39
|
## 0.1.3
|
|
24
40
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @sapiom/tools
|
|
2
2
|
|
|
3
|
-
A typed TypeScript client for Sapiom capabilities — sandboxes, git repositories, coding agents,
|
|
3
|
+
A typed TypeScript client for Sapiom capabilities — sandboxes, git repositories, coding agents, file storage, and content generation — authenticated to your tenant.
|
|
4
4
|
|
|
5
5
|
These are the same capabilities your Sapiom agents call as tools; this package makes them callable directly from your own code.
|
|
6
6
|
|
|
@@ -70,7 +70,8 @@ Each capability is a namespace, importable from the barrel or its own subpath (e
|
|
|
70
70
|
| `sandboxes` | Isolated, ephemeral compute | [src/sandboxes](./src/sandboxes/README.md) |
|
|
71
71
|
| `repositories` | Private, in-network git repos | [src/repositories](./src/repositories/README.md) |
|
|
72
72
|
| `agent` | Coding agents (LLM execution) | [src/agent](./src/agent/README.md) |
|
|
73
|
-
| `fileStorage` | Tenant-scoped object storage (presigned
|
|
73
|
+
| `fileStorage` | Tenant-scoped object storage (presigned URLs) | [src/file-storage](./src/file-storage/README.md) |
|
|
74
|
+
| `contentGeneration` | Media generation (images; video/audio soon), with optional `storage` | [src/content-generation](./src/content-generation/README.md) |
|
|
74
75
|
|
|
75
76
|
## Composing capabilities
|
|
76
77
|
|
|
@@ -83,6 +84,16 @@ await repo.pushFromSandbox(run.sandbox);
|
|
|
83
84
|
|
|
84
85
|
A useful pattern: let the agent do the open-ended work (writing files) and perform exact, repeatable actions — committing, pushing, deploying — in your own code rather than in the agent's prompt. The agent produces the changes; `pushFromSandbox` publishes them deterministically.
|
|
85
86
|
|
|
87
|
+
Some compositions need nothing but a param. `contentGeneration.images.create` takes an optional `storage`, and each generated image is persisted into `fileStorage` as it returns — handing you a durable `fileId` with no extra call:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const out = await contentGeneration.images.create({
|
|
91
|
+
prompt: "a logo",
|
|
92
|
+
storage: { visibility: "private" },
|
|
93
|
+
});
|
|
94
|
+
const { downloadUrl } = await fileStorage.getDownloadUrl(out.images![0].fileId!);
|
|
95
|
+
```
|
|
96
|
+
|
|
86
97
|
## License
|
|
87
98
|
|
|
88
99
|
MIT
|
|
@@ -76,13 +76,26 @@ export interface CodingRunResult {
|
|
|
76
76
|
/** Live handle to the sandbox the run executed in. */
|
|
77
77
|
sandbox: Sandbox;
|
|
78
78
|
}
|
|
79
|
+
/** Execution-environment `type` for a remote cloud sandbox; its `id` is the sandbox name. */
|
|
80
|
+
export declare const EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX = "blaxel_sandbox";
|
|
81
|
+
/**
|
|
82
|
+
* The execution environment a coding run used. For a `"blaxel_sandbox"`, `id` is
|
|
83
|
+
* the sandbox NAME — the value `ctx.sapiom.sandboxes.attach(id)` takes.
|
|
84
|
+
*/
|
|
85
|
+
export interface ExecutionEnvironmentRef {
|
|
86
|
+
/** Environment kind (today: `"blaxel_sandbox"` | `"local_host"`). */
|
|
87
|
+
type: string;
|
|
88
|
+
/** Type-specific id; for `"blaxel_sandbox"`, the sandbox name. */
|
|
89
|
+
id: string;
|
|
90
|
+
}
|
|
79
91
|
/**
|
|
80
92
|
* The coding run's terminal result as it arrives at a step **resumed** from
|
|
81
|
-
* `pauseUntilSignal(runHandle, { resumeStep })
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* `
|
|
93
|
+
* `pauseUntilSignal(runHandle, { resumeStep })` — the signal payload delivered as
|
|
94
|
+
* that step's `input`. It crossed a wire boundary, so there are no live handles:
|
|
95
|
+
* to act on the run's sandbox, re-attach one from `executionEnvironment` —
|
|
96
|
+
* `ctx.sapiom.sandboxes.attach(result.executionEnvironment.id)` (when its `type`
|
|
97
|
+
* is `"blaxel_sandbox"`). `executionEnvironment` is `null` when the run never
|
|
98
|
+
* provisioned one (e.g. a launch-stage failure).
|
|
86
99
|
*
|
|
87
100
|
* Annotate a resumed step's input with this so you don't have to hand-roll the
|
|
88
101
|
* shape:
|
|
@@ -92,12 +105,32 @@ export interface CodingRunResult {
|
|
|
92
105
|
* async run(result: CodingResultPayload, ctx) { … },
|
|
93
106
|
* });
|
|
94
107
|
*/
|
|
95
|
-
export interface CodingResultPayload
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
export interface CodingResultPayload {
|
|
109
|
+
runId: string;
|
|
110
|
+
status: RunStatus;
|
|
111
|
+
summary: string | null;
|
|
112
|
+
result: CodingRunOutcome | null;
|
|
113
|
+
error: CodingRunError | null;
|
|
114
|
+
executionEnvironment: ExecutionEnvironmentRef | null;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Map a live, awaited {@link CodingRunResult} to the plain {@link CodingResultPayload}
|
|
118
|
+
* a resumed step receives across the wire boundary (live handles become an
|
|
119
|
+
* `executionEnvironment` reference).
|
|
120
|
+
*/
|
|
121
|
+
export declare function toResumePayload(run: CodingRunResult): CodingResultPayload;
|
|
122
|
+
/** Thrown by {@link codingResultSchema}.parse on a malformed resume payload. */
|
|
123
|
+
export declare class CodingResultSchemaError extends Error {
|
|
100
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Runtime validator for {@link CodingResultPayload}. `parse` returns the value typed
|
|
127
|
+
* on success and throws a {@link CodingResultSchemaError} on any divergence. The
|
|
128
|
+
* `executionEnvironment` key is required (use `null` when no environment was
|
|
129
|
+
* provisioned).
|
|
130
|
+
*/
|
|
131
|
+
export declare const codingResultSchema: {
|
|
132
|
+
parse(value: unknown): CodingResultPayload;
|
|
133
|
+
};
|
|
101
134
|
/**
|
|
102
135
|
* A launched-but-not-awaited run. Satisfies {@link DispatchHandle}, so it can be
|
|
103
136
|
* handed straight to `pauseUntilSignal(handle, { resumeStep })` to suspend a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAK3D;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,wBAAwB,CAAC;AAE1D,oEAAoE;AACpE,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,QAAQ,GACR,SAAS,GACT,WAAW,GACX,QAAQ,CA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MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC9B;AAyED,wBAAsB,MAAM,CAC1B,IAAI,EAAE,aAAa,EACnB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,SAAS,CAAC,CAmDpB;AAED,wBAAsB,GAAG,CACvB,IAAI,EAAE,aAAa,EACnB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,eAAe,CAAC,CAG1B;AAED,8CAA8C;AAC9C,eAAO,MAAM,MAAM;;;CAAkB,CAAC"}
|
package/dist/cjs/agent/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.coding = exports.CODING_RESULT_SIGNAL = void 0;
|
|
3
|
+
exports.coding = exports.codingResultSchema = exports.CodingResultSchemaError = exports.EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX = exports.CODING_RESULT_SIGNAL = void 0;
|
|
4
|
+
exports.toResumePayload = toResumePayload;
|
|
4
5
|
exports.launch = launch;
|
|
5
6
|
exports.run = run;
|
|
6
7
|
/**
|
|
@@ -36,6 +37,97 @@ const DEFAULT_BASE_URL = process.env.SAPIOM_AGENTS_URL || "https://agents.servic
|
|
|
36
37
|
*/
|
|
37
38
|
exports.CODING_RESULT_SIGNAL = "agent.coding.result";
|
|
38
39
|
const TERMINAL = new Set(["completed", "failed"]);
|
|
40
|
+
/** Execution-environment `type` for a remote cloud sandbox; its `id` is the sandbox name. */
|
|
41
|
+
exports.EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX = "blaxel_sandbox";
|
|
42
|
+
/**
|
|
43
|
+
* Map a live, awaited {@link CodingRunResult} to the plain {@link CodingResultPayload}
|
|
44
|
+
* a resumed step receives across the wire boundary (live handles become an
|
|
45
|
+
* `executionEnvironment` reference).
|
|
46
|
+
*/
|
|
47
|
+
function toResumePayload(run) {
|
|
48
|
+
return {
|
|
49
|
+
runId: run.runId,
|
|
50
|
+
status: run.status,
|
|
51
|
+
summary: run.summary,
|
|
52
|
+
result: run.result,
|
|
53
|
+
error: run.error,
|
|
54
|
+
executionEnvironment: {
|
|
55
|
+
type: exports.EXECUTION_ENVIRONMENT_BLAXEL_SANDBOX,
|
|
56
|
+
id: run.sandbox.name,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Thrown by {@link codingResultSchema}.parse on a malformed resume payload. */
|
|
61
|
+
class CodingResultSchemaError extends Error {
|
|
62
|
+
}
|
|
63
|
+
exports.CodingResultSchemaError = CodingResultSchemaError;
|
|
64
|
+
const RUN_STATUSES = [
|
|
65
|
+
"pending",
|
|
66
|
+
"queued",
|
|
67
|
+
"running",
|
|
68
|
+
"completed",
|
|
69
|
+
"failed",
|
|
70
|
+
];
|
|
71
|
+
/**
|
|
72
|
+
* Runtime validator for {@link CodingResultPayload}. `parse` returns the value typed
|
|
73
|
+
* on success and throws a {@link CodingResultSchemaError} on any divergence. The
|
|
74
|
+
* `executionEnvironment` key is required (use `null` when no environment was
|
|
75
|
+
* provisioned).
|
|
76
|
+
*/
|
|
77
|
+
exports.codingResultSchema = {
|
|
78
|
+
parse(value) {
|
|
79
|
+
const fail = (msg) => {
|
|
80
|
+
throw new CodingResultSchemaError(`invalid coding result payload: ${msg}`);
|
|
81
|
+
};
|
|
82
|
+
if (!value || typeof value !== "object")
|
|
83
|
+
fail("not an object");
|
|
84
|
+
const v = value;
|
|
85
|
+
if (typeof v.runId !== "string")
|
|
86
|
+
fail("runId must be a string");
|
|
87
|
+
if (!RUN_STATUSES.includes(v.status))
|
|
88
|
+
fail(`status must be one of ${RUN_STATUSES.join(", ")}`);
|
|
89
|
+
if (v.summary !== null && typeof v.summary !== "string")
|
|
90
|
+
fail("summary must be a string or null");
|
|
91
|
+
if (v.result !== null) {
|
|
92
|
+
const r = v.result;
|
|
93
|
+
if (!r || typeof r !== "object")
|
|
94
|
+
fail("result must be an object or null");
|
|
95
|
+
if (typeof r.success !== "boolean")
|
|
96
|
+
fail("result.success must be a boolean");
|
|
97
|
+
if (typeof r.turns !== "number")
|
|
98
|
+
fail("result.turns must be a number");
|
|
99
|
+
if (r.modelUsed !== null && typeof r.modelUsed !== "string")
|
|
100
|
+
fail("result.modelUsed must be a string or null");
|
|
101
|
+
if (typeof r.durationMs !== "number")
|
|
102
|
+
fail("result.durationMs must be a number");
|
|
103
|
+
if (typeof r.toolCallCount !== "number")
|
|
104
|
+
fail("result.toolCallCount must be a number");
|
|
105
|
+
if (!r.usage || typeof r.usage !== "object")
|
|
106
|
+
fail("result.usage must be an object");
|
|
107
|
+
}
|
|
108
|
+
if (v.error !== null) {
|
|
109
|
+
const e = v.error;
|
|
110
|
+
if (!e || typeof e !== "object")
|
|
111
|
+
fail("error must be an object or null");
|
|
112
|
+
if (typeof e.stage !== "string")
|
|
113
|
+
fail("error.stage must be a string");
|
|
114
|
+
if (typeof e.message !== "string")
|
|
115
|
+
fail("error.message must be a string");
|
|
116
|
+
}
|
|
117
|
+
if (!("executionEnvironment" in v))
|
|
118
|
+
fail("executionEnvironment is required (use null when no environment was provisioned)");
|
|
119
|
+
if (v.executionEnvironment !== null) {
|
|
120
|
+
const env = v.executionEnvironment;
|
|
121
|
+
if (!env || typeof env !== "object")
|
|
122
|
+
fail("executionEnvironment must be an object or null");
|
|
123
|
+
if (typeof env.type !== "string")
|
|
124
|
+
fail("executionEnvironment.type must be a string");
|
|
125
|
+
if (typeof env.id !== "string")
|
|
126
|
+
fail("executionEnvironment.id must be a string");
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
39
131
|
/**
|
|
40
132
|
* When launched from inside a Sapiom workflow step, the engine injects an opaque
|
|
41
133
|
* per-execution resume token into the sandbox env. Forwarding it as a header — NOT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/agent/index.ts"],"names":[],"mappings":";;;AA4IA,0CAYC;AAoKD,wBAuDC;AAED,kBAOC;AA5XD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,kDAAkE;AAElE,oDAAgD;AAGhD,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,mCAAmC,CAAC;AAEvE;;;;;GAKG;AACU,QAAA,oBAAoB,GAAG,qBAAqB,CAAC;AAS1D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAY,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AAkD7D,6FAA6F;AAChF,QAAA,oCAAoC,GAAG,gBAAgB,CAAC;AAuCrE;;;;GAIG;AACH,SAAgB,eAAe,CAAC,GAAoB;IAClD,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,oBAAoB,EAAE;YACpB,IAAI,EAAE,4CAAoC;YAC1C,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI;SACrB;KACF,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAa,uBAAwB,SAAQ,KAAK;CAAG;AAArD,0DAAqD;AAErD,MAAM,YAAY,GAAyB;IACzC,SAAS;IACT,QAAQ;IACR,SAAS;IACT,WAAW;IACX,QAAQ;CACT,CAAC;AAEF;;;;;GAKG;AACU,QAAA,kBAAkB,GAAG;IAChC,KAAK,CAAC,KAAc;QAClB,MAAM,IAAI,GAAG,CAAC,GAAW,EAAS,EAAE;YAClC,MAAM,IAAI,uBAAuB,CAC/B,kCAAkC,GAAG,EAAE,CACxC,CAAC;QACJ,C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AAM,EAAE,MAAM,GAAG,IAAK,EAAE,GAAG,EAAE;YACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACxC,iDAAiD;YACjD,OAAO,IAAI,EAAE,CAAC;gBACZ,MAAM,CAAC,GAAG,MAAM,QAAQ,EAAE,CAAC;gBAC3B,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;oBAAE,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAC/D,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;oBAC1B,MAAM,IAAI,KAAK,CACb,cAAc,KAAK,oBAAoB,SAAS,oBAAoB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAChG,CAAC;gBACJ,CAAC;gBACD,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAEM,KAAK,UAAU,GAAG,CACvB,IAAmB,EACnB,YAAuB,IAAA,2BAAgB,GAAE,EACzC,OAAO,GAAG,gBAAgB;IAE1B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC;AAED,8CAA8C;AACjC,QAAA,MAAM,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type { SandboxCreateOptions } from "./sandboxes/index.js";
|
|
|
20
20
|
import { Repository } from "./repositories/index.js";
|
|
21
21
|
import type { CodingRunSpec, CodingRunResult, RunHandle } from "./agent/index.js";
|
|
22
22
|
import type { UploadInput, UploadResponse, DownloadUrlResponse, ListOptions, ListResponse, FileMetadata } from "./file-storage/index.js";
|
|
23
|
+
import type { ImageCreateInput, ImageGenerationResult } from "./content-generation/index.js";
|
|
23
24
|
export interface Sapiom {
|
|
24
25
|
readonly sandboxes: {
|
|
25
26
|
create(opts: SandboxCreateOptions): Promise<Sandbox>;
|
|
@@ -48,6 +49,15 @@ export interface Sapiom {
|
|
|
48
49
|
delete(fileId: string): Promise<void>;
|
|
49
50
|
setVisibility(fileId: string, visibility: "private" | "public"): Promise<FileMetadata>;
|
|
50
51
|
};
|
|
52
|
+
readonly contentGeneration: {
|
|
53
|
+
images: {
|
|
54
|
+
/**
|
|
55
|
+
* Generate image(s) from a prompt. Pass `storage` to persist each output into
|
|
56
|
+
* file-storage (the returned images then carry `file_id`).
|
|
57
|
+
*/
|
|
58
|
+
create(input: ImageCreateInput): Promise<ImageGenerationResult>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
51
61
|
/**
|
|
52
62
|
* Derive a client that attributes its calls to a different agent/trace. For the
|
|
53
63
|
* router case (one process acting for many agents); step-authoring code doesn't
|
package/dist/cjs/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,SAAS,EACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,yBAAy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MAAM,CAE7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
package/dist/cjs/client.js
CHANGED
|
@@ -56,6 +56,7 @@ const index_js_2 = require("./sandboxes/index.js");
|
|
|
56
56
|
const index_js_3 = require("./repositories/index.js");
|
|
57
57
|
const index_js_4 = require("./agent/index.js");
|
|
58
58
|
const fileStorage = __importStar(require("./file-storage/index.js"));
|
|
59
|
+
const contentGeneration = __importStar(require("./content-generation/index.js"));
|
|
59
60
|
/** Bind every capability namespace to a transport. `withAttribution` rebinds to a derived one. */
|
|
60
61
|
function bind(transport) {
|
|
61
62
|
return {
|
|
@@ -83,6 +84,11 @@ function bind(transport) {
|
|
|
83
84
|
delete: (fileId) => fileStorage.delete(fileId, transport),
|
|
84
85
|
setVisibility: (fileId, visibility) => fileStorage.setVisibility(fileId, visibility, transport),
|
|
85
86
|
},
|
|
87
|
+
contentGeneration: {
|
|
88
|
+
images: {
|
|
89
|
+
create: (input) => contentGeneration.createImage(input, transport),
|
|
90
|
+
},
|
|
91
|
+
},
|
|
86
92
|
withAttribution: (attribution) => bind(transport.withAttribution(attribution)),
|
|
87
93
|
};
|
|
88
94
|
}
|
package/dist/cjs/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqIA,oCAEC;AAWD,kDAEC;AApJD;;;;;;;;;;;;;;;GAeG;AACH,iDAK4B;AAC5B,mDAA+C;AAE/C,sDAAqD;AACrD,+CAA4E;AAM5E,qEAAuD;AASvD,iFAAmE;AAuDnE,kGAAkG;AAClG,SAAS,IAAI,CAAC,SAAoB;IAChC,OAAO;QACL,SAAS,EA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CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC;YACjD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;YACzD,aAAa,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CACpC,WAAW,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC;SAC3D;QACD,iBAAiB,EAAE;YACjB,MAAM,EAAE;gBACN,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,KAAK,EAAE,SAAS,CAAC;aACnE;SACF;QACD,eAAe,EAAE,CAAC,WAAW,EAAE,EAAE,CAC/B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,MAAwB;IACnD,OAAO,IAAI,CAAC,IAAI,oBAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,mBAAmB;IACjC,OAAO,IAAI,CAAC,IAAI,oBAAS,CAAC,EAAE,WAAW,EAAE,IAAA,6BAAkB,GAAE,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown by the `contentGeneration` capability when a request fails
|
|
3
|
+
* (non-2xx response). Exposes `status` (HTTP status code) and `body` (parsed JSON
|
|
4
|
+
* body, or raw text when the body isn't JSON) for programmatic inspection.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ContentGenerationHttpError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly body: unknown;
|
|
9
|
+
constructor(message: string, status: number, body: unknown);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Return the response when 2xx, otherwise throw a {@link ContentGenerationHttpError}.
|
|
13
|
+
* Parses the error body as JSON when possible; falls back to raw text.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ensureOk(response: Response, errorPrefix: string): Promise<Response>;
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/content-generation/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAM3D;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC,CAcnB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContentGenerationHttpError = void 0;
|
|
4
|
+
exports.ensureOk = ensureOk;
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown by the `contentGeneration` capability when a request fails
|
|
7
|
+
* (non-2xx response). Exposes `status` (HTTP status code) and `body` (parsed JSON
|
|
8
|
+
* body, or raw text when the body isn't JSON) for programmatic inspection.
|
|
9
|
+
*/
|
|
10
|
+
class ContentGenerationHttpError extends Error {
|
|
11
|
+
constructor(message, status, body) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ContentGenerationHttpError";
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.body = body;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ContentGenerationHttpError = ContentGenerationHttpError;
|
|
19
|
+
/**
|
|
20
|
+
* Return the response when 2xx, otherwise throw a {@link ContentGenerationHttpError}.
|
|
21
|
+
* Parses the error body as JSON when possible; falls back to raw text.
|
|
22
|
+
*/
|
|
23
|
+
async function ensureOk(response, errorPrefix) {
|
|
24
|
+
if (response.ok)
|
|
25
|
+
return response;
|
|
26
|
+
let body;
|
|
27
|
+
const text = await response.text().catch(() => "");
|
|
28
|
+
try {
|
|
29
|
+
body = JSON.parse(text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
body = text;
|
|
33
|
+
}
|
|
34
|
+
throw new ContentGenerationHttpError(`${errorPrefix}: ${response.status} ${text}`, response.status, body);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/content-generation/errors.ts"],"names":[],"mappings":";;;AAqBA,4BAiBC;AAtCD;;;;GAIG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAInD,YAAY,OAAe,EAAE,MAAc,EAAE,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,gEAUC;AAED;;;GAGG;AACI,KAAK,UAAU,QAAQ,CAC5B,QAAkB,EAClB,WAAmB;IAEnB,IAAI,QAAQ,CAAC,EAAE;QAAE,OAAO,QAAQ,CAAC;IACjC,IAAI,IAAa,CAAC;IAClB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IACnD,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,0BAA0B,CAClC,GAAG,WAAW,KAAK,QAAQ,CAAC,MAAM,IAAI,IAAI,EAAE,EAC5C,QAAQ,CAAC,MAAM,EACf,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -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,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.images = exports.ContentGenerationHttpError = void 0;
|
|
4
|
+
exports.createImage = createImage;
|
|
5
|
+
/**
|
|
6
|
+
* `contentGeneration` capability — generate media (images today; video and audio
|
|
7
|
+
* to come), with an optional `storage` param that persists each output to Sapiom
|
|
8
|
+
* file storage so you get a durable `fileId` back inline.
|
|
9
|
+
*
|
|
10
|
+
* import { contentGeneration } from "@sapiom/tools"; // ambient auth
|
|
11
|
+
* const out = await contentGeneration.images.create({
|
|
12
|
+
* prompt: "a red bicycle",
|
|
13
|
+
* storage: { visibility: "private" }, // optional — persist outputs
|
|
14
|
+
* });
|
|
15
|
+
* out.images[0].url; // hosted URL of the generated image
|
|
16
|
+
* out.images[0].fileId; // present when `storage` was passed → use with fileStorage
|
|
17
|
+
*
|
|
18
|
+
* Or via an explicit client: `createClient({ apiKey }).contentGeneration.images.create(...)`.
|
|
19
|
+
*/
|
|
20
|
+
const index_js_1 = require("../_client/index.js");
|
|
21
|
+
const errors_js_1 = require("./errors.js");
|
|
22
|
+
Object.defineProperty(exports, "ContentGenerationHttpError", { enumerable: true, get: function () { return errors_js_1.ContentGenerationHttpError; } });
|
|
23
|
+
const DEFAULT_BASE_URL = process.env.SAPIOM_CONTENT_GENERATION_URL || "https://fal.services.sapiom.ai";
|
|
24
|
+
/** Default image model when the caller doesn't pick one — a fast, low-cost model. */
|
|
25
|
+
const DEFAULT_IMAGE_MODEL = "fal-ai/flux/schnell";
|
|
26
|
+
function mapImage(raw) {
|
|
27
|
+
return {
|
|
28
|
+
url: raw.url,
|
|
29
|
+
...(raw.content_type !== undefined && { contentType: raw.content_type }),
|
|
30
|
+
...(raw.width !== undefined && { width: raw.width }),
|
|
31
|
+
...(raw.height !== undefined && { height: raw.height }),
|
|
32
|
+
...(raw.file_id !== undefined && { fileId: raw.file_id }),
|
|
33
|
+
...(raw.storage_error !== undefined && { storageError: raw.storage_error }),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function mapResult(raw) {
|
|
37
|
+
const { images, ...rest } = raw;
|
|
38
|
+
return images === undefined
|
|
39
|
+
? { ...rest }
|
|
40
|
+
: { ...rest, images: images.map(mapImage) };
|
|
41
|
+
}
|
|
42
|
+
// ----- Capability operations -----
|
|
43
|
+
/** Encode a model id into a URL path, preserving its `/` separators. */
|
|
44
|
+
function modelToPath(model) {
|
|
45
|
+
return model.split("/").filter(Boolean).map(encodeURIComponent).join("/");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generate one or more images from a prompt. Pass `storage` to persist each output
|
|
49
|
+
* (the returned images then carry `fileId`). Failed requests throw
|
|
50
|
+
* {@link ContentGenerationHttpError}.
|
|
51
|
+
*/
|
|
52
|
+
async function createImage(input, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
53
|
+
const path = modelToPath(input.model || DEFAULT_IMAGE_MODEL);
|
|
54
|
+
const body = {
|
|
55
|
+
prompt: input.prompt,
|
|
56
|
+
...input.params,
|
|
57
|
+
};
|
|
58
|
+
if (input.numImages !== undefined)
|
|
59
|
+
body.num_images = input.numImages;
|
|
60
|
+
// Truthy check (not `!== undefined`) so a caller passing `storage: null` is
|
|
61
|
+
// treated as "no storage" rather than sending a null field.
|
|
62
|
+
if (input.storage)
|
|
63
|
+
body.storage = input.storage;
|
|
64
|
+
const res = await (0, errors_js_1.ensureOk)(await transport.fetch(`${baseUrl}/run/${path}`, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
headers: { "content-type": "application/json" },
|
|
67
|
+
body: JSON.stringify(body),
|
|
68
|
+
}), "Failed to generate image");
|
|
69
|
+
return mapResult((await res.json()));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The `images` sub-namespace, so `contentGeneration.images.create(...)` reads the
|
|
73
|
+
* same whether imported from the barrel or used on a client. Video and audio will
|
|
74
|
+
* land here as sibling sub-namespaces.
|
|
75
|
+
*/
|
|
76
|
+
exports.images = { create: createImage };
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":";;;AAoIA,kCAyBC;AA7JD;;;;;;;;;;;;;;GAcG;AACH,kDAAkE;AAClE,2CAAmE;AAE1D,2GAFU,sCAA0B,OAEV;AAEnC,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,6BAA6B,IAAI,gCAAgC,CAAC;AAEhF,qFAAqF;AACrF,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AA8ElD,SAAS,QAAQ,CAAC,GAAa;IAC7B,OAAO;QACL,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,GAAG,CAAC,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC;QACxE,GAAG,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;QACpD,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC;QACvD,GAAG,CAAC,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;QACzD,GAAG,CAAC,GAAG,CAAC,aAAa,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,GAAG,CA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AAE,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;AACU,QAAA,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error thrown by the file-storage capability when
|
|
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 {
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FileStorageHttpError = void 0;
|
|
4
4
|
exports.ensureOk = ensureOk;
|
|
5
5
|
/**
|
|
6
|
-
* Error thrown by the file-storage capability when
|
|
7
|
-
* response. Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
|
|
6
|
+
* Error thrown by the file-storage capability when a request fails (non-2xx
|
|
7
|
+
* response). Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
|
|
8
8
|
* raw text when the body isn't JSON) for programmatic inspection.
|
|
9
9
|
*/
|
|
10
10
|
class FileStorageHttpError extends Error {
|