@clegra/sdk 0.0.0-stage → 0.1.0-next.0
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.
- package/CHANGELOG.md +152 -0
- package/LICENSE +21 -0
- package/NOTICE.md +25 -0
- package/README.md +258 -2
- package/dist/spec/kinds.json +211 -0
- package/dist/spec/schema/clegra.schema.json +1249 -0
- package/dist/spec/src/cli.d.ts +2 -0
- package/dist/spec/src/cli.js +21 -0
- package/dist/spec/src/cli.js.map +1 -0
- package/dist/spec/src/conformance.d.ts +34 -0
- package/dist/spec/src/conformance.js +703 -0
- package/dist/spec/src/conformance.js.map +1 -0
- package/dist/spec/src/init/index.d.ts +31 -0
- package/dist/spec/src/init/index.js +151 -0
- package/dist/spec/src/init/index.js.map +1 -0
- package/dist/spec/src/init/next-config.d.ts +19 -0
- package/dist/spec/src/init/next-config.js +77 -0
- package/dist/spec/src/init/next-config.js.map +1 -0
- package/dist/spec/src/init/project.d.ts +44 -0
- package/dist/spec/src/init/project.js +141 -0
- package/dist/spec/src/init/project.js.map +1 -0
- package/dist/spec/src/init/templates.d.ts +20 -0
- package/dist/spec/src/init/templates.js +166 -0
- package/dist/spec/src/init/templates.js.map +1 -0
- package/dist/spec/src/init/ui.d.ts +30 -0
- package/dist/spec/src/init/ui.js +82 -0
- package/dist/spec/src/init/ui.js.map +1 -0
- package/dist/spec/src/kinds.d.ts +89 -0
- package/dist/spec/src/kinds.js +319 -0
- package/dist/spec/src/kinds.js.map +1 -0
- package/dist/spec/src/protocol.d.ts +50 -0
- package/dist/spec/src/protocol.js +52 -0
- package/dist/spec/src/protocol.js.map +1 -0
- package/dist/spec/src/rules.d.ts +132 -0
- package/dist/spec/src/rules.js +282 -0
- package/dist/spec/src/rules.js.map +1 -0
- package/dist/src/auth.d.ts +371 -0
- package/dist/src/auth.js +964 -0
- package/dist/src/auth.js.map +1 -0
- package/dist/src/define.d.ts +249 -0
- package/dist/src/define.js +83 -0
- package/dist/src/define.js.map +1 -0
- package/dist/src/embed.d.ts +98 -0
- package/dist/src/embed.js +256 -0
- package/dist/src/embed.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/labels.d.ts +10 -0
- package/dist/src/labels.js +22 -0
- package/dist/src/labels.js.map +1 -0
- package/dist/src/manifest.d.ts +499 -0
- package/dist/src/manifest.js +188 -0
- package/dist/src/manifest.js.map +1 -0
- package/dist/src/meaning.d.ts +64 -0
- package/dist/src/meaning.js +116 -0
- package/dist/src/meaning.js.map +1 -0
- package/dist/src/next/index.d.ts +101 -0
- package/dist/src/next/index.js +187 -0
- package/dist/src/next/index.js.map +1 -0
- package/dist/src/node.d.ts +14 -0
- package/dist/src/node.js +64 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/server.d.ts +229 -0
- package/dist/src/server.js +2256 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/store.d.ts +129 -0
- package/dist/src/store.js +213 -0
- package/dist/src/store.js.map +1 -0
- package/dist/src/testing.d.ts +133 -0
- package/dist/src/testing.js +81 -0
- package/dist/src/testing.js.map +1 -0
- package/dist/src/types.d.ts +352 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/view.d.ts +35 -0
- package/dist/src/view.js +442 -0
- package/dist/src/view.js.map +1 -0
- package/docs/quickstart.md +350 -0
- package/docs/spec.md +997 -0
- package/package.json +89 -4
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { PROPERTY_TYPES } from "../spec/src/kinds.js";
|
|
2
|
+
import { EXPORT_TOOL, DELETE_TOOL, INSTALLATION_TOOL, LATER_TOOL, MANIFEST_PATH, SCHEMA_ID, SPEC_VERSION, uriPrefix } from "../spec/src/protocol.js";
|
|
3
|
+
import { LIMITS } from "../spec/src/rules.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* THE MANIFEST (spec §2): the app's definition without its code, as pure
|
|
7
|
+
* JSON. Hosts read it with one fetch (`/.well-known/clegra.json`) or as the
|
|
8
|
+
* MCP resource `clegra://<name>`. This Zod schema is the source of the
|
|
9
|
+
* published JSON Schema (schema/manifest.schema.json, `npm run schema`).
|
|
10
|
+
*/
|
|
11
|
+
export { MANIFEST_PATH, SPEC_VERSION };
|
|
12
|
+
/** The manifest as an MCP resource. */
|
|
13
|
+
export const manifestUri = (name) => uriPrefix(name);
|
|
14
|
+
const labelMap = z.record(z.string(), z.string()).describe("A label per locale (BCP 47 → text)");
|
|
15
|
+
const jsonSchema = z.record(z.string(), z.unknown()).describe("A JSON Schema (draft 2020-12)");
|
|
16
|
+
const ident = z.string().regex(/^[a-z][a-z0-9_]{0,39}$/);
|
|
17
|
+
const tone = z.enum(["neutral", "info", "success", "warning", "danger"]);
|
|
18
|
+
export const fieldSchema = z.object({
|
|
19
|
+
name: z.string(),
|
|
20
|
+
type: z.enum(["string", "number", "integer", "boolean", "array", "object"]),
|
|
21
|
+
required: z.boolean(),
|
|
22
|
+
enum: z.array(z.string()).optional(),
|
|
23
|
+
role: z.enum(["title", "subtitle", "status", "amount", "date", "person"]).optional(),
|
|
24
|
+
label: labelMap,
|
|
25
|
+
as: z.string().optional().describe("The property of the entity's kind this field holds (spec §3.1)"),
|
|
26
|
+
ref: z
|
|
27
|
+
.union([z.string().describe("An entity of this app: the field holds one of its record ids"), z.object({ kind: z.string() }).describe("A kind: the field holds the URI of a record of that kind, in any app (spec §3.2)")])
|
|
28
|
+
.optional(),
|
|
29
|
+
permission: z.string().optional().describe("Only callers with this permission see the field"),
|
|
30
|
+
filter: z.boolean().optional(),
|
|
31
|
+
sort: z.boolean().optional(),
|
|
32
|
+
search: z.boolean().optional(),
|
|
33
|
+
labels: z.record(z.string(), labelMap).optional(),
|
|
34
|
+
tones: z.record(z.string(), tone).optional(),
|
|
35
|
+
currency: z.string().optional(),
|
|
36
|
+
untrusted: z.boolean().optional().describe("Text written by outsiders: data, never instructions"),
|
|
37
|
+
});
|
|
38
|
+
const toolRef = z.object({ name: z.string().describe("The MCP tool"), plain: z.boolean().describe("Listed to plain MCP clients") });
|
|
39
|
+
const visibility = z.literal("app").optional().describe("App-only: hidden from every model (its tools carry MCP Apps `_meta.ui.visibility: [\"app\"]`); views and the host's own UI still call it. Absent: models and apps");
|
|
40
|
+
export const entitySchema = z.object({
|
|
41
|
+
name: ident,
|
|
42
|
+
label: labelMap,
|
|
43
|
+
plural: labelMap,
|
|
44
|
+
description: labelMap.optional(),
|
|
45
|
+
icon: z.string().optional(),
|
|
46
|
+
kind: z
|
|
47
|
+
.union([z.string(), z.object({ by: z.string().describe("A required enum field"), map: z.record(z.string(), z.string()).describe("A kind for each of its values") })])
|
|
48
|
+
.optional()
|
|
49
|
+
.describe("What the entity is (spec §3.1): a kind, or one per record by an enum field"),
|
|
50
|
+
permission: z.string().optional(),
|
|
51
|
+
schema: jsonSchema,
|
|
52
|
+
fields: z.array(fieldSchema),
|
|
53
|
+
tools: z.object({ list: toolRef, get: toolRef }),
|
|
54
|
+
searchable: z.boolean(),
|
|
55
|
+
visibility,
|
|
56
|
+
});
|
|
57
|
+
export const targetSchema = z
|
|
58
|
+
.object({
|
|
59
|
+
target: z.string().regex(/^(mail\.message|record:[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*)$/).describe("What the action is offered on: `mail.message`, or `record:<kind>` (a published kind or a namespaced one)"),
|
|
60
|
+
needs: z.array(z.string()).describe("The target's fields the action may receive (only these, ever); `uri` and, for records, `title` are always available"),
|
|
61
|
+
input: z.record(z.string(), z.unknown()).optional().describe("A template of the action's input: string values may hold `{field}` / `{field.sub}` placeholders naming `uri`, `title` or a needed field"),
|
|
62
|
+
label: labelMap.optional().describe("The item's words (default the action's title), at most 40 characters per locale"),
|
|
63
|
+
})
|
|
64
|
+
.describe("Where a host offers a global action on something of another app");
|
|
65
|
+
export const actionSchema = z.object({
|
|
66
|
+
name: ident,
|
|
67
|
+
entity: z.string().optional().describe("Set: the action works on one record; its tool takes `id`"),
|
|
68
|
+
title: labelMap,
|
|
69
|
+
description: labelMap.optional(),
|
|
70
|
+
icon: z.string().optional(),
|
|
71
|
+
input: jsonSchema,
|
|
72
|
+
readOnly: z.boolean(),
|
|
73
|
+
confirm: z.enum(["always", "optional", "never"]),
|
|
74
|
+
permission: z.string().optional(),
|
|
75
|
+
tool: toolRef,
|
|
76
|
+
visibility,
|
|
77
|
+
targets: z.array(targetSchema).max(LIMITS.targetsPerAction).optional(),
|
|
78
|
+
later: z
|
|
79
|
+
.object({
|
|
80
|
+
at: z.string().describe("A required date-time input property: when the action runs"),
|
|
81
|
+
window: z.number().int().min(LIMITS.laterWindow.min).max(LIMITS.laterWindow.max).describe("Minutes after `at` the run may still start"),
|
|
82
|
+
})
|
|
83
|
+
.optional()
|
|
84
|
+
.describe("«Approve now, act later»: the confirmed call is stored and runs at `at`, within `window` minutes"),
|
|
85
|
+
});
|
|
86
|
+
export const pageSchema = z.object({
|
|
87
|
+
name: ident,
|
|
88
|
+
kind: z.enum(["list", "record", "dashboard", "custom"]),
|
|
89
|
+
title: labelMap,
|
|
90
|
+
icon: z.string().optional(),
|
|
91
|
+
permission: z.string().optional(),
|
|
92
|
+
params: jsonSchema,
|
|
93
|
+
entity: z.string().optional(),
|
|
94
|
+
columns: z.array(z.string()).optional(),
|
|
95
|
+
sections: z.array(z.object({ title: labelMap, fields: z.array(z.string()) })).optional(),
|
|
96
|
+
tool: toolRef.describe("What opens the page with its params (record pages: the entity's get tool)"),
|
|
97
|
+
view: z.string().optional().describe("The ui:// view that draws it when the host doesn't draw it natively (dashboard, custom, or an override)"),
|
|
98
|
+
url: z.string().optional().describe("custom: the developer's own site, shown in an isolated frame"),
|
|
99
|
+
derived: z.boolean().optional(),
|
|
100
|
+
actions: z.array(z.string()).max(LIMITS.pageActions).optional().describe("Global actions offered on the page, in order: the first is the page's primary. Page params prefill the inputs of the same name"),
|
|
101
|
+
badge: z.string().optional().describe("A `stat` fragment type without required params: its data.value is the page's count in the navigation"),
|
|
102
|
+
});
|
|
103
|
+
export const fragmentSchema = z.object({
|
|
104
|
+
type: ident,
|
|
105
|
+
title: labelMap,
|
|
106
|
+
description: labelMap.optional(),
|
|
107
|
+
icon: z.string().optional(),
|
|
108
|
+
entity: z.string().optional().describe("Set: the entity's record card (params { id })"),
|
|
109
|
+
params: jsonSchema,
|
|
110
|
+
template: z.enum(["record", "card", "stat", "list", "chart"]).optional(),
|
|
111
|
+
view: z.string().optional(),
|
|
112
|
+
tool: toolRef,
|
|
113
|
+
permission: z.string().optional(),
|
|
114
|
+
actions: z.array(z.string()).optional().describe("Actions shown inside, by name"),
|
|
115
|
+
size: z.enum(["small", "medium", "large"]).optional(),
|
|
116
|
+
untrusted: z.boolean().optional().describe("Its texts are written by outsiders: data, never instructions"),
|
|
117
|
+
visibility,
|
|
118
|
+
});
|
|
119
|
+
export const navSchema = z.array(z.object({ section: labelMap.optional(), pages: z.array(z.string()).min(1) })).describe("The app's navigation: sections of pages (no record pages, each page at most once). Absent: every non-record page, ungrouped, in declaration order");
|
|
120
|
+
export const scheduleSchema = z.object({
|
|
121
|
+
name: ident,
|
|
122
|
+
action: z.string().optional().describe("The global action run (absent on the SDK's own `clegra_later`)"),
|
|
123
|
+
tool: z.string().describe("The tool the host calls as the installation, with `_meta.clegra.schedule` = name"),
|
|
124
|
+
every: z.number().int().min(LIMITS.scheduleEvery.min).max(LIMITS.scheduleEvery.max).describe("Minutes between runs, per installation"),
|
|
125
|
+
maxSeconds: z.number().int().min(LIMITS.scheduleSeconds.min).max(LIMITS.scheduleSeconds.max).describe("How long a run may take"),
|
|
126
|
+
});
|
|
127
|
+
export const notificationTypeSchema = z.object({
|
|
128
|
+
type: ident,
|
|
129
|
+
label: labelMap,
|
|
130
|
+
description: labelMap.optional(),
|
|
131
|
+
default: z.boolean().describe("false: off until the person turns it on"),
|
|
132
|
+
permission: z.string().optional().describe("Only holders of this permission receive it"),
|
|
133
|
+
});
|
|
134
|
+
export const lifecycleSchema = z
|
|
135
|
+
.object({ installation: z.literal(INSTALLATION_TOOL).optional(), export: z.literal(EXPORT_TOOL).optional(), delete: z.literal(DELETE_TOOL).optional() })
|
|
136
|
+
.describe("The app-only tools a workspace host calls as the installation: told of enable/disable/uninstall, export the tenant's data, delete it");
|
|
137
|
+
export const manifestSchema = z.object({
|
|
138
|
+
specVersion: z.literal(SPEC_VERSION),
|
|
139
|
+
name: z.string().regex(/^[a-z][a-z0-9-]{1,39}$/),
|
|
140
|
+
title: labelMap,
|
|
141
|
+
version: z.string(),
|
|
142
|
+
description: labelMap.optional(),
|
|
143
|
+
icons: z.array(z.object({ src: z.string(), mimeType: z.string().optional(), sizes: z.array(z.string()).optional() })).optional(),
|
|
144
|
+
publisher: z
|
|
145
|
+
.object({ name: z.string().min(1).max(LIMITS.publisherName), url: z.string().max(LIMITS.publisherUrl).describe("The publisher's web address: an absolute https URL") })
|
|
146
|
+
.strict()
|
|
147
|
+
.optional()
|
|
148
|
+
.describe("Who publishes the app: a claim that grants nothing; a store or host may verify it by the address's domain"),
|
|
149
|
+
locale: z.string(),
|
|
150
|
+
mcp: z.object({ url: z.string() }).describe("The MCP endpoint (Streamable HTTP), relative to the manifest"),
|
|
151
|
+
auth: z
|
|
152
|
+
.object({
|
|
153
|
+
resource: z.string().optional().describe("The app's public MCP address: the only token audience it accepts. A host installs the app from this address or not at all"),
|
|
154
|
+
authorizationServers: z.array(z.string()),
|
|
155
|
+
})
|
|
156
|
+
.describe("MCP authorization: the server's own address (the token audience) and who issues tokens"),
|
|
157
|
+
view: z.string().describe("The generated ui:// view for lists, records, dashboards and fragments"),
|
|
158
|
+
resolveTool: z.string().describe("Hosts resolve record and fragment URIs with this tool"),
|
|
159
|
+
embed: z
|
|
160
|
+
.object({
|
|
161
|
+
tool: toolRef.describe("The tool a host asks for an embed ticket with (spec §5.1)"),
|
|
162
|
+
path: z.string().describe("Where the embed pages live; tickets are posted to <path>/_ticket"),
|
|
163
|
+
frameAncestors: z.array(z.string()).min(1).describe("The hosts that may frame the embed pages (CSP frame-ancestors sources)"),
|
|
164
|
+
})
|
|
165
|
+
.optional()
|
|
166
|
+
.describe("Same-site url pages, framed by hosts with a sign-in ticket"),
|
|
167
|
+
searchTool: z.string().optional(),
|
|
168
|
+
kinds: z
|
|
169
|
+
.record(z.string(), z.object({ label: labelMap, properties: z.record(z.string(), z.object({ type: z.enum(PROPERTY_TYPES), many: z.boolean().optional(), key: z.boolean().optional() })) }))
|
|
170
|
+
.optional()
|
|
171
|
+
.describe("The namespaced kinds (with a dot) this app defines (spec §3.1)"),
|
|
172
|
+
entities: z.array(entitySchema),
|
|
173
|
+
actions: z.array(actionSchema),
|
|
174
|
+
pages: z.array(pageSchema),
|
|
175
|
+
fragments: z.array(fragmentSchema),
|
|
176
|
+
agents: z.array(z.object({ name: ident, title: labelMap, description: labelMap, instructions: z.string(), tools: z.array(z.string()), tier: z.enum(["fast", "standard", "strong"]), starters: z.array(labelMap).optional() })),
|
|
177
|
+
permissions: z.array(z.object({ id: z.string(), label: labelMap, description: labelMap.optional(), default: z.boolean() })),
|
|
178
|
+
settings: z.array(z.object({ id: z.string().regex(/^[a-z][a-z0-9_]{1,39}$/), label: labelMap, description: labelMap.optional(), type: z.enum(["text", "number", "boolean"]), required: z.boolean(), default: z.union([z.string(), z.number(), z.boolean()]).optional() })),
|
|
179
|
+
nav: navSchema.optional(),
|
|
180
|
+
schedules: z.array(scheduleSchema).max(LIMITS.schedules + 1).optional().describe(`Actions a workspace host runs as the installation, with no person; the SDK adds \`${LATER_TOOL}\` for later runs`),
|
|
181
|
+
notifications: z.array(notificationTypeSchema).optional().describe("The notification types the app sends; without them its notifications are untyped"),
|
|
182
|
+
lifecycle: lifecycleSchema.optional(),
|
|
183
|
+
});
|
|
184
|
+
/** The published JSON Schema of the manifest. */
|
|
185
|
+
export function manifestJsonSchema() {
|
|
186
|
+
return { $id: SCHEMA_ID, title: `Clegra app manifest ${SPEC_VERSION}`, ...z.toJSONSchema(manifestSchema, { target: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,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qFAAqF,UAAU,mBAAmB,CAAC;IACpM,aAAa,EAAE,CAAC,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kFAAkF,CAAC;IACtJ,SAAS,EAAE,eAAe,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAA;AAYF,iDAAiD;AACjD,MAAM,UAAU,kBAAkB;IAChC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,uBAAuB,YAAY,EAAE,EAAE,GAAG,CAAC,CAAC,YAAY,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,EAAE,CAAA;AACzI,CAAC","sourcesContent":["import { PROPERTY_TYPES } from \"../spec/src/kinds\"\nimport { EXPORT_TOOL, DELETE_TOOL, INSTALLATION_TOOL, LATER_TOOL, MANIFEST_PATH, SCHEMA_ID, SPEC_VERSION, uriPrefix } from \"../spec/src/protocol\"\nimport { LIMITS } from \"../spec/src/rules\"\nimport { z } from \"zod\"\n\n/**\n * THE MANIFEST (spec §2): the app's definition without its code, as pure\n * JSON. Hosts read it with one fetch (`/.well-known/clegra.json`) or as the\n * MCP resource `clegra://<name>`. This Zod schema is the source of the\n * published JSON Schema (schema/manifest.schema.json, `npm run schema`).\n */\n\nexport { MANIFEST_PATH, SPEC_VERSION }\n/** The manifest as an MCP resource. */\nexport const manifestUri = (name: string) => uriPrefix(name)\n\nconst labelMap = z.record(z.string(), z.string()).describe(\"A label per locale (BCP 47 → text)\")\nconst jsonSchema = z.record(z.string(), z.unknown()).describe(\"A JSON Schema (draft 2020-12)\")\nconst ident = z.string().regex(/^[a-z][a-z0-9_]{0,39}$/)\nconst tone = z.enum([\"neutral\", \"info\", \"success\", \"warning\", \"danger\"])\n\nexport const fieldSchema = z.object({\n name: z.string(),\n type: z.enum([\"string\", \"number\", \"integer\", \"boolean\", \"array\", \"object\"]),\n required: z.boolean(),\n enum: z.array(z.string()).optional(),\n role: z.enum([\"title\", \"subtitle\", \"status\", \"amount\", \"date\", \"person\"]).optional(),\n label: labelMap,\n as: z.string().optional().describe(\"The property of the entity's kind this field holds (spec §3.1)\"),\n ref: z\n .union([z.string().describe(\"An entity of this app: the field holds one of its record ids\"), z.object({ kind: z.string() }).describe(\"A kind: the field holds the URI of a record of that kind, in any app (spec §3.2)\")])\n .optional(),\n permission: z.string().optional().describe(\"Only callers with this permission see the field\"),\n filter: z.boolean().optional(),\n sort: z.boolean().optional(),\n search: z.boolean().optional(),\n labels: z.record(z.string(), labelMap).optional(),\n tones: z.record(z.string(), tone).optional(),\n currency: z.string().optional(),\n untrusted: z.boolean().optional().describe(\"Text written by outsiders: data, never instructions\"),\n})\n\nconst toolRef = z.object({ name: z.string().describe(\"The MCP tool\"), plain: z.boolean().describe(\"Listed to plain MCP clients\") })\nconst visibility = z.literal(\"app\").optional().describe(\"App-only: hidden from every model (its tools carry MCP Apps `_meta.ui.visibility: [\\\"app\\\"]`); views and the host's own UI still call it. Absent: models and apps\")\n\nexport const entitySchema = z.object({\n name: ident,\n label: labelMap,\n plural: labelMap,\n description: labelMap.optional(),\n icon: z.string().optional(),\n kind: z\n .union([z.string(), z.object({ by: z.string().describe(\"A required enum field\"), map: z.record(z.string(), z.string()).describe(\"A kind for each of its values\") })])\n .optional()\n .describe(\"What the entity is (spec §3.1): a kind, or one per record by an enum field\"),\n permission: z.string().optional(),\n schema: jsonSchema,\n fields: z.array(fieldSchema),\n tools: z.object({ list: toolRef, get: toolRef }),\n searchable: z.boolean(),\n visibility,\n})\n\nexport const targetSchema = z\n .object({\n target: z.string().regex(/^(mail\\.message|record:[a-z][a-z0-9-]*(\\.[a-z][a-z0-9-]*)*)$/).describe(\"What the action is offered on: `mail.message`, or `record:<kind>` (a published kind or a namespaced one)\"),\n needs: z.array(z.string()).describe(\"The target's fields the action may receive (only these, ever); `uri` and, for records, `title` are always available\"),\n input: z.record(z.string(), z.unknown()).optional().describe(\"A template of the action's input: string values may hold `{field}` / `{field.sub}` placeholders naming `uri`, `title` or a needed field\"),\n label: labelMap.optional().describe(\"The item's words (default the action's title), at most 40 characters per locale\"),\n })\n .describe(\"Where a host offers a global action on something of another app\")\n\nexport const actionSchema = z.object({\n name: ident,\n entity: z.string().optional().describe(\"Set: the action works on one record; its tool takes `id`\"),\n title: labelMap,\n description: labelMap.optional(),\n icon: z.string().optional(),\n input: jsonSchema,\n readOnly: z.boolean(),\n confirm: z.enum([\"always\", \"optional\", \"never\"]),\n permission: z.string().optional(),\n tool: toolRef,\n visibility,\n targets: z.array(targetSchema).max(LIMITS.targetsPerAction).optional(),\n later: z\n .object({\n at: z.string().describe(\"A required date-time input property: when the action runs\"),\n window: z.number().int().min(LIMITS.laterWindow.min).max(LIMITS.laterWindow.max).describe(\"Minutes after `at` the run may still start\"),\n })\n .optional()\n .describe(\"«Approve now, act later»: the confirmed call is stored and runs at `at`, within `window` minutes\"),\n})\n\nexport const pageSchema = z.object({\n name: ident,\n kind: z.enum([\"list\", \"record\", \"dashboard\", \"custom\"]),\n title: labelMap,\n icon: z.string().optional(),\n permission: z.string().optional(),\n params: jsonSchema,\n entity: z.string().optional(),\n columns: z.array(z.string()).optional(),\n sections: z.array(z.object({ title: labelMap, fields: z.array(z.string()) })).optional(),\n tool: toolRef.describe(\"What opens the page with its params (record pages: the entity's get tool)\"),\n view: z.string().optional().describe(\"The ui:// view that draws it when the host doesn't draw it natively (dashboard, custom, or an override)\"),\n url: z.string().optional().describe(\"custom: the developer's own site, shown in an isolated frame\"),\n derived: z.boolean().optional(),\n actions: z.array(z.string()).max(LIMITS.pageActions).optional().describe(\"Global actions offered on the page, in order: the first is the page's primary. Page params prefill the inputs of the same name\"),\n badge: z.string().optional().describe(\"A `stat` fragment type without required params: its data.value is the page's count in the navigation\"),\n})\n\nexport const fragmentSchema = z.object({\n type: ident,\n title: labelMap,\n description: labelMap.optional(),\n icon: z.string().optional(),\n entity: z.string().optional().describe(\"Set: the entity's record card (params { id })\"),\n params: jsonSchema,\n template: z.enum([\"record\", \"card\", \"stat\", \"list\", \"chart\"]).optional(),\n view: z.string().optional(),\n tool: toolRef,\n permission: z.string().optional(),\n actions: z.array(z.string()).optional().describe(\"Actions shown inside, by name\"),\n size: z.enum([\"small\", \"medium\", \"large\"]).optional(),\n untrusted: z.boolean().optional().describe(\"Its texts are written by outsiders: data, never instructions\"),\n visibility,\n})\n\nexport const navSchema = z.array(z.object({ section: labelMap.optional(), pages: z.array(z.string()).min(1) })).describe(\"The app's navigation: sections of pages (no record pages, each page at most once). Absent: every non-record page, ungrouped, in declaration order\")\n\nexport const scheduleSchema = z.object({\n name: ident,\n action: z.string().optional().describe(\"The global action run (absent on the SDK's own `clegra_later`)\"),\n tool: z.string().describe(\"The tool the host calls as the installation, with `_meta.clegra.schedule` = name\"),\n every: z.number().int().min(LIMITS.scheduleEvery.min).max(LIMITS.scheduleEvery.max).describe(\"Minutes between runs, per installation\"),\n maxSeconds: z.number().int().min(LIMITS.scheduleSeconds.min).max(LIMITS.scheduleSeconds.max).describe(\"How long a run may take\"),\n})\n\nexport const notificationTypeSchema = z.object({\n type: ident,\n label: labelMap,\n description: labelMap.optional(),\n default: z.boolean().describe(\"false: off until the person turns it on\"),\n permission: z.string().optional().describe(\"Only holders of this permission receive it\"),\n})\n\nexport const lifecycleSchema = z\n .object({ installation: z.literal(INSTALLATION_TOOL).optional(), export: z.literal(EXPORT_TOOL).optional(), delete: z.literal(DELETE_TOOL).optional() })\n .describe(\"The app-only tools a workspace host calls as the installation: told of enable/disable/uninstall, export the tenant's data, delete it\")\n\nexport const manifestSchema = z.object({\n specVersion: z.literal(SPEC_VERSION),\n name: z.string().regex(/^[a-z][a-z0-9-]{1,39}$/),\n title: labelMap,\n version: z.string(),\n description: labelMap.optional(),\n icons: z.array(z.object({ src: z.string(), mimeType: z.string().optional(), sizes: z.array(z.string()).optional() })).optional(),\n publisher: z\n .object({ name: z.string().min(1).max(LIMITS.publisherName), url: z.string().max(LIMITS.publisherUrl).describe(\"The publisher's web address: an absolute https URL\") })\n .strict()\n .optional()\n .describe(\"Who publishes the app: a claim that grants nothing; a store or host may verify it by the address's domain\"),\n locale: z.string(),\n mcp: z.object({ url: z.string() }).describe(\"The MCP endpoint (Streamable HTTP), relative to the manifest\"),\n auth: z\n .object({\n resource: z.string().optional().describe(\"The app's public MCP address: the only token audience it accepts. A host installs the app from this address or not at all\"),\n authorizationServers: z.array(z.string()),\n })\n .describe(\"MCP authorization: the server's own address (the token audience) and who issues tokens\"),\n view: z.string().describe(\"The generated ui:// view for lists, records, dashboards and fragments\"),\n resolveTool: z.string().describe(\"Hosts resolve record and fragment URIs with this tool\"),\n embed: z\n .object({\n tool: toolRef.describe(\"The tool a host asks for an embed ticket with (spec §5.1)\"),\n path: z.string().describe(\"Where the embed pages live; tickets are posted to <path>/_ticket\"),\n frameAncestors: z.array(z.string()).min(1).describe(\"The hosts that may frame the embed pages (CSP frame-ancestors sources)\"),\n })\n .optional()\n .describe(\"Same-site url pages, framed by hosts with a sign-in ticket\"),\n searchTool: z.string().optional(),\n kinds: z\n .record(z.string(), z.object({ label: labelMap, properties: z.record(z.string(), z.object({ type: z.enum(PROPERTY_TYPES), many: z.boolean().optional(), key: z.boolean().optional() })) }))\n .optional()\n .describe(\"The namespaced kinds (with a dot) this app defines (spec §3.1)\"),\n entities: z.array(entitySchema),\n actions: z.array(actionSchema),\n pages: z.array(pageSchema),\n fragments: z.array(fragmentSchema),\n agents: z.array(z.object({ name: ident, title: labelMap, description: labelMap, instructions: z.string(), tools: z.array(z.string()), tier: z.enum([\"fast\", \"standard\", \"strong\"]), starters: z.array(labelMap).optional() })),\n permissions: z.array(z.object({ id: z.string(), label: labelMap, description: labelMap.optional(), default: z.boolean() })),\n settings: z.array(z.object({ id: z.string().regex(/^[a-z][a-z0-9_]{1,39}$/), label: labelMap, description: labelMap.optional(), type: z.enum([\"text\", \"number\", \"boolean\"]), required: z.boolean(), default: z.union([z.string(), z.number(), z.boolean()]).optional() })),\n nav: navSchema.optional(),\n schedules: z.array(scheduleSchema).max(LIMITS.schedules + 1).optional().describe(`Actions a workspace host runs as the installation, with no person; the SDK adds \\`${LATER_TOOL}\\` for later runs`),\n notifications: z.array(notificationTypeSchema).optional().describe(\"The notification types the app sends; without them its notifications are untyped\"),\n lifecycle: lifecycleSchema.optional(),\n})\n\nexport type Manifest = z.infer<typeof manifestSchema>\nexport type ManifestField = z.infer<typeof fieldSchema>\nexport type ManifestEntity = z.infer<typeof entitySchema>\nexport type ManifestAction = z.infer<typeof actionSchema>\nexport type ManifestPage = z.infer<typeof pageSchema>\nexport type ManifestFragment = z.infer<typeof fragmentSchema>\nexport type ManifestTarget = z.infer<typeof targetSchema>\nexport type ManifestSchedule = z.infer<typeof scheduleSchema>\nexport type ManifestNotificationType = z.infer<typeof notificationTypeSchema>\n\n/** The published JSON Schema of the manifest. */\nexport function manifestJsonSchema(): Record<string, unknown> {\n return { $id: SCHEMA_ID, title: `Clegra app manifest ${SPEC_VERSION}`, ...z.toJSONSchema(manifestSchema, { target: \"draft-2020-12\" }) }\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type Label } from "./labels.js";
|
|
3
|
+
/**
|
|
4
|
+
* FIELD MEANING (spec §4): what an entity's Zod schema says beyond types,
|
|
5
|
+
* written with `.meta()`. Read back from the schema's JSON Schema, where Zod
|
|
6
|
+
* puts the metadata of every field (merged along `.meta()` chains and
|
|
7
|
+
* through `.optional()`).
|
|
8
|
+
*/
|
|
9
|
+
export declare const ROLES: readonly ["title", "subtitle", "status", "amount", "date", "person"];
|
|
10
|
+
export type Role = (typeof ROLES)[number];
|
|
11
|
+
export declare const TONES: readonly ["neutral", "info", "success", "warning", "danger"];
|
|
12
|
+
export type Tone = (typeof TONES)[number];
|
|
13
|
+
/** The keys a field's `.meta()` may carry. */
|
|
14
|
+
export type FieldMeta = {
|
|
15
|
+
role?: Role;
|
|
16
|
+
label?: Label;
|
|
17
|
+
/** The property of the entity's kind this field holds (spec §3.1): `email`, `vatID`, `startDate`… */
|
|
18
|
+
as?: string;
|
|
19
|
+
/** An entity of this app (the field holds a record id), or `{ kind }`: the URI of a record of that kind in any app (spec §3.2). */
|
|
20
|
+
ref?: string | {
|
|
21
|
+
kind: string;
|
|
22
|
+
};
|
|
23
|
+
permission?: string;
|
|
24
|
+
filter?: boolean;
|
|
25
|
+
sort?: boolean;
|
|
26
|
+
search?: boolean;
|
|
27
|
+
labels?: Record<string, Label>;
|
|
28
|
+
tones?: Record<string, Tone>;
|
|
29
|
+
currency?: string;
|
|
30
|
+
untrusted?: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type FieldType = "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
33
|
+
/** One field of an entity, as the SDK and the card know it. */
|
|
34
|
+
export type FieldInfo = {
|
|
35
|
+
name: string;
|
|
36
|
+
type: FieldType;
|
|
37
|
+
required: boolean;
|
|
38
|
+
enum?: string[];
|
|
39
|
+
/** The field's JSON Schema without the meaning keys. */
|
|
40
|
+
schema: Record<string, unknown>;
|
|
41
|
+
} & FieldMeta;
|
|
42
|
+
/**
|
|
43
|
+
* A string field holding the id of another entity's record of this app: `ref("company")`.
|
|
44
|
+
* `ref.kind("organization")`: the URI of a record of that kind in ANY app (spec §3.2), as a field or an action
|
|
45
|
+
* input. The app stores the URI and nothing else of the record; any syntactically valid record URI is accepted
|
|
46
|
+
* (checked), and the app never calls the other app: hosts resolve it, for each viewer.
|
|
47
|
+
*/
|
|
48
|
+
export declare const ref: ((entity: string) => z.ZodString) & {
|
|
49
|
+
kind(kind: string): z.ZodString;
|
|
50
|
+
};
|
|
51
|
+
/** The entity of this app a field (or an input) holds record ids of. */
|
|
52
|
+
export declare const localRef: (meta: {
|
|
53
|
+
ref?: unknown;
|
|
54
|
+
}) => string | undefined;
|
|
55
|
+
/** The kind a cross-app reference holds a record URI of (spec §3.2). */
|
|
56
|
+
export declare function kindRef(meta: {
|
|
57
|
+
ref?: unknown;
|
|
58
|
+
}): string | undefined;
|
|
59
|
+
/** JSON Schema of a Zod schema, without `$schema` (the shape tools and the card carry). */
|
|
60
|
+
export declare function jsonSchemaOf(schema: z.ZodType, io?: "input" | "output"): Record<string, unknown>;
|
|
61
|
+
/** The same JSON Schema with every meaning key removed, at any depth: what plain MCP hosts get. */
|
|
62
|
+
export declare function plainSchema(schema: unknown): unknown;
|
|
63
|
+
/** The fields of an entity's object schema, with their meaning, in declaration order. Throws on meaning that can't be right. */
|
|
64
|
+
export declare function fieldsOf(entity: string, schema: z.ZodObject): FieldInfo[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { kindNameProblem, RECORD_URI } from "../spec/src/kinds.js";
|
|
3
|
+
import { isLabel } from "./labels.js";
|
|
4
|
+
/**
|
|
5
|
+
* FIELD MEANING (spec §4): what an entity's Zod schema says beyond types,
|
|
6
|
+
* written with `.meta()`. Read back from the schema's JSON Schema, where Zod
|
|
7
|
+
* puts the metadata of every field (merged along `.meta()` chains and
|
|
8
|
+
* through `.optional()`).
|
|
9
|
+
*/
|
|
10
|
+
export const ROLES = ["title", "subtitle", "status", "amount", "date", "person"];
|
|
11
|
+
export const TONES = ["neutral", "info", "success", "warning", "danger"];
|
|
12
|
+
const META_KEYS = ["role", "label", "as", "ref", "permission", "filter", "sort", "search", "labels", "tones", "currency", "untrusted"];
|
|
13
|
+
/**
|
|
14
|
+
* A string field holding the id of another entity's record of this app: `ref("company")`.
|
|
15
|
+
* `ref.kind("organization")`: the URI of a record of that kind in ANY app (spec §3.2), as a field or an action
|
|
16
|
+
* input. The app stores the URI and nothing else of the record; any syntactically valid record URI is accepted
|
|
17
|
+
* (checked), and the app never calls the other app: hosts resolve it, for each viewer.
|
|
18
|
+
*/
|
|
19
|
+
export const ref = Object.assign(function ref(entity) {
|
|
20
|
+
return z.string().meta({ ref: entity });
|
|
21
|
+
}, {
|
|
22
|
+
kind(kind) {
|
|
23
|
+
const problem = kindNameProblem(kind);
|
|
24
|
+
if (problem)
|
|
25
|
+
throw new Error(`ref.kind: ${problem}`);
|
|
26
|
+
return z.string().regex(RECORD_URI, { error: "a record URI: clegra://<app>/<entity>/<id>" }).meta({ ref: { kind } });
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
/** The entity of this app a field (or an input) holds record ids of. */
|
|
30
|
+
export const localRef = (meta) => (typeof meta.ref === "string" ? meta.ref : undefined);
|
|
31
|
+
/** The kind a cross-app reference holds a record URI of (spec §3.2). */
|
|
32
|
+
export function kindRef(meta) {
|
|
33
|
+
const r = meta.ref;
|
|
34
|
+
return r && typeof r === "object" && !Array.isArray(r) && typeof r.kind === "string" ? r.kind : undefined;
|
|
35
|
+
}
|
|
36
|
+
/** JSON Schema of a Zod schema, without `$schema` (the shape tools and the card carry). */
|
|
37
|
+
export function jsonSchemaOf(schema, io = "output") {
|
|
38
|
+
const { $schema: _drop, ...rest } = z.toJSONSchema(schema, { io, unrepresentable: "any" });
|
|
39
|
+
return rest;
|
|
40
|
+
}
|
|
41
|
+
/** The same JSON Schema with every meaning key removed, at any depth: what plain MCP hosts get. */
|
|
42
|
+
export function plainSchema(schema) {
|
|
43
|
+
if (Array.isArray(schema))
|
|
44
|
+
return schema.map(plainSchema);
|
|
45
|
+
if (!schema || typeof schema !== "object")
|
|
46
|
+
return schema;
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const [k, v] of Object.entries(schema)) {
|
|
49
|
+
if (META_KEYS.includes(k) && k !== "label")
|
|
50
|
+
continue;
|
|
51
|
+
if (k === "label") {
|
|
52
|
+
if (typeof v === "string")
|
|
53
|
+
out.title = v;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
out[k] = k === "properties" && v && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([p, s]) => [p, plainSchema(s)])) : plainSchema(v);
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
const typeOf = (s) => {
|
|
61
|
+
const t = Array.isArray(s.type) ? s.type.find((x) => x !== "null") : s.type;
|
|
62
|
+
if (t === "number" || t === "integer" || t === "boolean" || t === "array" || t === "object")
|
|
63
|
+
return t;
|
|
64
|
+
if (!t && Array.isArray(s.anyOf)) {
|
|
65
|
+
const inner = s.anyOf.find((x) => x.type !== "null");
|
|
66
|
+
if (inner)
|
|
67
|
+
return typeOf(inner);
|
|
68
|
+
}
|
|
69
|
+
return "string";
|
|
70
|
+
};
|
|
71
|
+
/** The fields of an entity's object schema, with their meaning, in declaration order. Throws on meaning that can't be right. */
|
|
72
|
+
export function fieldsOf(entity, schema) {
|
|
73
|
+
const json = jsonSchemaOf(schema);
|
|
74
|
+
const properties = (json.properties ?? {});
|
|
75
|
+
const required = new Set(json.required ?? []);
|
|
76
|
+
const fields = [];
|
|
77
|
+
for (const [name, prop] of Object.entries(properties)) {
|
|
78
|
+
const inner = Array.isArray(prop.anyOf) ? (prop.anyOf.find((x) => x.type !== "null") ?? prop) : prop;
|
|
79
|
+
const merged = { ...inner, ...prop };
|
|
80
|
+
const meta = {};
|
|
81
|
+
for (const key of META_KEYS)
|
|
82
|
+
if (merged[key] !== undefined)
|
|
83
|
+
meta[key] = merged[key];
|
|
84
|
+
const where = `entity "${entity}", field "${name}"`;
|
|
85
|
+
if (meta.role !== undefined && !ROLES.includes(meta.role))
|
|
86
|
+
throw new Error(`${where}: role must be one of ${ROLES.join(", ")}`);
|
|
87
|
+
if (meta.label !== undefined && !isLabel(meta.label))
|
|
88
|
+
throw new Error(`${where}: label must be a string or a map of strings per locale`);
|
|
89
|
+
if (meta.tones)
|
|
90
|
+
for (const [v, t] of Object.entries(meta.tones))
|
|
91
|
+
if (!TONES.includes(t))
|
|
92
|
+
throw new Error(`${where}: tone of "${v}" must be one of ${TONES.join(", ")}`);
|
|
93
|
+
if (meta.permission !== undefined && typeof meta.permission !== "string")
|
|
94
|
+
throw new Error(`${where}: permission must be a permission id`);
|
|
95
|
+
if (meta.ref !== undefined && !localRef(meta) && !kindRef(meta))
|
|
96
|
+
throw new Error(`${where}: ref is an entity name or { kind }`);
|
|
97
|
+
const crossKind = kindRef(meta);
|
|
98
|
+
if (crossKind !== undefined && kindNameProblem(crossKind))
|
|
99
|
+
throw new Error(`${where}: ref: ${kindNameProblem(crossKind)}`);
|
|
100
|
+
const enumValues = Array.isArray(merged.enum) ? merged.enum.map(String) : undefined;
|
|
101
|
+
const plain = plainSchema(prop);
|
|
102
|
+
fields.push({ name, type: typeOf(merged), required: required.has(name), ...(enumValues ? { enum: enumValues } : {}), schema: plain, ...meta });
|
|
103
|
+
}
|
|
104
|
+
const id = fields.find((f) => f.name === "id");
|
|
105
|
+
if (!id || id.type !== "string" || !id.required)
|
|
106
|
+
throw new Error(`entity "${entity}": the schema needs a required string field "id"`);
|
|
107
|
+
for (const role of ROLES) {
|
|
108
|
+
const holders = fields.filter((f) => f.role === role);
|
|
109
|
+
if (holders.length > 1)
|
|
110
|
+
throw new Error(`entity "${entity}": role "${role}" is on ${holders.map((f) => f.name).join(" and ")}; at most one field per role`);
|
|
111
|
+
}
|
|
112
|
+
if (!fields.some((f) => f.role === "title"))
|
|
113
|
+
throw new Error(`entity "${entity}": one field needs role "title"`);
|
|
114
|
+
return fields;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=meaning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meaning.js","sourceRoot":"","sources":["../../src/meaning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,OAAO,EAAc,MAAM,UAAU,CAAA;AAE9C;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE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,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;IAChJ,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;IAC9C,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,EAAE,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,kDAAkD,CAAC,CAAA;IACrI,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;QACrD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,YAAY,IAAI,WAAW,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAA;IAC7J,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,iCAAiC,CAAC,CAAA;IAChH,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { z } from \"zod\"\n\nimport { kindNameProblem, RECORD_URI } from \"../spec/src/kinds\"\nimport { isLabel, type Label } from \"./labels\"\n\n/**\n * FIELD MEANING (spec §4): what an entity's Zod schema says beyond types,\n * written with `.meta()`. Read back from the schema's JSON Schema, where Zod\n * puts the metadata of every field (merged along `.meta()` chains and\n * through `.optional()`).\n */\n\nexport const ROLES = [\"title\", \"subtitle\", \"status\", \"amount\", \"date\", \"person\"] as const\nexport type Role = (typeof ROLES)[number]\nexport const TONES = [\"neutral\", \"info\", \"success\", \"warning\", \"danger\"] as const\nexport type Tone = (typeof TONES)[number]\n\n/** The keys a field's `.meta()` may carry. */\nexport type FieldMeta = {\n role?: Role\n label?: Label\n /** The property of the entity's kind this field holds (spec §3.1): `email`, `vatID`, `startDate`… */\n as?: string\n /** An entity of this app (the field holds a record id), or `{ kind }`: the URI of a record of that kind in any app (spec §3.2). */\n ref?: string | { kind: string }\n permission?: string\n filter?: boolean\n sort?: boolean\n search?: boolean\n labels?: Record<string, Label>\n tones?: Record<string, Tone>\n currency?: string\n untrusted?: boolean\n}\n\nexport type FieldType = \"string\" | \"number\" | \"integer\" | \"boolean\" | \"array\" | \"object\"\n\n/** One field of an entity, as the SDK and the card know it. */\nexport type FieldInfo = {\n name: string\n type: FieldType\n required: boolean\n enum?: string[]\n /** The field's JSON Schema without the meaning keys. */\n schema: Record<string, unknown>\n} & FieldMeta\n\nconst META_KEYS = [\"role\", \"label\", \"as\", \"ref\", \"permission\", \"filter\", \"sort\", \"search\", \"labels\", \"tones\", \"currency\", \"untrusted\"] as const\n\n/**\n * A string field holding the id of another entity's record of this app: `ref(\"company\")`.\n * `ref.kind(\"organization\")`: the URI of a record of that kind in ANY app (spec §3.2), as a field or an action\n * input. The app stores the URI and nothing else of the record; any syntactically valid record URI is accepted\n * (checked), and the app never calls the other app: hosts resolve it, for each viewer.\n */\nexport const ref = Object.assign(\n function ref(entity: string) {\n return z.string().meta({ ref: entity })\n },\n {\n kind(kind: string) {\n const problem = kindNameProblem(kind)\n if (problem) throw new Error(`ref.kind: ${problem}`)\n return z.string().regex(RECORD_URI, { error: \"a record URI: clegra://<app>/<entity>/<id>\" }).meta({ ref: { kind } })\n },\n },\n)\n\n/** The entity of this app a field (or an input) holds record ids of. */\nexport const localRef = (meta: { ref?: unknown }): string | undefined => (typeof meta.ref === \"string\" ? meta.ref : undefined)\n/** The kind a cross-app reference holds a record URI of (spec §3.2). */\nexport function kindRef(meta: { ref?: unknown }): string | undefined {\n const r = meta.ref\n return r && typeof r === \"object\" && !Array.isArray(r) && typeof (r as { kind?: unknown }).kind === \"string\" ? (r as { kind: string }).kind : undefined\n}\n\n/** JSON Schema of a Zod schema, without `$schema` (the shape tools and the card carry). */\nexport function jsonSchemaOf(schema: z.ZodType, io: \"input\" | \"output\" = \"output\"): Record<string, unknown> {\n const { $schema: _drop, ...rest } = z.toJSONSchema(schema, { io, unrepresentable: \"any\" }) as Record<string, unknown>\n return rest\n}\n\n/** The same JSON Schema with every meaning key removed, at any depth: what plain MCP hosts get. */\nexport function plainSchema(schema: unknown): unknown {\n if (Array.isArray(schema)) return schema.map(plainSchema)\n if (!schema || typeof schema !== \"object\") return schema\n const out: Record<string, unknown> = {}\n for (const [k, v] of Object.entries(schema)) {\n if ((META_KEYS as readonly string[]).includes(k) && k !== \"label\") continue\n if (k === \"label\") {\n if (typeof v === \"string\") out.title = v\n continue\n }\n out[k] = k === \"properties\" && v && typeof v === \"object\" ? Object.fromEntries(Object.entries(v).map(([p, s]) => [p, plainSchema(s)])) : plainSchema(v)\n }\n return out\n}\n\nconst typeOf = (s: Record<string, unknown>): FieldType => {\n const t = Array.isArray(s.type) ? s.type.find((x) => x !== \"null\") : s.type\n if (t === \"number\" || t === \"integer\" || t === \"boolean\" || t === \"array\" || t === \"object\") return t\n if (!t && Array.isArray(s.anyOf)) {\n const inner = (s.anyOf as Record<string, unknown>[]).find((x) => x.type !== \"null\")\n if (inner) return typeOf(inner)\n }\n return \"string\"\n}\n\n/** The fields of an entity's object schema, with their meaning, in declaration order. Throws on meaning that can't be right. */\nexport function fieldsOf(entity: string, schema: z.ZodObject): FieldInfo[] {\n const json = jsonSchemaOf(schema)\n const properties = (json.properties ?? {}) as Record<string, Record<string, unknown>>\n const required = new Set((json.required as string[] | undefined) ?? [])\n const fields: FieldInfo[] = []\n for (const [name, prop] of Object.entries(properties)) {\n const inner = Array.isArray(prop.anyOf) ? ((prop.anyOf as Record<string, unknown>[]).find((x) => x.type !== \"null\") ?? prop) : prop\n const merged = { ...inner, ...prop }\n const meta: FieldMeta = {}\n for (const key of META_KEYS) if (merged[key] !== undefined) (meta as Record<string, unknown>)[key] = merged[key]\n const where = `entity \"${entity}\", field \"${name}\"`\n if (meta.role !== undefined && !ROLES.includes(meta.role)) throw new Error(`${where}: role must be one of ${ROLES.join(\", \")}`)\n if (meta.label !== undefined && !isLabel(meta.label)) throw new Error(`${where}: label must be a string or a map of strings per locale`)\n if (meta.tones) for (const [v, t] of Object.entries(meta.tones)) if (!TONES.includes(t)) throw new Error(`${where}: tone of \"${v}\" must be one of ${TONES.join(\", \")}`)\n if (meta.permission !== undefined && typeof meta.permission !== \"string\") throw new Error(`${where}: permission must be a permission id`)\n if (meta.ref !== undefined && !localRef(meta) && !kindRef(meta)) throw new Error(`${where}: ref is an entity name or { kind }`)\n const crossKind = kindRef(meta)\n if (crossKind !== undefined && kindNameProblem(crossKind)) throw new Error(`${where}: ref: ${kindNameProblem(crossKind)}`)\n const enumValues = Array.isArray(merged.enum) ? (merged.enum as unknown[]).map(String) : undefined\n const plain = plainSchema(prop) as Record<string, unknown>\n fields.push({ name, type: typeOf(merged), required: required.has(name), ...(enumValues ? { enum: enumValues } : {}), schema: plain, ...meta })\n }\n const id = fields.find((f) => f.name === \"id\")\n if (!id || id.type !== \"string\" || !id.required) throw new Error(`entity \"${entity}\": the schema needs a required string field \"id\"`)\n for (const role of ROLES) {\n const holders = fields.filter((f) => f.role === role)\n if (holders.length > 1) throw new Error(`entity \"${entity}\": role \"${role}\" is on ${holders.map((f) => f.name).join(\" and \")}; at most one field per role`)\n }\n if (!fields.some((f) => f.role === \"title\")) throw new Error(`entity \"${entity}\": one field needs role \"title\"`)\n return fields\n}\n"]}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { App } from "../define.js";
|
|
2
|
+
import type { EmbedCaller } from "../embed.js";
|
|
3
|
+
import type { NextConfig } from "next";
|
|
4
|
+
/**
|
|
5
|
+
* `@clegra/sdk/next`: a Clegra app (a `defineApp` object) inside a Next.js app.
|
|
6
|
+
*
|
|
7
|
+
* - `toNextHandlers(app)` → the route handlers of `app/api/clegra/[...path]/route.ts`.
|
|
8
|
+
* - `withClegra(nextConfig)` → the rewrites that put MCP and the manifest where hosts and clients look for
|
|
9
|
+
* them: `/mcp` and `/.well-known/…` at the root of the site, served by that one route.
|
|
10
|
+
*
|
|
11
|
+
* - `embedProxy(app)` → proxy.ts for the embedded pages (`/embed/*`, spec §5.1): the ticket exchange and the
|
|
12
|
+
* `frame-ancestors` of every embed response. `getEmbedCaller(app, page)` → who looks at an embedded page.
|
|
13
|
+
*
|
|
14
|
+
* Only types are imported from the core: next.config loads this module and stays light. `next` is an optional
|
|
15
|
+
* peer dependency: types here, and `next/server` / `next/headers` loaded only when the proxy or a page runs.
|
|
16
|
+
*/
|
|
17
|
+
/** Where the catch-all route lives by default (`app/api/clegra/[...path]/route.ts`). */
|
|
18
|
+
export declare const DEFAULT_MOUNT = "/api/clegra";
|
|
19
|
+
export type NextHandlerOptions = {
|
|
20
|
+
/** Where the catch-all route is mounted (default `/api/clegra`): the same value as in `withClegra`. */
|
|
21
|
+
mount?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The site's public origin (`https://crm.example.com`), when the request alone can't say it (a proxy that
|
|
24
|
+
* rewrites the host). Default: the `CLEGRA_PUBLIC_URL` environment variable; without either, the origin is
|
|
25
|
+
* what the request says (`x-forwarded-host` / `x-forwarded-proto`, else `host`).
|
|
26
|
+
*/
|
|
27
|
+
publicUrl?: string;
|
|
28
|
+
};
|
|
29
|
+
export type NextRouteHandler = (request: Request) => Promise<Response>;
|
|
30
|
+
export type NextHandlers = {
|
|
31
|
+
GET: NextRouteHandler;
|
|
32
|
+
POST: NextRouteHandler;
|
|
33
|
+
DELETE: NextRouteHandler;
|
|
34
|
+
OPTIONS: NextRouteHandler;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The route handlers for `app/api/clegra/[...path]/route.ts`:
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* export const { GET, POST, DELETE, OPTIONS } = toNextHandlers(app)
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Each request reaches `app.fetch` at its PUBLIC address: the mount taken off (`/api/clegra/mcp` → `/mcp`),
|
|
44
|
+
* the origin `publicUrl` when given. Responses (JSON or an SSE stream) are returned as they are, never buffered.
|
|
45
|
+
* Nothing is kept between requests (MCP is stateless): it runs on serverless as on one server.
|
|
46
|
+
*
|
|
47
|
+
* Dev sign-in (`auth.dev`) is refused: it answers loopback callers only, and a Next route handler can't know the
|
|
48
|
+
* peer's address (`x-forwarded-for` is whatever the client sent). Sign people in with the app's own auth
|
|
49
|
+
* (`auth.resolve`), or run the app with `listen` from `@clegra/sdk/node` while developing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function toNextHandlers(app: App, options?: NextHandlerOptions): NextHandlers;
|
|
52
|
+
/** The app, or how to get it (an app made on first use, as the examples do). */
|
|
53
|
+
export type AppSource = App | (() => App | Promise<App>);
|
|
54
|
+
/**
|
|
55
|
+
* proxy.ts for the embedded pages (spec §5.1), with the matcher on the embed path:
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* export const proxy = embedProxy(app)
|
|
59
|
+
* export const config = { matcher: "/embed/:path*" }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* `POST /embed/_ticket` exchanges a host's ticket for the page's partitioned session cookie and redirects (303) to
|
|
63
|
+
* the page; every other embed request goes on to the page with `Content-Security-Policy: frame-ancestors <the
|
|
64
|
+
* declared hosts>` and `Referrer-Policy: no-referrer`. Options: `publicUrl` as in `toNextHandlers`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function embedProxy(source: AppSource, options?: {
|
|
67
|
+
publicUrl?: string;
|
|
68
|
+
}): (request: Request) => Promise<Response>;
|
|
69
|
+
/**
|
|
70
|
+
* Who looks at the embedded page `page` (its name in defineApp's `pages`), in a server component, route handler or
|
|
71
|
+
* server function of that page: the caller its ticket was issued to, from the page's session cookie; null without one
|
|
72
|
+
* (opened outside a host's frame, expired, or a top-level visit). Scope everything by `caller.installation`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getEmbedCaller(source: AppSource, page: string, options?: {
|
|
75
|
+
publicUrl?: string;
|
|
76
|
+
}): Promise<EmbedCaller | null>;
|
|
77
|
+
type Rewrite = {
|
|
78
|
+
source: string;
|
|
79
|
+
destination: string;
|
|
80
|
+
basePath?: false;
|
|
81
|
+
locale?: false;
|
|
82
|
+
has?: unknown[];
|
|
83
|
+
missing?: unknown[];
|
|
84
|
+
};
|
|
85
|
+
type ConfigFunction = (phase: string, context: {
|
|
86
|
+
defaultConfig: NextConfig;
|
|
87
|
+
}) => NextConfig | Promise<NextConfig>;
|
|
88
|
+
export type WithClegraOptions = {
|
|
89
|
+
/** Where the catch-all route is mounted (default `/api/clegra`): the same value as in `toNextHandlers`. */
|
|
90
|
+
mount?: string;
|
|
91
|
+
};
|
|
92
|
+
/** The rewrites `withClegra` adds (in `beforeFiles`, so no page or public file can shadow them). */
|
|
93
|
+
export declare function clegraRewrites(options?: WithClegraOptions): Rewrite[];
|
|
94
|
+
/**
|
|
95
|
+
* next.config: adds the rewrites for `/mcp`, `/.well-known/clegra.json` and the OAuth metadata paths to the
|
|
96
|
+
* clegra route (before the app's own, merged with them in any shape: array, object, sync or async function). The rest
|
|
97
|
+
* of the config is kept as it is. Takes the config object or a config function.
|
|
98
|
+
*/
|
|
99
|
+
export declare function withClegra(config: NextConfig, options?: WithClegraOptions): NextConfig;
|
|
100
|
+
export declare function withClegra(config: ConfigFunction, options?: WithClegraOptions): ConfigFunction;
|
|
101
|
+
export {};
|