Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.5"
".": "0.1.0-alpha.6"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 4
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-d168b58fcf39dbd0458d132091793d3e2d0930070b7dda2d5f7f1baff20dd31b.yml
openapi_spec_hash: b7e0fd7ee1656d7dbad57209d1584d92
config_hash: c2bc5253d8afd6d67e031f73353c9b22
config_hash: 2d282609080a6011e3f6222451f72237
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.6 (2025-05-10)

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)

### Features

* **api:** update via SDK Studio ([4f6bb37](https://github.com/onkernel/kernel-node-sdk/commit/4f6bb3761722ad4ff471a5b60837cba6b4533c8e))

## 0.1.0-alpha.5 (2025-05-10)

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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Kernel from '@onkernel/sdk';

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

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

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

async function main() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onkernel/sdk",
"version": "0.1.0-alpha.5",
"version": "0.1.0-alpha.6",
"description": "The official TypeScript library for the Kernel API",
"author": "Kernel <>",
"types": "dist/index.d.ts",
Expand Down
32 changes: 28 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@ import { formatRequestDetails, loggerFor } from './internal/utils/log';
import { isEmptyObj } from './internal/utils/values';
import { KernelApp, appRegistry } from './core/app-framework';

const environments = {
production: 'https://api.onkernel.com/',
development: 'https://localhost:3001/',
};
type Environment = keyof typeof environments;

export interface ClientOptions {
/**
* Defaults to process.env['KERNEL_API_KEY'].
*/
apiKey?: string | undefined;

/**
* Specifies the environment to use for the API.
*
* Each environment maps to a different base URL:
* - `production` corresponds to `https://api.onkernel.com/`
* - `development` corresponds to `https://localhost:3001/`
*/
environment?: Environment | undefined;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
*
Expand Down Expand Up @@ -129,7 +144,8 @@ export class Kernel {
* API Client for interfacing with the Kernel API.
*
* @param {string | undefined} [opts.apiKey=process.env['KERNEL_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? http://localhost:3001] - Override the default base URL for the API.
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
* @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? https://api.onkernel.com/] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
Expand All @@ -151,10 +167,17 @@ export class Kernel {
const options: ClientOptions = {
apiKey,
...opts,
baseURL: baseURL || `http://localhost:3001`,
baseURL,
environment: opts.environment ?? 'production',
};

this.baseURL = options.baseURL!;
if (baseURL && opts.environment) {
throw new Errors.KernelError(
'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',
);
}

this.baseURL = options.baseURL || environments[options.environment || 'production'];
this.timeout = options.timeout ?? Kernel.DEFAULT_TIMEOUT /* 1 minute */;
this.logger = options.logger ?? console;
const defaultLogLevel = 'warn';
Expand All @@ -180,7 +203,8 @@ export class Kernel {
withOptions(options: Partial<ClientOptions>): this {
return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
...this._options,
baseURL: this.baseURL,
environment: options.environment ? options.environment : undefined,
baseURL: options.environment ? undefined : this.baseURL,
maxRetries: this.maxRetries,
timeout: this.timeout,
logger: this.logger,
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.1.0-alpha.5'; // x-release-please-version
export const VERSION = '0.1.0-alpha.6'; // x-release-please-version
17 changes: 15 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,26 @@ describe('instantiate client', () => {
test('empty env variable', () => {
process.env['KERNEL_BASE_URL'] = ''; // empty
const client = new Kernel({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('http://localhost:3001');
expect(client.baseURL).toEqual('https://api.onkernel.com/');
});

test('blank env variable', () => {
process.env['KERNEL_BASE_URL'] = ' '; // blank
const client = new Kernel({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('http://localhost:3001');
expect(client.baseURL).toEqual('https://api.onkernel.com/');
});

test('env variable with environment', () => {
process.env['KERNEL_BASE_URL'] = 'https://example.com/from_env';

expect(
() => new Kernel({ apiKey: 'My API Key', environment: 'production' }),
).toThrowErrorMatchingInlineSnapshot(
`"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"`,
);

const client = new Kernel({ apiKey: 'My API Key', baseURL: null, environment: 'production' });
expect(client.baseURL).toEqual('https://api.onkernel.com/');
});
});

Expand Down