@agentprismform/agent-plugin 1.2.0 → 1.3.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.
@@ -5297,154 +5297,59 @@ module.exports = ${JSON.stringify(payload, null, 2)}
5297
5297
  let entryFile = "";
5298
5298
  let mountSnippet = "";
5299
5299
  if (platform === "vue3") {
5300
- packages = [`${scope}/core`, `${scope}/render`, `${scope}/render-vue`, `${scope}/render-ui`];
5300
+ packages = [`${scope}/render-vue`];
5301
5301
  entryFile = path2.join(absDir, `${compName}.vue`);
5302
5302
  const vueCode = `<script setup lang="ts">
5303
- import { onMounted, onUnmounted, provide, reactive, ref, watch } from 'vue'
5304
- import { FormCore, type FormSchema } from '${scope}/core'
5305
- import { createFormRenderState, type ResolvedFormGroup } from '${scope}/render'
5306
- import { FormRender } from '${scope}/render-vue'
5307
- import {
5308
- FORM_UI_HOST_HANDLERS_KEY,
5309
- MODERN_COLLAPSIBLE_KEY,
5310
- MODERN_CUSTOM_CONTROLS_KEY,
5311
- MODERN_KEYBOARD_POLICY_KEY,
5312
- MODERN_LOCALE_KEY,
5313
- MODERN_SHELL_SKIN_KEY,
5314
- MODERN_THEME_OVERRIDE_KEY,
5315
- getModernShellComponents,
5316
- resolveModernThemeVars,
5317
- type FormUiHostHandlers,
5318
- type ModernCustomControlsMap,
5319
- type ModernKeyboardPolicy,
5320
- type ModernLocale,
5321
- type ModernShellSkin,
5322
- } from '${scope}/render-ui'
5323
- import '${scope}/render-ui/style.css'
5303
+ import { PrismForm, type UniversalHostHandlers } from '${scope}/render-vue'
5324
5304
  import '${scope}/render-vue/style.css'
5325
5305
  import bundle from './form.bundle.json'
5326
5306
 
5327
- const props = withDefaults(
5307
+ withDefaults(
5328
5308
  defineProps<{
5329
- hostHandlers?: FormUiHostHandlers | null
5330
- customControls?: ModernCustomControlsMap
5331
- locale?: ModernLocale
5309
+ hostHandlers?: UniversalHostHandlers | null
5310
+ customControls?: Record<string, any>
5311
+ locale?: 'zh-CN' | 'en-US'
5332
5312
  submitText?: string
5313
+ submitting?: boolean
5333
5314
  }>(),
5334
5315
  {
5335
5316
  hostHandlers: null,
5336
5317
  customControls: () => ({}),
5337
- locale: ((bundle.themeConfig as any)?.locale || 'zh-CN') as ModernLocale,
5318
+ locale: ((bundle.themeConfig as any)?.locale || 'zh-CN') as 'zh-CN' | 'en-US',
5338
5319
  submitText: ((bundle.themeConfig as any)?.submitText || '') as string,
5320
+ submitting: false,
5339
5321
  },
5340
5322
  )
5341
5323
 
5342
5324
  const emit = defineEmits<{
5343
5325
  (e: 'submit', payload: Record<string, unknown>): void
5344
5326
  }>()
5345
-
5346
- const schema = bundle.schema as unknown as FormSchema
5347
- const themeCfg = (bundle.themeConfig || {}) as Record<string, any>
5348
- const skin = ref<ModernShellSkin>((themeCfg.skin || 'fin-minimal') as ModernShellSkin)
5349
- const localeRef = ref<ModernLocale>(props.locale)
5350
- watch(() => props.locale, (v) => { localeRef.value = v })
5351
-
5352
- const themeVars = resolveModernThemeVars(skin.value, themeCfg.override || null)
5353
- const modernShell = getModernShellComponents()
5354
-
5355
- const fields = reactive<Record<string, any>>({})
5356
- const groups = ref<ResolvedFormGroup[]>([])
5357
- const submitting = ref(false)
5358
- let core: FormCore | null = null
5359
-
5360
- provide(FORM_UI_HOST_HANDLERS_KEY, props.hostHandlers)
5361
- provide(MODERN_SHELL_SKIN_KEY, skin)
5362
- provide(MODERN_THEME_OVERRIDE_KEY, themeCfg.override || null)
5363
- provide(MODERN_COLLAPSIBLE_KEY, themeCfg.formMode === 'collapsible')
5364
- provide(MODERN_KEYBOARD_POLICY_KEY, (themeCfg.keyboardPolicy || 'auto') as ModernKeyboardPolicy)
5365
- provide(MODERN_LOCALE_KEY, localeRef)
5366
- provide(MODERN_CUSTOM_CONTROLS_KEY, props.customControls)
5367
-
5368
- function syncState() {
5369
- if (!core) return
5370
- for (const k of Object.keys(fields)) delete fields[k]
5371
- for (const k of Object.keys(core.fields)) fields[k] = { ...core.fields[k] }
5372
- groups.value = createFormRenderState(schema, { ...fields }, { excludeTaskAndAgreement: false }).groups
5373
- }
5374
-
5375
- async function onSubmit() {
5376
- if (!core || submitting.value) return
5377
- if (!core.validateAll()) {
5378
- syncState()
5379
- const firstErr = document.querySelector('[data-has-error="1"]') as HTMLElement | null
5380
- firstErr?.scrollIntoView({ behavior: 'smooth', block: 'center' })
5381
- const input = firstErr?.querySelector('input, textarea, select') as HTMLElement | null
5382
- input?.focus?.({ preventScroll: true })
5383
- return
5384
- }
5385
- submitting.value = true
5386
- try {
5387
- const payload = core.collectFormData({ skipVerify: true })
5388
- emit('submit', payload)
5389
- } finally {
5390
- submitting.value = false
5391
- }
5392
- }
5393
-
5394
- onMounted(async () => {
5395
- const mem = new Map<string, any>()
5396
- core = new FormCore(JSON.parse(JSON.stringify(schema)), {
5397
- get: (k) => mem.get(k),
5398
- set: (k, v) => mem.set(k, v),
5399
- remove: (k) => mem.delete(k),
5400
- })
5401
- await core.init({})
5402
- core.on('afterChange', syncState)
5403
- syncState()
5404
- })
5405
-
5406
- onUnmounted(() => {
5407
- core?.off('afterChange', syncState)
5408
- })
5409
5327
  </script>
5410
5328
 
5411
5329
  <template>
5412
- <div class="apf-host-page" :style="themeVars" style="max-width: 480px; margin: 0 auto; padding-bottom: 72px;">
5413
- <FormRender
5414
- v-if="core"
5415
- :groups="groups"
5416
- :fields="fields"
5417
- :formCore="core"
5418
- :host-handlers="hostHandlers"
5419
- :custom-controls="customControls"
5420
- v-bind="modernShell"
5421
- />
5422
- <div style="padding: 12px 16px;">
5423
- <button
5424
- type="button"
5425
- :disabled="submitting"
5426
- style="width: 100%; height: 44px; border: 0; border-radius: 10px; background: var(--fs-brand, #0F52BA); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;"
5427
- @click="onSubmit"
5428
- >
5429
- {{ submitText || (localeRef === 'en-US' ? 'Submit Form' : '\u63D0\u4EA4\u8868\u5355') }}
5430
- </button>
5431
- </div>
5432
- </div>
5330
+ <PrismForm
5331
+ :bundle="bundle as any"
5332
+ :host-handlers="hostHandlers"
5333
+ :custom-controls="customControls"
5334
+ :locale="locale"
5335
+ :submit-text="submitText || undefined"
5336
+ :submitting="submitting"
5337
+ @submit="(payload) => emit('submit', payload)"
5338
+ />
5433
5339
  </template>
5434
5340
  `;
5435
5341
  fs.writeFileSync(entryFile, vueCode, "utf8");
5436
5342
  files.component = entryFile;
5437
5343
  mountSnippet = `<${compName} :host-handlers="hostHandlers" :custom-controls="{}" @submit="handleSubmit" />`;
5438
5344
  } else if (platform === "react18") {
5439
- packages = [`${scope}/core`, `${scope}/render`, `${scope}/render-web`];
5345
+ packages = [`${scope}/render-web`];
5440
5346
  entryFile = path2.join(absDir, `${compName}.tsx`);
5441
- const reactCode = `import React, { useCallback, useEffect, useRef, useState } from 'react'
5442
- import { FormCore, type FormSchema } from '${scope}/core'
5347
+ const reactCode = `import React from 'react'
5443
5348
  import {
5444
- FormRender,
5349
+ PrismForm,
5445
5350
  type FormWebHostHandlers,
5446
5351
  type WebCustomControlsMap,
5447
- type WebModernSkin,
5352
+ type WebLocale,
5448
5353
  type WebRenderControlFn,
5449
5354
  } from '${scope}/render-web'
5450
5355
  import bundle from './form.bundle.json'
@@ -5453,6 +5358,7 @@ export interface ${compName}Props {
5453
5358
  hostHandlers?: FormWebHostHandlers | null
5454
5359
  customControls?: WebCustomControlsMap
5455
5360
  renderControl?: WebRenderControlFn
5361
+ locale?: WebLocale
5456
5362
  submitText?: string
5457
5363
  onSubmit: (payload: Record<string, unknown>) => void | Promise<void>
5458
5364
  }
@@ -5461,114 +5367,20 @@ export function ${compName}({
5461
5367
  hostHandlers = null,
5462
5368
  customControls,
5463
5369
  renderControl,
5370
+ locale,
5464
5371
  submitText,
5465
5372
  onSubmit,
5466
5373
  }: ${compName}Props) {
5467
- const schema = bundle.schema as unknown as FormSchema
5468
- const themeCfg = (bundle.themeConfig || {}) as Record<string, any>
5469
- const coreRef = useRef<FormCore | null>(null)
5470
- const [fields, setFields] = useState<Record<string, any>>({})
5471
- const [submitting, setSubmitting] = useState(false)
5472
-
5473
- const syncState = useCallback(() => {
5474
- const c = coreRef.current
5475
- if (!c) return
5476
- const next: Record<string, any> = {}
5477
- for (const k of Object.keys(c.fields)) next[k] = { ...c.fields[k] }
5478
- setFields(next)
5479
- }, [])
5480
-
5481
- useEffect(() => {
5482
- const mem = new Map<string, any>()
5483
- const c = new FormCore(JSON.parse(JSON.stringify(schema)), {
5484
- get: (k) => mem.get(k),
5485
- set: (k, v) => mem.set(k, v),
5486
- remove: (k) => mem.delete(k),
5487
- })
5488
- coreRef.current = c
5489
- c.init({}).then(() => {
5490
- c.on('afterChange', syncState)
5491
- syncState()
5492
- })
5493
- return () => { c.off('afterChange', syncState) }
5494
- }, [schema, syncState])
5495
-
5496
- const handleFieldChange = useCallback(
5497
- ({ key, value, eventType }: { key: string; value: any; eventType?: string }) => {
5498
- const c = coreRef.current
5499
- if (!c) return
5500
- const hadError = Boolean(c.fields[key]?.errMsg)
5501
- c.setControlData(key, value, {
5502
- eventType: eventType === 'inputChange' ? undefined : eventType,
5503
- ...(eventType === 'inputChange' && !hadError ? { skipVerify: true } : {}),
5504
- })
5505
- },
5506
- [],
5507
- )
5508
-
5509
- const handleSubmit = async () => {
5510
- const c = coreRef.current
5511
- if (!c || submitting) return
5512
- if (!c.validateAll()) {
5513
- syncState()
5514
- const firstErr = document.querySelector('[data-has-error="1"]') as HTMLElement | null
5515
- firstErr?.scrollIntoView({ behavior: 'smooth', block: 'center' })
5516
- const input = firstErr?.querySelector('input, textarea, select') as HTMLElement | null
5517
- input?.focus?.({ preventScroll: true })
5518
- return
5519
- }
5520
- setSubmitting(true)
5521
- try {
5522
- const payload = c.collectFormData({ skipVerify: true })
5523
- await onSubmit(payload)
5524
- } finally {
5525
- setSubmitting(false)
5526
- }
5527
- }
5528
-
5529
- const label =
5530
- submitText ||
5531
- themeCfg.submitText ||
5532
- (String(themeCfg.locale || '').startsWith('en') ? 'Submit Form' : '\u63D0\u4EA4\u8868\u5355')
5533
-
5534
5374
  return (
5535
- <div style={{ maxWidth: 680, margin: '0 auto', paddingBottom: 48 }}>
5536
- <FormRender
5537
- schema={schema}
5538
- fields={fields}
5539
- formCore={coreRef.current}
5540
- skin={(themeCfg.skin || 'fin-minimal') as WebModernSkin}
5541
- themeOverride={themeCfg.override || null}
5542
- formMode={themeCfg.formMode || 'flat'}
5543
- showProgressBar={themeCfg.showProgressBar !== false}
5544
- hostHandlers={hostHandlers}
5545
- customControls={customControls}
5546
- renderControl={renderControl}
5547
- onFieldChange={handleFieldChange}
5548
- footer={
5549
- <div style={{ padding: '12px 16px' }}>
5550
- <button
5551
- type="button"
5552
- disabled={submitting}
5553
- onClick={handleSubmit}
5554
- style={{
5555
- width: '100%',
5556
- height: 44,
5557
- border: 0,
5558
- borderRadius: 10,
5559
- background: themeCfg.override?.brandColor || '#0F52BA',
5560
- color: '#fff',
5561
- fontSize: 15,
5562
- fontWeight: 600,
5563
- cursor: 'pointer',
5564
- }}
5565
- >
5566
- {label}
5567
- </button>
5568
- </div>
5569
- }
5570
- />
5571
- </div>
5375
+ <PrismForm
5376
+ bundle={bundle as any}
5377
+ hostHandlers={hostHandlers}
5378
+ customControls={customControls}
5379
+ renderControl={renderControl}
5380
+ locale={locale}
5381
+ submitText={submitText}
5382
+ onSubmit={onSubmit}
5383
+ />
5572
5384
  )
5573
5385
  }
5574
5386
  `;
@@ -5731,14 +5543,14 @@ Page({
5731
5543
 
5732
5544
  ## 1. Install Required Packages / \u5B89\u88C5\u4F9D\u8D56\u5305
5733
5545
 
5734
- **Option A \u2014 From local AgentPrismForm clone (works immediately without npm publish / \u65E0\u9700\u53D1 npm \u7ACB\u5373\u53EF\u7528):**
5546
+ **Option A \u2014 From npm registry / \u4ECE npm \u5B98\u65B9\u6E90\u76F4\u63A5\u5B89\u88C5\uFF08\u63A8\u8350\uFF09:**
5735
5547
  \`\`\`bash
5736
- ${localInstallCmd}
5548
+ ${npmInstallCmd}
5737
5549
  \`\`\`
5738
5550
 
5739
- **Option B \u2014 From npm registry (after \`@agentprismform/*\` is published):**
5551
+ **Option B \u2014 From local AgentPrismForm clone / \u79BB\u7EBF\u6216\u672C\u5730\u4ED3\u5E93\u8C03\u8BD5:**
5740
5552
  \`\`\`bash
5741
- ${npmInstallCmd}
5553
+ ${localInstallCmd}
5742
5554
  \`\`\`
5743
5555
 
5744
5556
  ## 2. Mount in Your App / \u5728\u4E1A\u52A1\u9875\u9762\u6302\u8F7D
@@ -6123,6 +5935,11 @@ data: ${JSON.stringify({
6123
5935
  // output/oss-release/agentprismform-1.0.0-stage/packages/agent-plugin/.oss-cli-entry.cjs
6124
5936
  var path = require("node:path");
6125
5937
  var os = require("node:os");
5938
+ var { spawnSync } = require("node:child_process");
5939
+ if (process.argv[2] === "install") {
5940
+ const r = spawnSync(process.execPath, [path.join(__dirname, "install-host.cjs"), ...process.argv.slice(3)], { stdio: "inherit" });
5941
+ process.exit(r.status === null ? 1 : r.status);
5942
+ }
6126
5943
  var v2 = require_v2Core();
6127
5944
  var { startV2Server: startServer } = require_v2Server();
6128
5945
  var protocolVersion = "1.0";
@@ -6169,7 +5986,7 @@ async function run() {
6169
5986
  const assetsDir = path.resolve(flags["--assets-dir"] || path.join(__dirname, "../preview"));
6170
5987
  let result;
6171
5988
  if (command === "describe") {
6172
- result = { name: "@agentprismform/agent-plugin", version: "1.2.0", protocolVersion, v2Supported: true, v2Loop: Object.keys(commands) };
5989
+ result = { name: "@agentprismform/agent-plugin", version: "1.3.0", protocolVersion, v2Supported: true, v2Loop: Object.keys(commands) };
6173
5990
  } else if (command === "snippets") {
6174
5991
  result = v2.listSnippetsAndPresets();
6175
5992
  } else if (command === "schema-init") {
@@ -6,7 +6,7 @@ const path = require('node:path')
6
6
  const VALID_HOSTS = ['antigravity', 'deepseek-harness', 'claude', 'cursor', 'all']
7
7
 
8
8
  function parse(argv) {
9
- const out = { host: 'antigravity', scope: 'user', package: path.resolve(__dirname, '..'), writeMcp: false, dryRun: false, home: os.homedir() }
9
+ const out = { host: 'antigravity', scope: 'user', package: path.resolve(__dirname, '..'), persistDir: '', writeMcp: false, dryRun: false, home: os.homedir() }
10
10
  for (let i = 0; i < argv.length; i += 1) {
11
11
  const k = argv[i]
12
12
  if (k === '--write-mcp') { out.writeMcp = true; continue }
@@ -14,14 +14,44 @@ function parse(argv) {
14
14
  const v = argv[++i]
15
15
  if (k === '--host') out.host = v
16
16
  else if (k === '--package') out.package = path.resolve(v)
17
+ else if (k === '--persist-dir') out.persistDir = path.resolve(v)
17
18
  else if (k === '--scope') out.scope = v
18
19
  else if (k === '--home') out.home = path.resolve(v)
19
- else throw new Error('Usage: --host antigravity|deepseek-harness|claude|cursor|all [--scope user|project] [--write-mcp] [--dry-run]')
20
+ else throw new Error('Usage: --host antigravity|deepseek-harness|claude|cursor|all [--scope user|project] [--write-mcp] [--dry-run] [--persist-dir <dir>]')
20
21
  }
21
22
  if (!VALID_HOSTS.includes(out.host)) throw new Error('--host must be ' + VALID_HOSTS.join('|'))
22
23
  return out
23
24
  }
24
25
 
26
+ function copyTree(src, dest) {
27
+ const stat = fs.statSync(src)
28
+ if (stat.isDirectory()) {
29
+ fs.mkdirSync(dest, { recursive: true })
30
+ for (const e of fs.readdirSync(src)) copyTree(path.join(src, e), path.join(dest, e))
31
+ return
32
+ }
33
+ fs.mkdirSync(path.dirname(dest), { recursive: true })
34
+ fs.copyFileSync(src, dest)
35
+ fs.chmodSync(dest, stat.mode)
36
+ }
37
+
38
+ function resolveInstallRoot(opts) {
39
+ const fromNpx = /[\\/]_npx[\\/]/i.test(opts.package)
40
+ const targetDir = opts.persistDir || (fromNpx ? path.join(opts.home, '.agentprismform/agent-plugin') : '')
41
+ if (!targetDir || path.resolve(targetDir) === path.resolve(opts.package)) {
42
+ return { pkg: opts.package, persisted: false }
43
+ }
44
+ if (!opts.dryRun) {
45
+ fs.rmSync(targetDir, { recursive: true, force: true })
46
+ fs.mkdirSync(targetDir, { recursive: true })
47
+ for (const entry of ['bin', 'preview', 'skills', 'package.json', 'README.md', 'README.zh-CN.md']) {
48
+ const src = path.join(opts.package, entry)
49
+ if (fs.existsSync(src)) copyTree(src, path.join(targetDir, entry))
50
+ }
51
+ }
52
+ return { pkg: targetDir, persisted: true }
53
+ }
54
+
25
55
  function expand(h) { return h === 'all' ? ['antigravity', 'deepseek-harness', 'claude', 'cursor'] : [h] }
26
56
  function skillRoot(h, s, home) {
27
57
  const base = s === 'user' ? home : process.cwd()
@@ -39,7 +69,7 @@ function mcpPath(h, s, home) {
39
69
 
40
70
  function main() {
41
71
  const opts = parse(process.argv.slice(2))
42
- const pkg = opts.package
72
+ const { pkg, persisted } = resolveInstallRoot(opts)
43
73
  const mcp = path.join(pkg, 'bin/form-agent-mcp.cjs')
44
74
  const entry = { command: 'node', args: [mcp], env: { FORM_AGENT_HOME: pkg } }
45
75
  const links = []
@@ -85,6 +115,6 @@ function main() {
85
115
  }
86
116
  mcpConfigs.push({ host: h, path: mp, written: Boolean(opts.writeMcp && !opts.dryRun) })
87
117
  }
88
- process.stdout.write(JSON.stringify({ ok: true, links, mcpConfigs, mcpSnippet: { mcpServers: { 'form-schema-agent': entry } } }, null, 2) + '\n')
118
+ process.stdout.write(JSON.stringify({ ok: true, installRoot: pkg, persisted, links, mcpConfigs, mcpSnippet: { mcpServers: { 'form-schema-agent': entry } } }, null, 2) + '\n')
89
119
  }
90
120
  main()
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@agentprismform/agent-plugin",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "AI Agent plugin for schema-driven forms: zero-dependency CLI, stdio MCP Server, Skill, SSE live-reload preview, and standalone offline HTML exporter",
5
5
  "bin": {
6
+ "agent-plugin": "bin/form-agent.cjs",
6
7
  "form-schema-agent": "bin/form-agent.cjs",
7
8
  "form-schema-agent-mcp": "bin/form-agent-mcp.cjs",
8
9
  "form-schema-install": "bin/install-host.cjs"