@sapiom/tools 0.7.0 → 0.8.1
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 +35 -0
- package/README.md +10 -9
- package/dist/cjs/client.d.ts +28 -2
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +12 -0
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/content-generation/index.d.ts +64 -1
- package/dist/cjs/content-generation/index.d.ts.map +1 -1
- package/dist/cjs/content-generation/index.js +129 -5
- package/dist/cjs/content-generation/index.js.map +1 -1
- package/dist/cjs/database/errors.d.ts +16 -0
- package/dist/cjs/database/errors.d.ts.map +1 -0
- package/dist/cjs/database/errors.js +36 -0
- package/dist/cjs/database/errors.js.map +1 -0
- package/dist/cjs/database/index.d.ts +103 -0
- package/dist/cjs/database/index.d.ts.map +1 -0
- package/dist/cjs/database/index.js +120 -0
- package/dist/cjs/database/index.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +12 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/search/index.d.ts +132 -3
- package/dist/cjs/search/index.d.ts.map +1 -1
- package/dist/cjs/search/index.js +160 -3
- package/dist/cjs/search/index.js.map +1 -1
- package/dist/cjs/stub/index.d.ts.map +1 -1
- package/dist/cjs/stub/index.js +112 -2
- package/dist/cjs/stub/index.js.map +1 -1
- package/dist/esm/client.d.ts +28 -2
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +13 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/content-generation/index.d.ts +64 -1
- package/dist/esm/content-generation/index.d.ts.map +1 -1
- package/dist/esm/content-generation/index.js +126 -4
- package/dist/esm/content-generation/index.js.map +1 -1
- package/dist/esm/database/errors.d.ts +16 -0
- package/dist/esm/database/errors.d.ts.map +1 -0
- package/dist/esm/database/errors.js +31 -0
- package/dist/esm/database/errors.js.map +1 -0
- package/dist/esm/database/index.d.ts +103 -0
- package/dist/esm/database/index.d.ts.map +1 -0
- package/dist/esm/database/index.js +115 -0
- package/dist/esm/database/index.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/search/index.d.ts +132 -3
- package/dist/esm/search/index.d.ts.map +1 -1
- package/dist/esm/search/index.js +157 -3
- package/dist/esm/search/index.js.map +1 -1
- package/dist/esm/stub/index.d.ts.map +1 -1
- package/dist/esm/stub/index.js +112 -2
- 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 +67 -0
- package/src/database/README.md +62 -0
- package/src/search/README.md +130 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @sapiom/tools
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bfd2382: Validate the `duration` input in `database.create` and reject invalid values before the request.
|
|
8
|
+
|
|
9
|
+
## 0.8.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 2b94dff: Add the `database` namespace for on-demand Postgres databases:
|
|
14
|
+
|
|
15
|
+
- `database.create` — provision a database for a chosen `duration`, returned with direct connection credentials (`connection.connectionString`, `host`, `port`, `username`, `password`, `databaseName`).
|
|
16
|
+
- `database.get` — retrieve a database by its id or handle.
|
|
17
|
+
- `database.delete` — delete a database by its id or handle.
|
|
18
|
+
|
|
19
|
+
Results use normalized camelCase types, and a typed `DatabaseHttpError` (`{ status, body }`) is thrown on non-2xx responses.
|
|
20
|
+
|
|
21
|
+
- ac71754: Add the `search` namespace with provider-agnostic operations:
|
|
22
|
+
|
|
23
|
+
- `search.webSearch` — web search returning normalized `{ query, answer?, results }`.
|
|
24
|
+
- `search.scrape` — fetch a URL as clean Markdown/HTML with page metadata.
|
|
25
|
+
- `search.emailSearch.findEmail` / `verifyEmail` / `domainSearch` — find, verify, and discover professional email addresses for a domain.
|
|
26
|
+
|
|
27
|
+
Results use normalized camelCase types, and a typed `SearchHttpError` (`{ status, body }`) is thrown on non-2xx responses.
|
|
28
|
+
|
|
29
|
+
- f078ed5: Add `contentGeneration.video.launch()` — the dispatchable surface for video generation.
|
|
30
|
+
|
|
31
|
+
- `contentGeneration.video.launch(input)` submits a video generation job and returns a `VideoLaunchHandle` immediately. Pass the handle to `pauseUntilSignal(handle, { resumeStep })` to suspend a workflow step until the video is ready, or call `handle.wait()` to block inline.
|
|
32
|
+
- `VideoLaunchHandle` satisfies `DispatchHandle` — `dispatch.correlationId` and `dispatch.resultSignal` are the join keys the orchestration engine uses to resume a paused step.
|
|
33
|
+
- `VIDEO_RESULT_SIGNAL` (`"contentGeneration.video.result"`) is the capability-stable signal constant; use it in the static `pause: { signal }` declaration of a workflow step.
|
|
34
|
+
- `VideoResultPayload` and `toVideoResumePayload` describe the payload a resumed step receives across the wire boundary (plain JSON with `outputs[].fileId` / `outputs[].storageError`).
|
|
35
|
+
- Prompt-guard hardening: `images.create`, `video.create`, and `video.launch` now throw a typed error immediately when `prompt` is null, empty, or not a string — before any network request is made.
|
|
36
|
+
- `createStubClient()` wires `contentGeneration.video.launch` as a dispatchable stub that auto-registers a resume payload when `signals` is provided, enabling local workflow testing.
|
|
37
|
+
|
|
3
38
|
## 0.7.0
|
|
4
39
|
|
|
5
40
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -67,15 +67,16 @@ If a single process makes calls on behalf of more than one agent or trace, deriv
|
|
|
67
67
|
|
|
68
68
|
Each capability is a namespace, importable from the barrel or its own subpath (e.g. `@sapiom/tools/sandboxes`). Every capability has its own README with usage details, preconditions, and gotchas the type signatures can't express — read it before first use.
|
|
69
69
|
|
|
70
|
-
| Namespace | What it is
|
|
71
|
-
| ------------------- |
|
|
72
|
-
| `sandboxes` | Isolated, ephemeral compute
|
|
73
|
-
| `repositories` | Private, in-network git repos
|
|
74
|
-
| `agent` | Coding agents (LLM execution)
|
|
75
|
-
| `fileStorage` | Tenant-scoped object storage (presigned URLs)
|
|
76
|
-
| `contentGeneration` | Media generation (images + video; audio soon), with optional `storage`
|
|
77
|
-
| `search` | Search the web
|
|
78
|
-
| `orchestrations` | Run a deployed orchestration, or dispatch one from a step and await its result
|
|
70
|
+
| Namespace | What it is | Docs |
|
|
71
|
+
| ------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
|
|
72
|
+
| `sandboxes` | Isolated, ephemeral compute | [src/sandboxes](./src/sandboxes/README.md) |
|
|
73
|
+
| `repositories` | Private, in-network git repos | [src/repositories](./src/repositories/README.md) |
|
|
74
|
+
| `agent` | Coding agents (LLM execution) | [src/agent](./src/agent/README.md) |
|
|
75
|
+
| `fileStorage` | Tenant-scoped object storage (presigned URLs) | [src/file-storage](./src/file-storage/README.md) |
|
|
76
|
+
| `contentGeneration` | Media generation (images + video; audio soon), with optional `storage` | [src/content-generation](./src/content-generation/README.md) |
|
|
77
|
+
| `search` | Search the web (`webSearch`), read a page (`scrape`), and look up professional emails (`emailSearch`) | [src/search](./src/search/README.md) |
|
|
78
|
+
| `orchestrations` | Run a deployed orchestration, or dispatch one from a step and await its result | [src/orchestrations](./src/orchestrations/README.md) |
|
|
79
|
+
| `database` | On-demand Postgres databases, returned with direct connection credentials | [src/database](./src/database/README.md) |
|
|
79
80
|
|
|
80
81
|
## Composing capabilities
|
|
81
82
|
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ import { Repository } from "./repositories/index.js";
|
|
|
21
21
|
import type { CodingRunSpec, CodingRunResult, RunHandle } from "./agent/index.js";
|
|
22
22
|
import type { OrchestrationRunSpec, OrchestrationRunResult, RunHandle as OrchestrationRunHandle } from "./orchestrations/index.js";
|
|
23
23
|
import type { UploadInput, UploadResponse, DownloadUrlResponse, ListOptions, ListResponse, FileMetadata } from "./file-storage/index.js";
|
|
24
|
-
import type { ImageCreateInput, ImageGenerationResult, VideoCreateInput, VideoGenerationResult } from "./content-generation/index.js";
|
|
25
|
-
import type { ScrapeInput, ScrapeResult, WebSearchInput, WebSearchResponse } from "./search/index.js";
|
|
24
|
+
import type { ImageCreateInput, ImageGenerationResult, VideoCreateInput, VideoGenerationResult, VideoLaunchHandle } from "./content-generation/index.js";
|
|
25
|
+
import type { ScrapeInput, ScrapeResult, WebSearchInput, WebSearchResponse, FindEmailInput, FindEmailResult, VerifyEmailInput, VerifyEmailResult, DomainSearchInput, DomainSearchResult } from "./search/index.js";
|
|
26
|
+
import type { CreateDatabaseInput, Database } from "./database/index.js";
|
|
26
27
|
export interface Sapiom {
|
|
27
28
|
readonly sandboxes: {
|
|
28
29
|
create(opts: SandboxCreateOptions): Promise<Sandbox>;
|
|
@@ -72,6 +73,13 @@ export interface Sapiom {
|
|
|
72
73
|
* `fileId`).
|
|
73
74
|
*/
|
|
74
75
|
create(input: VideoCreateInput): Promise<VideoGenerationResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Submit a video generation job and return a dispatchable handle immediately.
|
|
78
|
+
* Pass the handle to `pauseUntilSignal(handle, { resumeStep })` to suspend the
|
|
79
|
+
* workflow step until the video is ready, or call `handle.wait()` to block
|
|
80
|
+
* inline (equivalent to `video.create`). Pass `storage` to persist the output.
|
|
81
|
+
*/
|
|
82
|
+
launch(input: VideoCreateInput): Promise<VideoLaunchHandle>;
|
|
75
83
|
};
|
|
76
84
|
};
|
|
77
85
|
/**
|
|
@@ -83,6 +91,24 @@ export interface Sapiom {
|
|
|
83
91
|
scrape(input: ScrapeInput): Promise<ScrapeResult>;
|
|
84
92
|
/** Search the web — a synthesized answer plus results by default. */
|
|
85
93
|
webSearch(input: WebSearchInput): Promise<WebSearchResponse>;
|
|
94
|
+
/** Find, verify, and discover professional email addresses. */
|
|
95
|
+
readonly emailSearch: {
|
|
96
|
+
/** Find a person's email from their name and company. */
|
|
97
|
+
findEmail(input: FindEmailInput): Promise<FindEmailResult>;
|
|
98
|
+
/** Verify that an email address is deliverable. */
|
|
99
|
+
verifyEmail(input: VerifyEmailInput): Promise<VerifyEmailResult>;
|
|
100
|
+
/** Discover the emails published at a company domain. */
|
|
101
|
+
domainSearch(input: DomainSearchInput): Promise<DomainSearchResult>;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/** On-demand Postgres databases, returned with direct connection credentials. */
|
|
105
|
+
readonly database: {
|
|
106
|
+
/** Provision a database (returns connection credentials). `duration` is required. */
|
|
107
|
+
create(input: CreateDatabaseInput): Promise<Database>;
|
|
108
|
+
/** Retrieve a database by its id or handle. */
|
|
109
|
+
get(idOrHandle: string): Promise<Database>;
|
|
110
|
+
/** Delete a database by its id or handle. */
|
|
111
|
+
delete(idOrHandle: string): Promise<void>;
|
|
86
112
|
};
|
|
87
113
|
/**
|
|
88
114
|
* Derive a client that attributes its calls to a different agent/trace. For the
|
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;AAK1B,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,SAAS,IAAI,sBAAsB,EACpC,MAAM,2BAA2B,CAAC;AAEnC,OAA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iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE;QACjB,qFAAqF;QACrF,MAAM,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtD,+CAA+C;QAC/C,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3C,6CAA6C;QAC7C,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC3C,CAAC;IACF;;;;OAIG;IACH,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAAC;CAEnD;AA8DD,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,MAAM,CAE7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
package/dist/cjs/client.js
CHANGED
|
@@ -59,6 +59,7 @@ const index_js_5 = require("./orchestrations/index.js");
|
|
|
59
59
|
const fileStorage = __importStar(require("./file-storage/index.js"));
|
|
60
60
|
const contentGeneration = __importStar(require("./content-generation/index.js"));
|
|
61
61
|
const index_js_6 = require("./search/index.js");
|
|
62
|
+
const database = __importStar(require("./database/index.js"));
|
|
62
63
|
/** Bind every capability namespace to a transport. `withAttribution` rebinds to a derived one. */
|
|
63
64
|
function bind(transport) {
|
|
64
65
|
return {
|
|
@@ -96,11 +97,22 @@ function bind(transport) {
|
|
|
96
97
|
},
|
|
97
98
|
video: {
|
|
98
99
|
create: (input) => contentGeneration.createVideo(input, transport),
|
|
100
|
+
launch: (input) => contentGeneration.launchVideo(input, transport),
|
|
99
101
|
},
|
|
100
102
|
},
|
|
101
103
|
search: {
|
|
102
104
|
scrape: (input) => (0, index_js_6.scrape)(input, transport),
|
|
103
105
|
webSearch: (input) => (0, index_js_6.webSearch)(input, transport),
|
|
106
|
+
emailSearch: {
|
|
107
|
+
findEmail: (input) => (0, index_js_6.findEmail)(input, transport),
|
|
108
|
+
verifyEmail: (input) => (0, index_js_6.verifyEmail)(input, transport),
|
|
109
|
+
domainSearch: (input) => (0, index_js_6.domainSearch)(input, transport),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
database: {
|
|
113
|
+
create: (input) => database.create(input, transport),
|
|
114
|
+
get: (idOrHandle) => database.get(idOrHandle, transport),
|
|
115
|
+
delete: (idOrHandle) => database.delete(idOrHandle, transport),
|
|
104
116
|
},
|
|
105
117
|
withAttribution: (attribution) => bind(transport.withAttribution(attribution)),
|
|
106
118
|
};
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6OA,oCAEC;AAWD,kDAEC;AA5PD;;;;;;;;;;;;;;;GAeG;AACH,iDAK4B;AAC5B,mDAA+C;AAE/C,sDAAqD;AACrD,+CAA4E;AAM5E,wDAGmC;AAMnC,qEAAuD;AASvD,iFAAmE;AAQnE,gDAM2B;AAa3B,8DAAgD;AAqGhD,kGAAkG;AAClG,SAAS,IAAI,CAAC,SAAoB;IAChC,OAAO;QACL,SAAS,EAAE;YACT,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC;YACjD,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,kBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC;SAC9D;QACD,YAAY,EAAE;YACZ,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC;YACpD,GAAG,EAAE,CA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AE,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC;SAC/D;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"}
|
|
@@ -12,10 +12,24 @@
|
|
|
12
12
|
* out.images[0].fileId; // present when `storage` was passed → use with fileStorage
|
|
13
13
|
*
|
|
14
14
|
* Or via an explicit client: `createClient({ apiKey }).contentGeneration.images.create(...)`.
|
|
15
|
+
*
|
|
16
|
+
* `video.launch` is the dispatchable surface: it submits the job and returns a
|
|
17
|
+
* handle immediately. Pass the handle to `pauseUntilSignal(handle, { resumeStep })`
|
|
18
|
+
* to suspend the workflow step until the video is ready, or call `handle.wait()`
|
|
19
|
+
* inline to block until done — same as `video.create` but with the ability to
|
|
20
|
+
* pause a running workflow.
|
|
15
21
|
*/
|
|
16
22
|
import { Transport } from "../_client/index.js";
|
|
17
23
|
import { ContentGenerationHttpError } from "./errors.js";
|
|
24
|
+
import type { DispatchHandle } from "../dispatch.js";
|
|
18
25
|
export { ContentGenerationHttpError };
|
|
26
|
+
/**
|
|
27
|
+
* Capability-stable signal a video launch fires when the video reaches a terminal
|
|
28
|
+
* state (ready OR failed — it carries the result either way, the resumed step
|
|
29
|
+
* branches). A workflow step paused on a launch handle resumes on this; it is the
|
|
30
|
+
* value carried in the handle's `dispatch.resultSignal`.
|
|
31
|
+
*/
|
|
32
|
+
export declare const VIDEO_RESULT_SIGNAL = "contentGeneration.video.result";
|
|
19
33
|
export interface StorageOptions {
|
|
20
34
|
/**
|
|
21
35
|
* Visibility of the persisted output.
|
|
@@ -132,8 +146,57 @@ export interface VideoGenerationResult {
|
|
|
132
146
|
* isn't ready within `timeoutMs`.
|
|
133
147
|
*/
|
|
134
148
|
export declare function createVideo(input: VideoCreateInput, transport?: Transport, baseUrl?: string): Promise<VideoGenerationResult>;
|
|
135
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* A launched-but-not-awaited video generation job. Satisfies {@link DispatchHandle},
|
|
151
|
+
* so it can be handed straight to `pauseUntilSignal(handle, { resumeStep })` to
|
|
152
|
+
* suspend a workflow step until the video is ready — or `wait()`-ed inline for
|
|
153
|
+
* standalone use (same as `video.create`, but with the dispatchable surface).
|
|
154
|
+
*/
|
|
155
|
+
export interface VideoLaunchHandle extends DispatchHandle {
|
|
156
|
+
/** The queue request id for this job. */
|
|
157
|
+
requestId: string;
|
|
158
|
+
/** Poll to completion and resolve the full result. */
|
|
159
|
+
wait(opts?: {
|
|
160
|
+
timeoutMs?: number;
|
|
161
|
+
pollMs?: number;
|
|
162
|
+
}): Promise<VideoGenerationResult>;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The video job's terminal result as it arrives at a step **resumed** from
|
|
166
|
+
* `pauseUntilSignal(launchHandle, { resumeStep })`. It crossed a wire boundary,
|
|
167
|
+
* so the shape is plain JSON. Annotate a resumed step's input with this type.
|
|
168
|
+
*
|
|
169
|
+
* const finalize = defineStep({
|
|
170
|
+
* name: "finalize", terminal: true,
|
|
171
|
+
* async run(result: VideoResultPayload, ctx) { … },
|
|
172
|
+
* });
|
|
173
|
+
*/
|
|
174
|
+
export interface VideoResultPayload {
|
|
175
|
+
outputs: Array<{
|
|
176
|
+
/** Present when the output was persisted to file storage. */
|
|
177
|
+
fileId?: string;
|
|
178
|
+
/** Present when storage was requested but persisting this output failed. */
|
|
179
|
+
storageError?: string;
|
|
180
|
+
}>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Map a live, awaited {@link VideoGenerationResult} to the plain
|
|
184
|
+
* {@link VideoResultPayload} a resumed step receives across the wire boundary.
|
|
185
|
+
*/
|
|
186
|
+
export declare function toVideoResumePayload(result: VideoGenerationResult): VideoResultPayload;
|
|
187
|
+
/**
|
|
188
|
+
* Submit a video generation job and return a dispatchable handle immediately.
|
|
189
|
+
* The handle's `dispatch` member lets a workflow step pause until the video
|
|
190
|
+
* is ready; `handle.wait()` blocks inline instead — same as `video.create` but
|
|
191
|
+
* with the ability to suspend a running workflow.
|
|
192
|
+
*
|
|
193
|
+
* Pass `storage` to persist the output (the result then carries `fileId`).
|
|
194
|
+
* Throws {@link ContentGenerationHttpError} when the submit fails.
|
|
195
|
+
*/
|
|
196
|
+
export declare function launchVideo(input: VideoCreateInput, transport?: Transport, baseUrl?: string): Promise<VideoLaunchHandle>;
|
|
197
|
+
/** The `video` sub-namespace: `contentGeneration.video.create(...)` and `contentGeneration.video.launch(...)`. */
|
|
136
198
|
export declare const video: {
|
|
137
199
|
create: typeof createVideo;
|
|
200
|
+
launch: typeof launchVideo;
|
|
138
201
|
};
|
|
139
202
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAoB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAY,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAKtC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,mCAAmC,CAAC;AAOp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kBAAkB,CAcpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,gBAAgB,EACvB,SAAS,GAAE,SAA8B,EACzC,OAAO,SAAmB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CA+D5B;AAED,kHAAkH;AAClH,eAAO,MAAM,KAAK;;;CAA+C,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.video = exports.images = exports.ContentGenerationHttpError = void 0;
|
|
3
|
+
exports.video = exports.images = exports.VIDEO_RESULT_SIGNAL = exports.ContentGenerationHttpError = void 0;
|
|
4
4
|
exports.createImage = createImage;
|
|
5
5
|
exports.createVideo = createVideo;
|
|
6
|
+
exports.toVideoResumePayload = toVideoResumePayload;
|
|
7
|
+
exports.launchVideo = launchVideo;
|
|
6
8
|
/**
|
|
7
9
|
* `contentGeneration` capability — generate media (images and video today; audio
|
|
8
10
|
* to come), with an optional `storage` param that persists each output to Sapiom
|
|
@@ -17,11 +19,24 @@ exports.createVideo = createVideo;
|
|
|
17
19
|
* out.images[0].fileId; // present when `storage` was passed → use with fileStorage
|
|
18
20
|
*
|
|
19
21
|
* Or via an explicit client: `createClient({ apiKey }).contentGeneration.images.create(...)`.
|
|
22
|
+
*
|
|
23
|
+
* `video.launch` is the dispatchable surface: it submits the job and returns a
|
|
24
|
+
* handle immediately. Pass the handle to `pauseUntilSignal(handle, { resumeStep })`
|
|
25
|
+
* to suspend the workflow step until the video is ready, or call `handle.wait()`
|
|
26
|
+
* inline to block until done — same as `video.create` but with the ability to
|
|
27
|
+
* pause a running workflow.
|
|
20
28
|
*/
|
|
21
29
|
const index_js_1 = require("../_client/index.js");
|
|
22
30
|
const errors_js_1 = require("./errors.js");
|
|
23
31
|
Object.defineProperty(exports, "ContentGenerationHttpError", { enumerable: true, get: function () { return errors_js_1.ContentGenerationHttpError; } });
|
|
24
32
|
const DEFAULT_BASE_URL = process.env.SAPIOM_CONTENT_GENERATION_URL || "https://fal.services.sapiom.ai";
|
|
33
|
+
/**
|
|
34
|
+
* Capability-stable signal a video launch fires when the video reaches a terminal
|
|
35
|
+
* state (ready OR failed — it carries the result either way, the resumed step
|
|
36
|
+
* branches). A workflow step paused on a launch handle resumes on this; it is the
|
|
37
|
+
* value carried in the handle's `dispatch.resultSignal`.
|
|
38
|
+
*/
|
|
39
|
+
exports.VIDEO_RESULT_SIGNAL = "contentGeneration.video.result";
|
|
25
40
|
/** Default image model when the caller doesn't pick one — a fast, low-cost model. */
|
|
26
41
|
const DEFAULT_IMAGE_MODEL = "fal-ai/flux/schnell";
|
|
27
42
|
function mapImage(raw) {
|
|
@@ -45,12 +60,34 @@ function mapResult(raw) {
|
|
|
45
60
|
function modelToPath(model) {
|
|
46
61
|
return model.split("/").filter(Boolean).map(encodeURIComponent).join("/");
|
|
47
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Guard a prompt value: throw a clear error before a paid job is submitted when
|
|
65
|
+
* the prompt is absent, empty, or not a string. A JS caller passing `null`,
|
|
66
|
+
* `undefined`, or `""` gets an immediate, actionable error instead of a silent
|
|
67
|
+
* paid request with a blank prompt.
|
|
68
|
+
*/
|
|
69
|
+
function assertPrompt(prompt) {
|
|
70
|
+
if (typeof prompt !== "string" || prompt.trim() === "") {
|
|
71
|
+
throw new errors_js_1.ContentGenerationHttpError("prompt is required and must be a non-empty string", 400, { error: "invalid_prompt" });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* When launched from inside a Sapiom workflow step, the engine injects an opaque
|
|
76
|
+
* per-execution resume token into the transport. Forwarding it as a header — NOT
|
|
77
|
+
* a body field, so author-supplied request fields can't clobber it — lets the
|
|
78
|
+
* service call back into the engine to resume the paused workflow when the job
|
|
79
|
+
* finishes. Absent outside a workflow → no header, no behavior change.
|
|
80
|
+
*/
|
|
81
|
+
function workflowResumeHeaders(token) {
|
|
82
|
+
return token ? { "x-sapiom-workflow-token": token } : {};
|
|
83
|
+
}
|
|
48
84
|
/**
|
|
49
85
|
* Generate one or more images from a prompt. Pass `storage` to persist each output
|
|
50
86
|
* (the returned images then carry `fileId`). Failed requests throw
|
|
51
87
|
* {@link ContentGenerationHttpError}.
|
|
52
88
|
*/
|
|
53
89
|
async function createImage(input, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
90
|
+
assertPrompt(input.prompt);
|
|
54
91
|
const path = modelToPath(input.model || DEFAULT_IMAGE_MODEL);
|
|
55
92
|
const body = {
|
|
56
93
|
prompt: input.prompt,
|
|
@@ -90,7 +127,9 @@ function mapVideo(raw) {
|
|
|
90
127
|
}
|
|
91
128
|
function mapVideoResult(raw) {
|
|
92
129
|
const { video, ...rest } = raw;
|
|
93
|
-
return video === undefined
|
|
130
|
+
return video === undefined
|
|
131
|
+
? { ...rest }
|
|
132
|
+
: { ...rest, video: mapVideo(video) };
|
|
94
133
|
}
|
|
95
134
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
96
135
|
/**
|
|
@@ -102,8 +141,12 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
102
141
|
* isn't ready within `timeoutMs`.
|
|
103
142
|
*/
|
|
104
143
|
async function createVideo(input, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
144
|
+
assertPrompt(input.prompt);
|
|
105
145
|
const path = modelToPath(input.model || DEFAULT_VIDEO_MODEL);
|
|
106
|
-
const body = {
|
|
146
|
+
const body = {
|
|
147
|
+
prompt: input.prompt,
|
|
148
|
+
...input.params,
|
|
149
|
+
};
|
|
107
150
|
// Truthy check (not `!== undefined`) so `storage: null` is treated as "no storage".
|
|
108
151
|
if (input.storage)
|
|
109
152
|
body.storage = input.storage;
|
|
@@ -144,6 +187,87 @@ async function createVideo(input, transport = (0, index_js_1.defaultTransport)()
|
|
|
144
187
|
}
|
|
145
188
|
throw new Error(`Video generation did not complete within ${timeoutMs}ms (request id: ${handle.request_id ?? "unknown"})`);
|
|
146
189
|
}
|
|
147
|
-
/**
|
|
148
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Map a live, awaited {@link VideoGenerationResult} to the plain
|
|
192
|
+
* {@link VideoResultPayload} a resumed step receives across the wire boundary.
|
|
193
|
+
*/
|
|
194
|
+
function toVideoResumePayload(result) {
|
|
195
|
+
if (!result.video)
|
|
196
|
+
return { outputs: [] };
|
|
197
|
+
return {
|
|
198
|
+
outputs: [
|
|
199
|
+
{
|
|
200
|
+
...(result.video.fileId !== undefined && {
|
|
201
|
+
fileId: result.video.fileId,
|
|
202
|
+
}),
|
|
203
|
+
...(result.video.storageError !== undefined && {
|
|
204
|
+
storageError: result.video.storageError,
|
|
205
|
+
}),
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Submit a video generation job and return a dispatchable handle immediately.
|
|
212
|
+
* The handle's `dispatch` member lets a workflow step pause until the video
|
|
213
|
+
* is ready; `handle.wait()` blocks inline instead — same as `video.create` but
|
|
214
|
+
* with the ability to suspend a running workflow.
|
|
215
|
+
*
|
|
216
|
+
* Pass `storage` to persist the output (the result then carries `fileId`).
|
|
217
|
+
* Throws {@link ContentGenerationHttpError} when the submit fails.
|
|
218
|
+
*/
|
|
219
|
+
async function launchVideo(input, transport = (0, index_js_1.defaultTransport)(), baseUrl = DEFAULT_BASE_URL) {
|
|
220
|
+
assertPrompt(input.prompt);
|
|
221
|
+
const path = modelToPath(input.model || DEFAULT_VIDEO_MODEL);
|
|
222
|
+
const body = {
|
|
223
|
+
prompt: input.prompt,
|
|
224
|
+
...input.params,
|
|
225
|
+
};
|
|
226
|
+
if (input.storage)
|
|
227
|
+
body.storage = input.storage;
|
|
228
|
+
// Submit — includes the workflow resume token header so the service can resume
|
|
229
|
+
// the paused step when the job completes (no-op outside a workflow context).
|
|
230
|
+
const submitRes = await (0, errors_js_1.ensureOk)(await transport.fetch(`${baseUrl}/run/${path}`, {
|
|
231
|
+
method: "POST",
|
|
232
|
+
headers: {
|
|
233
|
+
"content-type": "application/json",
|
|
234
|
+
...workflowResumeHeaders(transport.resumeToken),
|
|
235
|
+
},
|
|
236
|
+
body: JSON.stringify(body),
|
|
237
|
+
}), "Failed to submit video generation");
|
|
238
|
+
const handle = (await submitRes.json());
|
|
239
|
+
if (!handle.response_url) {
|
|
240
|
+
throw new Error("Video submit did not return a result URL to poll");
|
|
241
|
+
}
|
|
242
|
+
const requestId = handle.request_id ?? "unknown";
|
|
243
|
+
const responseUrl = handle.response_url;
|
|
244
|
+
const wait = async ({ timeoutMs = input.timeoutMs ?? DEFAULT_VIDEO_TIMEOUT_MS, pollMs = input.pollIntervalMs ?? DEFAULT_VIDEO_POLL_INTERVAL_MS, } = {}) => {
|
|
245
|
+
const deadline = Date.now() + timeoutMs;
|
|
246
|
+
while (Date.now() < deadline) {
|
|
247
|
+
const res = await transport.fetch(responseUrl, { method: "GET" });
|
|
248
|
+
if (res.ok) {
|
|
249
|
+
const raw = (await res.json());
|
|
250
|
+
if (raw.video?.url)
|
|
251
|
+
return mapVideoResult(raw);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
try {
|
|
255
|
+
await res.body?.cancel();
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
// best-effort drain
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
await sleep(pollMs);
|
|
262
|
+
}
|
|
263
|
+
throw new Error(`Video generation did not complete within ${timeoutMs}ms (request id: ${requestId})`);
|
|
264
|
+
};
|
|
265
|
+
return {
|
|
266
|
+
requestId,
|
|
267
|
+
dispatch: { correlationId: requestId, resultSignal: exports.VIDEO_RESULT_SIGNAL },
|
|
268
|
+
wait,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/** The `video` sub-namespace: `contentGeneration.video.create(...)` and `contentGeneration.video.launch(...)`. */
|
|
272
|
+
exports.video = { create: createVideo, launch: launchVideo };
|
|
149
273
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-generation/index.ts"],"names":[],"mappings":";;;AAgLA,kCA0BC;AA2GD,kCAsDC;AAyCD,oDAgBC;AAWD,kCAmEC;AAlfD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,kDAAkE;AAClE,2CAAmE;AAG1D,2GAHU,sCAA0B,OAGV;AAEnC,MAAM,gBAAgB,GACpB,OAAO,CAAC,GAAG,CAAC,6BAA6B,IAAI,gCAAgC,CAAC;AAEhF;;;;;GAKG;AACU,QAAA,mBAAmB,GAAG,gCAAgC,CAAC;AAEpE,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,CAAC,aAAa,EAAE,CAAC;KAC5E,CAAC;AACJ,CAAC;AAED,SAAS,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AE,SAAS,EAAE,YAAY,EAAE,2BAAmB,EAAE;QACzE,IAAI;KACL,CAAC;AACJ,CAAC;AAED,kHAAkH;AACrG,QAAA,KAAK,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown by the `database` capability when a request fails (non-2xx
|
|
3
|
+
* response). Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
|
|
4
|
+
* raw text when the body isn't JSON) for programmatic inspection.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DatabaseHttpError 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 DatabaseHttpError}.
|
|
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/database/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,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.DatabaseHttpError = void 0;
|
|
4
|
+
exports.ensureOk = ensureOk;
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown by the `database` capability when a request fails (non-2xx
|
|
7
|
+
* response). Exposes `status` (HTTP status code) and `body` (parsed JSON body, or
|
|
8
|
+
* raw text when the body isn't JSON) for programmatic inspection.
|
|
9
|
+
*/
|
|
10
|
+
class DatabaseHttpError extends Error {
|
|
11
|
+
constructor(message, status, body) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "DatabaseHttpError";
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.body = body;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.DatabaseHttpError = DatabaseHttpError;
|
|
19
|
+
/**
|
|
20
|
+
* Return the response when 2xx, otherwise throw a {@link DatabaseHttpError}.
|
|
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 DatabaseHttpError(`${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/database/errors.ts"],"names":[],"mappings":";;;AAqBA,4BAiBC;AAtCD;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAI1C,YAAY,OAAe,EAAE,MAAc,EAAE,IAAa;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,8CAUC;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,iBAAiB,CACzB,GAAG,WAAW,KAAK,QAAQ,CAAC,MAAM,IAAI,IAAI,EAAE,EAC5C,QAAQ,CAAC,MAAM,EACf,IAAI,CACL,CAAC;AACJ,CAAC"}
|