poe-code 3.0.187 → 3.0.189
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/prompts/github-issue-comment-created.md +1 -0
- package/dist/prompts/github-issue-opened.md +1 -0
- package/dist/prompts/github-pull-request-comment-created.md +1 -0
- package/dist/prompts/github-pull-request-opened.md +1 -0
- package/dist/prompts/github-pull-request-synchronized.md +1 -0
- 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 -1131
- 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,63 +0,0 @@
|
|
|
1
|
-
import type { ObjectSchema, Static } from "../../cmdkit-schema/dist/index.js";
|
|
2
|
-
import type { Group, Scope } from "./index.js";
|
|
3
|
-
type ScopeInput = readonly Scope[] | undefined;
|
|
4
|
-
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
5
|
-
type EmptyRecord = Record<never, never>;
|
|
6
|
-
type EffectiveCommandScope<TOwnScope extends ScopeInput, TInheritedScope extends ScopeInput> = TOwnScope extends readonly Scope[] ? TOwnScope : TInheritedScope extends readonly Scope[] ? TInheritedScope : readonly ["cli", "sdk"];
|
|
7
|
-
type EffectiveGroupScope<TOwnScope extends ScopeInput, TInheritedScope extends ScopeInput> = TOwnScope extends readonly Scope[] ? TOwnScope : TInheritedScope extends readonly Scope[] ? TInheritedScope : undefined;
|
|
8
|
-
type IncludesSDK<TScope> = TScope extends readonly Scope[] ? "sdk" extends TScope[number] ? true : false : false;
|
|
9
|
-
type Separator = "-" | "_" | " " | ".";
|
|
10
|
-
type IsUppercase<TValue extends string> = TValue extends Uppercase<TValue> ? TValue extends Lowercase<TValue> ? false : true : false;
|
|
11
|
-
type IsLowercase<TValue extends string> = TValue extends Lowercase<TValue> ? TValue extends Uppercase<TValue> ? false : true : false;
|
|
12
|
-
type LastCharacter<TValue extends string> = TValue extends `${infer THead}${infer TTail}` ? TTail extends "" ? THead : LastCharacter<TTail> : never;
|
|
13
|
-
type PushCurrentWord<TCurrent extends string, TWords extends readonly string[]> = TCurrent extends "" ? TWords : [...TWords, Lowercase<TCurrent>];
|
|
14
|
-
type SplitCamelWords<TValue extends string, TCurrent extends string = "", TWords extends readonly string[] = []> = TValue extends `${infer TChar}${infer TRest}` ? TChar extends Separator ? SplitCamelWords<TRest, "", PushCurrentWord<TCurrent, TWords>> : IsUppercase<TChar> extends true ? TCurrent extends "" ? SplitCamelWords<TRest, TChar, TWords> : TRest extends `${infer TNext}${string}` ? IsLowercase<LastCharacter<TCurrent>> extends true ? SplitCamelWords<TRest, TChar, PushCurrentWord<TCurrent, TWords>> : IsLowercase<TNext> extends true ? SplitCamelWords<TRest, TChar, PushCurrentWord<TCurrent, TWords>> : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords> : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords> : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords> : PushCurrentWord<TCurrent, TWords>;
|
|
15
|
-
type JoinCamelWords<TWords extends readonly string[]> = TWords extends readonly [
|
|
16
|
-
infer THead extends string,
|
|
17
|
-
...infer TTail extends readonly string[]
|
|
18
|
-
] ? `${THead}${CapitalizeJoinCamelWords<TTail>}` : "";
|
|
19
|
-
type CapitalizeJoinCamelWords<TWords extends readonly string[]> = TWords extends readonly [
|
|
20
|
-
infer THead extends string,
|
|
21
|
-
...infer TTail extends readonly string[]
|
|
22
|
-
] ? `${Capitalize<THead>}${CapitalizeJoinCamelWords<TTail>}` : "";
|
|
23
|
-
type CamelCase<TValue extends string> = JoinCamelWords<SplitCamelWords<TValue>>;
|
|
24
|
-
type Camelize<TValue> = TValue extends Primitive ? TValue : TValue extends readonly (infer TItem)[] ? Array<Camelize<TItem>> : TValue extends object ? {
|
|
25
|
-
[TKey in keyof TValue as TKey extends string ? CamelCase<TKey> : TKey]: Camelize<TValue[TKey]>;
|
|
26
|
-
} : TValue;
|
|
27
|
-
type SDKMethod<TParamsSchema extends ObjectSchema<any>, TResult> = (params: Camelize<Static<TParamsSchema>>) => Promise<TResult>;
|
|
28
|
-
type UnionToIntersection<TValue> = (TValue extends unknown ? (value: TValue) => void : never) extends (value: infer TResult) => void ? TResult : never;
|
|
29
|
-
type Simplify<TValue> = {
|
|
30
|
-
[TKey in keyof TValue]: TValue[TKey];
|
|
31
|
-
};
|
|
32
|
-
type RawChildrenValue<TChildren> = TChildren extends readonly unknown[] ? TChildren[number] : never;
|
|
33
|
-
type SDKNodeShape<TNode, TInheritedScope extends ScopeInput> = TNode extends {
|
|
34
|
-
kind: "command";
|
|
35
|
-
readonly __cmdkitCommandTypeInfo: {
|
|
36
|
-
name: infer TName extends string;
|
|
37
|
-
params: infer TParamsSchema extends ObjectSchema<any>;
|
|
38
|
-
result: infer TResult;
|
|
39
|
-
ownScope: infer TOwnScope extends ScopeInput;
|
|
40
|
-
};
|
|
41
|
-
} ? IncludesSDK<EffectiveCommandScope<TOwnScope, TInheritedScope>> extends true ? {
|
|
42
|
-
[TKey in CamelCase<TName>]: SDKMethod<TParamsSchema, TResult>;
|
|
43
|
-
} : EmptyRecord : TNode extends {
|
|
44
|
-
kind: "group";
|
|
45
|
-
readonly __cmdkitGroupTypeInfo: {
|
|
46
|
-
name: infer TName extends string;
|
|
47
|
-
children: infer TChildren extends readonly unknown[];
|
|
48
|
-
ownScope: infer TOwnScope extends ScopeInput;
|
|
49
|
-
};
|
|
50
|
-
} ? SDKChildrenShape<TChildren, EffectiveGroupScope<TOwnScope, TInheritedScope>> extends infer TChildShape extends object ? keyof TChildShape extends never ? EmptyRecord : {
|
|
51
|
-
[TKey in CamelCase<TName>]: TChildShape;
|
|
52
|
-
} : never : EmptyRecord;
|
|
53
|
-
type SDKChildrenShape<TChildren, TInheritedScope extends ScopeInput> = Simplify<UnionToIntersection<SDKNodeShape<RawChildrenValue<TChildren>, TInheritedScope>>>;
|
|
54
|
-
export interface CreateSDKOptions<TServices extends object = Record<string, unknown>> {
|
|
55
|
-
services?: TServices;
|
|
56
|
-
casing?: "camel";
|
|
57
|
-
}
|
|
58
|
-
export declare function createSDK<TRootInfo, TServices extends object = Record<string, unknown>>(root: Group<any> & {
|
|
59
|
-
readonly __cmdkitGroupTypeInfo: TRootInfo;
|
|
60
|
-
}, options?: CreateSDKOptions<TServices>): TRootInfo extends {
|
|
61
|
-
children: infer TChildren extends readonly unknown[];
|
|
62
|
-
} ? SDKChildrenShape<TChildren, undefined> : EmptyRecord;
|
|
63
|
-
export {};
|
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
// packages/cmdkit/src/sdk.ts
|
|
2
|
-
import { access, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
|
|
4
|
-
// packages/cmdkit/src/index.ts
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
var UserError = class extends Error {
|
|
7
|
-
constructor(message) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = "UserError";
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
function parseSimpleSemver(value) {
|
|
13
|
-
const parts = value.split(".");
|
|
14
|
-
if (parts.length !== 3) {
|
|
15
|
-
return void 0;
|
|
16
|
-
}
|
|
17
|
-
const parsed = parts.map((part) => {
|
|
18
|
-
if (part.length === 0) {
|
|
19
|
-
return Number.NaN;
|
|
20
|
-
}
|
|
21
|
-
for (const char of part) {
|
|
22
|
-
if (char < "0" || char > "9") {
|
|
23
|
-
return Number.NaN;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return Number(part);
|
|
27
|
-
});
|
|
28
|
-
if (parsed.some((part) => !Number.isInteger(part) || part < 0)) {
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
|
-
return parsed;
|
|
32
|
-
}
|
|
33
|
-
function parseMinimumApiVersion(requirement) {
|
|
34
|
-
if (!requirement.startsWith(">=")) {
|
|
35
|
-
return void 0;
|
|
36
|
-
}
|
|
37
|
-
return parseSimpleSemver(requirement.slice(2).trim());
|
|
38
|
-
}
|
|
39
|
-
function compareSemver(left, right) {
|
|
40
|
-
for (let index = 0; index < left.length; index += 1) {
|
|
41
|
-
if (left[index] === right[index]) {
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
return left[index] > right[index] ? 1 : -1;
|
|
45
|
-
}
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
function resolveCommandSecrets(command, env = process.env) {
|
|
49
|
-
const secrets = {};
|
|
50
|
-
for (const [name, secret] of Object.entries(command.secrets)) {
|
|
51
|
-
const value = env[secret.env];
|
|
52
|
-
if (value === void 0 && secret.optional !== true) {
|
|
53
|
-
const details = secret.description ? `
|
|
54
|
-
${secret.description}` : "";
|
|
55
|
-
throw new UserError(`Error: Missing required secret ${secret.env}${details}`);
|
|
56
|
-
}
|
|
57
|
-
secrets[name] = value;
|
|
58
|
-
}
|
|
59
|
-
return secrets;
|
|
60
|
-
}
|
|
61
|
-
async function assertCommandRequirements(command, context, options = {}) {
|
|
62
|
-
const requires = command.requires;
|
|
63
|
-
if (requires === void 0) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const env = options.env ?? process.env;
|
|
67
|
-
const authEnvVar = options.authEnvVar ?? "POE_API_KEY";
|
|
68
|
-
if (requires.auth === true && env[authEnvVar] === void 0) {
|
|
69
|
-
throw new UserError(
|
|
70
|
-
`Error: Command "${command.name}" requires authentication.
|
|
71
|
-
Run 'poe-code login' first.`
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
if (requires.apiVersion !== void 0) {
|
|
75
|
-
const minimumVersion = parseMinimumApiVersion(requires.apiVersion);
|
|
76
|
-
if (minimumVersion === void 0) {
|
|
77
|
-
throw new UserError(
|
|
78
|
-
`Error: Command "${command.name}" has invalid apiVersion requirement "${requires.apiVersion}". Expected format ">=X.Y.Z".`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
if (options.apiVersion === void 0) {
|
|
82
|
-
throw new UserError(
|
|
83
|
-
`Error: Command "${command.name}" requires API version ${requires.apiVersion}, but no runner API version was provided.`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
const runnerVersion = parseSimpleSemver(options.apiVersion);
|
|
87
|
-
if (runnerVersion === void 0) {
|
|
88
|
-
throw new UserError(
|
|
89
|
-
`Error: Command "${command.name}" requires API version ${requires.apiVersion}, but runner API version "${options.apiVersion}" is not valid semver.`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
if (compareSemver(runnerVersion, minimumVersion) < 0) {
|
|
93
|
-
throw new UserError(
|
|
94
|
-
`Error: Command "${command.name}" requires API version ${requires.apiVersion}, but runner API version is ${options.apiVersion}.`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const checkResult = await requires.check?.(context);
|
|
99
|
-
if (checkResult && !checkResult.ok) {
|
|
100
|
-
throw new UserError(checkResult.message ?? "Command precondition failed.");
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// packages/cmdkit/src/number-schema.ts
|
|
105
|
-
function isValidNumberSchemaValue(value, schema) {
|
|
106
|
-
return typeof value === "number" && Number.isFinite(value) && (schema.jsonType !== "integer" || Number.isInteger(value));
|
|
107
|
-
}
|
|
108
|
-
function getExpectedNumberDescription(schema) {
|
|
109
|
-
return schema.jsonType === "integer" ? "an integer" : "a number";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// packages/cmdkit/src/schema-scope.ts
|
|
113
|
-
function filterSchemaForScope(schema, scope) {
|
|
114
|
-
if (schema.scope !== void 0 && !schema.scope.includes(scope)) {
|
|
115
|
-
return void 0;
|
|
116
|
-
}
|
|
117
|
-
switch (schema.kind) {
|
|
118
|
-
case "optional": {
|
|
119
|
-
const inner = filterSchemaForScope(schema.inner, scope);
|
|
120
|
-
if (inner === void 0) {
|
|
121
|
-
return void 0;
|
|
122
|
-
}
|
|
123
|
-
if (inner.requiredScopes?.includes(scope)) {
|
|
124
|
-
return inner;
|
|
125
|
-
}
|
|
126
|
-
return { ...schema, inner };
|
|
127
|
-
}
|
|
128
|
-
case "array": {
|
|
129
|
-
const item = filterSchemaForScope(schema.item, scope);
|
|
130
|
-
return item === void 0 ? void 0 : { ...schema, item };
|
|
131
|
-
}
|
|
132
|
-
case "string":
|
|
133
|
-
case "number":
|
|
134
|
-
case "boolean":
|
|
135
|
-
case "enum":
|
|
136
|
-
return schema;
|
|
137
|
-
case "object":
|
|
138
|
-
return {
|
|
139
|
-
...schema,
|
|
140
|
-
shape: Object.fromEntries(
|
|
141
|
-
Object.entries(schema.shape).flatMap(([key, childSchema]) => {
|
|
142
|
-
const filtered = filterSchemaForScope(childSchema, scope);
|
|
143
|
-
return filtered === void 0 ? [] : [[key, filtered]];
|
|
144
|
-
})
|
|
145
|
-
)
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// packages/cmdkit/src/sdk.ts
|
|
151
|
-
var RESERVED_SERVICE_NAMES = /* @__PURE__ */ new Set(["params", "secrets", "fetch", "fs", "env", "progress"]);
|
|
152
|
-
function splitWords(value) {
|
|
153
|
-
const words = [];
|
|
154
|
-
let current = "";
|
|
155
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
156
|
-
const char = value[index] ?? "";
|
|
157
|
-
const lower = char.toLowerCase();
|
|
158
|
-
const upper = char.toUpperCase();
|
|
159
|
-
const isSeparator = char === "-" || char === "_" || char === " " || char === ".";
|
|
160
|
-
if (isSeparator) {
|
|
161
|
-
if (current.length > 0) {
|
|
162
|
-
words.push(current.toLowerCase());
|
|
163
|
-
current = "";
|
|
164
|
-
}
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
const isUppercase = char !== lower && char === upper;
|
|
168
|
-
const previous = value[index - 1];
|
|
169
|
-
const next = value[index + 1];
|
|
170
|
-
const previousIsLowercase = previous !== void 0 && previous === previous.toLowerCase() && previous !== previous.toUpperCase();
|
|
171
|
-
const nextIsLowercase = next !== void 0 && next === next.toLowerCase() && next !== next.toUpperCase();
|
|
172
|
-
if (isUppercase && current.length > 0 && (previousIsLowercase || nextIsLowercase)) {
|
|
173
|
-
words.push(current.toLowerCase());
|
|
174
|
-
current = char;
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
current += char;
|
|
178
|
-
}
|
|
179
|
-
if (current.length > 0) {
|
|
180
|
-
words.push(current.toLowerCase());
|
|
181
|
-
}
|
|
182
|
-
return words;
|
|
183
|
-
}
|
|
184
|
-
function formatSegment(segment) {
|
|
185
|
-
return splitWords(segment).map((word, index) => index === 0 ? word : `${word[0]?.toUpperCase() ?? ""}${word.slice(1)}`).join("");
|
|
186
|
-
}
|
|
187
|
-
function unwrapOptional(schema) {
|
|
188
|
-
if (schema.kind === "optional") {
|
|
189
|
-
return unwrapOptional(schema.inner);
|
|
190
|
-
}
|
|
191
|
-
return schema;
|
|
192
|
-
}
|
|
193
|
-
function isOptional(schema) {
|
|
194
|
-
return schema.kind === "optional";
|
|
195
|
-
}
|
|
196
|
-
function isPlainObject(value) {
|
|
197
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
198
|
-
}
|
|
199
|
-
function createFs() {
|
|
200
|
-
return {
|
|
201
|
-
readFile: async (path, encoding = "utf8") => readFile(path, { encoding }),
|
|
202
|
-
writeFile: async (path, contents) => {
|
|
203
|
-
await writeFile(path, contents);
|
|
204
|
-
},
|
|
205
|
-
exists: async (path) => {
|
|
206
|
-
try {
|
|
207
|
-
await access(path);
|
|
208
|
-
return true;
|
|
209
|
-
} catch {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
function createEnv(values = process.env) {
|
|
216
|
-
return {
|
|
217
|
-
get(key) {
|
|
218
|
-
return values[key];
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function validateServices(services) {
|
|
223
|
-
for (const name of Object.keys(services)) {
|
|
224
|
-
if (RESERVED_SERVICE_NAMES.has(name)) {
|
|
225
|
-
throw new Error(`Service name "${name}" is reserved. Choose a different name.`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function validateEnum(value, schema, label) {
|
|
230
|
-
if (!schema.values.includes(value)) {
|
|
231
|
-
throw new UserError(
|
|
232
|
-
`Invalid value for "${label}". Expected one of: ${schema.values.map((candidate) => String(candidate)).join(", ")}.`
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
return value;
|
|
236
|
-
}
|
|
237
|
-
function validateSchemaValue(schema, value, label) {
|
|
238
|
-
const unwrappedSchema = unwrapOptional(schema);
|
|
239
|
-
if (value === null && unwrappedSchema.nullable === true) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
switch (unwrappedSchema.kind) {
|
|
243
|
-
case "string":
|
|
244
|
-
if (typeof value !== "string") {
|
|
245
|
-
throw new UserError(`Invalid value for "${label}". Expected a string.`);
|
|
246
|
-
}
|
|
247
|
-
return value;
|
|
248
|
-
case "number":
|
|
249
|
-
if (!isValidNumberSchemaValue(value, unwrappedSchema)) {
|
|
250
|
-
throw new UserError(
|
|
251
|
-
`Invalid value for "${label}". Expected ${getExpectedNumberDescription(unwrappedSchema)}.`
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
return value;
|
|
255
|
-
case "boolean":
|
|
256
|
-
if (typeof value !== "boolean") {
|
|
257
|
-
throw new UserError(`Invalid value for "${label}". Expected a boolean.`);
|
|
258
|
-
}
|
|
259
|
-
return value;
|
|
260
|
-
case "enum":
|
|
261
|
-
return validateEnum(value, unwrappedSchema, label);
|
|
262
|
-
case "array":
|
|
263
|
-
if (!Array.isArray(value)) {
|
|
264
|
-
throw new UserError(`Invalid value for "${label}". Expected an array.`);
|
|
265
|
-
}
|
|
266
|
-
return value.map((item, index) => validateSchemaValue(unwrappedSchema.item, item, `${label}[${index}]`));
|
|
267
|
-
case "object":
|
|
268
|
-
return validateObjectSchema(unwrappedSchema, value, label);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function validateObjectSchema(schema, value, label) {
|
|
272
|
-
if (!isPlainObject(value)) {
|
|
273
|
-
throw new UserError(`Invalid value for "${label}". Expected an object.`);
|
|
274
|
-
}
|
|
275
|
-
const result = {};
|
|
276
|
-
const expectedKeys = /* @__PURE__ */ new Map();
|
|
277
|
-
for (const [key, childSchema] of Object.entries(schema.shape)) {
|
|
278
|
-
expectedKeys.set(formatSegment(key), [key, childSchema]);
|
|
279
|
-
}
|
|
280
|
-
for (const key of Object.keys(value)) {
|
|
281
|
-
if (!expectedKeys.has(key)) {
|
|
282
|
-
const fieldLabel = label.length === 0 ? key : `${label}.${key}`;
|
|
283
|
-
throw new UserError(`Unexpected parameter "${fieldLabel}".`);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
for (const [inputKey, [outputKey, rawChildSchema]] of expectedKeys.entries()) {
|
|
287
|
-
const childSchema = unwrapOptional(rawChildSchema);
|
|
288
|
-
const hasValue = Object.prototype.hasOwnProperty.call(value, inputKey);
|
|
289
|
-
const fieldLabel = label.length === 0 ? inputKey : `${label}.${inputKey}`;
|
|
290
|
-
if (!hasValue) {
|
|
291
|
-
if (childSchema.default !== void 0) {
|
|
292
|
-
result[outputKey] = childSchema.default;
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
if (isOptional(rawChildSchema)) {
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
throw new UserError(`Missing required parameter "${fieldLabel}".`);
|
|
299
|
-
}
|
|
300
|
-
result[outputKey] = validateSchemaValue(rawChildSchema, value[inputKey], fieldLabel);
|
|
301
|
-
}
|
|
302
|
-
return result;
|
|
303
|
-
}
|
|
304
|
-
function validateSDKArguments(schema, argumentsValue) {
|
|
305
|
-
return validateObjectSchema(schema, argumentsValue ?? {}, "");
|
|
306
|
-
}
|
|
307
|
-
function defineMember(target, key, value) {
|
|
308
|
-
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
309
|
-
throw new Error(`Duplicate SDK member "${key}".`);
|
|
310
|
-
}
|
|
311
|
-
Object.defineProperty(target, key, {
|
|
312
|
-
value,
|
|
313
|
-
enumerable: true,
|
|
314
|
-
configurable: false,
|
|
315
|
-
writable: false
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
function createSDK(root, options = {}) {
|
|
319
|
-
const services = options.services ?? {};
|
|
320
|
-
void options.casing;
|
|
321
|
-
validateServices(services);
|
|
322
|
-
function build(node) {
|
|
323
|
-
if (node.kind === "command") {
|
|
324
|
-
return async (params) => {
|
|
325
|
-
const secrets = resolveCommandSecrets(node);
|
|
326
|
-
const baseContext = {
|
|
327
|
-
...services,
|
|
328
|
-
secrets,
|
|
329
|
-
fetch: globalThis.fetch,
|
|
330
|
-
fs: createFs(),
|
|
331
|
-
env: createEnv(),
|
|
332
|
-
progress() {
|
|
333
|
-
return void 0;
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
await assertCommandRequirements(node, { ...baseContext, params: void 0 });
|
|
337
|
-
const paramsSchema = filterSchemaForScope(node.params, "sdk");
|
|
338
|
-
if (paramsSchema === void 0 || paramsSchema.kind !== "object") {
|
|
339
|
-
throw new Error(`Bug: command "${node.name}" must define an object params schema for SDK.`);
|
|
340
|
-
}
|
|
341
|
-
const validatedParams = validateSDKArguments(paramsSchema, params);
|
|
342
|
-
return node.handler({
|
|
343
|
-
...baseContext,
|
|
344
|
-
params: validatedParams
|
|
345
|
-
});
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
const output = {};
|
|
349
|
-
for (const child of node.children) {
|
|
350
|
-
if (child.kind === "command") {
|
|
351
|
-
if (!child.scope.includes("sdk")) {
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
defineMember(output, formatSegment(child.name), build(child));
|
|
355
|
-
continue;
|
|
356
|
-
}
|
|
357
|
-
const childValue = build(child);
|
|
358
|
-
if (isPlainObject(childValue) && Object.keys(childValue).length > 0) {
|
|
359
|
-
defineMember(output, formatSegment(child.name), childValue);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return output;
|
|
363
|
-
}
|
|
364
|
-
return build(root);
|
|
365
|
-
}
|
|
366
|
-
export {
|
|
367
|
-
createSDK
|
|
368
|
-
};
|
|
369
|
-
//# sourceMappingURL=sdk.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/sdk.ts", "../src/index.ts", "../src/number-schema.ts", "../src/schema-scope.ts"],
|
|
4
|
-
"sourcesContent": ["import { access, readFile, writeFile } from \"node:fs/promises\";\nimport type { AnySchema, ObjectSchema, Static } from \"@poe-code/cmdkit-schema\";\nimport type { Command, Group, HandlerEnv, HandlerFs, Scope } from \"./index.js\";\nimport { UserError, assertCommandRequirements, resolveCommandSecrets } from \"./index.js\";\nimport { getExpectedNumberDescription, isValidNumberSchemaValue } from \"./number-schema.js\";\nimport { filterSchemaForScope } from \"./schema-scope.js\";\n\nconst RESERVED_SERVICE_NAMES = new Set([\"params\", \"secrets\", \"fetch\", \"fs\", \"env\", \"progress\"]);\n\ntype ScopeInput = readonly Scope[] | undefined;\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined;\ntype EmptyRecord = Record<never, never>;\n\ntype EffectiveCommandScope<\n TOwnScope extends ScopeInput,\n TInheritedScope extends ScopeInput,\n> = TOwnScope extends readonly Scope[]\n ? TOwnScope\n : TInheritedScope extends readonly Scope[]\n ? TInheritedScope\n : readonly [\"cli\", \"sdk\"];\n\ntype EffectiveGroupScope<\n TOwnScope extends ScopeInput,\n TInheritedScope extends ScopeInput,\n> = TOwnScope extends readonly Scope[]\n ? TOwnScope\n : TInheritedScope extends readonly Scope[]\n ? TInheritedScope\n : undefined;\n\ntype IncludesSDK<TScope> = TScope extends readonly Scope[]\n ? \"sdk\" extends TScope[number]\n ? true\n : false\n : false;\n\ntype Separator = \"-\" | \"_\" | \" \" | \".\";\n\ntype IsUppercase<TValue extends string> = TValue extends Uppercase<TValue>\n ? TValue extends Lowercase<TValue>\n ? false\n : true\n : false;\n\ntype IsLowercase<TValue extends string> = TValue extends Lowercase<TValue>\n ? TValue extends Uppercase<TValue>\n ? false\n : true\n : false;\n\ntype LastCharacter<TValue extends string> = TValue extends `${infer THead}${infer TTail}`\n ? TTail extends \"\"\n ? THead\n : LastCharacter<TTail>\n : never;\n\ntype PushCurrentWord<\n TCurrent extends string,\n TWords extends readonly string[],\n> = TCurrent extends \"\" ? TWords : [...TWords, Lowercase<TCurrent>];\n\ntype SplitCamelWords<\n TValue extends string,\n TCurrent extends string = \"\",\n TWords extends readonly string[] = [],\n> = TValue extends `${infer TChar}${infer TRest}`\n ? TChar extends Separator\n ? SplitCamelWords<TRest, \"\", PushCurrentWord<TCurrent, TWords>>\n : IsUppercase<TChar> extends true\n ? TCurrent extends \"\"\n ? SplitCamelWords<TRest, TChar, TWords>\n : TRest extends `${infer TNext}${string}`\n ? IsLowercase<LastCharacter<TCurrent>> extends true\n ? SplitCamelWords<TRest, TChar, PushCurrentWord<TCurrent, TWords>>\n : IsLowercase<TNext> extends true\n ? SplitCamelWords<TRest, TChar, PushCurrentWord<TCurrent, TWords>>\n : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords>\n : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords>\n : SplitCamelWords<TRest, `${TCurrent}${TChar}`, TWords>\n : PushCurrentWord<TCurrent, TWords>;\n\ntype JoinCamelWords<TWords extends readonly string[]> = TWords extends readonly [\n infer THead extends string,\n ...infer TTail extends readonly string[],\n]\n ? `${THead}${CapitalizeJoinCamelWords<TTail>}`\n : \"\";\n\ntype CapitalizeJoinCamelWords<TWords extends readonly string[]> = TWords extends readonly [\n infer THead extends string,\n ...infer TTail extends readonly string[],\n]\n ? `${Capitalize<THead>}${CapitalizeJoinCamelWords<TTail>}`\n : \"\";\n\ntype CamelCase<TValue extends string> = JoinCamelWords<SplitCamelWords<TValue>>;\n\ntype Camelize<TValue> = TValue extends Primitive\n ? TValue\n : TValue extends readonly (infer TItem)[]\n ? Array<Camelize<TItem>>\n : TValue extends object\n ? {\n [TKey in keyof TValue as TKey extends string ? CamelCase<TKey> : TKey]: Camelize<TValue[TKey]>;\n }\n : TValue;\n\ntype SDKMethod<TParamsSchema extends ObjectSchema<any>, TResult> = (\n params: Camelize<Static<TParamsSchema>>\n) => Promise<TResult>;\n\ntype UnionToIntersection<TValue> = (\n TValue extends unknown ? (value: TValue) => void : never\n) extends (value: infer TResult) => void\n ? TResult\n : never;\n\ntype Simplify<TValue> = { [TKey in keyof TValue]: TValue[TKey] };\n\ntype RawChildrenValue<TChildren> = TChildren extends readonly unknown[] ? TChildren[number] : never;\n\ntype SDKNodeShape<TNode, TInheritedScope extends ScopeInput> =\n TNode extends {\n kind: \"command\";\n readonly __cmdkitCommandTypeInfo: {\n name: infer TName extends string;\n params: infer TParamsSchema extends ObjectSchema<any>;\n result: infer TResult;\n ownScope: infer TOwnScope extends ScopeInput;\n };\n }\n ? IncludesSDK<EffectiveCommandScope<TOwnScope, TInheritedScope>> extends true\n ? { [TKey in CamelCase<TName>]: SDKMethod<TParamsSchema, TResult> }\n : EmptyRecord\n : TNode extends {\n kind: \"group\";\n readonly __cmdkitGroupTypeInfo: {\n name: infer TName extends string;\n children: infer TChildren extends readonly unknown[];\n ownScope: infer TOwnScope extends ScopeInput;\n };\n }\n ? SDKChildrenShape<TChildren, EffectiveGroupScope<TOwnScope, TInheritedScope>> extends infer TChildShape extends object\n ? keyof TChildShape extends never\n ? EmptyRecord\n : { [TKey in CamelCase<TName>]: TChildShape }\n : never\n : EmptyRecord;\n\ntype SDKChildrenShape<TChildren, TInheritedScope extends ScopeInput> = Simplify<\n UnionToIntersection<SDKNodeShape<RawChildrenValue<TChildren>, TInheritedScope>>\n>;\n\nexport interface CreateSDKOptions<TServices extends object = Record<string, unknown>> {\n services?: TServices;\n casing?: \"camel\";\n}\n\nfunction splitWords(value: string): string[] {\n const words: string[] = [];\n let current = \"\";\n\n for (let index = 0; index < value.length; index += 1) {\n const char = value[index] ?? \"\";\n const lower = char.toLowerCase();\n const upper = char.toUpperCase();\n const isSeparator = char === \"-\" || char === \"_\" || char === \" \" || char === \".\";\n\n if (isSeparator) {\n if (current.length > 0) {\n words.push(current.toLowerCase());\n current = \"\";\n }\n continue;\n }\n\n const isUppercase = char !== lower && char === upper;\n const previous = value[index - 1];\n const next = value[index + 1];\n const previousIsLowercase =\n previous !== undefined && previous === previous.toLowerCase() && previous !== previous.toUpperCase();\n const nextIsLowercase =\n next !== undefined && next === next.toLowerCase() && next !== next.toUpperCase();\n\n if (isUppercase && current.length > 0 && (previousIsLowercase || nextIsLowercase)) {\n words.push(current.toLowerCase());\n current = char;\n continue;\n }\n\n current += char;\n }\n\n if (current.length > 0) {\n words.push(current.toLowerCase());\n }\n\n return words;\n}\n\nfunction formatSegment(segment: string): string {\n return splitWords(segment)\n .map((word, index) => (index === 0 ? word : `${word[0]?.toUpperCase() ?? \"\"}${word.slice(1)}`))\n .join(\"\");\n}\n\nfunction unwrapOptional(schema: AnySchema): AnySchema {\n if (schema.kind === \"optional\") {\n return unwrapOptional(schema.inner);\n }\n\n return schema;\n}\n\nfunction isOptional(schema: AnySchema): boolean {\n return schema.kind === \"optional\";\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction createFs(): HandlerFs {\n return {\n readFile: async (path: string, encoding = \"utf8\") => readFile(path, { encoding }),\n writeFile: async (path: string, contents: string) => {\n await writeFile(path, contents);\n },\n exists: async (path: string) => {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n },\n };\n}\n\nfunction createEnv(values: Record<string, string | undefined> = process.env): HandlerEnv {\n return {\n get(key: string): string | undefined {\n return values[key];\n },\n };\n}\n\nfunction validateServices(services: Record<string, unknown>): void {\n for (const name of Object.keys(services)) {\n if (RESERVED_SERVICE_NAMES.has(name)) {\n throw new Error(`Service name \"${name}\" is reserved. Choose a different name.`);\n }\n }\n}\n\nfunction validateEnum(value: unknown, schema: Extract<AnySchema, { kind: \"enum\" }>, label: string): string | number | boolean {\n if (!schema.values.includes(value as never)) {\n throw new UserError(\n `Invalid value for \"${label}\". Expected one of: ${schema.values.map((candidate) => String(candidate)).join(\", \")}.`\n );\n }\n\n return value as string | number | boolean;\n}\n\nfunction validateSchemaValue(schema: AnySchema, value: unknown, label: string): unknown {\n const unwrappedSchema = unwrapOptional(schema);\n\n if (value === null && unwrappedSchema.nullable === true) {\n return null;\n }\n\n switch (unwrappedSchema.kind) {\n case \"string\":\n if (typeof value !== \"string\") {\n throw new UserError(`Invalid value for \"${label}\". Expected a string.`);\n }\n return value;\n\n case \"number\":\n if (!isValidNumberSchemaValue(value, unwrappedSchema)) {\n throw new UserError(\n `Invalid value for \"${label}\". Expected ${getExpectedNumberDescription(unwrappedSchema)}.`\n );\n }\n return value;\n\n case \"boolean\":\n if (typeof value !== \"boolean\") {\n throw new UserError(`Invalid value for \"${label}\". Expected a boolean.`);\n }\n return value;\n\n case \"enum\":\n return validateEnum(value, unwrappedSchema, label);\n\n case \"array\":\n if (!Array.isArray(value)) {\n throw new UserError(`Invalid value for \"${label}\". Expected an array.`);\n }\n return value.map((item, index) => validateSchemaValue(unwrappedSchema.item, item, `${label}[${index}]`));\n\n case \"object\":\n return validateObjectSchema(unwrappedSchema, value, label);\n }\n}\n\nfunction validateObjectSchema(\n schema: ObjectSchema<any>,\n value: unknown,\n label: string\n): Record<string, unknown> {\n if (!isPlainObject(value)) {\n throw new UserError(`Invalid value for \"${label}\". Expected an object.`);\n }\n\n const result: Record<string, unknown> = {};\n const expectedKeys = new Map<string, [string, AnySchema]>();\n\n for (const [key, childSchema] of Object.entries(schema.shape) as Array<[string, AnySchema]>) {\n expectedKeys.set(formatSegment(key), [key, childSchema]);\n }\n\n for (const key of Object.keys(value)) {\n if (!expectedKeys.has(key)) {\n const fieldLabel = label.length === 0 ? key : `${label}.${key}`;\n throw new UserError(`Unexpected parameter \"${fieldLabel}\".`);\n }\n }\n\n for (const [inputKey, [outputKey, rawChildSchema]] of expectedKeys.entries()) {\n const childSchema = unwrapOptional(rawChildSchema);\n const hasValue = Object.prototype.hasOwnProperty.call(value, inputKey);\n const fieldLabel = label.length === 0 ? inputKey : `${label}.${inputKey}`;\n\n if (!hasValue) {\n if (childSchema.default !== undefined) {\n result[outputKey] = childSchema.default;\n continue;\n }\n\n if (isOptional(rawChildSchema)) {\n continue;\n }\n\n throw new UserError(`Missing required parameter \"${fieldLabel}\".`);\n }\n\n result[outputKey] = validateSchemaValue(rawChildSchema, value[inputKey], fieldLabel);\n }\n\n return result;\n}\n\nfunction validateSDKArguments(\n schema: ObjectSchema<any>,\n argumentsValue: Record<string, unknown> | undefined\n): Record<string, unknown> {\n return validateObjectSchema(schema, argumentsValue ?? {}, \"\");\n}\n\nfunction defineMember(target: Record<string, unknown>, key: string, value: unknown): void {\n if (Object.prototype.hasOwnProperty.call(target, key)) {\n throw new Error(`Duplicate SDK member \"${key}\".`);\n }\n\n Object.defineProperty(target, key, {\n value,\n enumerable: true,\n configurable: false,\n writable: false,\n });\n}\n\nexport function createSDK<\n TRootInfo,\n TServices extends object = Record<string, unknown>,\n>(\n root: Group<any> & {\n readonly __cmdkitGroupTypeInfo: TRootInfo;\n },\n options?: CreateSDKOptions<TServices>\n): TRootInfo extends { children: infer TChildren extends readonly unknown[] }\n ? SDKChildrenShape<TChildren, undefined>\n : EmptyRecord;\nexport function createSDK(\n root: Group<any>,\n options: CreateSDKOptions<any> = {}\n): Record<string, unknown> {\n const services = options.services ?? {};\n void options.casing;\n validateServices(services as Record<string, unknown>);\n\n function build(node: Group<any> | Command<any, any, any, any>): unknown {\n if (node.kind === \"command\") {\n return async (params: Record<string, unknown> | undefined) => {\n const secrets = resolveCommandSecrets(node);\n const baseContext = {\n ...services,\n secrets,\n fetch: globalThis.fetch,\n fs: createFs(),\n env: createEnv(),\n progress(): void {\n return undefined;\n },\n };\n\n await assertCommandRequirements(node, { ...baseContext, params: undefined });\n\n const paramsSchema = filterSchemaForScope(node.params, \"sdk\");\n\n if (paramsSchema === undefined || paramsSchema.kind !== \"object\") {\n throw new Error(`Bug: command \"${node.name}\" must define an object params schema for SDK.`);\n }\n\n const validatedParams = validateSDKArguments(paramsSchema, params);\n return node.handler({\n ...baseContext,\n params: validatedParams,\n } as Parameters<typeof node.handler>[0]);\n };\n }\n\n const output: Record<string, unknown> = {};\n\n for (const child of node.children) {\n if (child.kind === \"command\") {\n if (!child.scope.includes(\"sdk\")) {\n continue;\n }\n\n defineMember(output, formatSegment(child.name), build(child));\n continue;\n }\n\n const childValue = build(child);\n if (isPlainObject(childValue) && Object.keys(childValue).length > 0) {\n defineMember(output, formatSegment(child.name), childValue);\n }\n }\n\n return output;\n }\n\n return build(root) as Record<string, unknown>;\n}\n", "import { fileURLToPath } from \"node:url\";\nimport type { ObjectSchema, Static } from \"@poe-code/cmdkit-schema\";\nimport type { LoggerOutput, RenderTableOptions, ThemePalette } from \"@poe-code/design-system\";\n\nconst commandConfigSymbol = Symbol(\"cmdkit.command.config\");\nconst groupConfigSymbol = Symbol(\"cmdkit.group.config\");\nconst commandSourcePathSymbol = Symbol(\"cmdkit.command.sourcePath\");\n\ntype ScopeValue = \"cli\" | \"mcp\" | \"sdk\";\ntype AnyObjectSchema = ObjectSchema<Record<string, never>>;\ntype EmptyServices = Record<string, never>;\ntype ScopeInput = readonly Scope[] | undefined;\n\nexport type Scope = ScopeValue;\n\nexport interface SecretDefinition {\n env: string;\n description?: string;\n optional?: boolean;\n}\n\nexport type SecretDeclarations = Record<string, SecretDefinition>;\n\ntype OptionalSecretKeys<TSecrets extends SecretDeclarations> = {\n [TKey in keyof TSecrets]: TSecrets[TKey] extends { optional: true } ? TKey : never;\n}[keyof TSecrets];\n\ntype RequiredSecretKeys<TSecrets extends SecretDeclarations> = Exclude<\n keyof TSecrets,\n OptionalSecretKeys<TSecrets>\n>;\n\nexport type InferSecrets<TSecrets extends SecretDeclarations | undefined> =\n TSecrets extends SecretDeclarations\n ? { [TKey in RequiredSecretKeys<TSecrets>]: string } & {\n [TKey in OptionalSecretKeys<TSecrets>]?: string;\n }\n : Record<string, never>;\n\nexport interface HandlerFs {\n readFile(path: string, encoding?: BufferEncoding): Promise<string>;\n writeFile(path: string, contents: string): Promise<void>;\n exists(path: string): Promise<boolean>;\n}\n\nexport interface HandlerEnv {\n get(key: string): string | undefined;\n}\n\nexport interface RenderPrimitives {\n logger: LoggerOutput;\n renderTable(options: RenderTableOptions): string;\n getTheme(): ThemePalette;\n note(message: string, title?: string): void;\n}\n\nexport interface CheckResult {\n ok: boolean;\n message?: string;\n}\n\nexport type GroupCheckContext<TServices extends object = EmptyServices> = TServices & {\n params?: unknown;\n secrets?: Record<string, string | undefined>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport type CommandCheckContext<\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TServices extends object = EmptyServices,\n> = TServices & {\n params?: Static<TParamsSchema>;\n secrets?: InferSecrets<TSecrets>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport interface Requires<TContext = unknown> {\n auth?: boolean;\n apiVersion?: string;\n check?: (ctx: TContext) => Promise<CheckResult>;\n}\n\nexport interface Renderers<TResult> {\n rich?: (result: TResult, primitives: RenderPrimitives) => void;\n markdown?: (result: TResult, primitives: RenderPrimitives) => string;\n json?: (result: TResult, primitives: RenderPrimitives) => unknown;\n}\n\nexport type HandlerContext<\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TServices extends object = EmptyServices,\n> = TServices & {\n params: Static<TParamsSchema>;\n secrets: InferSecrets<TSecrets>;\n fetch: typeof globalThis.fetch;\n fs: HandlerFs;\n env: HandlerEnv;\n progress(message: string): void;\n};\n\nexport interface CommandConfig<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n> {\n name: string;\n description?: string;\n aliases?: string[];\n positional?: string[];\n params: TParamsSchema;\n secrets?: TSecrets;\n scope?: Scope[];\n confirm?: boolean;\n requires?: Requires<CommandCheckContext<TParamsSchema, TSecrets, TServices>>;\n handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;\n render?: Renderers<TResult>;\n}\n\nexport interface Command<\n TServices extends object = EmptyServices,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TResult = unknown,\n> {\n kind: \"command\";\n name: string;\n description?: string;\n aliases: string[];\n positional: string[];\n params: TParamsSchema;\n secrets: SecretDeclarations;\n scope: Scope[];\n confirm: boolean;\n requires?: Requires<any>;\n handler: (ctx: HandlerContext<TParamsSchema, TSecrets, TServices>) => Promise<TResult>;\n render?: Renderers<TResult>;\n}\n\nexport interface GroupConfig<TServices extends object> {\n name: string;\n description?: string;\n aliases?: string[];\n scope?: Scope[];\n secrets?: SecretDeclarations;\n requires?: Requires<GroupCheckContext<TServices>>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\nexport interface Group<TServices extends object = EmptyServices> {\n kind: \"group\";\n name: string;\n description?: string;\n aliases: string[];\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\nexport type CommandNode<TServices extends object = EmptyServices> =\n | Command<TServices, any, any, any>\n | Group<TServices>;\n\nexport interface CommandTypeInfo<\n TName extends string = string,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TResult = unknown,\n TOwnScope extends ScopeInput = ScopeInput,\n> {\n name: TName;\n params: TParamsSchema;\n result: TResult;\n ownScope: TOwnScope;\n}\n\nexport interface GroupTypeInfo<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TChildren extends readonly unknown[] = readonly CommandNode<TServices>[],\n TOwnScope extends ScopeInput = ScopeInput,\n> {\n name: TName;\n children: TChildren;\n ownScope: TOwnScope;\n}\n\ntype TypedCommandMetadata<\n TName extends string,\n TParamsSchema extends ObjectSchema<any>,\n TResult,\n TOwnScope extends ScopeInput,\n> = {\n readonly __cmdkitCommandTypeInfo: CommandTypeInfo<TName, TParamsSchema, TResult, TOwnScope>;\n};\n\ntype TypedGroupMetadata<\n TServices extends object,\n TName extends string,\n TChildren extends readonly unknown[],\n TOwnScope extends ScopeInput,\n> = {\n readonly __cmdkitGroupTypeInfo: GroupTypeInfo<TServices, TName, TChildren, TOwnScope>;\n};\n\ninterface InternalCommandConfig {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n sourcePath?: string;\n}\n\ninterface InternalGroupConfig<TServices extends object> {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n children: Array<CommandNode<TServices>>;\n default?: Command<TServices, any, any, any>;\n}\n\ninterface InheritedMetadata {\n scope?: Scope[];\n secrets: SecretDeclarations;\n requires?: Requires<any>;\n}\n\nexport class UserError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"UserError\";\n }\n}\n\nexport interface CommandRequirementOptions {\n apiVersion?: string;\n authEnvVar?: string;\n env?: Record<string, string | undefined>;\n}\n\nfunction cloneScope(scope: Scope[] | undefined): Scope[] | undefined {\n return scope === undefined ? undefined : [...scope];\n}\n\nfunction cloneSecretDefinition(secret: SecretDefinition): SecretDefinition {\n return {\n env: secret.env,\n description: secret.description,\n optional: secret.optional,\n };\n}\n\nfunction cloneSecrets(secrets: SecretDeclarations | undefined): SecretDeclarations {\n if (secrets === undefined) {\n return {};\n }\n\n return Object.fromEntries(\n Object.entries(secrets).map(([key, secret]) => [key, cloneSecretDefinition(secret)])\n );\n}\n\nfunction cloneRequires<TContext>(requires: Requires<TContext> | undefined): Requires<TContext> | undefined {\n if (requires === undefined) {\n return undefined;\n }\n\n return {\n auth: requires.auth,\n apiVersion: requires.apiVersion,\n check: requires.check,\n };\n}\n\nfunction parseStackPath(candidate: string): string | undefined {\n if (candidate.startsWith(\"file://\")) {\n try {\n return fileURLToPath(candidate);\n } catch {\n return undefined;\n }\n }\n\n if (candidate.startsWith(\"/\")) {\n return candidate;\n }\n\n return undefined;\n}\n\nfunction extractStackPath(line: string): string | undefined {\n const trimmed = line.trim();\n const fileIndex = trimmed.indexOf(\"file://\");\n\n if (fileIndex >= 0) {\n const location = trimmed.slice(fileIndex);\n const separatorIndex = location.lastIndexOf(\":\");\n const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(\":\", separatorIndex - 1) : -1;\n const candidate =\n separatorIndex >= 0 && previousSeparatorIndex >= 0\n ? location.slice(0, previousSeparatorIndex)\n : location;\n\n return parseStackPath(candidate);\n }\n\n const slashIndex = trimmed.indexOf(\"/\");\n if (slashIndex < 0) {\n return undefined;\n }\n\n const location = trimmed.slice(slashIndex);\n const separatorIndex = location.lastIndexOf(\":\");\n const previousSeparatorIndex = separatorIndex >= 0 ? location.lastIndexOf(\":\", separatorIndex - 1) : -1;\n const candidate =\n separatorIndex >= 0 && previousSeparatorIndex >= 0\n ? location.slice(0, previousSeparatorIndex)\n : location;\n\n return parseStackPath(candidate);\n}\n\nfunction inferCommandSourcePath(): string | undefined {\n const stack = new Error().stack;\n\n if (typeof stack !== \"string\") {\n return undefined;\n }\n\n for (const line of stack.split(\"\\n\").slice(1)) {\n const candidate = extractStackPath(line);\n\n if (candidate === undefined) {\n continue;\n }\n\n if (\n candidate.includes(\"/packages/cmdkit/src/index.ts\") ||\n candidate.includes(\"/packages/cmdkit/dist/index.js\")\n ) {\n continue;\n }\n\n return candidate;\n }\n\n return undefined;\n}\n\nfunction composeChecks(\n parentCheck: Requires<any>[\"check\"] | undefined,\n childCheck: Requires<any>[\"check\"] | undefined\n): Requires<any>[\"check\"] | undefined {\n if (parentCheck === undefined) {\n return childCheck;\n }\n\n if (childCheck === undefined) {\n return parentCheck;\n }\n\n return async (ctx) => {\n const parentResult = await parentCheck(ctx);\n if (!parentResult.ok) {\n return parentResult;\n }\n\n return childCheck(ctx);\n };\n}\n\nfunction mergeRequires(parent: Requires<any> | undefined, child: Requires<any> | undefined): Requires<any> | undefined {\n if (parent === undefined && child === undefined) {\n return undefined;\n }\n\n const merged: Requires<any> = {\n auth: child?.auth ?? parent?.auth,\n apiVersion: child?.apiVersion ?? parent?.apiVersion,\n check: composeChecks(parent?.check, child?.check),\n };\n\n if (\n merged.auth === undefined &&\n merged.apiVersion === undefined &&\n merged.check === undefined\n ) {\n return undefined;\n }\n\n return merged;\n}\n\nfunction parseSimpleSemver(value: string): [number, number, number] | undefined {\n const parts = value.split(\".\");\n if (parts.length !== 3) {\n return undefined;\n }\n\n const parsed = parts.map((part) => {\n if (part.length === 0) {\n return Number.NaN;\n }\n\n for (const char of part) {\n if (char < \"0\" || char > \"9\") {\n return Number.NaN;\n }\n }\n\n return Number(part);\n });\n\n if (parsed.some((part) => !Number.isInteger(part) || part < 0)) {\n return undefined;\n }\n\n return parsed as [number, number, number];\n}\n\nfunction parseMinimumApiVersion(requirement: string): [number, number, number] | undefined {\n if (!requirement.startsWith(\">=\")) {\n return undefined;\n }\n\n return parseSimpleSemver(requirement.slice(2).trim());\n}\n\nfunction compareSemver(left: [number, number, number], right: [number, number, number]): number {\n for (let index = 0; index < left.length; index += 1) {\n if (left[index] === right[index]) {\n continue;\n }\n\n return left[index]! > right[index]! ? 1 : -1;\n }\n\n return 0;\n}\n\nexport function resolveCommandSecrets(\n command: Command<any, any, any, any>,\n env: Record<string, string | undefined> = process.env\n): Record<string, string | undefined> {\n const secrets: Record<string, string | undefined> = {};\n\n for (const [name, secret] of Object.entries(command.secrets)) {\n const value = env[secret.env];\n\n if (value === undefined && secret.optional !== true) {\n const details = secret.description ? `\\n ${secret.description}` : \"\";\n throw new UserError(`Error: Missing required secret ${secret.env}${details}`);\n }\n\n secrets[name] = value;\n }\n\n return secrets;\n}\n\nexport async function assertCommandRequirements(\n command: Command<any, any, any, any>,\n context: GroupCheckContext<any>,\n options: CommandRequirementOptions = {}\n): Promise<void> {\n const requires = command.requires;\n if (requires === undefined) {\n return;\n }\n\n const env = options.env ?? process.env;\n const authEnvVar = options.authEnvVar ?? \"POE_API_KEY\";\n\n if (requires.auth === true && env[authEnvVar] === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires authentication.\\n Run 'poe-code login' first.`\n );\n }\n\n if (requires.apiVersion !== undefined) {\n const minimumVersion = parseMinimumApiVersion(requires.apiVersion);\n if (minimumVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" has invalid apiVersion requirement \"${requires.apiVersion}\". Expected format \">=X.Y.Z\".`\n );\n }\n\n if (options.apiVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but no runner API version was provided.`\n );\n }\n\n const runnerVersion = parseSimpleSemver(options.apiVersion);\n if (runnerVersion === undefined) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but runner API version \"${options.apiVersion}\" is not valid semver.`\n );\n }\n\n if (compareSemver(runnerVersion, minimumVersion) < 0) {\n throw new UserError(\n `Error: Command \"${command.name}\" requires API version ${requires.apiVersion}, but runner API version is ${options.apiVersion}.`\n );\n }\n }\n\n const checkResult = await requires.check?.(context);\n if (checkResult && !checkResult.ok) {\n throw new UserError(checkResult.message ?? \"Command precondition failed.\");\n }\n}\n\nfunction mergeSecrets(parent: SecretDeclarations, child: SecretDeclarations): SecretDeclarations {\n return cloneSecrets({\n ...parent,\n ...child,\n });\n}\n\nfunction resolveCommandScope(ownScope: Scope[] | undefined, inheritedScope: Scope[] | undefined): Scope[] {\n return cloneScope(ownScope ?? inheritedScope) ?? [\"cli\", \"sdk\"];\n}\n\nfunction resolveGroupScope(ownScope: Scope[] | undefined, inheritedScope: Scope[] | undefined): Scope[] | undefined {\n return cloneScope(ownScope ?? inheritedScope);\n}\n\nfunction createBaseCommand<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n>(\n config: CommandConfig<TServices, TParamsSchema, TSecrets, TResult>\n): Command<TServices, TParamsSchema, TSecrets, TResult> {\n const command: Command<TServices, TParamsSchema, TSecrets, TResult> = {\n kind: \"command\",\n name: config.name,\n description: config.description,\n aliases: [...(config.aliases ?? [])],\n positional: [...(config.positional ?? [])],\n params: config.params,\n secrets: cloneSecrets(config.secrets),\n scope: resolveCommandScope(config.scope, undefined),\n confirm: config.confirm ?? false,\n requires: cloneRequires(config.requires),\n handler: config.handler,\n render: config.render,\n };\n\n Object.defineProperty(command, commandConfigSymbol, {\n value: {\n scope: cloneScope(config.scope),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n sourcePath: inferCommandSourcePath(),\n } satisfies InternalCommandConfig,\n });\n\n return command;\n}\n\nfunction createBaseGroup<TServices extends object>(config: GroupConfig<TServices>): Group<TServices> {\n const group: Group<TServices> = {\n kind: \"group\",\n name: config.name,\n description: config.description,\n aliases: [...(config.aliases ?? [])],\n scope: resolveGroupScope(config.scope, undefined),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n children: [],\n default: undefined,\n };\n\n Object.defineProperty(group, groupConfigSymbol, {\n value: {\n scope: cloneScope(config.scope),\n secrets: cloneSecrets(config.secrets),\n requires: cloneRequires(config.requires),\n children: [...config.children],\n default: config.default,\n } satisfies InternalGroupConfig<TServices>,\n });\n\n return group;\n}\n\nfunction getInternalCommandConfig(command: Command<any, any, any, any>): InternalCommandConfig {\n return (command as Command<any, any, any, any> & { [commandConfigSymbol]: InternalCommandConfig })[\n commandConfigSymbol\n ];\n}\n\nfunction getInternalGroupConfig<TServices extends object>(group: Group<TServices>): InternalGroupConfig<TServices> {\n return (group as Group<TServices> & { [groupConfigSymbol]: InternalGroupConfig<TServices> })[\n groupConfigSymbol\n ];\n}\n\nfunction materializeCommand<\n TServices extends object,\n TParamsSchema extends ObjectSchema<any>,\n TSecrets extends SecretDeclarations | undefined,\n TResult,\n>(\n command: Command<TServices, TParamsSchema, TSecrets, TResult>,\n inherited: InheritedMetadata\n): Command<TServices, TParamsSchema, TSecrets, TResult> {\n const internal = getInternalCommandConfig(command);\n\n const materialized: Command<TServices, TParamsSchema, TSecrets, TResult> = {\n kind: \"command\",\n name: command.name,\n description: command.description,\n aliases: [...command.aliases],\n positional: [...command.positional],\n params: command.params,\n secrets: mergeSecrets(inherited.secrets, internal.secrets),\n scope: resolveCommandScope(internal.scope, inherited.scope),\n confirm: command.confirm,\n requires: mergeRequires(inherited.requires, internal.requires),\n handler: command.handler,\n render: command.render,\n };\n\n Object.defineProperty(materialized, commandConfigSymbol, {\n value: {\n scope: cloneScope(internal.scope),\n secrets: cloneSecrets(internal.secrets),\n requires: cloneRequires(internal.requires),\n sourcePath: internal.sourcePath,\n } satisfies InternalCommandConfig,\n });\n\n Object.defineProperty(materialized, commandSourcePathSymbol, {\n value: internal.sourcePath,\n });\n\n return materialized;\n}\n\nfunction materializeGroup<TServices extends object>(\n group: Group<TServices>,\n inherited: InheritedMetadata\n): Group<TServices> {\n const internal = getInternalGroupConfig(group);\n const scope = resolveGroupScope(internal.scope, inherited.scope);\n const secrets = mergeSecrets(inherited.secrets, internal.secrets);\n const requires = mergeRequires(inherited.requires, internal.requires);\n const materializedChildren = internal.children.map((child) =>\n materializeNode(child, {\n scope,\n secrets,\n requires,\n })\n );\n\n let defaultChild: Command<TServices, any, any, any> | undefined;\n\n if (internal.default !== undefined) {\n const defaultIndex = internal.children.indexOf(internal.default);\n\n if (defaultIndex === -1) {\n throw new UserError(`Default command \"${internal.default.name}\" must be listed in children.`);\n }\n\n const resolvedDefault = materializedChildren[defaultIndex];\n if (resolvedDefault?.kind !== \"command\") {\n throw new UserError(`Default child \"${internal.default.name}\" must be a command.`);\n }\n\n defaultChild = resolvedDefault;\n }\n\n const materialized: Group<TServices> = {\n kind: \"group\",\n name: group.name,\n description: group.description,\n aliases: [...group.aliases],\n scope,\n secrets,\n requires,\n children: materializedChildren,\n default: defaultChild,\n };\n\n Object.defineProperty(materialized, groupConfigSymbol, {\n value: {\n scope: cloneScope(internal.scope),\n secrets: cloneSecrets(internal.secrets),\n requires: cloneRequires(internal.requires),\n children: [...internal.children],\n default: internal.default,\n } satisfies InternalGroupConfig<TServices>,\n });\n\n return materialized;\n}\n\nfunction materializeNode<TServices extends object>(\n node: CommandNode<TServices>,\n inherited: InheritedMetadata\n): CommandNode<TServices> {\n if (node.kind === \"command\") {\n return materializeCommand(node, inherited);\n }\n\n return materializeGroup(node, inherited);\n}\n\nexport function defineCommand<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TParamsSchema extends ObjectSchema<any> = AnyObjectSchema,\n TSecrets extends SecretDeclarations | undefined = undefined,\n TResult = unknown,\n TOwnScope extends ScopeInput = undefined,\n>(\n config: Omit<CommandConfig<TServices, TParamsSchema, TSecrets, TResult>, \"name\" | \"scope\"> & {\n name: TName;\n scope?: TOwnScope;\n }\n): Command<TServices, TParamsSchema, TSecrets, TResult> &\n TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope> {\n return materializeCommand(createBaseCommand(config as CommandConfig<TServices, TParamsSchema, TSecrets, TResult>), {\n scope: undefined,\n secrets: {},\n requires: undefined,\n }) as Command<TServices, TParamsSchema, TSecrets, TResult> &\n TypedCommandMetadata<TName, TParamsSchema, TResult, TOwnScope>;\n}\n\nexport function defineGroup<\n TServices extends object = EmptyServices,\n TName extends string = string,\n TChildren extends readonly unknown[] = readonly CommandNode<TServices>[],\n TOwnScope extends ScopeInput = undefined,\n>(\n config: Omit<GroupConfig<TServices>, \"name\" | \"children\" | \"scope\"> & {\n name: TName;\n children: TChildren & readonly CommandNode<TServices>[];\n scope?: TOwnScope;\n }\n): Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope> {\n return materializeGroup(createBaseGroup(config as unknown as GroupConfig<TServices>), {\n scope: undefined,\n secrets: {},\n requires: undefined,\n }) as Group<TServices> & TypedGroupMetadata<TServices, TName, TChildren, TOwnScope>;\n}\n\nexport function getCommandSourcePath(command: Command<any, any, any, any>): string | undefined {\n return (command as Command<any, any, any, any> & { [commandSourcePathSymbol]?: string })[\n commandSourcePathSymbol\n ];\n}\n\nexport { S, toJsonSchema } from \"@poe-code/cmdkit-schema\";\nexport type { AnySchema, ArraySchema, BooleanSchema, EnumSchema, JsonSchema, NumberSchema, ObjectSchema, OptionalSchema, Static, StringSchema } from \"@poe-code/cmdkit-schema\";\n", "import type { NumberSchema } from \"@poe-code/cmdkit-schema\";\n\nexport function isValidNumberSchemaValue(\n value: unknown,\n schema: NumberSchema\n): value is number {\n return (\n typeof value === \"number\" &&\n Number.isFinite(value) &&\n (schema.jsonType !== \"integer\" || Number.isInteger(value))\n );\n}\n\nexport function getExpectedNumberDescription(schema: NumberSchema): string {\n return schema.jsonType === \"integer\" ? \"an integer\" : \"a number\";\n}\n", "import type { AnySchema } from \"@poe-code/cmdkit-schema\";\n\ntype SchemaScope = \"cli\" | \"mcp\" | \"sdk\";\n\nexport function filterSchemaForScope(schema: AnySchema, scope: SchemaScope): AnySchema | undefined {\n if (schema.scope !== undefined && !schema.scope.includes(scope)) {\n return undefined;\n }\n\n switch (schema.kind) {\n case \"optional\": {\n const inner = filterSchemaForScope(schema.inner, scope);\n\n if (inner === undefined) {\n return undefined;\n }\n\n if (inner.requiredScopes?.includes(scope)) {\n return inner;\n }\n\n return { ...schema, inner };\n }\n\n case \"array\": {\n const item = filterSchemaForScope(schema.item, scope);\n return item === undefined ? undefined : { ...schema, item };\n }\n\n case \"string\":\n case \"number\":\n case \"boolean\":\n case \"enum\":\n return schema;\n\n case \"object\":\n return {\n ...schema,\n shape: Object.fromEntries(\n Object.entries(schema.shape).flatMap(([key, childSchema]) => {\n const filtered = filterSchemaForScope(childSchema, scope);\n return filtered === undefined ? [] : [[key, filtered]];\n })\n ),\n };\n }\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,QAAQ,UAAU,iBAAiB;;;ACA5C,SAAS,qBAAqB;AA4OvB,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAiKA,SAAS,kBAAkB,OAAqD;AAC9E,QAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,MAAM,IAAI,CAAC,SAAS;AACjC,QAAI,KAAK,WAAW,GAAG;AACrB,aAAO,OAAO;AAAA,IAChB;AAEA,eAAW,QAAQ,MAAM;AACvB,UAAI,OAAO,OAAO,OAAO,KAAK;AAC5B,eAAO,OAAO;AAAA,MAChB;AAAA,IACF;AAEA,WAAO,OAAO,IAAI;AAAA,EACpB,CAAC;AAED,MAAI,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,CAAC,GAAG;AAC9D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEA,SAAS,uBAAuB,aAA2D;AACzF,MAAI,CAAC,YAAY,WAAW,IAAI,GAAG;AACjC,WA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S,KAAK,GAAG;AAChC;AAAA,QACF;AAEA,qBAAa,QAAQ,cAAc,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC;AAC5D;AAAA,MACF;AAEA,YAAM,aAAa,MAAM,KAAK;AAC9B,UAAI,cAAc,UAAU,KAAK,OAAO,KAAK,UAAU,EAAE,SAAS,GAAG;AACnE,qBAAa,QAAQ,cAAc,MAAM,IAAI,GAAG,UAAU;AAAA,MAC5D;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,IAAI;AACnB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Command } from "@poe-code/cmdkit";
|
|
2
|
-
import { defineCommand } from "@poe-code/cmdkit";
|
|
3
|
-
import type { ObjectSchema } from "@poe-code/cmdkit-schema";
|
|
4
|
-
import type { OpenApiClientServices } from "./define-client.js";
|
|
5
|
-
type ApiScope = readonly ["cli", "mcp", "sdk"];
|
|
6
|
-
export declare function defineApiCommand<TParamsSchema extends ObjectSchema<any>>(config: Parameters<typeof defineCommand<OpenApiClientServices, string, TParamsSchema, undefined, unknown, ApiScope>>[0]): Command<OpenApiClientServices, TParamsSchema, undefined, unknown>;
|
|
7
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AuthProvider } from "./types.js";
|
|
2
|
-
export interface BearerTokenAuthOptions {
|
|
3
|
-
serviceName: string;
|
|
4
|
-
envVar: string;
|
|
5
|
-
whoamiPath?: string;
|
|
6
|
-
commandPrefix?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare function bearerTokenAuth(options: BearerTokenAuthOptions): AuthProvider;
|