import {z} from 'zod' export type GetApiV1MarketplacesMarketplaceIdPluginsArgs = {marketplaceId: unknown}; export type GetApiV1MarketplacesMarketplaceIdPluginsOptions = {baseUrl?: string | undefined, denApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const openWorkExtensionManifest = z.object({schemaVersion: z.literal(1), id: z.string().min(1).max(255), name: z.string().min(1).max(255), description: z.string().min(1).max(2048), source: z.object({format: z.enum(["agent-plugin", "openwork-builtin", "openwork-extension-manifest", "claude-plugin", "opencode-plugin", "mcp-directory", "manual"]), trusted: z.boolean(), origin: z.enum(["builtin", "den", "workspace", "local"]).optional(), reference: z.string().min(1).max(512).optional()}), resources: z.array(z.record(z.string(), z.unknown())), contributions: z.array(z.record(z.string(), z.unknown())).optional(), setup: z.record(z.string(), z.unknown()).optional(), lifecycle: z.record(z.string(), z.unknown()).optional()}).and(z.record(z.string(), z.unknown())); export const pluginArchExtensionProjection = z.object({id: z.string().min(30).max(30), name: z.string().min(1).max(255), description: z.string().min(1).nullable(), sourceFormat: z.enum(["agent-plugin", "openwork-builtin", "openwork-extension-manifest", "claude-plugin", "opencode-plugin", "mcp-directory", "manual"]), manifest: openWorkExtensionManifest.nullable()}); export const pluginArchPlugin = z.object({id: z.string().min(30).max(30), organizationId: z.string().min(30).max(30), name: z.string().min(1).max(255), description: z.string().min(1).nullable(), sourceRepositoryUrl: z.string().min(1).max(1024).nullable(), sourceFormat: z.enum(["agent-plugin", "openwork-builtin", "openwork-extension-manifest", "claude-plugin", "opencode-plugin", "mcp-directory", "manual"]).nullable(), sourceSchemaVersion: z.string().min(1).max(100).nullable(), status: z.enum(["active", "inactive", "deleted", "archived"]), createdByOrgMembershipId: z.string().min(29).max(29), createdAt: z.string(), updatedAt: z.string(), deletedAt: z.string().nullable(), memberCount: z.number().int().gte(0).lte(9007199254740991).optional(), marketplaces: z.array(z.object({id: z.string().min(30).max(30), name: z.string().min(1).max(255)})).optional(), extension: pluginArchExtensionProjection.nullable().optional()}); export const pluginArchMarketplacePluginMembership = z.object({id: z.string().min(30).max(30), marketplaceId: z.string().min(30).max(30), pluginId: z.string().min(30).max(30), membershipSource: z.enum(["manual", "connector", "api", "system"]), createdByOrgMembershipId: z.string().min(29).max(29).nullable(), createdAt: z.string(), removedAt: z.string().nullable(), plugin: pluginArchPlugin.optional()}); export const pluginArchMarketplacePluginListResponse = z.object({items: z.array(pluginArchMarketplacePluginMembership), nextCursor: z.string().min(1).max(255).nullable()}); 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 marketplace plugins * * GET /v1/marketplaces/{marketplaceId}/plugins * * Also accepts auth: bearerAuth */ export const getApiV1MarketplacesMarketplaceIdPlugins = async (args: GetApiV1MarketplacesMarketplaceIdPluginsArgs, options?: GetApiV1MarketplacesMarketplaceIdPluginsOptions) => { const {baseUrl = "https://api.openworklabs.com", fetch: fetchFn = fetch, denApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (denApiKey !== undefined) headers.set("x-api-key", denApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/marketplaces/${encodeURIComponent(String(args.marketplaceId))}/plugins${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(pluginArchMarketplacePluginListResponse, await res.json()) };