Skip to content

Commit c98b263

Browse files
committed
Sync from diffio-ui
1 parent 18c8964 commit c98b263

39 files changed

Lines changed: 7284 additions & 2 deletions

AGENTS.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Repository Guidelines
2+
3+
## Project Structure and Module Organization
4+
Source lives in `src/`, with API resource clients and serialization under `src/api/`, shared helpers in `src/core/`, errors in `src/errors/`, and shared types in `src/types/`. Entry points are `src/index.ts` and `src/Client.ts`. Tests live in `tests/` with unit coverage in `tests/unit/` and wire level coverage in `tests/wire/`. Mock server utilities for wire tests live in `tests/mock-server/`.
5+
6+
## Build, Test, and Development Commands
7+
1. `npm run build` compiles TypeScript to `dist/` using `tsc`.
8+
2. `npm test` runs all Jest projects.
9+
3. `npm run test:unit` runs the unit test project only.
10+
4. `npm run test:wire` runs the wire test project with MSW based mocks.
11+
12+
## Coding Style and Naming Conventions
13+
Use TypeScript with strict typing, avoid `any` unless there is no alternative. Indentation is two spaces, and semicolons are used. Use `camelCase` for variables and methods, `PascalCase` for classes and exported types. Follow existing filename patterns, `PascalCase` for class files and lowercase for small utilities. Keep public client options and request payloads in `camelCase`.
14+
15+
## Testing Guidelines
16+
Tests use Jest with project separation for unit and wire suites. Test files follow the `*.test.ts` pattern, for example `tests/unit/client/Client.test.ts`. Prefer adding unit coverage for helper logic and wire tests for client request and response behavior. Run the smallest relevant suite while iterating, then run `npm test` before submitting changes.
17+
18+
## Commit and Pull Request Guidelines
19+
Recent history shows short, descriptive subjects without strict prefixes, so keep commit messages concise and clear about the change. For pull requests, include a summary, the test commands you ran, and any API surface changes. If you add or change a public method, update `README.md` usage examples.
20+
21+
## SDK Documentation Sync
22+
Whenever you change the SDK, update the website API documentation in `app/components/docs/` to match the new behavior. Before finishing any SDK update, use a sub agent to review and apply the documentation updates in `app/components/docs/`, and do not exit until that review is complete.
23+
Before finishing any SDK update, use a sub agent to review `README.md`, apply any updates needed to match the code, and do not exit until that review is complete.
24+
25+
## Configuration Tips
26+
Set `DIFFIO_API_KEY` for authentication and `DIFFIO_API_BASE_URL` to target emulators or alternate environments. Use Node 18 or later so the built in `fetch` API is available.

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
MIT License
22

3-
Copyright (c) 2026 Diffio AI
3+
Copyright (c) 2026 Diffio
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
77
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
to use, copy, modify, merge, publish, distribute, sublicense, and or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

