import {z} from 'zod' export type GetApiConversationsShowArchivesSearchArgs = {search: string, page?: number | undefined, limit?: number | undefined}; export type GetApiConversationsShowArchivesSearchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const conversationSharedBy = z.object({userId: z.string(), name: z.string()}); export const getApiConversationsShowArchivesSearchResponse = z.object({conversations: z.array(z.object({agentKey: z.string().optional(), _id: z.string().optional(), userId: z.string().optional(), orgId: z.string().optional(), title: z.string().optional(), initiator: z.string().optional(), status: z.enum(["None", "Inprogress", "Complete", "Failed", "Stopped"]).optional(), failReason: z.string().optional(), modelInfo: z.object({modelKey: z.string().optional(), modelName: z.string().optional(), modelFriendlyName: z.string().optional(), modelProvider: z.string().optional(), chatMode: z.string().optional(), reasoningEffort: z.enum(["none", "low", "medium", "high", "max"]).optional()}).optional(), isShared: z.boolean().optional(), shareLink: z.string().optional(), sharedWith: z.array(z.object({userId: z.string().optional(), accessLevel: z.enum(["read", "write"]).optional(), _id: z.string().optional()})).optional(), isArchived: z.boolean().optional(), archivedBy: z.string().nullable().optional(), isDeleted: z.boolean().optional(), deletedBy: z.string().optional(), conversationErrors: z.array(z.object({_id: z.string().optional(), message: z.string().optional(), errorType: z.string().optional(), timestamp: z.string().optional(), messageId: z.string().optional(), stack: z.string().optional(), metadata: z.record(z.string(), z.unknown()).optional()})).optional(), metadata: z.record(z.string(), z.unknown()).optional(), lastActivityAt: z.number().int().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), isOwner: z.boolean().optional(), accessLevel: z.enum(["read", "write"]).optional(), isPinned: z.boolean().optional(), projectId: z.string().nullable().optional(), projectVisibility: z.enum(["private", "project"]).nullable().optional(), sharedBy: conversationSharedBy.optional(), source: z.enum(["assistant", "agent"]).optional(), archivedAt: z.string().optional()})).optional(), pagination: z.object({page: z.number().int().optional(), limit: z.number().int().optional(), totalCount: z.number().int().optional(), totalPages: z.number().int().optional(), hasNextPage: z.boolean().optional(), hasPrevPage: z.boolean().optional()}).optional(), summary: z.object({totalMatches: z.number().int().optional(), assistantMatches: z.number().int().optional(), agentMatches: z.number().int().optional(), searchQuery: z.string().optional()}).optional(), meta: z.object({requestId: z.string().optional(), timestamp: z.string().optional(), duration: z.number().int().optional()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Search archived conversations * * GET /conversations/show/archives/search * * Also accepts auth: oauth2 */ export const getApiConversationsShowArchivesSearch = async (args: GetApiConversationsShowArchivesSearchArgs, options?: GetApiConversationsShowArchivesSearchOptions) => { const {baseUrl = "https://app.pipeshub.com/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.search != null) query.append("search", String(args.search)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/conversations/show/archives/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiConversationsShowArchivesSearchResponse, await res.json()) };