| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
- import { APIResource } from '../core/resource';
- import * as SessionAPI from './session';
- 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 SessionResource extends APIResource {
- /**
- * Create a new session
- */
- create(options?: RequestOptions): APIPromise<Session> {
- return this._client.post('/session', options);
- }
- /**
- * List all sessions
- */
- list(options?: RequestOptions): APIPromise<SessionListResponse> {
- return this._client.get('/session', options);
- }
- /**
- * Delete a session and all its data
- */
- delete(id: string, options?: RequestOptions): APIPromise<SessionDeleteResponse> {
- return this._client.delete(path`/session/${id}`, options);
- }
- /**
- * Abort a session
- */
- abort(id: string, options?: RequestOptions): APIPromise<SessionAbortResponse> {
- return this._client.post(path`/session/${id}/abort`, options);
- }
- /**
- * Create and send a new message to a session
- */
- chat(id: string, body: SessionChatParams, options?: RequestOptions): APIPromise<AssistantMessage> {
- return this._client.post(path`/session/${id}/message`, { body, ...options });
- }
- /**
- * Analyze the app and create an AGENTS.md file
- */
- init(id: string, body: SessionInitParams, options?: RequestOptions): APIPromise<SessionInitResponse> {
- return this._client.post(path`/session/${id}/init`, { body, ...options });
- }
- /**
- * List messages for a session
- */
- messages(id: string, options?: RequestOptions): APIPromise<SessionMessagesResponse> {
- return this._client.get(path`/session/${id}/message`, options);
- }
- /**
- * Revert a message
- */
- revert(id: string, body: SessionRevertParams, options?: RequestOptions): APIPromise<Session> {
- return this._client.post(path`/session/${id}/revert`, { body, ...options });
- }
- /**
- * Share a session
- */
- share(id: string, options?: RequestOptions): APIPromise<Session> {
- return this._client.post(path`/session/${id}/share`, options);
- }
- /**
- * Summarize the session
- */
- summarize(
- id: string,
- body: SessionSummarizeParams,
- options?: RequestOptions,
- ): APIPromise<SessionSummarizeResponse> {
- return this._client.post(path`/session/${id}/summarize`, { body, ...options });
- }
- /**
- * Restore all reverted messages
- */
- unrevert(id: string, options?: RequestOptions): APIPromise<Session> {
- return this._client.post(path`/session/${id}/unrevert`, options);
- }
- /**
- * Unshare the session
- */
- unshare(id: string, options?: RequestOptions): APIPromise<Session> {
- return this._client.delete(path`/session/${id}/share`, options);
- }
- }
- export interface AssistantMessage {
- id: string;
- cost: number;
- mode: string;
- modelID: string;
- path: AssistantMessage.Path;
- providerID: string;
- role: 'assistant';
- sessionID: string;
- system: Array<string>;
- time: AssistantMessage.Time;
- tokens: AssistantMessage.Tokens;
- error?:
- | Shared.ProviderAuthError
- | Shared.UnknownError
- | AssistantMessage.MessageOutputLengthError
- | Shared.MessageAbortedError;
- summary?: boolean;
- }
- export namespace AssistantMessage {
- export interface Path {
- cwd: string;
- root: string;
- }
- export interface Time {
- created: number;
- completed?: number;
- }
- export interface Tokens {
- cache: Tokens.Cache;
- input: number;
- output: number;
- reasoning: number;
- }
- export namespace Tokens {
- export interface Cache {
- read: number;
- write: number;
- }
- }
- export interface MessageOutputLengthError {
- data: unknown;
- name: 'MessageOutputLengthError';
- }
- }
- export interface FilePart {
- id: string;
- messageID: string;
- mime: string;
- sessionID: string;
- type: 'file';
- url: string;
- filename?: string;
- source?: FilePartSource;
- }
- export interface FilePartInput {
- mime: string;
- type: 'file';
- url: string;
- id?: string;
- filename?: string;
- source?: FilePartSource;
- }
- export type FilePartSource = FileSource | SymbolSource;
- export interface FilePartSourceText {
- end: number;
- start: number;
- value: string;
- }
- export interface FileSource {
- path: string;
- text: FilePartSourceText;
- type: 'file';
- }
- export type Message = UserMessage | AssistantMessage;
- export type Part =
- | TextPart
- | FilePart
- | ToolPart
- | StepStartPart
- | StepFinishPart
- | SnapshotPart
- | Part.PatchPart;
- export namespace Part {
- export interface PatchPart {
- id: string;
- files: Array<string>;
- hash: string;
- messageID: string;
- sessionID: string;
- type: 'patch';
- }
- }
- export interface Session {
- id: string;
- time: Session.Time;
- title: string;
- version: string;
- parentID?: string;
- revert?: Session.Revert;
- share?: Session.Share;
- }
- export namespace Session {
- export interface Time {
- created: number;
- updated: number;
- }
- export interface Revert {
- messageID: string;
- partID?: string;
- snapshot?: string;
- }
- export interface Share {
- url: string;
- }
- }
- export interface SnapshotPart {
- id: string;
- messageID: string;
- sessionID: string;
- snapshot: string;
- type: 'snapshot';
- }
- export interface StepFinishPart {
- id: string;
- cost: number;
- messageID: string;
- sessionID: string;
- tokens: StepFinishPart.Tokens;
- type: 'step-finish';
- }
- export namespace StepFinishPart {
- export interface Tokens {
- cache: Tokens.Cache;
- input: number;
- output: number;
- reasoning: number;
- }
- export namespace Tokens {
- export interface Cache {
- read: number;
- write: number;
- }
- }
- }
- export interface StepStartPart {
- id: string;
- messageID: string;
- sessionID: string;
- type: 'step-start';
- }
- export interface SymbolSource {
- kind: number;
- name: string;
- path: string;
- range: SymbolSource.Range;
- text: FilePartSourceText;
- type: 'symbol';
- }
- export namespace SymbolSource {
- export interface Range {
- end: Range.End;
- start: Range.Start;
- }
- export namespace Range {
- export interface End {
- character: number;
- line: number;
- }
- export interface Start {
- character: number;
- line: number;
- }
- }
- }
- export interface TextPart {
- id: string;
- messageID: string;
- sessionID: string;
- text: string;
- type: 'text';
- synthetic?: boolean;
- time?: TextPart.Time;
- }
- export namespace TextPart {
- export interface Time {
- start: number;
- end?: number;
- }
- }
- export interface TextPartInput {
- text: string;
- type: 'text';
- id?: string;
- synthetic?: boolean;
- time?: TextPartInput.Time;
- }
- export namespace TextPartInput {
- export interface Time {
- start: number;
- end?: number;
- }
- }
- export interface ToolPart {
- id: string;
- callID: string;
- messageID: string;
- sessionID: string;
- state: ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError;
- tool: string;
- type: 'tool';
- }
- export interface ToolStateCompleted {
- input: { [key: string]: unknown };
- metadata: { [key: string]: unknown };
- output: string;
- status: 'completed';
- time: ToolStateCompleted.Time;
- title: string;
- }
- export namespace ToolStateCompleted {
- export interface Time {
- end: number;
- start: number;
- }
- }
- export interface ToolStateError {
- error: string;
- input: { [key: string]: unknown };
- status: 'error';
- time: ToolStateError.Time;
- }
- export namespace ToolStateError {
- export interface Time {
- end: number;
- start: number;
- }
- }
- export interface ToolStatePending {
- status: 'pending';
- }
- export interface ToolStateRunning {
- status: 'running';
- time: ToolStateRunning.Time;
- input?: unknown;
- metadata?: { [key: string]: unknown };
- title?: string;
- }
- export namespace ToolStateRunning {
- export interface Time {
- start: number;
- }
- }
- export interface UserMessage {
- id: string;
- role: 'user';
- sessionID: string;
- time: UserMessage.Time;
- }
- export namespace UserMessage {
- export interface Time {
- created: number;
- }
- }
- export type SessionListResponse = Array<Session>;
- export type SessionDeleteResponse = boolean;
- export type SessionAbortResponse = boolean;
- export type SessionInitResponse = boolean;
- export type SessionMessagesResponse = Array<SessionMessagesResponse.SessionMessagesResponseItem>;
- export namespace SessionMessagesResponse {
- export interface SessionMessagesResponseItem {
- info: SessionAPI.Message;
- parts: Array<SessionAPI.Part>;
- }
- }
- export type SessionSummarizeResponse = boolean;
- export interface SessionChatParams {
- modelID: string;
- parts: Array<TextPartInput | FilePartInput>;
- providerID: string;
- messageID?: string;
- mode?: string;
- tools?: { [key: string]: boolean };
- }
- export interface SessionInitParams {
- messageID: string;
- modelID: string;
- providerID: string;
- }
- export interface SessionRevertParams {
- messageID: string;
- partID?: string;
- }
- export interface SessionSummarizeParams {
- modelID: string;
- providerID: string;
- }
- export declare namespace SessionResource {
- export {
- type AssistantMessage as AssistantMessage,
- type FilePart as FilePart,
- type FilePartInput as FilePartInput,
- type FilePartSource as FilePartSource,
- type FilePartSourceText as FilePartSourceText,
- type FileSource as FileSource,
- type Message as Message,
- type Part as Part,
- type Session as Session,
- type SnapshotPart as SnapshotPart,
- type StepFinishPart as StepFinishPart,
- type StepStartPart as StepStartPart,
- type SymbolSource as SymbolSource,
- type TextPart as TextPart,
- type TextPartInput as TextPartInput,
- type ToolPart as ToolPart,
- type ToolStateCompleted as ToolStateCompleted,
- type ToolStateError as ToolStateError,
- type ToolStatePending as ToolStatePending,
- type ToolStateRunning as ToolStateRunning,
- type UserMessage as UserMessage,
- type SessionListResponse as SessionListResponse,
- type SessionDeleteResponse as SessionDeleteResponse,
- type SessionAbortResponse as SessionAbortResponse,
- type SessionInitResponse as SessionInitResponse,
- type SessionMessagesResponse as SessionMessagesResponse,
- type SessionSummarizeResponse as SessionSummarizeResponse,
- type SessionChatParams as SessionChatParams,
- type SessionInitParams as SessionInitParams,
- type SessionRevertParams as SessionRevertParams,
- type SessionSummarizeParams as SessionSummarizeParams,
- };
- }
|