Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ existing `0.1.0` release; earlier development prereleases are not listed.

### Fixed

- Throw `QoderError` for client-side authentication and path-parameter validation failures and validate `sessionID` eagerly in Forward and Managed `sessions.events.resumableStream()`, preventing unauthenticated or empty-ID streams from looping indefinitely on retries.
- Accept masked OSS bucket credentials in typed Forward Environment updates, so callers can edit and resend read configurations without supplying secrets again. New bucket creation still requires complete write credentials.
- Send Managed `environments.work.heartbeat()` `expected_last_heartbeat` and `desired_ttl_seconds` as query parameters. Earlier releases put them in the JSON body, which the service ignores, so lease preconditions and requested TTLs had no effect.
- Accept `"latest"` and positive integer strings for child Agent `version` in Managed Agent multiagent rosters, and type saved roster versions as `number | "latest"` in Agent responses. Session and Deployment Agent references keep numeric versions.
Expand Down
2 changes: 1 addition & 1 deletion src/core/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class APIClient {
return;
}

throw new Error(
throw new QoderError(
'Could not resolve authentication method. Configure accessToken or credential, or QODER_ACCESS_TOKEN (QODER_PAT is supported in PAT mode).',
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { QoderError } from './error.js';

export interface Credential {
getToken(): string | Promise<string>;
}
Expand All @@ -12,7 +14,7 @@ export function readEnv(name: string): string | undefined {

export class PATCredential implements Credential {
constructor(private readonly token: string) {
if (!token) throw new Error('PAT must not be empty');
if (!token) throw new QoderError('PAT must not be empty');
}

static fromEnv(name = 'QODER_PAT'): PATCredential {
Expand Down
3 changes: 2 additions & 1 deletion src/forward/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Shared transport details for the Forward resources.
import { QoderError } from '../core/error.js';
import type { IdentityScopeOptions } from './types.js';
import type { RequestOptions } from '../core/client.js';

/** Validate before invoking fetch, then escape the value as one path segment. */
export function pathParam(value: string, name: string): string {
if (typeof value !== 'string' || value.length === 0) {
throw new Error(`missing required ${name} parameter`);
throw new QoderError(`missing required ${name} parameter`);
}
return encodeURIComponent(value);
}
Expand Down
1 change: 1 addition & 0 deletions src/forward/session-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class SessionEvents extends APIResource {
params: SessionEventStreamParams = {},
options?: RequestOptions,
): ResumableSessionEventStream<SessionEvent> {
pathParam(sessionID, "session_id");
const initialCursor = initialLastEventID(params.last_event_id, this._client.defaultHeaders, options?.headers);
return new ResumableSessionEventStream<SessionEvent>(
(lastEventID, signal) => this.streamEvents(
Expand Down
3 changes: 2 additions & 1 deletion src/managed/internal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mergeHeaders, type RequestOptions } from '../core/client.js';
import { QoderError } from '../core/error.js';
import { toFile, type Uploadable } from '../core/uploads.js';

/** Extract header and parent-path parameters without mutating the caller's input. */
Expand Down Expand Up @@ -30,7 +31,7 @@ export function splitParams(
}

export function pathParam(value: string | undefined | null, name: string): string {
if (typeof value !== 'string' || value.length === 0) throw new Error(`Missing required ${name} parameter`);
if (typeof value !== 'string' || value.length === 0) throw new QoderError(`Missing required ${name} parameter`);
return encodeURIComponent(value);
}

Expand Down
1 change: 1 addition & 0 deletions src/managed/resources/session-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class SessionsEvents extends APIResource {
params: Types.SessionEventStreamParams | null | undefined = {},
options?: RequestOptions,
): ResumableSessionEventStream<Types.ManagedAgentsStreamSessionEventsUnion> {
pathParam(sessionID, "session_id");
const values = params ?? {};
const initialCursor = initialLastEventID(values.last_event_id, this._client.defaultHeaders, options?.headers);
return new ResumableSessionEventStream<Types.ManagedAgentsStreamSessionEventsUnion>(
Expand Down
41 changes: 41 additions & 0 deletions tests/resumable-streaming.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,44 @@ test('close aborts the active child stream and is idempotent', async () => {
assert.equal(requestSignal.aborted, true);
assert.equal((await iterator.next()).done, true);
});

test('missing credentials fail immediately as QoderError without retrying', async () => {
const prevToken = process.env.QODER_ACCESS_TOKEN;
const prevPat = process.env.QODER_PAT;
delete process.env.QODER_ACCESS_TOKEN;
delete process.env.QODER_PAT;
try {
for (const [label, client] of [
['forward', new sdk.ForwardClient({ fetch: () => { throw new Error('network should not be called'); } })],
['managed', new sdk.ManagedClient({ fetch: () => { throw new Error('network should not be called'); } })],
]) {
const stream = client.sessions.events.resumableStream('sess-one');
await assert.rejects(
() => stream[Symbol.asyncIterator]().next(),
error => error instanceof sdk.QoderError && /authentication method/i.test(error.message),
label,
);
}
} finally {
if (prevToken !== undefined) process.env.QODER_ACCESS_TOKEN = prevToken;
if (prevPat !== undefined) process.env.QODER_PAT = prevPat;
}
});

test('empty sessionID throws QoderError eagerly on resumableStream', () => {
for (const mode of ['forward', 'managed']) {
const client = testClient(mode, () => { throw new Error('network should not be called'); });
assert.throws(
() => client.sessions.events.resumableStream(''),
error => error instanceof sdk.QoderError && /session_id/i.test(error.message),
mode,
);
}
});

test('PATCredential rejects empty token with QoderError', () => {
assert.throws(
() => new sdk.PATCredential(''),
error => error instanceof sdk.QoderError,
);
});