threads.mjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. import { APIResource } from "../../../core/resource.mjs";
  3. import { ConversationCursorPage, } from "../../../core/pagination.mjs";
  4. import { buildHeaders } from "../../../internal/headers.mjs";
  5. import { path } from "../../../internal/utils/path.mjs";
  6. export class Threads extends APIResource {
  7. /**
  8. * Retrieve a ChatKit thread
  9. *
  10. * @example
  11. * ```ts
  12. * const chatkitThread =
  13. * await client.beta.chatkit.threads.retrieve('cthr_123');
  14. * ```
  15. */
  16. retrieve(threadID, options) {
  17. return this._client.get(path `/chatkit/threads/${threadID}`, {
  18. ...options,
  19. headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
  20. });
  21. }
  22. /**
  23. * List ChatKit threads
  24. *
  25. * @example
  26. * ```ts
  27. * // Automatically fetches more pages as needed.
  28. * for await (const chatkitThread of client.beta.chatkit.threads.list()) {
  29. * // ...
  30. * }
  31. * ```
  32. */
  33. list(query = {}, options) {
  34. return this._client.getAPIList('/chatkit/threads', (ConversationCursorPage), {
  35. query,
  36. ...options,
  37. headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
  38. });
  39. }
  40. /**
  41. * Delete a ChatKit thread
  42. *
  43. * @example
  44. * ```ts
  45. * const thread = await client.beta.chatkit.threads.delete(
  46. * 'cthr_123',
  47. * );
  48. * ```
  49. */
  50. delete(threadID, options) {
  51. return this._client.delete(path `/chatkit/threads/${threadID}`, {
  52. ...options,
  53. headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
  54. });
  55. }
  56. /**
  57. * List ChatKit thread items
  58. *
  59. * @example
  60. * ```ts
  61. * // Automatically fetches more pages as needed.
  62. * for await (const thread of client.beta.chatkit.threads.listItems(
  63. * 'cthr_123',
  64. * )) {
  65. * // ...
  66. * }
  67. * ```
  68. */
  69. listItems(threadID, query = {}, options) {
  70. return this._client.getAPIList(path `/chatkit/threads/${threadID}/items`, (ConversationCursorPage), { query, ...options, headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]) });
  71. }
  72. }
  73. //# sourceMappingURL=threads.mjs.map