diff --git a/.stats.yml b/.stats.yml index 5b8a780..7839199 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 37 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-e36029186c19d818349104455aabb7827128d0f0719e768337e9d04c17f4d676.yml +configured_endpoints: 38 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/plastic-labs%2Fhoncho-9d856cd5016ed2e3273de9ef9aaca939bc2e90a0c557ad44c808fafa928b8310.yml diff --git a/README.md b/README.md index 2d6841e..614f4d5 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,37 @@ On timeout, an `APIConnectionTimeoutError` is thrown. Note that requests which time out will be [retried twice by default](#retries). +## Auto-pagination + +List methods in the Honcho API are paginated. +You can use `for await … of` syntax to iterate through items across all pages: + +```ts +async function fetchAllAppsUsers(params) { + const allAppsUsers = []; + // Automatically fetches more pages as needed. + for await (const user of honcho.apps.users.list('REPLACE_ME')) { + allAppsUsers.push(user); + } + return allAppsUsers; +} +``` + +Alternatively, you can make request a single page at a time: + +```ts +let page = await honcho.apps.users.list('REPLACE_ME'); +for (const user of page.items) { + console.log(user); +} + +// Convenience methods are provided for manually paginating: +while (page.hasNextPage()) { + page = page.getNextPage(); + // ... +} +``` + ## Advanced Usage ### Accessing raw Response data (e.g., headers) diff --git a/api.md b/api.md index cb89643..5869281 100644 --- a/api.md +++ b/api.md @@ -22,9 +22,10 @@ Types: Methods: - client.apps.users.create(appId, { ...params }) -> User -- client.apps.users.retrieve(appId, userId) -> User - client.apps.users.update(appId, userId, { ...params }) -> User -- client.apps.users.list(appId, { ...params }) -> PageUser +- client.apps.users.list(appId, { ...params }) -> UsersPage +- client.apps.users.get(appId, userId) -> User +- client.apps.users.getByName(appId, name) -> User - client.apps.users.getOrCreate(appId, name) -> User ### Sessions @@ -35,14 +36,17 @@ Types: - PageSession - Session - SessionDeleteResponse +- SessionStreamResponse Methods: - client.apps.users.sessions.create(appId, userId, { ...params }) -> Session - client.apps.users.sessions.update(appId, userId, sessionId, { ...params }) -> Session -- client.apps.users.sessions.list(appId, userId, { ...params }) -> PageSession +- client.apps.users.sessions.list(appId, userId, { ...params }) -> SessionsPage - client.apps.users.sessions.delete(appId, userId, sessionId) -> unknown +- client.apps.users.sessions.chat(appId, userId, sessionId, { ...params }) -> AgentChat - client.apps.users.sessions.get(appId, userId, sessionId) -> Session +- client.apps.users.sessions.stream(appId, userId, sessionId, { ...params }) -> unknown #### Messages @@ -55,7 +59,7 @@ Methods: - client.apps.users.sessions.messages.create(appId, userId, sessionId, { ...params }) -> Message - client.apps.users.sessions.messages.update(appId, userId, sessionId, messageId, { ...params }) -> Message -- client.apps.users.sessions.messages.list(appId, userId, sessionId, { ...params }) -> PageMessage +- client.apps.users.sessions.messages.list(appId, userId, sessionId, { ...params }) -> MessagesPage - client.apps.users.sessions.messages.get(appId, userId, sessionId, messageId) -> Message #### Metamessages @@ -69,19 +73,9 @@ Methods: - client.apps.users.sessions.metamessages.create(appId, userId, sessionId, { ...params }) -> Metamessage - client.apps.users.sessions.metamessages.update(appId, userId, sessionId, metamessageId, { ...params }) -> Metamessage -- client.apps.users.sessions.metamessages.list(appId, userId, sessionId, { ...params }) -> PageMetamessage +- client.apps.users.sessions.metamessages.list(appId, userId, sessionId, { ...params }) -> MetamessagesPage - client.apps.users.sessions.metamessages.get(appId, userId, sessionId, metamessageId, { ...params }) -> Metamessage -#### Chat - -Types: - -- ChatStreamResponse - -Methods: - -- client.apps.users.sessions.chat.stream(appId, userId, sessionId, { ...params }) -> unknown - ### Collections Types: @@ -93,10 +87,11 @@ Types: Methods: - client.apps.users.collections.create(appId, userId, { ...params }) -> Collection -- client.apps.users.collections.retrieve(appId, userId, collectionId) -> Collection - client.apps.users.collections.update(appId, userId, collectionId, { ...params }) -> Collection -- client.apps.users.collections.list(appId, userId, { ...params }) -> PageCollection +- client.apps.users.collections.list(appId, userId, { ...params }) -> CollectionsPage - client.apps.users.collections.delete(appId, userId, collectionId) -> unknown +- client.apps.users.collections.get(appId, userId, collectionId) -> Collection +- client.apps.users.collections.getByName(appId, userId, name) -> Collection #### Documents @@ -110,7 +105,7 @@ Methods: - client.apps.users.collections.documents.create(appId, userId, collectionId, { ...params }) -> Document - client.apps.users.collections.documents.update(appId, userId, collectionId, documentId, { ...params }) -> Document -- client.apps.users.collections.documents.list(appId, userId, collectionId, { ...params }) -> PageDocument +- client.apps.users.collections.documents.list(appId, userId, collectionId, { ...params }) -> DocumentsPage - client.apps.users.collections.documents.delete(appId, userId, collectionId, documentId) -> unknown - client.apps.users.collections.documents.get(appId, userId, collectionId, documentId) -> Document diff --git a/src/resources/apps/apps.ts b/src/resources/apps/apps.ts index 90b2652..23623da 100644 --- a/src/resources/apps/apps.ts +++ b/src/resources/apps/apps.ts @@ -94,6 +94,7 @@ export namespace Apps { export import Users = UsersAPI.Users; export import PageUser = UsersAPI.PageUser; export import User = UsersAPI.User; + export import UsersPage = UsersAPI.UsersPage; export import UserCreateParams = UsersAPI.UserCreateParams; export import UserUpdateParams = UsersAPI.UserUpdateParams; export import UserListParams = UsersAPI.UserListParams; diff --git a/src/resources/apps/index.ts b/src/resources/apps/index.ts index 507b4b9..e1a9145 100644 --- a/src/resources/apps/index.ts +++ b/src/resources/apps/index.ts @@ -1,4 +1,12 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. export { App, AppCreateParams, AppUpdateParams, Apps } from './apps'; -export { PageUser, User, UserCreateParams, UserUpdateParams, UserListParams, Users } from './users/index'; +export { + PageUser, + User, + UserCreateParams, + UserUpdateParams, + UserListParams, + UsersPage, + Users, +} from './users/index'; diff --git a/src/resources/apps/users/collections/collections.ts b/src/resources/apps/users/collections/collections.ts index 5c60bb9..f873500 100644 --- a/src/resources/apps/users/collections/collections.ts +++ b/src/resources/apps/users/collections/collections.ts @@ -7,6 +7,7 @@ import * as CollectionsAPI from 'honcho/resources/apps/users/collections/collect import * as DocumentsAPI from 'honcho/resources/apps/users/collections/documents'; import * as NameAPI from 'honcho/resources/apps/users/collections/name'; import * as QueryAPI from 'honcho/resources/apps/users/collections/query'; +import { Page, type PageParams } from 'honcho/pagination'; export class Collections extends APIResource { documents: DocumentsAPI.Documents = new DocumentsAPI.Documents(this._client); @@ -25,18 +26,6 @@ export class Collections extends APIResource { return this._client.post(`/apps/${appId}/users/${userId}/collections`, { body, ...options }); } - /** - * Get Collection By Id - */ - retrieve( - appId: string, - userId: string, - collectionId: string, - options?: Core.RequestOptions, - ): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}/collections/${collectionId}`, options); - } - /** * Update Collection */ @@ -67,18 +56,25 @@ export class Collections extends APIResource { userId: string, query?: CollectionListParams, options?: Core.RequestOptions, - ): Core.APIPromise; - list(appId: string, userId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + list( + appId: string, + userId: string, + options?: Core.RequestOptions, + ): Core.PagePromise; list( appId: string, userId: string, query: CollectionListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(appId, userId, {}, query); } - return this._client.get(`/apps/${appId}/users/${userId}/collections`, { query, ...options }); + return this._client.getAPIList(`/apps/${appId}/users/${userId}/collections`, CollectionsPage, { + query, + ...options, + }); } /** @@ -92,8 +88,34 @@ export class Collections extends APIResource { ): Core.APIPromise { return this._client.delete(`/apps/${appId}/users/${userId}/collections/${collectionId}`, options); } + + /** + * Get Collection By Id + */ + get( + appId: string, + userId: string, + collectionId: string, + options?: Core.RequestOptions, + ): Core.APIPromise { + return this._client.get(`/apps/${appId}/users/${userId}/collections/${collectionId}`, options); + } + + /** + * Get Collection By Name + */ + getByName( + appId: string, + userId: string, + name: string, + options?: Core.RequestOptions, + ): Core.APIPromise { + return this._client.get(`/apps/${appId}/users/${userId}/collections/name/${name}`, options); + } } +export class CollectionsPage extends Page {} + export interface Collection { id: string; @@ -109,13 +131,13 @@ export interface Collection { export interface PageCollection { items: Array; - page: number | null; + page: number; - size: number | null; + size: number; - total: number | null; + total: number; - pages?: number | null; + pages?: number; } export type CollectionDeleteResponse = unknown; @@ -132,26 +154,17 @@ export interface CollectionUpdateParams { metadata?: unknown | null; } -export interface CollectionListParams { +export interface CollectionListParams extends PageParams { filter?: string | null; - /** - * Page number - */ - page?: number; - reverse?: boolean | null; - - /** - * Page size - */ - size?: number; } export namespace Collections { export import Collection = CollectionsAPI.Collection; export import PageCollection = CollectionsAPI.PageCollection; export import CollectionDeleteResponse = CollectionsAPI.CollectionDeleteResponse; + export import CollectionsPage = CollectionsAPI.CollectionsPage; export import CollectionCreateParams = CollectionsAPI.CollectionCreateParams; export import CollectionUpdateParams = CollectionsAPI.CollectionUpdateParams; export import CollectionListParams = CollectionsAPI.CollectionListParams; @@ -159,6 +172,7 @@ export namespace Collections { export import Document = DocumentsAPI.Document; export import PageDocument = DocumentsAPI.PageDocument; export import DocumentDeleteResponse = DocumentsAPI.DocumentDeleteResponse; + export import DocumentsPage = DocumentsAPI.DocumentsPage; export import DocumentCreateParams = DocumentsAPI.DocumentCreateParams; export import DocumentUpdateParams = DocumentsAPI.DocumentUpdateParams; export import DocumentListParams = DocumentsAPI.DocumentListParams; diff --git a/src/resources/apps/users/collections/documents.ts b/src/resources/apps/users/collections/documents.ts index 99d5322..876bad0 100644 --- a/src/resources/apps/users/collections/documents.ts +++ b/src/resources/apps/users/collections/documents.ts @@ -4,6 +4,7 @@ import * as Core from 'honcho/core'; import { APIResource } from 'honcho/resource'; import { isRequestOptions } from 'honcho/core'; import * as DocumentsAPI from 'honcho/resources/apps/users/collections/documents'; +import { Page, type PageParams } from 'honcho/pagination'; export class Documents extends APIResource { /** @@ -48,27 +49,28 @@ export class Documents extends APIResource { collectionId: string, query?: DocumentListParams, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; list( appId: string, userId: string, collectionId: string, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; list( appId: string, userId: string, collectionId: string, query: DocumentListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(appId, userId, collectionId, {}, query); } - return this._client.get(`/apps/${appId}/users/${userId}/collections/${collectionId}/documents`, { - query, - ...options, - }); + return this._client.getAPIList( + `/apps/${appId}/users/${userId}/collections/${collectionId}/documents`, + DocumentsPage, + { query, ...options }, + ); } /** @@ -104,6 +106,8 @@ export class Documents extends APIResource { } } +export class DocumentsPage extends Page {} + export interface Document { id: string; @@ -119,13 +123,13 @@ export interface Document { export interface PageDocument { items: Array; - page: number | null; + page: number; - size: number | null; + size: number; - total: number | null; + total: number; - pages?: number | null; + pages?: number; } export type DocumentDeleteResponse = unknown; @@ -142,26 +146,17 @@ export interface DocumentUpdateParams { metadata?: unknown | null; } -export interface DocumentListParams { +export interface DocumentListParams extends PageParams { filter?: string | null; - /** - * Page number - */ - page?: number; - reverse?: boolean | null; - - /** - * Page size - */ - size?: number; } export namespace Documents { export import Document = DocumentsAPI.Document; export import PageDocument = DocumentsAPI.PageDocument; export import DocumentDeleteResponse = DocumentsAPI.DocumentDeleteResponse; + export import DocumentsPage = DocumentsAPI.DocumentsPage; export import DocumentCreateParams = DocumentsAPI.DocumentCreateParams; export import DocumentUpdateParams = DocumentsAPI.DocumentUpdateParams; export import DocumentListParams = DocumentsAPI.DocumentListParams; diff --git a/src/resources/apps/users/collections/index.ts b/src/resources/apps/users/collections/index.ts index e10391b..b51f2b4 100644 --- a/src/resources/apps/users/collections/index.ts +++ b/src/resources/apps/users/collections/index.ts @@ -7,6 +7,7 @@ export { CollectionCreateParams, CollectionUpdateParams, CollectionListParams, + CollectionsPage, Collections, } from './collections'; export { @@ -16,6 +17,7 @@ export { DocumentCreateParams, DocumentUpdateParams, DocumentListParams, + DocumentsPage, Documents, } from './documents'; export { Name } from './name'; diff --git a/src/resources/apps/users/index.ts b/src/resources/apps/users/index.ts index be38e81..9185553 100644 --- a/src/resources/apps/users/index.ts +++ b/src/resources/apps/users/index.ts @@ -5,9 +5,13 @@ export { PageSession, Session, SessionDeleteResponse, + SessionStreamResponse, SessionCreateParams, SessionUpdateParams, SessionListParams, + SessionChatParams, + SessionStreamParams, + SessionsPage, Sessions, } from './sessions/index'; export { @@ -17,7 +21,16 @@ export { CollectionCreateParams, CollectionUpdateParams, CollectionListParams, + CollectionsPage, Collections, } from './collections/index'; export { Name } from './name'; -export { PageUser, User, UserCreateParams, UserUpdateParams, UserListParams, Users } from './users'; +export { + PageUser, + User, + UserCreateParams, + UserUpdateParams, + UserListParams, + UsersPage, + Users, +} from './users'; diff --git a/src/resources/apps/users/sessions/chat.ts b/src/resources/apps/users/sessions/chat.ts deleted file mode 100644 index d83fb29..0000000 --- a/src/resources/apps/users/sessions/chat.ts +++ /dev/null @@ -1,34 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import * as Core from 'honcho/core'; -import { APIResource } from 'honcho/resource'; -import * as ChatAPI from 'honcho/resources/apps/users/sessions/chat'; - -export class Chat extends APIResource { - /** - * Get Chat Stream - */ - stream( - appId: string, - userId: string, - sessionId: string, - query: ChatStreamParams, - options?: Core.RequestOptions, - ): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}/chat/stream`, { - query, - ...options, - }); - } -} - -export type ChatStreamResponse = unknown; - -export interface ChatStreamParams { - query: string; -} - -export namespace Chat { - export import ChatStreamResponse = ChatAPI.ChatStreamResponse; - export import ChatStreamParams = ChatAPI.ChatStreamParams; -} diff --git a/src/resources/apps/users/sessions/index.ts b/src/resources/apps/users/sessions/index.ts index 9a714f2..4580149 100644 --- a/src/resources/apps/users/sessions/index.ts +++ b/src/resources/apps/users/sessions/index.ts @@ -5,18 +5,22 @@ export { PageSession, Session, SessionDeleteResponse, + SessionStreamResponse, SessionCreateParams, SessionUpdateParams, SessionListParams, + SessionChatParams, + SessionStreamParams, + SessionsPage, Sessions, } from './sessions'; -export { ChatStreamResponse, ChatStreamParams, Chat } from './chat'; export { Message, PageMessage, MessageCreateParams, MessageUpdateParams, MessageListParams, + MessagesPage, Messages, } from './messages'; export { @@ -26,5 +30,6 @@ export { MetamessageUpdateParams, MetamessageListParams, MetamessageGetParams, + MetamessagesPage, Metamessages, } from './metamessages'; diff --git a/src/resources/apps/users/sessions/messages.ts b/src/resources/apps/users/sessions/messages.ts index 9a17c13..a861de9 100644 --- a/src/resources/apps/users/sessions/messages.ts +++ b/src/resources/apps/users/sessions/messages.ts @@ -4,6 +4,7 @@ import * as Core from 'honcho/core'; import { APIResource } from 'honcho/resource'; import { isRequestOptions } from 'honcho/core'; import * as MessagesAPI from 'honcho/resources/apps/users/sessions/messages'; +import { Page, type PageParams } from 'honcho/pagination'; export class Messages extends APIResource { /** @@ -67,27 +68,28 @@ export class Messages extends APIResource { sessionId: string, query?: MessageListParams, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; list( appId: string, userId: string, sessionId: string, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; list( appId: string, userId: string, sessionId: string, query: MessageListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(appId, userId, sessionId, {}, query); } - return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}/messages`, { - query, - ...options, - }); + return this._client.getAPIList( + `/apps/${appId}/users/${userId}/sessions/${sessionId}/messages`, + MessagesPage, + { query, ...options }, + ); } /** @@ -107,6 +109,8 @@ export class Messages extends APIResource { } } +export class MessagesPage extends Page {} + export interface Message { id: string; @@ -124,13 +128,13 @@ export interface Message { export interface PageMessage { items: Array; - page: number | null; + page: number; - size: number | null; + size: number; - total: number | null; + total: number; - pages?: number | null; + pages?: number; } export interface MessageCreateParams { @@ -145,25 +149,16 @@ export interface MessageUpdateParams { metadata?: unknown | null; } -export interface MessageListParams { +export interface MessageListParams extends PageParams { filter?: string | null; - /** - * Page number - */ - page?: number; - reverse?: boolean | null; - - /** - * Page size - */ - size?: number; } export namespace Messages { export import Message = MessagesAPI.Message; export import PageMessage = MessagesAPI.PageMessage; + export import MessagesPage = MessagesAPI.MessagesPage; export import MessageCreateParams = MessagesAPI.MessageCreateParams; export import MessageUpdateParams = MessagesAPI.MessageUpdateParams; export import MessageListParams = MessagesAPI.MessageListParams; diff --git a/src/resources/apps/users/sessions/metamessages.ts b/src/resources/apps/users/sessions/metamessages.ts index 6d02bc2..cfd91e4 100644 --- a/src/resources/apps/users/sessions/metamessages.ts +++ b/src/resources/apps/users/sessions/metamessages.ts @@ -4,6 +4,7 @@ import * as Core from 'honcho/core'; import { APIResource } from 'honcho/resource'; import { isRequestOptions } from 'honcho/core'; import * as MetamessagesAPI from 'honcho/resources/apps/users/sessions/metamessages'; +import { Page, type PageParams } from 'honcho/pagination'; export class Metamessages extends APIResource { /** @@ -67,27 +68,28 @@ export class Metamessages extends APIResource { sessionId: string, query?: MetamessageListParams, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; list( appId: string, userId: string, sessionId: string, options?: Core.RequestOptions, - ): Core.APIPromise; + ): Core.PagePromise; list( appId: string, userId: string, sessionId: string, query: MetamessageListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(appId, userId, sessionId, {}, query); } - return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages`, { - query, - ...options, - }); + return this._client.getAPIList( + `/apps/${appId}/users/${userId}/sessions/${sessionId}/metamessages`, + MetamessagesPage, + { query, ...options }, + ); } /** @@ -116,6 +118,8 @@ export class Metamessages extends APIResource { } } +export class MetamessagesPage extends Page {} + export interface Metamessage { id: string; @@ -133,13 +137,13 @@ export interface Metamessage { export interface PageMetamessage { items: Array; - page: number | null; + page: number; - size: number | null; + size: number; - total: number | null; + total: number; - pages?: number | null; + pages?: number; } export interface MetamessageCreateParams { @@ -160,24 +164,14 @@ export interface MetamessageUpdateParams { metamessage_type?: string | null; } -export interface MetamessageListParams { +export interface MetamessageListParams extends PageParams { filter?: string | null; message_id?: string | null; metamessage_type?: string | null; - /** - * Page number - */ - page?: number; - reverse?: boolean | null; - - /** - * Page size - */ - size?: number; } export interface MetamessageGetParams { @@ -187,6 +181,7 @@ export interface MetamessageGetParams { export namespace Metamessages { export import Metamessage = MetamessagesAPI.Metamessage; export import PageMetamessage = MetamessagesAPI.PageMetamessage; + export import MetamessagesPage = MetamessagesAPI.MetamessagesPage; export import MetamessageCreateParams = MetamessagesAPI.MetamessageCreateParams; export import MetamessageUpdateParams = MetamessagesAPI.MetamessageUpdateParams; export import MetamessageListParams = MetamessagesAPI.MetamessageListParams; diff --git a/src/resources/apps/users/sessions/sessions.ts b/src/resources/apps/users/sessions/sessions.ts index 4ecac34..4bb8ba8 100644 --- a/src/resources/apps/users/sessions/sessions.ts +++ b/src/resources/apps/users/sessions/sessions.ts @@ -4,14 +4,13 @@ import * as Core from 'honcho/core'; import { APIResource } from 'honcho/resource'; import { isRequestOptions } from 'honcho/core'; import * as SessionsAPI from 'honcho/resources/apps/users/sessions/sessions'; -import * as ChatAPI from 'honcho/resources/apps/users/sessions/chat'; import * as MessagesAPI from 'honcho/resources/apps/users/sessions/messages'; import * as MetamessagesAPI from 'honcho/resources/apps/users/sessions/metamessages'; +import { Page, type PageParams } from 'honcho/pagination'; export class Sessions extends APIResource { messages: MessagesAPI.Messages = new MessagesAPI.Messages(this._client); metamessages: MetamessagesAPI.Metamessages = new MetamessagesAPI.Metamessages(this._client); - chat: ChatAPI.Chat = new ChatAPI.Chat(this._client); /** * Create a Session for a User @@ -67,18 +66,21 @@ export class Sessions extends APIResource { userId: string, query?: SessionListParams, options?: Core.RequestOptions, - ): Core.APIPromise; - list(appId: string, userId: string, options?: Core.RequestOptions): Core.APIPromise; + ): Core.PagePromise; + list(appId: string, userId: string, options?: Core.RequestOptions): Core.PagePromise; list( appId: string, userId: string, query: SessionListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(appId, userId, {}, query); } - return this._client.get(`/apps/${appId}/users/${userId}/sessions`, { query, ...options }); + return this._client.getAPIList(`/apps/${appId}/users/${userId}/sessions`, SessionsPage, { + query, + ...options, + }); } /** @@ -101,6 +103,22 @@ export class Sessions extends APIResource { return this._client.delete(`/apps/${appId}/users/${userId}/sessions/${sessionId}`, options); } + /** + * Get Chat + */ + chat( + appId: string, + userId: string, + sessionId: string, + query: SessionChatParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}/chat`, { + query, + ...options, + }); + } + /** * Get a specific session for a user by ID * @@ -120,8 +138,26 @@ export class Sessions extends APIResource { ): Core.APIPromise { return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}`, options); } + + /** + * Get Chat Stream + */ + stream( + appId: string, + userId: string, + sessionId: string, + query: SessionStreamParams, + options?: Core.RequestOptions, + ): Core.APIPromise { + return this._client.get(`/apps/${appId}/users/${userId}/sessions/${sessionId}/chat/stream`, { + query, + ...options, + }); + } } +export class SessionsPage extends Page {} + export interface AgentChat { content: string; } @@ -129,13 +165,13 @@ export interface AgentChat { export interface PageSession { items: Array; - page: number | null; + page: number; - size: number | null; + size: number; - total: number | null; + total: number; - pages?: number | null; + pages?: number; } export interface Session { @@ -154,6 +190,8 @@ export interface Session { export type SessionDeleteResponse = unknown; +export type SessionStreamResponse = unknown; + export interface SessionCreateParams { location_id: string; @@ -164,24 +202,22 @@ export interface SessionUpdateParams { metadata?: unknown | null; } -export interface SessionListParams { +export interface SessionListParams extends PageParams { filter?: string | null; is_active?: boolean | null; location_id?: string | null; - /** - * Page number - */ - page?: number; - reverse?: boolean | null; +} - /** - * Page size - */ - size?: number; +export interface SessionChatParams { + query: string; +} + +export interface SessionStreamParams { + query: string; } export namespace Sessions { @@ -189,23 +225,26 @@ export namespace Sessions { export import PageSession = SessionsAPI.PageSession; export import Session = SessionsAPI.Session; export import SessionDeleteResponse = SessionsAPI.SessionDeleteResponse; + export import SessionStreamResponse = SessionsAPI.SessionStreamResponse; + export import SessionsPage = SessionsAPI.SessionsPage; export import SessionCreateParams = SessionsAPI.SessionCreateParams; export import SessionUpdateParams = SessionsAPI.SessionUpdateParams; export import SessionListParams = SessionsAPI.SessionListParams; + export import SessionChatParams = SessionsAPI.SessionChatParams; + export import SessionStreamParams = SessionsAPI.SessionStreamParams; export import Messages = MessagesAPI.Messages; export import Message = MessagesAPI.Message; export import PageMessage = MessagesAPI.PageMessage; + export import MessagesPage = MessagesAPI.MessagesPage; export import MessageCreateParams = MessagesAPI.MessageCreateParams; export import MessageUpdateParams = MessagesAPI.MessageUpdateParams; export import MessageListParams = MessagesAPI.MessageListParams; export import Metamessages = MetamessagesAPI.Metamessages; export import Metamessage = MetamessagesAPI.Metamessage; export import PageMetamessage = MetamessagesAPI.PageMetamessage; + export import MetamessagesPage = MetamessagesAPI.MetamessagesPage; export import MetamessageCreateParams = MetamessagesAPI.MetamessageCreateParams; export import MetamessageUpdateParams = MetamessagesAPI.MetamessageUpdateParams; export import MetamessageListParams = MetamessagesAPI.MetamessageListParams; export import MetamessageGetParams = MetamessagesAPI.MetamessageGetParams; - export import Chat = ChatAPI.Chat; - export import ChatStreamResponse = ChatAPI.ChatStreamResponse; - export import ChatStreamParams = ChatAPI.ChatStreamParams; } diff --git a/src/resources/apps/users/users.ts b/src/resources/apps/users/users.ts index 97a4a54..3e3e3ef 100644 --- a/src/resources/apps/users/users.ts +++ b/src/resources/apps/users/users.ts @@ -7,6 +7,7 @@ import * as UsersAPI from 'honcho/resources/apps/users/users'; import * as NameAPI from 'honcho/resources/apps/users/name'; import * as CollectionsAPI from 'honcho/resources/apps/users/collections/collections'; import * as SessionsAPI from 'honcho/resources/apps/users/sessions/sessions'; +import { Page, type PageParams } from 'honcho/pagination'; export class Users extends APIResource { sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client); @@ -25,19 +26,6 @@ export class Users extends APIResource { return this._client.post(`/apps/${appId}/users`, { body, ...options }); } - /** - * Get a User - * - * Args: app_id (uuid.UUID): The ID of the app representing the client application - * using honcho user_id (str): The User ID representing the user, managed by the - * user - * - * Returns: schemas.User: User object - */ - retrieve(appId: string, userId: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/apps/${appId}/users/${userId}`, options); - } - /** * Update a User * @@ -64,17 +52,47 @@ export class Users extends APIResource { * * Returns: list[schemas.User]: List of User objects */ - list(appId: string, query?: UserListParams, options?: Core.RequestOptions): Core.APIPromise; - list(appId: string, options?: Core.RequestOptions): Core.APIPromise; + list( + appId: string, + query?: UserListParams, + options?: Core.RequestOptions, + ): Core.PagePromise; + list(appId: string, options?: Core.RequestOptions): Core.PagePromise; list( appId: string, query: UserListParams | Core.RequestOptions = {}, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.PagePromise { if (isRequestOptions(query)) { return this.list(appId, {}, query); } - return this._client.get(`/apps/${appId}/users`, { query, ...options }); + return this._client.getAPIList(`/apps/${appId}/users`, UsersPage, { query, ...options }); + } + + /** + * Get a User + * + * Args: app_id (uuid.UUID): The ID of the app representing the client application + * using honcho user_id (str): The User ID representing the user, managed by the + * user + * + * Returns: schemas.User: User object + */ + get(appId: string, userId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/apps/${appId}/users/${userId}`, options); + } + + /** + * Get a User + * + * Args: app_id (uuid.UUID): The ID of the app representing the client application + * using honcho user_id (str): The User ID representing the user, managed by the + * user + * + * Returns: schemas.User: User object + */ + getByName(appId: string, name: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/apps/${appId}/users/name/${name}`, options); } /** @@ -91,16 +109,18 @@ export class Users extends APIResource { } } +export class UsersPage extends Page {} + export interface PageUser { items: Array; - page: number | null; + page: number; - size: number | null; + size: number; - total: number | null; + total: number; - pages?: number | null; + pages?: number; } export interface User { @@ -127,25 +147,16 @@ export interface UserUpdateParams { name?: string | null; } -export interface UserListParams { +export interface UserListParams extends PageParams { filter?: string | null; - /** - * Page number - */ - page?: number; - reverse?: boolean; - - /** - * Page size - */ - size?: number; } export namespace Users { export import PageUser = UsersAPI.PageUser; export import User = UsersAPI.User; + export import UsersPage = UsersAPI.UsersPage; export import UserCreateParams = UsersAPI.UserCreateParams; export import UserUpdateParams = UsersAPI.UserUpdateParams; export import UserListParams = UsersAPI.UserListParams; @@ -154,13 +165,18 @@ export namespace Users { export import PageSession = SessionsAPI.PageSession; export import Session = SessionsAPI.Session; export import SessionDeleteResponse = SessionsAPI.SessionDeleteResponse; + export import SessionStreamResponse = SessionsAPI.SessionStreamResponse; + export import SessionsPage = SessionsAPI.SessionsPage; export import SessionCreateParams = SessionsAPI.SessionCreateParams; export import SessionUpdateParams = SessionsAPI.SessionUpdateParams; export import SessionListParams = SessionsAPI.SessionListParams; + export import SessionChatParams = SessionsAPI.SessionChatParams; + export import SessionStreamParams = SessionsAPI.SessionStreamParams; export import Collections = CollectionsAPI.Collections; export import Collection = CollectionsAPI.Collection; export import PageCollection = CollectionsAPI.PageCollection; export import CollectionDeleteResponse = CollectionsAPI.CollectionDeleteResponse; + export import CollectionsPage = CollectionsAPI.CollectionsPage; export import CollectionCreateParams = CollectionsAPI.CollectionCreateParams; export import CollectionUpdateParams = CollectionsAPI.CollectionUpdateParams; export import CollectionListParams = CollectionsAPI.CollectionListParams; diff --git a/tests/api-resources/apps/users/collections/collections.test.ts b/tests/api-resources/apps/users/collections/collections.test.ts index cd35733..14b09c5 100644 --- a/tests/api-resources/apps/users/collections/collections.test.ts +++ b/tests/api-resources/apps/users/collections/collections.test.ts @@ -29,33 +29,6 @@ describe('resource collections', () => { ); }); - test('retrieve', async () => { - const responsePromise = honcho.apps.users.collections.retrieve( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '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); - }); - - test('retrieve: request options instead of 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( - honcho.apps.users.collections.retrieve( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { path: '/_stainless_unknown_path' }, - ), - ).rejects.toThrow(Honcho.NotFoundError); - }); - test('update: only required params', async () => { const responsePromise = honcho.apps.users.collections.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -144,4 +117,58 @@ describe('resource collections', () => { ), ).rejects.toThrow(Honcho.NotFoundError); }); + + test('get', async () => { + const responsePromise = honcho.apps.users.collections.get( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '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); + }); + + test('get: request options instead of 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( + honcho.apps.users.collections.get( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Honcho.NotFoundError); + }); + + test('getByName', async () => { + const responsePromise = honcho.apps.users.collections.getByName( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'string', + ); + 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); + }); + + test('getByName: request options instead of 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( + honcho.apps.users.collections.getByName( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + 'string', + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(Honcho.NotFoundError); + }); }); diff --git a/tests/api-resources/apps/users/sessions/chat.test.ts b/tests/api-resources/apps/users/sessions/chat.test.ts deleted file mode 100644 index bb32a5a..0000000 --- a/tests/api-resources/apps/users/sessions/chat.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - -import Honcho from 'honcho'; -import { Response } from 'node-fetch'; - -const honcho = new Honcho({ baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010' }); - -describe('resource chat', () => { - test('stream: only required params', async () => { - const responsePromise = honcho.apps.users.sessions.chat.stream( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, - ); - 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); - }); - - test('stream: required and optional params', async () => { - const response = await honcho.apps.users.sessions.chat.stream( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { query: 'string' }, - ); - }); -}); diff --git a/tests/api-resources/apps/users/sessions/sessions.test.ts b/tests/api-resources/apps/users/sessions/sessions.test.ts index 0a74f39..f37fda2 100644 --- a/tests/api-resources/apps/users/sessions/sessions.test.ts +++ b/tests/api-resources/apps/users/sessions/sessions.test.ts @@ -109,6 +109,31 @@ describe('resource sessions', () => { ).rejects.toThrow(Honcho.NotFoundError); }); + test('chat: only required params', async () => { + const responsePromise = honcho.apps.users.sessions.chat( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { query: 'string' }, + ); + 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); + }); + + test('chat: required and optional params', async () => { + const response = await honcho.apps.users.sessions.chat( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { query: 'string' }, + ); + }); + test('get', async () => { const responsePromise = honcho.apps.users.sessions.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', @@ -135,4 +160,29 @@ describe('resource sessions', () => { ), ).rejects.toThrow(Honcho.NotFoundError); }); + + test('stream: only required params', async () => { + const responsePromise = honcho.apps.users.sessions.stream( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { query: 'string' }, + ); + 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); + }); + + test('stream: required and optional params', async () => { + const response = await honcho.apps.users.sessions.stream( + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { query: 'string' }, + ); + }); }); diff --git a/tests/api-resources/apps/users/users.test.ts b/tests/api-resources/apps/users/users.test.ts index 0fbf7dc..01aa123 100644 --- a/tests/api-resources/apps/users/users.test.ts +++ b/tests/api-resources/apps/users/users.test.ts @@ -26,10 +26,11 @@ describe('resource users', () => { }); }); - test('retrieve', async () => { - const responsePromise = honcho.apps.users.retrieve( + test('update', async () => { + const responsePromise = honcho.apps.users.update( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + {}, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -40,22 +41,39 @@ describe('resource users', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('retrieve: request options instead of params are passed correctly', async () => { + test('list', async () => { + const responsePromise = honcho.apps.users.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); + }); + + test('list: request options instead of 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( - honcho.apps.users.retrieve( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + honcho.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(Honcho.NotFoundError); + }); + + test('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( + honcho.apps.users.list( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', + { filter: 'string', page: 1, reverse: true, size: 1 }, { path: '/_stainless_unknown_path' }, ), ).rejects.toThrow(Honcho.NotFoundError); }); - test('update', async () => { - const responsePromise = honcho.apps.users.update( + test('get', async () => { + const responsePromise = honcho.apps.users.get( '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - {}, ); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); @@ -66,8 +84,17 @@ describe('resource users', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list', async () => { - const responsePromise = honcho.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e'); + test('get: request options instead of 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( + honcho.apps.users.get('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { + path: '/_stainless_unknown_path', + }), + ).rejects.toThrow(Honcho.NotFoundError); + }); + + test('getByName', async () => { + const responsePromise = honcho.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'string'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -77,21 +104,12 @@ describe('resource users', () => { expect(dataAndResponse.response).toBe(rawResponse); }); - test('list: request options instead of 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( - honcho.apps.users.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', { path: '/_stainless_unknown_path' }), - ).rejects.toThrow(Honcho.NotFoundError); - }); - - test('list: request options and params are passed correctly', async () => { + test('getByName: request options instead of 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( - honcho.apps.users.list( - '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', - { filter: 'string', page: 1, reverse: true, size: 1 }, - { path: '/_stainless_unknown_path' }, - ), + honcho.apps.users.getByName('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'string', { + path: '/_stainless_unknown_path', + }), ).rejects.toThrow(Honcho.NotFoundError); });