Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ec7be8d
chore: avoid type error in certain environments
stainless-app[bot] Jun 7, 2025
16c70f4
fix: publish script — handle NPM errors correctly
stainless-app[bot] Jun 14, 2025
71cd518
chore(internal): add pure annotations, make base APIResource abstract
stainless-app[bot] Jun 14, 2025
bb6cff2
codegen metadata
stainless-app[bot] Jun 14, 2025
638c748
codegen metadata
stainless-app[bot] Jun 14, 2025
171423f
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
e4ad78d
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
ef99764
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
567602f
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
121219a
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
6e4f782
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
371e317
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
76a1ea8
feat(api): update via SDK Studio
stainless-app[bot] Jun 14, 2025
801fb38
chore(client): refactor imports
stainless-app[bot] Jun 17, 2025
7b4d7a2
feat(client): add support for endpoint-specific base URLs
stainless-app[bot] Jun 17, 2025
0dc0e13
chore(ci): enable for pull requests
stainless-app[bot] Jun 17, 2025
b0652c7
feat(api): update via SDK Studio
stainless-app[bot] Jun 17, 2025
842ec55
feat(api): update via SDK Studio
stainless-app[bot] Jun 17, 2025
c6890ba
feat(api): update via SDK Studio
stainless-app[bot] Jun 17, 2025
b4fbd8c
feat(api): update via SDK Studio
stainless-app[bot] Jun 17, 2025
ce675af
feat(api): update via SDK Studio
stainless-app[bot] Jun 17, 2025
48f24e9
chore(readme): update badges
stainless-app[bot] Jun 18, 2025
e931ee6
release: 0.6.0
stainless-app[bot] Jun 18, 2025
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
- 'integrated/**'
- 'stl-preview-head/**'
- 'stl-preview-base/**'
pull_request:
branches-ignore:
- 'stl-preview-head/**'
- 'stl-preview-base/**'

jobs:
lint:
Expand Down
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.5.0"
".": "0.6.0"
}
8 changes: 4 additions & 4 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 11
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-4502c65bef0843a6ae96d23bba075433af6bab49b55b544b1522f63e7881c00c.yml
openapi_spec_hash: 3e67b77bbc8cd6155b8f66f3271f2643
config_hash: c6bab7ac8da570a5abbcfb19db119b6b
configured_endpoints: 15
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-5d4e11bc46eeecee7363d56a9dfe946acee997d5b352c2b0a50c20e742c54d2d.yml
openapi_spec_hash: 333e53ad9c706296b9afdb8ff73bec8f
config_hash: 0fdf285ddd8dee229fd84ea57df9080f
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# Changelog

## 0.6.0 (2025-06-18)

