@lushly-dev/afd-server 2.2.1 → 2.4.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/README.md +468 -6
- package/dist/approval-crypto.d.ts +26 -4
- package/dist/approval-crypto.d.ts.map +1 -1
- package/dist/approval-crypto.js +90 -7
- package/dist/approval-crypto.js.map +1 -1
- package/dist/approval-relay.d.ts +5 -5
- package/dist/approval-relay.d.ts.map +1 -1
- package/dist/approval.d.ts +6 -1
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +43 -32
- package/dist/approval.js.map +1 -1
- package/dist/bootstrap/afd-context.d.ts +2 -27
- package/dist/bootstrap/afd-context.d.ts.map +1 -1
- package/dist/bootstrap/afd-context.js +6 -36
- package/dist/bootstrap/afd-context.js.map +1 -1
- package/dist/bootstrap/afd-help.d.ts +24 -2
- package/dist/bootstrap/afd-help.d.ts.map +1 -1
- package/dist/bootstrap/afd-help.js +17 -2
- package/dist/bootstrap/afd-help.js.map +1 -1
- package/dist/bootstrap/described-command.d.ts +1 -0
- package/dist/bootstrap/described-command.d.ts.map +1 -1
- package/dist/bootstrap/described-command.js.map +1 -1
- package/dist/bootstrap/registry.d.ts +13 -0
- package/dist/bootstrap/registry.d.ts.map +1 -1
- package/dist/bootstrap/registry.js +30 -1
- package/dist/bootstrap/registry.js.map +1 -1
- package/dist/command-allow.d.ts +31 -0
- package/dist/command-allow.d.ts.map +1 -0
- package/dist/command-allow.js +55 -0
- package/dist/command-allow.js.map +1 -0
- package/dist/command-names.d.ts +17 -0
- package/dist/command-names.d.ts.map +1 -1
- package/dist/command-names.js +55 -0
- package/dist/command-names.js.map +1 -1
- package/dist/command-routing.d.ts +10 -3
- package/dist/command-routing.d.ts.map +1 -1
- package/dist/command-routing.js +18 -7
- package/dist/command-routing.js.map +1 -1
- package/dist/confirmation-gate.d.ts +32 -0
- package/dist/confirmation-gate.d.ts.map +1 -0
- package/dist/confirmation-gate.js +140 -0
- package/dist/confirmation-gate.js.map +1 -0
- package/dist/confirmations.d.ts +15 -23
- package/dist/confirmations.d.ts.map +1 -1
- package/dist/confirmations.js +8 -127
- package/dist/confirmations.js.map +1 -1
- package/dist/context-fields-describe.d.ts +18 -0
- package/dist/context-fields-describe.d.ts.map +1 -0
- package/dist/context-fields-describe.js +17 -0
- package/dist/context-fields-describe.js.map +1 -0
- package/dist/context-fields.d.ts +50 -0
- package/dist/context-fields.d.ts.map +1 -0
- package/dist/context-fields.js +146 -0
- package/dist/context-fields.js.map +1 -0
- package/dist/context-scope.d.ts +29 -2
- package/dist/context-scope.d.ts.map +1 -1
- package/dist/context-scope.js +37 -1
- package/dist/context-scope.js.map +1 -1
- package/dist/credentials.d.ts +17 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +16 -0
- package/dist/credentials.js.map +1 -0
- package/dist/define-core.d.ts +213 -0
- package/dist/define-core.d.ts.map +1 -0
- package/dist/define-core.js +161 -0
- package/dist/define-core.js.map +1 -0
- package/dist/define.d.ts +13 -8
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js +13 -8
- package/dist/define.js.map +1 -1
- package/dist/direct-registry.d.ts +154 -7
- package/dist/direct-registry.d.ts.map +1 -1
- package/dist/direct-registry.js +111 -13
- package/dist/direct-registry.js.map +1 -1
- package/dist/direct-tool-surface.d.ts +66 -0
- package/dist/direct-tool-surface.d.ts.map +1 -0
- package/dist/direct-tool-surface.js +162 -0
- package/dist/direct-tool-surface.js.map +1 -0
- package/dist/direct.d.ts +68 -0
- package/dist/direct.d.ts.map +1 -0
- package/dist/direct.js +66 -0
- package/dist/direct.js.map +1 -0
- package/dist/execution.d.ts +11 -1
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +18 -4
- package/dist/execution.js.map +1 -1
- package/dist/frontmatter.d.ts +16 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +111 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/http-handler.d.ts +11 -2
- package/dist/http-handler.d.ts.map +1 -1
- package/dist/http-handler.js +46 -15
- package/dist/http-handler.js.map +1 -1
- package/dist/http-security.d.ts.map +1 -1
- package/dist/http-security.js.map +1 -1
- package/dist/http-sessions.d.ts +12 -4
- package/dist/http-sessions.d.ts.map +1 -1
- package/dist/http-sessions.js +4 -4
- package/dist/http-sessions.js.map +1 -1
- package/dist/http-sse.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -4
- package/dist/index.js.map +1 -1
- package/dist/issue-message.d.ts +20 -0
- package/dist/issue-message.d.ts.map +1 -0
- package/dist/issue-message.js +55 -0
- package/dist/issue-message.js.map +1 -0
- package/dist/journal-replay.d.ts +7 -0
- package/dist/journal-replay.d.ts.map +1 -1
- package/dist/journal-replay.js +18 -1
- package/dist/journal-replay.js.map +1 -1
- package/dist/journal.d.ts +9 -1
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +44 -1
- package/dist/journal.js.map +1 -1
- package/dist/json-rpc.d.ts +2 -2
- package/dist/json-rpc.d.ts.map +1 -1
- package/dist/json-rpc.js.map +1 -1
- package/dist/json-schema.d.ts +30 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +25 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/lazy-tools.d.ts +3 -0
- package/dist/lazy-tools.d.ts.map +1 -1
- package/dist/lazy-tools.js +2 -0
- package/dist/lazy-tools.js.map +1 -1
- package/dist/mcp-auth-bearer.d.ts +23 -0
- package/dist/mcp-auth-bearer.d.ts.map +1 -0
- package/dist/mcp-auth-bearer.js +50 -0
- package/dist/mcp-auth-bearer.js.map +1 -0
- package/dist/mcp-auth-jwt.d.ts +178 -0
- package/dist/mcp-auth-jwt.d.ts.map +1 -0
- package/dist/mcp-auth-jwt.js +365 -0
- package/dist/mcp-auth-jwt.js.map +1 -0
- package/dist/mcp-auth-resource.d.ts +74 -0
- package/dist/mcp-auth-resource.d.ts.map +1 -0
- package/dist/mcp-auth-resource.js +196 -0
- package/dist/mcp-auth-resource.js.map +1 -0
- package/dist/mcp-auth-rules.d.ts +135 -0
- package/dist/mcp-auth-rules.d.ts.map +1 -0
- package/dist/mcp-auth-rules.js +306 -0
- package/dist/mcp-auth-rules.js.map +1 -0
- package/dist/mcp-auth.d.ts +81 -0
- package/dist/mcp-auth.d.ts.map +1 -0
- package/dist/mcp-auth.js +256 -0
- package/dist/mcp-auth.js.map +1 -0
- package/dist/mcp-modern.d.ts +29 -5
- package/dist/mcp-modern.d.ts.map +1 -1
- package/dist/mcp-modern.js +99 -19
- package/dist/mcp-modern.js.map +1 -1
- package/dist/meta-argument.d.ts +42 -0
- package/dist/meta-argument.d.ts.map +1 -0
- package/dist/meta-argument.js +102 -0
- package/dist/meta-argument.js.map +1 -0
- package/dist/meta-keys.d.ts +29 -0
- package/dist/meta-keys.d.ts.map +1 -0
- package/dist/meta-keys.js +90 -0
- package/dist/meta-keys.js.map +1 -0
- package/dist/meta-tools.d.ts +8 -1
- package/dist/meta-tools.d.ts.map +1 -1
- package/dist/meta-tools.js +17 -7
- package/dist/meta-tools.js.map +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +0 -1
- package/dist/middleware.js.map +1 -1
- package/dist/patterns.d.ts +46 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +38 -0
- package/dist/patterns.js.map +1 -0
- package/dist/principal-binding.d.ts +42 -0
- package/dist/principal-binding.d.ts.map +1 -0
- package/dist/principal-binding.js +70 -0
- package/dist/principal-binding.js.map +1 -0
- package/dist/request-context.d.ts +7 -1
- package/dist/request-context.d.ts.map +1 -1
- package/dist/request-context.js +14 -3
- package/dist/request-context.js.map +1 -1
- package/dist/resources.d.ts +122 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +256 -0
- package/dist/resources.js.map +1 -0
- package/dist/schema.d.ts +7 -171
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +10 -135
- package/dist/schema.js.map +1 -1
- package/dist/server-types.d.ts +94 -7
- package/dist/server-types.d.ts.map +1 -1
- package/dist/server-types.js +2 -0
- package/dist/server-types.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +45 -31
- package/dist/server.js.map +1 -1
- package/dist/skills.d.ts +95 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +340 -0
- package/dist/skills.js.map +1 -0
- package/dist/strict-json.d.ts +17 -0
- package/dist/strict-json.d.ts.map +1 -0
- package/dist/strict-json.js +93 -0
- package/dist/strict-json.js.map +1 -0
- package/dist/tool-router.d.ts +13 -1
- package/dist/tool-router.d.ts.map +1 -1
- package/dist/tool-router.js +44 -10
- package/dist/tool-router.js.map +1 -1
- package/dist/tools.d.ts +10 -5
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +48 -22
- package/dist/tools.js.map +1 -1
- package/dist/validation.d.ts +6 -45
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +25 -58
- package/dist/validation.js.map +1 -1
- package/dist/verified-credentials.d.ts +34 -0
- package/dist/verified-credentials.d.ts.map +1 -0
- package/dist/verified-credentials.js +51 -0
- package/dist/verified-credentials.js.map +1 -0
- package/package.json +18 -6
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Declared context fields (`spec/context-fields.md`): named, schema-validated request
|
|
3
|
+
* values a host declares, which reach the command context on every surface and, when declared
|
|
4
|
+
* `journal: true`, the journal.
|
|
5
|
+
*/
|
|
6
|
+
import { failure } from '@lushly-dev/afd-core';
|
|
7
|
+
import { safeParse } from 'zod/v4/core';
|
|
8
|
+
import { issueMessage } from './issue-message.js';
|
|
9
|
+
/** Context keys AFD or its packages set, which a declared field cannot take. */
|
|
10
|
+
const RESERVED_NAMES = new Set([
|
|
11
|
+
'actor',
|
|
12
|
+
'approval',
|
|
13
|
+
'auth',
|
|
14
|
+
'clock',
|
|
15
|
+
'credentials',
|
|
16
|
+
'interface',
|
|
17
|
+
'random',
|
|
18
|
+
'session',
|
|
19
|
+
'signal',
|
|
20
|
+
'source',
|
|
21
|
+
'timeout',
|
|
22
|
+
'traceId',
|
|
23
|
+
]);
|
|
24
|
+
const LABEL = '[A-Za-z](?:[A-Za-z0-9-]*[A-Za-z0-9])?';
|
|
25
|
+
/** A reverse-DNS prefix of two or more labels, a slash, then the key's name. */
|
|
26
|
+
const META_KEY = new RegExp(`^${LABEL}(?:\\.${LABEL})+/[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$`);
|
|
27
|
+
/**
|
|
28
|
+
* On a context the engine validated: the names of the declared fields marked `journal: true`, for
|
|
29
|
+
* the journal middleware. A symbol, so it never shows up among the context's keys.
|
|
30
|
+
*/
|
|
31
|
+
export const JOURNALED_CONTEXT_FIELDS = Symbol('afd.journaledContextFields');
|
|
32
|
+
/** The `_meta` key under which `server/discover` lists the declared fields. */
|
|
33
|
+
export const AFD_CONTEXT_FIELDS_META_KEY = 'dev.afd/context-fields';
|
|
34
|
+
/**
|
|
35
|
+
* The declared fields' values in a request's `_meta`, by field name. Undeclared keys are left out.
|
|
36
|
+
* Callers spread trusted values (from `createContext`) after these, so trusted code wins.
|
|
37
|
+
*/
|
|
38
|
+
export function contextFieldValues(fields, meta) {
|
|
39
|
+
if (!fields?.length || !meta || typeof meta !== 'object' || Array.isArray(meta))
|
|
40
|
+
return {};
|
|
41
|
+
const values = {};
|
|
42
|
+
for (const field of fields) {
|
|
43
|
+
const value = meta[field.meta];
|
|
44
|
+
if (value !== undefined)
|
|
45
|
+
values[field.name] = value;
|
|
46
|
+
}
|
|
47
|
+
return values;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check declarations when a server or registry is created.
|
|
51
|
+
*
|
|
52
|
+
* @throws TypeError naming the field for a reserved or repeated name, a `meta` key without a
|
|
53
|
+
* reverse-DNS prefix or with a reserved one, a repeated `meta` key, or a missing schema
|
|
54
|
+
*/
|
|
55
|
+
export function checkContextFields(fields) {
|
|
56
|
+
if (fields === undefined)
|
|
57
|
+
return [];
|
|
58
|
+
if (!Array.isArray(fields))
|
|
59
|
+
throw new TypeError('contextFields must be an array');
|
|
60
|
+
const names = new Set();
|
|
61
|
+
const metaKeys = new Set();
|
|
62
|
+
for (const field of fields) {
|
|
63
|
+
const { name, meta, schema } = field ?? {};
|
|
64
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
65
|
+
throw new TypeError('A context field needs a non-empty name');
|
|
66
|
+
}
|
|
67
|
+
if (RESERVED_NAMES.has(name)) {
|
|
68
|
+
throw new TypeError(`Context field '${name}' uses a name AFD sets itself; choose another name`);
|
|
69
|
+
}
|
|
70
|
+
if (names.has(name))
|
|
71
|
+
throw new TypeError(`Context field '${name}' is declared twice`);
|
|
72
|
+
if (typeof meta !== 'string' || !META_KEY.test(meta)) {
|
|
73
|
+
throw new TypeError(`Context field '${name}' needs a meta key with a reverse-DNS prefix, such as 'dev.example/${name}'`);
|
|
74
|
+
}
|
|
75
|
+
const labels = meta.slice(0, meta.indexOf('/')).toLowerCase().split('.');
|
|
76
|
+
if (meta.toLowerCase().startsWith('dev.afd/') || labels.some(isMcpLabel)) {
|
|
77
|
+
throw new TypeError(`Context field '${name}' uses the reserved meta prefix of '${meta}'; use your own domain`);
|
|
78
|
+
}
|
|
79
|
+
if (metaKeys.has(meta))
|
|
80
|
+
throw new TypeError(`Meta key '${meta}' is declared twice`);
|
|
81
|
+
if (!schema?._zod) {
|
|
82
|
+
throw new TypeError(`Context field '${name}' needs a Zod schema`);
|
|
83
|
+
}
|
|
84
|
+
names.add(name);
|
|
85
|
+
metaKeys.add(meta);
|
|
86
|
+
}
|
|
87
|
+
return fields;
|
|
88
|
+
}
|
|
89
|
+
function isMcpLabel(label) {
|
|
90
|
+
return label === 'mcp' || label === 'modelcontextprotocol';
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Validate a call's declared fields on its context, in place: each value is replaced by its
|
|
94
|
+
* schema's output, and the journaled names are marked for the journal. An absent or `null` value
|
|
95
|
+
* is no value. A required field is not enforced for AFD's own `afd-*` commands, so a client can
|
|
96
|
+
* discover the fields before it sends them.
|
|
97
|
+
*
|
|
98
|
+
* @returns a `VALIDATION_ERROR` result for an invalid value or a missing required one, else
|
|
99
|
+
* `undefined`
|
|
100
|
+
*/
|
|
101
|
+
export function applyContextFields(fields, context, commandName) {
|
|
102
|
+
if (fields.length === 0)
|
|
103
|
+
return undefined;
|
|
104
|
+
const values = context;
|
|
105
|
+
const ownCommand = commandName.startsWith('afd-');
|
|
106
|
+
for (const field of fields) {
|
|
107
|
+
const value = values[field.name];
|
|
108
|
+
if (value === undefined || value === null) {
|
|
109
|
+
if (field.required && !ownCommand) {
|
|
110
|
+
return fieldFailure(field, `Context field '${field.name}' is required`, [
|
|
111
|
+
{ path: '', message: 'Required' },
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
let parsed;
|
|
117
|
+
try {
|
|
118
|
+
parsed = safeParse(field.schema, value, { reportInput: true });
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
return fieldFailure(field, `Context field '${field.name}' is not valid`, [
|
|
122
|
+
{ path: '', message: error instanceof Error ? error.message : String(error) },
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
if (!parsed.success) {
|
|
126
|
+
return fieldFailure(field, `Context field '${field.name}' is not valid`, parsed.error.issues.map((issue) => ({
|
|
127
|
+
path: issue.path.map(String).join('.'),
|
|
128
|
+
message: issueMessage(issue),
|
|
129
|
+
})));
|
|
130
|
+
}
|
|
131
|
+
values[field.name] = parsed.data;
|
|
132
|
+
}
|
|
133
|
+
context[JOURNALED_CONTEXT_FIELDS] = fields
|
|
134
|
+
.filter((field) => field.journal === true)
|
|
135
|
+
.map((field) => field.name);
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
function fieldFailure(field, message, errors) {
|
|
139
|
+
return failure({
|
|
140
|
+
code: 'VALIDATION_ERROR',
|
|
141
|
+
message,
|
|
142
|
+
suggestion: `Send '${field.name}' in _meta["${field.meta}"] as its schema describes (server/discover lists it under _meta["dev.afd/context-fields"])${field.required ? '; it is required' : ', or leave it out'}`,
|
|
143
|
+
details: { field: field.name, meta: field.meta, errors },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=context-fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-fields.js","sourceRoot":"","sources":["../src/context-fields.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAwC,SAAS,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAgBlD,gFAAgF;AAChF,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC9B,OAAO;IACP,UAAU;IACV,MAAM;IACN,OAAO;IACP,aAAa;IACb,WAAW;IACX,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;CACT,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,uCAAuC,CAAC;AACtD,gFAAgF;AAChF,MAAM,QAAQ,GAAG,IAAI,MAAM,CAC1B,IAAI,KAAK,SAAS,KAAK,gDAAgD,CACvE,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAkB,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAE5F,+EAA+E;AAC/E,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AAEpE;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,MAA2C,EAC3C,IAAa;IAEb,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,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AC,KAAK,CAAC;aAC5B,CAAC,CAAC,CACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC;IAClC,CAAC;IACA,OAAmC,CAAC,wBAAwB,CAAC,GAAG,MAAM;SACrE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC;SACzC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,YAAY,CACpB,KAAmB,EACnB,OAAe,EACf,MAAgD;IAEhD,OAAO,OAAO,CAAC;QACd,IAAI,EAAE,kBAAkB;QACxB,OAAO;QACP,UAAU,EAAE,SAAS,KAAK,CAAC,IAAI,eAAe,KAAK,CAAC,IAAI,8FAA8F,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,mBAAmB,EAAE;QACjN,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE;KACxD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/context-scope.d.ts
CHANGED
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
2
|
+
* @fileoverview Context state, and its binding to the `CommandContext` of a call.
|
|
3
3
|
*
|
|
4
4
|
* HTTP clients each get their own context stack (keyed by MCP session), so the state cannot
|
|
5
5
|
* live in a closure shared by the whole server. The HTTP handler binds the caller's state to
|
|
6
6
|
* the command context under a private symbol; the tool router, execution engine and
|
|
7
7
|
* `afd-context-*` commands read it back. Symbol keys survive the `{ ...context }` copies made
|
|
8
8
|
* for batch items and pipeline steps, never serialize, and cannot be set by `createContext`.
|
|
9
|
+
* `createDirectRegistry` binds a state per call, built from the call's `activeContext` option,
|
|
10
|
+
* so this module stays free of the bootstrap commands and of Node.js built-ins.
|
|
9
11
|
*/
|
|
10
12
|
import type { CommandContext } from '@lushly-dev/afd-core';
|
|
11
|
-
|
|
13
|
+
/** Default maximum depth of a context stack. */
|
|
14
|
+
export declare const DEFAULT_CONTEXT_MAX_DEPTH = 16;
|
|
15
|
+
export interface ContextState {
|
|
16
|
+
stack: string[];
|
|
17
|
+
/** Maximum stack depth (default: 16). `afd-context-enter` fails once it is reached. */
|
|
18
|
+
maxDepth?: number;
|
|
19
|
+
/**
|
|
20
|
+
* `false` for the per-request state of a stateless MCP 2026-07-28 request: the active
|
|
21
|
+
* context comes from the request's `_meta["dev.afd/context"]`, and `afd-context-enter` and
|
|
22
|
+
* `afd-context-exit` validate but never change it. Omitted (persistent) otherwise.
|
|
23
|
+
*/
|
|
24
|
+
persistent?: boolean;
|
|
25
|
+
getActive(): string | null;
|
|
26
|
+
enter(name: string): void;
|
|
27
|
+
exit(): string | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a context state manager: one stack of entered contexts.
|
|
31
|
+
*
|
|
32
|
+
* The MCP server keeps one for stdio and one per HTTP session. Re-entering the active context
|
|
33
|
+
* is a no-op, and `enter` throws once `maxDepth` contexts are stacked.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createContextState(options?: {
|
|
36
|
+
maxDepth?: number;
|
|
37
|
+
persistent?: boolean;
|
|
38
|
+
}): ContextState;
|
|
12
39
|
/**
|
|
13
40
|
* Return a copy of `context` bound to `state`.
|
|
14
41
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-scope.d.ts","sourceRoot":"","sources":["../src/context-scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"context-scope.d.ts","sourceRoot":"","sources":["../src/context-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,gDAAgD;AAChD,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,MAAM,WAAW,YAAY;IAC5B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,IAAI,MAAM,GAAG,IAAI,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACvD,YAAY,CAyBd;AAMD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,GAAG,IAAI,GACxB,cAAc,CAGhB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,QAAQ,CAAC,EAAE,YAAY,GACrB,YAAY,GAAG,IAAI,GAAG,SAAS,CAGjC"}
|
package/dist/context-scope.js
CHANGED
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
2
|
+
* @fileoverview Context state, and its binding to the `CommandContext` of a call.
|
|
3
3
|
*
|
|
4
4
|
* HTTP clients each get their own context stack (keyed by MCP session), so the state cannot
|
|
5
5
|
* live in a closure shared by the whole server. The HTTP handler binds the caller's state to
|
|
6
6
|
* the command context under a private symbol; the tool router, execution engine and
|
|
7
7
|
* `afd-context-*` commands read it back. Symbol keys survive the `{ ...context }` copies made
|
|
8
8
|
* for batch items and pipeline steps, never serialize, and cannot be set by `createContext`.
|
|
9
|
+
* `createDirectRegistry` binds a state per call, built from the call's `activeContext` option,
|
|
10
|
+
* so this module stays free of the bootstrap commands and of Node.js built-ins.
|
|
9
11
|
*/
|
|
12
|
+
/** Default maximum depth of a context stack. */
|
|
13
|
+
export const DEFAULT_CONTEXT_MAX_DEPTH = 16;
|
|
14
|
+
/**
|
|
15
|
+
* Create a context state manager: one stack of entered contexts.
|
|
16
|
+
*
|
|
17
|
+
* The MCP server keeps one for stdio and one per HTTP session. Re-entering the active context
|
|
18
|
+
* is a no-op, and `enter` throws once `maxDepth` contexts are stacked.
|
|
19
|
+
*/
|
|
20
|
+
export function createContextState(options = {}) {
|
|
21
|
+
const maxDepth = options.maxDepth ?? DEFAULT_CONTEXT_MAX_DEPTH;
|
|
22
|
+
if (!Number.isSafeInteger(maxDepth) || maxDepth <= 0) {
|
|
23
|
+
throw new Error('Context maxDepth must be a positive integer');
|
|
24
|
+
}
|
|
25
|
+
const stack = [];
|
|
26
|
+
return {
|
|
27
|
+
stack,
|
|
28
|
+
maxDepth,
|
|
29
|
+
...(options.persistent === false && { persistent: false }),
|
|
30
|
+
getActive() {
|
|
31
|
+
return stack.length > 0 ? (stack[stack.length - 1] ?? null) : null;
|
|
32
|
+
},
|
|
33
|
+
enter(name) {
|
|
34
|
+
if (stack[stack.length - 1] === name)
|
|
35
|
+
return;
|
|
36
|
+
if (stack.length >= maxDepth) {
|
|
37
|
+
throw new Error(`Context stack is limited to ${maxDepth} levels`);
|
|
38
|
+
}
|
|
39
|
+
stack.push(name);
|
|
40
|
+
},
|
|
41
|
+
exit() {
|
|
42
|
+
return stack.pop() ?? null;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
10
46
|
const CONTEXT_STATE = Symbol('afd.contextState');
|
|
11
47
|
/**
|
|
12
48
|
* Return a copy of `context` bound to `state`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-scope.js","sourceRoot":"","sources":["../src/context-scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"context-scope.js","sourceRoot":"","sources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ACH,MAAM,UAAU,gBAAgB,CAC/B,OAAuB,EACvB,KAA0B;IAE1B,MAAM,MAAM,GAAkB,EAAE,GAAG,OAAO,EAAE,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC;IACrE,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAClC,OAAmC,EACnC,QAAuB;IAEvB,MAAM,MAAM,GAAG,OAAoC,CAAC;IACpD,OAAO,MAAM,IAAI,aAAa,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Transport-free entry point: `@lushly-dev/afd-server/credentials`
|
|
3
|
+
*
|
|
4
|
+
* `isVerifiedCredentials` alone, so a host can tell afd-auth's middleware which `credentials`
|
|
5
|
+
* afd-server verified without loading the server, the MCP SDK or a Node.js builtin.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createAuthMiddleware } from '@lushly-dev/afd-auth';
|
|
10
|
+
* import { isVerifiedCredentials } from '@lushly-dev/afd-server/credentials';
|
|
11
|
+
*
|
|
12
|
+
* const auth = createAuthMiddleware(adapter, { isVerifiedCredentials });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type { Credentials } from './mcp-auth-rules.js';
|
|
16
|
+
export { isVerifiedCredentials } from './verified-credentials.js';
|
|
17
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Transport-free entry point: `@lushly-dev/afd-server/credentials`
|
|
3
|
+
*
|
|
4
|
+
* `isVerifiedCredentials` alone, so a host can tell afd-auth's middleware which `credentials`
|
|
5
|
+
* afd-server verified without loading the server, the MCP SDK or a Node.js builtin.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createAuthMiddleware } from '@lushly-dev/afd-auth';
|
|
10
|
+
* import { isVerifiedCredentials } from '@lushly-dev/afd-server/credentials';
|
|
11
|
+
*
|
|
12
|
+
* const auth = createAuthMiddleware(adapter, { isVerifiedCredentials });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { isVerifiedCredentials } from './verified-credentials.js';
|
|
16
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../src/credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The command definition every path ends in, with no JSON Schema conversion.
|
|
3
|
+
*
|
|
4
|
+
* Module-graph rule: nothing here, and nothing `createDirectRegistry` or `createJournalMiddleware`
|
|
5
|
+
* reach, imports `zod` at run time, only `zod/v4/core`, so a host on Zod Mini loads neither classic
|
|
6
|
+
* Zod nor `toJSONSchema`. `entry-points.test.ts` enforces it. `defineCommand`, in `schema.ts`, adds
|
|
7
|
+
* the conversion for everyone else.
|
|
8
|
+
*/
|
|
9
|
+
import type { ApprovalPolicy, CommandContext, CommandDefinition, CommandExample, CommandParameter, CommandResult, ExposeOptions, JsonSchema } from '@lushly-dev/afd-core';
|
|
10
|
+
import type { ZodType } from 'zod';
|
|
11
|
+
import type { $ZodType, input, output } from 'zod/v4/core';
|
|
12
|
+
/**
|
|
13
|
+
* Options for defining a command with Zod schema.
|
|
14
|
+
*/
|
|
15
|
+
export interface ZodCommandOptions<TInput extends $ZodType, TOutput> {
|
|
16
|
+
/** Unique command name in kebab-case (e.g., 'todo-create') */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Human-readable description of what the command does */
|
|
19
|
+
description: string;
|
|
20
|
+
/** Zod schema for input validation: classic or Zod Mini */
|
|
21
|
+
input: TInput;
|
|
22
|
+
/**
|
|
23
|
+
* Optional Zod schema describing the command's output data shape.
|
|
24
|
+
* Used for agent introspection — not validated at runtime.
|
|
25
|
+
* Describes the shape of `CommandResult.data`, not the full envelope.
|
|
26
|
+
*/
|
|
27
|
+
output?: $ZodType<TOutput>;
|
|
28
|
+
/** Command handler function */
|
|
29
|
+
handler: (input: output<TInput>, context: CommandContext) => Promise<CommandResult<TOutput>>;
|
|
30
|
+
/** A short human-readable label, reported as the MCP tool `title` and by afd-detail */
|
|
31
|
+
title?: string;
|
|
32
|
+
/** Category for grouping related commands */
|
|
33
|
+
category?: string;
|
|
34
|
+
/** Whether this command performs side effects */
|
|
35
|
+
mutation?: boolean;
|
|
36
|
+
/** Command version for tracking changes */
|
|
37
|
+
version?: string;
|
|
38
|
+
/** Tags for additional categorization */
|
|
39
|
+
tags?: string[];
|
|
40
|
+
/** Commands that should be called before this one. Metadata only — not enforced at runtime. */
|
|
41
|
+
requires?: string[];
|
|
42
|
+
/** Estimated execution time category */
|
|
43
|
+
executionTime?: 'instant' | 'fast' | 'slow' | 'long-running';
|
|
44
|
+
/** Error codes this command may return */
|
|
45
|
+
errors?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Whether this command returns a HandoffResult for protocol handoffs.
|
|
48
|
+
* When true, the command will automatically be tagged with 'handoff'.
|
|
49
|
+
*/
|
|
50
|
+
handoff?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The specific handoff protocol this command uses (if handoff is true).
|
|
53
|
+
* When specified, the command will also be tagged with 'handoff:{protocol}'.
|
|
54
|
+
*/
|
|
55
|
+
handoffProtocol?: 'websocket' | 'webrtc' | 'sse' | 'http-stream' | string;
|
|
56
|
+
/**
|
|
57
|
+
* Whether this command performs destructive/irreversible actions.
|
|
58
|
+
* When true, frontends SHOULD prompt for user confirmation before
|
|
59
|
+
* applying the result locally.
|
|
60
|
+
*/
|
|
61
|
+
destructive?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Custom confirmation prompt message for destructive commands.
|
|
64
|
+
* If not provided, frontends MAY use a generic confirmation message.
|
|
65
|
+
* @example "Delete 'Buy groceries' permanently?"
|
|
66
|
+
*/
|
|
67
|
+
confirmPrompt?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Whether this command can be undone.
|
|
70
|
+
* Implementation is consumer-specific; AFD only carries the flag.
|
|
71
|
+
*/
|
|
72
|
+
undoable?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Whether a call needs a human's approval before the handler runs: `'required'`,
|
|
75
|
+
* `'not-required'` (the default), or a function of the validated input and context.
|
|
76
|
+
* Enforced by `createApprovalMiddleware`; reported as `_meta.approval`.
|
|
77
|
+
*/
|
|
78
|
+
approval?: ApprovalPolicy<output<TInput>>;
|
|
79
|
+
/**
|
|
80
|
+
* Which interfaces this command is exposed to.
|
|
81
|
+
* Controls visibility in command palette, MCP, agent, and CLI surfaces.
|
|
82
|
+
* Defaults to `defaultExpose` if not specified.
|
|
83
|
+
*/
|
|
84
|
+
expose?: ExposeOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Concrete input examples to help agents construct valid payloads.
|
|
87
|
+
* Each example is validated against the input schema at define-time.
|
|
88
|
+
*/
|
|
89
|
+
examples?: CommandExample<input<TInput>>[];
|
|
90
|
+
/**
|
|
91
|
+
* Contexts this command belongs to. When context-based tool scoping is enabled,
|
|
92
|
+
* only commands matching the active context (or commands without contexts) are visible.
|
|
93
|
+
*/
|
|
94
|
+
contexts?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Extra `_meta` entries for this command's tool, its grouped action entry and afd-detail
|
|
97
|
+
* (`spec/mcp-resources.md`, T1). Keys are reverse-DNS prefixed with two or more labels, outside
|
|
98
|
+
* `dev.afd/` and the prefixes MCP reserves (`dev.umbel/origin`), or exactly `ui`, the MCP Apps
|
|
99
|
+
* key (`{ resourceUri: 'ui://app/view.html' }`). An MCP server refuses any other key when it
|
|
100
|
+
* registers the command, so an entry never replaces one the server sets. (`defineCommand` and
|
|
101
|
+
* the in-process registry do not check, to keep the `/direct` entry within its size budget.)
|
|
102
|
+
*/
|
|
103
|
+
toolMeta?: Record<string, unknown>;
|
|
104
|
+
/**
|
|
105
|
+
* The input schema shown on every surface (tool `inputSchema`, afd-detail, afd-schema,
|
|
106
|
+
* afd-docs), in place of the one generated from `input`. `input` still validates every call.
|
|
107
|
+
* It must be a JSON object whose `type` is `"object"`; nothing else in it is checked. Keeping
|
|
108
|
+
* `input` no wider than this schema is the caller's duty (`spec/mcp-resources.md`, V1).
|
|
109
|
+
*/
|
|
110
|
+
advertisedInputSchema?: JsonSchema;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A command definition that includes Zod schema for runtime validation.
|
|
114
|
+
*/
|
|
115
|
+
export interface ZodCommandDefinition<TInput extends $ZodType = ZodType, TOutput = unknown> {
|
|
116
|
+
/** Unique command name */
|
|
117
|
+
name: string;
|
|
118
|
+
/** Human-readable description */
|
|
119
|
+
description: string;
|
|
120
|
+
/** Zod schema for input validation */
|
|
121
|
+
inputSchema: TInput;
|
|
122
|
+
/** JSON Schema shown on every surface (for MCP tools): the advertised schema when one was given */
|
|
123
|
+
jsonSchema: JsonSchema;
|
|
124
|
+
/** Command handler */
|
|
125
|
+
handler: (input: output<TInput>, context: CommandContext) => Promise<CommandResult<TOutput>>;
|
|
126
|
+
/** Display label (MCP tool `title`) */
|
|
127
|
+
title?: string;
|
|
128
|
+
/** Category for grouping */
|
|
129
|
+
category?: string;
|
|
130
|
+
/** Whether this is a mutation */
|
|
131
|
+
mutation?: boolean;
|
|
132
|
+
/** Command version */
|
|
133
|
+
version?: string;
|
|
134
|
+
/** Tags for categorization */
|
|
135
|
+
tags?: string[];
|
|
136
|
+
/** Commands that should be called before this one. Metadata only — not enforced at runtime. */
|
|
137
|
+
requires?: string[];
|
|
138
|
+
/** Execution time category */
|
|
139
|
+
executionTime?: 'instant' | 'fast' | 'slow' | 'long-running';
|
|
140
|
+
/** Possible error codes */
|
|
141
|
+
errors?: string[];
|
|
142
|
+
/** Whether this command returns a HandoffResult */
|
|
143
|
+
handoff?: boolean;
|
|
144
|
+
/** The specific handoff protocol this command uses */
|
|
145
|
+
handoffProtocol?: 'websocket' | 'webrtc' | 'sse' | 'http-stream' | string;
|
|
146
|
+
/** Whether this command is destructive (triggers confirmation UI) */
|
|
147
|
+
destructive?: boolean;
|
|
148
|
+
/** Custom confirmation prompt message */
|
|
149
|
+
confirmPrompt?: string;
|
|
150
|
+
/** Whether this command can be undone */
|
|
151
|
+
undoable?: boolean;
|
|
152
|
+
/** Pre-execution approval policy (enforced by `createApprovalMiddleware`) */
|
|
153
|
+
approval?: ApprovalPolicy<output<TInput>>;
|
|
154
|
+
/**
|
|
155
|
+
* Which interfaces this command is exposed to.
|
|
156
|
+
* Controls visibility in command palette, MCP, agent, and CLI surfaces.
|
|
157
|
+
*/
|
|
158
|
+
expose?: ExposeOptions;
|
|
159
|
+
/** Concrete input examples validated against the input schema */
|
|
160
|
+
examples?: CommandExample<input<TInput>>[];
|
|
161
|
+
/** Zod schema for output validation (optional) */
|
|
162
|
+
outputSchema?: $ZodType;
|
|
163
|
+
/** JSON Schema for the output data shape */
|
|
164
|
+
outputJsonSchema?: JsonSchema;
|
|
165
|
+
/** Contexts this command belongs to */
|
|
166
|
+
contexts?: string[];
|
|
167
|
+
/** Extra `_meta` entries for this command's tool (`spec/mcp-resources.md`, T1) */
|
|
168
|
+
toolMeta?: Record<string, unknown>;
|
|
169
|
+
/**
|
|
170
|
+
* Convert to standard CommandDefinition format.
|
|
171
|
+
*/
|
|
172
|
+
toCommandDefinition(): CommandDefinition<output<TInput>, TOutput>;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Define a command whose JSON Schema you already have, so nothing converts it at run time. The
|
|
176
|
+
* lean path: it takes a classic or a Zod Mini schema, and a host that defines every command this
|
|
177
|
+
* way bundles neither classic Zod nor `toJSONSchema`.
|
|
178
|
+
*
|
|
179
|
+
* `jsonSchema` is what every surface shows, unless `advertisedInputSchema` replaces it, and `input`
|
|
180
|
+
* validates every call. Nothing compares the two, so hold them equal in a test, against
|
|
181
|
+
* `zodToJsonSchema(schema)`. `output` is not converted either: pass `outputJsonSchema` to advertise it.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* import * as z from 'zod/mini';
|
|
186
|
+
* import { defineCommandWithSchema, success } from '@lushly-dev/afd-server/define';
|
|
187
|
+
*
|
|
188
|
+
* const panelOpen = defineCommandWithSchema({
|
|
189
|
+
* name: 'panel-open',
|
|
190
|
+
* description: 'Open a panel',
|
|
191
|
+
* input: z.object({ id: z.string() }),
|
|
192
|
+
* jsonSchema: {
|
|
193
|
+
* type: 'object',
|
|
194
|
+
* properties: { id: { type: 'string' } },
|
|
195
|
+
* required: ['id'],
|
|
196
|
+
* },
|
|
197
|
+
* async handler(input) {
|
|
198
|
+
* return success({ id: input.id, open: true });
|
|
199
|
+
* },
|
|
200
|
+
* });
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export declare function defineCommandWithSchema<TInput extends $ZodType, TOutput>(options: ZodCommandOptions<TInput, TOutput> & {
|
|
204
|
+
/** The input's JSON Schema, shown on every surface */
|
|
205
|
+
jsonSchema: JsonSchema;
|
|
206
|
+
/** The output's JSON Schema, reported wherever a command's output is described */
|
|
207
|
+
outputJsonSchema?: JsonSchema;
|
|
208
|
+
}): ZodCommandDefinition<TInput, TOutput>;
|
|
209
|
+
/**
|
|
210
|
+
* Convert JSON Schema to CommandParameter array for @lushly-dev/afd-core compatibility.
|
|
211
|
+
*/
|
|
212
|
+
export declare function jsonSchemaToParameters(schema: JsonSchema): CommandParameter[];
|
|
213
|
+
//# sourceMappingURL=define-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-core.d.ts","sourceRoot":"","sources":["../src/define-core.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACX,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,UAAU,EACV,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAO3D;;GAEG;AACH,MAAM,WAAW,iBAAiB,CAAC,MAAM,SAAS,QAAQ,EAAE,OAAO;IAClE,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IAEb,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IAEpB,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE3B,+BAA+B;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,cAAc,KAAK,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAE7F,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAA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