@sogni-ai/sogni-intelligence-client 3.0.0-alpha.0 → 3.0.0-alpha.4
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/README.md +163 -729
- package/chatRun/index.d.ts +1 -0
- package/chatRun/index.js +2 -0
- package/context/index.d.ts +1 -0
- package/context/index.js +2 -0
- package/dist/chatRun/costApproval.d.ts +10 -0
- package/dist/chatRun/costApproval.d.ts.map +1 -0
- package/dist/chatRun/costApproval.js +70 -0
- package/dist/chatRun/costApproval.js.map +1 -0
- package/dist/chatRun/index.d.ts +207 -0
- package/dist/chatRun/index.d.ts.map +1 -0
- package/dist/chatRun/index.js +350 -0
- package/dist/chatRun/index.js.map +1 -0
- package/dist/client/SogniClientWrapper.d.ts +2 -2
- package/dist/client/SogniClientWrapper.d.ts.map +1 -1
- package/dist/client/SogniClientWrapper.js +55 -55
- package/dist/client/SogniClientWrapper.js.map +1 -1
- package/dist/context/index.d.ts +56 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +460 -0
- package/dist/context/index.js.map +1 -0
- package/dist/contracts/storyboard.d.ts +1 -0
- package/dist/contracts/storyboard.d.ts.map +1 -1
- package/dist/contracts/storyboard.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -34
- package/dist/index.js.map +1 -1
- package/dist/openai-tools/_manifests.generated.d.ts +4 -0
- package/dist/openai-tools/_manifests.generated.d.ts.map +1 -0
- package/dist/openai-tools/_manifests.generated.js +1792 -0
- package/dist/openai-tools/_manifests.generated.js.map +1 -0
- package/dist/openai-tools/app-tools.json +297 -0
- package/dist/openai-tools/composition-tools.json +228 -0
- package/dist/openai-tools/generation-tools.json +1263 -0
- package/dist/openai-tools/index.d.ts +17 -0
- package/dist/openai-tools/index.d.ts.map +1 -0
- package/dist/openai-tools/index.js +32 -0
- package/dist/openai-tools/index.js.map +1 -0
- package/dist/public-skill-runtime/index.d.ts +1 -0
- package/dist/public-skill-runtime/index.d.ts.map +1 -1
- package/dist/public-skill-runtime/index.js +85 -8
- package/dist/public-skill-runtime/index.js.map +1 -1
- package/dist/schemas/errors/error.schema.json +21 -0
- package/dist/schemas/errors/repair-control.schema.json +40 -0
- package/dist/schemas/events/artifact-reference.schema.json +22 -0
- package/dist/schemas/events/progress-event.schema.json +28 -0
- package/dist/schemas/events/workflow-event.schema.json +22 -0
- package/dist/schemas/storyboards/storyboard-planning-contract.schema.json +108 -0
- package/dist/schemas/tools/add_subtitles.schema.json +77 -0
- package/dist/schemas/tools/animate_photo.schema.json +104 -0
- package/dist/schemas/tools/apply_style.schema.json +37 -0
- package/dist/schemas/tools/change_angle.schema.json +30 -0
- package/dist/schemas/tools/compose_instrumental.schema.json +24 -0
- package/dist/schemas/tools/compose_lyrics.schema.json +28 -0
- package/dist/schemas/tools/compose_script.schema.json +68 -0
- package/dist/schemas/tools/compose_workflow.schema.json +67 -0
- package/dist/schemas/tools/compose_workflow_template.schema.json +156 -0
- package/dist/schemas/tools/dance_montage.schema.json +47 -0
- package/dist/schemas/tools/edit_image.schema.json +74 -0
- package/dist/schemas/tools/enhance_prompt.schema.json +76 -0
- package/dist/schemas/tools/extend_video.schema.json +42 -0
- package/dist/schemas/tools/generate_image.schema.json +104 -0
- package/dist/schemas/tools/generate_music.schema.json +62 -0
- package/dist/schemas/tools/generate_video.schema.json +97 -0
- package/dist/schemas/tools/orbit_video.schema.json +70 -0
- package/dist/schemas/tools/overlay_video.schema.json +126 -0
- package/dist/schemas/tools/refine_result.schema.json +43 -0
- package/dist/schemas/tools/replace_video_segment.schema.json +60 -0
- package/dist/schemas/tools/restore_photo.schema.json +47 -0
- package/dist/schemas/tools/sound_to_video.schema.json +70 -0
- package/dist/schemas/tools/stitch_video.schema.json +52 -0
- package/dist/schemas/tools/video_to_video.schema.json +77 -0
- package/dist/schemas/workflows/durable-workflow-run.schema.json +165 -0
- package/dist/schemas/workflows/durable-workflow-step.schema.json +141 -0
- package/dist/skill-runtime-source/crossSurfaceParity.d.ts +23 -0
- package/dist/skill-runtime-source/crossSurfaceParity.d.ts.map +1 -0
- package/dist/skill-runtime-source/crossSurfaceParity.js +472 -0
- package/dist/skill-runtime-source/crossSurfaceParity.js.map +1 -0
- package/dist/skill-runtime-source/index.d.ts +4 -0
- package/dist/skill-runtime-source/index.d.ts.map +1 -0
- package/dist/skill-runtime-source/index.js +20 -0
- package/dist/skill-runtime-source/index.js.map +1 -0
- package/dist/skill-runtime-source/seedanceAudioWindow.d.ts +8 -0
- package/dist/skill-runtime-source/seedanceAudioWindow.d.ts.map +1 -0
- package/dist/skill-runtime-source/seedanceAudioWindow.js +52 -0
- package/dist/skill-runtime-source/seedanceAudioWindow.js.map +1 -0
- package/dist/skill-runtime-source/workflowStatus.d.ts +17 -0
- package/dist/skill-runtime-source/workflowStatus.d.ts.map +1 -0
- package/dist/skill-runtime-source/workflowStatus.js +353 -0
- package/dist/skill-runtime-source/workflowStatus.js.map +1 -0
- package/dist/utils/errors.d.ts +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +55 -55
- package/dist/utils/helpers.js.map +1 -1
- package/dist/workflows/bindings.d.ts.map +1 -1
- package/dist/workflows/bindings.js +32 -2
- package/dist/workflows/bindings.js.map +1 -1
- package/dist/workflows/index.d.ts +3 -0
- package/dist/workflows/index.d.ts.map +1 -1
- package/dist/workflows/index.js +24 -1
- package/dist/workflows/index.js.map +1 -1
- package/dist/workflows/primitives/index.d.ts +3 -0
- package/dist/workflows/primitives/index.d.ts.map +1 -0
- package/dist/workflows/primitives/index.js +19 -0
- package/dist/workflows/primitives/index.js.map +1 -0
- package/dist/workflows/primitives/retryUntilCondition.d.ts +39 -0
- package/dist/workflows/primitives/retryUntilCondition.d.ts.map +1 -0
- package/dist/workflows/primitives/retryUntilCondition.js +102 -0
- package/dist/workflows/primitives/retryUntilCondition.js.map +1 -0
- package/dist/workflows/primitives/validateWithRubric.d.ts +28 -0
- package/dist/workflows/primitives/validateWithRubric.d.ts.map +1 -0
- package/dist/workflows/primitives/validateWithRubric.js +148 -0
- package/dist/workflows/primitives/validateWithRubric.js.map +1 -0
- package/dist-esm/chatRun/costApproval.js +64 -0
- package/dist-esm/chatRun/costApproval.js.map +1 -0
- package/dist-esm/chatRun/index.js +327 -0
- package/dist-esm/chatRun/index.js.map +1 -0
- package/dist-esm/client/SogniClientWrapper.js +3 -3
- package/dist-esm/client/SogniClientWrapper.js.map +1 -1
- package/dist-esm/context/index.js +453 -0
- package/dist-esm/context/index.js.map +1 -0
- package/dist-esm/contracts/storyboard.js.map +1 -1
- package/dist-esm/index.js +5 -5
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/openai-tools/_manifests.generated.js +1789 -0
- package/dist-esm/openai-tools/_manifests.generated.js.map +1 -0
- package/dist-esm/openai-tools/app-tools.json +297 -0
- package/dist-esm/openai-tools/composition-tools.json +228 -0
- package/dist-esm/openai-tools/generation-tools.json +1263 -0
- package/dist-esm/openai-tools/index.js +27 -0
- package/dist-esm/openai-tools/index.js.map +1 -0
- package/dist-esm/public-skill-runtime/index.js +85 -8
- package/dist-esm/public-skill-runtime/index.js.map +1 -1
- package/dist-esm/schemas/errors/error.schema.json +21 -0
- package/dist-esm/schemas/errors/repair-control.schema.json +40 -0
- package/dist-esm/schemas/events/artifact-reference.schema.json +22 -0
- package/dist-esm/schemas/events/progress-event.schema.json +28 -0
- package/dist-esm/schemas/events/workflow-event.schema.json +22 -0
- package/dist-esm/schemas/storyboards/storyboard-planning-contract.schema.json +108 -0
- package/dist-esm/schemas/tools/add_subtitles.schema.json +77 -0
- package/dist-esm/schemas/tools/animate_photo.schema.json +104 -0
- package/dist-esm/schemas/tools/apply_style.schema.json +37 -0
- package/dist-esm/schemas/tools/change_angle.schema.json +30 -0
- package/dist-esm/schemas/tools/compose_instrumental.schema.json +24 -0
- package/dist-esm/schemas/tools/compose_lyrics.schema.json +28 -0
- package/dist-esm/schemas/tools/compose_script.schema.json +68 -0
- package/dist-esm/schemas/tools/compose_workflow.schema.json +67 -0
- package/dist-esm/schemas/tools/compose_workflow_template.schema.json +156 -0
- package/dist-esm/schemas/tools/dance_montage.schema.json +47 -0
- package/dist-esm/schemas/tools/edit_image.schema.json +74 -0
- package/dist-esm/schemas/tools/enhance_prompt.schema.json +76 -0
- package/dist-esm/schemas/tools/extend_video.schema.json +42 -0
- package/dist-esm/schemas/tools/generate_image.schema.json +104 -0
- package/dist-esm/schemas/tools/generate_music.schema.json +62 -0
- package/dist-esm/schemas/tools/generate_video.schema.json +97 -0
- package/dist-esm/schemas/tools/orbit_video.schema.json +70 -0
- package/dist-esm/schemas/tools/overlay_video.schema.json +126 -0
- package/dist-esm/schemas/tools/refine_result.schema.json +43 -0
- package/dist-esm/schemas/tools/replace_video_segment.schema.json +60 -0
- package/dist-esm/schemas/tools/restore_photo.schema.json +47 -0
- package/dist-esm/schemas/tools/sound_to_video.schema.json +70 -0
- package/dist-esm/schemas/tools/stitch_video.schema.json +52 -0
- package/dist-esm/schemas/tools/video_to_video.schema.json +77 -0
- package/dist-esm/schemas/workflows/durable-workflow-run.schema.json +165 -0
- package/dist-esm/schemas/workflows/durable-workflow-step.schema.json +141 -0
- package/dist-esm/skill-runtime-source/crossSurfaceParity.js +469 -0
- package/dist-esm/skill-runtime-source/crossSurfaceParity.js.map +1 -0
- package/dist-esm/skill-runtime-source/index.js +4 -0
- package/dist-esm/skill-runtime-source/index.js.map +1 -0
- package/dist-esm/skill-runtime-source/seedanceAudioWindow.js +47 -0
- package/dist-esm/skill-runtime-source/seedanceAudioWindow.js.map +1 -0
- package/dist-esm/skill-runtime-source/workflowStatus.js +348 -0
- package/dist-esm/skill-runtime-source/workflowStatus.js.map +1 -0
- package/dist-esm/utils/helpers.js +1 -1
- package/dist-esm/utils/helpers.js.map +1 -1
- package/dist-esm/workflows/bindings.js +32 -2
- package/dist-esm/workflows/bindings.js.map +1 -1
- package/dist-esm/workflows/index.js +1 -0
- package/dist-esm/workflows/index.js.map +1 -1
- package/dist-esm/workflows/primitives/index.js +3 -0
- package/dist-esm/workflows/primitives/index.js.map +1 -0
- package/dist-esm/workflows/primitives/retryUntilCondition.js +95 -0
- package/dist-esm/workflows/primitives/retryUntilCondition.js.map +1 -0
- package/dist-esm/workflows/primitives/validateWithRubric.js +141 -0
- package/dist-esm/workflows/primitives/validateWithRubric.js.map +1 -0
- package/package.json +51 -3
- package/src/skill-runtime-source/crossSurfaceParity.ts +525 -0
- package/src/skill-runtime-source/index.ts +10 -0
- package/src/skill-runtime-source/seedanceAudioWindow.ts +61 -0
- package/src/skill-runtime-source/workflowStatus.ts +375 -0
- package/dist/contracts/index.mjs +0 -102
- package/dist/media/index.mjs +0 -116
- package/dist/public-skill-runtime/index.mjs +0 -141
- package/dist/replay/index.mjs +0 -12
- package/dist/runtime/index.mjs +0 -21
- package/dist/skills/asset_reference_management/index.mjs +0 -18
- package/dist/tools/index.mjs +0 -86
- package/dist/workflows/index.mjs +0 -22
package/README.md
CHANGED
|
@@ -1,823 +1,257 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sogni-ai/sogni-intelligence-client
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@sogni-ai/sogni-intelligence-client) [](https://www.npmjs.com/package/@sogni-ai/sogni-intelligence-client)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The public, mid‑tier Node.js client for the [Sogni Supernet](https://sogni.ai/) — Sogni's OpenAI‑compatible LLM and agent API for image, video, music, and chat generation. Bundles a hardened wrapper over the [`@sogni-ai/sogni-client`](https://sdk-docs.sogni.ai/) SDK with the public‑safe subset of Sogni's creative‑agent platform: hosted tool definitions, the contract registry, asset manifests, `RunRecord` types with redaction, skill‑runtime helpers, and JSON Schema artifacts for cross‑language codegen.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
For most agent builders this is the recommended starting point. Designed for third‑party integrations, downstream SDKs, and orchestration frameworks (n8n, LangChain, Anthropic skills, custom runtimes). Drives the same contracts and tool surface that the hosted `POST https://api.sogni.ai/v1/chat/completions`, `/v1/chat/runs`, and `/v1/creative-agent/workflows` endpoints use, so a client‑side agent loop stays shape‑locked with the server.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Which package should I install?
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **Vision Chat + Thinking Controls**: Send OpenAI-style multimodal `image_url` messages and toggle reasoning with `think`.
|
|
18
|
-
- **Chat Tool Execution Helpers**: Execute Sogni platform tool calls manually from the wrapper, including streaming follow-up loops.
|
|
19
|
-
- **Flexible Authentication**: Token, cookies, or API key authentication.
|
|
20
|
-
- **Wallet + Tracking Utilities**: Query Base/Etherlink wallet balances and inspect SDK-tracked projects/current account state.
|
|
21
|
-
- **Simplified Configuration**: Sensible defaults and clear configuration options.
|
|
22
|
-
- **Enhanced Error Handling**: Custom error classes for better error diagnosis.
|
|
23
|
-
- **Type-Safe**: Written entirely in TypeScript with full type definitions.
|
|
24
|
-
- **n8n-Ready**: Built with n8n integration in mind, managing connection lifecycles effectively.
|
|
25
|
-
- **Utility Helpers**: Includes helpers for validation, retries, and formatting.
|
|
11
|
+
| You're building… | Install |
|
|
12
|
+
|---|---|
|
|
13
|
+
| Custom AI agent that calls Sogni tools, validates LLM tool arguments, manages asset references | **`@sogni-ai/sogni-intelligence-client`** (recommended) |
|
|
14
|
+
| Thin wrapper that only generates an image/video/audio from a single direct call | [`@sogni-ai/sogni-client`](https://www.npmjs.com/package/@sogni-ai/sogni-client) (raw SDK) |
|
|
15
|
+
| n8n workflow node | **`@sogni-ai/sogni-intelligence-client`** (n8n compat helpers preserved) |
|
|
16
|
+
| Anthropic‑style Claude Skill, OpenClaw plugin, Hermes / Manus agent | [`@sogni-ai/sogni-creative-agent-skill`](https://github.com/Sogni-AI/sogni-creative-agent-skill) (consumes intelligence‑client under the hood) |
|
|
26
17
|
|
|
27
18
|
## Installation
|
|
28
19
|
|
|
29
20
|
```bash
|
|
30
|
-
npm install @sogni-ai/sogni-intelligence-client
|
|
21
|
+
npm install @sogni-ai/sogni-intelligence-client@alpha
|
|
31
22
|
```
|
|
32
23
|
|
|
33
|
-
|
|
24
|
+
> **Pre‑release.** The current published version is `3.0.0-alpha.0` on the `alpha` dist‑tag. Pin with `@^3.0.0-alpha.0` until `3.0.0` stable is cut.
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
yarn add @sogni-ai/sogni-intelligence-client
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Quick Start
|
|
40
|
-
|
|
41
|
-
### 1. Setup Environment Variables
|
|
42
|
-
|
|
43
|
-
First, create a `.env` file in your project root to securely store your credentials:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
# Copy the example file
|
|
47
|
-
cp node_modules/@sogni-ai/sogni-intelligence-client/.env.example .env
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
### 2. Install Dependencies
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npm install dotenv
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### 3. Create Your Script
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { config } from 'dotenv';
|
|
60
|
-
import { SogniClientWrapper } from '@sogni-ai/sogni-intelligence-client';
|
|
61
|
-
|
|
62
|
-
// Load environment variables from .env file
|
|
63
|
-
config();
|
|
64
|
-
|
|
65
|
-
async function main() {
|
|
66
|
-
// 1. Create and connect the client with credentials from .env
|
|
67
|
-
const client = new SogniClientWrapper({
|
|
68
|
-
username: process.env.SOGNI_USERNAME!,
|
|
69
|
-
password: process.env.SOGNI_PASSWORD!,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
// The client connects automatically on the first operation
|
|
74
|
-
console.log('Client connected!');
|
|
75
|
-
|
|
76
|
-
// 2. Find the most popular model
|
|
77
|
-
const model = await client.getMostPopularModel();
|
|
78
|
-
console.log(`Using model: ${model.id} (${model.workerCount} workers)`);
|
|
79
|
-
|
|
80
|
-
// 3. Generate an image
|
|
81
|
-
console.log('Generating image...');
|
|
82
|
-
const result = await client.createProject({
|
|
83
|
-
type: 'image',
|
|
84
|
-
modelId: model.id,
|
|
85
|
-
positivePrompt: 'A photorealistic portrait of a majestic lion in the savanna at sunset',
|
|
86
|
-
negativePrompt: 'blurry, cartoon, low quality',
|
|
87
|
-
stylePrompt: 'cinematic',
|
|
88
|
-
numberOfMedia: 1,
|
|
89
|
-
steps: 30,
|
|
90
|
-
guidance: 8,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (result.completed && result.imageUrls) {
|
|
94
|
-
console.log('Image generation successful!');
|
|
95
|
-
console.log('Image URLs:', result.imageUrls);
|
|
96
|
-
} else {
|
|
97
|
-
console.error('Image generation did not complete.');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
} catch (error) {
|
|
101
|
-
console.error('An error occurred:', error);
|
|
102
|
-
} finally {
|
|
103
|
-
// 4. Disconnect the client
|
|
104
|
-
await client.disconnect();
|
|
105
|
-
console.log('Client disconnected.');
|
|
106
|
-
}
|
|
107
|
-
}
|
|
26
|
+
Requires Node.js ≥ 18.
|
|
108
27
|
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### 4. Run the Script
|
|
28
|
+
## Package structure
|
|
113
29
|
|
|
114
|
-
|
|
115
|
-
# If using TypeScript
|
|
116
|
-
npx tsx your-script.ts
|
|
117
|
-
|
|
118
|
-
# If using compiled JavaScript
|
|
119
|
-
node your-script.js
|
|
120
|
-
```
|
|
30
|
+
The package exposes nine subpath entry points so consumers import only what they need:
|
|
121
31
|
|
|
122
|
-
|
|
32
|
+
| Subpath | Purpose |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `@sogni-ai/sogni-intelligence-client` | `SogniClientWrapper` connection class + helpers + re‑exports from the underlying SDK |
|
|
35
|
+
| `…/contracts` | Public contracts, default policies, repair recipes, prompt contracts, schema registry |
|
|
36
|
+
| `…/tools` | Sogni‑hosted tool definitions and argument validators (image, video, audio, editing, analysis) |
|
|
37
|
+
| `…/replay` | `RunRecord` types + redaction utilities (signed URLs, JWTs, bearer tokens scrubbed) |
|
|
38
|
+
| `…/runtime` | Contract runtime — apply policies, recipes, and prompt contracts at call sites |
|
|
39
|
+
| `…/public-skill-runtime` | Skill‑side helpers: classify turns, compile tool surface, dispatch tool calls |
|
|
40
|
+
| `…/skills/asset_reference_management` | Asset‑reference resolution helpers for hosted media |
|
|
41
|
+
| `…/workflows` | Creative‑workflow type definitions, bindings with embedded‑interpolation support, and a `primitives` namespace of pure helpers for `wf:*` stage tools (LLM judge + `__PASS__`/`__FAIL__` parser, bounded retry‑until‑predicate, storyboard script expander, dialogue duration fitter, SSRF allow‑list for fetched artifact URLs) |
|
|
42
|
+
| `…/media` | Media reference helpers (upload / download URL flows) |
|
|
43
|
+
| `…/schemas/*` | Raw JSON Schema artifacts for cross‑language codegen (Swift, Kotlin, Python, etc.) |
|
|
123
44
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
### Video Generation Example
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
// Text-to-Video (t2v) using speed variant for reliability
|
|
130
|
-
const videoResult = await client.createVideoProject({
|
|
131
|
-
modelId: 'wan_v2.2-14b-fp8_t2v_lightx2v', // Speed variant (4 steps)
|
|
132
|
-
positivePrompt: 'A serene waterfall flowing through a lush green forest',
|
|
133
|
-
numberOfMedia: 1,
|
|
134
|
-
frames: 81, // Generate 81 frames (5 seconds at 16fps)
|
|
135
|
-
fps: 16, // 16 frames per second
|
|
136
|
-
width: 640, // 640x640 resolution
|
|
137
|
-
height: 640,
|
|
138
|
-
steps: 4, // Optimized for speed variant
|
|
139
|
-
outputFormat: 'mp4',
|
|
140
|
-
waitForCompletion: true,
|
|
141
|
-
timeout: 300000, // 5 minute timeout for video generation
|
|
142
|
-
});
|
|
45
|
+
Each subpath ships dual CJS + ESM with TypeScript declarations.
|
|
143
46
|
|
|
144
|
-
|
|
145
|
-
```
|
|
47
|
+
## Quick start
|
|
146
48
|
|
|
147
|
-
###
|
|
49
|
+
### 1. Configure credentials
|
|
148
50
|
|
|
149
|
-
|
|
150
|
-
const estimate = await client.estimateVideoCost({
|
|
151
|
-
modelId: 'wan_v2.2-14b-fp8_i2v_lightx2v',
|
|
152
|
-
width: 512,
|
|
153
|
-
height: 512,
|
|
154
|
-
frames: 81,
|
|
155
|
-
fps: 16,
|
|
156
|
-
steps: 4,
|
|
157
|
-
tokenType: 'spark',
|
|
158
|
-
});
|
|
51
|
+
Create a `.env` in your project root:
|
|
159
52
|
|
|
160
|
-
|
|
53
|
+
```env
|
|
54
|
+
SOGNI_USERNAME=your-username
|
|
55
|
+
SOGNI_PASSWORD=your-password
|
|
56
|
+
SOGNI_APP_ID=your-app-id # optional; auto‑generated if omitted
|
|
57
|
+
SOGNI_NETWORK=fast # or "relaxed"
|
|
161
58
|
```
|
|
162
59
|
|
|
163
|
-
###
|
|
164
|
-
|
|
165
|
-
The wrapper supports multiple video generation workflows:
|
|
166
|
-
|
|
167
|
-
1. **Text-to-Video (t2v)**: Generate videos from text prompts
|
|
168
|
-
2. **Image-to-Video (i2v)**: Animate static images or interpolate between two images
|
|
169
|
-
3. **Sound-to-Video (s2v / ia2v / a2v)**: Drive generation with audio references
|
|
170
|
-
4. **Video-to-Video (v2v)**: Control motion/style from a reference video
|
|
171
|
-
5. **Animate Workflows**: Create character animations or motion transfers
|
|
172
|
-
|
|
173
|
-
### Advanced Video Examples
|
|
60
|
+
### 2. Image generation
|
|
174
61
|
|
|
175
62
|
```typescript
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
modelId: 'wan_v2.2-14b-fp8_i2v_lightx2v',
|
|
179
|
-
positivePrompt: 'Smooth camera movement',
|
|
180
|
-
referenceImage: startImageBuffer, // Starting image
|
|
181
|
-
referenceImageEnd: endImageBuffer, // Optional: end image for interpolation
|
|
182
|
-
width: 512,
|
|
183
|
-
height: 512,
|
|
184
|
-
frames: 81,
|
|
185
|
-
fps: 16,
|
|
186
|
-
steps: 4,
|
|
187
|
-
autoResizeVideoAssets: true, // Auto-resize reference images (default: true)
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
// Animate with motion transfer
|
|
191
|
-
const animateResult = await client.createVideoProject({
|
|
192
|
-
modelId: 'wan_v2.2-14b-fp8_animate',
|
|
193
|
-
positivePrompt: 'Character animation',
|
|
194
|
-
referenceImage: characterImage, // Character to animate
|
|
195
|
-
referenceVideo: motionVideo, // Video with motion to transfer
|
|
196
|
-
frames: 90,
|
|
197
|
-
fps: 30,
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
// LTX image+audio-to-video (ia2v)
|
|
201
|
-
const ia2vResult = await client.createVideoProject({
|
|
202
|
-
modelId: 'ltx2-13b-fp8_ia2v_distilled',
|
|
203
|
-
positivePrompt: 'A cinematic portrait delivering the spoken line naturally',
|
|
204
|
-
referenceImage: portraitBuffer,
|
|
205
|
-
referenceAudio: speechBuffer,
|
|
206
|
-
audioStart: 0,
|
|
207
|
-
audioDuration: 5,
|
|
208
|
-
fps: 24,
|
|
209
|
-
duration: 5,
|
|
210
|
-
numberOfMedia: 1,
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
// LTX audio-to-video (a2v)
|
|
214
|
-
const a2vResult = await client.createVideoProject({
|
|
215
|
-
modelId: 'ltx23-22b-fp8_a2v_distilled',
|
|
216
|
-
positivePrompt: 'Abstract visuals that pulse with the soundtrack',
|
|
217
|
-
referenceAudio: soundtrackBuffer,
|
|
218
|
-
audioStart: 2,
|
|
219
|
-
audioDuration: 6,
|
|
220
|
-
fps: 24,
|
|
221
|
-
duration: 6,
|
|
222
|
-
numberOfMedia: 1,
|
|
223
|
-
});
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### Convenience Methods
|
|
227
|
-
|
|
228
|
-
For cleaner code, use the dedicated convenience methods:
|
|
63
|
+
import 'dotenv/config';
|
|
64
|
+
import { SogniClientWrapper } from '@sogni-ai/sogni-intelligence-client';
|
|
229
65
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
modelId: 'flux1-schnell-fp8',
|
|
234
|
-
positivePrompt: 'A beautiful sunset',
|
|
235
|
-
numberOfMedia: 1,
|
|
66
|
+
const client = new SogniClientWrapper({
|
|
67
|
+
username: process.env.SOGNI_USERNAME!,
|
|
68
|
+
password: process.env.SOGNI_PASSWORD!,
|
|
236
69
|
});
|
|
237
70
|
|
|
238
|
-
|
|
239
|
-
const videoResult = await client.createVideoProject({
|
|
240
|
-
modelId: 'wan_v2.2-14b-fp8_t2v',
|
|
241
|
-
positivePrompt: 'Ocean waves crashing on a beach',
|
|
242
|
-
numberOfMedia: 1,
|
|
243
|
-
frames: 60,
|
|
244
|
-
fps: 30,
|
|
245
|
-
});
|
|
71
|
+
const model = await client.getMostPopularModel();
|
|
246
72
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
modelId:
|
|
250
|
-
positivePrompt: '
|
|
73
|
+
const result = await client.createProject({
|
|
74
|
+
type: 'image',
|
|
75
|
+
modelId: model.id,
|
|
76
|
+
positivePrompt: 'A photorealistic portrait of a majestic lion at sunset',
|
|
77
|
+
negativePrompt: 'blurry, cartoon, low quality',
|
|
78
|
+
stylePrompt: 'cinematic',
|
|
251
79
|
numberOfMedia: 1,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
outputFormat: 'mp3',
|
|
80
|
+
steps: 30,
|
|
81
|
+
guidance: 8,
|
|
255
82
|
});
|
|
256
|
-
```
|
|
257
83
|
|
|
258
|
-
|
|
84
|
+
console.log(result.images.map((i) => i.url));
|
|
259
85
|
|
|
260
|
-
|
|
261
|
-
const audioEstimate = await client.estimateAudioCost({
|
|
262
|
-
modelId: 'ace-step-v1',
|
|
263
|
-
duration: 30,
|
|
264
|
-
steps: 20,
|
|
265
|
-
numberOfMedia: 1,
|
|
266
|
-
tokenType: 'spark',
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
console.log('Estimated audio cost (USD):', audioEstimate.usd);
|
|
86
|
+
await client.disconnect();
|
|
270
87
|
```
|
|
271
88
|
|
|
272
|
-
|
|
89
|
+
### 3. Tool calling against Sogni's hosted catalog
|
|
273
90
|
|
|
274
91
|
```typescript
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
92
|
+
import {
|
|
93
|
+
SogniClientWrapper,
|
|
94
|
+
SogniTools,
|
|
95
|
+
isSogniToolCall,
|
|
96
|
+
} from '@sogni-ai/sogni-intelligence-client';
|
|
97
|
+
|
|
98
|
+
const client = new SogniClientWrapper({ /* … */ });
|
|
99
|
+
|
|
100
|
+
const chat = await client.chat.completions.create({
|
|
101
|
+
model: 'openai/gpt-oss-120b',
|
|
102
|
+
messages: [{ role: 'user', content: 'Generate a 3‑second clip of a koi pond.' }],
|
|
103
|
+
tools: SogniTools.all, // the full Sogni-hosted tool catalog
|
|
279
104
|
});
|
|
280
|
-
console.log(completion.content);
|
|
281
105
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
stream: true,
|
|
287
|
-
});
|
|
288
|
-
for await (const chunk of stream) {
|
|
289
|
-
process.stdout.write(chunk.content);
|
|
106
|
+
const call = chat.choices[0].message.tool_calls?.[0];
|
|
107
|
+
if (call && isSogniToolCall(call.function.name)) {
|
|
108
|
+
// Hand the tool call off to Sogni's hosted execution surface, or
|
|
109
|
+
// dispatch it locally via /public-skill-runtime.
|
|
290
110
|
}
|
|
291
111
|
```
|
|
292
112
|
|
|
293
|
-
###
|
|
294
|
-
|
|
295
|
-
`createChatCompletion()` accepts OpenAI-style `tools` and `tool_choice` parameters.
|
|
113
|
+
### 4. Replay a previous run with redaction
|
|
296
114
|
|
|
297
115
|
```typescript
|
|
298
|
-
import
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
parameters: {
|
|
307
|
-
type: 'object',
|
|
308
|
-
properties: {
|
|
309
|
-
a: { type: 'number' },
|
|
310
|
-
b: { type: 'number' },
|
|
311
|
-
},
|
|
312
|
-
required: ['a', 'b'],
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
},
|
|
316
|
-
];
|
|
317
|
-
|
|
318
|
-
const messages: ChatMessage[] = [
|
|
319
|
-
{ role: 'user', content: 'Please add 17 and 25.' },
|
|
320
|
-
];
|
|
321
|
-
|
|
322
|
-
for (let turn = 0; turn < 4; turn++) {
|
|
323
|
-
const result = await client.createChatCompletion({
|
|
324
|
-
model: 'qwen3-30b-a3b-gptq-int4',
|
|
325
|
-
messages,
|
|
326
|
-
tools,
|
|
327
|
-
tool_choice: 'auto',
|
|
328
|
-
tokenType: 'spark',
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
const toolCalls = result.tool_calls || [];
|
|
332
|
-
if (toolCalls.length === 0) {
|
|
333
|
-
console.log('Final answer:', result.content);
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
messages.push({
|
|
338
|
-
role: 'assistant',
|
|
339
|
-
content: result.content || null,
|
|
340
|
-
tool_calls: toolCalls,
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
for (const toolCall of toolCalls) {
|
|
344
|
-
const args = JSON.parse(toolCall.function.arguments || '{}');
|
|
345
|
-
let output = { error: `Unknown tool: ${toolCall.function.name}` };
|
|
346
|
-
|
|
347
|
-
if (toolCall.function.name === 'add_numbers') {
|
|
348
|
-
const a = Number(args.a || 0);
|
|
349
|
-
const b = Number(args.b || 0);
|
|
350
|
-
output = { a, b, sum: a + b };
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
messages.push({
|
|
354
|
-
role: 'tool',
|
|
355
|
-
tool_call_id: toolCall.id,
|
|
356
|
-
name: toolCall.function.name,
|
|
357
|
-
content: JSON.stringify(output),
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
}
|
|
116
|
+
import {
|
|
117
|
+
type RunRecord,
|
|
118
|
+
redactRunRecord,
|
|
119
|
+
redactPayload,
|
|
120
|
+
} from '@sogni-ai/sogni-intelligence-client/replay';
|
|
121
|
+
|
|
122
|
+
const safeRecord: RunRecord = redactRunRecord(originalRecord);
|
|
123
|
+
// Signed URLs, bearer tokens, JWTs, and inline secrets are scrubbed.
|
|
361
124
|
```
|
|
362
125
|
|
|
363
|
-
###
|
|
364
|
-
|
|
365
|
-
The wrapper re-exports the SDK helpers for Sogni platform tool calling:
|
|
366
|
-
|
|
367
|
-
- `SogniTools` — the canonical 24-tool surface (use `SogniTools.all` for the full list)
|
|
368
|
-
- `isSogniToolCall()`
|
|
369
|
-
- `parseToolCallArguments()`
|
|
126
|
+
### 5. Validate a hosted‑tool argument blob
|
|
370
127
|
|
|
371
128
|
```typescript
|
|
372
|
-
import {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
129
|
+
import {
|
|
130
|
+
validateAndNormalizeHostedToolArguments,
|
|
131
|
+
} from '@sogni-ai/sogni-intelligence-client/contracts';
|
|
132
|
+
|
|
133
|
+
const { ok, value, error } = validateAndNormalizeHostedToolArguments(
|
|
134
|
+
'generate_image',
|
|
135
|
+
{ prompt: 'a serene koi pond', steps: 30 },
|
|
136
|
+
);
|
|
137
|
+
if (!ok) throw error;
|
|
138
|
+
// `value` is the normalized argument object ready to dispatch.
|
|
381
139
|
```
|
|
382
140
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
const result = await client.createChatCompletion({
|
|
387
|
-
model: 'qwen3.5-35b-a3b-gguf-q4km',
|
|
388
|
-
messages: [
|
|
389
|
-
{
|
|
390
|
-
role: 'user',
|
|
391
|
-
content: [
|
|
392
|
-
{ type: 'text', text: 'Describe the scene and read any visible text.' },
|
|
393
|
-
{
|
|
394
|
-
type: 'image_url',
|
|
395
|
-
image_url: {
|
|
396
|
-
url: 'https://example.com/photo.jpg',
|
|
397
|
-
detail: 'high',
|
|
398
|
-
},
|
|
399
|
-
},
|
|
400
|
-
],
|
|
401
|
-
},
|
|
402
|
-
],
|
|
403
|
-
think: false,
|
|
404
|
-
max_tokens: 300,
|
|
405
|
-
tokenType: 'spark',
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
console.log(result.content);
|
|
409
|
-
```
|
|
141
|
+
## Authentication
|
|
410
142
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
Useful for streaming or custom multi-round tool loops where you want the wrapper to execute returned Sogni tool calls directly.
|
|
143
|
+
The wrapper accepts three authentication strategies through the `SogniClientConfig`:
|
|
414
144
|
|
|
415
145
|
```typescript
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
messages: [{ role: 'user', content: 'Generate a neon cyberpunk city image.' }],
|
|
419
|
-
tools: SogniTools.all,
|
|
420
|
-
tool_choice: 'auto',
|
|
421
|
-
tokenType: 'spark',
|
|
422
|
-
});
|
|
146
|
+
// Username/password
|
|
147
|
+
new SogniClientWrapper({ username, password });
|
|
423
148
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
tokenType: 'spark',
|
|
427
|
-
onToolProgress: (toolCall, progress) => {
|
|
428
|
-
console.log(toolCall.function.name, progress.status, progress.percent);
|
|
429
|
-
},
|
|
430
|
-
});
|
|
149
|
+
// API key
|
|
150
|
+
new SogniClientWrapper({ apiKey });
|
|
431
151
|
|
|
432
|
-
|
|
433
|
-
}
|
|
152
|
+
// Token + cookies (typical for browser/edge contexts)
|
|
153
|
+
new SogniClientWrapper({ token, cookies });
|
|
434
154
|
```
|
|
435
155
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
Run these scripts with `npx tsx`:
|
|
439
|
-
|
|
440
|
-
- `examples/llm-chat-basic.ts`
|
|
441
|
-
- `examples/llm-chat-streaming.ts`
|
|
442
|
-
- `examples/llm-chat-vision.ts --image ./photo.jpg`
|
|
443
|
-
- `examples/llm-tool-calling-custom.ts`
|
|
444
|
-
- `examples/llm-tool-calling-sogni-tools.ts` (supports `--dry-run`)
|
|
156
|
+
Connection management, reconnection, and credit/balance polling are handled automatically. Call `client.disconnect()` when finished.
|
|
445
157
|
|
|
446
|
-
##
|
|
158
|
+
## Generation surfaces
|
|
447
159
|
|
|
448
|
-
The wrapper
|
|
160
|
+
The root wrapper exposes type‑safe project creation across every modality Sogni supports:
|
|
449
161
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
| `qwen_image_edit_2511_fp8_lightning` | Fast | 4 | 3 |
|
|
456
|
-
|
|
457
|
-
### Image Edit Example
|
|
458
|
-
|
|
459
|
-
```typescript
|
|
460
|
-
import { readFileSync } from 'fs';
|
|
162
|
+
- **Image generation** — Stable Diffusion XL, Flux, full model marketplace.
|
|
163
|
+
- **Video generation** — WAN 2.2, LTX‑2.3, Seedance v2; workflows `t2v`, `i2v`, `s2v`, `ia2v`, `a2v`, `v2v`, `animate_move`, `animate_replace`.
|
|
164
|
+
- **Audio generation** — music and SFX models with cost estimation.
|
|
165
|
+
- **Image editing** — Qwen vision‑aware editors with multi‑reference context images.
|
|
166
|
+
- **Chat completions** — OpenAI‑shaped chat API against Sogni's LLM worker network. Streaming, vision (`image_url`), reasoning (`think`), and function/tool calling are first‑class.
|
|
461
167
|
|
|
462
|
-
|
|
463
|
-
const referenceImage = readFileSync('./my-image.png');
|
|
168
|
+
See the [SDK docs](https://sdk-docs.sogni.ai/) for full parameter references on each surface.
|
|
464
169
|
|
|
465
|
-
|
|
466
|
-
const result = await client.createImageEditProject({
|
|
467
|
-
modelId: 'qwen_image_edit_2511_fp8',
|
|
468
|
-
positivePrompt: 'Transform the cat into a majestic lion',
|
|
469
|
-
contextImages: [referenceImage],
|
|
470
|
-
numberOfMedia: 1,
|
|
471
|
-
steps: 20,
|
|
472
|
-
guidance: 4.0,
|
|
473
|
-
});
|
|
170
|
+
## Contracts, tools, and skills
|
|
474
171
|
|
|
475
|
-
|
|
476
|
-
```
|
|
172
|
+
Sogni's hosted tool surface — `generate_image`, `generate_video`, `analyze_video`, `replace_video_segment`, and 20+ others — is described declaratively. Consumers can:
|
|
477
173
|
|
|
478
|
-
|
|
174
|
+
- Enumerate the catalog: `import { SogniTools } from '@sogni-ai/sogni-intelligence-client'`.
|
|
175
|
+
- Validate / normalize arguments before dispatch: `validateAndNormalizeHostedToolArguments` from `/contracts`.
|
|
176
|
+
- Apply gating policies, repair recipes, and prompt contracts at runtime: `createPublicSkillDefaultContractRuntime` from `/public-skill-runtime`.
|
|
177
|
+
- Generate JSON Schema clients for other languages from `/schemas/*`.
|
|
479
178
|
|
|
480
|
-
|
|
179
|
+
For an end‑to‑end agent example, see the [Sogni Creative Agent Skill](https://github.com/Sogni-AI/sogni-creative-agent-skill) — the `sogni-agent` CLI plus a `SKILL.md` behavior file for Claude Code, OpenClaw, Hermes Agent, and Manus. It consumes only this package's public surface.
|
|
481
180
|
|
|
482
|
-
|
|
483
|
-
const image1 = readFileSync('./subject.png');
|
|
484
|
-
const image2 = readFileSync('./style-reference.png');
|
|
485
|
-
const image3 = readFileSync('./background.png');
|
|
486
|
-
|
|
487
|
-
const result = await client.createImageEditProject({
|
|
488
|
-
modelId: 'qwen_image_edit_2511_fp8_lightning', // Fast variant
|
|
489
|
-
positivePrompt: 'Combine the subject with the style and background',
|
|
490
|
-
contextImages: [image1, image2, image3],
|
|
491
|
-
numberOfMedia: 1,
|
|
492
|
-
steps: 4, // Optimized for lightning variant
|
|
493
|
-
guidance: 1.0,
|
|
494
|
-
});
|
|
495
|
-
```
|
|
181
|
+
## RunRecord replay & redaction
|
|
496
182
|
|
|
497
|
-
|
|
183
|
+
`RunRecord` is the canonical JSON representation of a Sogni run: tool calls, results, costs, audit trail, and timing. Useful for replay, post‑hoc audits, and offline analysis.
|
|
498
184
|
|
|
499
185
|
```typescript
|
|
500
|
-
import {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
steps: 4,
|
|
510
|
-
guidance: 1.0,
|
|
511
|
-
sampler: 'euler',
|
|
512
|
-
scheduler: 'simple',
|
|
513
|
-
outputFormat: 'jpg',
|
|
514
|
-
loras: ['multiple_angles'],
|
|
515
|
-
loraStrengths: [0.9],
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
console.log('Generated images:', result.imageUrls);
|
|
186
|
+
import {
|
|
187
|
+
type RunRecord,
|
|
188
|
+
type RunRecordRound,
|
|
189
|
+
type RunRecordToolCall,
|
|
190
|
+
type RunRecordToolResult,
|
|
191
|
+
emptyRunRecord,
|
|
192
|
+
redactRunRecord,
|
|
193
|
+
RUN_RECORD_SCHEMA_VERSION,
|
|
194
|
+
} from '@sogni-ai/sogni-intelligence-client/replay';
|
|
519
195
|
```
|
|
520
196
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
The `contextImages` parameter accepts an array of `InputMedia` types:
|
|
524
|
-
|
|
525
|
-
- `Buffer` - Node.js Buffer containing image data
|
|
526
|
-
- `Blob` - Browser Blob object
|
|
527
|
-
- `File` - Browser File object
|
|
528
|
-
- `true` - Boolean indicating a pre-uploaded image
|
|
197
|
+
`redactRunRecord` / `redactPayload` scrub signed URLs, bearer tokens, JWTs, and inline secrets — call them before persisting or logging records.
|
|
529
198
|
|
|
530
|
-
|
|
199
|
+
## Error handling
|
|
531
200
|
|
|
532
|
-
|
|
201
|
+
Errors are typed for precise dispatch:
|
|
533
202
|
|
|
534
203
|
```typescript
|
|
535
|
-
import {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
getMaxContextImages('kontext-model'); // Returns 2
|
|
548
|
-
getMaxContextImages('sd-xl-base'); // Returns 0 (not supported)
|
|
204
|
+
import {
|
|
205
|
+
SogniError,
|
|
206
|
+
SogniConnectionError,
|
|
207
|
+
SogniAuthenticationError,
|
|
208
|
+
SogniProjectError,
|
|
209
|
+
SogniTimeoutError,
|
|
210
|
+
SogniBalanceError,
|
|
211
|
+
SogniValidationError,
|
|
212
|
+
SogniConfigurationError,
|
|
213
|
+
SogniModelNotFoundError,
|
|
214
|
+
SogniNetworkError,
|
|
215
|
+
} from '@sogni-ai/sogni-intelligence-client';
|
|
549
216
|
```
|
|
550
217
|
|
|
551
|
-
|
|
218
|
+
Each error carries `cause` and a typed `data` field where applicable.
|
|
552
219
|
|
|
553
|
-
|
|
220
|
+
## TypeScript & module formats
|
|
554
221
|
|
|
555
|
-
|
|
222
|
+
- Written in TypeScript; full `.d.ts` declarations ship for every subpath.
|
|
223
|
+
- Dual CJS + ESM builds (`require()` and `import` both work).
|
|
224
|
+
- `moduleResolution: 'node'` and `'bundler'` both supported; `'node16'` / `'nodenext'` consumers should prefer the `import` condition.
|
|
556
225
|
|
|
557
|
-
|
|
226
|
+
## Migrating from `@sogni-ai/sogni-client-wrapper`
|
|
558
227
|
|
|
559
|
-
|
|
560
|
-
|---|---|---|---|
|
|
561
|
-
| `authType` | `'token' \| 'cookies' \| 'apiKey'` | `'token'` | Authentication mode. |
|
|
562
|
-
| `username` | `string` | Conditionally required | Required for `token` auth; optional for `cookies`/`apiKey`. |
|
|
563
|
-
| `password` | `string` | Conditionally required | Required for `token` auth; optional for `cookies`/`apiKey`. |
|
|
564
|
-
| `apiKey` | `string` | Conditionally required | Required for `apiKey` auth. |
|
|
565
|
-
| `appId` | `string` | Auto-generated UUID | Unique ID for your application. |
|
|
566
|
-
| `network` | `'fast' \| 'relaxed'` | `'fast'` | The Sogni network to use. |
|
|
567
|
-
| `testnet` | `boolean` | `false` | Connect to the testnet network. |
|
|
568
|
-
| `socketEndpoint` | `string` | `undefined` | Override the default WebSocket API endpoint. |
|
|
569
|
-
| `restEndpoint` | `string` | `undefined` | Override the default REST API endpoint. |
|
|
570
|
-
| `disableSocket` | `boolean` | `false` | Disable WebSocket connection (advanced/testing). |
|
|
571
|
-
| `allowInsecureTLS` | `boolean` | `false` | Allow insecure TLS (useful for testnet with self-signed certs). |
|
|
572
|
-
| `autoConnect` | `boolean` | `true` | Connect automatically on the first operation. |
|
|
573
|
-
| `reconnect` | `boolean` | `true` | Attempt to reconnect if the connection is lost. |
|
|
574
|
-
| `reconnectInterval` | `number` | `5000` | Time in ms between reconnect attempts. |
|
|
575
|
-
| `timeout` | `number` | `300000` | Default timeout in ms for operations. |
|
|
576
|
-
| `debug` | `boolean` | `false` | Enable detailed console logging. |
|
|
228
|
+
If you previously installed `@sogni-ai/sogni-client-wrapper`, the import path is the only thing that changes:
|
|
577
229
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const client = new SogniClientWrapper({
|
|
582
|
-
authType: 'apiKey',
|
|
583
|
-
apiKey: process.env.SOGNI_API_KEY!,
|
|
584
|
-
network: 'fast',
|
|
585
|
-
});
|
|
230
|
+
```diff
|
|
231
|
+
- import { SogniClientWrapper } from '@sogni-ai/sogni-client-wrapper';
|
|
232
|
+
+ import { SogniClientWrapper } from '@sogni-ai/sogni-intelligence-client';
|
|
586
233
|
```
|
|
587
234
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
- `connect(): Promise<void>`: Manually initiates the connection to Sogni.
|
|
591
|
-
- `disconnect(): Promise<void>`: Disconnects the client.
|
|
592
|
-
- `isConnected(): boolean`: Checks if the client is currently connected.
|
|
593
|
-
- `getConnectionState(): ConnectionState`: Returns the current connection status.
|
|
594
|
-
|
|
595
|
-
### Main Operations
|
|
596
|
-
|
|
597
|
-
- `createProject(config: ProjectConfig): Promise<ProjectResult>`: Creates a new image, video, or audio generation project.
|
|
598
|
-
- `waitForCompletion` (default: `true`): If true, the promise resolves only when the media is ready.
|
|
599
|
-
- For images: returns `imageUrls` in result
|
|
600
|
-
- For videos: returns `videoUrls` in result
|
|
601
|
-
- For audio: returns `audioUrls` in result
|
|
602
|
-
- `createImageProject(config)`: Convenience method for image generation (automatically sets `type: 'image'`).
|
|
603
|
-
- `createVideoProject(config)`: Convenience method for video generation (automatically sets `type: 'video'`).
|
|
604
|
-
- `createAudioProject(config)`: Convenience method for audio generation (automatically sets `type: 'audio'`).
|
|
605
|
-
- `createImageEditProject(config: QwenImageEditConfig)`: Convenience method for image editing with context images (validates model-specific limits).
|
|
606
|
-
- `getAvailableModels(options?: GetModelsOptions): Promise<ModelInfo[]>`: Retrieves a list of available models.
|
|
607
|
-
- `getModel(modelId: string): Promise<ModelInfo>`: Retrieves details for a specific model.
|
|
608
|
-
- `getMostPopularModel(): Promise<ModelInfo>`: A helper to get the model with the most active workers.
|
|
609
|
-
- `getBalance(): Promise<BalanceInfo>`: Fetches your current SOGNI and Spark token balances using the `account.refreshBalance()` method.
|
|
610
|
-
- `getWalletBalance(walletAddress?, provider?): Promise<WalletBalanceInfo>`: Fetches Base or Etherlink wallet balances. When `walletAddress` is omitted, the wrapper uses the connected account wallet.
|
|
611
|
-
- `getCurrentAccount(): CurrentAccount | null`: Returns the SDK's current account snapshot if the client has connected.
|
|
612
|
-
- `getTrackedProjects(): Project[]`: Returns the projects currently tracked by the underlying SDK instance.
|
|
613
|
-
- `getSizePresets(network: 'fast' \| 'relaxed', modelId: string): Promise<SizePreset[]>`: Gets available output size presets for a model.
|
|
614
|
-
- `estimateVideoCost(params: VideoCostEstimateParams): Promise<CostEstimate>`: Estimates video generation costs (frames/duration, fps, steps, size).
|
|
615
|
-
- `estimateAudioCost(params: AudioCostEstimateParams): Promise<CostEstimate>`: Estimates audio generation costs (duration, steps, count).
|
|
616
|
-
- `createChatCompletion(params)`: Creates chat completions (streaming or non-streaming, including `tools` / `tool_choice` function calling).
|
|
617
|
-
- `executeChatTool(toolCall, options?)`: Executes a single Sogni platform tool call returned by chat.
|
|
618
|
-
- `executeChatTools(toolCalls, options?)`: Executes multiple tool calls, including mixed Sogni/custom tool flows.
|
|
619
|
-
- `estimateChatCost(params)`: Estimates chat completion cost.
|
|
620
|
-
- `getAvailableChatModels()`: Returns available chat/LLM models.
|
|
621
|
-
- `waitForChatModels(timeout?)`: Waits until chat/LLM models are available.
|
|
622
|
-
- SDK helper exports: `ChatStream`, `ChatToolsApi`, `CurrentAccount`, `SogniTools`, `isSogniToolCall`, `parseToolCallArguments`.
|
|
623
|
-
|
|
624
|
-
### Event Handling
|
|
625
|
-
|
|
626
|
-
The wrapper is an `EventEmitter` and provides type-safe events.
|
|
235
|
+
All wrapper APIs are preserved at the root export. The intelligence client adds the new subpaths above; adopt them incrementally. The old `@sogni-ai/sogni-client-wrapper` npm name is deprecated.
|
|
627
236
|
|
|
628
|
-
|
|
629
|
-
import { ClientEvent } from '@sogni-ai/sogni-intelligence-client';
|
|
237
|
+
## Related packages and docs
|
|
630
238
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
client
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
client.on(ClientEvent.ERROR, (error) => {
|
|
643
|
-
console.error('A client error occurred:', error.message);
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
// Per-media events - Display outputs as soon as they're ready!
|
|
647
|
-
client.on(ClientEvent.JOB_COMPLETED, (data) => {
|
|
648
|
-
console.log(`Job ${data.jobIndex + 1}/${data.totalJobs} completed!`);
|
|
649
|
-
console.log(`URL: ${data.imageUrl || data.videoUrl || data.audioUrl}`);
|
|
650
|
-
// You can now handle this individual output without waiting for the entire batch
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
client.on(ClientEvent.JOB_FAILED, (data) => {
|
|
654
|
-
console.log(`Job ${data.jobIndex + 1}/${data.totalJobs} failed:`, data.error);
|
|
655
|
-
});
|
|
656
|
-
```
|
|
657
|
-
|
|
658
|
-
#### Available Events
|
|
659
|
-
|
|
660
|
-
| Event | Payload | Description |
|
|
661
|
-
|---|---|---|
|
|
662
|
-
| `connected` | `void` | Fired when the client successfully connects. |
|
|
663
|
-
| `disconnected` | `void` | Fired when the client disconnects. |
|
|
664
|
-
| `reconnecting` | `number` | Fired when a reconnection attempt starts. Payload is the attempt number. |
|
|
665
|
-
| `error` | `ErrorData` | Fired when a client or connection error occurs. |
|
|
666
|
-
| `projectProgress` | `ProjectProgress` | Fired with real-time progress updates for a project. |
|
|
667
|
-
| `projectCompleted` | `ProjectResult` | Fired when a project successfully completes. |
|
|
668
|
-
| `projectFailed` | `ErrorData` | Fired when a project fails. |
|
|
669
|
-
| **`jobCompleted`** | **`JobCompletedData`** | **Fired when an individual job finishes (image/video/audio).** |
|
|
670
|
-
| **`jobFailed`** | **`JobFailedData`** | **Fired when an individual job fails.** |
|
|
671
|
-
| `projectEvent` | `ProjectEvent` | Raw project events from the SDK (`queued`, `completed`, `error`). |
|
|
672
|
-
| `jobEvent` | `JobEvent` | Raw job events from the SDK (includes `jobETA`, `started`, `progress`, etc). |
|
|
673
|
-
| `chatToken` | `ChatCompletionChunk` | Fired for each streaming chat token chunk. |
|
|
674
|
-
| `chatCompleted` | `ChatCompletionResult` | Fired when a chat completion finishes. |
|
|
675
|
-
| `chatError` | `ChatErrorData` | Fired when a chat completion fails. |
|
|
676
|
-
| `chatJobState` | `ChatJobStateEvent` | Fired on chat job state transitions. |
|
|
677
|
-
| `chatModelsUpdated` | `Record<string, LLMModelInfo>` | Fired when available chat models are updated. |
|
|
678
|
-
|
|
679
|
-
#### Per-Job Event Example
|
|
680
|
-
|
|
681
|
-
Perfect for displaying batch outputs immediately as they complete:
|
|
682
|
-
|
|
683
|
-
```typescript
|
|
684
|
-
const client = new SogniClientWrapper({
|
|
685
|
-
username: process.env.SOGNI_USERNAME!,
|
|
686
|
-
password: process.env.SOGNI_PASSWORD!,
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
// Listen for individual image completions
|
|
690
|
-
client.on(ClientEvent.JOB_COMPLETED, (data) => {
|
|
691
|
-
console.log(`✓ Image ${data.jobIndex + 1} of ${data.totalJobs} ready!`);
|
|
692
|
-
console.log(` URL: ${data.imageUrl}`);
|
|
693
|
-
// Display the image in your UI immediately
|
|
694
|
-
displayImage(data.imageUrl);
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
// Generate a batch of images
|
|
698
|
-
const result = await client.createProject({
|
|
699
|
-
type: 'image',
|
|
700
|
-
modelId: 'flux1-schnell-fp8',
|
|
701
|
-
positivePrompt: 'A beautiful landscape',
|
|
702
|
-
numberOfMedia: 4, // Generate 4 images
|
|
703
|
-
steps: 4,
|
|
704
|
-
guidance: 3.5,
|
|
705
|
-
});
|
|
706
|
-
|
|
707
|
-
// All 4 images will be displayed as they complete, not all at once!
|
|
708
|
-
```
|
|
709
|
-
|
|
710
|
-
## Error Handling
|
|
711
|
-
|
|
712
|
-
The library throws custom errors that extend `SogniError`. This allows you to catch specific types of errors.
|
|
713
|
-
|
|
714
|
-
- `SogniConnectionError`: Issues with connecting to the WebSocket server.
|
|
715
|
-
- `SogniAuthenticationError`: Invalid credentials (username/password, cookie session, or API key).
|
|
716
|
-
- `SogniProjectError`: The image generation project failed.
|
|
717
|
-
- `SogniTimeoutError`: An operation took longer than the configured timeout.
|
|
718
|
-
- `SogniValidationError`: Invalid configuration or parameters.
|
|
719
|
-
- `SogniBalanceError`: Insufficient token balance.
|
|
720
|
-
|
|
721
|
-
```typescript
|
|
722
|
-
import { SogniAuthenticationError, SogniProjectError } from '@sogni-ai/sogni-intelligence-client';
|
|
723
|
-
|
|
724
|
-
try {
|
|
725
|
-
// ... your code
|
|
726
|
-
} catch (error) {
|
|
727
|
-
if (error instanceof SogniAuthenticationError) {
|
|
728
|
-
console.error('Please check your credentials.');
|
|
729
|
-
} else if (error instanceof SogniProjectError) {
|
|
730
|
-
console.error('The image generation failed. Please try a different prompt or model.');
|
|
731
|
-
} else {
|
|
732
|
-
console.error('An unknown error occurred:', error);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
```
|
|
239
|
+
| | Where |
|
|
240
|
+
|---|---|
|
|
241
|
+
| **Intelligence Client docs** | https://sdk-docs.sogni.ai/our-superapps/sogni-sdk/intelligence-client/ |
|
|
242
|
+
| **Sogni Intelligence API** | https://sdk-docs.sogni.ai/sogni-intelligence/introduction/ |
|
|
243
|
+
| **`@sogni-ai/sogni-client`** (raw SDK) | [npm](https://www.npmjs.com/package/@sogni-ai/sogni-client) · [docs](https://sdk-docs.sogni.ai/) |
|
|
244
|
+
| **`@sogni-ai/sogni-creative-agent-skill`** (CLI + Anthropic skill) | [GitHub](https://github.com/Sogni-AI/sogni-creative-agent-skill) · [npm](https://www.npmjs.com/package/@sogni-ai/sogni-creative-agent-skill) |
|
|
245
|
+
| **SogniKit** (Swift, regenerated from `/schemas/*.json`) | https://github.com/Sogni-AI/SogniKit |
|
|
246
|
+
| `@sogni/creative-agent` (private) | Server‑side orchestration, billing enforcement, persona management. Not on npm. |
|
|
736
247
|
|
|
737
248
|
## Testing
|
|
738
249
|
|
|
739
|
-
The library includes basic unit tests, example type-checking, and end-to-end tests.
|
|
740
|
-
|
|
741
|
-
### Running Tests
|
|
742
|
-
|
|
743
250
|
```bash
|
|
744
|
-
#
|
|
745
|
-
npm test
|
|
746
|
-
|
|
747
|
-
# Type-check all example scripts (including LLM/tool-calling examples)
|
|
748
|
-
npm run test:examples
|
|
749
|
-
|
|
750
|
-
# Run end-to-end tests (requires Sogni API credentials)
|
|
751
|
-
npm run test:e2e
|
|
752
|
-
|
|
753
|
-
# Run only LLM/tool-calling e2e tests
|
|
754
|
-
npm run test:e2e:llm
|
|
755
|
-
|
|
756
|
-
# Run all tests
|
|
757
|
-
npm run test:all
|
|
251
|
+
npm test # unit + type checks; no credentials required
|
|
252
|
+
npm run test:e2e # full end-to-end, requires SOGNI_USERNAME/SOGNI_PASSWORD in .env
|
|
758
253
|
```
|
|
759
254
|
|
|
760
|
-
### Setting Up End-to-End Tests
|
|
761
|
-
|
|
762
|
-
To run the end-to-end tests, you need to provide your Sogni API credentials via environment variables:
|
|
763
|
-
|
|
764
|
-
1. Copy the example environment file:
|
|
765
|
-
```bash
|
|
766
|
-
cp .env.example .env
|
|
767
|
-
```
|
|
768
|
-
|
|
769
|
-
2. Edit `.env` and add your Sogni credentials:
|
|
770
|
-
```env
|
|
771
|
-
SOGNI_USERNAME=your_sogni_username
|
|
772
|
-
SOGNI_PASSWORD=your_sogni_password
|
|
773
|
-
# Optional: force a specific chat/LLM model for e2e tests
|
|
774
|
-
# SOGNI_LLM_MODEL=qwen3-30b-a3b-gptq-int4
|
|
775
|
-
# Optional: fail suite if LLM tests cannot run (default: skip LLM tests if unavailable)
|
|
776
|
-
# SOGNI_REQUIRE_LLM_E2E=true
|
|
777
|
-
# Optional: fail suite if tool-calling tests cannot get tool_calls
|
|
778
|
-
# SOGNI_REQUIRE_TOOL_CALL_E2E=true
|
|
779
|
-
# Optional: run only LLM/tool-calling e2e tests
|
|
780
|
-
# SOGNI_E2E_SCOPE=llm
|
|
781
|
-
```
|
|
782
|
-
|
|
783
|
-
3. Run the e2e tests:
|
|
784
|
-
```bash
|
|
785
|
-
npm run test:e2e
|
|
786
|
-
```
|
|
787
|
-
|
|
788
|
-
**Note:** The e2e tests make real API calls and may consume tokens from your Sogni account. They include image/video generation and live LLM chat calls.
|
|
789
|
-
|
|
790
|
-
## TypeScript
|
|
791
|
-
|
|
792
|
-
This library is written in TypeScript and exports all necessary types for a fully-typed experience.
|
|
793
|
-
|
|
794
|
-
- `SogniClientConfig`: Configuration for the client constructor.
|
|
795
|
-
- `ProjectConfig`: Parameters for creating a project (union of `ImageProjectConfig`, `VideoProjectConfig`, and `AudioProjectConfig`).
|
|
796
|
-
- `ImageProjectConfig`: Parameters specific to image generation.
|
|
797
|
-
- `VideoProjectConfig`: Parameters specific to video generation.
|
|
798
|
-
- `AudioProjectConfig`: Parameters specific to audio generation.
|
|
799
|
-
- `QwenImageEditConfig`: Parameters for image editing with context images.
|
|
800
|
-
- `InputMedia`: Type for media inputs (`File | Buffer | Blob | boolean`).
|
|
801
|
-
- `ProjectResult`: The return type for a completed project.
|
|
802
|
-
- `VideoCostEstimateParams`: Parameters for estimating video cost.
|
|
803
|
-
- `AudioCostEstimateParams`: Parameters for estimating audio cost.
|
|
804
|
-
- `CostEstimate`: Cost estimate response shape.
|
|
805
|
-
- `ModelInfo`: Detailed information about an available model.
|
|
806
|
-
- `BalanceInfo`: Your token balance.
|
|
807
|
-
- `ErrorData`: The structure of error objects.
|
|
808
|
-
- `VideoWorkflowType`: Video generation workflow types (`t2v`, `i2v`, `s2v`, `ia2v`, `a2v`, `v2v`, `animate-move`, `animate-replace`).
|
|
809
|
-
- `JobCompletedData`: Data emitted when an individual job completes.
|
|
810
|
-
- `JobFailedData`: Data emitted when an individual job fails.
|
|
811
|
-
- `ChatCompletionParams` / `ChatCompletionResult` / `ChatCompletionChunk`: Types for chat completions.
|
|
812
|
-
- `ContentPart` / `ImageUrlContentPart`: Types for multimodal chat content.
|
|
813
|
-
- `ToolDefinition` / `ToolChoice` / `ToolCall` / `ToolCallDelta`: Types for LLM tool/function calling.
|
|
814
|
-
- `ToolExecutionOptions` / `ToolExecutionProgress` / `ToolExecutionResult` / `ToolHistoryEntry`: Types for manual or automatic chat tool execution.
|
|
815
|
-
- `LLMModelInfo` / `LLMCostEstimation`: Types for chat model metadata and cost estimates.
|
|
816
|
-
- `WalletBalanceInfo`: Wallet balance response shape for Base/Etherlink lookups.
|
|
817
|
-
- `SogniTools` / `isSogniToolCall` / `parseToolCallArguments`: Helper exports for platform tool calling workflows.
|
|
818
|
-
- `ProjectEvent`: Raw project events from the SDK.
|
|
819
|
-
- `JobEvent`: Raw job events from the SDK (includes ETA updates).
|
|
820
|
-
|
|
821
255
|
## License
|
|
822
256
|
|
|
823
|
-
[
|
|
257
|
+
MIT — see [LICENSE](./LICENSE).
|