diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 945fbaf..c84411f 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.25.0" + ".": "0.26.0" } diff --git a/.stats.yml b/.stats.yml index e1dcb32..dc04f86 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 8 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-78325ecc9bdc8e9850866fcdd3be3d209b06f151059c774afc7e6005a1775f09.yml -openapi_spec_hash: 19a34c8ddd46f81dd0b0850af5ee42f3 -config_hash: 620d4d190431b939dd17ac5d442918e6 +configured_endpoints: 23 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai%2Fperplexity-e7ac06ada1aa9e0a37a95c1aa5927efe563fc2683c7a144638fa8bd6f68012ac.yml +openapi_spec_hash: 3ced2367a3f063e4eddce3a3253a4087 +config_hash: 12ef310e24ea5bae135eacbbe1a391ca diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d6bbe0..7b2423c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Changelog +## 0.26.0 (2026-02-17) + +Full Changelog: [v0.25.0...v0.26.0](https://github.com/perplexityai/perplexity-node/compare/v0.25.0...v0.26.0) + +### Features + +* **api:** Add browser and sandbox API endpoints ([a35f39c](https://github.com/perplexityai/perplexity-node/commit/a35f39c37eddf661d131c9f07a7b4ea25d95ab5d)) + + +### Chores + +* **internal/client:** fix form-urlencoded requests ([36bfdb4](https://github.com/perplexityai/perplexity-node/commit/36bfdb4f151bc3d20e946f5658679edfe78d7f73)) + ## 0.25.0 (2026-02-12) Full Changelog: [v0.24.0...v0.25.0](https://github.com/perplexityai/perplexity-node/compare/v0.24.0...v0.25.0) diff --git a/api.md b/api.md index 792f7c7..f4308f8 100644 --- a/api.md +++ b/api.md @@ -3,18 +3,29 @@ Types: - APIPublicSearchResult +- BrowserSessionResponse - ChatMessageInput - ChatMessageOutput - Choice - ContextualizedEmbeddingObject - EmbeddingObject - EmbeddingsUsage +- ExecuteCodeResponse +- FileEntry - JsonSchemaFormat +- ListFilesResponse +- ListProcessesResponse +- ModifiedFilesResponse +- PauseSandboxResponse +- ProcessInfo +- ReadFileResponse - ResponseFormat +- SandboxSessionResponse - SearchResult - UsageInfo - UserLocation - WebSearchOptions +- WriteFileResponse # Chat @@ -78,6 +89,60 @@ Methods: - client.contextualizedEmbeddings.create({ ...params }) -> ContextualizedEmbeddingCreateResponse +# Browser + +## Sessions + +Methods: + +- client.browser.sessions.create() -> BrowserSessionResponse +- client.browser.sessions.delete(sessionID) -> void + +# Sandbox + +## Sessions + +Methods: + +- client.sandbox.sessions.create({ ...params }) -> SandboxSessionResponse +- client.sandbox.sessions.delete(sessionID) -> void +- client.sandbox.sessions.get(sessionID) -> SandboxSessionResponse + +### Execute + +Methods: + +- client.sandbox.sessions.execute.create(sessionID, { ...params }) -> ExecuteCodeResponse + +### Pause + +Methods: + +- client.sandbox.sessions.pause.create(sessionID) -> PauseSandboxResponse + +### Resume + +Methods: + +- client.sandbox.sessions.resume.create(sessionID, { ...params }) -> SandboxSessionResponse + +### Files + +Methods: + +- client.sandbox.sessions.files.list(sessionID, { ...params }) -> ListFilesResponse +- client.sandbox.sessions.files.modified(sessionID) -> ModifiedFilesResponse +- client.sandbox.sessions.files.read(sessionID, { ...params }) -> ReadFileResponse +- client.sandbox.sessions.files.write(sessionID, { ...params }) -> WriteFileResponse + +### Processes + +Methods: + +- client.sandbox.sessions.processes.list(sessionID) -> ListProcessesResponse +- client.sandbox.sessions.processes.delete(pid, { ...params }) -> void +- client.sandbox.sessions.processes.get(pid, { ...params }) -> ProcessInfo + # Async ## Chat diff --git a/package.json b/package.json index 2ab60ee..0e8fff3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@perplexity-ai/perplexity_ai", - "version": "0.25.0", + "version": "0.26.0", "description": "The official TypeScript library for the Perplexity API", "author": "Perplexity ", "types": "dist/index.d.ts", diff --git a/src/client.ts b/src/client.ts index 49feccb..f2e0754 100644 --- a/src/client.ts +++ b/src/client.ts @@ -41,7 +41,9 @@ import { } from './resources/responses'; import { Search, SearchCreateParams, SearchCreateResponse } from './resources/search'; import { Async } from './resources/async/async'; +import { Browser } from './resources/browser/browser'; import { Chat, StreamChunk } from './resources/chat/chat'; +import { Sandbox } from './resources/sandbox/sandbox'; import { type Fetch } from './internal/builtin-types'; import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers'; import { FinalRequestOptions, RequestOptions } from './internal/request-options'; @@ -722,6 +724,14 @@ export class Perplexity { (Symbol.iterator in body && 'next' in body && typeof body.next === 'function')) ) { return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable) }; + } else if ( + typeof body === 'object' && + headers.values.get('content-type') === 'application/x-www-form-urlencoded' + ) { + return { + bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' }, + body: this.stringifyQuery(body as Record), + }; } else { return this.#encoder({ body, headers }); } @@ -751,6 +761,8 @@ export class Perplexity { responses: API.Responses = new API.Responses(this); embeddings: API.Embeddings = new API.Embeddings(this); contextualizedEmbeddings: API.ContextualizedEmbeddings = new API.ContextualizedEmbeddings(this); + browser: API.Browser = new API.Browser(this); + sandbox: API.Sandbox = new API.Sandbox(this); async: API.Async = new API.Async(this); } @@ -759,6 +771,8 @@ Perplexity.Search = Search; Perplexity.Responses = Responses; Perplexity.Embeddings = Embeddings; Perplexity.ContextualizedEmbeddings = ContextualizedEmbeddings; +Perplexity.Browser = Browser; +Perplexity.Sandbox = Sandbox; Perplexity.Async = Async; export declare namespace Perplexity { @@ -802,19 +816,34 @@ export declare namespace Perplexity { type ContextualizedEmbeddingCreateParams as ContextualizedEmbeddingCreateParams, }; + export { Browser as Browser }; + + export { Sandbox as Sandbox }; + export { Async as Async }; export type APIPublicSearchResult = API.APIPublicSearchResult; + export type BrowserSessionResponse = API.BrowserSessionResponse; export type ChatMessageInput = API.ChatMessageInput; export type ChatMessageOutput = API.ChatMessageOutput; export type Choice = API.Choice; export type ContextualizedEmbeddingObject = API.ContextualizedEmbeddingObject; export type EmbeddingObject = API.EmbeddingObject; export type EmbeddingsUsage = API.EmbeddingsUsage; + export type ExecuteCodeResponse = API.ExecuteCodeResponse; + export type FileEntry = API.FileEntry; export type JsonSchemaFormat = API.JsonSchemaFormat; + export type ListFilesResponse = API.ListFilesResponse; + export type ListProcessesResponse = API.ListProcessesResponse; + export type ModifiedFilesResponse = API.ModifiedFilesResponse; + export type PauseSandboxResponse = API.PauseSandboxResponse; + export type ProcessInfo = API.ProcessInfo; + export type ReadFileResponse = API.ReadFileResponse; export type ResponseFormat = API.ResponseFormat; + export type SandboxSessionResponse = API.SandboxSessionResponse; export type SearchResult = API.SearchResult; export type UsageInfo = API.UsageInfo; export type UserLocation = API.UserLocation; export type WebSearchOptions = API.WebSearchOptions; + export type WriteFileResponse = API.WriteFileResponse; } diff --git a/src/resources/browser.ts b/src/resources/browser.ts new file mode 100644 index 0000000..53b35d9 --- /dev/null +++ b/src/resources/browser.ts @@ -0,0 +1,3 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +export * from './browser/index'; diff --git a/src/resources/browser/browser.ts b/src/resources/browser/browser.ts new file mode 100644 index 0000000..f854818 --- /dev/null +++ b/src/resources/browser/browser.ts @@ -0,0 +1,15 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../core/resource'; +import * as SessionsAPI from './sessions'; +import { SessionCreateParams, Sessions } from './sessions'; + +export class Browser extends APIResource { + sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client); +} + +Browser.Sessions = Sessions; + +export declare namespace Browser { + export { Sessions as Sessions, type SessionCreateParams as SessionCreateParams }; +} diff --git a/src/resources/browser/index.ts b/src/resources/browser/index.ts new file mode 100644 index 0000000..6084119 --- /dev/null +++ b/src/resources/browser/index.ts @@ -0,0 +1,4 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +export { Browser } from './browser'; +export { Sessions, type SessionCreateParams } from './sessions'; diff --git a/src/resources/browser/sessions.ts b/src/resources/browser/sessions.ts new file mode 100644 index 0000000..14c551f --- /dev/null +++ b/src/resources/browser/sessions.ts @@ -0,0 +1,36 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../core/resource'; +import * as Shared from '../shared'; +import { APIPromise } from '../../core/api-promise'; +import { buildHeaders } from '../../internal/headers'; +import { RequestOptions } from '../../internal/request-options'; +import { path } from '../../internal/utils/path'; + +export class Sessions extends APIResource { + /** + * Create a new remote browser session for CDP-based automation. + */ + create( + body?: SessionCreateParams | null | undefined, + options?: RequestOptions, + ): APIPromise { + return this._client.post('/v1/browser/sessions', { body, ...options }); + } + + /** + * Stop and clean up a remote browser session. + */ + delete(sessionID: string, options?: RequestOptions): APIPromise { + return this._client.delete(path`/v1/browser/sessions/${sessionID}`, { + ...options, + headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), + }); + } +} + +export interface SessionCreateParams {} + +export declare namespace Sessions { + export { type SessionCreateParams as SessionCreateParams }; +} diff --git a/src/resources/index.ts b/src/resources/index.ts index 06b373e..8814b8f 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -2,6 +2,7 @@ export * from './shared'; export { Async } from './async/async'; +export { Browser } from './browser/browser'; export { Chat, type StreamChunk } from './chat/chat'; export { ContextualizedEmbeddings, @@ -26,4 +27,5 @@ export { type ResponseCreateParamsNonStreaming, type ResponseCreateParamsStreaming, } from './responses'; +export { Sandbox } from './sandbox/sandbox'; export { Search, type SearchCreateResponse, type SearchCreateParams } from './search'; diff --git a/src/resources/sandbox.ts b/src/resources/sandbox.ts new file mode 100644 index 0000000..5b74147 --- /dev/null +++ b/src/resources/sandbox.ts @@ -0,0 +1,3 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +export * from './sandbox/index'; diff --git a/src/resources/sandbox/index.ts b/src/resources/sandbox/index.ts new file mode 100644 index 0000000..c79d0f2 --- /dev/null +++ b/src/resources/sandbox/index.ts @@ -0,0 +1,4 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +export { Sandbox } from './sandbox'; +export { Sessions, type SessionCreateParams } from './sessions/index'; diff --git a/src/resources/sandbox/sandbox.ts b/src/resources/sandbox/sandbox.ts new file mode 100644 index 0000000..ff2cd99 --- /dev/null +++ b/src/resources/sandbox/sandbox.ts @@ -0,0 +1,15 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../core/resource'; +import * as SessionsAPI from './sessions/sessions'; +import { SessionCreateParams, Sessions } from './sessions/sessions'; + +export class Sandbox extends APIResource { + sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client); +} + +Sandbox.Sessions = Sessions; + +export declare namespace Sandbox { + export { Sessions as Sessions, type SessionCreateParams as SessionCreateParams }; +} diff --git a/src/resources/sandbox/sessions.ts b/src/resources/sandbox/sessions.ts new file mode 100644 index 0000000..253b6db --- /dev/null +++ b/src/resources/sandbox/sessions.ts @@ -0,0 +1,3 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +export * from './sessions/index'; diff --git a/src/resources/sandbox/sessions/execute.ts b/src/resources/sandbox/sessions/execute.ts new file mode 100644 index 0000000..072b5d3 --- /dev/null +++ b/src/resources/sandbox/sessions/execute.ts @@ -0,0 +1,46 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../core/resource'; +import * as Shared from '../../shared'; +import { APIPromise } from '../../../core/api-promise'; +import { RequestOptions } from '../../../internal/request-options'; +import { path } from '../../../internal/utils/path'; + +export class Execute extends APIResource { + /** + * Execute Python or Bash code in the sandbox environment. + */ + create( + sessionID: string, + body: ExecuteCreateParams, + options?: RequestOptions, + ): APIPromise { + return this._client.post(path`/v1/sandbox/sessions/${sessionID}/execute`, { body, ...options }); + } +} + +export interface ExecuteCreateParams { + /** + * Base64 encoded code to execute + */ + code: string; + + /** + * Programming language of the code + */ + language: 'python' | 'bash'; + + /** + * Run in background (bash only) + */ + background?: boolean; + + /** + * Execution timeout in seconds (max 120) + */ + execution_timeout?: number; +} + +export declare namespace Execute { + export { type ExecuteCreateParams as ExecuteCreateParams }; +} diff --git a/src/resources/sandbox/sessions/files.ts b/src/resources/sandbox/sessions/files.ts new file mode 100644 index 0000000..8bfcbc6 --- /dev/null +++ b/src/resources/sandbox/sessions/files.ts @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../core/resource'; +import * as Shared from '../../shared'; +import { APIPromise } from '../../../core/api-promise'; +import { RequestOptions } from '../../../internal/request-options'; +import { path } from '../../../internal/utils/path'; + +export class Files extends APIResource { + /** + * List files and directories in the sandbox filesystem. + */ + list( + sessionID: string, + query: FileListParams | null | undefined = {}, + options?: RequestOptions, + ): APIPromise { + return this._client.get(path`/v1/sandbox/sessions/${sessionID}/files/list`, { query, ...options }); + } + + /** + * Get a list of files that have been modified since the session started. + */ + modified(sessionID: string, options?: RequestOptions): APIPromise { + return this._client.get(path`/v1/sandbox/sessions/${sessionID}/files/modified`, options); + } + + /** + * Read a file from the sandbox filesystem. Content is returned base64 encoded. + */ + read( + sessionID: string, + query: FileReadParams, + options?: RequestOptions, + ): APIPromise { + return this._client.get(path`/v1/sandbox/sessions/${sessionID}/files`, { query, ...options }); + } + + /** + * Write a file to the sandbox filesystem. Content must be base64 encoded. + */ + write( + sessionID: string, + body: FileWriteParams, + options?: RequestOptions, + ): APIPromise { + return this._client.post(path`/v1/sandbox/sessions/${sessionID}/files`, { body, ...options }); + } +} + +export interface FileListParams { + /** + * Directory traversal depth + */ + depth?: number; + + /** + * Directory path to list + */ + path?: string; +} + +export interface FileReadParams { + /** + * Absolute path to the file to read + */ + path: string; +} + +export interface FileWriteParams { + /** + * Base64 encoded file content + */ + content: string; + + /** + * Absolute path where the file should be written + */ + path: string; +} + +export declare namespace Files { + export { + type FileListParams as FileListParams, + type FileReadParams as FileReadParams, + type FileWriteParams as FileWriteParams, + }; +} diff --git a/src/resources/sandbox/sessions/index.ts b/src/resources/sandbox/sessions/index.ts new file mode 100644 index 0000000..6e6581f --- /dev/null +++ b/src/resources/sandbox/sessions/index.ts @@ -0,0 +1,8 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +export { Execute, type ExecuteCreateParams } from './execute'; +export { Files, type FileListParams, type FileReadParams, type FileWriteParams } from './files'; +export { Pause } from './pause'; +export { Processes, type ProcessDeleteParams, type ProcessGetParams } from './processes'; +export { Resume, type ResumeCreateParams } from './resume'; +export { Sessions, type SessionCreateParams } from './sessions'; diff --git a/src/resources/sandbox/sessions/pause.ts b/src/resources/sandbox/sessions/pause.ts new file mode 100644 index 0000000..4bd93d8 --- /dev/null +++ b/src/resources/sandbox/sessions/pause.ts @@ -0,0 +1,16 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../core/resource'; +import * as Shared from '../../shared'; +import { APIPromise } from '../../../core/api-promise'; +import { RequestOptions } from '../../../internal/request-options'; +import { path } from '../../../internal/utils/path'; + +export class Pause extends APIResource { + /** + * Pause the sandbox and snapshot its state to S3 for later resumption. + */ + create(sessionID: string, options?: RequestOptions): APIPromise { + return this._client.post(path`/v1/sandbox/sessions/${sessionID}/pause`, options); + } +} diff --git a/src/resources/sandbox/sessions/processes.ts b/src/resources/sandbox/sessions/processes.ts new file mode 100644 index 0000000..e25acd6 --- /dev/null +++ b/src/resources/sandbox/sessions/processes.ts @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../core/resource'; +import * as Shared from '../../shared'; +import { APIPromise } from '../../../core/api-promise'; +import { buildHeaders } from '../../../internal/headers'; +import { RequestOptions } from '../../../internal/request-options'; +import { path } from '../../../internal/utils/path'; + +export class Processes extends APIResource { + /** + * List all running processes in the sandbox session. + */ + list(sessionID: string, options?: RequestOptions): APIPromise { + return this._client.get(path`/v1/sandbox/sessions/${sessionID}/processes`, options); + } + + /** + * Kill a running process in the sandbox session. + */ + delete(pid: number, params: ProcessDeleteParams, options?: RequestOptions): APIPromise { + const { session_id } = params; + return this._client.delete(path`/v1/sandbox/sessions/${session_id}/processes/${pid}`, { + ...options, + headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), + }); + } + + /** + * Get details of a specific process in the sandbox session. + */ + get(pid: number, params: ProcessGetParams, options?: RequestOptions): APIPromise { + const { session_id } = params; + return this._client.get(path`/v1/sandbox/sessions/${session_id}/processes/${pid}`, options); + } +} + +export interface ProcessDeleteParams { + /** + * The unique identifier of the sandbox session + */ + session_id: string; +} + +export interface ProcessGetParams { + /** + * The unique identifier of the sandbox session + */ + session_id: string; +} + +export declare namespace Processes { + export { type ProcessDeleteParams as ProcessDeleteParams, type ProcessGetParams as ProcessGetParams }; +} diff --git a/src/resources/sandbox/sessions/resume.ts b/src/resources/sandbox/sessions/resume.ts new file mode 100644 index 0000000..517bee7 --- /dev/null +++ b/src/resources/sandbox/sessions/resume.ts @@ -0,0 +1,31 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../core/resource'; +import * as Shared from '../../shared'; +import { APIPromise } from '../../../core/api-promise'; +import { RequestOptions } from '../../../internal/request-options'; +import { path } from '../../../internal/utils/path'; + +export class Resume extends APIResource { + /** + * Resume a paused sandbox session from its S3 snapshot. + */ + create( + sessionID: string, + body: ResumeCreateParams | null | undefined = {}, + options?: RequestOptions, + ): APIPromise { + return this._client.post(path`/v1/sandbox/sessions/${sessionID}/resume`, { body, ...options }); + } +} + +export interface ResumeCreateParams { + /** + * Override network setting when resuming + */ + network_enabled?: boolean; +} + +export declare namespace Resume { + export { type ResumeCreateParams as ResumeCreateParams }; +} diff --git a/src/resources/sandbox/sessions/sessions.ts b/src/resources/sandbox/sessions/sessions.ts new file mode 100644 index 0000000..4a38291 --- /dev/null +++ b/src/resources/sandbox/sessions/sessions.ts @@ -0,0 +1,89 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import { APIResource } from '../../../core/resource'; +import * as Shared from '../../shared'; +import * as ExecuteAPI from './execute'; +import { Execute, ExecuteCreateParams } from './execute'; +import * as FilesAPI from './files'; +import { FileListParams, FileReadParams, FileWriteParams, Files } from './files'; +import * as PauseAPI from './pause'; +import { Pause } from './pause'; +import * as ProcessesAPI from './processes'; +import { ProcessDeleteParams, ProcessGetParams, Processes } from './processes'; +import * as ResumeAPI from './resume'; +import { Resume, ResumeCreateParams } from './resume'; +import { APIPromise } from '../../../core/api-promise'; +import { buildHeaders } from '../../../internal/headers'; +import { RequestOptions } from '../../../internal/request-options'; +import { path } from '../../../internal/utils/path'; + +export class Sessions extends APIResource { + execute: ExecuteAPI.Execute = new ExecuteAPI.Execute(this._client); + pause: PauseAPI.Pause = new PauseAPI.Pause(this._client); + resume: ResumeAPI.Resume = new ResumeAPI.Resume(this._client); + files: FilesAPI.Files = new FilesAPI.Files(this._client); + processes: ProcessesAPI.Processes = new ProcessesAPI.Processes(this._client); + + /** + * Create a new isolated sandbox environment for code execution. + */ + create( + body: SessionCreateParams | null | undefined = {}, + options?: RequestOptions, + ): APIPromise { + return this._client.post('/v1/sandbox/sessions', { body, ...options }); + } + + /** + * Terminate and clean up a sandbox session. + */ + delete(sessionID: string, options?: RequestOptions): APIPromise { + return this._client.delete(path`/v1/sandbox/sessions/${sessionID}`, { + ...options, + headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), + }); + } + + /** + * Retrieve the current status of a sandbox session. + */ + get(sessionID: string, options?: RequestOptions): APIPromise { + return this._client.get(path`/v1/sandbox/sessions/${sessionID}`, options); + } +} + +export interface SessionCreateParams { + /** + * Enable network access in the sandbox + */ + network_enabled?: boolean; +} + +Sessions.Execute = Execute; +Sessions.Pause = Pause; +Sessions.Resume = Resume; +Sessions.Files = Files; +Sessions.Processes = Processes; + +export declare namespace Sessions { + export { type SessionCreateParams as SessionCreateParams }; + + export { Execute as Execute, type ExecuteCreateParams as ExecuteCreateParams }; + + export { Pause as Pause }; + + export { Resume as Resume, type ResumeCreateParams as ResumeCreateParams }; + + export { + Files as Files, + type FileListParams as FileListParams, + type FileReadParams as FileReadParams, + type FileWriteParams as FileWriteParams, + }; + + export { + Processes as Processes, + type ProcessDeleteParams as ProcessDeleteParams, + type ProcessGetParams as ProcessGetParams, + }; +} diff --git a/src/resources/shared.ts b/src/resources/shared.ts index 676b664..d1b11df 100644 --- a/src/resources/shared.ts +++ b/src/resources/shared.ts @@ -16,6 +16,21 @@ export interface APIPublicSearchResult { source?: 'web' | 'attachment'; } +/** + * Response containing browser session details + */ +export interface BrowserSessionResponse { + /** + * Unique identifier for the browser session + */ + session_id?: string; + + /** + * Current status of the session + */ + status?: 'running' | 'stopped'; +} + export interface ChatMessageInput { content: | string @@ -412,6 +427,90 @@ export namespace EmbeddingsUsage { } } +/** + * Response from code execution + */ +export interface ExecuteCodeResponse { + /** + * Error message if execution failed + */ + error?: string; + + /** + * Time taken to execute the code in milliseconds + */ + execution_time_ms?: number; + + /** + * Process exit code (0 for success) + */ + exit_code?: number; + + /** + * Whether this was a background execution + */ + is_background?: boolean; + + /** + * Structured output from the execution + */ + output?: Array; + + /** + * PID of the background process (only for background execution) + */ + process_id?: number; + + /** + * Standard error from the execution + */ + stderr?: string; + + /** + * Standard output from the execution + */ + stdout?: string; + + /** + * Whether the execution completed successfully + */ + success?: boolean; +} + +export namespace ExecuteCodeResponse { + export interface Output { + /** + * Output content + */ + content?: string; + + /** + * Output type (stdout, stderr) + */ + type?: string; + } +} + +/** + * A file or directory entry + */ +export interface FileEntry { + /** + * Absolute path of the entry + */ + path?: string; + + /** + * Size in bytes (0 for directories) + */ + size?: number; + + /** + * Entry type + */ + type?: 'file' | 'directory'; +} + /** * Defines a JSON schema for structured output validation */ @@ -437,6 +536,116 @@ export interface JsonSchemaFormat { strict?: boolean; } +/** + * Response containing directory listing + */ +export interface ListFilesResponse { + /** + * List of file and directory entries + */ + entries?: Array; +} + +/** + * Response containing list of running processes + */ +export interface ListProcessesResponse { + /** + * List of running processes + */ + processes?: Array; +} + +/** + * Response containing list of modified files since session start + */ +export interface ModifiedFilesResponse { + /** + * List of modified file paths + */ + files?: Array; +} + +/** + * Response from pausing a sandbox session + */ +export interface PauseSandboxResponse { + /** + * Number of files in the snapshot + */ + file_count?: number; + + /** + * List of files included in the snapshot + */ + file_list?: Array; + + /** + * S3 bucket containing the snapshot + */ + s3_bucket?: string; + + /** + * S3 object key for the snapshot + */ + s3_key?: string; + + /** + * Whether the snapshot was uploaded to S3 + */ + s3_uploaded?: boolean; + + /** + * Whether the pause was successful + */ + success?: boolean; + + /** + * Size of the snapshot in bytes + */ + tarball_size?: number; +} + +/** + * Information about a running process + */ +export interface ProcessInfo { + /** + * Command that started the process + */ + command?: string; + + /** + * Process ID + */ + pid?: number; + + /** + * Current status of the process + */ + status?: string; +} + +/** + * Response containing file content + */ +export interface ReadFileResponse { + /** + * Base64 encoded file content + */ + content?: string; + + /** + * Path of the file + */ + path?: string; + + /** + * File size in bytes + */ + size?: number; +} + /** * Specifies the desired output format for the model response */ @@ -452,6 +661,31 @@ export interface ResponseFormat { json_schema?: JsonSchemaFormat; } +/** + * Response containing sandbox session details + */ +export interface SandboxSessionResponse { + /** + * URL endpoint for executing code in this session + */ + execute_url?: string; + + /** + * Whether network access is enabled + */ + network_enabled?: boolean; + + /** + * Unique identifier for the sandbox session + */ + session_id?: string; + + /** + * Current status of the session + */ + status?: 'running' | 'pending' | 'failed' | 'succeeded' | 'unknown' | 'paused'; +} + /** * A single search result used in LLM responses */ @@ -531,3 +765,18 @@ export interface WebSearchOptions { user_location?: UserLocation | null; } + +/** + * Response from writing a file + */ +export interface WriteFileResponse { + /** + * Path where the file was written + */ + path?: string; + + /** + * Whether the file was written successfully + */ + success?: boolean; +} diff --git a/src/version.ts b/src/version.ts index 4931d4f..aa25151 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.25.0'; // x-release-please-version +export const VERSION = '0.26.0'; // x-release-please-version diff --git a/tests/api-resources/browser/sessions.test.ts b/tests/api-resources/browser/sessions.test.ts new file mode 100644 index 0000000..a8de3fb --- /dev/null +++ b/tests/api-resources/browser/sessions.test.ts @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource sessions', () => { + // Prism tests are disabled + test.skip('create', async () => { + const responsePromise = client.browser.sessions.create(); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('create: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(client.browser.sessions.create({}, { path: '/_stainless_unknown_path' })).rejects.toThrow( + Perplexity.NotFoundError, + ); + }); + + // Prism tests are disabled + test.skip('delete', async () => { + const responsePromise = client.browser.sessions.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); +}); diff --git a/tests/api-resources/sandbox/sessions/execute.test.ts b/tests/api-resources/sandbox/sessions/execute.test.ts new file mode 100644 index 0000000..3dfe63b --- /dev/null +++ b/tests/api-resources/sandbox/sessions/execute.test.ts @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource execute', () => { + // Prism tests are disabled + test.skip('create: only required params', async () => { + const responsePromise = client.sandbox.sessions.execute.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + code: 'code', + language: 'python', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('create: required and optional params', async () => { + const response = await client.sandbox.sessions.execute.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + code: 'code', + language: 'python', + background: true, + execution_timeout: 1, + }); + }); +}); diff --git a/tests/api-resources/sandbox/sessions/files.test.ts b/tests/api-resources/sandbox/sessions/files.test.ts new file mode 100644 index 0000000..efbdc8e --- /dev/null +++ b/tests/api-resources/sandbox/sessions/files.test.ts @@ -0,0 +1,90 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource files', () => { + // Prism tests are disabled + test.skip('list', async () => { + const responsePromise = client.sandbox.sessions.files.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('list: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.sandbox.sessions.files.list( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { depth: 1, path: 'path' }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Perplexity.NotFoundError); + }); + + // Prism tests are disabled + test.skip('modified', async () => { + const responsePromise = client.sandbox.sessions.files.modified('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('read: only required params', async () => { + const responsePromise = client.sandbox.sessions.files.read('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + path: 'path', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('read: required and optional params', async () => { + const response = await client.sandbox.sessions.files.read('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + path: 'path', + }); + }); + + // Prism tests are disabled + test.skip('write: only required params', async () => { + const responsePromise = client.sandbox.sessions.files.write('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + content: 'content', + path: 'path', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('write: required and optional params', async () => { + const response = await client.sandbox.sessions.files.write('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + content: 'content', + path: 'path', + }); + }); +}); diff --git a/tests/api-resources/sandbox/sessions/pause.test.ts b/tests/api-resources/sandbox/sessions/pause.test.ts new file mode 100644 index 0000000..901bf12 --- /dev/null +++ b/tests/api-resources/sandbox/sessions/pause.test.ts @@ -0,0 +1,22 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource pause', () => { + // Prism tests are disabled + test.skip('create', async () => { + const responsePromise = client.sandbox.sessions.pause.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); +}); diff --git a/tests/api-resources/sandbox/sessions/processes.test.ts b/tests/api-resources/sandbox/sessions/processes.test.ts new file mode 100644 index 0000000..6d97b31 --- /dev/null +++ b/tests/api-resources/sandbox/sessions/processes.test.ts @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource processes', () => { + // Prism tests are disabled + test.skip('list', async () => { + const responsePromise = client.sandbox.sessions.processes.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('delete: only required params', async () => { + const responsePromise = client.sandbox.sessions.processes.delete(0, { + session_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('delete: required and optional params', async () => { + const response = await client.sandbox.sessions.processes.delete(0, { + session_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + }); + }); + + // Prism tests are disabled + test.skip('get: only required params', async () => { + const responsePromise = client.sandbox.sessions.processes.get(0, { + session_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + }); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('get: required and optional params', async () => { + const response = await client.sandbox.sessions.processes.get(0, { + session_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + }); + }); +}); diff --git a/tests/api-resources/sandbox/sessions/resume.test.ts b/tests/api-resources/sandbox/sessions/resume.test.ts new file mode 100644 index 0000000..34f95f3 --- /dev/null +++ b/tests/api-resources/sandbox/sessions/resume.test.ts @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource resume', () => { + // Prism tests are disabled + test.skip('create', async () => { + const responsePromise = client.sandbox.sessions.resume.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('create: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.sandbox.sessions.resume.create( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { network_enabled: true }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Perplexity.NotFoundError); + }); +}); diff --git a/tests/api-resources/sandbox/sessions/sessions.test.ts b/tests/api-resources/sandbox/sessions/sessions.test.ts new file mode 100644 index 0000000..d933a87 --- /dev/null +++ b/tests/api-resources/sandbox/sessions/sessions.test.ts @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +import Perplexity from '@perplexity-ai/perplexity_ai'; + +const client = new Perplexity({ + apiKey: 'My API Key', + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', +}); + +describe('resource sessions', () => { + // Prism tests are disabled + test.skip('create', async () => { + const responsePromise = client.sandbox.sessions.create(); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('create: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.sandbox.sessions.create({ network_enabled: true }, { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(Perplexity.NotFoundError); + }); + + // Prism tests are disabled + test.skip('delete', async () => { + const responsePromise = client.sandbox.sessions.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + // Prism tests are disabled + test.skip('get', async () => { + const responsePromise = client.sandbox.sessions.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); +});