session.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. import { APIResource } from '../core/resource';
  3. import * as SessionAPI from './session';
  4. import * as Shared from './shared';
  5. import { APIPromise } from '../core/api-promise';
  6. import { RequestOptions } from '../internal/request-options';
  7. import { path } from '../internal/utils/path';
  8. export class SessionResource extends APIResource {
  9. /**
  10. * Create a new session
  11. */
  12. create(options?: RequestOptions): APIPromise<Session> {
  13. return this._client.post('/session', options);
  14. }
  15. /**
  16. * List all sessions
  17. */
  18. list(options?: RequestOptions): APIPromise<SessionListResponse> {
  19. return this._client.get('/session', options);
  20. }
  21. /**
  22. * Delete a session and all its data
  23. */
  24. delete(id: string, options?: RequestOptions): APIPromise<SessionDeleteResponse> {
  25. return this._client.delete(path`/session/${id}`, options);
  26. }
  27. /**
  28. * Abort a session
  29. */
  30. abort(id: string, options?: RequestOptions): APIPromise<SessionAbortResponse> {
  31. return this._client.post(path`/session/${id}/abort`, options);
  32. }
  33. /**
  34. * Create and send a new message to a session
  35. */
  36. chat(id: string, body: SessionChatParams, options?: RequestOptions): APIPromise<AssistantMessage> {
  37. return this._client.post(path`/session/${id}/message`, { body, ...options });
  38. }
  39. /**
  40. * Analyze the app and create an AGENTS.md file
  41. */
  42. init(id: string, body: SessionInitParams, options?: RequestOptions): APIPromise<SessionInitResponse> {
  43. return this._client.post(path`/session/${id}/init`, { body, ...options });
  44. }
  45. /**
  46. * List messages for a session
  47. */
  48. messages(id: string, options?: RequestOptions): APIPromise<SessionMessagesResponse> {
  49. return this._client.get(path`/session/${id}/message`, options);
  50. }
  51. /**
  52. * Revert a message
  53. */
  54. revert(id: string, body: SessionRevertParams, options?: RequestOptions): APIPromise<Session> {
  55. return this._client.post(path`/session/${id}/revert`, { body, ...options });
  56. }
  57. /**
  58. * Share a session
  59. */
  60. share(id: string, options?: RequestOptions): APIPromise<Session> {
  61. return this._client.post(path`/session/${id}/share`, options);
  62. }
  63. /**
  64. * Summarize the session
  65. */
  66. summarize(
  67. id: string,
  68. body: SessionSummarizeParams,
  69. options?: RequestOptions,
  70. ): APIPromise<SessionSummarizeResponse> {
  71. return this._client.post(path`/session/${id}/summarize`, { body, ...options });
  72. }
  73. /**
  74. * Restore all reverted messages
  75. */
  76. unrevert(id: string, options?: RequestOptions): APIPromise<Session> {
  77. return this._client.post(path`/session/${id}/unrevert`, options);
  78. }
  79. /**
  80. * Unshare the session
  81. */
  82. unshare(id: string, options?: RequestOptions): APIPromise<Session> {
  83. return this._client.delete(path`/session/${id}/share`, options);
  84. }
  85. }
  86. export interface AssistantMessage {
  87. id: string;
  88. cost: number;
  89. mode: string;
  90. modelID: string;
  91. path: AssistantMessage.Path;
  92. providerID: string;
  93. role: 'assistant';
  94. sessionID: string;
  95. system: Array<string>;
  96. time: AssistantMessage.Time;
  97. tokens: AssistantMessage.Tokens;
  98. error?:
  99. | Shared.ProviderAuthError
  100. | Shared.UnknownError
  101. | AssistantMessage.MessageOutputLengthError
  102. | Shared.MessageAbortedError;
  103. summary?: boolean;
  104. }
  105. export namespace AssistantMessage {
  106. export interface Path {
  107. cwd: string;
  108. root: string;
  109. }
  110. export interface Time {
  111. created: number;
  112. completed?: number;
  113. }
  114. export interface Tokens {
  115. cache: Tokens.Cache;
  116. input: number;
  117. output: number;
  118. reasoning: number;
  119. }
  120. export namespace Tokens {
  121. export interface Cache {
  122. read: number;
  123. write: number;
  124. }
  125. }
  126. export interface MessageOutputLengthError {
  127. data: unknown;
  128. name: 'MessageOutputLengthError';
  129. }
  130. }
  131. export interface FilePart {
  132. id: string;
  133. messageID: string;
  134. mime: string;
  135. sessionID: string;
  136. type: 'file';
  137. url: string;
  138. filename?: string;
  139. source?: FilePartSource;
  140. }
  141. export interface FilePartInput {
  142. mime: string;
  143. type: 'file';
  144. url: string;
  145. id?: string;
  146. filename?: string;
  147. source?: FilePartSource;
  148. }
  149. export type FilePartSource = FileSource | SymbolSource;
  150. export interface FilePartSourceText {
  151. end: number;
  152. start: number;
  153. value: string;
  154. }
  155. export interface FileSource {
  156. path: string;
  157. text: FilePartSourceText;
  158. type: 'file';
  159. }
  160. export type Message = UserMessage | AssistantMessage;
  161. export type Part =
  162. | TextPart
  163. | FilePart
  164. | ToolPart
  165. | StepStartPart
  166. | StepFinishPart
  167. | SnapshotPart
  168. | Part.PatchPart;
  169. export namespace Part {
  170. export interface PatchPart {
  171. id: string;
  172. files: Array<string>;
  173. hash: string;
  174. messageID: string;
  175. sessionID: string;
  176. type: 'patch';
  177. }
  178. }
  179. export interface Session {
  180. id: string;
  181. time: Session.Time;
  182. title: string;
  183. version: string;
  184. parentID?: string;
  185. revert?: Session.Revert;
  186. share?: Session.Share;
  187. }
  188. export namespace Session {
  189. export interface Time {
  190. created: number;
  191. updated: number;
  192. }
  193. export interface Revert {
  194. messageID: string;
  195. partID?: string;
  196. snapshot?: string;
  197. }
  198. export interface Share {
  199. url: string;
  200. }
  201. }
  202. export interface SnapshotPart {
  203. id: string;
  204. messageID: string;
  205. sessionID: string;
  206. snapshot: string;
  207. type: 'snapshot';
  208. }
  209. export interface StepFinishPart {
  210. id: string;
  211. cost: number;
  212. messageID: string;
  213. sessionID: string;
  214. tokens: StepFinishPart.Tokens;
  215. type: 'step-finish';
  216. }
  217. export namespace StepFinishPart {
  218. export interface Tokens {
  219. cache: Tokens.Cache;
  220. input: number;
  221. output: number;
  222. reasoning: number;
  223. }
  224. export namespace Tokens {
  225. export interface Cache {
  226. read: number;
  227. write: number;
  228. }
  229. }
  230. }
  231. export interface StepStartPart {
  232. id: string;
  233. messageID: string;
  234. sessionID: string;
  235. type: 'step-start';
  236. }
  237. export interface SymbolSource {
  238. kind: number;
  239. name: string;
  240. path: string;
  241. range: SymbolSource.Range;
  242. text: FilePartSourceText;
  243. type: 'symbol';
  244. }
  245. export namespace SymbolSource {
  246. export interface Range {
  247. end: Range.End;
  248. start: Range.Start;
  249. }
  250. export namespace Range {
  251. export interface End {
  252. character: number;
  253. line: number;
  254. }
  255. export interface Start {
  256. character: number;
  257. line: number;
  258. }
  259. }
  260. }
  261. export interface TextPart {
  262. id: string;
  263. messageID: string;
  264. sessionID: string;
  265. text: string;
  266. type: 'text';
  267. synthetic?: boolean;
  268. time?: TextPart.Time;
  269. }
  270. export namespace TextPart {
  271. export interface Time {
  272. start: number;
  273. end?: number;
  274. }
  275. }
  276. export interface TextPartInput {
  277. text: string;
  278. type: 'text';
  279. id?: string;
  280. synthetic?: boolean;
  281. time?: TextPartInput.Time;
  282. }
  283. export namespace TextPartInput {
  284. export interface Time {
  285. start: number;
  286. end?: number;
  287. }
  288. }
  289. export interface ToolPart {
  290. id: string;
  291. callID: string;
  292. messageID: string;
  293. sessionID: string;
  294. state: ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError;
  295. tool: string;
  296. type: 'tool';
  297. }
  298. export interface ToolStateCompleted {
  299. input: { [key: string]: unknown };
  300. metadata: { [key: string]: unknown };
  301. output: string;
  302. status: 'completed';
  303. time: ToolStateCompleted.Time;
  304. title: string;
  305. }
  306. export namespace ToolStateCompleted {
  307. export interface Time {
  308. end: number;
  309. start: number;
  310. }
  311. }
  312. export interface ToolStateError {
  313. error: string;
  314. input: { [key: string]: unknown };
  315. status: 'error';
  316. time: ToolStateError.Time;
  317. }
  318. export namespace ToolStateError {
  319. export interface Time {
  320. end: number;
  321. start: number;
  322. }
  323. }
  324. export interface ToolStatePending {
  325. status: 'pending';
  326. }
  327. export interface ToolStateRunning {
  328. status: 'running';
  329. time: ToolStateRunning.Time;
  330. input?: unknown;
  331. metadata?: { [key: string]: unknown };
  332. title?: string;
  333. }
  334. export namespace ToolStateRunning {
  335. export interface Time {
  336. start: number;
  337. }
  338. }
  339. export interface UserMessage {
  340. id: string;
  341. role: 'user';
  342. sessionID: string;
  343. time: UserMessage.Time;
  344. }
  345. export namespace UserMessage {
  346. export interface Time {
  347. created: number;
  348. }
  349. }
  350. export type SessionListResponse = Array<Session>;
  351. export type SessionDeleteResponse = boolean;
  352. export type SessionAbortResponse = boolean;
  353. export type SessionInitResponse = boolean;
  354. export type SessionMessagesResponse = Array<SessionMessagesResponse.SessionMessagesResponseItem>;
  355. export namespace SessionMessagesResponse {
  356. export interface SessionMessagesResponseItem {
  357. info: SessionAPI.Message;
  358. parts: Array<SessionAPI.Part>;
  359. }
  360. }
  361. export type SessionSummarizeResponse = boolean;
  362. export interface SessionChatParams {
  363. modelID: string;
  364. parts: Array<TextPartInput | FilePartInput>;
  365. providerID: string;
  366. messageID?: string;
  367. mode?: string;
  368. tools?: { [key: string]: boolean };
  369. }
  370. export interface SessionInitParams {
  371. messageID: string;
  372. modelID: string;
  373. providerID: string;
  374. }
  375. export interface SessionRevertParams {
  376. messageID: string;
  377. partID?: string;
  378. }
  379. export interface SessionSummarizeParams {
  380. modelID: string;
  381. providerID: string;
  382. }
  383. export declare namespace SessionResource {
  384. export {
  385. type AssistantMessage as AssistantMessage,
  386. type FilePart as FilePart,
  387. type FilePartInput as FilePartInput,
  388. type FilePartSource as FilePartSource,
  389. type FilePartSourceText as FilePartSourceText,
  390. type FileSource as FileSource,
  391. type Message as Message,
  392. type Part as Part,
  393. type Session as Session,
  394. type SnapshotPart as SnapshotPart,
  395. type StepFinishPart as StepFinishPart,
  396. type StepStartPart as StepStartPart,
  397. type SymbolSource as SymbolSource,
  398. type TextPart as TextPart,
  399. type TextPartInput as TextPartInput,
  400. type ToolPart as ToolPart,
  401. type ToolStateCompleted as ToolStateCompleted,
  402. type ToolStateError as ToolStateError,
  403. type ToolStatePending as ToolStatePending,
  404. type ToolStateRunning as ToolStateRunning,
  405. type UserMessage as UserMessage,
  406. type SessionListResponse as SessionListResponse,
  407. type SessionDeleteResponse as SessionDeleteResponse,
  408. type SessionAbortResponse as SessionAbortResponse,
  409. type SessionInitResponse as SessionInitResponse,
  410. type SessionMessagesResponse as SessionMessagesResponse,
  411. type SessionSummarizeResponse as SessionSummarizeResponse,
  412. type SessionChatParams as SessionChatParams,
  413. type SessionInitParams as SessionInitParams,
  414. type SessionRevertParams as SessionRevertParams,
  415. type SessionSummarizeParams as SessionSummarizeParams,
  416. };
  417. }