@kitsuden/shared 0.0.0-stage → 0.9.0-beta

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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/dist/admin-registry-contract.d.ts +99 -0
  4. package/dist/admin-registry-contract.d.ts.map +1 -0
  5. package/dist/admin-view.d.ts +123 -0
  6. package/dist/admin-view.d.ts.map +1 -0
  7. package/dist/agent-permission.d.ts +161 -0
  8. package/dist/agent-permission.d.ts.map +1 -0
  9. package/dist/approvals.d.ts +164 -0
  10. package/dist/approvals.d.ts.map +1 -0
  11. package/dist/automation.d.ts +175 -0
  12. package/dist/automation.d.ts.map +1 -0
  13. package/dist/block-keys.d.ts +82 -0
  14. package/dist/block-keys.d.ts.map +1 -0
  15. package/dist/code-scan.d.ts +64 -0
  16. package/dist/code-scan.d.ts.map +1 -0
  17. package/dist/comment-subjects.d.ts +129 -0
  18. package/dist/comment-subjects.d.ts.map +1 -0
  19. package/dist/connections.d.ts +96 -0
  20. package/dist/connections.d.ts.map +1 -0
  21. package/dist/constants.d.ts +37 -0
  22. package/dist/constants.d.ts.map +1 -0
  23. package/dist/content-publishing.d.ts +34 -0
  24. package/dist/content-publishing.d.ts.map +1 -0
  25. package/dist/contracts.d.ts +87 -0
  26. package/dist/contracts.d.ts.map +1 -0
  27. package/dist/dataset-catalog.d.ts +91 -0
  28. package/dist/dataset-catalog.d.ts.map +1 -0
  29. package/dist/deck-analysis.d.ts +63 -0
  30. package/dist/deck-analysis.d.ts.map +1 -0
  31. package/dist/env.d.ts +2 -0
  32. package/dist/env.d.ts.map +1 -0
  33. package/dist/errors.d.ts +275 -0
  34. package/dist/errors.d.ts.map +1 -0
  35. package/dist/field-types.d.ts +304 -0
  36. package/dist/field-types.d.ts.map +1 -0
  37. package/dist/index.d.ts +79 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +7785 -0
  40. package/dist/kon-api.d.ts +914 -0
  41. package/dist/kon-api.d.ts.map +1 -0
  42. package/dist/kon-entities.d.ts +204 -0
  43. package/dist/kon-entities.d.ts.map +1 -0
  44. package/dist/kon-events.d.ts +103 -0
  45. package/dist/kon-events.d.ts.map +1 -0
  46. package/dist/kon-package.d.ts +124 -0
  47. package/dist/kon-package.d.ts.map +1 -0
  48. package/dist/link-relations.d.ts +73 -0
  49. package/dist/link-relations.d.ts.map +1 -0
  50. package/dist/meta-levels.d.ts +81 -0
  51. package/dist/meta-levels.d.ts.map +1 -0
  52. package/dist/models-sql.d.ts +110 -0
  53. package/dist/models-sql.d.ts.map +1 -0
  54. package/dist/models.d.ts +354 -0
  55. package/dist/models.d.ts.map +1 -0
  56. package/dist/operations.d.ts +428 -0
  57. package/dist/operations.d.ts.map +1 -0
  58. package/dist/promotion.d.ts +244 -0
  59. package/dist/promotion.d.ts.map +1 -0
  60. package/dist/public-site.d.ts +106 -0
  61. package/dist/public-site.d.ts.map +1 -0
  62. package/dist/render-blocks.d.ts +150 -0
  63. package/dist/render-blocks.d.ts.map +1 -0
  64. package/dist/reports.d.ts +109 -0
  65. package/dist/reports.d.ts.map +1 -0
  66. package/dist/rls-builder.d.ts +136 -0
  67. package/dist/rls-builder.d.ts.map +1 -0
  68. package/dist/safe-pattern.d.ts +47 -0
  69. package/dist/safe-pattern.d.ts.map +1 -0
  70. package/dist/schemas.d.ts +977 -0
  71. package/dist/schemas.d.ts.map +1 -0
  72. package/dist/sensitivity.d.ts +37 -0
  73. package/dist/sensitivity.d.ts.map +1 -0
  74. package/dist/signer.d.ts +67 -0
  75. package/dist/signer.d.ts.map +1 -0
  76. package/dist/tier-ranges.d.ts +37 -0
  77. package/dist/tier-ranges.d.ts.map +1 -0
  78. package/dist/types.d.ts +261 -0
  79. package/dist/types.d.ts.map +1 -0
  80. package/dist/utils.d.ts +71 -0
  81. package/dist/utils.d.ts.map +1 -0
  82. package/dist/wiki-links.d.ts +56 -0
  83. package/dist/wiki-links.d.ts.map +1 -0
  84. package/package.json +53 -3
