@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.
Files changed (66) hide show
  1. package/AUTHORING.md +53 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +5 -1
  4. package/SUBMISSION.md +1 -1
  5. package/bin/apifuse-check.ts +26 -1
  6. package/bin/apifuse-pack-check.ts +14 -0
  7. package/bin/apifuse-submit-check.ts +193 -2
  8. package/bin/apifuse-sync-assets.ts +117 -0
  9. package/dist/auth-turn/index.d.ts +2 -2
  10. package/dist/cli/commands.d.ts +1 -1
  11. package/dist/cli/commands.js +8 -0
  12. package/dist/cli/create.d.ts +3 -0
  13. package/dist/cli/create.js +34 -35
  14. package/dist/cli/prompt-assets.d.ts +80 -0
  15. package/dist/cli/prompt-assets.js +743 -0
  16. package/dist/cli/templates/provider/AGENTS.md.tpl +17 -8
  17. package/dist/config/loader.d.ts +79 -6
  18. package/dist/config/loader.js +272 -48
  19. package/dist/define.js +27 -3
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +1 -0
  22. package/dist/runtime/executor.js +7 -0
  23. package/dist/runtime/http.js +3 -0
  24. package/dist/runtime/proxy-errors.js +6 -2
  25. package/dist/runtime/proxy-nodemaven.d.ts +34 -0
  26. package/dist/runtime/proxy-nodemaven.js +128 -0
  27. package/dist/runtime/proxy-telemetry.d.ts +2 -1
  28. package/dist/runtime/proxy-telemetry.js +39 -4
  29. package/dist/runtime/secrets.d.ts +27 -0
  30. package/dist/runtime/secrets.js +51 -0
  31. package/dist/runtime/stealth.js +20 -9
  32. package/dist/server/serve.d.ts +5 -0
  33. package/dist/server/serve.js +39 -0
  34. package/dist/server/types.d.ts +9 -9
  35. package/dist/types.d.ts +30 -1
  36. package/package.json +4 -3
  37. package/src/cli/commands.ts +10 -0
  38. package/src/cli/create.ts +42 -35
  39. package/src/cli/prompt-assets.ts +865 -0
  40. package/src/cli/templates/provider/AGENTS.md.tpl +17 -8
  41. package/src/config/loader.ts +405 -61
  42. package/src/define.ts +35 -3
  43. package/src/index.ts +5 -0
  44. package/src/runtime/executor.ts +8 -0
  45. package/src/runtime/http.ts +3 -0
  46. package/src/runtime/proxy-errors.ts +12 -4
  47. package/src/runtime/proxy-nodemaven.ts +178 -0
  48. package/src/runtime/proxy-telemetry.ts +56 -5
  49. package/src/runtime/secrets.ts +64 -0
  50. package/src/runtime/stealth.ts +26 -10
  51. package/src/server/serve.ts +53 -0
  52. package/src/types.ts +30 -1
  53. package/dist/cli/templates/provider/CLAUDE.md.tpl +0 -1
  54. package/src/cli/templates/provider/CLAUDE.md.tpl +0 -1
  55. /package/dist/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  56. /package/dist/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  57. /package/dist/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  58. /package/dist/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  59. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  60. /package/dist/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
  61. /package/src/cli/templates/provider/{skills → .agents/skills}/fixtures-and-recording/SKILL.md.tpl +0 -0
  62. /package/src/cli/templates/provider/{skills → .agents/skills}/health-checks-and-fail-closed/SKILL.md.tpl +0 -0
  63. /package/src/cli/templates/provider/{skills → .agents/skills}/normalization-standards/SKILL.md.tpl +0 -0
  64. /package/src/cli/templates/provider/{skills → .agents/skills}/pagination-and-counts/SKILL.md.tpl +0 -0
  65. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-contract-verification/SKILL.md.tpl +0 -0
  66. /package/src/cli/templates/provider/{skills → .agents/skills}/upstream-notes/README.md.tpl +0 -0
package/src/cli/create.ts CHANGED
@@ -1,6 +1,6 @@
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
 
@@ -8,6 +8,11 @@ import { cancel, intro, isCancel, note, outro, select, text } from "@clack/promp
8
8
  import { z } from "zod";
9
9
 
10
10
  import packageJson from "../../package.json";
11
+ import {
12
+ buildPromptAssetManifest,
13
+ buildPromptAssetPlanEntries,
14
+ PROMPT_ASSET_MANIFEST_PATH,
15
+ } from "./prompt-assets.js";
11
16
 
12
17
  export const PROVIDER_NAME_REGEX = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
