import {z} from 'zod' export type GetApiWorkspacesWorkspaceIdConnectedSourcesArgs = {workspace_id: string}; export type GetApiWorkspacesWorkspaceIdConnectedSourcesOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const adapterType = z.enum(["github", "slack", "uploaded_file"]); export const sourceVisibility = z.enum(["private", "public"]); export const gitHubSourceConfig = z.object({repo: z.string(), branch: z.string()}); export const slackSourceConfig = z.object({slack_team_id: z.string(), channel_id: z.string()}); export const uploadedFileSourceConfig = z.object({file_id: z.string()}); export const gitHubSourceMetadata = z.object({installation_id: z.number().int(), commit_sha: z.string()}); export const slackSourceMetadata = z.object({team_name: z.string().nullable().optional(), channel_name: z.string(), is_private: z.boolean().optional()}); export const uploadedFileSourceMetadata = z.object({filename: z.string(), content_type: z.string().nullable().optional(), size_bytes: z.number().int().nullable().optional()}); export const connectedSource = z.object({id: z.string().nullable().optional(), linked_by_user_id: z.string(), adapter: adapterType, visibility: sourceVisibility.optional(), config: z.union([gitHubSourceConfig, slackSourceConfig, uploadedFileSourceConfig]), metadata: z.union([gitHubSourceMetadata, slackSourceMetadata, uploadedFileSourceMetadata])}); export const getApiWorkspacesWorkspaceIdConnectedSourcesResponse = z.array(connectedSource); 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 }; /** * List Connected Sources * * GET /workspaces/{workspace_id}/connected-sources */ export const getApiWorkspacesWorkspaceIdConnectedSources = async (args: GetApiWorkspacesWorkspaceIdConnectedSourcesArgs, options: GetApiWorkspacesWorkspaceIdConnectedSourcesOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/workspaces/${encodeURIComponent(String(args.workspace_id))}/connected-sources${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(getApiWorkspacesWorkspaceIdConnectedSourcesResponse, await res.json()) };