@w6w/embed 0.2.23 → 0.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/{ImportSpecModal-Cpzp8ndt.js → ImportSpecModal-VdYN1QeZ.js} +21 -20
  2. package/dist/{ImportSpecModal-Cpzp8ndt.js.map → ImportSpecModal-VdYN1QeZ.js.map} +1 -1
  3. package/dist/{WorkflowEditor-LesBKjb2.js → WorkflowEditor-CGKoeSG7.js} +6 -6
  4. package/dist/{WorkflowEditor-LesBKjb2.js.map → WorkflowEditor-CGKoeSG7.js.map} +1 -1
  5. package/dist/{apps-CYUgEfGf.js → apps-FMcQfyL2.js} +2 -2
  6. package/dist/{apps-CYUgEfGf.js.map → apps-FMcQfyL2.js.map} +1 -1
  7. package/dist/chrome/ImportSpecModal.d.ts +2 -0
  8. package/dist/{credentials-Cn92LGhJ.js → credentials-CMR_wEvx.js} +96 -71
  9. package/dist/credentials-CMR_wEvx.js.map +1 -0
  10. package/dist/editor-apps-HEOclsxL.js +152 -0
  11. package/dist/{editor-apps-LZmDWMqf.js.map → editor-apps-HEOclsxL.js.map} +1 -1
  12. package/dist/{editor-tools-DHyWiG21.js → editor-tools-Brw0cv2F.js} +4 -4
  13. package/dist/{editor-tools-DHyWiG21.js.map → editor-tools-Brw0cv2F.js.map} +1 -1
  14. package/dist/editor.mjs +1 -1
  15. package/dist/editors.mjs +7 -7
  16. package/dist/index.mjs +15 -15
  17. package/dist/lib/workflow-blank.d.ts +12 -2
  18. package/dist/lib.mjs +41 -39
  19. package/dist/lists/ConnectionList.d.ts +3 -1
  20. package/dist/lists/CredentialCreate.d.ts +25 -0
  21. package/dist/lists/CredentialDetail.d.ts +5 -1
  22. package/dist/lists/CredentialList.d.ts +3 -1
  23. package/dist/lists.d.ts +2 -0
  24. package/dist/lists.mjs +943 -768
  25. package/dist/lists.mjs.map +1 -1
  26. package/dist/models-CK1KHd39.js.map +1 -1
  27. package/dist/rail.mjs +1 -1
  28. package/dist/repos/agents-studio-agents.d.ts +46 -2
  29. package/dist/repos/credentials.d.ts +16 -2
  30. package/dist/repos/models.d.ts +36 -6
  31. package/dist/repos.mjs +468 -451
  32. package/dist/repos.mjs.map +1 -1
  33. package/dist/{spec-export-DGigBUsP.js → spec-export-DMMET5VM.js} +2 -2
  34. package/dist/{spec-export-DGigBUsP.js.map → spec-export-DMMET5VM.js.map} +1 -1
  35. package/dist/workflow-blank-BJFLdGyE.js +37 -0
  36. package/dist/workflow-blank-BJFLdGyE.js.map +1 -0
  37. package/dist/{workflows-BK6IM4if.js → workflows-Dz8LMjnt.js} +37 -34
  38. package/dist/workflows-Dz8LMjnt.js.map +1 -0
  39. package/package.json +2 -2
  40. package/dist/credentials-Cn92LGhJ.js.map +0 -1
  41. package/dist/editor-apps-LZmDWMqf.js +0 -152
  42. package/dist/workflow-blank-CorOIrSj.js +0 -21
  43. package/dist/workflow-blank-CorOIrSj.js.map +0 -1
  44. package/dist/workflows-BK6IM4if.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"models-CK1KHd39.js","sources":["../src/repos/models.ts"],"sourcesContent":["/**\n * The model-registry repo — catalog, routes, budgets and usage over `W6WClient.request()`\n * (the stable ops for these land in the SDK separately; `request()` is the public escape hatch,\n * same as `vars.ts`). Shapes are the server's pinned wire shapes (project plan §Wire shapes).\n *\n * Scope: the catalog is tenant-wide and NEVER sends `project`. Routes, budgets and usage are\n * project-scoped, so their hooks are `enabled: projectId != null` and every fetcher sends\n * `?project=`; a project-scoped page therefore never queries before the project resolves.\n */\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type { W6WClient } from \"@w6w/sdk\";\nimport { path } from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\n\nexport interface ModelRates {\n input?: number;\n output?: number;\n cachedInput?: number;\n cacheWrite?: number;\n perRequest?: number;\n currency?: string;\n}\nexport interface ModelRate {\n id: string;\n modelId: string;\n effectiveFrom: string;\n rates: ModelRates;\n source: \"seed\" | \"tenant\";\n}\nexport interface Model {\n id: string;\n providerAppId: string;\n provider: string;\n nativeId: string;\n displayName: string;\n capabilities: unknown;\n limits: { maxInputTokens?: number; maxOutputTokens?: number };\n status: \"active\" | \"deprecated\" | \"blocked\";\n source: \"discovered\" | \"manual\";\n currentRate: ModelRate | null;\n discoveredAt: string | null;\n createdAt: string;\n updatedAt: string;\n}\nexport interface ModelFallback {\n model: string;\n connection: string;\n}\nexport interface ModelRoute {\n id: string;\n name: string;\n project: string;\n modelId: string;\n connectionId: string;\n fallbacks: ModelFallback[];\n defaults: Record<string, unknown>;\n status: \"active\" | \"broken\";\n createdAt: string;\n updatedAt: string;\n}\nexport interface ModelRouteInput {\n name: string;\n model: string;\n connection: string;\n fallbacks?: ModelFallback[];\n defaults?: Record<string, unknown>;\n}\nexport type ModelRoutePatch = Partial<Omit<ModelRouteInput, \"name\">>;\nexport interface ModelBudgetLimits {\n requests?: number;\n tokens?: number;\n costMinor?: number;\n currency?: string;\n}\nexport interface ModelBudget {\n id: string;\n scopeKind: string;\n scopeId: string | null;\n window: string;\n limits: ModelBudgetLimits;\n onBreach: \"block\" | \"warn\";\n}\nexport interface ModelBudgetInput {\n scopeKind: string;\n scopeId?: string;\n window: string;\n limits: ModelBudgetLimits;\n onBreach: \"block\" | \"warn\";\n}\nexport type ModelBudgetPatch = Partial<Omit<ModelBudgetInput, \"scopeKind\" | \"scopeId\">>;\nexport interface ModelBudgetUsageCounts {\n requests: number;\n tokens: number;\n costMinor: number;\n}\nexport interface ModelBudgetUsage {\n budgetId: string;\n window: string;\n windowStart: string;\n limits: ModelBudgetLimits;\n used: ModelBudgetUsageCounts;\n reserved: ModelBudgetUsageCounts;\n}\nexport interface ModelCost {\n currency: string;\n amountMinor: number;\n}\nexport interface ModelUsageGroup {\n key: string;\n requests: number;\n totalTokens: number;\n cost: ModelCost[];\n}\nexport interface ModelUsageTotals {\n requests: number;\n inputTokens: number;\n outputTokens: number;\n cachedInputTokens: number;\n cacheWriteTokens: number;\n totalTokens: number;\n cost: ModelCost[];\n unpriced: number;\n}\nexport interface ModelUsageItem {\n id: string;\n routeId: string | null;\n modelId: string;\n connectionId: string;\n provider: string;\n nativeId: string;\n inputTokens: number;\n outputTokens: number;\n cachedInputTokens: number;\n cacheWriteTokens: number;\n totalTokens: number;\n costMinor: number | null;\n currency: string | null;\n rateVersion: string | null;\n durationMs: number;\n ok: boolean;\n errorCode: string | null;\n invocationId: string | null;\n runId: string | null;\n occurredAt: string;\n}\nexport interface ModelUsageReport {\n totals: ModelUsageTotals;\n totalsTruncated?: boolean | null;\n groups?: ModelUsageGroup[];\n items: ModelUsageItem[];\n nextCursor: string | null;\n}\nexport interface ModelUsageFilter {\n route?: string;\n model?: string;\n from?: string;\n to?: string;\n groupBy?: \"route\" | \"model\" | \"day\";\n limit?: number;\n cursor?: string;\n}\nexport interface ModelCatalogFilter {\n provider?: string;\n status?: string;\n limit?: number;\n cursor?: string;\n}\nexport interface ModelCatalogPage {\n models: Model[];\n nextCursor: string | null;\n}\n\nexport const modelCatalogKey = (filter: ModelCatalogFilter = {}) =>\n [\"model-catalog\", filter] as const;\nexport const modelProvidersKey = [\"model-providers\"] as const;\nexport const modelRoutesKey = (projectId?: string) => [\"model-routes\", projectId] as const;\nexport const modelBudgetsKey = (projectId?: string) => [\"model-budgets\", projectId] as const;\nexport const modelBudgetUsageKey = (id: string, projectId?: string) =>\n [\"model-budget-usage\", id, projectId] as const;\nexport const modelUsageKey = (projectId?: string, filter: ModelUsageFilter = {}) =>\n [\"model-usage\", projectId, filter] as const;\n\nexport async function listModelCatalog(\n client: W6WClient,\n filter: ModelCatalogFilter = {},\n): Promise<ModelCatalogPage> {\n // Tenant-wide: deliberately no `project` here.\n const res = await client.request<ModelCatalogPage>({\n method: \"GET\",\n path: \"/models\",\n query: { ...filter },\n });\n return res.body;\n}\n\n/** One row of `GET /models/providers` — the descriptor the model pickers are driven by. */\nexport interface ModelProviderRow {\n appId: string;\n provider: string | null;\n installed: boolean;\n designation?: { modelTypes: string[]; modelFamilies?: string[] } | null;\n operations?: {\n discover: { supported: boolean; reason?: string };\n complete: {\n supported: boolean;\n reason?: string;\n features?: Partial<Record<ModelFeature, ModelFeatureState>>;\n };\n };\n /** A2 (optional): the bridge adapter serving this app; `null` = none. */\n adapter?: { provider: string; contractVersion: number } | null;\n /** A2 (optional): why this app cannot serve the caller right now. */\n reasons?: ModelProviderReason[];\n}\nexport type ModelFeature = \"toolCalls\" | \"structuredOutput\" | \"streaming\";\nexport type ModelFeatureState = \"supported\" | \"unsupported\" | \"unknown\";\nexport type ModelProviderReasonCode =\n | \"not_installed\"\n | \"no_adapter\"\n | \"not_entitled\"\n | \"no_connection\";\nexport interface ModelProviderReason {\n code: ModelProviderReasonCode;\n message: string;\n}\nexport interface CompleteSupport {\n supported: boolean;\n features: Partial<Record<ModelFeature, ModelFeatureState>>;\n reasons: ModelProviderReason[];\n}\n\n/**\n * THE support policy for `operations.complete`. Unsupported when the descriptor says so or the\n * row names no adapter (`adapter: null`); a pre-A2 row (no `adapter`/`features`/`reasons`) falls\n * back to `operations.complete.supported`. Unsupported rows always carry a reason.\n */\nexport function completeSupport(row: ModelProviderRow): CompleteSupport {\n const op = row.operations?.complete;\n const noAdapter = row.adapter === null;\n const supported = op?.supported === true && !noAdapter;\n const reasons = [...(row.reasons ?? [])];\n if (!supported && reasons.length === 0) {\n reasons.push({\n code:\n noAdapter || op?.supported === true\n ? \"no_adapter\"\n : row.installed\n ? \"no_adapter\"\n : \"not_installed\",\n message: op?.reason ?? \"Not supported for this provider\",\n });\n }\n return { supported, features: op?.features ?? {}, reasons };\n}\n\n/** Follow `nextCursor` until null (or `maxPages`), concatenating `models`. */\nexport async function loadAllModelCatalogPages(\n fetchPage: (cursor?: string) => Promise<ModelCatalogPage>,\n opts: { maxPages?: number } = {},\n): Promise<{ models: Model[]; truncated: boolean }> {\n const maxPages = opts.maxPages ?? 50;\n const models: Model[] = [];\n let cursor: string | undefined;\n for (let i = 0; i < maxPages; i++) {\n const page = await fetchPage(cursor);\n models.push(...page.models);\n if (!page.nextCursor) return { models, truncated: false };\n cursor = page.nextCursor;\n }\n return { models, truncated: true };\n}\nexport type ModelOperation = \"discover\" | \"complete\";\nexport interface ConnectionChoice {\n id: string;\n appId: string;\n displayName: string;\n /** Present only when the descriptor says the operation is unsupported for this provider. */\n disabledReason?: string;\n}\n\nexport async function listModelProviders(client: W6WClient): Promise<ModelProviderRow[]> {\n const res = await client.request<{ providers?: ModelProviderRow[] } | ModelProviderRow[]>({\n method: \"GET\",\n path: \"/models/providers\",\n });\n const b = res.body;\n return Array.isArray(b) ? b : (b?.providers ?? []);\n}\n\n/**\n * The connections a model picker may offer for `operation`, decided by the descriptor alone:\n * a connection whose app has no designated provider row never appears (an `ai`-category app is\n * not a provider); a designated row whose `discover` is unsupported appears disabled with the\n * descriptor's reason; for `complete` the shared `completeSupport` policy decides (unsupported => disabled, never selectable).\n */\nexport function connectionChoices<C extends { id: string; appId: string; displayName: string }>(\n connections: C[],\n providers: ModelProviderRow[],\n operation: ModelOperation,\n): ConnectionChoice[] {\n const byApp = new Map<string, ModelProviderRow>();\n for (const p of providers) if (p.designation) byApp.set(p.appId, p);\n const out: ConnectionChoice[] = [];\n for (const c of connections) {\n const row = byApp.get(c.appId);\n if (!row) continue;\n const op = row.operations?.[operation];\n const choice: ConnectionChoice = { id: c.id, appId: c.appId, displayName: c.displayName };\n if (operation === \"complete\") {\n const sup = completeSupport(row);\n if (!sup.supported) {\n choice.disabledReason =\n op?.reason ?? sup.reasons[0]?.message ?? \"Not supported for this provider\";\n }\n } else if (!op?.supported) {\n choice.disabledReason = op?.reason ?? \"Not supported for this provider\";\n }\n out.push(choice);\n }\n return out;\n}\n\n/** The server answers fallbacks as `{modelId, connectionId}`; the editor works in `{model, connection}`. */\nexport function normaliseRoute(r: ModelRoute): ModelRoute {\n const fallbacks = (r.fallbacks ?? []).map((f) => {\n const x = f as ModelFallback & { modelId?: string; connectionId?: string };\n return { model: x.model ?? x.modelId ?? \"\", connection: x.connection ?? x.connectionId ?? \"\" };\n });\n return { ...r, fallbacks };\n}\n\nexport async function listModelRoutes(client: W6WClient, project: string): Promise<ModelRoute[]> {\n const res = await client.request<{ routes: ModelRoute[] }>({\n method: \"GET\",\n path: \"/model-routes\",\n query: { project },\n });\n return res.body.routes.map(normaliseRoute);\n}\nexport async function createModelRoute(\n client: W6WClient,\n project: string,\n input: ModelRouteInput,\n): Promise<ModelRoute> {\n const res = await client.request<{ route: ModelRoute }>({\n method: \"POST\",\n path: \"/model-routes\",\n query: { project },\n body: input,\n });\n return normaliseRoute(res.body.route);\n}\nexport async function updateModelRoute(\n client: W6WClient,\n project: string,\n name: string,\n patch: ModelRoutePatch,\n): Promise<ModelRoute> {\n const res = await client.request<{ route: ModelRoute }>({\n method: \"PATCH\",\n path: path`/model-routes/${name}`,\n query: { project },\n body: patch,\n });\n return normaliseRoute(res.body.route);\n}\n/** One chat message for a route completion (the bridge dialect). */\nexport interface ModelCompletionMessage {\n role: \"system\" | \"user\" | \"assistant\";\n content: string;\n}\n/** A route completion request: the messages plus the agent's model options. */\nexport interface ModelCompletionInput {\n messages: ModelCompletionMessage[];\n temperature?: number;\n topP?: number;\n maxOutputTokens?: number;\n stop?: string[];\n}\n/** The parts of the completion envelope a caller reads (`response=output`, no raw). */\nexport interface ModelCompletionResult {\n provider: string;\n model: string;\n route: string | null;\n output?: {\n choices?: {\n message?: { content?: string | { type: string; text?: string }[] };\n finishReason?: string;\n }[];\n };\n usageSummary?: { inclusiveInputTokens?: number; outputTokens?: number; totalTokens?: number };\n durationMs?: number;\n}\n/** `POST /model-routes/{name}/complete` — calls the route's model once (billed like any call). */\nexport async function completeModelRoute(\n client: W6WClient,\n project: string,\n name: string,\n input: ModelCompletionInput,\n): Promise<ModelCompletionResult> {\n const res = await client.request<ModelCompletionResult>({\n method: \"POST\",\n path: path`/model-routes/${name}/complete`,\n query: { project, response: \"output\" },\n body: input,\n });\n return res.body;\n}\nexport async function deleteModelRoute(\n client: W6WClient,\n project: string,\n name: string,\n): Promise<void> {\n await client.request<{ ok: true }>({\n method: \"DELETE\",\n path: path`/model-routes/${name}`,\n query: { project },\n });\n}\n\nexport async function listModelBudgets(client: W6WClient, project: string): Promise<ModelBudget[]> {\n const res = await client.request<{ budgets: ModelBudget[] }>({\n method: \"GET\",\n path: \"/model-budgets\",\n query: { project },\n });\n return res.body.budgets;\n}\nexport async function createModelBudget(\n client: W6WClient,\n project: string,\n input: ModelBudgetInput,\n): Promise<ModelBudget> {\n // The server answers with the budget row itself (201), not a `{ budget }` wrapper.\n const res = await client.request<ModelBudget>({\n method: \"POST\",\n path: \"/model-budgets\",\n query: { project },\n body: input,\n });\n return res.body;\n}\nexport async function updateModelBudget(\n client: W6WClient,\n project: string,\n id: string,\n patch: ModelBudgetPatch,\n): Promise<ModelBudget> {\n // The server answers with the updated budget row itself, not a `{ budget }` wrapper.\n const res = await client.request<ModelBudget>({\n method: \"PATCH\",\n path: path`/model-budgets/${id}`,\n query: { project },\n body: patch,\n });\n return res.body;\n}\nexport async function deleteModelBudget(\n client: W6WClient,\n project: string,\n id: string,\n): Promise<void> {\n await client.request<{ ok: true }>({\n method: \"DELETE\",\n path: path`/model-budgets/${id}`,\n query: { project },\n });\n}\nexport async function getModelBudgetUsage(\n client: W6WClient,\n project: string,\n id: string,\n): Promise<ModelBudgetUsage> {\n const res = await client.request<ModelBudgetUsage>({\n method: \"GET\",\n path: path`/model-budgets/${id}/usage`,\n query: { project },\n });\n return res.body;\n}\nexport async function getModelUsage(\n client: W6WClient,\n project: string,\n filter: ModelUsageFilter = {},\n): Promise<ModelUsageReport> {\n const res = await client.request<ModelUsageReport>({\n method: \"GET\",\n path: \"/model-usage\",\n query: { project, ...filter },\n });\n return res.body;\n}\n\n/** What `POST /models/discover` changed in the tenant catalog — model ids per bucket. */\nexport interface ModelDiscoverResult {\n added: string[];\n updated: string[];\n deprecated: string[];\n}\n/**\n * Ask the provider behind `connection` for its model list and fold it into the tenant catalog.\n * Tenant administration only: anyone else gets a 403 `forbidden`.\n */\nexport async function discoverModels(\n client: W6WClient,\n connection: string,\n): Promise<ModelDiscoverResult> {\n const res = await client.request<ModelDiscoverResult>({\n method: \"POST\",\n path: \"/models/discover\",\n body: { connection },\n });\n return res.body;\n}\n\nexport function useModelCatalogQuery(filter: ModelCatalogFilter = {}) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelCatalogKey(filter),\n queryFn: () => listModelCatalog(client, filter),\n });\n}\nexport function useAllModelCatalogQuery(filter: Omit<ModelCatalogFilter, \"cursor\"> = {}) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: [\"model-catalog-all\", filter] as const,\n queryFn: () =>\n loadAllModelCatalogPages((cursor) => listModelCatalog(client, { ...filter, cursor })),\n });\n}\nexport function useModelProvidersQuery() {\n const client = useEmbedClient();\n return useQuery({ queryKey: modelProvidersKey, queryFn: () => listModelProviders(client) });\n}\nexport function useModelRoutesQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelRoutesKey(projectId),\n enabled: projectId != null,\n queryFn: () => listModelRoutes(client, projectId as string),\n });\n}\nexport function useModelBudgetsQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelBudgetsKey(projectId),\n enabled: projectId != null,\n queryFn: () => listModelBudgets(client, projectId as string),\n });\n}\nexport function useModelBudgetUsageQuery(id: string, projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelBudgetUsageKey(id, projectId),\n enabled: projectId != null,\n queryFn: () => getModelBudgetUsage(client, projectId as string, id),\n });\n}\nexport function useModelUsageQuery(projectId?: string, filter: ModelUsageFilter = {}) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelUsageKey(projectId, filter),\n enabled: projectId != null,\n queryFn: () => getModelUsage(client, projectId as string, filter),\n });\n}\n\nexport function useDiscoverModelsMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (connection: string) => discoverModels(client, connection),\n onSuccess: async () => {\n await Promise.all([\n qc.invalidateQueries({ queryKey: [\"model-catalog\"] }),\n qc.invalidateQueries({ queryKey: [\"model-catalog-all\"] }),\n ]);\n },\n });\n}\nexport function useCreateModelRouteMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; input: ModelRouteInput }) =>\n createModelRoute(client, v.project, v.input),\n // The agent editor lists routes under its own key; a new route belongs in both lists.\n onSuccess: () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: [\"model-routes\"] }),\n qc.invalidateQueries({ queryKey: [\"agents\", \"model-routes\"] }),\n ]),\n });\n}\nexport function useUpdateModelRouteMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; name: string; patch: ModelRoutePatch }) =>\n updateModelRoute(client, v.project, v.name, v.patch),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-routes\"] }),\n });\n}\nexport function useCompleteModelRouteMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { project: string; name: string; input: ModelCompletionInput }) =>\n completeModelRoute(client, v.project, v.name, v.input),\n });\n}\nexport function useDeleteModelRouteMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; name: string }) =>\n deleteModelRoute(client, v.project, v.name),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-routes\"] }),\n });\n}\nexport function useCreateModelBudgetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; input: ModelBudgetInput }) =>\n createModelBudget(client, v.project, v.input),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-budgets\"] }),\n });\n}\nexport function useUpdateModelBudgetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; id: string; patch: ModelBudgetPatch }) =>\n updateModelBudget(client, v.project, v.id, v.patch),\n // The row meter reads its limit from the per-budget usage query, so refresh it too.\n onSuccess: (_b, v) =>\n Promise.all([\n qc.invalidateQueries({ queryKey: [\"model-budgets\"] }),\n qc.invalidateQueries({ queryKey: [\"model-budget-usage\", v.id] }),\n ]),\n });\n}\nexport function useDeleteModelBudgetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; id: string }) => deleteModelBudget(client, v.project, v.id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-budgets\"] }),\n });\n}\n"],"names":["modelCatalogKey","filter","modelProvidersKey","modelRoutesKey","projectId","modelBudgetsKey","modelBudgetUsageKey","id","modelUsageKey","listModelCatalog","client","completeSupport","row","op","_a","noAdapter","supported","reasons","loadAllModelCatalogPages","fetchPage","opts","maxPages","models","cursor","i","page","listModelProviders","b","connectionChoices","connections","providers","operation","byApp","p","out","c","choice","sup","_b","normaliseRoute","r","fallbacks","f","x","listModelRoutes","project","createModelRoute","input","res","updateModelRoute","name","patch","path","completeModelRoute","deleteModelRoute","listModelBudgets","createModelBudget","updateModelBudget","deleteModelBudget","getModelBudgetUsage","getModelUsage","discoverModels","connection","useModelCatalogQuery","useEmbedClient","useQuery","useAllModelCatalogQuery","useModelProvidersQuery","useModelRoutesQuery","useModelBudgetsQuery","useModelBudgetUsageQuery","useModelUsageQuery","useDiscoverModelsMutation","qc","useQueryClient","useMutation","useCreateModelRouteMutation","v","useUpdateModelRouteMutation","useCompleteModelRouteMutation","useDeleteModelRouteMutation","useCreateModelBudgetMutation","useUpdateModelBudgetMutation","useDeleteModelBudgetMutation"],"mappings":";;;AA4KO,MAAMA,IAAkB,CAACC,IAA6B,OAC3D,CAAC,iBAAiBA,CAAM,GACbC,IAAoB,CAAC,iBAAiB,GACtCC,IAAiB,CAACC,MAAuB,CAAC,gBAAgBA,CAAS,GACnEC,IAAkB,CAACD,MAAuB,CAAC,iBAAiBA,CAAS,GACrEE,IAAsB,CAACC,GAAY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BAAkB,EAAE,UAAU,CAAC,eAAe,EAAA,CAAG;AAAA,EAAA,CACtE;AACH;"}