13
18
  export const CATEGORY_OPTIONS = [
@@ -64,7 +69,10 @@ export type CreateResolvedOptions = {
64
69
 
65
70
  export type ProviderPlanFile = {
66
71
  path: string;
72
+ /** File content, or the symlink target (relative path) for kind "symlink". */
67
73
  content: string;
74
+ /** Absent kind means "file" (backward compatible with older consumers). */
75
+ kind?: "file" | "symlink";
68
76
  };
69
77
 
70
78
  export type ProviderCreatePlan = {
@@ -410,11 +418,16 @@ export async function buildProviderCreatePlan(
410
418
  );
411
419
  }
412
420
 
421
+ // Exact pin, not a caret range: the prompt-asset freshness gate requires
422
+ // manifest.sdkVersion === installed SDK version, and the manifest records
423
+ // this CLI's own version. A caret range would let `bun install` resolve a
424
+ // newer SDK than the create binary, making a fresh scaffold fail its own
425
+ // gate. `sync-assets` after an explicit SDK upgrade re-records the version.
413
426
  const sdkSpecifier =
414
427
  options.sdkSpecifier ??
415
428
  (options.preset === "monorepo" && resolvedWorkspaceRoot
416
429
  ? "workspace:*"
417
- : `^${packageJson.version}`);
430
+ : packageJson.version);
418
431
  const relativeProviderRoot = relative(cwd, providerRoot) || options.name;
419
432
  const nextDevCommand = `cd ${relativeProviderRoot} && bun run dev`;
420
433
  const packageName =
@@ -538,40 +551,23 @@ export async function buildProviderCreatePlan(
538
551
  PROVIDER_ID: options.name,
539
552
  }),
540
553
  },
541
- {
542
- path: resolve(providerRoot, "AGENTS.md"),
543
- content: await renderTemplate("AGENTS.md.tpl", {}),
544
- },
545
- {
546
- path: resolve(providerRoot, "CLAUDE.md"),
547
- content: await renderTemplate("CLAUDE.md.tpl", {}),
548
- },
549
- {
550
- path: resolve(providerRoot, "skills", "normalization-standards", "SKILL.md"),
551
- content: await renderTemplate("skills/normalization-standards/SKILL.md.tpl", {}),
552
- },
553
- {
554
- path: resolve(providerRoot, "skills", "upstream-contract-verification", "SKILL.md"),
555
- content: await renderTemplate("skills/upstream-contract-verification/SKILL.md.tpl", {}),
556
- },
557
- {
558
- path: resolve(providerRoot, "skills", "fixtures-and-recording", "SKILL.md"),
559
- content: await renderTemplate("skills/fixtures-and-recording/SKILL.md.tpl", {}),
560
- },
561
- {
562
- path: resolve(providerRoot, "skills", "pagination-and-counts", "SKILL.md"),
563
- content: await renderTemplate("skills/pagination-and-counts/SKILL.md.tpl", {}),
564
- },
565
- {
566
- path: resolve(providerRoot, "skills", "health-checks-and-fail-closed", "SKILL.md"),
567
- content: await renderTemplate("skills/health-checks-and-fail-closed/SKILL.md.tpl", {}),
568
- },
569
- {
570
- path: resolve(providerRoot, "skills", "upstream-notes", "README.md"),
571
- content: await renderTemplate("skills/upstream-notes/README.md.tpl", {}),
572
- },
573
554
  ];
574
555
 
556
+ const promptAssetEntries = await buildPromptAssetPlanEntries(renderTemplate);
557
+ for (const entry of promptAssetEntries) {
558
+ files.push({
559
+ path: resolve(providerRoot, entry.path),
560
+ content: entry.content,
561
+ ...(entry.kind === "symlink" ? { kind: "symlink" as const } : {}),
562
+ });
563
+ }
564
+ // Manifest last: writePlan writes in order, so a crash mid-scaffold never
565
+ // leaves a manifest that claims assets which were not written.
566
+ files.push({
567
+ path: resolve(providerRoot, PROMPT_ASSET_MANIFEST_PATH),
568
+ content: buildPromptAssetManifest(promptAssetEntries, packageJson.version),
569
+ });
570
+
575
571
  return {
576
572
  displayName: options.displayName,
577
573
  files,
@@ -614,6 +610,7 @@ function renderPackageJson(input: { packageName: string; sdkSpecifier: string })
614
610
  check: "apifuse check . && bun run type-check",
615
611
  "type-check": "tsc --noEmit",
616
612
  "submit-check": "apifuse submit-check . --markdown submission-report.md",
613
+ "sync-assets": "apifuse sync-assets .",
617
614
  test: "apifuse test .",
618
615
  record: "apifuse record .",
619
616
  start: "bun start.ts",
@@ -869,6 +866,13 @@ function isApifuseInternalWorkspaceRoot(workspaceRoot: string): boolean {
869
866
  async function writePlan(plan: ProviderCreatePlan): Promise<void> {
870
867
  for (const file of plan.files) {
871
868
  await mkdir(dirname(file.path), { recursive: true });
869
+ if (file.kind === "symlink") {
870
+ // rm operates on the link itself (lstat semantics) and tolerates
871
+ // directories, so whatever occupies the path is replaced by the link.
872
+ await rm(file.path, { recursive: true, force: true });
873
+ await symlink(file.content, file.path);
874
+ continue;
875
+ }
872
876
  await writeFile(file.path, file.content);
873
877
  }
874
878
  }
@@ -940,7 +944,10 @@ function printResult(plan: ProviderCreatePlan, jsonMode: boolean, dryRun: boolea
940
944
  },
941
945
  validationCommands: plan.validationCommands,
942
946
  nextDevCommand: plan.nextDevCommand,
943
- files: plan.files.map((file) => relative(plan.providerRoot, file.path) || file.path),
947
+ files: plan.files.map((file) => {
948
+ const relativePath = relative(plan.providerRoot, file.path) || file.path;
949
+ return file.kind === "symlink" ? `${relativePath} -> ${file.content} (symlink)` : relativePath;
950
+ }),
944
951
  };
945
952
 
946
953
  if (jsonMode) {