Skip to content

Commit 40e5ff3

Browse files
authored
Merge pull request #7 from onkernel/release-please--branches--main--changes--next--components--sdk
release: 0.1.0-alpha.6
2 parents b885fff + ce8f23c commit 40e5ff3

File tree

8 files changed

+57
-10
lines changed

8 files changed

+57
-10
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.1.0-alpha.5"
2+
".": "0.1.0-alpha.6"
33
}

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 4
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-d168b58fcf39dbd0458d132091793d3e2d0930070b7dda2d5f7f1baff20dd31b.yml
33
openapi_spec_hash: b7e0fd7ee1656d7dbad57209d1584d92
4-
config_hash: c2bc5253d8afd6d67e031f73353c9b22
4+
config_hash: 2d282609080a6011e3f6222451f72237

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.1.0-alpha.6 (2025-05-10)
4+
5+
Full Changelog: [v0.1.0-alpha.5...v0.1.0-alpha.6](https://github.com/onkernel/kernel-node-sdk/compare/v0.1.0-alpha.5...v0.1.0-alpha.6)
6+
7+
### Features
8+
9+
* **api:** update via SDK Studio ([4f6bb37](https://github.com/onkernel/kernel-node-sdk/commit/4f6bb3761722ad4ff471a5b60837cba6b4533c8e))
10+
311
## 0.1.0-alpha.5 (2025-05-10)
412

513
Full Changelog: [v0.1.0-alpha.4...v0.1.0-alpha.5](https://github.com/onkernel/kernel-node-sdk/compare/v0.1.0-alpha.4...v0.1.0-alpha.5)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Kernel from '@onkernel/sdk';
2424

2525
const client = new Kernel({
2626
apiKey: process.env['KERNEL_API_KEY'], // This is the default and can be omitted
27+
environment: 'development', // defaults to 'production'
2728
});
2829

2930
async function main() {
@@ -49,6 +50,7 @@ import Kernel from '@onkernel/sdk';
4950

5051
const client = new Kernel({
5152
apiKey: process.env['KERNEL_API_KEY'], // This is the default and can be omitted
53+
environment: 'development', // defaults to 'production'
5254
});
5355

5456
async function main() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onkernel/sdk",
3-
"version": "0.1.0-alpha.5",
3+
"version": "0.1.0-alpha.6",
44
"description": "The official TypeScript library for the Kernel API",
55
"author": "Kernel <>",
66
"types": "dist/index.d.ts",

src/client.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,27 @@ import { formatRequestDetails, loggerFor } from './internal/utils/log';
3434
import { isEmptyObj } from './internal/utils/values';
3535
import { KernelApp, appRegistry } from './core/app-framework';
3636

37+
const environments = {
38+
production: 'https://api.onkernel.com/',
39+
development: 'https://localhost:3001/',
40+
};
41+
type Environment = keyof typeof environments;
42+
3743
export interface ClientOptions {
3844
/**
3945
* Defaults to process.env['KERNEL_API_KEY'].
4046
*/
4147
apiKey?: string | undefined;
4248

49+
/**
50+
* Specifies the environment to use for the API.
51+
*
52+
* Each environment maps to a different base URL:
53+
* - `production` corresponds to `https://api.onkernel.com/`
54+
* - `development` corresponds to `https://localhost:3001/`
55+
*/
56+
environment?: Environment | undefined;
57+
4358
/**
4459
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
4560
*
@@ -129,7 +144,8 @@ export class Kernel {
129144
* API Client for interfacing with the Kernel API.
130145
*
131146
* @param {string | undefined} [opts.apiKey=process.env['KERNEL_API_KEY'] ?? undefined]
132-
* @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? http://localhost:3001] - Override the default base URL for the API.
147+
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
148+
* @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? https://api.onkernel.com/] - Override the default base URL for the API.
133149
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
134150
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
135151
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
@@ -151,10 +167,17 @@ export class Kernel {
151167
const options: ClientOptions = {
152168
apiKey,
153169
...opts,
154-
baseURL: baseURL || `http://localhost:3001`,
170+
baseURL,
171+
environment: opts.environment ?? 'production',
155172
};
156173

157-
this.baseURL = options.baseURL!;
174+
if (baseURL && opts.environment) {
175+
throw new Errors.KernelError(
176+
'Ambiguous URL; The `baseURL` option (or KERNEL_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
177+
);
178+
}
179+
180+
this.baseURL = options.baseURL || environments[options.environment || 'production'];
158181
this.timeout = options.timeout ?? Kernel.DEFAULT_TIMEOUT /* 1 minute */;
159182
this.logger = options.logger ?? console;
160183
const defaultLogLevel = 'warn';
@@ -180,7 +203,8 @@ export class Kernel {
180203
withOptions(options: Partial<ClientOptions>): this {
181204
return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
182205
...this._options,
183-
baseURL: this.baseURL,
206+
environment: options.environment ? options.environment : undefined,
207+
baseURL: options.environment ? undefined : this.baseURL,
184208
maxRetries: this.maxRetries,
185209
timeout: this.timeout,
186210
logger: this.logger,

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = '0.1.0-alpha.5'; // x-release-please-version
1+
export const VERSION = '0.1.0-alpha.6'; // x-release-please-version

tests/index.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,26 @@ describe('instantiate client', () => {
302302
test('empty env variable', () => {
303303
process.env['KERNEL_BASE_URL'] = ''; // empty
304304
const client = new Kernel({ apiKey: 'My API Key' });
305-
expect(client.baseURL).toEqual('http://localhost:3001');
305+
expect(client.baseURL).toEqual('https://api.onkernel.com/');
306306
});
307307

308308
test('blank env variable', () => {
309309
process.env['KERNEL_BASE_URL'] = ' '; // blank
310310
const client = new Kernel({ apiKey: 'My API Key' });
311-
expect(client.baseURL).toEqual('http://localhost:3001');
311+
expect(client.baseURL).toEqual('https://api.onkernel.com/');
312+
});
313+
314+
test('env variable with environment', () => {
315+
process.env['KERNEL_BASE_URL'] = 'https://example.com/from_env';
316+
317+
expect(
318+
() => new Kernel({ apiKey: 'My API Key', environment: 'production' }),
319+
).toThrowErrorMatchingInlineSnapshot(
320+
`"Ambiguous URL; The \`baseURL\` option (or KERNEL_BASE_URL env var) and the \`environment\` option are given. If you want to use the environment you must pass baseURL: null"`,
321+
);
322+
323+
const client = new Kernel({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
324+
expect(client.baseURL).toEqual('https://api.onkernel.com/');
312325
});
313326
});
314327

0 commit comments

Comments
 (0)