Skip to content

Commit d369090

Browse files
committed
feat(api): regenerate for LMNT API 1.1
Baseline regeneration for the 1.1 spec; further refinements will follow as smaller deltas on top.
1 parent 4b97641 commit d369090

15 files changed

Lines changed: 609 additions & 388 deletions

_carbonsteel.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"version": "1.0.0",
3-
"generated_at": "2026-04-27T23:27:14Z",
4-
"spec_sha": "04a10d47ed2270bd:510635fad1875bc4",
2+
"version": "1.1",
3+
"generated_at": "2026-05-07T23:13:22Z",
4+
"spec_sha": "dd2556942628d8b4:63d381c5e2045349",
55
"files": [
66
"api.md",
77
"src/_shims/MultipartBody.ts",
@@ -32,6 +32,7 @@
3232
"src/_shims/web-types.d.ts",
3333
"src/_shims/web-types.js",
3434
"src/_shims/web-types.mjs",
35+
"src/_websocketRuntime.ts",
3536
"src/core.ts",
3637
"src/error.ts",
3738
"src/index.ts",
@@ -45,6 +46,7 @@
4546
"src/uploads.ts",
4647
"src/version.ts",
4748
"tests/api-resources/accounts.test.ts",
49+
"tests/api-resources/sessions.test.ts",
4850
"tests/api-resources/speech.test.ts",
4951
"tests/api-resources/voices.test.ts",
5052
"tests/form.test.ts",

src/_websocketRuntime.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Vendored by carbonsteel. DO NOT EDIT here in the SDK; edit
2+
// tool/carbonsteel/src/lmnt/tool/carbonsteel/codegen/node/vendor/src/_websocketRuntime.ts
3+
// in the monorepo and re-run carbonsteel.
4+
//
5+
// Spec-agnostic WebSocket session helpers shared by the generated SpeechSession.
6+
// MessageQueue: simple async resolver/buffer pair so the generated session can
7+
// expose an `AsyncIterator` while the underlying WebSocket pushes via callbacks.
8+
// processAudioData: normalises Blob/Buffer payloads to a uniform binary type.
9+
10+
import { Buffer } from 'buffer';
11+
import { LmntError } from './error';
12+
13+
export const WEBSOCKET_OPEN_STATE = 1;
14+
export const WEBSOCKET_NORMAL_CLOSE = 1000;
15+
16+
export class MessageQueue {
17+
private messages: any[] = [];
18+
private resolvers: ((value: any) => void)[] = [];
19+
private done = false;
20+
21+
finish() {
22+
this.done = true;
23+
while (this.resolvers.length) {
24+
const resolve = this.resolvers.shift();
25+
resolve?.(null);
26+
}
27+
}
28+
29+
push(message: any) {
30+
if (this.done) return;
31+
if (this.resolvers.length) {
32+
const resolve = this.resolvers.shift();
33+
resolve?.(message);
34+
} else {
35+
this.messages.push(message);
36+
}
37+
}
38+
39+
async next() {
40+
if (this.messages.length) {
41+
return this.messages.shift();
42+
}
43+
if (this.done) {
44+
return null;
45+
}
46+
return new Promise((resolve) => this.resolvers.push(resolve));
47+
}
48+
}
49+
50+
export async function processAudioData(audioData: Blob | Buffer): Promise<ArrayBuffer | Buffer> {
51+
if (audioData instanceof Blob) {
52+
return await audioData.arrayBuffer();
53+
} else if (audioData instanceof Buffer) {
54+
return audioData;
55+
} else {
56+
throw new LmntError(`Unexpected message type received from server: ${audioData}`);
57+
}
58+
}

src/core.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
7474

7575
debug('response', response.status, response.url, response.headers, json);
7676

77-
return json as T;
77+
return addRequestID(json as T, response);
7878
}
7979

8080
const text = await response.text();
@@ -84,6 +84,27 @@ async function defaultParseResponse<T>(props: APIResponseProps): Promise<T> {
8484
return text as unknown as T;
8585
}
8686

