@apifuse/provider-sdk 2.2.0-beta.5 → 2.2.0-beta.8
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/AUTHORING.md +53 -0
- package/CHANGELOG.md +12 -0
- package/README.md +5 -1
- package/SUBMISSION.md +1 -1
- package/bin/apifuse-check.ts +26 -1
- package/bin/apifuse-pack-check.ts +14 -0
- package/bin/apifuse-submit-check.ts +193 -2
- package/bin/apifuse-sync-assets.ts +117 -0
- package/dist/auth-turn/index.d.ts +2 -2
- package/dist/cli/commands.d.ts +1 -1
- package/dist/cli/commands.js +8 -0
- package/dist/cli/create.d.ts +3 -0
- package/dist/cli/create.js +34 -35
- package/dist/cli/prompt-assets.d.ts +80 -0
- package/dist/cli/prompt-assets.js +743 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/dist/config/loader.d.ts +79 -6
- package/dist/config/loader.js +272 -48
- package/dist/define.js +27 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/runtime/executor.js +7 -0
- package/dist/runtime/http.js +3 -0
- package/dist/runtime/proxy-errors.js +6 -2
- package/dist/runtime/proxy-nodemaven.d.ts +34 -0
- package/dist/runtime/proxy-nodemaven.js +128 -0
- package/dist/runtime/proxy-telemetry.d.ts +2 -1
- package/dist/runtime/proxy-telemetry.js +39 -4
- package/dist/runtime/secrets.d.ts +27 -0
- package/dist/runtime/secrets.js +51 -0
- package/dist/runtime/stealth.js +20 -9
- package/dist/server/serve.d.ts +5 -0
- package/dist/server/serve.js +39 -0
- package/dist/server/types.d.ts +9 -9
- package/dist/types.d.ts +30 -1
- package/package.json +4 -3
- package/src/cli/commands.ts +10 -0
- package/src/cli/create.ts +42 -35
- package/src/cli/prompt-assets.ts +865 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
- package/src/config/loader.ts +405 -61
- package/src/define.ts +35 -3
- package/src/index.ts +5 -0
- package/src/runtime/executor.ts +8 -0
- package/src/runtime/http.ts +3 -0
- package/src/runtime/proxy-errors.ts +12 -4
- package/src/runtime/proxy-nodemaven.ts +178 -0
- package/src/runtime/proxy-telemetry.ts +56 -5
- package/src/runtime/secrets.ts +64 -0
- package/src/runtime/stealth.ts +26 -10
- package/src/server/serve.ts +53 -0
- package/src/types.ts +30 -1
- package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
- package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
- /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
- /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/dist/cli/create.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { cancel, intro, isCancel, note, outro, select, text } from "@clack/prompts";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import packageJson from "../../package.json";
|
|
9
|
+
import { buildPromptAssetManifest, buildPromptAssetPlanEntries, PROMPT_ASSET_MANIFEST_PATH, } from "./prompt-assets.js";
|
|
9
10
|
export const PROVIDER_NAME_REGEX = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
10
11
|
export const CATEGORY_OPTIONS = [
|
|
11
12
|
"developer-tools",
|
|
@@ -283,10 +284,15 @@ export async function buildProviderCreatePlan(options, cwd) {
|
|
|
283
284
|
if (options.sdkSpecifier?.startsWith("workspace:") && !resolvedWorkspaceRoot) {
|
|
284
285
|
throw new Error("workspace:* is only valid inside the APIFuse monorepo because public Provider SDK scaffolds must install from npm or an explicit tarball/file specifier.");
|
|
285
286
|
}
|
|
287
|
+
// Exact pin, not a caret range: the prompt-asset freshness gate requires
|
|
288
|
+
// manifest.sdkVersion === installed SDK version, and the manifest records
|
|
289
|
+
// this CLI's own version. A caret range would let `bun install` resolve a
|
|
290
|
+
// newer SDK than the create binary, making a fresh scaffold fail its own
|
|
291
|
+
// gate. `sync-assets` after an explicit SDK upgrade re-records the version.
|
|
286
292
|
const sdkSpecifier = options.sdkSpecifier ??
|
|
287
293
|
(options.preset === "monorepo" && resolvedWorkspaceRoot
|
|
288
294
|
? "workspace:*"
|
|
289
|
-
:
|
|
295
|
+
: packageJson.version);
|
|
290
296
|
const relativeProviderRoot = relative(cwd, providerRoot) || options.name;
|
|
291
297
|
const nextDevCommand = `cd ${relativeProviderRoot} && bun run dev`;
|
|
292
298
|
const packageName = options.preset === "monorepo"
|
|
@@ -405,39 +411,21 @@ export async function buildProviderCreatePlan(options, cwd) {
|
|
|
405
411
|
PROVIDER_ID: options.name,
|
|
406
412
|
}),
|
|
407
413
|
},
|
|
408
|
-
{
|
|
409
|
-
path: resolve(providerRoot, "AGENTS.md"),
|
|
410
|
-
content: await renderTemplate("AGENTS.md.tpl", {}),
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
path: resolve(providerRoot, "CLAUDE.md"),
|
|
414
|
-
content: await renderTemplate("CLAUDE.md.tpl", {}),
|
|
415
|
-
},
|
|
416
|
-
{
|
|
417
|
-
path: resolve(providerRoot, "skills", "normalization-standards", "SKILL.md"),
|
|
418
|
-
content: await renderTemplate("skills/normalization-standards/SKILL.md.tpl", {}),
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
path: resolve(providerRoot, "skills", "upstream-contract-verification", "SKILL.md"),
|
|
422
|
-
content: await renderTemplate("skills/upstream-contract-verification/SKILL.md.tpl", {}),
|
|
423
|
-
},
|
|
424
|
-
{
|
|
425
|
-
path: resolve(providerRoot, "skills", "fixtures-and-recording", "SKILL.md"),
|
|
426
|
-
content: await renderTemplate("skills/fixtures-and-recording/SKILL.md.tpl", {}),
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
path: resolve(providerRoot, "skills", "pagination-and-counts", "SKILL.md"),
|
|
430
|
-
content: await renderTemplate("skills/pagination-and-counts/SKILL.md.tpl", {}),
|
|
431
|
-
},
|
|
432
|
-
{
|
|
433
|
-
path: resolve(providerRoot, "skills", "health-checks-and-fail-closed", "SKILL.md"),
|
|
434
|
-
content: await renderTemplate("skills/health-checks-and-fail-closed/SKILL.md.tpl", {}),
|
|
435
|
-
},
|
|
436
|
-
{
|
|
437
|
-
path: resolve(providerRoot, "skills", "upstream-notes", "README.md"),
|
|
438
|
-
content: await renderTemplate("skills/upstream-notes/README.md.tpl", {}),
|
|
439
|
-
},
|
|
440
414
|
];
|
|
415
|
+
const promptAssetEntries = await buildPromptAssetPlanEntries(renderTemplate);
|
|
416
|
+
for (const entry of promptAssetEntries) {
|
|
417
|
+
files.push({
|
|
418
|
+
path: resolve(providerRoot, entry.path),
|
|
419
|
+
content: entry.content,
|
|
420
|
+
...(entry.kind === "symlink" ? { kind: "symlink" } : {}),
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
// Manifest last: writePlan writes in order, so a crash mid-scaffold never
|
|
424
|
+
// leaves a manifest that claims assets which were not written.
|
|
425
|
+
files.push({
|
|
426
|
+
path: resolve(providerRoot, PROMPT_ASSET_MANIFEST_PATH),
|
|
427
|
+
content: buildPromptAssetManifest(promptAssetEntries, packageJson.version),
|
|
428
|
+
});
|
|
441
429
|
return {
|
|
442
430
|
displayName: options.displayName,
|
|
443
431
|
files,
|
|
@@ -477,6 +465,7 @@ function renderPackageJson(input) {
|
|
|
477
465
|
check: "apifuse check . && bun run type-check",
|
|
478
466
|
"type-check": "tsc --noEmit",
|
|
479
467
|
"submit-check": "apifuse submit-check . --markdown submission-report.md",
|
|
468
|
+
"sync-assets": "apifuse sync-assets .",
|
|
480
469
|
test: "apifuse test .",
|
|
481
470
|
record: "apifuse record .",
|
|
482
471
|
start: "bun start.ts",
|
|
@@ -696,6 +685,13 @@ function isApifuseInternalWorkspaceRoot(workspaceRoot) {
|
|
|
696
685
|
async function writePlan(plan) {
|
|
697
686
|
for (const file of plan.files) {
|
|
698
687
|
await mkdir(dirname(file.path), { recursive: true });
|
|
688
|
+
if (file.kind === "symlink") {
|
|
689
|
+
// rm operates on the link itself (lstat semantics) and tolerates
|
|
690
|
+
// directories, so whatever occupies the path is replaced by the link.
|
|
691
|
+
await rm(file.path, { recursive: true, force: true });
|
|
692
|
+
await symlink(file.content, file.path);
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
699
695
|
await writeFile(file.path, file.content);
|
|
700
696
|
}
|
|
701
697
|
}
|
|
@@ -754,7 +750,10 @@ function printResult(plan, jsonMode, dryRun) {
|
|
|
754
750
|
},
|
|
755
751
|
validationCommands: plan.validationCommands,
|
|
756
752
|
nextDevCommand: plan.nextDevCommand,
|
|
757
|
-
files: plan.files.map((file) =>
|
|
753
|
+
files: plan.files.map((file) => {
|
|
754
|
+
const relativePath = relative(plan.providerRoot, file.path) || file.path;
|
|
755
|
+
return file.kind === "symlink" ? `${relativePath} -> ${file.content} (symlink)` : relativePath;
|
|
756
|
+
}),
|
|
758
757
|
};
|
|
759
758
|
if (jsonMode) {
|
|
760
759
|
console.log(JSON.stringify(payload, null, 2));
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK-managed agent prompt assets.
|
|
3
|
+
*
|
|
4
|
+
* `apifuse create` scaffolds these files, `apifuse sync-assets` regenerates
|
|
5
|
+
* them in an existing provider root, and `apifuse check` / `submit-check`
|
|
6
|
+
* enforce that they byte-match the installed SDK version (fail closed).
|
|
7
|
+
*
|
|
8
|
+
* Layout contract:
|
|
9
|
+
* - AGENTS.md — real file (agent guide)
|
|
10
|
+
* - CLAUDE.md — symlink -> AGENTS.md
|
|
11
|
+
* - .agents/skills/<skill>/SKILL.md — real files
|
|
12
|
+
* - .agents/skills/upstream-notes/README.md — real file
|
|
13
|
+
* - .claude / .codex — symlinks -> .agents
|
|
14
|
+
* - .apifuse/prompt-assets.json — manifest (schema v2), written last
|
|
15
|
+
*/
|
|
16
|
+
export declare const PROMPT_ASSET_MANIFEST_PATH = ".apifuse/prompt-assets.json";
|
|
17
|
+
export declare const PROMPT_ASSET_MANIFEST_SCHEMA_VERSION = 2;
|
|
18
|
+
export declare const PROMPT_ASSET_SYNC_REMEDIATION = "Run `bun run sync-assets` (or `bunx apifuse sync-assets .`) to regenerate the SDK-managed agent prompt assets.";
|
|
19
|
+
export declare const PROMPT_ASSET_SYMLINKS: Readonly<Record<string, string>>;
|
|
20
|
+
/** Relative asset paths whose content is rendered from `<path>.tpl`. */
|
|
21
|
+
export declare const PROMPT_ASSET_FILE_PATHS: readonly string[];
|
|
22
|
+
export type PromptAssetKind = "file" | "symlink";
|
|
23
|
+
export type PromptAssetEntry = {
|
|
24
|
+
/** Provider-root-relative path (POSIX separators). */
|
|
25
|
+
path: string;
|
|
26
|
+
/** File content, or the symlink target for kind "symlink". */
|
|
27
|
+
content: string;
|
|
28
|
+
kind: PromptAssetKind;
|
|
29
|
+
};
|
|
30
|
+
export type PromptAssetTemplateRenderer = (fileName: string, values: Record<string, string>) => string | Promise<string>;
|
|
31
|
+
export type PromptAssetVerification = {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
/** Expected paths (or the manifest) absent on disk. */
|
|
34
|
+
missing: string[];
|
|
35
|
+
/** Manifest recorded for a different SDK version than the installed one. */
|
|
36
|
+
stale: string[];
|
|
37
|
+
/** Files/symlinks/manifest whose bytes or target differ from the regenerated set. */
|
|
38
|
+
modified: string[];
|
|
39
|
+
/** Legacy layout remnants (top-level skills/). */
|
|
40
|
+
legacy: string[];
|
|
41
|
+
/** Entries inside `.agents/` that are not part of the managed asset set. */
|
|
42
|
+
unexpected: string[];
|
|
43
|
+
};
|
|
44
|
+
export type PromptAssetSyncResult = {
|
|
45
|
+
changed: boolean;
|
|
46
|
+
removed: string[];
|
|
47
|
+
wroteFiles: string[];
|
|
48
|
+
createdSymlinks: string[];
|
|
49
|
+
manifestPath: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Build the full managed asset entry list (files first, symlinks after,
|
|
53
|
+
* manifest excluded). The renderer is injected so `apifuse create` can reuse
|
|
54
|
+
* its own template renderer; sync/verify use the SDK-internal renderer.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildPromptAssetPlanEntries(renderTemplate: PromptAssetTemplateRenderer): Promise<PromptAssetEntry[]>;
|
|
57
|
+
export declare function buildPromptAssetPlanEntriesSync(): PromptAssetEntry[];
|
|
58
|
+
/**
|
|
59
|
+
* Deterministic manifest serialization: schema v2, 2-space JSON, trailing
|
|
60
|
+
* newline, sorted paths (including symlink paths, excluding the manifest
|
|
61
|
+
* itself). `sdkVersion` + `paths` keep their v1 semantics so older parsers
|
|
62
|
+
* keep working; `schemaVersion` and `symlinks` are additive.
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildPromptAssetManifest(entries: readonly PromptAssetEntry[], sdkVersion: string): string;
|
|
65
|
+
export declare function installedSdkVersion(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Verify the on-disk prompt assets against the set regenerated from the
|
|
68
|
+
* installed SDK. Uses lstat/readlink for symlinks (never follows), byte
|
|
69
|
+
* comparison for files, and exact-version comparison for the manifest.
|
|
70
|
+
*/
|
|
71
|
+
export declare function verifyPromptAssets(providerRoot: string): PromptAssetVerification;
|
|
72
|
+
export declare function formatPromptAssetIssues(verification: PromptAssetVerification): string[];
|
|
73
|
+
/**
|
|
74
|
+
* Regenerate the full managed asset set for the installed SDK version in an
|
|
75
|
+
* existing provider root. Deletes legacy managed paths first (top-level
|
|
76
|
+
* skills/**, plus manifest-listed paths that left the set — restricted to
|
|
77
|
+
* managed namespaces with no symlinked ancestors), writes files, replaces
|
|
78
|
+
* symlinks, and writes the manifest last. Idempotent.
|
|
79
|
+
*/
|
|
80
|
+
export declare function syncPromptAssets(providerRoot: string): PromptAssetSyncResult;
|