1
+ {"version":3,"file":"models-CK1KHd39.js","sources":["../src/repos/models.ts"],"sourcesContent":["/**\n * The model-registry repo — catalog, routes, budgets and usage over `W6WClient.request()`\n * (the stable ops for these land in the SDK separately; `request()` is the public escape hatch,\n * same as `vars.ts`). Shapes are the server's pinned wire shapes (project plan §Wire shapes).\n *\n * Scope: the catalog is tenant-wide and NEVER sends `project`. Routes, budgets and usage are\n * project-scoped, so their hooks are `enabled: projectId != null` and every fetcher sends\n * `?project=`; a project-scoped page therefore never queries before the project resolves.\n */\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport type { W6WClient } from \"@w6w/sdk\";\nimport { path } from \"@w6w/sdk\";\nimport { useEmbedClient } from \"../draft/client-context.ts\";\n\nexport interface ModelRates {\n input?: number;\n output?: number;\n cachedInput?: number;\n cacheWrite?: number;\n perRequest?: number;\n currency?: string;\n}\nexport interface ModelRate {\n id: string;\n modelId: string;\n effectiveFrom: string;\n rates: ModelRates;\n source: \"seed\" | \"tenant\";\n}\nexport interface Model {\n id: string;\n providerAppId: string;\n provider: string;\n nativeId: string;\n displayName: string;\n capabilities: unknown;\n limits: { maxInputTokens?: number; maxOutputTokens?: number };\n status: \"active\" | \"deprecated\" | \"blocked\";\n source: \"discovered\" | \"manual\";\n currentRate: ModelRate | null;\n discoveredAt: string | null;\n createdAt: string;\n updatedAt: string;\n}\nexport interface ModelFallback {\n model: string;\n connection: string;\n}\nexport interface ModelRoute {\n id: string;\n name: string;\n project: string;\n modelId: string;\n connectionId: string;\n fallbacks: ModelFallback[];\n defaults: Record<string, unknown>;\n status: \"active\" | \"broken\";\n createdAt: string;\n updatedAt: string;\n}\nexport interface ModelRouteInput {\n name: string;\n model: string;\n connection: string;\n fallbacks?: ModelFallback[];\n defaults?: Record<string, unknown>;\n}\nexport type ModelRoutePatch = Partial<Omit<ModelRouteInput, \"name\">>;\nexport interface ModelBudgetLimits {\n requests?: number;\n tokens?: number;\n costMinor?: number;\n currency?: string;\n}\nexport interface ModelBudget {\n id: string;\n scopeKind: string;\n scopeId: string | null;\n window: string;\n limits: ModelBudgetLimits;\n onBreach: \"block\" | \"warn\";\n}\nexport interface ModelBudgetInput {\n scopeKind: string;\n scopeId?: string;\n window: string;\n limits: ModelBudgetLimits;\n onBreach: \"block\" | \"warn\";\n}\nexport type ModelBudgetPatch = Partial<Omit<ModelBudgetInput, \"scopeKind\" | \"scopeId\">>;\nexport interface ModelBudgetUsageCounts {\n requests: number;\n tokens: number;\n costMinor: number;\n}\nexport interface ModelBudgetUsage {\n budgetId: string;\n window: string;\n windowStart: string;\n limits: ModelBudgetLimits;\n used: ModelBudgetUsageCounts;\n reserved: ModelBudgetUsageCounts;\n}\nexport interface ModelCost {\n currency: string;\n amountMinor: number;\n}\nexport interface ModelUsageGroup {\n key: string;\n requests: number;\n totalTokens: number;\n cost: ModelCost[];\n}\nexport interface ModelUsageTotals {\n requests: number;\n inputTokens: number;\n outputTokens: number;\n cachedInputTokens: number;\n cacheWriteTokens: number;\n totalTokens: number;\n cost: ModelCost[];\n unpriced: number;\n}\nexport interface ModelUsageItem {\n id: string;\n routeId: string | null;\n modelId: string;\n connectionId: string;\n provider: string;\n nativeId: string;\n inputTokens: number;\n outputTokens: number;\n cachedInputTokens: number;\n cacheWriteTokens: number;\n totalTokens: number;\n costMinor: number | null;\n currency: string | null;\n rateVersion: string | null;\n durationMs: number;\n ok: boolean;\n errorCode: string | null;\n invocationId: string | null;\n runId: string | null;\n occurredAt: string;\n}\nexport interface ModelUsageReport {\n totals: ModelUsageTotals;\n totalsTruncated?: boolean | null;\n groups?: ModelUsageGroup[];\n items: ModelUsageItem[];\n nextCursor: string | null;\n}\nexport interface ModelUsageFilter {\n route?: string;\n model?: string;\n from?: string;\n to?: string;\n groupBy?: \"route\" | \"model\" | \"day\";\n limit?: number;\n cursor?: string;\n}\nexport interface ModelCatalogFilter {\n provider?: string;\n status?: string;\n limit?: number;\n cursor?: string;\n}\nexport interface ModelCatalogPage {\n models: Model[];\n nextCursor: string | null;\n}\n\nexport const modelCatalogKey = (filter: ModelCatalogFilter = {}) =>\n [\"model-catalog\", filter] as const;\nexport const modelProvidersKey = [\"model-providers\"] as const;\nexport const modelRoutesKey = (projectId?: string) => [\"model-routes\", projectId] as const;\nexport const modelBudgetsKey = (projectId?: string) => [\"model-budgets\", projectId] as const;\nexport const modelBudgetUsageKey = (id: string, projectId?: string) =>\n [\"model-budget-usage\", id, projectId] as const;\nexport const modelUsageKey = (projectId?: string, filter: ModelUsageFilter = {}) =>\n [\"model-usage\", projectId, filter] as const;\n\nexport async function listModelCatalog(\n client: W6WClient,\n filter: ModelCatalogFilter = {},\n): Promise<ModelCatalogPage> {\n // Tenant-wide: deliberately no `project` here.\n const res = await client.request<ModelCatalogPage>({\n method: \"GET\",\n path: \"/models\",\n query: { ...filter },\n });\n return res.body;\n}\n\n/** One row of `GET /models/providers` — the descriptor the model pickers are driven by. */\nexport interface ModelProviderRow {\n appId: string;\n provider: string | null;\n installed: boolean;\n designation?: { modelTypes: string[]; modelFamilies?: string[] } | null;\n operations?: {\n discover: { supported: boolean; reason?: string };\n complete: {\n supported: boolean;\n reason?: string;\n features?: Partial<Record<ModelFeature, ModelFeatureState>>;\n };\n };\n /** A2 (optional): the bridge adapter serving this app; `null` = none. */\n adapter?: { provider: string; contractVersion: number } | null;\n /** A2 (optional): why this app cannot serve the caller right now. */\n reasons?: ModelProviderReason[];\n}\nexport type ModelFeature = \"toolCalls\" | \"structuredOutput\" | \"streaming\";\nexport type ModelFeatureState = \"supported\" | \"unsupported\" | \"unknown\";\nexport type ModelProviderReasonCode =\n | \"not_installed\"\n | \"no_adapter\"\n | \"not_entitled\"\n | \"no_connection\";\nexport interface ModelProviderReason {\n code: ModelProviderReasonCode;\n message: string;\n}\nexport interface CompleteSupport {\n supported: boolean;\n features: Partial<Record<ModelFeature, ModelFeatureState>>;\n reasons: ModelProviderReason[];\n}\n\n/**\n * THE support policy for `operations.complete`. Unsupported when the descriptor says so or the\n * row names no adapter (`adapter: null`); a pre-A2 row (no `adapter`/`features`/`reasons`) falls\n * back to `operations.complete.supported`. Unsupported rows always carry a reason.\n */\nexport function completeSupport(row: ModelProviderRow): CompleteSupport {\n const op = row.operations?.complete;\n const noAdapter = row.adapter === null;\n const supported = op?.supported === true && !noAdapter;\n const reasons = [...(row.reasons ?? [])];\n if (!supported && reasons.length === 0) {\n reasons.push({\n code:\n noAdapter || op?.supported === true\n ? \"no_adapter\"\n : row.installed\n ? \"no_adapter\"\n : \"not_installed\",\n message: op?.reason ?? \"Not supported for this provider\",\n });\n }\n return { supported, features: op?.features ?? {}, reasons };\n}\n\n/** Follow `nextCursor` until null (or `maxPages`), concatenating `models`. */\nexport async function loadAllModelCatalogPages(\n fetchPage: (cursor?: string) => Promise<ModelCatalogPage>,\n opts: { maxPages?: number } = {},\n): Promise<{ models: Model[]; truncated: boolean }> {\n const maxPages = opts.maxPages ?? 50;\n const models: Model[] = [];\n let cursor: string | undefined;\n for (let i = 0; i < maxPages; i++) {\n const page = await fetchPage(cursor);\n models.push(...page.models);\n if (!page.nextCursor) return { models, truncated: false };\n cursor = page.nextCursor;\n }\n return { models, truncated: true };\n}\nexport type ModelOperation = \"discover\" | \"complete\";\nexport interface ConnectionChoice {\n id: string;\n appId: string;\n displayName: string;\n /** Present only when the descriptor says the operation is unsupported for this provider. */\n disabledReason?: string;\n}\n\nexport async function listModelProviders(client: W6WClient): Promise<ModelProviderRow[]> {\n const res = await client.request<{ providers?: ModelProviderRow[] } | ModelProviderRow[]>({\n method: \"GET\",\n path: \"/models/providers\",\n });\n const b = res.body;\n return Array.isArray(b) ? b : (b?.providers ?? []);\n}\n\n/**\n * The connections a model picker may offer for `operation`, decided by the descriptor alone:\n * a connection whose app has no designated provider row never appears (an `ai`-category app is\n * not a provider); a designated row whose `discover` is unsupported appears disabled with the\n * descriptor's reason; for `complete` the shared `completeSupport` policy decides (unsupported => disabled, never selectable).\n */\nexport function connectionChoices<C extends { id: string; appId: string; displayName: string }>(\n connections: C[],\n providers: ModelProviderRow[],\n operation: ModelOperation,\n): ConnectionChoice[] {\n const byApp = new Map<string, ModelProviderRow>();\n for (const p of providers) if (p.designation) byApp.set(p.appId, p);\n const out: ConnectionChoice[] = [];\n for (const c of connections) {\n const row = byApp.get(c.appId);\n if (!row) continue;\n const op = row.operations?.[operation];\n const choice: ConnectionChoice = { id: c.id, appId: c.appId, displayName: c.displayName };\n if (operation === \"complete\") {\n const sup = completeSupport(row);\n if (!sup.supported) {\n choice.disabledReason =\n op?.reason ?? sup.reasons[0]?.message ?? \"Not supported for this provider\";\n }\n } else if (!op?.supported) {\n choice.disabledReason = op?.reason ?? \"Not supported for this provider\";\n }\n out.push(choice);\n }\n return out;\n}\n\n/** The server answers fallbacks as `{modelId, connectionId}`; the editor works in `{model, connection}`. */\nexport function normaliseRoute(r: ModelRoute): ModelRoute {\n const fallbacks = (r.fallbacks ?? []).map((f) => {\n const x = f as ModelFallback & { modelId?: string; connectionId?: string };\n return { model: x.model ?? x.modelId ?? \"\", connection: x.connection ?? x.connectionId ?? \"\" };\n });\n return { ...r, fallbacks };\n}\n\nexport async function listModelRoutes(client: W6WClient, project: string): Promise<ModelRoute[]> {\n const res = await client.request<{ routes: ModelRoute[] }>({\n method: \"GET\",\n path: \"/model-routes\",\n query: { project },\n });\n return res.body.routes.map(normaliseRoute);\n}\nexport async function createModelRoute(\n client: W6WClient,\n project: string,\n input: ModelRouteInput,\n): Promise<ModelRoute> {\n const res = await client.request<{ route: ModelRoute }>({\n method: \"POST\",\n path: \"/model-routes\",\n query: { project },\n body: input,\n });\n return normaliseRoute(res.body.route);\n}\nexport async function updateModelRoute(\n client: W6WClient,\n project: string,\n name: string,\n patch: ModelRoutePatch,\n): Promise<ModelRoute> {\n const res = await client.request<{ route: ModelRoute }>({\n method: \"PATCH\",\n path: path`/model-routes/${name}`,\n query: { project },\n body: patch,\n });\n return normaliseRoute(res.body.route);\n}\n/**\n * One content block (the bridge dialect): text, or a `tool-call` the model made, or the\n * `tool-result` sent back for it. Other block kinds pass through untyped.\n */\nexport type ModelCompletionBlock =\n | { type: \"text\"; text: string }\n | { type: \"tool-call\"; id: string; name: string; input: unknown; arguments?: string }\n | { type: \"tool-result\"; id: string; content: string | ModelCompletionBlock[] }\n | { type: string; [key: string]: unknown };\n/** One chat message for a route completion (the bridge dialect). */\nexport interface ModelCompletionMessage {\n role: \"system\" | \"user\" | \"assistant\";\n content: string | unknown[];\n}\n/** A function the model may call: a name, what it is for, and a JSON Schema for its input. */\nexport interface ModelCompletionTool {\n type: \"function\";\n name: string;\n description?: string;\n /** A JSON Schema object (`{ type: \"object\", properties, required? }`). */\n inputSchema: object;\n}\n/** A route completion request: the messages plus the agent's model options and tools. */\nexport interface ModelCompletionInput {\n messages: ModelCompletionMessage[];\n temperature?: number;\n topP?: number;\n maxOutputTokens?: number;\n stop?: string[];\n tools?: ModelCompletionTool[];\n toolChoice?: \"auto\" | \"none\" | \"required\" | { name: string };\n}\n/** The parts of the completion envelope a caller reads (`response=output`, no raw). */\nexport interface ModelCompletionResult {\n provider: string;\n model: string;\n route: string | null;\n output?: {\n choices?: {\n message?: { content?: string | ModelCompletionBlock[] };\n finishReason?: string;\n }[];\n };\n usageSummary?: { inclusiveInputTokens?: number; outputTokens?: number; totalTokens?: number };\n durationMs?: number;\n}\n/** `POST /model-routes/{name}/complete` — calls the route's model once (billed like any call). */\nexport async function completeModelRoute(\n client: W6WClient,\n project: string,\n name: string,\n input: ModelCompletionInput,\n): Promise<ModelCompletionResult> {\n const res = await client.request<ModelCompletionResult>({\n method: \"POST\",\n path: path`/model-routes/${name}/complete`,\n query: { project, response: \"output\" },\n body: input,\n });\n return res.body;\n}\nexport async function deleteModelRoute(\n client: W6WClient,\n project: string,\n name: string,\n): Promise<void> {\n await client.request<{ ok: true }>({\n method: \"DELETE\",\n path: path`/model-routes/${name}`,\n query: { project },\n });\n}\n\nexport async function listModelBudgets(client: W6WClient, project: string): Promise<ModelBudget[]> {\n const res = await client.request<{ budgets: ModelBudget[] }>({\n method: \"GET\",\n path: \"/model-budgets\",\n query: { project },\n });\n return res.body.budgets;\n}\nexport async function createModelBudget(\n client: W6WClient,\n project: string,\n input: ModelBudgetInput,\n): Promise<ModelBudget> {\n // The server answers with the budget row itself (201), not a `{ budget }` wrapper.\n const res = await client.request<ModelBudget>({\n method: \"POST\",\n path: \"/model-budgets\",\n query: { project },\n body: input,\n });\n return res.body;\n}\nexport async function updateModelBudget(\n client: W6WClient,\n project: string,\n id: string,\n patch: ModelBudgetPatch,\n): Promise<ModelBudget> {\n // The server answers with the updated budget row itself, not a `{ budget }` wrapper.\n const res = await client.request<ModelBudget>({\n method: \"PATCH\",\n path: path`/model-budgets/${id}`,\n query: { project },\n body: patch,\n });\n return res.body;\n}\nexport async function deleteModelBudget(\n client: W6WClient,\n project: string,\n id: string,\n): Promise<void> {\n await client.request<{ ok: true }>({\n method: \"DELETE\",\n path: path`/model-budgets/${id}`,\n query: { project },\n });\n}\nexport async function getModelBudgetUsage(\n client: W6WClient,\n project: string,\n id: string,\n): Promise<ModelBudgetUsage> {\n const res = await client.request<ModelBudgetUsage>({\n method: \"GET\",\n path: path`/model-budgets/${id}/usage`,\n query: { project },\n });\n return res.body;\n}\nexport async function getModelUsage(\n client: W6WClient,\n project: string,\n filter: ModelUsageFilter = {},\n): Promise<ModelUsageReport> {\n const res = await client.request<ModelUsageReport>({\n method: \"GET\",\n path: \"/model-usage\",\n query: { project, ...filter },\n });\n return res.body;\n}\n\n/** What `POST /models/discover` changed in the tenant catalog — model ids per bucket. */\nexport interface ModelDiscoverResult {\n added: string[];\n updated: string[];\n deprecated: string[];\n}\n/**\n * Ask the provider behind `connection` for its model list and fold it into the tenant catalog.\n * Tenant administration only: anyone else gets a 403 `forbidden`.\n */\nexport async function discoverModels(\n client: W6WClient,\n connection: string,\n): Promise<ModelDiscoverResult> {\n const res = await client.request<ModelDiscoverResult>({\n method: \"POST\",\n path: \"/models/discover\",\n body: { connection },\n });\n return res.body;\n}\n\nexport function useModelCatalogQuery(filter: ModelCatalogFilter = {}) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelCatalogKey(filter),\n queryFn: () => listModelCatalog(client, filter),\n });\n}\nexport function useAllModelCatalogQuery(filter: Omit<ModelCatalogFilter, \"cursor\"> = {}) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: [\"model-catalog-all\", filter] as const,\n queryFn: () =>\n loadAllModelCatalogPages((cursor) => listModelCatalog(client, { ...filter, cursor })),\n });\n}\nexport function useModelProvidersQuery() {\n const client = useEmbedClient();\n return useQuery({ queryKey: modelProvidersKey, queryFn: () => listModelProviders(client) });\n}\nexport function useModelRoutesQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelRoutesKey(projectId),\n enabled: projectId != null,\n queryFn: () => listModelRoutes(client, projectId as string),\n });\n}\nexport function useModelBudgetsQuery(projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelBudgetsKey(projectId),\n enabled: projectId != null,\n queryFn: () => listModelBudgets(client, projectId as string),\n });\n}\nexport function useModelBudgetUsageQuery(id: string, projectId?: string) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelBudgetUsageKey(id, projectId),\n enabled: projectId != null,\n queryFn: () => getModelBudgetUsage(client, projectId as string, id),\n });\n}\nexport function useModelUsageQuery(projectId?: string, filter: ModelUsageFilter = {}) {\n const client = useEmbedClient();\n return useQuery({\n queryKey: modelUsageKey(projectId, filter),\n enabled: projectId != null,\n queryFn: () => getModelUsage(client, projectId as string, filter),\n });\n}\n\nexport function useDiscoverModelsMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (connection: string) => discoverModels(client, connection),\n onSuccess: async () => {\n await Promise.all([\n qc.invalidateQueries({ queryKey: [\"model-catalog\"] }),\n qc.invalidateQueries({ queryKey: [\"model-catalog-all\"] }),\n ]);\n },\n });\n}\nexport function useCreateModelRouteMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; input: ModelRouteInput }) =>\n createModelRoute(client, v.project, v.input),\n // The agent editor lists routes under its own key; a new route belongs in both lists.\n onSuccess: () =>\n Promise.all([\n qc.invalidateQueries({ queryKey: [\"model-routes\"] }),\n qc.invalidateQueries({ queryKey: [\"agents\", \"model-routes\"] }),\n ]),\n });\n}\nexport function useUpdateModelRouteMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; name: string; patch: ModelRoutePatch }) =>\n updateModelRoute(client, v.project, v.name, v.patch),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-routes\"] }),\n });\n}\nexport function useCompleteModelRouteMutation() {\n const client = useEmbedClient();\n return useMutation({\n mutationFn: (v: { project: string; name: string; input: ModelCompletionInput }) =>\n completeModelRoute(client, v.project, v.name, v.input),\n });\n}\nexport function useDeleteModelRouteMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; name: string }) =>\n deleteModelRoute(client, v.project, v.name),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-routes\"] }),\n });\n}\nexport function useCreateModelBudgetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; input: ModelBudgetInput }) =>\n createModelBudget(client, v.project, v.input),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-budgets\"] }),\n });\n}\nexport function useUpdateModelBudgetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; id: string; patch: ModelBudgetPatch }) =>\n updateModelBudget(client, v.project, v.id, v.patch),\n // The row meter reads its limit from the per-budget usage query, so refresh it too.\n onSuccess: (_b, v) =>\n Promise.all([\n qc.invalidateQueries({ queryKey: [\"model-budgets\"] }),\n qc.invalidateQueries({ queryKey: [\"model-budget-usage\", v.id] }),\n ]),\n });\n}\nexport function useDeleteModelBudgetMutation() {\n const client = useEmbedClient();\n const qc = useQueryClient();\n return useMutation({\n mutationFn: (v: { project: string; id: string }) => deleteModelBudget(client, v.project, v.id),\n onSuccess: () => qc.invalidateQueries({ queryKey: [\"model-budgets\"] }),\n });\n}\n"],"names":["modelCatalogKey","filter","modelProvidersKey","modelRoutesKey","projectId","modelBudgetsKey","modelBudgetUsageKey","id","modelUsageKey","listModelCatalog","client","completeSupport","row","op","_a","noAdapter","supported","reasons","loadAllModelCatalogPages","fetchPage","opts","maxPages","models","cursor","i","page","listModelProviders","b","connectionChoices","connections","providers","operation","byApp","p","out","c","choice","sup","_b","normaliseRoute","r","fallbacks","f","x","listModelRoutes","project","createModelRoute","input","res","updateModelRoute","name","patch","path","completeModelRoute","deleteModelRoute","listModelBudgets","createModelBudget","updateModelBudget","deleteModelBudget","getModelBudgetUsage","getModelUsage","discoverModels","connection","useModelCatalogQuery","useEmbedClient","useQuery","useAllModelCatalogQuery","useModelProvidersQuery","useModelRoutesQuery","useModelBudgetsQuery","useModelBudgetUsageQuery","useModelUsageQuery","useDiscoverModelsMutation","qc","useQueryClient","useMutation","useCreateModelRouteMutation","v","useUpdateModelRouteMutation","useCompleteModelRouteMutation","useDeleteModelRouteMutation","useCreateModelBudgetMutation","useUpdateModelBudgetMutation","useDeleteModelBudgetMutation"],"mappings":";;;AA4KO,MAAMA,IAAkB,CAACC,IAA6B,OAC3D,CAAC,iBAAiBA,CAAM,GACbC,IAAoB,CAAC,iBAAiB,GACtCC,IAAiB,CAACC,MAAuB,CAAC,gBAAgBA,CAAS,GACnEC,IAAkB,CAACD,MAAuB,CAAC,iBAAiBA,CAAS,GACrEE,IAAsB,CAACC,GAAYH,MAC9C,CAAC,sBAAsBG,GAAIH,CAAS,GACzBI,IAAgB,CAACJ,GAAoBH,IAA2B,CAAA,MAC3E,CAAC,eAAeG,GAAWH,CAAM;AAEnC,eAAsBQ,EACpBC,GACAT,IAA6B,I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
3
  import { useMemo as u } from "react";
4
- import { W as d, R as p, P as m, u as f, a as v, e as b, b as h } from "./editor-tools-DHyWiG21.js";
4
+ import { W as d, R as p, P as m, u as f, a as v, e as b, b as h } from "./editor-tools-Brw0cv2F.js";
5
5
  import { r as P, a as j } from "./project-context-Tvp-La7A.js";
6
6
  const R = () => {
7
7
  };
@@ -1,5 +1,5 @@
1
- import { Agent, ApiError, ContextEntry, ContextPin, CreateAgentInput, SkillPin, SkillVersion, UpdateAgentInput, W6WClient } from '@w6w/sdk';
2
- export type { Agent, ContextEntry, ContextPin, CreateAgentInput, SkillPin, SkillVersion, UpdateAgentInput, };
1
+ import { Agent, AgentTool, ApiError, ContextEntry, ContextPin, CreateAgentInput, SkillPin, SkillVersion, UpdateAgentInput, W6WClient } from '@w6w/sdk';
2
+ export type { Agent, AgentTool, ContextEntry, ContextPin, CreateAgentInput, SkillPin, SkillVersion, UpdateAgentInput, };
3
3
  /** Thrown by {@linkcode updateAgent} on a 409: the draft changed elsewhere. Never overwrites. */
4
4
  export declare class AgentConflictError extends Error {
5
5
  readonly kind: "conflict";
@@ -50,3 +50,47 @@ export declare function useAgentModelRoutesQuery(projectId?: string): import('@t
50
50
  export declare function useAgentSettingsQuery(): import('@tanstack/react-query').UseQueryResult<NoInfer<import('@w6w/sdk/console').AgentSettings>, Error>;
51
51
  export declare function usePatchAgentSettings(): import('@tanstack/react-query').UseMutationResult<import('@w6w/sdk/console').AgentSettings, Error, Partial<import('@w6w/sdk/console').AgentSettingsValues>, unknown>;
52
52
  export declare function useStorageBindingsQuery(): import('@tanstack/react-query').UseQueryResult<NoInfer<import('@w6w/sdk/console').StorageBinding[]>, Error>;
53
+ /** One message of a Test conversation, as the model contract has it. */
54
+ export interface AgentTestTurn {
55
+ role: "user" | "assistant";
56
+ content: unknown;
57
+ }
58
+ export interface AgentTestRequest {
59
+ project: string;
60
+ message: string;
61
+ /** The `turns` of earlier answers, so a follow-up keeps the conversation. */
62
+ history?: AgentTestTurn[];
63
+ /** Unsaved form state laid over the stored agent. */
64
+ draft?: {
65
+ instructions?: string;
66
+ modelRouteId?: string | null;
67
+ modelOptions?: Record<string, unknown>;
68
+ tools?: AgentTool[];
69
+ };
70
+ }
71
+ export interface AgentTestToolCall {
72
+ tool: string;
73
+ input: Record<string, unknown>;
74
+ ok: boolean;
75
+ /** The tool's output, or the error message when `ok` is false. */
76
+ output: unknown;
77
+ }
78
+ export interface AgentTestResult {
79
+ text: string;
80
+ turns: AgentTestTurn[];
81
+ toolCalls: AgentTestToolCall[];
82
+ model: string | null;
83
+ rounds: number;
84
+ usage: {
85
+ inputTokens: number;
86
+ outputTokens: number;
87
+ };
88
+ finishReason: string | null;
89
+ }
90
+ /**
91
+ * Run the agent once on a message through the server's agent runtime — the same one a workflow's
92
+ * "Run agent" step uses, so tools run there (fixed values resolved server-side, only the AI fields
93
+ * passed on). Real, billed model and tool calls. Through `client.request` (Studio-internal route).
94
+ */
95
+ export declare function testAgent(client: W6WClient, id: string, body: AgentTestRequest): Promise<AgentTestResult>;
96
+ export declare function useTestAgentMutation(id: string): import('@tanstack/react-query').UseMutationResult<AgentTestResult, Error, AgentTestRequest, unknown>;
@@ -1,9 +1,10 @@
1
1
  import { QueryClient } from '@tanstack/react-query';
2
2
  import { W6WClient } from '@w6w/sdk';
3
- import { CredentialDependents, CredentialListFilter, CredentialSummary, CredentialTestResult } from '@w6w/sdk/console';
4
- export type { CredentialDependents, CredentialListFilter, CredentialSummary, CredentialTestResult, } from '@w6w/sdk/console';
3
+ import { CredentialDependents, CredentialListFilter, CredentialSummary, CredentialTestResult, CredentialTypeDescriptor } from '@w6w/sdk/console';
4
+ export type { CredentialDependents, CredentialListFilter, CredentialSummary, CredentialTestResult, CredentialTypeDescriptor, CredentialTypeField, } from '@w6w/sdk/console';
5
5
  export declare const credentialsKey: readonly ["credentials"];
6
6
  export declare const credentialKey: (id: string) => readonly ["credential", string];
7
+ export declare const credentialTypesKey: readonly ["credential-types"];
7
8
  export declare const credentialDependentsKey: (id: string) => readonly ["credential-dependents", string];
8
9
  /**
9
10
  * A credential write (rotate, enable/disable, delete) changes what every connection on it
@@ -11,6 +12,8 @@ export declare const credentialDependentsKey: (id: string) => readonly ["credent
11
12
  */
12
13
  export declare function invalidateAfterCredentialWrite(qc: QueryClient, id: string): void;
13
14
  export declare function listCredentials(client: W6WClient, filter?: CredentialListFilter): Promise<CredentialSummary[]>;
15
+ /** The credential types the server can store and the fields each collects, in server order. */
16
+ export declare function listCredentialTypes(client: W6WClient): Promise<CredentialTypeDescriptor[]>;
14
17
  export declare function getCredential(client: W6WClient, id: string): Promise<CredentialSummary>;
15
18
  export declare function createCredential(client: W6WClient, body: {
16
19
  name: string;
@@ -39,7 +42,18 @@ export type DeleteCredentialResult = {
39
42
  * Wire (RECONCILE R-11): `{ error: { code, message, dependents: { connections } } }`.
40
43
  */
41
44
  export declare function deleteCredential(client: W6WClient, id: string): Promise<DeleteCredentialResult>;
45
+ /**
46
+ * Fixed, secret-free text for a failed credential write, chosen by the server's status / error
47
+ * code. The server's own message is never shown: a value the user typed could be echoed in it.
48
+ */
49
+ export declare function credentialWriteErrorText(e: unknown, verb: "create" | "rotate"): string;
42
50
  export declare function useCredentialsQuery(filter?: CredentialListFilter): import('@tanstack/react-query').UseQueryResult<NoInfer<CredentialSummary[]>, Error>;
51
+ /**
52
+ * The descriptors that drive the create form, the list's type label and the rotate fields. They
53
+ * change only with a server release, so they are cached for the session; a failure is not retried
54
+ * (the callers degrade to the contract id / the JSON rotate box).
55
+ */
56
+ export declare function useCredentialTypesQuery(): import('@tanstack/react-query').UseQueryResult<NoInfer<CredentialTypeDescriptor[]>, Error>;
43
57
  export declare function useCredentialQuery(id: string): import('@tanstack/react-query').UseQueryResult<NoInfer<CredentialSummary>, Error>;
44
58
  export declare function useCredentialDependentsQuery(id: string, enabled?: boolean): import('@tanstack/react-query').UseQueryResult<NoInfer<CredentialDependents>, Error>;
45
59
  export declare function useCreateCredentialMutation(): import('@tanstack/react-query').UseMutationResult<CredentialSummary, Error, {
@@ -244,18 +244,51 @@ export declare function normaliseRoute(r: ModelRoute): ModelRoute;
244
244
  export declare function listModelRoutes(client: W6WClient, project: string): Promise<ModelRoute[]>;
245
245
  export declare function createModelRoute(client: W6WClient, project: string, input: ModelRouteInput): Promise<ModelRoute>;
246
246
  export declare function updateModelRoute(client: W6WClient, project: string, name: string, patch: ModelRoutePatch): Promise<ModelRoute>;
247
+ /**
248
+ * One content block (the bridge dialect): text, or a `tool-call` the model made, or the
249
+ * `tool-result` sent back for it. Other block kinds pass through untyped.
250
+ */
251
+ export type ModelCompletionBlock = {
252
+ type: "text";
253
+ text: string;
254
+ } | {
255
+ type: "tool-call";
256
+ id: string;
257
+ name: string;
258
+ input: unknown;
259
+ arguments?: string;
260
+ } | {
261
+ type: "tool-result";
262
+ id: string;
263
+ content: string | ModelCompletionBlock[];
264
+ } | {
265
+ type: string;
266
+ [key: string]: unknown;
267
+ };
247
268
  /** One chat message for a route completion (the bridge dialect). */
248
269
  export interface ModelCompletionMessage {
249
270
  role: "system" | "user" | "assistant";
250
- content: string;
271
+ content: string | unknown[];
272
+ }
273
+ /** A function the model may call: a name, what it is for, and a JSON Schema for its input. */
274
+ export interface ModelCompletionTool {
275
+ type: "function";
276
+ name: string;
277
+ description?: string;
278
+ /** A JSON Schema object (`{ type: "object", properties, required? }`). */
279
+ inputSchema: object;
251
280
  }
252
- /** A route completion request: the messages plus the agent's model options. */
281
+ /** A route completion request: the messages plus the agent's model options and tools. */
253
282
  export interface ModelCompletionInput {
254
283
  messages: ModelCompletionMessage[];
255
284
  temperature?: number;
256
285
  topP?: number;
257
286
  maxOutputTokens?: number;
258
287
  stop?: string[];
288
+ tools?: ModelCompletionTool[];
289
+ toolChoice?: "auto" | "none" | "required" | {
290
+ name: string;
291
+ };
259
292
  }
260
293
  /** The parts of the completion envelope a caller reads (`response=output`, no raw). */
261
294
  export interface ModelCompletionResult {
@@ -265,10 +298,7 @@ export interface ModelCompletionResult {
265
298
  output?: {
266
299
  choices?: {
267
300
  message?: {
268
- content?: string | {
269
- type: string;
270
- text?: string;
271
- }[];
301
+ content?: string | ModelCompletionBlock[];
272
302
  };
273
303
  finishReason?: string;
274
304
  }[];