87+
/**
88+
* Attaches `_request_id` (read from the `request-id` response header) as a non-enumerable
89+
* property on object responses. Skipped for arrays and non-objects (callers can read the
90+
* `request-id` header from the underlying `Response` directly via `.withResponse()`).
91+
*/
92+
export function addRequestID<T>(value: T, response: Response): T {
93+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
94+
return value;
95+
}
96+
return Object.defineProperty(value, '_request_id', {
97+
value: response.headers.get('request-id'),
98+
enumerable: false,
99+
}) as T;
100+
}
101+
102+
/** Optional `_request_id` field added to plain-object responses by `addRequestID`. */
103+
export type WithRequestID<T> =
104+
T extends Array<any> | Response ? T
105+
: T extends Record<string, any> ? T & { _request_id?: string | null }
106+
: T;
107+
87108
/**
88109
* A subclass of `Promise` providing additional helper methods
89110
* for interacting with the SDK.

src/error.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@ export class APIError<
1616
/** JSON body of the response that caused the error */
1717
readonly error: TError;
1818

19-
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
19+
/** The unique identifier of the request that caused this error, matching the `request-id` response header. */
20+
readonly requestID: string | null | undefined;
21+
22+
/** The `error.type` from the API response body, e.g. `"rate_limit_error"`. */
23+
readonly type: string | null;
24+
25+
constructor(
26+
status: TStatus,
27+
error: TError,
28+
message: string | undefined,
29+
headers: THeaders,
30+
type?: string | null,
31+
) {
2032
super(`${APIError.makeMessage(status, error, message)}`);
2133
this.status = status;
2234
this.headers = headers;
35+
this.requestID = headers?.['request-id'] ?? undefined;
2336
this.error = error;
37+
this.type = type ?? null;
2438
}
2539

2640
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
@@ -55,40 +69,41 @@ export class APIError<
5569
}
5670

5771
const error = errorResponse as Record<string, any>;
72+
const type = (error?.['error']?.['type'] as string | undefined) ?? null;
5873

5974
if (status === 400) {
60-
return new BadRequestError(status, error, message, headers);
75+
return new BadRequestError(status, error, message, headers, type);
6176
}
6277

6378
if (status === 401) {
64-
return new AuthenticationError(status, error, message, headers);
79+
return new AuthenticationError(status, error, message, headers, type);
6580
}
6681

6782
if (status === 403) {
68-
return new PermissionDeniedError(status, error, message, headers);
83+
return new PermissionDeniedError(status, error, message, headers, type);
6984
}
7085

7186
if (status === 404) {
72-
return new NotFoundError(status, error, message, headers);
87+
return new NotFoundError(status, error, message, headers, type);
7388
}
7489

7590
if (status === 409) {
76-
return new ConflictError(status, error, message, headers);
91+
return new ConflictError(status, error, message, headers, type);
7792
}
7893

7994
if (status === 422) {
80-
return new UnprocessableEntityError(status, error, message, headers);
95+
return new UnprocessableEntityError(status, error, message, headers, type);
8196
}
8297

8398
if (status === 429) {
84-
return new RateLimitError(status, error, message, headers);
99+
return new RateLimitError(status, error, message, headers, type);
85100
}
86101

87102
if (status >= 500) {
88-
return new InternalServerError(status, error, message, headers);
103+
return new InternalServerError(status, error, message, headers, type);
89104
}
90105

91-
return new APIError(status, error, message, headers);
106+
return new APIError(status, error, message, headers, type);
92107
}
93108
}
94109

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type Agent } from './_shims/index';
44
import * as Core from './core';
55
import * as Errors from './error';
66
import * as Uploads from './uploads';
7+
import { LMNT_API_VERSION } from './version';
78
import * as API from './resources/index';
89
import {
910
Speech,
@@ -158,6 +159,7 @@ export class Lmnt extends Core.APIClient {
158159
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
159160
return {
160161
...super.defaultHeaders(opts),
162+
'lmnt-version': LMNT_API_VERSION,
161163
...this._options.defaultHeaders,
162164
};
163165
}

src/lib/.keep

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)