@@ -0,0 +1,428 @@
1
+ /**
2
+ * Kon SDK — the CONTRACT of an operation (version 1)
3
+ * ============================================================================
4
+ *
5
+ * A kon declares its operations ONCE and the core generates from that
6
+ * declaration:
7
+ *
8
+ * - the REST route (with 422 problem+json validation, authorization by scope and
9
+ * by the kon's policy, idempotency and per-request RLS inherited);
10
+ * - the OpenAPI 3.1 operation with real schemas (zod → JSON Schema);
11
+ * - the MCP tool with the same schemas, which inherits the scopes and the
12
+ * `allowedTools` list of the agent's session.
13
+ *
14
+ * Only what is CONTRACT and pure lives here (types, names, permission
15
+ * resolution): it is shared by the engine (which mounts the routes), the API (OpenAPI and
16
+ * MCP), the panel (what each scope grants) and the coverage tests. The
17
+ * execution engine lives in `@kitsuden/engine` (`defineKonSdk`).
18
+ *
19
+ * The contract version is published in `GET /api/version` as
20
+ * `contracts["kon-sdk"]` (see `contracts.ts`). Adding an OPTIONAL field to the
21
+ * declaration is compatible; renaming one, changing a default value that
22
+ * changes behavior (e.g. `sensitive`) or the format of a tool name or of a
23
+ * fine scope is NOT.
24
+ *
25
+ * Public guide: docs/kons/README.md.
26
+ */
27
+ import type { Context, MiddlewareHandler } from "hono";
28
+ import { z, type ZodTypeAny } from "zod";
29
+ import { scopeCovers } from "./agent-permission";
30
+ import { type KitsudenErrorCode } from "./errors";
31
+ import type { KonContext } from "./kon-api";
32
+ export { scopeCovers };
33
+ /** Version of the kon SDK contract (integer: bumped only if something breaks). */
34
+ export declare const KONS_SDK_VERSION = 1;
35
+ export type OperationMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
36
+ /**
37
+ * Who can REACH the operation, before the policy:
38
+ *
39
+ * public no credential (the request may carry one and it is used if present).
40
+ * optional same as `public`, but the operation looks at who it is (drafts
41
+ * for the team, for example). Documented that way in OpenAPI.
42
+ * session a verified account or agent is required: without one, 401.
43
+ */
44
+ export type OperationAccess = "public" | "optional" | "session";
45
+ /**
46
+ * What is needed, besides reaching it, to execute the operation. It is a UNION:
47
+ * it is enough for ONE of the routes to be satisfied.
48
+ *
49
+ * 1. The operation's fine scope: `kon:<kon>:<operation>` (and its wildcards
50
+ * `kon:<kon>:*`, `kon:*`), or the kon's broad one `<kon>:*`. Only agents
51
+ * carry them.
52
+ * 2. One of `scopes` (broad, e.g. `content:edit`), with the usual
53
+ * wildcard rules (`resource:*`, `*:action`).
54
+ * 3. `admin` / `admin:*`.
55
+ * 4. The kon's policy (`definePolicy`): `can(user, action, resource,
56
+ * type)`, which also grants the scope `<type>:<action>`.
57
+ * 5. `roles`: the account's role is in the list.
58
+ *
59
+ * A fine scope never TAKES AWAY what a broad one grants (everything is a union). The
60
+ * only thing that takes away is an explicit DENIAL by the agent (`!kon:<kon>:<op>`,
61
+ * `!<kon>:*`, `!datasets:<slug>:<action>`…), which beats everything above,
62
+ * `admin` and roles included (see docs/agents/permissions.md).
63
+ */
64
+ export interface OperationPermission {
65
+ /** Broad scopes that also grant the operation. */
66
+ scopes?: string[];
67
+ /** The kon's policy. */
68
+ policy?: {
69
+ resource: string;
70
+ action: string;
71
+ /**
72
+ * `true`: the policy needs the resource (the dataset, the entry…) and the
73
+ * handler checks it with `h.authorize(resource)` after loading it. Without this,
74
+ * it is checked BEFORE validating and executing, with an empty resource.
75
+ */
76
+ inHandler?: boolean;
77
+ };
78
+ /** Account roles that grant it (e.g. `["admin"]`). */
79
+ roles?: string[];
80
+ /**
81
+ * The RESOURCE scope that also grants the operation (and that a
82
+ * denial can take away): `datasets:<slug>:write`. It is computed from the
83
+ * input and, in `policy.inHandler` operations, from the resource the
84
+ * handler passes to `h.authorize(resource)`. Returning `null` = this request has no
85
+ * resource scope.
86
+ */
87
+ resourceScope?: (input: ValidatedInput, resource?: unknown) => string | null;
88
+ }
89
+ /** How the successful response comes out. */
90
+ export interface OperationOutput {
91
+ /**
92
+ * HTTP success status (200 by default; 201 on create, 204 without a body). A
93
+ * redirect (301, 302, 303, 307, 308) carries no body or schema: the
94
+ * handler returns the `Response` with its `Location` (`c.redirect`).
95
+ */
96
+ status?: SuccessStatus | RedirectStatus;
97
+ /** Body schema (for JSON). Required except with binary `type`, 204 or 3xx. */
98
+ schema?: ZodTypeAny;
99
+ /** `application/json` by default; `image/*`, `text/html`… for binary. */
100
+ type?: string;
101
+ description?: string;
102
+ /**
103
+ * Other success statuses with the SAME body, which the handler returns as a
104
+ * ready-made `Response`: an upsert that responds 201 on create and 200 on rewrite.
105
+ * They are only published (OpenAPI); without declaring them, Schemathesis considers the
106
+ * status that is not listed to be broken (kon-tierlist). It can also carry
107
+ * redirects: a read that sends an old slug to the new one with 308.
108
+ */
109
+ otherStatuses?: (200 | 201 | 202 | RedirectStatus)[];
110
+ /**
111
+ * A FLOW: `handle` returns an `AsyncIterable` (the
112
+ * usual case, an `async function*`) and each value it `yield`s goes out as a
113
+ * STANDARD Server-Sent Events event (`text/event-stream`), validated against
114
+ * `schema`, which here is the schema of ONE event. On finishing, an `end` event; if the
115
+ * generator throws, an `error` event with the problem+json. In the SDK the
116
+ * operation returns a typed `AsyncIterable`; over MCP, the list of events.
117
+ *
118
+ * Each step of the generator runs in its own short RLS transaction, with
119
+ * the asker: the flow does not hold a connection while it waits.
120
+ */
121
+ flow?: boolean;
122
+ }
123
+ export type SuccessStatus = 200 | 201 | 202 | 204;
124
+ /** Redirects an operation can declare (they are not errors: they carry no catalog code). */
125
+ export type RedirectStatus = 301 | 302 | 303 | 307 | 308;
126
+ export declare const REDIRECT_STATUSES: readonly RedirectStatus[];
127
+ export declare function isRedirect(status: number | undefined): status is RedirectStatus;
128
+ /** What comes in, in parts. Each part is a zod schema. */
129
+ export interface OperationInput {
130
+ /** Path parameters (`:id`). All text; use `z.string()`/`z.coerce`. */
131
+ params?: ZodTypeAny;
132
+ /** Query string. Arrives as text: use `z.coerce.number()` and similar. */
133
+ query?: ZodTypeAny;
134
+ /** Body. JSON by default. */
135
+ body?: ZodTypeAny;
136
+ /** `multipart`: form with files (not exposed over MCP). */
137
+ format?: "json" | "multipart";
138
+ /**
139
+ * Compatibility: the BODY is validated by the handler with this same schema and
140
+ * it responds with its usual 400 (`{ error: "Validation failed", issues }`). The
141
+ * SDK publishes it (OpenAPI, MCP) but does not validate it, and the handler receives the
142
+ * body exactly as it arrived. Only for kons that already had that contract published;
143
+ * a new one lets the SDK validate (422 problem+json).
144
+ */
145
+ validatesHandler?: boolean;
146
+ }
147
+ /** MCP exposure: yes by default; to exclude you must say why. */
148
+ export type OperationMcp = true | {
149
+ exclude: string;
150
+ } | {
151
+ /** Tool name if the generated one will not do (rare). */
152
+ name?: string;
153
+ };
154
+ /**
155
+ * Arguments of a generated MCP tool: path and query parameters are FLAT,
156
+ * the whole body goes under `body` and the idempotency key
157
+ * under `idempotency_key`. They are contract (an agent stores them).
158
+ */
159
+ export declare const MCP_BODY_ARGUMENT = "body";
160
+ export declare const MCP_IDEMPOTENCY_ARGUMENT = "idempotency_key";
161
+ /**
162
+ * Usage guide for agents: what the schema does NOT say. The schema says what
163
+ * shape the input has; this says when to use the operation, where the ids it
164
+ * asks for come from and how to get out of the typical errors.
165
+ *
166
+ * It exists because the agent's harness (Claude, Cursor, whichever) only sees what
167
+ * the server tells it: a good guide here improves ALL the harnesses
168
+ * that connect, without touching any of them. It is published in the MCP
169
+ * tool's description (the short part), as the MCP resource `kitsuden://guide/<tool>`
170
+ * (all of it) and in OpenAPI as `x-kitsuden-guide`.
171
+ *
172
+ * The examples are VALIDATED against the schemas when the operation is declared: an
173
+ * example that does not validate teaches how to fail.
174
+ */
175
+ export interface OperationDeprecation {
176
+ /** Day it was deprecated (YYYY-MM-DD): the `Deprecation` header. */
177
+ since: string;
178
+ /** Day from which it may be removed (YYYY-MM-DD, after `since`): `Sunset` and `x-sunset`. */
179
+ sunset: string;
180
+ /** Id of the operation of the same kon that replaces it, if there is one. */
181
+ use?: string;
182
+ }
183
+ /** `2026-11-18` → milliseconds at 00:00 UTC, or NaN if it is not a real day. */
184
+ export declare function dayToTime(day: string): number;
185
+ /** The headers of a deprecated operation's responses (RFC 9745 and RFC 8594). */
186
+ export declare function deprecationHeaders(d: OperationDeprecation): Record<string, string>;
187
+ /** One line for humans and agents: "Deprecated: removed after 2027-03-01; use list-posts." */
188
+ export declare function deprecationNote(d: OperationDeprecation, replacement?: string): string;
189
+ export interface OperationGuide {
190
+ /** When to use it, and when NOT to (which other operation applies then). */
191
+ whenToUse?: string;
192
+ /** What is needed beforehand: which operation each id it asks for comes from. */
193
+ before?: string[];
194
+ /**
195
+ * Example arguments, shaped like the MCP tool: flat path and query
196
+ * parameters, the body under `body`.
197
+ */
198
+ examples?: {
199
+ title: string;
200
+ args: Record<string, unknown>;
201
+ }[];
202
+ /** Typical errors and how to get out of them. */
203
+ traps?: {
204
+ if: string;
205
+ then: string;
206
+ }[];
207
+ }
208
+ /** The already validated input the handler receives. */
209
+ export interface ValidatedInput<P = unknown, Q = unknown, B = unknown> {
210
+ params: P;
211
+ query: Q;
212
+ body: B;
213
+ }
214
+ /** User as the operations see them (account or agent). */
215
+ export interface OperationUser {
216
+ id?: string;
217
+ role?: string;
218
+ scopes?: string[];
219
+ [key: string]: unknown;
220
+ }
221
+ /** What the handler receives besides the input. */
222
+ export interface OperationContext {
223
+ /**
224
+ * Hono context of the request (headers, `c.json`, `c.body`…). The validated
225
+ * (and typed) parameters are in `input.params`.
226
+ */
227
+ c: Context;
228
+ /** The kon's context (the request's db, cache, events, storage…). */
229
+ ctx: KonContext;
230
+ /** Who is asking (`null` if nobody). */
231
+ user: OperationUser | null;
232
+ /**
233
+ * Checks the operation's permission with the RESOURCE already loaded (for
234
+ * `policy.inHandler`). Throws 401/403 (AppError) if not granted.
235
+ */
236
+ authorize(resource?: unknown, action?: string): Promise<void>;
237
+ /** Same as `authorize` but returns the result instead of throwing. */
238
+ can(resource?: unknown, action?: string): Promise<boolean>;
239
+ konId: string;
240
+ operation: KonOperation;
241
+ }
242
+ /** The handler's response: the data (served with `output.status`) or a ready-made Response. */
243
+ export type OperationResult = unknown;
244
+ /**
245
+ * The declaration of an operation.
246
+ *
247
+ * Generics: the input schemas, so the handler receives the inferred
248
+ * types without annotating them by hand.
249
+ */
250
+ export interface KonOperation<P extends ZodTypeAny = ZodTypeAny, Q extends ZodTypeAny = ZodTypeAny, B extends ZodTypeAny = ZodTypeAny> {
251
+ /** Stable, kebab-case, unique within the kon: `create-page`. It is contract. */
252
+ id: string;
253
+ method: OperationMethod;
254
+ /** Relative to the kon's mount, with `:param`: `/pages/:id`. */
255
+ route: string;
256
+ /** One line for humans (OpenAPI `summary`). */
257
+ summary: string;
258
+ /** For humans and agents: what it does, when to use it, what it returns. */
259
+ description: string;
260
+ tags?: string[];
261
+ input?: {
262
+ params?: P;
263
+ query?: Q;
264
+ body?: B;
265
+ format?: OperationInput["format"];
266
+ validatesHandler?: boolean;
267
+ };
268
+ output: OperationOutput;
269
+ access: OperationAccess;
270
+ /** Without `permission`, `access` is enough. */
271
+ permission?: OperationPermission;
272
+ /**
273
+ * A sensitive operation, requested by an agent, may end up as a
274
+ * PROPOSAL awaiting a human. By default: `true` on DELETE,
275
+ * `false` on everything else. Today it is only published (OpenAPI and MCP).
276
+ */
277
+ sensitive?: boolean;
278
+ /**
279
+ * A POST that changes nothing (validate, preview, compare, calculate):
280
+ * the SELECTIVE retention of agents in `propose` does not hold it, and MCP
281
+ * announces it with `readOnlyHint`. Only valid on POST (a GET already is one; PUT, PATCH
282
+ * and DELETE write by definition). Default: `false`.
283
+ */
284
+ readOnly?: boolean;
285
+ /**
286
+ * Does repeating the same request leave the same state? By default, HTTP
287
+ * semantics: GET/PUT/DELETE yes, POST/PATCH no. Non-idempotent ones accept
288
+ * `Idempotency-Key` (REST) / `idempotency_key` (MCP).
289
+ */
290
+ idempotent?: boolean;
291
+ /**
292
+ * Errors the operation MAY return besides the automatic ones
293
+ * (validation, authentication, permission, internal). Codes from the catalog.
294
+ */
295
+ errors?: KitsudenErrorCode[];
296
+ /**
297
+ * The operation is on its way out (docs/api-contract.md, deprecation policy).
298
+ * Published as `deprecated: true` + `x-sunset` in the OpenAPI (what oasdiff reads
299
+ * before it lets the operation go), `Deprecation`/`Sunset` headers on every response
300
+ * (RFC 9745, RFC 8594), a first line in the MCP tool description, `@deprecated` in
301
+ * the TypeScript client and a `DeprecationWarning` in the Python one.
302
+ */
303
+ deprecated?: OperationDeprecation;
304
+ /**
305
+ * A GET list that returns the whole collection ON PURPOSE, and why (a fixed
306
+ * catalogue, the tools of one server, the fields of one dataset). Without it, a
307
+ * `list-*` / `search-*` takes a page size: `pnpm api:lint` (kitsuden-list-pagination)
308
+ * fails on a list that may silently stop at a cap. Published as
309
+ * `x-kitsuden-operation.unpaginated`.
310
+ */
311
+ unpaginated?: string;
312
+ /** MCP exposure (yes by default). */
313
+ mcp?: OperationMcp;
314
+ /** Usage guide for agents (see `OperationGuide`). Optional. */
315
+ guide?: OperationGuide;
316
+ /**
317
+ * What it costs from the agent's daily budget (`budget_units_per_day`).
318
+ * 1 by default; an expensive operation (export, reindex, generate) declares
319
+ * more. Integer ≥ 0.
320
+ */
321
+ cost?: number;
322
+ /**
323
+ * Middleware that runs after authentication and BEFORE the permission,
324
+ * validation and the handler (e.g. `bodyLimit` on an upload: it has to
325
+ * cut off before the body is read). Escape hatch: normally it is not used.
326
+ */
327
+ before?: MiddlewareHandler[];
328
+ handle(input: ValidatedInput<P extends ZodTypeAny ? z.output<P> : undefined, Q extends ZodTypeAny ? z.output<Q> : undefined, B extends ZodTypeAny ? z.output<B> : undefined>, h: OperationContext): Promise<OperationResult> | OperationResult;
329
+ }
330
+ export declare function isSensitive(op: Pick<KonOperation, "method" | "sensitive">): boolean;
331
+ /** Changes nothing? GETs, and the POSTs that declare it. */
332
+ export declare function isReadOnly(op: Pick<KonOperation, "method" | "readOnly">): boolean;
333
+ /** Budget units it consumes (1 by default). */
334
+ export declare function operationCost(op: Pick<KonOperation, "cost"> | null | undefined): number;
335
+ export declare function isIdempotent(op: Pick<KonOperation, "method" | "idempotent">): boolean;
336
+ /** Reason for MCP exclusion, or `null` if it is exposed. */
337
+ export declare function exclusionMcp(op: Pick<KonOperation, "mcp" | "input">): string | null;
338
+ /** The errors it can return, automatic ones included, without repeats. */
339
+ export declare function operationErrors(op: Pick<KonOperation, "access" | "permission" | "input" | "errors"> & {
340
+ method?: OperationMethod;
341
+ }): KitsudenErrorCode[];
342
+ /** `kon-blog` → `blog`. */
343
+ export declare function konShortName(konId: string): string;
344
+ /** The fine scope of an operation: `kon:blog:create-post`. */
345
+ export declare function operationFineScope(konId: string, operationId: string): string;
346
+ /**
347
+ * Name of the MCP tool: `blog__create-post`. Only `[a-z0-9_-]`, as
348
+ * MCP clients require, and at most 64 characters.
349
+ */
350
+ export declare function toolName(konId: string, op: Pick<KonOperation, "id" | "mcp">): string;
351
+ /** The OpenAPI `operationId`: `blog.create-post`. */
352
+ export declare function operationIdOf(konId: string, operationId: string): string;
353
+ /**
354
+ * All the scopes that, on their own, grant the operation (what the agent permissions
355
+ * panel will show as "these grant it: …"). The policy is not here:
356
+ * it is decided with the user and the resource, not with a list.
357
+ */
358
+ export declare function scopesThatGrant(konId: string, op: Pick<KonOperation, "id" | "permission">): string[];
359
+ export interface GrantByScope {
360
+ granted: boolean;
361
+ /** The granted scope that opened it (for auditing). */
362
+ by?: string;
363
+ /** The denial that closed it, if there was one. */
364
+ deniedBy?: string;
365
+ }
366
+ /**
367
+ * What identifies the operation in front of a DENIAL: its fine scope, the
368
+ * per-kon alias (`blog:create-post`, so that `!blog:*` also closes it) and
369
+ * the resource scope if there is one.
370
+ */
371
+ export declare function operationIdentities(konId: string, op: Pick<KonOperation, "id" | "permission">, input?: ValidatedInput, resource?: unknown): string[];
372
+ /** The agent's denial that closes this operation, or `null`. */
373
+ export declare function operationDenial(grantedItems: readonly string[] | undefined, konId: string, op: Pick<KonOperation, "id" | "permission">, input?: ValidatedInput, resource?: unknown): string | null;
374
+ /**
375
+ * Do the agent's scopes open this operation? UNION: one is enough.
376
+ *
377
+ * · `admin`, `admin:*`
378
+ * · the fine `kon:<kon>:<op>` and its wildcards (`kon:<kon>:*`, `kon:*`)
379
+ * · the kon's broad `<kon>:*`
380
+ * · the broad ones declared in `permission.scopes` (with wildcards)
381
+ * · the resource one returned by `permission.resourceScope(input, resource)`
382
+ *
383
+ * …unless a DENIAL by the agent covers the operation (its fine one, its alias
384
+ * `<kon>:<op>` or its resource scope): then no, even if it carries `admin`.
385
+ *
386
+ * The POLICY scope (`<type>:<action>`) is granted by `can()` in the engine,
387
+ * not by this: that way it is evaluated once and with the resource.
388
+ */
389
+ export declare function grantsByScopes(grantedItems: readonly string[] | undefined, konId: string, op: Pick<KonOperation, "id" | "permission">, input?: ValidatedInput, resource?: unknown): GrantByScope;
390
+ /** The scope (without denials) that would open the operation, to show it. */
391
+ export declare function whyGranted(grantedItems: readonly string[] | undefined, konId: string, op: Pick<KonOperation, "id" | "permission">): string | null;
392
+ /**
393
+ * Declares an operation. At definition time it checks what would later be a silent
394
+ * failure: well-formed id, relative path, catalog errors, MCP
395
+ * exclusion with a reason, JSON output with a schema.
396
+ */
397
+ export declare function defineOperation<P extends ZodTypeAny = ZodTypeAny, Q extends ZodTypeAny = ZodTypeAny, B extends ZodTypeAny = ZodTypeAny>(declared: KonOperation<P, Q, B>): KonOperation<P, Q, B>;
398
+ /** The `:param`s of a path, in order. */
399
+ export declare function routeParameters(route: string): string[];
400
+ /**
401
+ * The short part of the guide, for the MCP tool's DESCRIPTION: it is the only thing
402
+ * that all harnesses reliably show the model. The examples and
403
+ * pitfalls go in the resource (they do not inflate `tools/list`).
404
+ */
405
+ export declare function shortGuide(op: Pick<KonOperation, "guide">): string | null;
406
+ /**
407
+ * Checks a kon's list of operations: no repeated ids or paths, and
408
+ * no path shadowed by an earlier one (see `overshadows`). It throws when mounting the
409
+ * kon, which is when it can still be fixed.
410
+ */
411
+ export declare function checkOperations(konId: string, ops: readonly KonOperation[]): void;
412
+ /**
413
+ * `deprecated.use` names its replacement: a typo would send clients nowhere. Needs the
414
+ * kon's WHOLE list (the replacement may be declared in another file of the kon), so it
415
+ * runs where a kon is mounted entire (`defineKonSdk`), not in every `operationsRouter`:
416
+ * a router built for one operation (a test, a guard) would not find the other one.
417
+ */
418
+ export declare function checkDeprecations(konId: string, ops: readonly KonOperation[]): void;
419
+ /**
420
+ * A date in the INPUT: ISO 8601 text (what JSON sends) or `Date`, and the
421
+ * handler always receives a `Date`. It exists because text that reached a Drizzle
422
+ * `timestamp` column as is blew up with
423
+ * `value.toISOString is not a function` (blog PATCH).
424
+ */
425
+ export declare function dateSchema(): z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>, z.ZodTransform<Date, string | Date>>;
426
+ /** A uuid `:id` in the parameters. */
427
+ export declare const uuidSchema: () => z.ZodGUID;
428
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,EAAiC,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1E;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAShE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,mBAAmB;IA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