Skip to content

release: 0.7.1 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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.7.0"
".": "0.7.1"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.7.1 (2025-07-03)

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

### Bug Fixes

* avoid console usage ([f37b356](https://github.com/onkernel/kernel-node-sdk/commit/f37b3560b92abc5a85416b9b69f03a70b3ff71cf))


### Chores

* add docs to RequestOptions type ([fcb82ff](https://github.com/onkernel/kernel-node-sdk/commit/fcb82ff3d5c14af006bba0e441d57baf318a19cf))

## 0.7.0 (2025-07-02)

Full Changelog: [v0.6.5...v0.7.0](https://github.com/onkernel/kernel-node-sdk/compare/v0.6.5...v0.7.0)
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.7.0",
"version": "0.7.1",
"description": "The official TypeScript library for the Kernel API",
"author": "Kernel <>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export interface ClientOptions {
*
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
* much longer than this timeout before the promise succeeds or fails.
*
* @unit milliseconds
*/
timeout?: number | undefined;
/**
Expand Down
30 changes: 22 additions & 8 deletions src/core/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { findDoubleNewlineIndex, LineDecoder } from '../internal/decoders/line';
import { ReadableStreamToAsyncIterable } from '../internal/shims';
import { isAbortError } from '../internal/errors';
import { encodeUTF8 } from '../internal/utils/bytes';
import { loggerFor } from '../internal/utils/log';
import type { Kernel } from '../client';

type Bytes = string | ArrayBuffer | Uint8Array | null | undefined;

Expand All @@ -16,16 +18,24 @@ export type ServerSentEvent = {

export class Stream<Item> implements AsyncIterable<Item> {
controller: AbortController;
#client: Kernel | undefined;

constructor(
private iterator: () => AsyncIterator<Item>,
controller: AbortController,
client?: Kernel,
) {
this.controller = controller;
this.#client = client;
}

static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item> {
static fromSSEResponse<Item>(
response: Response,
controller: AbortController,
client?: Kernel,
): Stream<Item> {
let consumed = false;
const logger = client ? loggerFor(client) : console;

async function* iterator(): AsyncIterator<Item, any, undefined> {
if (consumed) {
Expand All @@ -38,8 +48,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
try {
yield JSON.parse(sse.data);
} catch (e) {
console.error(`Could not parse message into JSON:`, sse.data);
console.error(`From chunk:`, sse.raw);
logger.error(`Could not parse message into JSON:`, sse.data);
logger.error(`From chunk:`, sse.raw);
throw e;
}
}
Expand All @@ -54,14 +64,18 @@ export class Stream<Item> implements AsyncIterable<Item> {
}
}

return new Stream(iterator, controller);
return new Stream(iterator, controller, client);
}

/**
* Generates a Stream from a newline-separated ReadableStream
* where each item is a JSON value.
*/
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item> {
static fromReadableStream<Item>(
readableStream: ReadableStream,
controller: AbortController,
client?: Kernel,
): Stream<Item> {
let consumed = false;

async function* iterLines(): AsyncGenerator<string, void, unknown> {
Expand Down Expand Up @@ -101,7 +115,7 @@ export class Stream<Item> implements AsyncIterable<Item> {
}
}

return new Stream(iterator, controller);
return new Stream(iterator, controller, client);
}

[Symbol.asyncIterator](): AsyncIterator<Item> {
Expand Down Expand Up @@ -131,8 +145,8 @@ export class Stream<Item> implements AsyncIterable<Item> {
};

return [
new Stream(() => teeIterator(left), this.controller),
new Stream(() => teeIterator(right), this.controller),
new Stream(() => teeIterator(left), this.controller, this.#client),
new Stream(() => teeIterator(right), this.controller, this.#client),
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/internal/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export async function defaultParseResponse<T>(client: Kernel, props: APIResponse
// that if you set `stream: true` the response type must also be `Stream<T>`

if (props.options.__streamClass) {
return props.options.__streamClass.fromSSEResponse(response, props.controller) as any;
return props.options.__streamClass.fromSSEResponse(response, props.controller, client) as any;
}

return Stream.fromSSEResponse(response, props.controller) as any;
return Stream.fromSSEResponse(response, props.controller, client) as any;
}

// fetch refuses to read the body when the status code is 204.
Expand Down
53 changes: 53 additions & 0 deletions src/internal/request-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,70 @@ import { type HeadersLike } from './headers';
export type FinalRequestOptions = RequestOptions & { method: HTTPMethod; path: string };

export type RequestOptions = {
/**
* The HTTP method for the request (e.g., 'get', 'post', 'put', 'delete').
*/
method?: HTTPMethod;

/**
* The URL path for the request.
*
* @example "/v1/foo"
*/
path?: string;

/**
* Query parameters to include in the request URL.
*/
query?: object | undefined | null;

/**
* The request body. Can be a string, JSON object, FormData, or other supported types.
*/
body?: unknown;

/**
* HTTP headers to include with the request. Can be a Headers object, plain object, or array of tuples.
*/
headers?: HeadersLike;

/**
* The maximum number of times that the client will retry a request in case of a
* temporary failure, like a network error or a 5XX error from the server.
*
* @default 2
*/
maxRetries?: number;

stream?: boolean | undefined;

/**
* The maximum amount of time (in milliseconds) that the client should wait for a response
* from the server before timing out a single request.
*
* @unit milliseconds
*/
timeout?: number;

/**
* Additional `RequestInit` options to be passed to the underlying `fetch` call.
* These options will be merged with the client's default fetch options.
*/
fetchOptions?: MergedRequestInit;

/**
* An AbortSignal that can be used to cancel the request.
*/
signal?: AbortSignal | undefined | null;

/**
* A unique key for this request to enable idempotency.
*/
idempotencyKey?: string;

/**
* Override the default base URL for this specific request.
*/
defaultBaseURL?: string | undefined;

__binaryResponse?: boolean | undefined;
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.7.0'; // x-release-please-version
export const VERSION = '0.7.1'; // x-release-please-version