@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.
@@ -5,17 +5,17 @@ var __commonJS = (cb, mod) => function __require() {
5
5
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
6
  };
7
7
 
8
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/types.js
8
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/types.js
9
9
  var require_types = __commonJS({
10
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/types.js"(exports2) {
10
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/types.js"(exports2) {
11
11
  "use strict";
12
12
  Object.defineProperty(exports2, "__esModule", { value: true });
13
13
  }
14
14
  });
15
15
 
16
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/expression/types.js
16
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/expression/types.js
17
17
  var require_types2 = __commonJS({
18
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/expression/types.js"(exports2) {
18
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/expression/types.js"(exports2) {
19
19
  "use strict";
20
20
  Object.defineProperty(exports2, "__esModule", { value: true });
21
21
  exports2.DEFAULT_MAX_DEPTH = exports2.DEFAULT_MAX_LENGTH = exports2.ExpressionError = void 0;
@@ -32,9 +32,9 @@ var require_types2 = __commonJS({
32
32
  }
33
33
  });
34
34
 
35
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/expression/safeV1.js
35
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/expression/safeV1.js
36
36
  var require_safeV1 = __commonJS({
37
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/expression/safeV1.js"(exports2) {
37
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/expression/safeV1.js"(exports2) {
38
38
  "use strict";
39
39
  Object.defineProperty(exports2, "__esModule", { value: true });
40
40
  exports2.tokenize = tokenize;
@@ -461,9 +461,9 @@ var require_safeV1 = __commonJS({
461
461
  }
462
462
  });
463
463
 
464
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/expression/index.js
464
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/expression/index.js
465
465
  var require_expression = __commonJS({
466
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/expression/index.js"(exports2) {
466
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/expression/index.js"(exports2) {
467
467
  "use strict";
468
468
  Object.defineProperty(exports2, "__esModule", { value: true });
469
469
  exports2.tokenize = exports2.parseSafeV1 = exports2.isSafeV1Expression = exports2.DEFAULT_MAX_LENGTH = exports2.DEFAULT_MAX_DEPTH = exports2.ExpressionError = void 0;
@@ -621,9 +621,9 @@ var require_expression = __commonJS({
621
621
  }
622
622
  });
623
623
 
624
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/utils.js
624
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/utils.js
625
625
  var require_utils = __commonJS({
626
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/utils.js"(exports2) {
626
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/utils.js"(exports2) {
627
627
  "use strict";
628
628
  Object.defineProperty(exports2, "__esModule", { value: true });
629
629
  exports2.evaluateExpression = void 0;
@@ -722,9 +722,9 @@ var require_utils = __commonJS({
722
722
  }
723
723
  });
724
724
 
725
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/validate.js
725
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/validate.js
726
726
  var require_validate = __commonJS({
727
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/validate.js"(exports2) {
727
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/validate.js"(exports2) {
728
728
  "use strict";
729
729
  Object.defineProperty(exports2, "__esModule", { value: true });
730
730
  exports2.isEmptyValue = isEmptyValue;
@@ -920,9 +920,9 @@ var require_validate = __commonJS({
920
920
  }
921
921
  });
922
922
 
923
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/relations.js
923
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/relations.js
924
924
  var require_relations = __commonJS({
925
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/relations.js"(exports2) {
925
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/relations.js"(exports2) {
926
926
  "use strict";
927
927
  Object.defineProperty(exports2, "__esModule", { value: true });
928
928
  exports2.resolveRelations = resolveRelations;
@@ -1021,9 +1021,9 @@ var require_relations = __commonJS({
1021
1021
  }
1022
1022
  });
1023
1023
 
1024
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/FormCore.js
1024
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/FormCore.js
1025
1025
  var require_FormCore = __commonJS({
1026
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/FormCore.js"(exports2) {
1026
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/FormCore.js"(exports2) {
1027
1027
  "use strict";
1028
1028
  Object.defineProperty(exports2, "__esModule", { value: true });
1029
1029
  exports2.FormCore = void 0;
@@ -2227,9 +2227,9 @@ var require_FormCore = __commonJS({
2227
2227
  }
2228
2228
  });
2229
2229
 
2230
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/questionnaire.js
2230
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/questionnaire.js
2231
2231
  var require_questionnaire = __commonJS({
2232
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/questionnaire.js"(exports2) {
2232
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/questionnaire.js"(exports2) {
2233
2233
  "use strict";
2234
2234
  Object.defineProperty(exports2, "__esModule", { value: true });
2235
2235
  exports2.schemaToQuestionnaire = schemaToQuestionnaire;
@@ -2284,9 +2284,9 @@ var require_questionnaire = __commonJS({
2284
2284
  }
2285
2285
  });
2286
2286
 
2287
- // output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/index.js
2287
+ // output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/index.js
2288
2288
  var require_dist = __commonJS({
2289
- "output/oss-release/agentprismform-1.0.0-stage/packages/core/dist/index.js"(exports2) {
2289
+ "output/oss-release/agentprismform-1.4.0-stage/packages/core/dist/index.js"(exports2) {
2290
2290
  "use strict";
2291
2291
  var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
2292
2292
  if (k2 === void 0) k2 = k;
@@ -3131,19 +3131,37 @@ var require_patch = __commonJS({
3131
3131
  for (const op of operations) {
3132
3132
  switch (op.type) {
3133
3133
  case "SET_FORM_META": {
3134
- if (op.patch.title !== void 0)
3135
- next.title = op.patch.title;
3136
- if (op.patch.description !== void 0)
3137
- next.description = op.patch.description;
3138
- if (op.patch.submitApi !== void 0)
3139
- next.submitApi = op.patch.submitApi;
3140
- if (op.patch.storageKey !== void 0)
3141
- next.storageKey = op.patch.storageKey;
3134
+ const meta = op.patch || op;
3135
+ if (!meta || typeof meta !== "object") {
3136
+ opErrors.push({
3137
+ code: "INVALID_FIELD_KEY",
3138
+ severity: "error",
3139
+ message: 'SET_FORM_META \u9700\u8981 patch \u5BF9\u8C61\uFF0C\u4F8B\u5982 { "type": "SET_FORM_META", "patch": { "title": "...", "storageKey": "..." } }'
3140
+ });
3141
+ break;
3142
+ }
3143
+ if (meta.title !== void 0)
3144
+ next.title = meta.title;
3145
+ if (meta.description !== void 0)
3146
+ next.description = meta.description;
3147
+ if (meta.submitApi !== void 0)
3148
+ next.submitApi = meta.submitApi;
3149
+ if (meta.storageKey !== void 0)
3150
+ next.storageKey = meta.storageKey;
3142
3151
  break;
3143
3152
  }
3144
3153
  case "ADD_GROUP": {
3154
+ const grp = op.group || (op.key ? { key: op.key, title: op.title || "", items: op.items || [] } : null);
3155
+ if (!grp || typeof grp !== "object" || !grp.key) {
3156
+ opErrors.push({
3157
+ code: "GROUP_NOT_FOUND",
3158
+ severity: "error",
3159
+ 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": [] } }'
3160
+ });
3161
+ break;
3162
+ }
3145
3163
  const idx = clampIndex(op.index, next.groups.length);
3146
- next.groups.splice(idx, 0, JSON.parse(JSON.stringify(op.group)));
3164
+ next.groups.splice(idx, 0, JSON.parse(JSON.stringify(grp)));
3147
3165
  break;
3148
3166
  }
3149
3167
  case "UPDATE_GROUP": {
@@ -3157,12 +3175,13 @@ var require_patch = __commonJS({
3157
3175
  });
3158
3176
  break;
3159
3177
  }
3160
- if (op.patch.title !== void 0)
3161
- g.title = op.patch.title;
3162
- if (op.patch.description !== void 0)
3163
- g.description = op.patch.description;
3164
- if (op.patch.visible !== void 0)
3165
- g.visible = op.patch.visible;
3178
+ const gPatch = op.patch || {};
3179
+ if (gPatch.title !== void 0)
3180
+ g.title = gPatch.title;
3181
+ if (gPatch.description !== void 0)
3182
+ g.description = gPatch.description;
3183
+ if (gPatch.visible !== void 0)
3184
+ g.visible = gPatch.visible;
3166
3185
  break;
3167
3186
  }
3168
3187
  case "REMOVE_GROUP": {
@@ -4610,6 +4629,7 @@ var require_v2Core = __commonJS({
4610
4629
  "packages/form-agent/src/v2Core.cjs"(exports2, module2) {
4611
4630
  "use strict";
4612
4631
  var fs = require("node:fs");
4632
+ var os2 = require("node:os");
4613
4633
  var path2 = require("node:path");
4614
4634
  var crypto = require("node:crypto");
4615
4635
  var { FormCore } = require_dist();
@@ -5006,7 +5026,18 @@ var require_v2Core = __commonJS({
5006
5026
  function escapeInlineScript(text) {
5007
5027
  return String(text).replace(/<\/(script)/gi, "<\\/$1");
5008
5028
  }
5009
- function renderStandaloneHtml({ schema, themeConfig, mode, locale, assetsDir }) {
5029
+ function normalizeSubmitUrl(raw) {
5030
+ if (raw === void 0 || raw === null) return "";
5031
+ const trimmed = String(raw).trim();
5032
+ if (!trimmed) return "";
5033
+ if (!/^https?:\/\//i.test(trimmed)) {
5034
+ throw Object.assign(new Error(`\u65E0\u6548\u7684 submitUrl\uFF1A${trimmed}\uFF08\u4EC5\u652F\u6301 http:// \u6216 https:// \u5730\u5740\uFF09`), {
5035
+ code: "INVALID_ARGUMENT"
5036
+ });
5037
+ }
5038
+ return trimmed;
5039
+ }
5040
+ function renderStandaloneHtml({ schema, themeConfig, mode, locale, submitUrl, assetsDir }) {
5010
5041
  const normalizedTheme = themeConfig ? { ...themeConfig } : { version: "1.0.0", skin: "fin-minimal", override: {}, formMode: "flat", showProgressBar: true };
5011
5042
  const effectiveMode = mode === "final" || normalizedTheme.mode === "final" ? "final" : "preview";
5012
5043
  if (effectiveMode === "final") {
@@ -5016,6 +5047,7 @@ var require_v2Core = __commonJS({
5016
5047
  if (locale !== void 0 || normalizedTheme.locale) {
5017
5048
  normalizedTheme.locale = effectiveLocale;
5018
5049
  }
5050
+ const effectiveSubmitUrl = normalizeSubmitUrl(submitUrl);
5019
5051
  const jsPath = path2.join(assetsDir, "modern-preview.iife.js");
5020
5052
  const cssPath = path2.join(assetsDir, "modern-preview.css");
5021
5053
  if (!fs.existsSync(jsPath) || !fs.existsSync(cssPath)) {
@@ -5027,6 +5059,8 @@ var require_v2Core = __commonJS({
5027
5059
  const cssCode = fs.readFileSync(cssPath, "utf8");
5028
5060
  const safeTitle = String(schema.title || (effectiveLocale === "en-US" ? "FormSchema Live Preview" : "FormSchema \u5B9E\u65F6\u9884\u89C8")).replace(/[<>&"]/g, "");
5029
5061
  const pageTitle = effectiveMode === "final" ? safeTitle : `${safeTitle} \xB7 FormSchema Preview`;
5062
+ const submitUrlScriptLine = effectiveSubmitUrl ? `
5063
+ window.__AGENT_SUBMIT_URL__ = ${escapeInlineScript(JSON.stringify(effectiveSubmitUrl))};` : "";
5030
5064
  const html = `<!DOCTYPE html>
5031
5065
  <html lang="${effectiveLocale}">
5032
5066
  <head>
@@ -5038,7 +5072,7 @@ var require_v2Core = __commonJS({
5038
5072
  <body>
5039
5073
  <div id="app"></div>
5040
5074
  <script>
5041
- window.__AGENT_PREVIEW_MODE__ = ${JSON.stringify(effectiveMode)};
5075
+ window.__AGENT_PREVIEW_MODE__ = ${JSON.stringify(effectiveMode)};${submitUrlScriptLine}
5042
5076
  window.__AGENT_FORM_SCHEMA__ = ${escapeInlineScript(JSON.stringify(schema))};
5043
5077
  window.__AGENT_THEME_CONFIG__ = ${escapeInlineScript(JSON.stringify(normalizedTheme))};
5044
5078
  </script>
@@ -5046,16 +5080,22 @@ var require_v2Core = __commonJS({
5046
5080
  </body>
5047
5081
  </html>
5048
5082
  `;
5049
- return { html, mode: effectiveMode, locale: effectiveLocale };
5083
+ return { html, mode: effectiveMode, locale: effectiveLocale, submitUrl: effectiveSubmitUrl || null };
5050
5084
  }
5051
- function previewExportHtml({ schemaPath, themePath, out, mode, locale, assetsDir }) {
5085
+ function previewExportHtml({ schemaPath, themePath, out, mode, locale, submitUrl, assetsDir }) {
5052
5086
  const schema = normalizeSchemaEnvelope(readJsonFile(schemaPath, "FormSchema \u6587\u4EF6"));
5053
5087
  const themeConfig = themePath ? readJsonFile(themePath, "ThemeConfigJson \u6587\u4EF6") : { version: "1.0.0", skin: "fin-minimal", override: {}, formMode: "flat", showProgressBar: true };
5054
- const { html, mode: effectiveMode, locale: effectiveLocale } = renderStandaloneHtml({
5088
+ const {
5089
+ html,
5090
+ mode: effectiveMode,
5091
+ locale: effectiveLocale,
5092
+ submitUrl: effectiveSubmitUrl
5093
+ } = renderStandaloneHtml({
5055
5094
  schema,
5056
5095
  themeConfig,
5057
5096
  mode,
5058
5097
  locale,
5098
+ submitUrl,
5059
5099
  assetsDir
5060
5100
  });
5061
5101
  const absOut = path2.resolve(out);
@@ -5066,6 +5106,7 @@ var require_v2Core = __commonJS({
5066
5106
  status: "exported",
5067
5107
  mode: effectiveMode,
5068
5108
  locale: effectiveLocale,
5109
+ submitUrl: effectiveSubmitUrl,
5069
5110
  path: absOut,
5070
5111
  sizeKb,
5071
5112
  fileUrl: `file://${absOut}`
@@ -5131,8 +5172,10 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5131
5172
  outDir,
5132
5173
  keyStyle = "snake_case",
5133
5174
  includeHtml = true,
5175
+ submitUrl,
5134
5176
  assetsDir
5135
5177
  }) {
5178
+ const effectiveSubmitUrl = normalizeSubmitUrl(submitUrl);
5136
5179
  const schema = normalizeSchemaEnvelope(readJsonFile(schemaPath, "FormSchema \u6587\u4EF6"));
5137
5180
  const governance = validateFormSchemaGovernance(schema);
5138
5181
  if (!governance.valid) {
@@ -5170,7 +5213,7 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5170
5213
  let finalHtmlOut = null;
5171
5214
  let finalHtmlSizeKb = null;
5172
5215
  if (includeHtml !== false && assetsDir) {
5173
- const { html } = renderStandaloneHtml({ schema, themeConfig, mode: "final", assetsDir });
5216
+ const { html } = renderStandaloneHtml({ schema, themeConfig, mode: "final", submitUrl: effectiveSubmitUrl, assetsDir });
5174
5217
  finalHtmlOut = path2.join(absDir, "final.html");
5175
5218
  fs.writeFileSync(finalHtmlOut, html, "utf8");
5176
5219
  finalHtmlSizeKb = Math.round(fs.statSync(finalHtmlOut).size / 1024);
@@ -5187,6 +5230,7 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5187
5230
  piiFields: contract.piiSummary.map((p) => p.key),
5188
5231
  governanceValid: governance.valid,
5189
5232
  presetAuditCount: auditFieldPresetCoverage(schema).length,
5233
+ ...effectiveSubmitUrl ? { submitUrl: effectiveSubmitUrl } : {},
5190
5234
  artifacts: {
5191
5235
  schema: { file: "form.schema.json", sha256: sha256(schemaOut) },
5192
5236
  theme: { file: "theme.config.json", sha256: sha256(themeOut) },
@@ -5258,22 +5302,148 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5258
5302
  if (!name.endsWith("Form")) name += "Form";
5259
5303
  return name;
5260
5304
  }
5305
+ function tryReadJsonSafe(filePath) {
5306
+ try {
5307
+ if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) return null;
5308
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
5309
+ } catch (_) {
5310
+ return null;
5311
+ }
5312
+ }
5313
+ function findNearestExistingDir(targetPath) {
5314
+ let cur = path2.resolve(targetPath || process.cwd());
5315
+ for (let i = 0; i < 12; i++) {
5316
+ try {
5317
+ if (fs.existsSync(cur)) {
5318
+ return fs.statSync(cur).isDirectory() ? cur : path2.dirname(cur);
5319
+ }
5320
+ } catch (_) {
5321
+ }
5322
+ const parent = path2.dirname(cur);
5323
+ if (parent === cur) break;
5324
+ cur = parent;
5325
+ }
5326
+ return process.cwd();
5327
+ }
5328
+ function detectHostEnvironment({ projectDir, outDir } = {}) {
5329
+ const startDir = findNearestExistingDir(projectDir || outDir || process.cwd());
5330
+ const homeDir = path2.resolve(os2.homedir());
5331
+ const tmpDirs = /* @__PURE__ */ new Set([path2.resolve(os2.tmpdir())]);
5332
+ try {
5333
+ tmpDirs.add(fs.realpathSync(os2.tmpdir()));
5334
+ } catch (_) {
5335
+ }
5336
+ let cur = startDir;
5337
+ for (let depth = 0; depth < 6; depth++) {
5338
+ if (depth > 0 && (cur === homeDir || tmpDirs.has(cur))) break;
5339
+ const wxProj = tryReadJsonSafe(path2.join(cur, "project.config.json"));
5340
+ if (wxProj && (wxProj.appid !== void 0 || wxProj.miniprogramRoot !== void 0 || wxProj.compileType === "miniprogram")) {
5341
+ return {
5342
+ resolvedPlatform: "miniapp",
5343
+ confidence: "high",
5344
+ projectRoot: cur,
5345
+ signals: ["project.config.json"],
5346
+ summary: "Detected WeChat Miniapp project via project.config.json"
5347
+ };
5348
+ }
5349
+ const wxApp = tryReadJsonSafe(path2.join(cur, "app.json"));
5350
+ if (wxApp && Array.isArray(wxApp.pages)) {
5351
+ return {
5352
+ resolvedPlatform: "miniapp",
5353
+ confidence: "high",
5354
+ projectRoot: cur,
5355
+ signals: ["app.json(pages)"],
5356
+ summary: "Detected WeChat Miniapp project via app.json"
5357
+ };
5358
+ }
5359
+ const pkg = tryReadJsonSafe(path2.join(cur, "package.json"));
5360
+ if (pkg && typeof pkg === "object") {
5361
+ const deps = { ...pkg.dependencies || {}, ...pkg.devDependencies || {} };
5362
+ const hasVue = Boolean(deps.vue || deps.nuxt || deps["@vitejs/plugin-vue"]);
5363
+ const hasReact = Boolean(deps.react || deps["react-dom"] || deps.next || deps["@vitejs/plugin-react"]);
5364
+ if (hasVue && !hasReact) {
5365
+ const signals = ["package.json", deps.nuxt ? "dep:nuxt" : "dep:vue"];
5366
+ return {
5367
+ resolvedPlatform: "vue3",
5368
+ confidence: "high",
5369
+ projectRoot: cur,
5370
+ signals,
5371
+ summary: `Detected Vue 3 host project (${signals.join(", ")})`
5372
+ };
5373
+ }
5374
+ if (hasReact && !hasVue) {
5375
+ const signals = ["package.json", deps.next ? "dep:next" : "dep:react"];
5376
+ return {
5377
+ resolvedPlatform: "react18",
5378
+ confidence: "high",
5379
+ projectRoot: cur,
5380
+ signals,
5381
+ summary: `Detected React 18 host project (${signals.join(", ")})`
5382
+ };
5383
+ }
5384
+ if (hasVue && hasReact) {
5385
+ if (fs.existsSync(path2.join(cur, "src/App.vue"))) {
5386
+ return {
5387
+ resolvedPlatform: "vue3",
5388
+ confidence: "high",
5389
+ projectRoot: cur,
5390
+ signals: ["package.json", "src/App.vue"],
5391
+ summary: "Detected Vue 3 host project via src/App.vue"
5392
+ };
5393
+ }
5394
+ if (fs.existsSync(path2.join(cur, "src/App.tsx")) || fs.existsSync(path2.join(cur, "src/App.jsx"))) {
5395
+ return {
5396
+ resolvedPlatform: "react18",
5397
+ confidence: "high",
5398
+ projectRoot: cur,
5399
+ signals: ["package.json", "src/App.tsx"],
5400
+ summary: "Detected React 18 host project via src/App.tsx"
5401
+ };
5402
+ }
5403
+ }
5404
+ }
5405
+ const parent = path2.dirname(cur);
5406
+ if (parent === cur) break;
5407
+ cur = parent;
5408
+ }
5409
+ return {
5410
+ resolvedPlatform: "standalone",
5411
+ confidence: "fallback",
5412
+ projectRoot: startDir,
5413
+ signals: ["no-frontend-framework-detected"],
5414
+ summary: "No Vue/React/Miniapp host detected \u2014 delivering zero-dependency standalone HTML bundle"
5415
+ };
5416
+ }
5261
5417
  function scaffoldHost({
5262
5418
  schemaPath,
5263
5419
  themePath,
5264
- platform,
5420
+ platform = "auto",
5265
5421
  outDir,
5422
+ projectDir,
5266
5423
  componentName,
5267
5424
  keyStyle = "snake_case",
5268
- packageScope = "@agentprismform"
5425
+ packageScope = "@agentprismform",
5426
+ submitUrl,
5427
+ assetsDir
5269
5428
  }) {
5270
- const VALID_PLATFORMS = ["vue3", "react18", "miniapp", "headless"];
5271
- if (!VALID_PLATFORMS.includes(platform)) {
5429
+ const VALID_PLATFORMS = ["auto", "vue3", "react18", "miniapp", "standalone", "headless"];
5430
+ const requestedPlatform = platform || "auto";
5431
+ if (!VALID_PLATFORMS.includes(requestedPlatform)) {
5272
5432
  throw Object.assign(
5273
- new Error(`\u4E0D\u652F\u6301\u7684\u76EE\u6807\u5E73\u53F0\uFF1A${platform}\uFF08\u53EF\u9009\uFF1A${VALID_PLATFORMS.join(", ")}\uFF09`),
5433
+ new Error(`\u4E0D\u652F\u6301\u7684\u76EE\u6807\u5E73\u53F0\uFF1A${requestedPlatform}\uFF08\u53EF\u9009\uFF1A${VALID_PLATFORMS.join(", ")}\uFF09`),
5274
5434
  { code: "INVALID_ARGUMENT" }
5275
5435
  );
5276
5436
  }
5437
+ const effectiveSubmitUrl = normalizeSubmitUrl(submitUrl);
5438
+ const detection = requestedPlatform === "auto" ? { requestedPlatform: "auto", ...detectHostEnvironment({ projectDir, outDir }) } : {
5439
+ requestedPlatform,
5440
+ resolvedPlatform: requestedPlatform,
5441
+ confidence: "explicit",
5442
+ projectRoot: findNearestExistingDir(projectDir || outDir || process.cwd()),
5443
+ signals: ["explicit-platform"],
5444
+ summary: `Explicit platform requested: ${requestedPlatform}`
5445
+ };
5446
+ const resolvedPlatform = detection.resolvedPlatform;
5277
5447
  const schema = normalizeSchemaEnvelope(readJsonFile(schemaPath, "FormSchema \u6587\u4EF6"));
5278
5448
  const rawTheme = themePath ? readJsonFile(themePath, "ThemeConfigJson \u6587\u4EF6") : { version: "1.0.0", skin: "fin-minimal", override: {}, formMode: "flat", showProgressBar: true };
5279
5449
  const themeConfig = { ...rawTheme, mode: "final" };
@@ -5287,7 +5457,8 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5287
5457
  format: "agentprismform-mobile-bundle/v1",
5288
5458
  exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
5289
5459
  schema,
5290
- themeConfig
5460
+ themeConfig,
5461
+ ...effectiveSubmitUrl ? { submitUrl: effectiveSubmitUrl } : {}
5291
5462
  };
5292
5463
  const bundleOut = writeJsonAtomic(path2.join(absDir, "form.bundle.json"), bundle, { overwrite: true });
5293
5464
  const typesOut = path2.join(absDir, "types.d.ts");
@@ -5296,7 +5467,7 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5296
5467
  let packages = [];
5297
5468
  let entryFile = "";
5298
5469
  let mountSnippet = "";
5299
- if (platform === "vue3") {
5470
+ if (resolvedPlatform === "vue3") {
5300
5471
  packages = [`${scope}/render-vue`];
5301
5472
  entryFile = path2.join(absDir, `${compName}.vue`);
5302
5473
  const vueCode = `<script setup lang="ts">
@@ -5341,7 +5512,7 @@ const emit = defineEmits<{
5341
5512
  fs.writeFileSync(entryFile, vueCode, "utf8");
5342
5513
  files.component = entryFile;
5343
5514
  mountSnippet = `<${compName} :host-handlers="hostHandlers" :custom-controls="{}" @submit="handleSubmit" />`;
5344
- } else if (platform === "react18") {
5515
+ } else if (resolvedPlatform === "react18") {
5345
5516
  packages = [`${scope}/render-web`];
5346
5517
  entryFile = path2.join(absDir, `${compName}.tsx`);
5347
5518
  const reactCode = `import React from 'react'
@@ -5387,7 +5558,7 @@ export function ${compName}({
5387
5558
  fs.writeFileSync(entryFile, reactCode, "utf8");
5388
5559
  files.component = entryFile;
5389
5560
  mountSnippet = `<${compName} hostHandlers={hostHandlers} customControls={{}} onSubmit={handleSubmit} />`;
5390
- } else if (platform === "headless") {
5561
+ } else if (resolvedPlatform === "headless") {
5391
5562
  packages = [`${scope}/core`, `${scope}/render`];
5392
5563
  entryFile = path2.join(absDir, `${compName}.tsx`);
5393
5564
  const headlessCode = `import React, { useEffect, useRef, useState } from 'react'
@@ -5473,8 +5644,23 @@ export function ${compName}({ onSubmit }: ${compName}Props) {
5473
5644
  fs.writeFileSync(entryFile, headlessCode, "utf8");
5474
5645
  files.component = entryFile;
5475
5646
  mountSnippet = `<${compName} onSubmit={handleSubmit} />`;
5647
+ } else if (resolvedPlatform === "standalone") {
5648
+ packages = [];
5649
+ const resolvedAssetsDir = assetsDir || path2.resolve(__dirname, "../preview");
5650
+ const { html } = renderStandaloneHtml({
5651
+ schema,
5652
+ themeConfig,
5653
+ mode: "final",
5654
+ submitUrl: effectiveSubmitUrl,
5655
+ assetsDir: resolvedAssetsDir
5656
+ });
5657
+ entryFile = path2.join(absDir, "index.html");
5658
+ fs.writeFileSync(entryFile, html, "utf8");
5659
+ files.html = entryFile;
5660
+ mountSnippet = effectiveSubmitUrl ? `# Deploy index.html to any static host (Cloudflare Pages / Vercel / Nginx / OSS)
5661
+ # 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)`;
5476
5662
  } else {
5477
- packages = [`${scope}/core`, `${scope}/render`, `${scope}/render-miniapp`];
5663
+ packages = [`${scope}/render-miniapp`];
5478
5664
  const dataFile = path2.join(absDir, "preview-data.js");
5479
5665
  const jsonFile = path2.join(absDir, "index.json");
5480
5666
  const wxmlFile = path2.join(absDir, "index.wxml");
@@ -5504,6 +5690,7 @@ export function ${compName}({ onSubmit }: ${compName}Props) {
5504
5690
  `,
5505
5691
  "utf8"
5506
5692
  );
5693
+ const defaultMiniappUrl = effectiveSubmitUrl || "https://api.example.com/forms/submit";
5507
5694
  fs.writeFileSync(
5508
5695
  jsFile,
5509
5696
  `const bundle = require('./preview-data.js')
@@ -5516,7 +5703,7 @@ Page({
5516
5703
  onFormSubmit(ev) {
5517
5704
  this.setData({ submitting: true })
5518
5705
  wx.request({
5519
- url: (this.data.schema && this.data.schema.submitApi) || 'https://api.example.com/forms/submit',
5706
+ url: bundle.submitUrl || (this.data.schema && this.data.schema.submitApi) || ${JSON.stringify(defaultMiniappUrl)},
5520
5707
  method: 'POST',
5521
5708
  header: { 'Idempotency-Key': 'wx_' + Date.now() },
5522
5709
  data: ev.detail,
@@ -5534,14 +5721,19 @@ Page({
5534
5721
  files.pageJs = jsFile;
5535
5722
  mountSnippet = `// Register "${path2.basename(absDir)}/index" inside WeChat Miniapp app.json -> "pages"`;
5536
5723
  }
5537
- const localInstallCmd = "npm install --install-links " + packages.map((p) => `<path-to-AgentPrismForm>/packages/${p.split("/")[1]}`).join(" ");
5538
- const npmInstallCmd = `npm install ${packages.join(" ")}`;
5539
- const integrationDoc = path2.join(absDir, "INTEGRATION.md");
5540
- fs.writeFileSync(
5541
- integrationDoc,
5542
- `# ${compName} Integration Guide / \u63A5\u5165\u6307\u5357
5724
+ const localInstallCmd = packages.length ? "npm install --install-links " + packages.map((p) => `<path-to-AgentPrismForm>/packages/${p.split("/")[1]}`).join(" ") : "";
5725
+ const npmInstallCmd = packages.length ? `npm install ${packages.join(" ")}` : "";
5726
+ const submitNote = effectiveSubmitUrl ? `
5727
+ ## Submit Endpoint / \u63D0\u4EA4\u63A5\u53E3\u51FA\u53E3
5728
+
5729
+ Configured \`submitUrl\`: \`${effectiveSubmitUrl}\`
5543
5730
 
5544
- ## 1. Install Required Packages / \u5B89\u88C5\u4F9D\u8D56\u5305
5731
+ Payload envelope sent via \`POST\` (with \`Idempotency-Key\` header):
5732
+ \`\`\`json
5733
+ { "submissionId": "sub_...", "schemaVersion": "1.0.0", "storageKey": "${schema.storageKey || ""}", "submittedAt": "...", "channel": "web-mobile", "data": { ... } }
5734
+ \`\`\`
5735
+ ` : "";
5736
+ const installSection = packages.length ? `## 1. Install Required Packages / \u5B89\u88C5\u4F9D\u8D56\u5305
5545
5737
 
5546
5738
  **Option A \u2014 From npm registry / \u4ECE npm \u5B98\u65B9\u6E90\u76F4\u63A5\u5B89\u88C5\uFF08\u63A8\u8350\uFF09:**
5547
5739
  \`\`\`bash
@@ -5552,24 +5744,37 @@ ${npmInstallCmd}
5552
5744
  \`\`\`bash
5553
5745
  ${localInstallCmd}
5554
5746
  \`\`\`
5747
+ ` : `## 1. Zero-Dependency Standalone Delivery / \u96F6\u4F9D\u8D56\u72EC\u7ACB\u4EA4\u4ED8
5555
5748
 
5556
- ## 2. Mount in Your App / \u5728\u4E1A\u52A1\u9875\u9762\u6302\u8F7D
5749
+ 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).
5750
+ `;
5751
+ const integrationDoc = path2.join(absDir, "INTEGRATION.md");
5752
+ fs.writeFileSync(
5753
+ integrationDoc,
5754
+ `# ${compName} Integration Guide / \u63A5\u5165\u6307\u5357
5755
+
5756
+ > **Resolved Delivery Target**: \`${resolvedPlatform}\` (${detection.summary})
5757
+
5758
+ ${installSection}
5759
+ ## 2. Mount or Deploy / \u6302\u8F7D\u6216\u90E8\u7F72
5557
5760
 
5558
5761
  \`\`\`tsx
5559
5762
  ${mountSnippet}
5560
5763
  \`\`\`
5561
-
5764
+ ${submitNote}
5562
5765
  ## 3. Files Generated / \u751F\u6210\u6587\u4EF6\u6E05\u5355
5563
5766
  - \`form.bundle.json\` \u2014 Finalized FormSchema + locked ThemeConfig
5564
5767
  - \`types.d.ts\` \u2014 TypeScript DTO derived from FormSchema
5565
- - \`${path2.basename(entryFile)}\` \u2014 Ready-to-run ${platform} page/component (supports \`hostHandlers\` & \`customControls\`)
5768
+ - \`${path2.basename(entryFile)}\` \u2014 Ready-to-run ${resolvedPlatform} deliverable
5566
5769
  `,
5567
5770
  "utf8"
5568
5771
  );
5569
5772
  files.integrationGuide = integrationDoc;
5570
5773
  return {
5571
5774
  status: "scaffolded",
5572
- platform,
5775
+ platform: resolvedPlatform,
5776
+ detection,
5777
+ submitUrl: effectiveSubmitUrl || null,
5573
5778
  componentName: compName,
5574
5779
  outDir: absDir,
5575
5780
  packages,
@@ -5580,6 +5785,7 @@ ${mountSnippet}
5580
5785
  }
5581
5786
  module2.exports = {
5582
5787
  listSnippetsAndPresets,
5788
+ detectHostEnvironment,
5583
5789
  schemaInit,
5584
5790
  schemaSet,
5585
5791
  schemaPatch,
@@ -5932,7 +6138,7 @@ data: ${JSON.stringify({
5932
6138
  }
5933
6139
  });
5934
6140
 
5935
- // output/oss-release/agentprismform-1.0.0-stage/packages/agent-plugin/.oss-cli-entry.cjs
6141
+ // output/oss-release/agentprismform-1.4.0-stage/packages/agent-plugin/.oss-cli-entry.cjs
5936
6142
  var path = require("node:path");
5937
6143
  var os = require("node:os");
5938
6144
  var { spawnSync } = require("node:child_process");
@@ -5958,7 +6164,7 @@ var commands = {
5958
6164
  "preview-miniapp": ["--schema", "--miniapp-project"],
5959
6165
  "schema-export": ["--schema", "--out"],
5960
6166
  "release-export": ["--schema", "--out-dir"],
5961
- "scaffold-host": ["--schema", "--platform", "--out-dir"],
6167
+ "scaffold-host": ["--schema", "--out-dir"],
5962
6168
  "schema-contract": ["--schema"],
5963
6169
  "contract-verify": ["--schema", "--target"],
5964
6170
  "payload-map": ["--schema", "--data"],
@@ -5986,7 +6192,7 @@ async function run() {
5986
6192
  const assetsDir = path.resolve(flags["--assets-dir"] || path.join(__dirname, "../preview"));
5987
6193
  let result;
5988
6194
  if (command === "describe") {
5989
- result = { name: "@agentprismform/agent-plugin", version: "1.3.0", protocolVersion, v2Supported: true, v2Loop: Object.keys(commands) };
6195
+ result = { name: "@agentprismform/agent-plugin", version: "1.4.0", protocolVersion, v2Supported: true, v2Loop: Object.keys(commands) };
5990
6196
  } else if (command === "snippets") {
5991
6197
  result = v2.listSnippetsAndPresets();
5992
6198
  } else if (command === "schema-init") {
@@ -6020,7 +6226,7 @@ async function run() {
6020
6226
  } else if (command === "preview-register") {
6021
6227
  result = v2.registerV2Preview({ schemaPath: flags["--schema"], themePath: flags["--theme"], dataDir });
6022
6228
  } else if (command === "preview-html") {
6023
- result = v2.previewExportHtml({ schemaPath: flags["--schema"], themePath: flags["--theme"], out: flags["--out"], mode: flags["--mode"], locale: flags["--locale"], assetsDir });
6229
+ result = v2.previewExportHtml({ schemaPath: flags["--schema"], themePath: flags["--theme"], out: flags["--out"], mode: flags["--mode"], locale: flags["--locale"], submitUrl: flags["--submit-url"], assetsDir });
6024
6230
  } else if (command === "preview-miniapp") {
6025
6231
  result = v2.previewSyncMiniapp({ schemaPath: flags["--schema"], themePath: flags["--theme"], miniappProject: flags["--miniapp-project"] });
6026
6232
  } else if (command === "schema-export") {
@@ -6033,17 +6239,21 @@ async function run() {
6033
6239
  outDir: flags["--out-dir"],
6034
6240
  keyStyle: flags["--key-style"] || "snake_case",
6035
6241
  includeHtml: flags["--include-html"] === void 0 ? true : flags["--include-html"] !== "false",
6242
+ submitUrl: flags["--submit-url"],
6036
6243
  assetsDir
6037
6244
  });
6038
6245
  } else if (command === "scaffold-host") {
6039
6246
  result = v2.scaffoldHost({
6040
6247
  schemaPath: flags["--schema"],
6041
6248
  themePath: flags["--theme"],
6042
- platform: flags["--platform"],
6249
+ platform: flags["--platform"] || "auto",
6043
6250
  outDir: flags["--out-dir"],
6251
+ projectDir: flags["--project-dir"],
6044
6252
  componentName: flags["--component-name"],
6045
6253
  keyStyle: flags["--key-style"] || "snake_case",
6046
- packageScope: flags["--scope"] || "@agentprismform"
6254
+ packageScope: flags["--scope"] || "@agentprismform",
6255
+ submitUrl: flags["--submit-url"],
6256
+ assetsDir
6047
6257
  });
6048
6258
  } else if (command === "schema-contract") {
6049
6259
  result = v2.schemaContract({ schemaPath: flags["--schema"], keyStyle: flags["--key-style"], out: flags["--out"] });