Skip to content

Commit 79b3510

Browse files
authored
feat: v0.1.2 api update (#16)
* Sync updates from stainless branch: main * 0.1.2 * 0.1.2
1 parent b89ca2e commit 79b3510

File tree

18 files changed

+103
-65
lines changed

18 files changed

+103
-65
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default tseslint.config(
1010
parserOptions: { sourceType: 'module' },
1111
},
1212
files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.js', '**/*.mjs', '**/*.cjs'],
13-
ignores: ['dist/**'],
13+
ignores: ['dist/'],
1414
plugins: {
1515
'@typescript-eslint': tseslint.plugin,
1616
'unused-imports': unusedImports,

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const config: JestConfigWithTsJest = {
1515
'<rootDir>/dist/',
1616
'<rootDir>/deno/',
1717
'<rootDir>/deno_tests/',
18+
'<rootDir>/packages/',
1819
],
1920
testPathIgnorePatterns: ['scripts'],
2021
};

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "llama-api-client",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "The official TypeScript library for the Llama API Client API",
55
"author": "Llama API Client <[email protected]>",
66
"types": "dist/index.d.ts",
@@ -34,21 +34,18 @@
3434
"@typescript-eslint/eslint-plugin": "8.31.1",
3535
"@typescript-eslint/parser": "8.31.1",
3636
"eslint": "^9.20.1",
37-
"eslint-plugin-prettier": "^5.2.3",
37+
"eslint-plugin-prettier": "^5.4.1",
3838
"eslint-plugin-unused-imports": "^4.1.4",
3939
"iconv-lite": "^0.6.3",
4040
"jest": "^29.4.0",
4141
"prettier": "^3.0.0",
4242
"publint": "^0.2.12",
4343
"ts-jest": "^29.1.0",
4444
"ts-node": "^10.5.0",
45-
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.4/tsc-multi-1.1.4.tgz",
45+
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.8/tsc-multi.tgz",
4646
"tsconfig-paths": "^4.0.0",
4747
"typescript": "5.8.3"
4848
},
49-
"resolutions": {
50-
"synckit": "0.8.8"
51-
},
5249
"imports": {
5350
"llama-api-client": ".",
5451
"llama-api-client/*": "./src/*"

scripts/build

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ fi
3131
node scripts/utils/make-dist-package-json.cjs > dist/package.json
3232

3333
# build to .js/.mjs/.d.ts files
34-
npm exec tsc-multi
34+
./node_modules/.bin/tsc-multi
3535
# we need to patch index.js so that `new module.exports()` works for cjs backwards
3636
# compat. No way to get that from index.ts because it would cause compile errors
3737
# when building .mjs
3838
node scripts/utils/fix-index-exports.cjs
3939
cp tsconfig.dist-src.json dist/src/tsconfig.json
40-
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.ts
41-
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.mts
4240

4341
node scripts/utils/postprocess-files.cjs
4442

src/client.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestIni
55
import { uuid4 } from './internal/utils/uuid';
66
import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
77
import { sleep } from './internal/utils/sleep';
8-
import { type Logger, type LogLevel, parseLogLevel } from './internal/utils/log';
98
export type { Logger, LogLevel } from './internal/utils/log';
109
import { castToError, isAbortError } from './internal/errors';
1110
import type { APIResponseProps } from './internal/parse';
@@ -17,14 +16,8 @@ import * as Errors from './core/error';
1716
import * as Uploads from './core/uploads';
1817
import * as API from './resources/index';
1918
import { APIPromise } from './core/api-promise';
20-
import { type Fetch } from './internal/builtin-types';
21-
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
22-
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
2319
import { LlamaModel, ModelListResponse, Models } from './resources/models';
2420
import { ModerationCreateParams, ModerationCreateResponse, Moderations } from './resources/moderations';
25-
import { readEnv } from './internal/utils/env';
26-
import { formatRequestDetails, loggerFor } from './internal/utils/log';
27-
import { isEmptyObj } from './internal/utils/values';
2821
import {
2922
Chat,
3023
CompletionMessage,
@@ -38,6 +31,18 @@ import {
3831
ToolResponseMessage,
3932
UserMessage,
4033
} from './resources/chat/chat';
34+
import { type Fetch } from './internal/builtin-types';
35+
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
36+
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
37+
import { readEnv } from './internal/utils/env';
38+
import {
39+
type LogLevel,
40+
type Logger,
41+
formatRequestDetails,
42+
loggerFor,
43+
parseLogLevel,
44+
} from './internal/utils/log';
45+
import { isEmptyObj } from './internal/utils/values';
4146

4247
export interface ClientOptions {
4348
/**
@@ -190,12 +195,20 @@ export class LlamaAPIClient {
190195
timeout: this.timeout,
191196
logger: this.logger,
192197
logLevel: this.logLevel,
198+
fetch: this.fetch,
193199
fetchOptions: this.fetchOptions,
194200
apiKey: this.apiKey,
195201
...options,
196202
});
197203
}
198204

205+
/**
206+
* Check whether the base URL is set to its default.
207+
*/
208+
#baseURLOverridden(): boolean {
209+
return this.baseURL !== 'https://api.llama.com/v1';
210+
}
211+
199212
protected defaultQuery(): Record<string, string | undefined> | undefined {
200213
return this._options.defaultQuery;
201214
}
@@ -245,11 +258,16 @@ export class LlamaAPIClient {
245258
return Errors.APIError.generate(status, error, message, headers);
246259
}
247260

248-
buildURL(path: string, query: Record<string, unknown> | null | undefined): string {
261+
buildURL(
262+
path: string,
263+
query: Record<string, unknown> | null | undefined,
264+
defaultBaseURL?: string | undefined,
265+
): string {
266+
const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
249267
const url =
250268
isAbsoluteURL(path) ?
251269
new URL(path)
252-
: new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
270+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
253271

254272
const defaultQuery = this.defaultQuery();
255273
if (!isEmptyObj(defaultQuery)) {
@@ -590,9 +608,9 @@ export class LlamaAPIClient {
590608
{ retryCount = 0 }: { retryCount?: number } = {},
591609
): { req: FinalizedRequestInit; url: string; timeout: number } {
592610
const options = { ...inputOptions };
593-
const { method, path, query } = options;
611+
const { method, path, query, defaultBaseURL } = options;
594612

595-
const url = this.buildURL(path!, query as Record<string, unknown>);
613+
const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
596614
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
597615
options.timeout = options.timeout ?? this.timeout;
598616
const { bodyHeaders, body } = this.buildBody({ options });

src/core/resource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import type { LlamaAPIClient } from '../client';
44

5-
export class APIResource {
5+
export abstract class APIResource {
66
protected _client: LlamaAPIClient;
77

88
constructor(client: LlamaAPIClient) {

src/internal/detect-platform.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ const getPlatformProperties = (): PlatformProperties => {
8585
return {
8686
'X-Stainless-Lang': 'js',
8787
'X-Stainless-Package-Version': VERSION,
88-
'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform),
89-
'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch),
88+
'X-Stainless-OS': normalizePlatform((globalThis as any).process.platform ?? 'unknown'),
89+
'X-Stainless-Arch': normalizeArch((globalThis as any).process.arch ?? 'unknown'),
9090
'X-Stainless-Runtime': 'node',
91-
'X-Stainless-Runtime-Version': (globalThis as any).process.version,
91+
'X-Stainless-Runtime-Version': (globalThis as any).process.version ?? 'unknown',
9292
};
9393
}
9494

src/internal/headers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
import { isReadonlyArray } from './utils/values';
4+
35
type HeaderValue = string | undefined | null;
46
export type HeadersLike =
57
| Headers
@@ -9,7 +11,7 @@ export type HeadersLike =
911
| null
1012
| NullableHeaders;
1113

12-
const brand_privateNullableHeaders = Symbol('brand.privateNullableHeaders');
14+
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
1315

1416
/**
1517
* @internal
@@ -25,8 +27,6 @@ export type NullableHeaders = {
2527
nulls: Set<string>;
2628
};
2729

28-
const isArray = Array.isArray as (val: unknown) => val is readonly unknown[];
29-
3030
function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [string, string | null]> {
3131
if (!headers) return;
3232

@@ -43,7 +43,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
4343
let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;
4444
if (headers instanceof Headers) {
4545
iter = headers.entries();
46-
} else if (isArray(headers)) {
46+
} else if (isReadonlyArray(headers)) {
4747
iter = headers;
4848
} else {
4949
shouldClear = true;
@@ -52,7 +52,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
5252
for (let row of iter) {
5353
const name = row[0];
5454
if (typeof name !== 'string') throw new TypeError('expected header name to be a string');
55-
const values = isArray(row[1]) ? row[1] : [row[1]];
55+
const values = isReadonlyArray(row[1]) ? row[1] : [row[1]];
5656
let didClear = false;
5757
for (const value of values) {
5858
if (value === undefined) continue;

src/internal/request-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type RequestOptions = {
2121
fetchOptions?: MergedRequestInit;
2222
signal?: AbortSignal | undefined | null;
2323
idempotencyKey?: string;
24+
defaultBaseURL?: string | undefined;
2425

2526
__binaryResponse?: boolean | undefined;
2627
__streamClass?: typeof Stream;

src/internal/shim-types.d.ts

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

0 commit comments

Comments
 (0)