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
8,009 changes: 0 additions & 8,009 deletions package-lock.json

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
"eslint-plugin-unused-imports": "^3.0.0",
"gh-pages": "^6.3.0",
"iconv-lite": "^0.6.3",
"jest": "^29.4.0",
"jest": "^30.2.0",
"prettier": "^3.0.0",
"ts-jest": "^29.1.0",
"ts-node": "^10.5.0",
"ts-jest": "^29.4.6",
"ts-node": "^10.9.2",
"tsc-multi": "^1.1.0",
"tsconfig-paths": "^4.0.0",
"typedoc": "^0.28.14",
Expand Down
11 changes: 6 additions & 5 deletions src/lib/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface PollingOptions<T> {
initialDelayMs?: number;
/** Delay between subsequent polling attempts (in milliseconds) */
pollingIntervalMs?: number;
/** Maximum number of polling attempts before throwing an error */
/** Maximum number of polling attempts before throwing an error. Defaults to infinite (no limit). */
maxAttempts?: number;
/** Optional timeout for the entire polling operation (in milliseconds) */
timeoutMs?: number;
Expand All @@ -26,7 +26,6 @@ export interface PollingOptions<T> {
const DEFAULT_OPTIONS: Partial<PollingOptions<any>> = {
initialDelayMs: 1000,
pollingIntervalMs: 1000,
maxAttempts: 120,
};

export class PollingTimeoutError extends Error {
Expand Down Expand Up @@ -112,7 +111,8 @@ export async function poll<T>(

let attempts = 0;

while (attempts < maxAttempts!) {
// maxAttempts === undefined means infinite polling (by design, see PollingOptions.maxAttempts JSDoc)
while (maxAttempts === undefined || attempts < maxAttempts) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when would maxAttempts be undefined? If it is, can we set a default on it

++attempts;

const pollingPromise = async () => {
Expand All @@ -132,7 +132,7 @@ export async function poll<T>(
return result;
}

if (attempts === maxAttempts) {
if (maxAttempts !== undefined && attempts === maxAttempts) {
throw new MaxAttemptsExceededError(`Polling exceeded maximum attempts (${maxAttempts})`, result);
}

Expand All @@ -150,7 +150,8 @@ export async function poll<T>(
}
}

throw new MaxAttemptsExceededError(`Polling exceeded maximum attempts (${maxAttempts})`, result);
// This should only be reachable if maxAttempts is defined
throw new MaxAttemptsExceededError(`Polling exceeded maximum attempts (${maxAttempts})`, result!);
} catch (error) {
clearTimeoutIfExists();
throw error;
Expand Down
118 changes: 118 additions & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Snapshot } from './sdk/snapshot';
import { StorageObject } from './sdk/storage-object';
import { Agent } from './sdk/agent';
import { Scorer } from './sdk/scorer';
import { NetworkPolicy } from './sdk/network-policy';

// Import types used in this file
import type {
Expand All @@ -19,6 +20,7 @@ import type { BlueprintListParams } from './resources/blueprints';
import type { ObjectCreateParams, ObjectListParams } from './resources/objects';
import type { AgentCreateParams, AgentListParams } from './resources/agents';
import type { ScorerCreateParams, ScorerListParams } from './resources/scenarios/scorers';
import type { NetworkPolicyCreateParams, NetworkPolicyListParams } from './resources/network-policies';
import { PollingOptions } from './lib/polling';
import * as Shared from './resources/shared';

Expand Down Expand Up @@ -193,6 +195,7 @@ type ContentType = ObjectCreateParams['content_type'];
* - `storageObject` - {@link StorageObjectOps}
* - `agent` - {@link AgentOps}
* - `scorer` - {@link ScorerOps}
* - `networkPolicy` - {@link NetworkPolicyOps}
*
* See the documentation for each Operations class for more details.
*
Expand Down Expand Up @@ -271,6 +274,14 @@ export class RunloopSDK {
*/
public readonly scorer: ScorerOps;

/**
* **Network Policy Operations** - {@link NetworkPolicyOps} for creating and accessing {@link NetworkPolicy} class instances.
*
* Network policies define egress network access rules for devboxes. Policies can be applied to
* blueprints, devboxes, and snapshot resumes to control network access.
*/
public readonly networkPolicy: NetworkPolicyOps;

/**
* Creates a new RunloopSDK instance.
* @param {ClientOptions} [options] - Optional client configuration options.
Expand All @@ -283,6 +294,7 @@ export class RunloopSDK {
this.storageObject = new StorageObjectOps(this.api);
this.agent = new AgentOps(this.api);
this.scorer = new ScorerOps(this.api);
this.networkPolicy = new NetworkPolicyOps(this.api);
}
}

Expand Down Expand Up @@ -1382,6 +1394,109 @@ export class ScorerOps {
}
}

/**
* Network Policy SDK interface for managing network policies.
*
* @category Network Policy
*
* @remarks
* ## Overview
*
* The `NetworkPolicyOps` class provides a high-level abstraction for managing network policies,
* which define egress network access rules for devboxes. Policies can be applied to blueprints,
* devboxes, and snapshot resumes to control network access.
*
* ## Usage
*
* This interface is accessed via {@link RunloopSDK.networkPolicy}. You should construct
* a {@link RunloopSDK} instance and use it from there:
*
* @example
* ```typescript
* const runloop = new RunloopSDK();
* const policy = await runloop.networkPolicy.create({
* name: 'restricted-policy',
* allow_all: false,
* allowed_hostnames: ['github.com', 'api.openai.com'],
* });
*
* const info = await policy.getInfo();
* console.log(`Policy: ${info.name}`);
* ```
*/
export class NetworkPolicyOps {
/**
* @private
*/
constructor(private client: RunloopAPI) {}

/**
* Create a new network policy.
*
* @example
* ```typescript
* const runloop = new RunloopSDK();
* const policy = await runloop.networkPolicy.create({
* name: 'my-policy',
* allow_all: false,
* allowed_hostnames: ['github.com', '*.npmjs.org'],
* allow_devbox_to_devbox: true,
* description: 'Policy for restricted network access',
* });
* ```
*
* @param {NetworkPolicyCreateParams} params - Parameters for creating the network policy.
* @param {Core.RequestOptions} [options] - Request options.
* @returns {Promise<NetworkPolicy>} A {@link NetworkPolicy} instance.
*/
async create(params: NetworkPolicyCreateParams, options?: Core.RequestOptions): Promise<NetworkPolicy> {
return NetworkPolicy.create(this.client, params, options);
}

/**
* Get a network policy object by its ID.
*
* @example
* ```typescript
* const runloop = new RunloopSDK();
* const policy = runloop.networkPolicy.fromId('npol_1234567890');
* const info = await policy.getInfo();
* console.log(`Policy name: ${info.name}`);
* ```
*
* @param {string} id - The ID of the network policy.
* @returns {NetworkPolicy} A {@link NetworkPolicy} instance.
*/
fromId(id: string): NetworkPolicy {
return NetworkPolicy.fromId(this.client, id);
}

/**
* List all network policies with optional filters.
*
* @example
* ```typescript
* const runloop = new RunloopSDK();
* const policies = await runloop.networkPolicy.list({ limit: 10 });
* console.log(policies.map((p) => p.id));
* ```
*
* @param {NetworkPolicyListParams} [params] - Optional filter parameters.
* @param {Core.RequestOptions} [options] - Request options.
* @returns {Promise<NetworkPolicy[]>} An array of {@link NetworkPolicy} instances.
*/
async list(params?: NetworkPolicyListParams, options?: Core.RequestOptions): Promise<NetworkPolicy[]> {
const result = await this.client.networkPolicies.list(params, options);
const policies: NetworkPolicy[] = [];

for await (const policy of result) {
policies.push(NetworkPolicy.fromId(this.client, policy.id));
}

return policies;
}
}

// @deprecated Use {@link RunloopSDK} instead.
/**
* @deprecated Use {@link RunloopSDK} instead.
Expand All @@ -1403,12 +1518,14 @@ export declare namespace RunloopSDK {
StorageObjectOps as StorageObjectOps,
AgentOps as AgentOps,
ScorerOps as ScorerOps,
NetworkPolicyOps as NetworkPolicyOps,
Devbox as Devbox,
Blueprint as Blueprint,
Snapshot as Snapshot,
StorageObject as StorageObject,
Agent as Agent,
Scorer as Scorer,
NetworkPolicy as NetworkPolicy,
};
}
// Export SDK classes from sdk/sdk.ts - these are separate from RunloopSDK to avoid circular dependencies
Expand All @@ -1423,6 +1540,7 @@ export {
StorageObject,
Agent,
Scorer,
NetworkPolicy,
Execution,
ExecutionResult,
} from './sdk/index';
1 change: 1 addition & 0 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { Agent } from './agent';
export { Execution } from './execution';
export { ExecutionResult } from './execution-result';
export { Scorer } from './scorer';
export { NetworkPolicy } from './network-policy';
Loading
Loading