@agentprismform/agent-plugin 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14783,19 +14783,37 @@ var require_patch = __commonJS({
14783
14783
  for (const op of operations) {
14784
14784
  switch (op.type) {
14785
14785
  case "SET_FORM_META": {
14786
- if (op.patch.title !== void 0)
14787
- next.title = op.patch.title;
14788
- if (op.patch.description !== void 0)
14789
- next.description = op.patch.description;
14790
- if (op.patch.submitApi !== void 0)
14791
- next.submitApi = op.patch.submitApi;
14792
- if (op.patch.storageKey !== void 0)
14793
- next.storageKey = op.patch.storageKey;
14786
+ const meta = op.patch || op;
14787
+ if (!meta || typeof meta !== "object") {
14788
+ opErrors.push({
14789
+ code: "INVALID_FIELD_KEY",
14790
+ severity: "error",
14791
+ message: 'SET_FORM_META \u9700\u8981 patch \u5BF9\u8C61\uFF0C\u4F8B\u5982 { "type": "SET_FORM_META", "patch": { "title": "...", "storageKey": "..." } }'
14792
+ });
14793
+ break;
14794
+ }
14795
+ if (meta.title !== void 0)
14796
+ next.title = meta.title;
14797
+ if (meta.description !== void 0)
14798
+ next.description = meta.description;
14799
+ if (meta.submitApi !== void 0)
14800
+ next.submitApi = meta.submitApi;
14801
+ if (meta.storageKey !== void 0)
14802
+ next.storageKey = meta.storageKey;
14794
14803
  break;
14795
14804
  }
14796
14805
  case "ADD_GROUP": {
14806
+ const grp = op.group || (op.key ? { key: op.key, title: op.title || "", items: op.items || [] } : null);
14807
+ if (!grp || typeof grp !== "object" || !grp.key) {
14808
+ opErrors.push({
14809
+ code: "GROUP_NOT_FOUND",
14810
+ severity: "error",
14811
+ message: 'ADD_GROUP \u9700\u8981 group \u5BF9\u8C61\u4E14\u542B key\uFF0C\u4F8B\u5982 { "type": "ADD_GROUP", "group": { "key": "group_info", "title": "\u57FA\u672C\u4FE1\u606F", "items": [] } }'
14812
+ });
14813
+ break;
14814
+ }
14797
14815
  const idx = clampIndex(op.index, next.groups.length);
14798
- next.groups.splice(idx, 0, JSON.parse(JSON.stringify(op.group)));
14816
+ next.groups.splice(idx, 0, JSON.parse(JSON.stringify(grp)));
14799
14817
  break;
14800
14818
  }
14801
14819
  case "UPDATE_GROUP": {
@@ -14809,12 +14827,13 @@ var require_patch = __commonJS({
14809
14827
  });
14810
14828
  break;
14811
14829
  }
14812
- if (op.patch.title !== void 0)
14813
- g.title = op.patch.title;
14814
- if (op.patch.description !== void 0)
14815
- g.description = op.patch.description;
14816
- if (op.patch.visible !== void 0)
14817
- g.visible = op.patch.visible;
14830
+ const gPatch = op.patch || {};
14831
+ if (gPatch.title !== void 0)
14832
+ g.title = gPatch.title;
14833
+ if (gPatch.description !== void 0)
14834
+ g.description = gPatch.description;
14835
+ if (gPatch.visible !== void 0)
14836
+ g.visible = gPatch.visible;
14818
14837
  break;
14819
14838
  }
14820
14839
  case "REMOVE_GROUP": {
@@ -16262,6 +16281,7 @@ var require_v2Core = __commonJS({
16262
16281
  "packages/form-agent/src/v2Core.cjs"(exports2, module2) {
16263
16282
  "use strict";
16264
16283
  var fs = require("node:fs");
16284
+ var os2 = require("node:os");
16265
16285
  var path2 = require("node:path");
16266
16286
  var crypto = require("node:crypto");
16267
16287
  var { FormCore } = require_dist();
@@ -16658,7 +16678,18 @@ var require_v2Core = __commonJS({
16658
16678
  function escapeInlineScript(text) {
16659
16679
  return String(text).replace(/<\/(script)/gi, "<\\/$1");
16660
16680
  }
16661
- function renderStandaloneHtml({ schema, themeConfig, mode, locale, assetsDir }) {
16681
+ function normalizeSubmitUrl(raw) {
16682
+ if (raw === void 0 || raw === null) return "";
16683
+ const trimmed = String(raw).trim();
16684
+ if (!trimmed) return "";
16685
+ if (!/^https?:\/\//i.test(trimmed)) {
16686
+ throw Object.assign(new Error(`\u65E0\u6548\u7684 submitUrl\uFF1A${trimmed}\uFF08\u4EC5\u652F\u6301 http:// \u6216 https:// \u5730\u5740\uFF09`), {
16687
+ code: "INVALID_ARGUMENT"
16688
+ });
16689
+ }
16690
+ return trimmed;
16691
+ }
16692
+ function renderStandaloneHtml({ schema, themeConfig, mode, locale, submitUrl, assetsDir }) {
16662
16693
  const normalizedTheme = themeConfig ? { ...themeConfig } : { version: "1.0.0", skin: "fin-minimal", override: {}, formMode: "flat", showProgressBar: true };
16663
16694
  const effectiveMode = mode === "final" || normalizedTheme.mode === "final" ? "final" : "preview";
16664
16695
  if (effectiveMode === "final") {
@@ -16668,6 +16699,7 @@ var require_v2Core = __commonJS({
16668
16699
  if (locale !== void 0 || normalizedTheme.locale) {
16669
16700
  normalizedTheme.locale = effectiveLocale;
16670
16701
  }
16702
+ const effectiveSubmitUrl = normalizeSubmitUrl(submitUrl);
16671
16703
  const jsPath = path2.join(assetsDir, "modern-preview.iife.js");
16672
16704
  const cssPath = path2.join(assetsDir, "modern-preview.css");
16673
16705
  if (!fs.existsSync(jsPath) || !fs.existsSync(cssPath)) {
@@ -16679,6 +16711,8 @@ var require_v2Core = __commonJS({
16679
16711
  const cssCode = fs.readFileSync(cssPath, "utf8");
16680
16712
  const safeTitle = String(schema.title || (effectiveLocale === "en-US" ? "FormSchema Live Preview" : "FormSchema \u5B9E\u65F6\u9884\u89C8")).replace(/[<>&"]/g, "");
16681
16713
  const pageTitle = effectiveMode === "final" ? safeTitle : `${safeTitle} \xB7 FormSchema Preview`;
16714
+ const submitUrlScriptLine = effectiveSubmitUrl ? `
16715
+ window.__AGENT_SUBMIT_URL__ = ${escapeInlineScript(JSON.stringify(effectiveSubmitUrl))};` : "";
16682
16716
  const html = `<!DOCTYPE html>
16683
16717
  <html lang="${effectiveLocale}">
16684
16718
  <head>
@@ -16690,7 +16724,7 @@ var require_v2Core = __commonJS({
16690
16724
  <body>
16691
16725
  <div id="app"></div>
16692
16726
  <script>
16693
- window.__AGENT_PREVIEW_MODE__ = ${JSON.stringify(effectiveMode)};
16727
+ window.__AGENT_PREVIEW_MODE__ = ${JSON.stringify(effectiveMode)};${submitUrlScriptLine}
16694
16728
  window.__AGENT_FORM_SCHEMA__ = ${escapeInlineScript(JSON.stringify(schema))};
16695
16729
  window.__AGENT_THEME_CONFIG__ = ${escapeInlineScript(JSON.stringify(normalizedTheme))};
16696
16730
  </script>
@@ -16698,16 +16732,22 @@ var require_v2Core = __commonJS({
16698
16732
  </body>
16699
16733
  </html>
16700
16734
  `;
16701
- return { html, mode: effectiveMode, locale: effectiveLocale };
16735
+ return { html, mode: effectiveMode, locale: effectiveLocale, submitUrl: effectiveSubmitUrl || null };
16702
16736
  }
16703
- function previewExportHtml({ schemaPath, themePath, out, mode, locale, assetsDir }) {
16737
+ function previewExportHtml({ schemaPath, themePath, out, mode, locale, submitUrl, assetsDir }) {
16704
16738
  const schema = normalizeSchemaEnvelope(readJsonFile(schemaPath, "FormSchema \u6587\u4EF6"));
16705
16739
  const themeConfig = themePath ? readJsonFile(themePath, "ThemeConfigJson \u6587\u4EF6") : { version: "1.0.0", skin: "fin-minimal", override: {}, formMode: "flat", showProgressBar: true };
16706
- const { html, mode: effectiveMode, locale: effectiveLocale } = renderStandaloneHtml({
16740
+ const {
16741
+ html,
16742
+ mode: effectiveMode,
16743
+ locale: effectiveLocale,
16744
+ submitUrl: effectiveSubmitUrl
16745
+ } = renderStandaloneHtml({
16707
16746
  schema,
16708
16747
  themeConfig,
16709
16748
  mode,
16710
16749
  locale,
16750
+ submitUrl,
16711
16751
  assetsDir
16712
16752
  });
16713
16753
  const absOut = path2.resolve(out);
@@ -16718,6 +16758,7 @@ var require_v2Core = __commonJS({
16718
16758
  status: "exported",
16719
16759
  mode: effectiveMode,
16720
16760
  locale: effectiveLocale,
16761
+ submitUrl: effectiveSubmitUrl,
16721
16762
  path: absOut,
16722
16763
  sizeKb,
16723
16764
  fileUrl: `file://${absOut}`
@@ -16783,8 +16824,10 @@ module.exports = ${JSON.stringify(payload, null, 2)}
16783
16824
  outDir,
16784
16825
  keyStyle = "snake_case",
16785
16826
  includeHtml = true,
16827
+ submitUrl,
16786
16828
  assetsDir
16787
16829
  }) {
16830
+ const effectiveSubmitUrl = normalizeSubmitUrl(submitUrl);
16788
16831
  const schema = normalizeSchemaEnvelope(readJsonFile(schemaPath, "FormSchema \u6587\u4EF6"));
16789
16832
  const governance = validateFormSchemaGovernance(schema);
16790
16833
  if (!governance.valid) {
@@ -16822,7 +16865,7 @@ module.exports = ${JSON.stringify(payload, null, 2)}
16822
16865
  let finalHtmlOut = null;
16823
16866
  let finalHtmlSizeKb = null;
16824
16867
  if (includeHtml !== false && assetsDir) {
16825
- const { html } = renderStandaloneHtml({ schema, themeConfig, mode: "final", assetsDir });
16868
+ const { html } = renderStandaloneHtml({ schema, themeConfig, mode: "final", submitUrl: effectiveSubmitUrl, assetsDir });
16826
16869
  finalHtmlOut = path2.join(absDir, "final.html");
16827
16870
  fs.writeFileSync(finalHtmlOut, html, "utf8");
16828
16871
  finalHtmlSizeKb = Math.round(fs.statSync(finalHtmlOut).size / 1024);
@@ -16839,6 +16882,7 @@ module.exports = ${JSON.stringify(payload, null, 2)}
16839
16882
  piiFields: contract.piiSummary.map((p) => p.key),
16840
16883
  governanceValid: governance.valid,
16841
16884
  presetAuditCount: auditFieldPresetCoverage(schema).length,
16885
+ ...effectiveSubmitUrl ? { submitUrl: effectiveSubmitUrl } : {},
16842
16886
  artifacts: {
16843
16887
  schema: { file: "form.schema.json", sha256: sha256(schemaOut) },
16844
16888
  theme: { file: "theme.config.json", sha256: sha256(themeOut) },
@@ -16910,22 +16954,148 @@ module.exports = ${JSON.stringify(payload, null, 2)}
16910
16954
  if (!name.endsWith("Form")) name += "Form";
16911
16955
  return name;
16912
16956
  }
16957
+ function tryReadJsonSafe(filePath) {
16958
+ try {
16959
+ if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) return null;
16960
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
16961
+ } catch (_) {
16962
+ return null;
16963
+ }
16964
+ }
16965
+ function findNearestExistingDir(targetPath) {
16966
+ let cur = path2.resolve(targetPath || process.cwd());
16967
+ for (let i = 0; i < 12; i++) {
16968
+ try {
16969
+ if (fs.existsSync(cur)) {
16970
+ return fs.statSync(cur).isDirectory() ? cur : path2.dirname(cur);
16971
+ }
16972
+ } catch (_) {
16973
+ }
16974
+ const parent = path2.dirname(cur);
16975
+ if (parent === cur) break;
16976
+ cur = parent;
16977
+ }
16978
+ return process.cwd();
16979
+ }
16980
+ function detectHostEnvironment({ projectDir, outDir } = {}) {
16981
+ const startDir = findNearestExistingDir(projectDir || outDir || process.cwd());
16982
+ const homeDir = path2.resolve(os2.homedir());
16983
+ const tmpDirs = /* @__PURE__ */ new Set([path2.resolve(os2.tmpdir())]);
16984
+ try {
16985
+ tmpDirs.add(fs.realpathSync(os2.tmpdir()));
16986
+ } catch (_) {
16987
+ }
16988
+ let cur = startDir;
16989
+ for (let depth = 0; depth < 6; depth++) {
16990
+ if (depth > 0 && (cur === homeDir || tmpDirs.has(cur))) break;
16991
+ const wxProj = tryReadJsonSafe(path2.join(cur, "project.config.json"));
16992
+ if (wxProj && (wxProj.appid !== void 0 || wxProj.miniprogramRoot !== void 0 || wxProj.compileType === "miniprogram")) {
16993
+ return {
16994
+ resolvedPlatform: "miniapp",
16995
+ confidence: "high",
16996
+ projectRoot: cur,
16997
+ signals: ["project.config.json"],
16998
+ summary: "Detected WeChat Miniapp project via project.config.json"
16999
+ };
17000
+ }
17001
+ const wxApp = tryReadJsonSafe(path2.join(cur, "app.json"));
17002
+ if (wxApp && Array.isArray(wxApp.pages)) {
17003
+ return {
17004
+ resolvedPlatform: "miniapp",
17005
+ confidence: "high",
17006
+ projectRoot: cur,
17007
+ signals: ["app.json(pages)"],
17008
+ summary: "Detected WeChat Miniapp project via app.json"
17009
+ };
17010
+ }
17011
+ const pkg = tryReadJsonSafe(path2.join(cur, "package.json"));
17012
+ if (pkg && typeof pkg === "object") {
17013
+ const deps = { ...pkg.dependencies || {}, ...pkg.devDependencies || {} };
17014
+ const hasVue = Boolean(deps.vue || deps.nuxt || deps["@vitejs/plugin-vue"]);
17015
+ const hasReact = Boolean(deps.react || deps["react-dom"] || deps.next || deps["@vitejs/plugin-react"]);
17016
+ if (hasVue && !hasReact) {
17017
+ const signals = ["package.json", deps.nuxt ? "dep:nuxt" : "dep:vue"];
17018
+ return {
17019
+ resolvedPlatform: "vue3",
17020
+ confidence: "high",
17021
+ projectRoot: cur,
17022
+ signals,
17023
+ summary: `Detected Vue 3 host project (${signals.join(", ")})`
17024
+ };
17025
+ }
17026
+ if (hasReact && !hasVue) {
17027
+ const signals = ["package.json", deps.next ? "dep:next" : "dep:react"];
17028
+ return {
17029
+ resolvedPlatform: "react18",
17030
+ confidence: "high",
17031
+ projectRoot: cur,
17032
+ signals,
17033
+ summary: `Detected React 18 host project (${signals.join(", ")})`
17034
+ };
17035
+ }
17036
+ if (hasVue && hasReact) {
17037
+ if (fs.existsSync(path2.join(cur, "src/App.vue"))) {
17038
+ return {
17039
+ resolvedPlatform: "vue3",
17040
+ confidence: "high",
17041
+ projectRoot: cur,
17042
+ signals: ["package.json", "src/App.vue"],
17043
+ summary: "Detected Vue 3 host project via src/App.vue"
17044
+ };
17045
+ }
17046
+ if (fs.existsSync(path2.join(cur, "src/App.tsx")) || fs.existsSync(path2.join(cur, "src/App.jsx"))) {
17047
+ return {
17048
+ resolvedPlatform: "react18",
17049
+ confidence: "high",
17050
+ projectRoot: cur,
17051
+ signals: ["package.json", "src/App.tsx"],
17052
+ summary: "Detected React 18 host project via src/App.tsx"
17053
+ };
17054
+ }
17055
+ }
17056
+ }
17057
+ const parent = path2.dirname(cur);
17058
+ if (parent === cur) break;
17059
+ cur = parent;
17060
+ }
17061
+ return {
17062
+ resolvedPlatform: "standalone",
17063
+ confidence: "fallback",
17064
+ projectRoot: startDir,
17065
+ signals: ["no-frontend-framework-detected"],
17066
+ summary: "No Vue/React/Miniapp host detected \u2014 delivering zero-dependency standalone HTML bundle"
17067
+ };
17068
+ }
16913
17069
  function scaffoldHost({
16914
17070
  schemaPath,
16915
17071
  themePath,
16916
- platform,
17072
+ platform = "auto",
16917
17073
  outDir,
17074
+ projectDir,
16918
17075
  componentName,
16919
17076
  keyStyle = "snake_case",
16920
- packageScope = "@agentprismform"
17077
+ packageScope = "@agentprismform",
17078
+ submitUrl,
17079
+ assetsDir
16921
17080
  }) {
16922
- const VALID_PLATFORMS = ["vue3", "react18", "miniapp", "headless"];
16923
- if (!VALID_PLATFORMS.includes(platform)) {
17081
+ const VALID_PLATFORMS = ["auto", "vue3", "react18", "miniapp", "standalone", "headless"];
17082
+ const requestedPlatform = platform || "auto";
17083
+ if (!VALID_PLATFORMS.includes(requestedPlatform)) {
16924
17084
  throw Object.assign(
16925
- new Error(`\u4E0D\u652F\u6301\u7684\u76EE\u6807\u5E73\u53F0\uFF1A${platform}\uFF08\u53EF\u9009\uFF1A${VALID_PLATFORMS.join(", ")}\uFF09`),
17085
+ new Error(`\u4E0D\u652F\u6301\u7684\u76EE\u6807\u5E73\u53F0\uFF1A${requestedPlatform}\uFF08\u53EF\u9009\uFF1A${VALID_PLATFORMS.join(", ")}\uFF09`),
16926
17086
  { code: "INVALID_ARGUMENT" }
16927
17087
  );
16928
17088
  }
17089
+ const effectiveSubmitUrl = normalizeSubmitUrl(submitUrl);
17090
+ const detection = requestedPlatform === "auto" ? { requestedPlatform: "auto", ...detectHostEnvironment({ projectDir, outDir }) } : {
17091
+ requestedPlatform,
17092
+ resolvedPlatform: requestedPlatform,
17093
+ confidence: "explicit",
17094
+ projectRoot: findNearestExistingDir(projectDir || outDir || process.cwd()),
17095
+ signals: ["explicit-platform"],
17096
+ summary: `Explicit platform requested: ${requestedPlatform}`
17097
+ };
17098
+ const resolvedPlatform = detection.resolvedPlatform;
16929
17099
  const schema = normalizeSchemaEnvelope(readJsonFile(schemaPath, "FormSchema \u6587\u4EF6"));
16930
17100
  const rawTheme = themePath ? readJsonFile(themePath, "ThemeConfigJson \u6587\u4EF6") : { version: "1.0.0", skin: "fin-minimal", override: {}, formMode: "flat", showProgressBar: true };
16931
17101
  const themeConfig = { ...rawTheme, mode: "final" };
@@ -16939,7 +17109,8 @@ module.exports = ${JSON.stringify(payload, null, 2)}
16939
17109
  format: "agentprismform-mobile-bundle/v1",
16940
17110
  exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
16941
17111
  schema,
16942
- themeConfig
17112
+ themeConfig,
17113
+ ...effectiveSubmitUrl ? { submitUrl: effectiveSubmitUrl } : {}
16943
17114
  };
16944
17115
  const bundleOut = writeJsonAtomic(path2.join(absDir, "form.bundle.json"), bundle, { overwrite: true });
16945
17116
  const typesOut = path2.join(absDir, "types.d.ts");
@@ -16948,7 +17119,7 @@ module.exports = ${JSON.stringify(payload, null, 2)}
16948
17119
  let packages = [];
16949
17120
  let entryFile = "";
16950
17121
  let mountSnippet = "";
16951
- if (platform === "vue3") {
17122
+ if (resolvedPlatform === "vue3") {
16952
17123
  packages = [`${scope}/render-vue`];
16953
17124
  entryFile = path2.join(absDir, `${compName}.vue`);
16954
17125
  const vueCode = `<script setup lang="ts">
@@ -16993,7 +17164,7 @@ const emit = defineEmits<{
16993
17164
  fs.writeFileSync(entryFile, vueCode, "utf8");
16994
17165
  files.component = entryFile;
16995
17166
  mountSnippet = `<${compName} :host-handlers="hostHandlers" :custom-controls="{}" @submit="handleSubmit" />`;
16996
- } else if (platform === "react18") {
17167
+ } else if (resolvedPlatform === "react18") {
16997
17168
  packages = [`${scope}/render-web`];
16998
17169
  entryFile = path2.join(absDir, `${compName}.tsx`);
16999
17170
  const reactCode = `import React from 'react'
@@ -17039,7 +17210,7 @@ export function ${compName}({
17039
17210
  fs.writeFileSync(entryFile, reactCode, "utf8");
17040
17211
  files.component = entryFile;
17041
17212
  mountSnippet = `<${compName} hostHandlers={hostHandlers} customControls={{}} onSubmit={handleSubmit} />`;
17042
- } else if (platform === "headless") {
17213
+ } else if (resolvedPlatform === "headless") {
17043
17214
  packages = [`${scope}/core`, `${scope}/render`];
17044
17215
  entryFile = path2.join(absDir, `${compName}.tsx`);
17045
17216
  const headlessCode = `import React, { useEffect, useRef, useState } from 'react'
@@ -17125,8 +17296,23 @@ export function ${compName}({ onSubmit }: ${compName}Props) {
17125
17296
  fs.writeFileSync(entryFile, headlessCode, "utf8");
17126
17297
  files.component = entryFile;
17127
17298
  mountSnippet = `<${compName} onSubmit={handleSubmit} />`;
17299
+ } else if (resolvedPlatform === "standalone") {
17300
+ packages = [];
17301
+ const resolvedAssetsDir = assetsDir || path2.resolve(__dirname, "../preview");
17302
+ const { html } = renderStandaloneHtml({
17303
+ schema,
17304
+ themeConfig,
17305
+ mode: "final",
17306
+ submitUrl: effectiveSubmitUrl,
17307
+ assetsDir: resolvedAssetsDir
17308
+ });
17309
+ entryFile = path2.join(absDir, "index.html");
17310
+ fs.writeFileSync(entryFile, html, "utf8");
17311
+ files.html = entryFile;
17312
+ mountSnippet = effectiveSubmitUrl ? `# Deploy index.html to any static host (Cloudflare Pages / Vercel / Nginx / OSS)
17313
+ # Submissions POST JSON with Idempotency-Key -> ${effectiveSubmitUrl}` : `# Open index.html directly in any browser, or deploy to Cloudflare Pages / Vercel / Nginx / OSS (zero backend required)`;
17128
17314
  } else {
17129
- packages = [`${scope}/core`, `${scope}/render`, `${scope}/render-miniapp`];
17315
+ packages = [`${scope}/render-miniapp`];
17130
17316
  const dataFile = path2.join(absDir, "preview-data.js");
17131
17317
  const jsonFile = path2.join(absDir, "index.json");
17132
17318
  const wxmlFile = path2.join(absDir, "index.wxml");
@@ -17156,6 +17342,7 @@ export function ${compName}({ onSubmit }: ${compName}Props) {
17156
17342
  `,
17157
17343
  "utf8"
17158
17344
  );
17345
+ const defaultMiniappUrl = effectiveSubmitUrl || "https://api.example.com/forms/submit";
17159
17346
  fs.writeFileSync(
17160
17347
  jsFile,
17161
17348
  `const bundle = require('./preview-data.js')
@@ -17168,7 +17355,7 @@ Page({
17168
17355
  onFormSubmit(ev) {
17169
17356
  this.setData({ submitting: true })
17170
17357
  wx.request({
17171
- url: (this.data.schema && this.data.schema.submitApi) || 'https://api.example.com/forms/submit',
17358
+ url: bundle.submitUrl || (this.data.schema && this.data.schema.submitApi) || ${JSON.stringify(defaultMiniappUrl)},
17172
17359
  method: 'POST',
17173
17360
  header: { 'Idempotency-Key': 'wx_' + Date.now() },
17174
17361
  data: ev.detail,
@@ -17186,14 +17373,19 @@ Page({
17186
17373
  files.pageJs = jsFile;
17187
17374
  mountSnippet = `// Register "${path2.basename(absDir)}/index" inside WeChat Miniapp app.json -> "pages"`;
17188
17375
  }
17189
- const localInstallCmd = "npm install --install-links " + packages.map((p) => `<path-to-AgentPrismForm>/packages/${p.split("/")[1]}`).join(" ");
17190
- const npmInstallCmd = `npm install ${packages.join(" ")}`;
17191
- const integrationDoc = path2.join(absDir, "INTEGRATION.md");
17192
- fs.writeFileSync(
17193
- integrationDoc,
17194
- `# ${compName} Integration Guide / \u63A5\u5165\u6307\u5357
17376
+ const localInstallCmd = packages.length ? "npm install --install-links " + packages.map((p) => `<path-to-AgentPrismForm>/packages/${p.split("/")[1]}`).join(" ") : "";
17377
+ const npmInstallCmd = packages.length ? `npm install ${packages.join(" ")}` : "";
17378
+ const submitNote = effectiveSubmitUrl ? `
17379
+ ## Submit Endpoint / \u63D0\u4EA4\u63A5\u53E3\u51FA\u53E3
17380
+
17381
+ Configured \`submitUrl\`: \`${effectiveSubmitUrl}\`
17195
17382
 
17196
- ## 1. Install Required Packages / \u5B89\u88C5\u4F9D\u8D56\u5305
17383
+ Payload envelope sent via \`POST\` (with \`Idempotency-Key\` header):
17384
+ \`\`\`json
17385
+ { "submissionId": "sub_...", "schemaVersion": "1.0.0", "storageKey": "${schema.storageKey || ""}", "submittedAt": "...", "channel": "web-mobile", "data": { ... } }
17386
+ \`\`\`
17387
+ ` : "";
17388
+ const installSection = packages.length ? `## 1. Install Required Packages / \u5B89\u88C5\u4F9D\u8D56\u5305
17197
17389
 
17198
17390
  **Option A \u2014 From npm registry / \u4ECE npm \u5B98\u65B9\u6E90\u76F4\u63A5\u5B89\u88C5\uFF08\u63A8\u8350\uFF09:**
17199
17391
  \`\`\`bash
@@ -17204,24 +17396,37 @@ ${npmInstallCmd}
17204
17396
  \`\`\`bash
17205
17397
  ${localInstallCmd}
17206
17398
  \`\`\`
17399
+ ` : `## 1. Zero-Dependency Standalone Delivery / \u96F6\u4F9D\u8D56\u72EC\u7ACB\u4EA4\u4ED8
17207
17400
 
17208
- ## 2. Mount in Your App / \u5728\u4E1A\u52A1\u9875\u9762\u6302\u8F7D
17401
+ No npm packages or build step required. \`index.html\` is a self-contained zero-chrome deliverable ready for any static host (Cloudflare Pages, Vercel, GitHub Pages, Nginx, or OSS).
17402
+ `;
17403
+ const integrationDoc = path2.join(absDir, "INTEGRATION.md");
17404
+ fs.writeFileSync(
17405
+ integrationDoc,
17406
+ `# ${compName} Integration Guide / \u63A5\u5165\u6307\u5357
17407
+
17408
+ > **Resolved Delivery Target**: \`${resolvedPlatform}\` (${detection.summary})
17409
+
17410
+ ${installSection}
17411
+ ## 2. Mount or Deploy / \u6302\u8F7D\u6216\u90E8\u7F72
17209
17412
 
17210
17413
  \`\`\`tsx
17211
17414
  ${mountSnippet}
17212
17415
  \`\`\`
17213
-
17416
+ ${submitNote}
17214
17417
  ## 3. Files Generated / \u751F\u6210\u6587\u4EF6\u6E05\u5355
17215
17418
  - \`form.bundle.json\` \u2014 Finalized FormSchema + locked ThemeConfig
17216
17419
  - \`types.d.ts\` \u2014 TypeScript DTO derived from FormSchema
17217
- - \`${path2.basename(entryFile)}\` \u2014 Ready-to-run ${platform} page/component (supports \`hostHandlers\` & \`customControls\`)
17420
+ - \`${path2.basename(entryFile)}\` \u2014 Ready-to-run ${resolvedPlatform} deliverable
17218
17421
  `,
17219
17422
  "utf8"
17220
17423
  );
17221
17424
  files.integrationGuide = integrationDoc;
17222
17425
  return {
17223
17426
  status: "scaffolded",
17224
- platform,
17427
+ platform: resolvedPlatform,
17428
+ detection,
17429
+ submitUrl: effectiveSubmitUrl || null,
17225
17430
  componentName: compName,
17226
17431
  outDir: absDir,
17227
17432
  packages,
@@ -17232,6 +17437,7 @@ ${mountSnippet}
17232
17437
  }
17233
17438
  module2.exports = {
17234
17439
  listSnippetsAndPresets,
17440
+ detectHostEnvironment,
17235
17441
  schemaInit,
17236
17442
  schemaSet,
17237
17443
  schemaPatch,
@@ -17299,13 +17505,16 @@ var TOOLS = [
17299
17505
  },
17300
17506
  {
17301
17507
  name: "form_schema_patch",
17302
- description: "\u6309\u539F\u5B50 Patch \u64CD\u4F5C\u589E\u91CF\u7F16\u8F91\u5DF2\u6709 FormSchema\uFF08\u81EA\u52A8\u8865\u9F50\u624B\u673A\u53F7/\u8EAB\u4EFD\u8BC1\u7B49\u6807\u51C6\u683C\u5F0F\u6821\u9A8C\u5E76\u8FD4\u56DE Diff \u4E0E\u6CBB\u7406\u7ED3\u679C\uFF09",
17508
+ description: `\u6309\u539F\u5B50 Patch \u64CD\u4F5C\u589E\u91CF\u7F16\u8F91\u5DF2\u6709 FormSchema\uFF08\u81EA\u52A8\u8865\u9F50\u624B\u673A\u53F7/\u8EAB\u4EFD\u8BC1\u7B49\u6807\u51C6\u683C\u5F0F\u6821\u9A8C\u5E76\u8FD4\u56DE Diff \u4E0E\u6CBB\u7406\u7ED3\u679C\uFF09\u3002inputPath JSON \u793A\u4F8B\uFF1A{"ops":[{"type":"SET_FORM_META","patch":{"storageKey":"apf_demo"}},{"type":"ADD_GROUP","group":{"key":"g1","title":"\u5206\u7EC4","items":[]}},{"type":"ADD_FIELD","groupKey":"g1","item":{"key":"team_mode","type":"radioGroup","label":"\u65B9\u5F0F","required":true,"initOptions":[{"code":"solo","name":"\u4E2A\u4EBA"},{"code":"team","name":"\u7EC4\u961F"}],"relations":[{"target":"team_size","effect":"visible","type":"local","logic":"value === 'team'"}]}}]}`,
17303
17509
  inputSchema: {
17304
17510
  type: "object",
17305
17511
  required: ["schemaPath", "inputPath"],
17306
17512
  properties: {
17307
17513
  schemaPath: { type: "string" },
17308
- inputPath: { type: "string", description: "\u5305\u542B ops \u6570\u7EC4\u7684 JSON \u6587\u4EF6\u8DEF\u5F84" },
17514
+ inputPath: {
17515
+ type: "string",
17516
+ description: "\u5305\u542B ops \u6570\u7EC4\u7684 JSON \u6587\u4EF6\u8DEF\u5F84\uFF08\u652F\u6301 SET_FORM_META.patch / ADD_GROUP.group / UPDATE_GROUP / REMOVE_GROUP / ADD_FIELD.groupKey+item / PATCH_FIELD.fieldKey+patch / REMOVE_FIELD / MOVE_FIELD / UPSERT_RELATION / INSERT_SNIPPET\uFF09"
17517
+ },
17309
17518
  enrich: { type: "boolean", default: true }
17310
17519
  }
17311
17520
  }
@@ -17336,13 +17545,16 @@ var TOOLS = [
17336
17545
  },
17337
17546
  {
17338
17547
  name: "form_schema_selftest",
17339
- description: "\u4F7F\u7528\u771F\u5B9E\u65E0\u5934 FormCore \u6267\u884C\u573A\u666F\u6D4B\u8BD5\uFF08\u6821\u9A8C\u62E6\u622A\u3001\u8054\u52A8\u663E\u9690\u3001collectFormData \u65AD\u8A00\uFF09\uFF0C\u4F5C\u4E3A\u4EA4\u4ED8\u95E8\u7981",
17548
+ description: '\u4F7F\u7528\u771F\u5B9E\u65E0\u5934 FormCore \u6267\u884C\u573A\u666F\u6D4B\u8BD5\uFF08\u6821\u9A8C\u62E6\u622A\u3001\u8054\u52A8\u663E\u9690\u3001collectFormData \u65AD\u8A00\uFF09\uFF0C\u4F5C\u4E3A\u4EA4\u4ED8\u95E8\u7981\u3002inputPath JSON \u793A\u4F8B\uFF1A{"name":"E2E","steps":[{"name":"\u8054\u52A8","set":{"team_mode":"team"},"validateAll":true,"expect":{"visible":{"team_size":true},"values":{"team_mode":"team"},"errMsg":{"full_name":null}}}]}',
17340
17549
  inputSchema: {
17341
17550
  type: "object",
17342
17551
  required: ["schemaPath", "inputPath"],
17343
17552
  properties: {
17344
17553
  schemaPath: { type: "string" },
17345
- inputPath: { type: "string", description: "\u81EA\u6D4B\u573A\u666F JSON \u8DEF\u5F84" }
17554
+ inputPath: {
17555
+ type: "string",
17556
+ description: '\u81EA\u6D4B\u573A\u666F JSON \u8DEF\u5F84\uFF08\u683C\u5F0F\uFF1A{"name":"...","steps":[{"name":"...","set":{},"validateAll":true,"expect":{"visible":{},"values":{},"errMsg":{},"relationApplied":[]}}]}\uFF09'
17557
+ }
17346
17558
  }
17347
17559
  }
17348
17560
  },
@@ -17382,7 +17594,7 @@ var TOOLS = [
17382
17594
  },
17383
17595
  {
17384
17596
  name: "form_preview_html",
17385
- description: '1 \u79D2\u5BFC\u51FA\u96F6\u4F9D\u8D56\u3001\u65E0\u9700\u542F\u52A8\u670D\u52A1\u7684\u79BB\u7EBF\u5355\u6587\u4EF6 HTML\uFF1B\u652F\u6301 mode="preview"\uFF08\u5E26\u6837\u5F0F/\u952E\u76D8\u8C03\u8BD5\u5DE5\u5177\u680F\uFF09\u4E0E mode="final"\uFF08\u96F6\u8C03\u8BD5\u680F\u3001\u6837\u5F0F\u4E0E\u4EA4\u4E92\u5DF2\u6C89\u6DC0\u9501\u5B9A\u7684\u6700\u7EC8\u4EA4\u4ED8\u6210\u54C1\uFF09\uFF0C\u652F\u6301 locale="zh-CN"|"en-US"',
17597
+ description: '1 \u79D2\u5BFC\u51FA\u96F6\u4F9D\u8D56\u3001\u65E0\u9700\u542F\u52A8\u670D\u52A1\u7684\u79BB\u7EBF\u5355\u6587\u4EF6 HTML\uFF1B\u652F\u6301 mode="preview"\uFF08\u5E26\u6837\u5F0F/\u952E\u76D8\u8C03\u8BD5\u5DE5\u5177\u680F\uFF09\u4E0E mode="final"\uFF08\u96F6\u8C03\u8BD5\u680F\u3001\u6837\u5F0F\u4E0E\u4EA4\u4E92\u5DF2\u6C89\u6DC0\u9501\u5B9A\u7684\u6700\u7EC8\u4EA4\u4ED8\u6210\u54C1\uFF09\uFF0C\u652F\u6301 locale="zh-CN"|"en-US" \u4EE5\u53CA\u53EF\u9009 submitUrl \u63D0\u4EA4\u51FA\u53E3',
17386
17598
  inputSchema: {
17387
17599
  type: "object",
17388
17600
  required: ["schemaPath", "out"],
@@ -17391,7 +17603,8 @@ var TOOLS = [
17391
17603
  themePath: { type: "string" },
17392
17604
  out: { type: "string" },
17393
17605
  mode: { type: "string", enum: ["preview", "final"], default: "preview" },
17394
- locale: { type: "string", enum: ["zh-CN", "en-US"], description: "\u53EF\u9009\u8986\u76D6\u5BFC\u51FA HTML \u7684 UI \u8BED\u8A00\uFF08\u9ED8\u8BA4\u8DDF\u968F theme.locale \u6216 zh-CN\uFF09" }
17606
+ locale: { type: "string", enum: ["zh-CN", "en-US"], description: "\u53EF\u9009\u8986\u76D6\u5BFC\u51FA HTML \u7684 UI \u8BED\u8A00\uFF08\u9ED8\u8BA4\u8DDF\u968F theme.locale \u6216 zh-CN\uFF09" },
17607
+ submitUrl: { type: "string", description: "\u53EF\u9009\uFF1A\u663E\u5F0F\u914D\u7F6E\u72EC\u7ACB\u5B9A\u7A3F HTML \u7684 POST JSON \u63D0\u4EA4\u63A5\u53E3\uFF08http/https\uFF09\uFF1B\u7559\u7A7A\u5219 100% \u79BB\u7EBF\u672C\u5730\u56DE\u6267\u3001\u4E0D\u5916\u53D1\u4EFB\u4F55\u6570\u636E" }
17395
17608
  }
17396
17609
  }
17397
17610
  },
@@ -17420,7 +17633,8 @@ var TOOLS = [
17420
17633
  mappingPath: { type: "string" },
17421
17634
  outDir: { type: "string", description: "\u6700\u7EC8\u4EA4\u4ED8\u5305\u8F93\u51FA\u76EE\u5F55" },
17422
17635
  keyStyle: { type: "string", enum: ["snake_case", "camelCase"], default: "snake_case" },
17423
- includeHtml: { type: "boolean", default: true }
17636
+ includeHtml: { type: "boolean", default: true },
17637
+ submitUrl: { type: "string", description: "\u53EF\u9009\uFF1A\u4E3A\u5BFC\u51FA\u7684 final.html \u6CE8\u5165 POST JSON \u63D0\u4EA4\u51FA\u53E3\uFF08http/https\uFF09\uFF1B\u7559\u7A7A\u5219\u7EAF\u79BB\u7EBF" }
17424
17638
  }
17425
17639
  }
17426
17640
  },
@@ -17534,18 +17748,25 @@ var TOOLS = [
17534
17748
  },
17535
17749
  {
17536
17750
  name: "form_scaffold_host",
17537
- description: "\u4E00\u952E\u5C06\u5B9A\u7A3F\u8868\u5355\u811A\u624B\u67B6\u6CE8\u5165\u5230\u76EE\u6807\u5BBF\u4E3B\u5DE5\u7A0B\uFF08vue3 / react18 / miniapp / headless\uFF09\uFF0C\u81EA\u52A8\u751F\u6210 form.bundle.json\u3001types.d.ts\u3001\u63A5\u597D FormCore/\u5355\u5B57\u6BB5\u5931\u7126\u6821\u9A8C/hostHandlers/customControls \u7684\u53EF\u76F4\u63A5\u6302\u8F7D\u9875\u9762\u7EC4\u4EF6\u53CA INTEGRATION.md \u5B89\u88C5\u6307\u5F15",
17751
+ description: 'Agent-First \u4E00\u952E\u81EA\u52A8\u51B3\u7B56\u5E76\u843D\u5730\u6700\u7EC8\u4EA4\u4ED8\u7269\uFF1A\u9ED8\u8BA4 platform="auto" \u81EA\u52A8\u626B\u63CF\u5BBF\u4E3B\u76EE\u5F55\uFF08Vue 3 / React 18 / \u5FAE\u4FE1\u5C0F\u7A0B\u5E8F / \u65E0\u5DE5\u7A0B\u65F6\u81EA\u52A8\u964D\u7EA7\u4E3A\u72EC\u7ACB\u96F6\u4F9D\u8D56 HTML\uFF09\uFF0C\u81EA\u52A8\u751F\u6210 form.bundle.json\u3001types.d.ts\u3001\u53EF\u76F4\u63A5\u6302\u8F7D\u9875\u9762\u6216\u72EC\u7ACB index.html \u53CA INTEGRATION.md',
17538
17752
  inputSchema: {
17539
17753
  type: "object",
17540
- required: ["schemaPath", "platform", "outDir"],
17754
+ required: ["schemaPath", "outDir"],
17541
17755
  properties: {
17542
17756
  schemaPath: { type: "string" },
17543
17757
  themePath: { type: "string" },
17544
- platform: { type: "string", enum: ["vue3", "react18", "miniapp", "headless"] },
17545
- outDir: { type: "string", description: "\u76EE\u6807\u4E1A\u52A1\u5DE5\u7A0B\u5185\u7684\u76EE\u5F55\u8DEF\u5F84\uFF0C\u5982 ./src/forms/event-reg" },
17758
+ platform: {
17759
+ type: "string",
17760
+ enum: ["auto", "vue3", "react18", "miniapp", "standalone", "headless"],
17761
+ default: "auto",
17762
+ description: "\u76EE\u6807\u4EA4\u4ED8\u5F62\u6001\uFF1B\u9ED8\u8BA4 auto \u81EA\u52A8\u63A2\u6D4B\u9879\u76EE\u6280\u672F\u6808\uFF08\u65E0\u524D\u7AEF\u4ED3\u5E93\u65F6\u81EA\u52A8\u4EA7\u51FA\u96F6\u4F9D\u8D56 standalone index.html\uFF09"
17763
+ },
17764
+ projectDir: { type: "string", description: "\u53EF\u9009\uFF1A\u7528\u4E8E auto \u63A2\u6D4B\u7684\u5BBF\u4E3B\u5DE5\u7A0B\u6839\u76EE\u5F55\uFF08\u9ED8\u8BA4\u4ECE outDir \u5411\u4E0A\u626B\u63CF\uFF09" },
17765
+ outDir: { type: "string", description: "\u76EE\u6807\u4EA4\u4ED8\u76EE\u5F55\u8DEF\u5F84\uFF0C\u5982 ./src/forms/event-reg \u6216 ./dist-form" },
17546
17766
  componentName: { type: "string", description: "\u53EF\u9009\u7EC4\u4EF6\u540D\uFF08PascalCase\uFF09" },
17547
17767
  keyStyle: { type: "string", enum: ["snake_case", "camelCase"], default: "snake_case" },
17548
- packageScope: { type: "string", default: "@agentprismform" }
17768
+ packageScope: { type: "string", default: "@agentprismform" },
17769
+ submitUrl: { type: "string", description: "\u53EF\u9009\uFF1A\u663E\u5F0F\u914D\u7F6E\u63D0\u4EA4\u63A5\u6536\u7AEF\u70B9\uFF08http/https\uFF09\uFF0C\u7528\u4E8E\u72EC\u7ACB HTML \u6216\u5C0F\u7A0B\u5E8F\u9ED8\u8BA4\u63D0\u4EA4\u63A5\u53E3" }
17549
17770
  }
17550
17771
  }
17551
17772
  }
@@ -17593,7 +17814,7 @@ async function callTool(name, args = {}) {
17593
17814
  case "form_hub_webhook":
17594
17815
  return await v2.hubWebhook(args);
17595
17816
  case "form_scaffold_host":
17596
- return v2.scaffoldHost(args);
17817
+ return v2.scaffoldHost({ ...args, assetsDir });
17597
17818
  default:
17598
17819
  throw Object.assign(new Error(`\u672A\u77E5 MCP \u5DE5\u5177\uFF1A${name}`), { code: "INVALID_ARGUMENT" });
17599
17820
  }