README.md

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Diffio JS SDK
2+
3+
The Diffio JS SDK helps you call the Diffio API from Node. This version covers project creation, upload, generation, progress checks, and download URLs.
4+
5+
## Install
6+
7+
```bash
8+
npm install diffio-js
9+
```
10+
11+
For local development:
12+
13+
```bash
14+
cd diffio-js
15+
npm install
16+
```
17+
18+
## Configuration
19+
20+
Set the API key with `DIFFIO_API_KEY`. You can also override the base URL with `DIFFIO_API_BASE_URL`.
21+
22+
```bash
23+
export DIFFIO_API_KEY="diffio_live_..."
24+
export DIFFIO_API_BASE_URL="https://us-central1-diffioai.cloudfunctions.net"
25+
```
26+
27+
For emulators, set the base URL to the Functions emulator host.
28+
29+
```bash
30+
export DIFFIO_API_BASE_URL="http://127.0.0.1:5001/diffioai/us-central1"
31+
```
32+
33+
## Request options
34+
35+
Use request options to override headers, timeouts, retries, or the API key per request.
36+
37+
```ts
38+
import { DiffioClient } from "diffio-js";
39+
40+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
41+
const projects = await client.listProjects({
42+
requestOptions: {
43+
headers: { "X-Debug": "1" },
44+
timeoutInSeconds: 30,
45+
maxRetries: 2,
46+
retryBackoff: 0.5
47+
}
48+
});
49+
```
50+
51+
## Create a project and generation
52+
53+
`createProject` uploads the file and returns the project metadata.
54+
55+
```ts
56+
import { DiffioClient } from "diffio-js";
57+
58+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
59+
const filePath = "sample.wav";
60+
61+
const project = await client.createProject({
62+
filePath
63+
});
64+
65+
const generation = await client.createGeneration({
66+
apiProjectId: project.apiProjectId,
67+
model: "diffio-2",
68+
sampling: { steps: 12, guidance: 1.5 }
69+
});
70+
71+
console.log(generation.generationId);
72+
```
73+
74+
## Audio isolation helper
75+
76+
```ts
77+
import { DiffioClient } from "diffio-js";
78+
79+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
80+
const result = await client.audioIsolation.isolate({
81+
filePath: "sample.wav",
82+
model: "diffio-2",
83+
sampling: { steps: 12, guidance: 1.5 }
84+
});
85+
86+
console.log(result.generation.generationId);
87+
```
88+
89+
## Restore audio in one call
90+
91+
This helper runs the full flow and returns the downloaded bytes plus a metadata object.
92+
93+
```ts
94+
import fs from "node:fs";
95+
import { DiffioClient } from "diffio-js";
96+
97+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
98+
const [audioBytes, info] = await client.restoreAudio({
99+
filePath: "sample.wav",
100+
model: "diffio-2",
101+
sampling: { steps: 12, guidance: 1.5 },
102+
onProgress: (progress) => console.log(progress.status)
103+
});
104+
105+
if (info.error) {
106+
console.log(info.error);
107+
} else if (audioBytes) {
108+
fs.writeFileSync("restored.mp3", Buffer.from(audioBytes));
109+
}
110+
111+
console.log(info.apiProjectId, info.generationId);
112+
```
113+
114+
## Generation progress
115+
116+
```ts
117+
import { DiffioClient } from "diffio-js";
118+
119+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
120+
const progress = await client.generations.getProgress({
121+
generationId: "gen_123",
122+
apiProjectId: "proj_123"
123+
});
124+
125+
console.log(progress.status);
126+
```
127+
128+
## Generation download
129+
130+
```ts
131+
import { DiffioClient } from "diffio-js";
132+
133+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
134+
const download = await client.generations.getDownload({
135+
generationId: "gen_123",
136+
apiProjectId: "proj_123",
137+
downloadType: "audio"
138+
});
139+
140+
console.log(download.downloadUrl);
141+
```
142+
143+
## List projects
144+
145+
```ts
146+
import { DiffioClient } from "diffio-js";
147+
148+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
149+
const projects = await client.projects.list();
150+
151+
for (const project of projects.projects) {
152+
console.log(project.apiProjectId, project.status);
153+
}
154+
```
155+
156+
## List project generations
157+
158+
```ts
159+
import { DiffioClient } from "diffio-js";
160+
161+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
162+
const generations = await client.projects.listGenerations({ apiProjectId: "proj_123" });
163+
164+
for (const generation of generations.generations) {
165+
console.log(generation.generationId, generation.status);
166+
}
167+
```
168+
169+
## Webhooks portal access
170+
171+
```ts
172+
import { DiffioClient } from "diffio-js";
173+
174+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
175+
const portal = await client.webhooks.getPortalAccess({ mode: "test" });
176+
console.log(portal.portalUrl);
177+
```
178+
179+
## Send a test webhook event
180+
181+
```ts
182+
import { DiffioClient } from "diffio-js";
183+
184+
const client = new DiffioClient({ apiKey: "diffio_live_..." });
185+
const event = await client.webhooks.sendTestEvent({
186+
eventType: "generation.completed",
187+
mode: "test",
188+
samplePayload: { apiProjectId: "proj_123" }
189+
});
190+
191+
console.log(event.svixMessageId);
192+
```
193+
194+
## Runtime compatibility
195+
196+
Use Node 18 or later so `fetch` is available without extra packages.
197+
Examples use ES modules. Save files with a `.mjs` extension or set `"type": "module"` in your package.json.
198+
199+
## Tests
200+
201+
```bash
202+
cd diffio-js
203+
npm run build
204+
```

jest.config.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/** @type {import("jest").Config} */
2+
export default {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
projects: [
6+
{
7+
displayName: "unit",
8+
preset: "ts-jest",
9+
testEnvironment: "node",
10+
moduleNameMapper: {
11+
"^(\\.{1,2}/.*)\\.js$": "$1"
12+
},
13+
transform: {
14+
"^.+\\.(ts|tsx|js|jsx)$": ["ts-jest", { tsconfig: { allowJs: true } }]
15+
},
16+
transformIgnorePatterns: ["/node_modules/(?!(msw|@mswjs|until-async)/)"],
17+
roots: ["<rootDir>/tests/unit"],
18+
setupFilesAfterEnv: ["<rootDir>/tests/setup.ts"]
19+
},
20+
{
21+
displayName: "wire",
22+
preset: "ts-jest",
23+
testEnvironment: "node",
24+
moduleNameMapper: {
25+
"^(\\.{1,2}/.*)\\.js$": "$1"
26+
},
27+
transform: {
28+
"^.+\\.(ts|tsx|js|jsx)$": ["ts-jest", { tsconfig: { allowJs: true } }]
29+
},
30+
transformIgnorePatterns: ["/node_modules/(?!(msw|@mswjs|until-async)/)"],
31+
roots: ["<rootDir>/tests/wire"],
32+
setupFilesAfterEnv: ["<rootDir>/tests/setup.ts", "<rootDir>/tests/mock-server/setup.ts"]
33+
}
34+
],
35+
workerThreads: false,
36+
passWithNoTests: true
37+
};

0 commit comments

Comments
 (0)