import {z} from 'zod' export type GetApiExperimentalOrgsOrgIdAgentSignalsSkillsArgs = {rankBy?: ('skill.activation' | 'skill.read') | undefined, 'page[size]'?: number | undefined, 'page[number]'?: number | undefined, orgId: string, Authorization?: string | undefined}; export type GetApiExperimentalOrgsOrgIdAgentSignalsSkillsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiExperimentalOrgsOrgIdAgentSignalsSkillsResponse = z.object({links: z.object({self: z.string(), next: z.string().nullable(), prev: z.string().nullable()}), meta: z.object({count: z.number()}), data: z.array(z.object({id: z.string(), type: z.literal("agent-signal-skill-aggregate"), attributes: z.object({name: z.string(), namespace: z.string().nullable(), activation: z.object({count: z.number(), distinctUsers: z.number(), unattributedRows: z.number(), interactiveUsers: z.number(), automatedRows: z.number(), distinctSessions: z.number()}), read: z.object({count: z.number(), distinctUsers: z.number(), unattributedRows: z.number(), interactiveUsers: z.number(), automatedRows: z.number(), distinctSessions: z.number()})})}))}); 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 }; /** * Lists skills with the highest activation or read count for an organization. Activation and read counts, distinct users, and distinct sessions are reported separately and are never combined. * * GET /experimental/orgs/{orgId}/agent-signals/skills */ export const getApiExperimentalOrgsOrgIdAgentSignalsSkills = async (args: GetApiExperimentalOrgsOrgIdAgentSignalsSkillsArgs, options?: GetApiExperimentalOrgsOrgIdAgentSignalsSkillsOptions) => { const {baseUrl = "https://api.tessl.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.rankBy != null) query.append("rankBy", String(args.rankBy)) if (args['page[size]'] != null) query.append("page[size]", String(args['page[size]'])) if (args['page[number]'] != null) query.append("page[number]", String(args['page[number]'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/experimental/orgs/${encodeURIComponent(String(args.orgId))}/agent-signals/skills${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(getApiExperimentalOrgsOrgIdAgentSignalsSkillsResponse, await res.json()) };