@aithos/sdk 0.1.0-alpha.42 → 0.1.0-alpha.44
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 +34 -0
- package/dist/src/compute.d.ts +218 -0
- package/dist/src/compute.js +457 -0
- package/dist/src/ethos.js +72 -20
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +2 -1
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/index.js +1 -0
- package/dist/src/react/use-transcribe-pending.d.ts +21 -0
- package/dist/src/react/use-transcribe-pending.js +47 -0
- package/dist/src/transcribe-resilience.d.ts +57 -0
- package/dist/src/transcribe-resilience.js +203 -0
- package/dist/test/ethos-first-edition.test.js +125 -2
- package/dist/test/transcribe-invoke.test.d.ts +2 -0
- package/dist/test/transcribe-invoke.test.js +204 -0
- package/dist/test/transcribe.test.d.ts +2 -0
- package/dist/test/transcribe.test.js +186 -0
- package/package.json +14 -12
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2026 Mathieu Colla
|
|
3
|
+
// Unit tests for the transcription low-level API (sdk.compute.{prepare,
|
|
4
|
+
// start,getStatus,listPending}Transcribe) with a mock fetch. A real
|
|
5
|
+
// BrowserIdentity signs the envelopes, so any signing/canonicalization
|
|
6
|
+
// regression surfaces here too.
|
|
7
|
+
import { strict as assert } from "node:assert";
|
|
8
|
+
import { describe, it } from "node:test";
|
|
9
|
+
import { createBrowserIdentity } from "@aithos/protocol-client";
|
|
10
|
+
import { AithosAuth, AithosSDK, memoryKeyStore, noopStore, } from "../src/index.js";
|
|
11
|
+
import { serializeRecoveryFile } from "../src/internal/recovery-file.js";
|
|
12
|
+
const APP_DID = "did:aithos:app:test";
|
|
13
|
+
async function makeSdk(fetchImpl) {
|
|
14
|
+
const id = createBrowserIdentity("test-handle", "Test User");
|
|
15
|
+
const auth = new AithosAuth({
|
|
16
|
+
authBaseUrl: "https://auth.test",
|
|
17
|
+
fetch: (() => {
|
|
18
|
+
throw new Error("auth not used in compute tests");
|
|
19
|
+
}),
|
|
20
|
+
sessionStore: noopStore(),
|
|
21
|
+
keyStore: memoryKeyStore(),
|
|
22
|
+
});
|
|
23
|
+
const { text } = serializeRecoveryFile(id);
|
|
24
|
+
await auth.signInWithRecovery({ file: text });
|
|
25
|
+
return new AithosSDK({
|
|
26
|
+
auth,
|
|
27
|
+
appDid: APP_DID,
|
|
28
|
+
endpoints: { compute: "https://compute.example.test" },
|
|
29
|
+
fetch: fetchImpl,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function jsonRpc(result) {
|
|
33
|
+
return new Response(JSON.stringify({ result }), {
|
|
34
|
+
status: 200,
|
|
35
|
+
headers: { "content-type": "application/json" },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function bodyParams(init) {
|
|
39
|
+
return JSON.parse(init?.body).params;
|
|
40
|
+
}
|
|
41
|
+
function bodyMethod(init) {
|
|
42
|
+
return JSON.parse(init?.body).method;
|
|
43
|
+
}
|
|
44
|
+
describe("compute.prepareTranscribe", () => {
|
|
45
|
+
it("posts transcribe_prepare with app_did + content_type and maps the result", async () => {
|
|
46
|
+
let method;
|
|
47
|
+
let params;
|
|
48
|
+
const sdk = await makeSdk(async (_url, init) => {
|
|
49
|
+
method = bodyMethod(init);
|
|
50
|
+
params = bodyParams(init);
|
|
51
|
+
return jsonRpc({
|
|
52
|
+
job_id: "tj_ABC",
|
|
53
|
+
upload_url: "https://s3.example/upload?sig=1",
|
|
54
|
+
s3_object_key: "uploads/2026/05/tj_ABC.webm",
|
|
55
|
+
expires_at: 1717000000,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
const out = await sdk.compute.prepareTranscribe({
|
|
59
|
+
contentType: "audio/webm",
|
|
60
|
+
durationSecEstimate: 120,
|
|
61
|
+
});
|
|
62
|
+
assert.equal(method, "aithos.compute_transcribe_prepare");
|
|
63
|
+
assert.equal(params?.app_did, APP_DID);
|
|
64
|
+
assert.equal(params?.content_type, "audio/webm");
|
|
65
|
+
assert.equal(params?.duration_sec_estimate, 120);
|
|
66
|
+
assert.ok(params._envelope, "must carry an envelope");
|
|
67
|
+
assert.deepEqual(out, {
|
|
68
|
+
jobId: "tj_ABC",
|
|
69
|
+
uploadUrl: "https://s3.example/upload?sig=1",
|
|
70
|
+
s3ObjectKey: "uploads/2026/05/tj_ABC.webm",
|
|
71
|
+
expiresAt: 1717000000,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe("compute.startTranscribe", () => {
|
|
76
|
+
it("posts transcribe_start with the wire params and maps the result", async () => {
|
|
77
|
+
let method;
|
|
78
|
+
let params;
|
|
79
|
+
const sdk = await makeSdk(async (_url, init) => {
|
|
80
|
+
method = bodyMethod(init);
|
|
81
|
+
params = bodyParams(init);
|
|
82
|
+
return jsonRpc({
|
|
83
|
+
job_id: "tj_ABC",
|
|
84
|
+
status: "running",
|
|
85
|
+
estimated_credits: 240,
|
|
86
|
+
walletBalance: 49_760,
|
|
87
|
+
fundedBy: "purchase",
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
const out = await sdk.compute.startTranscribe({
|
|
91
|
+
jobId: "tj_ABC",
|
|
92
|
+
model: "transcribe:aws-fr-standard",
|
|
93
|
+
durationSec: 120,
|
|
94
|
+
languageCode: "fr-FR",
|
|
95
|
+
diarization: false,
|
|
96
|
+
idempotencyKey: "ik_1",
|
|
97
|
+
});
|
|
98
|
+
assert.equal(method, "aithos.compute_transcribe_start");
|
|
99
|
+
assert.equal(params?.job_id, "tj_ABC");
|
|
100
|
+
assert.equal(params?.model, "transcribe:aws-fr-standard");
|
|
101
|
+
assert.equal(params?.duration_sec, 120);
|
|
102
|
+
assert.equal(params?.language_code, "fr-FR");
|
|
103
|
+
assert.equal(params?.diarization, false);
|
|
104
|
+
assert.equal(params?.idempotency_key, "ik_1");
|
|
105
|
+
assert.ok(typeof params?.mandate_id === "string" && params.mandate_id.length > 0);
|
|
106
|
+
assert.deepEqual(out, {
|
|
107
|
+
jobId: "tj_ABC",
|
|
108
|
+
status: "running",
|
|
109
|
+
estimatedCredits: 240,
|
|
110
|
+
walletBalance: 49_760,
|
|
111
|
+
fundedBy: "purchase",
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("compute.getTranscribeStatus", () => {
|
|
116
|
+
it("maps a running response", async () => {
|
|
117
|
+
const sdk = await makeSdk(async () => jsonRpc({ job_id: "tj_ABC", status: "running", elapsed_sec: 12 }));
|
|
118
|
+
const out = await sdk.compute.getTranscribeStatus({ jobId: "tj_ABC" });
|
|
119
|
+
assert.deepEqual(out, { jobId: "tj_ABC", status: "running", elapsedSec: 12 });
|
|
120
|
+
});
|
|
121
|
+
it("maps a completed response (duration_sec_actual -> durationSec)", async () => {
|
|
122
|
+
const sdk = await makeSdk(async () => jsonRpc({
|
|
123
|
+
job_id: "tj_ABC",
|
|
124
|
+
status: "completed",
|
|
125
|
+
text: "Bonjour le monde",
|
|
126
|
+
segments: [{ start_sec: 0, end_sec: 1.4, text: "Bonjour le monde" }],
|
|
127
|
+
words: [{ start_sec: 0, end_sec: 0.4, content: "Bonjour", confidence: 0.99 }],
|
|
128
|
+
duration_sec_actual: 127,
|
|
129
|
+
language_code: "fr-FR",
|
|
130
|
+
creditsCharged: 254,
|
|
131
|
+
walletBalance: 49_746,
|
|
132
|
+
auditId: "audit_1",
|
|
133
|
+
fundedBy: "purchase",
|
|
134
|
+
}));
|
|
135
|
+
const out = await sdk.compute.getTranscribeStatus({ jobId: "tj_ABC" });
|
|
136
|
+
assert.equal(out.status, "completed");
|
|
137
|
+
if (out.status !== "completed")
|
|
138
|
+
return;
|
|
139
|
+
assert.equal(out.text, "Bonjour le monde");
|
|
140
|
+
assert.equal(out.durationSec, 127);
|
|
141
|
+
assert.equal(out.languageCode, "fr-FR");
|
|
142
|
+
assert.equal(out.creditsCharged, 254);
|
|
143
|
+
assert.equal(out.auditId, "audit_1");
|
|
144
|
+
assert.equal(out.fundedBy, "purchase");
|
|
145
|
+
assert.equal(out.segments.length, 1);
|
|
146
|
+
assert.equal(out.words[0]?.content, "Bonjour");
|
|
147
|
+
});
|
|
148
|
+
it("maps a failed response", async () => {
|
|
149
|
+
const sdk = await makeSdk(async () => jsonRpc({
|
|
150
|
+
job_id: "tj_ABC",
|
|
151
|
+
status: "failed",
|
|
152
|
+
error: { code: "transcribe_provider_error", message: "boom" },
|
|
153
|
+
}));
|
|
154
|
+
const out = await sdk.compute.getTranscribeStatus({ jobId: "tj_ABC" });
|
|
155
|
+
assert.equal(out.status, "failed");
|
|
156
|
+
if (out.status !== "failed")
|
|
157
|
+
return;
|
|
158
|
+
assert.equal(out.error.code, "transcribe_provider_error");
|
|
159
|
+
assert.equal(out.error.message, "boom");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe("compute.listPendingTranscribes", () => {
|
|
163
|
+
it("forwards include_completed and maps job summaries", async () => {
|
|
164
|
+
let params;
|
|
165
|
+
const sdk = await makeSdk(async (_url, init) => {
|
|
166
|
+
params = bodyParams(init);
|
|
167
|
+
return jsonRpc({
|
|
168
|
+
jobs: [
|
|
169
|
+
{ job_id: "tj_1", status: "running", created_at: 1717000000, estimated_credits: 240 },
|
|
170
|
+
{ job_id: "tj_2", status: "completed", created_at: 1717000100, creditsCharged: 250 },
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
const out = await sdk.compute.listPendingTranscribes({ includeCompleted: true });
|
|
175
|
+
assert.equal(params?.include_completed, true);
|
|
176
|
+
assert.equal(out.jobs.length, 2);
|
|
177
|
+
assert.deepEqual(out.jobs[0], {
|
|
178
|
+
jobId: "tj_1",
|
|
179
|
+
status: "running",
|
|
180
|
+
createdAt: 1717000000,
|
|
181
|
+
estimatedCredits: 240,
|
|
182
|
+
});
|
|
183
|
+
assert.equal(out.jobs[1]?.creditsCharged, 250);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
//# sourceMappingURL=transcribe.test.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aithos/sdk",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.44",
|
|
4
4
|
"description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aithos",
|
|
@@ -43,12 +43,21 @@
|
|
|
43
43
|
"README.md",
|
|
44
44
|
"LICENSE"
|
|
45
45
|
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"build:test": "tsc -p tsconfig.test.json",
|
|
49
|
+
"check-types": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
50
|
+
"test": "npm run clean && npm run build && npm run build:test && cd dist && node --test",
|
|
51
|
+
"test:watch": "cd dist && node --test --watch",
|
|
52
|
+
"clean": "rm -rf dist",
|
|
53
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
54
|
+
},
|
|
46
55
|
"engines": {
|
|
47
56
|
"node": ">=20"
|
|
48
57
|
},
|
|
49
58
|
"peerDependencies": {
|
|
50
|
-
"@aithos/protocol-client": ">=0.1.0-alpha.13 <0.2.0",
|
|
51
59
|
"@aithos/assets-crypto": ">=0.1.0-alpha.1 <0.2.0",
|
|
60
|
+
"@aithos/protocol-client": "^0.1.0-alpha.14",
|
|
52
61
|
"react": "^18.0.0 || ^19.0.0"
|
|
53
62
|
},
|
|
54
63
|
"peerDependenciesMeta": {
|
|
@@ -60,7 +69,8 @@
|
|
|
60
69
|
}
|
|
61
70
|
},
|
|
62
71
|
"devDependencies": {
|
|
63
|
-
"@aithos/
|
|
72
|
+
"@aithos/assets-crypto": "^0.1.0-alpha.1",
|
|
73
|
+
"@aithos/protocol-client": "^0.1.0-alpha.14",
|
|
64
74
|
"@types/node": "^24.12.2",
|
|
65
75
|
"fake-indexeddb": "^6.2.5",
|
|
66
76
|
"typescript": "^5.9.2"
|
|
@@ -68,13 +78,5 @@
|
|
|
68
78
|
"publishConfig": {
|
|
69
79
|
"access": "public",
|
|
70
80
|
"tag": "alpha"
|
|
71
|
-
},
|
|
72
|
-
"scripts": {
|
|
73
|
-
"build": "tsc",
|
|
74
|
-
"build:test": "tsc -p tsconfig.test.json",
|
|
75
|
-
"check-types": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
|
|
76
|
-
"test": "npm run clean && npm run build && npm run build:test && cd dist && node --test",
|
|
77
|
-
"test:watch": "cd dist && node --test --watch",
|
|
78
|
-
"clean": "rm -rf dist"
|
|
79
81
|
}
|
|
80
|
-
}
|
|
82
|
+
}
|