poe-code 3.0.186 → 3.0.188
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/dist/cli/commands/experiment.js +1 -1
- package/dist/cli/commands/experiment.js.map +1 -1
- package/dist/cli/commands/pipeline-init.js +1 -1
- package/dist/cli/commands/pipeline-init.js.map +1 -1
- package/dist/cli/commands/pipeline.js +1 -1
- package/dist/cli/commands/pipeline.js.map +1 -1
- package/dist/cli/commands/spawn.js +2 -1
- package/dist/cli/commands/spawn.js.map +1 -1
- package/dist/cli/program.js +6 -6
- package/dist/cli/program.js.map +1 -1
- package/dist/index.js +122 -225
- package/dist/index.js.map +4 -4
- package/dist/providers/claude-code.js +2 -76
- package/dist/providers/claude-code.js.map +4 -4
- package/dist/providers/codex.js +2 -76
- package/dist/providers/codex.js.map +4 -4
- package/dist/providers/goose.js +2 -76
- package/dist/providers/goose.js.map +4 -4
- package/dist/providers/kimi.js +2 -76
- package/dist/providers/kimi.js.map +4 -4
- package/dist/providers/opencode.js +2 -76
- package/dist/providers/opencode.js.map +4 -4
- package/dist/providers/poe-agent.js +23 -107
- package/dist/providers/poe-agent.js.map +4 -4
- package/dist/sdk/experiment.js +1 -1
- package/dist/sdk/experiment.js.map +1 -1
- package/package.json +10 -30
- package/packages/design-system/dist/prompts/primitives/cancel.d.ts +1 -1
- package/packages/design-system/dist/prompts/primitives/cancel.js +1 -1
- package/packages/cmdkit/dist/cli.compile-check.d.ts +0 -1
- package/packages/cmdkit/dist/cli.compile-check.js +0 -26
- package/packages/cmdkit/dist/cli.d.ts +0 -12
- package/packages/cmdkit/dist/cli.js +0 -2331
- package/packages/cmdkit/dist/cli.js.map +0 -7
- package/packages/cmdkit/dist/index.compile-check.d.ts +0 -1
- package/packages/cmdkit/dist/index.compile-check.js +0 -50
- package/packages/cmdkit/dist/index.d.ts +0 -164
- package/packages/cmdkit/dist/index.js +0 -561
- package/packages/cmdkit/dist/index.js.map +0 -7
- package/packages/cmdkit/dist/mcp.compile-check.d.ts +0 -1
- package/packages/cmdkit/dist/mcp.compile-check.js +0 -26
- package/packages/cmdkit/dist/mcp.d.ts +0 -31
- package/packages/cmdkit/dist/mcp.js +0 -1254
- package/packages/cmdkit/dist/mcp.js.map +0 -7
- package/packages/cmdkit/dist/number-schema.d.ts +0 -3
- package/packages/cmdkit/dist/number-schema.js +0 -8
- package/packages/cmdkit/dist/renderer.d.ts +0 -5
- package/packages/cmdkit/dist/renderer.js +0 -164
- package/packages/cmdkit/dist/renderer.js.map +0 -7
- package/packages/cmdkit/dist/schema-scope.d.ts +0 -4
- package/packages/cmdkit/dist/schema-scope.js +0 -34
- package/packages/cmdkit/dist/sdk.compile-check.d.ts +0 -1
- package/packages/cmdkit/dist/sdk.compile-check.js +0 -79
- package/packages/cmdkit/dist/sdk.d.ts +0 -63
- package/packages/cmdkit/dist/sdk.js +0 -369
- package/packages/cmdkit/dist/sdk.js.map +0 -7
- package/packages/cmdkit-openapi/dist/api-command.d.ts +0 -7
- package/packages/cmdkit-openapi/dist/api-command.js +0 -4
- package/packages/cmdkit-openapi/dist/auth/bearer-token-auth.d.ts +0 -8
- package/packages/cmdkit-openapi/dist/auth/bearer-token-auth.js +0 -216
- package/packages/cmdkit-openapi/dist/auth/types.d.ts +0 -9
- package/packages/cmdkit-openapi/dist/auth/types.js +0 -1
- package/packages/cmdkit-openapi/dist/bin/generate.d.ts +0 -40
- package/packages/cmdkit-openapi/dist/bin/generate.js +0 -248
- package/packages/cmdkit-openapi/dist/define-client.d.ts +0 -20
- package/packages/cmdkit-openapi/dist/define-client.js +0 -148
- package/packages/cmdkit-openapi/dist/generate.d.ts +0 -210
- package/packages/cmdkit-openapi/dist/generate.js +0 -1091
- package/packages/cmdkit-openapi/dist/group-by-noun.d.ts +0 -6
- package/packages/cmdkit-openapi/dist/group-by-noun.js +0 -17
- package/packages/cmdkit-openapi/dist/http.d.ts +0 -26
- package/packages/cmdkit-openapi/dist/http.js +0 -123
- package/packages/cmdkit-openapi/dist/index.d.ts +0 -12
- package/packages/cmdkit-openapi/dist/index.js +0 -6
- package/packages/cmdkit-openapi/dist/interpreter.d.ts +0 -6
- package/packages/cmdkit-openapi/dist/interpreter.js +0 -289
- package/packages/cmdkit-openapi/dist/lock.d.ts +0 -14
- package/packages/cmdkit-openapi/dist/lock.js +0 -48
- package/packages/cmdkit-openapi/dist/naming.d.ts +0 -24
- package/packages/cmdkit-openapi/dist/naming.js +0 -218
- package/packages/cmdkit-openapi/dist/request-shape.d.ts +0 -15
- package/packages/cmdkit-openapi/dist/request-shape.js +0 -5
- package/packages/cmdkit-openapi/dist/runtime.d.ts +0 -13
- package/packages/cmdkit-openapi/dist/runtime.js +0 -94
- package/packages/cmdkit-openapi/dist/spec-source.d.ts +0 -11
- package/packages/cmdkit-openapi/dist/spec-source.js +0 -63
- package/packages/cmdkit-schema/dist/index.compile-check.d.ts +0 -1
- package/packages/cmdkit-schema/dist/index.compile-check.js +0 -12
- package/packages/cmdkit-schema/dist/index.d.ts +0 -124
- package/packages/cmdkit-schema/dist/index.js +0 -175
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { UserError } from "@poe-code/cmdkit";
|
|
2
|
-
export const METHOD_DEFAULTS = {
|
|
3
|
-
delete: {
|
|
4
|
-
collection: "delete",
|
|
5
|
-
resource: "delete",
|
|
6
|
-
confirm: true
|
|
7
|
-
},
|
|
8
|
-
get: {
|
|
9
|
-
collection: "list",
|
|
10
|
-
resource: "view",
|
|
11
|
-
genericVerbs: ["get", "list", "view"],
|
|
12
|
-
preferOperationIdWhenPathTailIsGeneric: true
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
export function deriveNoun(operation, path, operationId) {
|
|
16
|
-
const noun = operation.tags?.[0];
|
|
17
|
-
if (typeof noun !== "string" || noun.length === 0) {
|
|
18
|
-
const fallbackNoun = deriveNounFromPath(path);
|
|
19
|
-
if (fallbackNoun === undefined) {
|
|
20
|
-
throw new UserError(`Operation ${JSON.stringify(operationId)} must define tags[0] or a static resource segment in the path to derive a command noun.`);
|
|
21
|
-
}
|
|
22
|
-
return fallbackNoun;
|
|
23
|
-
}
|
|
24
|
-
return toKebabCase(noun);
|
|
25
|
-
}
|
|
26
|
-
export function deriveVerb(method, path, operation, operationId, noun) {
|
|
27
|
-
const segments = splitPathSegments(path);
|
|
28
|
-
const defaults = METHOD_DEFAULTS[method];
|
|
29
|
-
if (defaults !== undefined) {
|
|
30
|
-
const lastSegment = segments.at(-1);
|
|
31
|
-
if (isPathTemplateSegment(lastSegment)) {
|
|
32
|
-
return defaults.resource;
|
|
33
|
-
}
|
|
34
|
-
if (defaults.preferOperationIdWhenPathTailIsGeneric === true) {
|
|
35
|
-
const derived = deriveVerbFromOperationId(method, operation.operationId, noun, defaults);
|
|
36
|
-
const pathTail = lastSegment === undefined ? undefined : toKebabCase(lastSegment);
|
|
37
|
-
if (derived !== undefined) {
|
|
38
|
-
if (pathTail === undefined || derived !== pathTail) {
|
|
39
|
-
return derived;
|
|
40
|
-
}
|
|
41
|
-
if (!operationIdStartsWithCollectionVerb(method, operation.operationId, noun, defaults)) {
|
|
42
|
-
return pathTail;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return defaults.collection;
|
|
47
|
-
}
|
|
48
|
-
const derived = deriveVerbFromOperationId(method, operation.operationId, noun);
|
|
49
|
-
if (derived !== undefined) {
|
|
50
|
-
return derived;
|
|
51
|
-
}
|
|
52
|
-
throw new UserError(`Operation ${JSON.stringify(operationId)} is missing an operationId, so cmdkit-openapi cannot derive a stable command verb.`);
|
|
53
|
-
}
|
|
54
|
-
export function normalizeParamName(name) {
|
|
55
|
-
return toCamelCase(name);
|
|
56
|
-
}
|
|
57
|
-
export function toPascalCase(value) {
|
|
58
|
-
const camel = toCamelCase(value);
|
|
59
|
-
return camel.length === 0 ? camel : `${camel[0]?.toUpperCase() ?? ""}${camel.slice(1)}`;
|
|
60
|
-
}
|
|
61
|
-
export function toCamelCase(value) {
|
|
62
|
-
return splitWords(value)
|
|
63
|
-
.map((word, index) => (index === 0 ? word : `${word[0]?.toUpperCase() ?? ""}${word.slice(1)}`))
|
|
64
|
-
.join("");
|
|
65
|
-
}
|
|
66
|
-
export function toKebabCase(value) {
|
|
67
|
-
return splitWords(value).join("-");
|
|
68
|
-
}
|
|
69
|
-
export function toCliFlag(value) {
|
|
70
|
-
return toKebabCase(value);
|
|
71
|
-
}
|
|
72
|
-
export function splitWords(value) {
|
|
73
|
-
const normalized = value
|
|
74
|
-
.replaceAll("-", " ")
|
|
75
|
-
.replaceAll("_", " ")
|
|
76
|
-
.replaceAll(".", " ")
|
|
77
|
-
.replaceAll("/", " ");
|
|
78
|
-
return normalized
|
|
79
|
-
.split(" ")
|
|
80
|
-
.flatMap(splitCamelCaseWord)
|
|
81
|
-
.filter((word) => word.length > 0)
|
|
82
|
-
.map((word) => word.toLowerCase());
|
|
83
|
-
}
|
|
84
|
-
export function toMcpPrefix(name) {
|
|
85
|
-
return name.replaceAll("-", "_");
|
|
86
|
-
}
|
|
87
|
-
export function isIdentifierName(value) {
|
|
88
|
-
return /^[$A-Z_a-z][$\w]*$/u.test(value);
|
|
89
|
-
}
|
|
90
|
-
function splitPathSegments(path) {
|
|
91
|
-
return path.split("/").filter((segment) => segment.length > 0);
|
|
92
|
-
}
|
|
93
|
-
function deriveNounFromPath(path) {
|
|
94
|
-
return splitPathSegments(path)
|
|
95
|
-
.find((segment) => !isPathTemplateSegment(segment) && segment !== "api" && !isVersionWord(segment))
|
|
96
|
-
?.split("/")
|
|
97
|
-
.map((segment) => toKebabCase(segment))
|
|
98
|
-
.find((segment) => segment.length > 0);
|
|
99
|
-
}
|
|
100
|
-
function isPathTemplateSegment(segment) {
|
|
101
|
-
return segment !== undefined && segment.startsWith("{") && segment.endsWith("}");
|
|
102
|
-
}
|
|
103
|
-
function deriveVerbFromOperationId(method, operationId, noun, defaults) {
|
|
104
|
-
const words = normalizeOperationIdWords(method, operationId, noun);
|
|
105
|
-
if (words === undefined) {
|
|
106
|
-
return undefined;
|
|
107
|
-
}
|
|
108
|
-
const verbWords = stripLeadingGenericVerb(words, defaults?.genericVerbs);
|
|
109
|
-
return verbWords.length === 0 ? undefined : verbWords.join("-");
|
|
110
|
-
}
|
|
111
|
-
function operationIdStartsWithCollectionVerb(method, operationId, noun, defaults) {
|
|
112
|
-
const words = normalizeOperationIdWords(method, operationId, noun);
|
|
113
|
-
return words?.[0] === defaults.collection;
|
|
114
|
-
}
|
|
115
|
-
function normalizeOperationIdWords(method, operationId, noun) {
|
|
116
|
-
if (operationId === undefined) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
const nounWords = splitWords(noun);
|
|
120
|
-
return dedupeAdjacentWords(trimTrailingNounUnlessItConsumesAll(trimTrailingMethod(trimLeadingWords(splitWords(operationId).filter((word) => !isVersionWord(word)), nounWords), method), nounWords));
|
|
121
|
-
}
|
|
122
|
-
function stripLeadingGenericVerb(words, genericVerbs) {
|
|
123
|
-
if (genericVerbs === undefined || words.length <= 1 || !genericVerbs.includes(words[0] ?? "")) {
|
|
124
|
-
return words;
|
|
125
|
-
}
|
|
126
|
-
let start = 1;
|
|
127
|
-
while (start < words.length - 1 && words[start] === words[0]) {
|
|
128
|
-
start += 1;
|
|
129
|
-
}
|
|
130
|
-
return words.slice(start);
|
|
131
|
-
}
|
|
132
|
-
function trimTrailingNounUnlessItConsumesAll(words, nounWords) {
|
|
133
|
-
const withoutTrailingNoun = trimTrailingWords(words, nounWords);
|
|
134
|
-
return withoutTrailingNoun.length === 0 ? words : withoutTrailingNoun;
|
|
135
|
-
}
|
|
136
|
-
function trimLeadingWords(words, prefix) {
|
|
137
|
-
if (prefix.length === 0 || prefix.length > words.length) {
|
|
138
|
-
return words;
|
|
139
|
-
}
|
|
140
|
-
for (let index = 0; index < prefix.length; index += 1) {
|
|
141
|
-
if (words[index] !== prefix[index]) {
|
|
142
|
-
return words;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return words.slice(prefix.length);
|
|
146
|
-
}
|
|
147
|
-
function trimTrailingWords(words, suffix) {
|
|
148
|
-
if (suffix.length === 0 || suffix.length >= words.length) {
|
|
149
|
-
return words;
|
|
150
|
-
}
|
|
151
|
-
const start = words.length - suffix.length;
|
|
152
|
-
for (let index = 0; index < suffix.length; index += 1) {
|
|
153
|
-
if (words[start + index] !== suffix[index]) {
|
|
154
|
-
return words;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return words.slice(0, start);
|
|
158
|
-
}
|
|
159
|
-
function trimTrailingMethod(words, method) {
|
|
160
|
-
return words.at(-1) === method ? words.slice(0, -1) : words;
|
|
161
|
-
}
|
|
162
|
-
function dedupeAdjacentWords(words) {
|
|
163
|
-
if (words.length === 0) {
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
const deduped = [words[0] ?? ""];
|
|
167
|
-
for (let index = 1; index < words.length; index += 1) {
|
|
168
|
-
const word = words[index] ?? "";
|
|
169
|
-
if (word !== deduped.at(-1)) {
|
|
170
|
-
deduped.push(word);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return deduped;
|
|
174
|
-
}
|
|
175
|
-
function isVersionWord(word) {
|
|
176
|
-
if (!word.startsWith("v") || word.length < 2) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
for (const character of word.slice(1)) {
|
|
180
|
-
if (character < "0" || character > "9") {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
function splitCamelCaseWord(value) {
|
|
187
|
-
if (value.length === 0) {
|
|
188
|
-
return [];
|
|
189
|
-
}
|
|
190
|
-
const words = [value[0] ?? ""];
|
|
191
|
-
for (let index = 1; index < value.length; index += 1) {
|
|
192
|
-
const character = value[index] ?? "";
|
|
193
|
-
const previous = value[index - 1] ?? "";
|
|
194
|
-
const next = value[index + 1];
|
|
195
|
-
if (shouldStartNewWord(previous, character, next)) {
|
|
196
|
-
words.push(character);
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
const currentWord = words.at(-1) ?? "";
|
|
200
|
-
words[words.length - 1] = `${currentWord}${character}`;
|
|
201
|
-
}
|
|
202
|
-
return words;
|
|
203
|
-
}
|
|
204
|
-
function shouldStartNewWord(previous, character, next) {
|
|
205
|
-
if (!isUppercaseLetter(character)) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
if (isLowercaseLetter(previous)) {
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
return isUppercaseLetter(previous) && next !== undefined && isLowercaseLetter(next);
|
|
212
|
-
}
|
|
213
|
-
function isLowercaseLetter(character) {
|
|
214
|
-
return character >= "a" && character <= "z";
|
|
215
|
-
}
|
|
216
|
-
function isUppercaseLetter(character) {
|
|
217
|
-
return character >= "A" && character <= "Z";
|
|
218
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const REQUEST_PARAM_SECTIONS: readonly [{
|
|
2
|
-
readonly location: "path";
|
|
3
|
-
readonly key: "pathParams";
|
|
4
|
-
readonly omittable: false;
|
|
5
|
-
}, {
|
|
6
|
-
readonly location: "query";
|
|
7
|
-
readonly key: "query";
|
|
8
|
-
readonly omittable: false;
|
|
9
|
-
}, {
|
|
10
|
-
readonly location: "body";
|
|
11
|
-
readonly key: "body";
|
|
12
|
-
readonly omittable: true;
|
|
13
|
-
}];
|
|
14
|
-
export type RequestParamSection = (typeof REQUEST_PARAM_SECTIONS)[number];
|
|
15
|
-
export type RequestSectionKey = RequestParamSection["key"];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type CommandNode } from "@poe-code/cmdkit";
|
|
2
|
-
import { type DefineClientOptions, type DefinedClient, type OpenApiClientServices } from "./define-client.js";
|
|
3
|
-
import { type OpenApiDocument } from "./generate.js";
|
|
4
|
-
import { type OpenApiSourceFileSystem } from "./spec-source.js";
|
|
5
|
-
export type OpenApiDocumentSource = OpenApiDocument | string | URL;
|
|
6
|
-
export interface CommandsFromSpecOptions {
|
|
7
|
-
cwd?: string;
|
|
8
|
-
fetch?: typeof globalThis.fetch;
|
|
9
|
-
fs?: OpenApiSourceFileSystem;
|
|
10
|
-
}
|
|
11
|
-
export type DefineClientFromSpecOptions<TServices extends object = Record<string, never>> = Omit<DefineClientOptions<TServices>, "commands"> & CommandsFromSpecOptions;
|
|
12
|
-
export declare function commandsFromSpec(source: OpenApiDocumentSource, options?: CommandsFromSpecOptions): Promise<CommandNode<OpenApiClientServices>[]>;
|
|
13
|
-
export declare function defineClientFromSpec<TServices extends object = Record<string, never>>(spec: OpenApiDocumentSource, options: DefineClientFromSpecOptions<TServices>): Promise<DefinedClient<TServices>>;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { defineCommand, defineGroup, S } from "@poe-code/cmdkit";
|
|
3
|
-
import { defineClient } from "./define-client.js";
|
|
4
|
-
import { collectSchemaOptionEntries, collectGeneratedCommands } from "./generate.js";
|
|
5
|
-
import { groupByNoun } from "./group-by-noun.js";
|
|
6
|
-
import { requestJson } from "./http.js";
|
|
7
|
-
import { buildRequestShape, executePreflightBlocks } from "./interpreter.js";
|
|
8
|
-
import { parseOpenApiDocument, readOpenApiSourceText } from "./spec-source.js";
|
|
9
|
-
const RUNTIME_COMMAND_SCOPE = ["cli", "mcp", "sdk"];
|
|
10
|
-
export async function commandsFromSpec(source, options = {}) {
|
|
11
|
-
const document = await resolveDocument(source, options);
|
|
12
|
-
return createRuntimeGroups(collectGeneratedCommands(document));
|
|
13
|
-
}
|
|
14
|
-
export async function defineClientFromSpec(spec, options) {
|
|
15
|
-
const { cwd, fetch, fs: specFs, ...clientOptions } = options;
|
|
16
|
-
const commands = (await commandsFromSpec(spec, {
|
|
17
|
-
cwd,
|
|
18
|
-
fetch,
|
|
19
|
-
fs: specFs
|
|
20
|
-
}));
|
|
21
|
-
return defineClient({ ...clientOptions, commands });
|
|
22
|
-
}
|
|
23
|
-
async function resolveDocument(source, options) {
|
|
24
|
-
if (typeof source !== "string" && !(source instanceof URL)) {
|
|
25
|
-
return source;
|
|
26
|
-
}
|
|
27
|
-
const sourceText = await readOpenApiSourceText(source, {
|
|
28
|
-
cwd: options.cwd ?? process.cwd(),
|
|
29
|
-
fetch: options.fetch ?? globalThis.fetch,
|
|
30
|
-
fs: options.fs ?? fs
|
|
31
|
-
});
|
|
32
|
-
return parseOpenApiDocument(sourceText, source);
|
|
33
|
-
}
|
|
34
|
-
function createRuntimeGroups(commands) {
|
|
35
|
-
return groupByNoun(commands).map(({ noun, commands: nounCommands }) => defineGroup({
|
|
36
|
-
name: noun,
|
|
37
|
-
children: nounCommands.map((command) => createRuntimeCommand(command))
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
function createRuntimeCommand(command) {
|
|
41
|
-
const paramsSchema = S.Object(Object.fromEntries(command.params.map((param) => [param.paramName, createRuntimeParamSchema(param)])), command.paramsSchemaOptions);
|
|
42
|
-
return defineCommand({
|
|
43
|
-
name: command.verb,
|
|
44
|
-
...(command.description === undefined ? {} : { description: command.description }),
|
|
45
|
-
scope: RUNTIME_COMMAND_SCOPE,
|
|
46
|
-
...(command.confirm ? { confirm: true } : {}),
|
|
47
|
-
params: paramsSchema,
|
|
48
|
-
handler: createRuntimeHandler(command)
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function createRuntimeHandler(command) {
|
|
52
|
-
return async ({ params, baseUrl, tokenSource, fetch }) => {
|
|
53
|
-
const resolvedValues = executePreflightBlocks(command.preflightBlocks, params);
|
|
54
|
-
const requestShape = buildRequestShape(command.requestFields, command.sectionRenders, command.optionalSections, params, resolvedValues);
|
|
55
|
-
return requestJson({
|
|
56
|
-
baseUrl,
|
|
57
|
-
path: command.path,
|
|
58
|
-
method: command.method,
|
|
59
|
-
auth: command.auth,
|
|
60
|
-
tokenSource,
|
|
61
|
-
fetch,
|
|
62
|
-
dryRun: params.dryRun,
|
|
63
|
-
verbose: params.verbose,
|
|
64
|
-
...requestShape
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function createRuntimeParamSchema(param) {
|
|
69
|
-
const definition = createRuntimeDefinition(param.definition, param.description, param.shortFlag, param.scope);
|
|
70
|
-
return param.optional ? S.Optional(definition) : definition;
|
|
71
|
-
}
|
|
72
|
-
function createRuntimeDefinition(definition, description, shortFlag, scope) {
|
|
73
|
-
const options = createRuntimeSchemaOptions(definition, description, shortFlag, scope);
|
|
74
|
-
return RUNTIME_DEFINITION_BUILDERS[definition.kind](definition, options);
|
|
75
|
-
}
|
|
76
|
-
const RUNTIME_DEFINITION_BUILDERS = {
|
|
77
|
-
array: (definition, options) => {
|
|
78
|
-
const itemDefinition = createRuntimeDefinition(definition.itemDefinition, undefined, undefined, undefined);
|
|
79
|
-
return options === undefined ? S.Array(itemDefinition) : S.Array(itemDefinition, options);
|
|
80
|
-
},
|
|
81
|
-
boolean: (_definition, options) => options === undefined ? S.Boolean() : S.Boolean(options),
|
|
82
|
-
enum: (definition, options) => options === undefined ? S.Enum(definition.enumValues) : S.Enum(definition.enumValues, options),
|
|
83
|
-
number: (_definition, options) => options === undefined ? S.Number() : S.Number(options),
|
|
84
|
-
string: (_definition, options) => options === undefined ? S.String() : S.String(options)
|
|
85
|
-
};
|
|
86
|
-
function createRuntimeSchemaOptions(definition, description, shortFlag, scope) {
|
|
87
|
-
const options = Object.fromEntries(collectSchemaOptionEntries({
|
|
88
|
-
definition,
|
|
89
|
-
description,
|
|
90
|
-
shortFlag,
|
|
91
|
-
scope
|
|
92
|
-
}).map(({ key, value }) => [key, Array.isArray(value) ? [...value] : value]));
|
|
93
|
-
return Object.keys(options).length === 0 ? undefined : options;
|
|
94
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { OpenApiDocument } from "./generate.js";
|
|
2
|
-
export interface OpenApiSourceFileSystem {
|
|
3
|
-
readFile(filePath: string, encoding: BufferEncoding): Promise<string>;
|
|
4
|
-
}
|
|
5
|
-
export interface OpenApiSourceServices {
|
|
6
|
-
cwd: string;
|
|
7
|
-
fetch: typeof globalThis.fetch;
|
|
8
|
-
fs: OpenApiSourceFileSystem;
|
|
9
|
-
}
|
|
10
|
-
export declare function readOpenApiSourceText(input: string | URL, services: OpenApiSourceServices): Promise<string>;
|
|
11
|
-
export declare function parseOpenApiDocument(sourceText: string, input: string | URL): OpenApiDocument;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { parse as parseYaml } from "yaml";
|
|
4
|
-
import { UserError } from "@poe-code/cmdkit";
|
|
5
|
-
export async function readOpenApiSourceText(input, services) {
|
|
6
|
-
const inputUrl = input instanceof URL ? input : tryParseUrl(input);
|
|
7
|
-
const sourceLabel = formatSourceLabel(input);
|
|
8
|
-
try {
|
|
9
|
-
if (typeof input === "string" && inputUrl === null) {
|
|
10
|
-
return await services.fs.readFile(path.resolve(services.cwd, input), "utf8");
|
|
11
|
-
}
|
|
12
|
-
if (inputUrl === null) {
|
|
13
|
-
throw new UserError(`Unsupported OpenAPI input ${JSON.stringify(sourceLabel)}.`);
|
|
14
|
-
}
|
|
15
|
-
if (inputUrl.protocol === "file:") {
|
|
16
|
-
return await services.fs.readFile(fileURLToPath(inputUrl), "utf8");
|
|
17
|
-
}
|
|
18
|
-
if (inputUrl.protocol !== "http:" && inputUrl.protocol !== "https:") {
|
|
19
|
-
throw new UserError(`Unsupported OpenAPI input URL protocol ${JSON.stringify(inputUrl.protocol)}.`);
|
|
20
|
-
}
|
|
21
|
-
const response = await services.fetch(inputUrl.toString());
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
throw new UserError(`Failed to fetch ${JSON.stringify(inputUrl.toString())}: ${response.status} ${response.statusText}`);
|
|
24
|
-
}
|
|
25
|
-
return await response.text();
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
if (error instanceof UserError) {
|
|
29
|
-
throw error;
|
|
30
|
-
}
|
|
31
|
-
throw new UserError(`Failed to read OpenAPI document ${JSON.stringify(sourceLabel)}: ${getErrorMessage(error)}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export function parseOpenApiDocument(sourceText, input) {
|
|
35
|
-
let parsed;
|
|
36
|
-
try {
|
|
37
|
-
parsed = parseYaml(sourceText);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
throw new UserError(`Failed to parse OpenAPI document ${JSON.stringify(formatSourceLabel(input))}: ${getErrorMessage(error)}`);
|
|
41
|
-
}
|
|
42
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
43
|
-
throw new UserError(`OpenAPI document ${JSON.stringify(formatSourceLabel(input))} must parse to an object.`);
|
|
44
|
-
}
|
|
45
|
-
return parsed;
|
|
46
|
-
}
|
|
47
|
-
function tryParseUrl(value) {
|
|
48
|
-
try {
|
|
49
|
-
return new URL(value);
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function formatSourceLabel(source) {
|
|
56
|
-
return source instanceof URL ? source.toString() : source;
|
|
57
|
-
}
|
|
58
|
-
function getErrorMessage(error) {
|
|
59
|
-
if (error instanceof Error) {
|
|
60
|
-
return error.message;
|
|
61
|
-
}
|
|
62
|
-
return String(error);
|
|
63
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { S } from "./index.js";
|
|
2
|
-
const ignoredStringSchema = S.String({ description: "Name", default: "guest" });
|
|
3
|
-
const ignoredNumberSchema = S.Number({ description: "Count", default: 1 });
|
|
4
|
-
const ignoredBooleanSchema = S.Boolean({ description: "Enabled", default: false });
|
|
5
|
-
const ignoredEnumSchema = S.Enum(["admin", "user"], { default: "admin" });
|
|
6
|
-
const ignoredIntegerEnumSchema = S.Enum([1, 2], { jsonType: "integer" });
|
|
7
|
-
const ignoredArraySchema = S.Array(S.String(), { default: ["a"] });
|
|
8
|
-
const ignoredObjectSchema = S.Object({
|
|
9
|
-
name: S.String(),
|
|
10
|
-
retries: S.Optional(S.Number()),
|
|
11
|
-
});
|
|
12
|
-
const ignoredOptionalSchema = S.Optional(S.Boolean());
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
type JsonSchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
|
|
2
|
-
type SchemaKind = "string" | "number" | "boolean" | "enum" | "array" | "object" | "optional";
|
|
3
|
-
type EnumValue = string | number | boolean;
|
|
4
|
-
type JsonSchemaEnumValue = EnumValue | null;
|
|
5
|
-
type NumberJsonType = "number" | "integer";
|
|
6
|
-
type NonEmptyReadonlyArray<T> = readonly [T, ...T[]];
|
|
7
|
-
type ObjectShape = Record<string, AnySchema>;
|
|
8
|
-
type SchemaScope = "cli" | "mcp" | "sdk";
|
|
9
|
-
type StringMetadata = {
|
|
10
|
-
format?: string;
|
|
11
|
-
maxLength?: number;
|
|
12
|
-
minLength?: number;
|
|
13
|
-
pattern?: string;
|
|
14
|
-
};
|
|
15
|
-
type NumberMetadata = {
|
|
16
|
-
maximum?: number;
|
|
17
|
-
minimum?: number;
|
|
18
|
-
};
|
|
19
|
-
type ArrayMetadata = {
|
|
20
|
-
maxItems?: number;
|
|
21
|
-
minItems?: number;
|
|
22
|
-
};
|
|
23
|
-
type ObjectMetadata = {
|
|
24
|
-
additionalProperties?: boolean;
|
|
25
|
-
};
|
|
26
|
-
type OptionalKeys<TShape extends ObjectShape> = {
|
|
27
|
-
[TKey in keyof TShape]: TShape[TKey] extends OptionalSchema<any> ? TKey : never;
|
|
28
|
-
}[keyof TShape];
|
|
29
|
-
type RequiredKeys<TShape extends ObjectShape> = Exclude<keyof TShape, OptionalKeys<TShape>>;
|
|
30
|
-
type PropertyStatic<TSchema extends AnySchema> = TSchema extends OptionalSchema<infer TInner> ? Static<TInner> : Static<TSchema>;
|
|
31
|
-
type InferObject<TShape extends ObjectShape> = {
|
|
32
|
-
[TKey in RequiredKeys<TShape>]: PropertyStatic<TShape[TKey]>;
|
|
33
|
-
} & {
|
|
34
|
-
[TKey in OptionalKeys<TShape>]?: PropertyStatic<TShape[TKey]>;
|
|
35
|
-
};
|
|
36
|
-
type SchemaOptions<TDefault> = {
|
|
37
|
-
description?: string;
|
|
38
|
-
default?: TDefault;
|
|
39
|
-
nullable?: boolean;
|
|
40
|
-
requiredScopes?: readonly SchemaScope[];
|
|
41
|
-
short?: string;
|
|
42
|
-
scope?: readonly SchemaScope[];
|
|
43
|
-
};
|
|
44
|
-
interface SchemaBase<TKind extends SchemaKind, TStatic> {
|
|
45
|
-
readonly kind: TKind;
|
|
46
|
-
readonly description?: string;
|
|
47
|
-
readonly default?: TStatic;
|
|
48
|
-
readonly nullable?: boolean;
|
|
49
|
-
readonly requiredScopes?: readonly SchemaScope[];
|
|
50
|
-
readonly short?: string;
|
|
51
|
-
readonly scope?: readonly SchemaScope[];
|
|
52
|
-
readonly __static?: TStatic;
|
|
53
|
-
}
|
|
54
|
-
export interface JsonSchema {
|
|
55
|
-
additionalProperties?: boolean;
|
|
56
|
-
type?: JsonSchemaType;
|
|
57
|
-
description?: string;
|
|
58
|
-
default?: unknown;
|
|
59
|
-
enum?: ReadonlyArray<JsonSchemaEnumValue>;
|
|
60
|
-
format?: string;
|
|
61
|
-
items?: JsonSchema;
|
|
62
|
-
maxItems?: number;
|
|
63
|
-
maximum?: number;
|
|
64
|
-
maxLength?: number;
|
|
65
|
-
minItems?: number;
|
|
66
|
-
minimum?: number;
|
|
67
|
-
minLength?: number;
|
|
68
|
-
nullable?: boolean;
|
|
69
|
-
pattern?: string;
|
|
70
|
-
properties?: Record<string, JsonSchema>;
|
|
71
|
-
required?: string[];
|
|
72
|
-
}
|
|
73
|
-
export interface StringSchema extends SchemaBase<"string", string>, StringMetadata {
|
|
74
|
-
}
|
|
75
|
-
export interface NumberSchema extends SchemaBase<"number", number>, NumberMetadata {
|
|
76
|
-
readonly jsonType?: NumberJsonType;
|
|
77
|
-
}
|
|
78
|
-
export type BooleanSchema = SchemaBase<"boolean", boolean>;
|
|
79
|
-
export interface EnumSchema<TValues extends NonEmptyReadonlyArray<EnumValue>> extends SchemaBase<"enum", TValues[number]> {
|
|
80
|
-
readonly values: TValues;
|
|
81
|
-
readonly jsonType?: "integer";
|
|
82
|
-
readonly labels?: Partial<Record<string, string>>;
|
|
83
|
-
readonly loadOptions?: (() => Array<{
|
|
84
|
-
label: string;
|
|
85
|
-
value: string;
|
|
86
|
-
}>) | (() => Promise<Array<{
|
|
87
|
-
label: string;
|
|
88
|
-
value: string;
|
|
89
|
-
}>>);
|
|
90
|
-
}
|
|
91
|
-
export interface ArraySchema<TItem extends AnySchema> extends SchemaBase<"array", Array<Static<TItem>>>, ArrayMetadata {
|
|
92
|
-
readonly item: TItem;
|
|
93
|
-
}
|
|
94
|
-
export interface ObjectSchema<TShape extends ObjectShape> extends SchemaBase<"object", InferObject<TShape>>, ObjectMetadata {
|
|
95
|
-
readonly shape: TShape;
|
|
96
|
-
}
|
|
97
|
-
export interface OptionalSchema<TInner extends AnySchema> extends SchemaBase<"optional", Static<TInner> | undefined> {
|
|
98
|
-
readonly inner: TInner;
|
|
99
|
-
}
|
|
100
|
-
export type AnySchema = StringSchema | NumberSchema | BooleanSchema | EnumSchema<NonEmptyReadonlyArray<EnumValue>> | ArraySchema<AnySchema> | ObjectSchema<ObjectShape> | OptionalSchema<AnySchema>;
|
|
101
|
-
export type Static<TSchema extends AnySchema> = TSchema extends SchemaBase<any, infer TStatic> ? TStatic : never;
|
|
102
|
-
export declare const S: {
|
|
103
|
-
readonly String: (options?: SchemaOptions<string> & StringMetadata) => StringSchema;
|
|
104
|
-
readonly Number: (options?: SchemaOptions<number> & NumberMetadata & {
|
|
105
|
-
jsonType?: NumberJsonType;
|
|
106
|
-
}) => NumberSchema;
|
|
107
|
-
readonly Boolean: (options?: SchemaOptions<boolean>) => BooleanSchema;
|
|
108
|
-
readonly Enum: <const TValues extends NonEmptyReadonlyArray<EnumValue>>(values: TValues, options?: SchemaOptions<TValues[number]> & {
|
|
109
|
-
jsonType?: "integer";
|
|
110
|
-
labels?: Partial<Record<string, string>>;
|
|
111
|
-
loadOptions?: (() => Array<{
|
|
112
|
-
label: string;
|
|
113
|
-
value: string;
|
|
114
|
-
}>) | (() => Promise<Array<{
|
|
115
|
-
label: string;
|
|
116
|
-
value: string;
|
|
117
|
-
}>>);
|
|
118
|
-
}) => EnumSchema<TValues>;
|
|
119
|
-
readonly Array: <TItem extends AnySchema>(item: TItem, options?: SchemaOptions<Array<Static<TItem>>> & ArrayMetadata) => ArraySchema<TItem>;
|
|
120
|
-
readonly Object: <const TShape extends ObjectShape>(shape: TShape, options?: SchemaOptions<InferObject<TShape>> & ObjectMetadata) => ObjectSchema<TShape>;
|
|
121
|
-
readonly Optional: <TInner extends AnySchema>(inner: TInner) => OptionalSchema<TInner>;
|
|
122
|
-
};
|
|
123
|
-
export declare function toJsonSchema(schema: AnySchema): JsonSchema;
|
|
124
|
-
export {};
|