Full Changelog: [v0.5.0...v0.6.0](https://github.com/onkernel/kernel-node-sdk/compare/v0.5.0...v0.6.0)

### Features

* **api:** update via SDK Studio ([ce675af](https://github.com/onkernel/kernel-node-sdk/commit/ce675afa43f72708fd26bd0ab9d37b43f2e4b645))
* **api:** update via SDK Studio ([b4fbd8c](https://github.com/onkernel/kernel-node-sdk/commit/b4fbd8cd5287894a1e31c3369e6268676b5cfb93))
* **api:** update via SDK Studio ([c6890ba](https://github.com/onkernel/kernel-node-sdk/commit/c6890ba4c2ccebc4be3388107de407ef833555d6))
* **api:** update via SDK Studio ([842ec55](https://github.com/onkernel/kernel-node-sdk/commit/842ec5503a95b8a7bd43405cb0af36411610d14a))
* **api:** update via SDK Studio ([b0652c7](https://github.com/onkernel/kernel-node-sdk/commit/b0652c76a0d9b8ff39c8d97d0087a305ed1bb0b7))
* **api:** update via SDK Studio ([76a1ea8](https://github.com/onkernel/kernel-node-sdk/commit/76a1ea8d2d978b7872ff122f6b4457f361695e22))
* **api:** update via SDK Studio ([371e317](https://github.com/onkernel/kernel-node-sdk/commit/371e3178a73439915a459dc0b7e968aeaf9f7e8f))
* **api:** update via SDK Studio ([6e4f782](https://github.com/onkernel/kernel-node-sdk/commit/6e4f782824e8ec1956d31ddaff7073a0015a3014))
* **api:** update via SDK Studio ([121219a](https://github.com/onkernel/kernel-node-sdk/commit/121219a8e7dab92398d7373afb84be06a9d15217))
* **api:** update via SDK Studio ([567602f](https://github.com/onkernel/kernel-node-sdk/commit/567602fb83e9135938abd7cd080f864fc787f288))
* **api:** update via SDK Studio ([ef99764](https://github.com/onkernel/kernel-node-sdk/commit/ef99764a42bc6243b028162eb1fcc88ae36eed41))
* **api:** update via SDK Studio ([e4ad78d](https://github.com/onkernel/kernel-node-sdk/commit/e4ad78d21af5a7d009f55cea09da358780ca8d2d))
* **api:** update via SDK Studio ([171423f](https://github.com/onkernel/kernel-node-sdk/commit/171423fb6af8fde206a1e32a1e8611f4b1d325be))
* **client:** add support for endpoint-specific base URLs ([7b4d7a2](https://github.com/onkernel/kernel-node-sdk/commit/7b4d7a2da7ba44fa0e0648545eccb5e175cf8255))


### Bug Fixes

* publish script — handle NPM errors correctly ([16c70f4](https://github.com/onkernel/kernel-node-sdk/commit/16c70f444b06763b186c7138e16476d03b9638fe))


### Chores

* avoid type error in certain environments ([ec7be8d](https://github.com/onkernel/kernel-node-sdk/commit/ec7be8d0c90029c4fb5911afee057dcd73f6caa1))
* **ci:** enable for pull requests ([0dc0e13](https://github.com/onkernel/kernel-node-sdk/commit/0dc0e130a319209e0debcb41df6a7e4e473a013b))
* **client:** refactor imports ([801fb38](https://github.com/onkernel/kernel-node-sdk/commit/801fb38b66af7598d9bbc12d6964031f44f7a6ea))
* **internal:** add pure annotations, make base APIResource abstract ([71cd518](https://github.com/onkernel/kernel-node-sdk/commit/71cd5185af173938e8bf933045de56dec7c04802))
* **readme:** update badges ([48f24e9](https://github.com/onkernel/kernel-node-sdk/commit/48f24e9591eeb869dfeb38b6f52f28d6edfcd10e))

## 0.5.0 (2025-06-04)

Full Changelog: [v0.4.0...v0.5.0](https://github.com/onkernel/kernel-node-sdk/compare/v0.4.0...v0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kernel TypeScript API Library

[![NPM version](https://img.shields.io/npm/v/@onkernel/sdk.svg)](https://npmjs.org/package/@onkernel/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@onkernel/sdk)
[![NPM version](<https://img.shields.io/npm/v/@onkernel/sdk.svg?label=npm%20(stable)>)](https://npmjs.org/package/@onkernel/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@onkernel/sdk)

This library provides convenient access to the Kernel REST API from server-side TypeScript or JavaScript.

Expand Down
41 changes: 34 additions & 7 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# Shared

Types:

- <code><a href="./src/resources/shared.ts">ErrorDetail</a></code>
- <code><a href="./src/resources/shared.ts">ErrorEvent</a></code>
- <code><a href="./src/resources/shared.ts">ErrorModel</a></code>
- <code><a href="./src/resources/shared.ts">LogEvent</a></code>

# Deployments

Types:

- <code><a href="./src/resources/deployments.ts">DeploymentStateEvent</a></code>
- <code><a href="./src/resources/deployments.ts">DeploymentCreateResponse</a></code>
- <code><a href="./src/resources/deployments.ts">DeploymentRetrieveResponse</a></code>
- <code><a href="./src/resources/deployments.ts">DeploymentFollowResponse</a></code>

Methods:

- <code title="post /deployments">client.deployments.<a href="./src/resources/deployments.ts">create</a>({ ...params }) -> DeploymentCreateResponse</code>
- <code title="get /deployments/{id}">client.deployments.<a href="./src/resources/deployments.ts">retrieve</a>(id) -> DeploymentRetrieveResponse</code>
- <code title="get /deployments/{id}/events">client.deployments.<a href="./src/resources/deployments.ts">follow</a>(id) -> DeploymentFollowResponse</code>

# Apps

Types:
Expand All @@ -20,19 +44,22 @@ Methods:
- <code title="post /deploy">client.apps.deployments.<a href="./src/resources/apps/deployments.ts">create</a>({ ...params }) -> DeploymentCreateResponse</code>
- <code title="get /apps/{id}/events">client.apps.deployments.<a href="./src/resources/apps/deployments.ts">follow</a>(id) -> DeploymentFollowResponse</code>

## Invocations
# Invocations

Types:

- <code><a href="./src/resources/apps/invocations.ts">InvocationCreateResponse</a></code>
- <code><a href="./src/resources/apps/invocations.ts">InvocationRetrieveResponse</a></code>
- <code><a href="./src/resources/apps/invocations.ts">InvocationUpdateResponse</a></code>
- <code><a href="./src/resources/invocations.ts">InvocationStateEvent</a></code>
- <code><a href="./src/resources/invocations.ts">InvocationCreateResponse</a></code>
- <code><a href="./src/resources/invocations.ts">InvocationRetrieveResponse</a></code>
- <code><a href="./src/resources/invocations.ts">InvocationUpdateResponse</a></code>
- <code><a href="./src/resources/invocations.ts">InvocationFollowResponse</a></code>

Methods:

- <code title="post /invocations">client.apps.invocations.<a href="./src/resources/apps/invocations.ts">create</a>({ ...params }) -> InvocationCreateResponse</code>
- <code title="get /invocations/{id}">client.apps.invocations.<a href="./src/resources/apps/invocations.ts">retrieve</a>(id) -> InvocationRetrieveResponse</code>
- <code title="patch /invocations/{id}">client.apps.invocations.<a href="./src/resources/apps/invocations.ts">update</a>(id, { ...params }) -> InvocationUpdateResponse</code>
- <code title="post /invocations">client.invocations.<a href="./src/resources/invocations.ts">create</a>({ ...params }) -> InvocationCreateResponse</code>
- <code title="get /invocations/{id}">client.invocations.<a href="./src/resources/invocations.ts">retrieve</a>(id) -> InvocationRetrieveResponse</code>
- <code title="patch /invocations/{id}">client.invocations.<a href="./src/resources/invocations.ts">update</a>(id, { ...params }) -> InvocationUpdateResponse</code>
- <code title="get /invocations/{id}/events">client.invocations.<a href="./src/resources/invocations.ts">follow</a>(id) -> InvocationFollowResponse</code>

# Browsers

Expand Down
34 changes: 27 additions & 7 deletions bin/publish-npm
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,35 @@ npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"
yarn build
cd dist

# Get package name and version from package.json
PACKAGE_NAME="$(jq -r -e '.name' ./package.json)"
VERSION="$(jq -r -e '.version' ./package.json)"

# Get latest version from npm
#
# If the package doesn't exist, yarn will return
# {"type":"error","data":"Received invalid response from npm."}
# where .data.version doesn't exist so LAST_VERSION will be an empty string.
LAST_VERSION="$(yarn info --json 2> /dev/null | jq -r '.data.version')"

# Get current version from package.json
VERSION="$(node -p "require('./package.json').version")"
# If the package doesn't exist, npm will return:
# {
# "error": {
# "code": "E404",
# "summary": "Unpublished on 2025-06-05T09:54:53.528Z",
# "detail": "'the_package' is not in this registry..."
# }
# }
NPM_INFO="$(npm view "$PACKAGE_NAME" version --json 2>/dev/null || true)"

# Check if we got an E404 error
if echo "$NPM_INFO" | jq -e '.error.code == "E404"' > /dev/null 2>&1; then
# Package doesn't exist yet, no last version
LAST_VERSION=""
elif echo "$NPM_INFO" | jq -e '.error' > /dev/null 2>&1; then
# Report other errors
echo "ERROR: npm returned unexpected data:"
echo "$NPM_INFO"
exit 1
else
# Success - get the version
LAST_VERSION=$(echo "$NPM_INFO" | jq -r '.') # strip quotes
fi

# Check if current version is pre-release (e.g. alpha / beta / rc)
CURRENT_IS_PRERELEASE=false
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onkernel/sdk",
"version": "0.5.0",
"version": "0.6.0",
"description": "The official TypeScript library for the Kernel API",
"author": "Kernel <>",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -42,7 +42,7 @@
"publint": "^0.2.12",
"ts-jest": "^29.1.0",
"ts-node": "^10.5.0",
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.4/tsc-multi-1.1.4.tgz",
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.8/tsc-multi.tgz",
"tsconfig-paths": "^4.0.0",
"typescript": "5.8.3"
},
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fi
node scripts/utils/make-dist-package-json.cjs > dist/package.json

# build to .js/.mjs/.d.ts files
npm exec tsc-multi
./node_modules/.bin/tsc-multi
# we need to patch index.js so that `new module.exports()` works for cjs backwards
# compat. No way to get that from index.ts because it would cause compile errors
# when building .mjs
Expand Down
86 changes: 75 additions & 11 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestIni
import { uuid4 } from './internal/utils/uuid';
import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
import { sleep } from './internal/utils/sleep';
import { type Logger, type LogLevel, parseLogLevel } from './internal/utils/log';
export type { Logger, LogLevel } from './internal/utils/log';
import { castToError, isAbortError } from './internal/errors';
import type { APIResponseProps } from './internal/parse';
Expand All @@ -17,9 +16,6 @@ import * as Errors from './core/error';
import * as Uploads from './core/uploads';
import * as API from './resources/index';
import { APIPromise } from './core/api-promise';
import { type Fetch } from './internal/builtin-types';
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
import {
BrowserCreateParams,
BrowserCreateResponse,
Expand All @@ -29,11 +25,38 @@ import {
BrowserRetrieveResponse,
Browsers,
} from './resources/browsers';
import { readEnv } from './internal/utils/env';
import { formatRequestDetails, loggerFor } from './internal/utils/log';
import { isEmptyObj } from './internal/utils/values';
import {
DeploymentCreateParams,
DeploymentCreateResponse,
DeploymentFollowResponse,
DeploymentRetrieveResponse,
DeploymentStateEvent,
Deployments,
} from './resources/deployments';
import { KernelApp } from './core/app-framework';
import {
InvocationCreateParams,
InvocationCreateResponse,
InvocationFollowResponse,
InvocationRetrieveResponse,
InvocationStateEvent,
InvocationUpdateParams,
InvocationUpdateResponse,
Invocations,
} from './resources/invocations';
import { AppListParams, AppListResponse, Apps } from './resources/apps/apps';
import { type Fetch } from './internal/builtin-types';
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
import { readEnv } from './internal/utils/env';
import {
type LogLevel,
type Logger,
formatRequestDetails,
loggerFor,
parseLogLevel,
} from './internal/utils/log';
import { isEmptyObj } from './internal/utils/values';

const environments = {
production: 'https://api.onkernel.com/',
Expand Down Expand Up @@ -216,6 +239,13 @@ export class Kernel {
});
}

/**
* Check whether the base URL is set to its default.
*/
#baseURLOverridden(): boolean {
return this.baseURL !== environments[this._options.environment || 'production'];
}

protected defaultQuery(): Record<string, string | undefined> | undefined {
return this._options.defaultQuery;
}
Expand Down Expand Up @@ -265,11 +295,16 @@ export class Kernel {
return Errors.APIError.generate(status, error, message, headers);
}

buildURL(path: string, query: Record<string, unknown> | null | undefined): string {
buildURL(
path: string,
query: Record<string, unknown> | null | undefined,
defaultBaseURL?: string | undefined,
): string {
const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
const url =
isAbsoluteURL(path) ?
new URL(path)
: new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));

const defaultQuery = this.defaultQuery();
if (!isEmptyObj(defaultQuery)) {
Expand Down Expand Up @@ -610,9 +645,9 @@ export class Kernel {
{ retryCount = 0 }: { retryCount?: number } = {},
): { req: FinalizedRequestInit; url: string; timeout: number } {
const options = { ...inputOptions };
const { method, path, query } = options;
const { method, path, query, defaultBaseURL } = options;

const url = this.buildURL(path!, query as Record<string, unknown>);
const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
options.timeout = options.timeout ?? this.timeout;
const { bodyHeaders, body } = this.buildBody({ options });
Expand Down Expand Up @@ -735,16 +770,40 @@ export class Kernel {

static toFile = Uploads.toFile;

deployments: API.Deployments = new API.Deployments(this);
apps: API.Apps = new API.Apps(this);
invocations: API.Invocations = new API.Invocations(this);
browsers: API.Browsers = new API.Browsers(this);
}
Kernel.Deployments = Deployments;
Kernel.Apps = Apps;
Kernel.Invocations = Invocations;
Kernel.Browsers = Browsers;
export declare namespace Kernel {
export type RequestOptions = Opts.RequestOptions;

export {
Deployments as Deployments,
type DeploymentStateEvent as DeploymentStateEvent,
type DeploymentCreateResponse as DeploymentCreateResponse,
type DeploymentRetrieveResponse as DeploymentRetrieveResponse,
type DeploymentFollowResponse as DeploymentFollowResponse,
type DeploymentCreateParams as DeploymentCreateParams,
};

export { Apps as Apps, type AppListResponse as AppListResponse, type AppListParams as AppListParams };

export {
Invocations as Invocations,
type InvocationStateEvent as InvocationStateEvent,
type InvocationCreateResponse as InvocationCreateResponse,
type InvocationRetrieveResponse as InvocationRetrieveResponse,
type InvocationUpdateResponse as InvocationUpdateResponse,
type InvocationFollowResponse as InvocationFollowResponse,
type InvocationCreateParams as InvocationCreateParams,
type InvocationUpdateParams as InvocationUpdateParams,
};

export {
Browsers as Browsers,
type BrowserPersistence as BrowserPersistence,
Expand All @@ -754,4 +813,9 @@ export declare namespace Kernel {
type BrowserCreateParams as BrowserCreateParams,
type BrowserDeleteParams as BrowserDeleteParams,
};

export type ErrorDetail = API.ErrorDetail;
export type ErrorEvent = API.ErrorEvent;
export type ErrorModel = API.ErrorModel;
export type LogEvent = API.LogEvent;
}
2 changes: 1 addition & 1 deletion src/core/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { Kernel } from '../client';

export class APIResource {
export abstract class APIResource {
protected _client: Kernel;

constructor(client: Kernel) {
Expand Down
Loading