weifuwu 0.95.1 → 0.95.2

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.
@@ -101,9 +101,17 @@ async function main() {
101
101
  // 1. 应用 + 用户(框架 userSystem 三层模型)
102
102
  // ════════════════════════════════════════════════════
103
103
 
104
- // 使用固定 UUID 确保 re-seed app ID 永远不变
105
- // 应用 token 中的 appId 始终有效,无需重新登录
106
- const DEMO_APP_ID = '00000000-0000-0000-0000-000000000001'
104
+ // 应用 = 单应用模式的 _default 租户(agent-platform 实例化就是它)——业务数据必须落在 UI 登录租户
105
+ // (0.95.1 实证:数据落新建 demo 租户 → 登录后 agents/departments 全空)
106
+ // _default 不存在则建(与 users.migrate 同形——seed 可先于 server 首发运行)
107
+ let [defApp] = await orm.query.from('_weifuwu_apps').select('id').where({ slug: { eq: '_default' } }).run()
108
+ if (!defApp) {
109
+ ;[defApp] = await orm.query.insert('_weifuwu_apps')
110
+ .values({ slug: '_default', name: 'Default', owner_user_id: null, open_registration: true })
111
+ .returning('id')
112
+ .run()
113
+ }
114
+ const DEMO_APP_ID = String(defApp.id)
107
115
  const adminPassword = await hashPassword('admin123')
108
116
  const [admin] = await ins('_weifuwu_users', [{ email: 'admin@demo.com', name: '张明', password_hash: adminPassword, role: 'admin' }], { conflict: 'email', update: true, returning: ['id', 'name'] })
109
117
  console.log(' ✓ 管理员: admin@demo.com / admin123')
@@ -112,14 +120,15 @@ async function main() {
112
120
  const [user] = await ins('_weifuwu_users', [{ email: 'user@demo.com', name: '李华', password_hash: userPassword, role: 'member' }], { conflict: 'email', update: true, returning: ['id', 'name'] })
113
121
  console.log(' ✓ 用户: user@demo.com / user123')
114
122
 
115
- // 应用(= 产品/公司——一个 app 就是一个公司)
116
- await ins('_weifuwu_apps', [{ id: DEMO_APP_ID, slug: 'demo', name: '演示科技有限公司', owner_user_id: admin.id, sandbox_quota: 20 }], { conflict: 'id', update: true, merge: { sandbox_quota: 20 } })
117
- // 成员关系(owner + member
123
+ // 应用元数据(演示名/owner/沙箱配额——不动 open_registration:由 bootstrap 定策)
124
+ await orm.query.update('_weifuwu_apps').set({ name: '演示科技有限公司', owner_user_id: admin.id, sandbox_quota: 20 }).where({ id: { eq: DEMO_APP_ID } }).run()
125
+ // 成员关系(owner + member)——PK (app_id, user_id) 冲突 upsert(仅 role/invited_by 刷新)
126
+ // 可重复执行:re-seed 不撞 _weifuwu_app_members_pkey(2027-xx 实证)
118
127
  await ins('_weifuwu_app_members', [
119
128
  { app_id: DEMO_APP_ID, user_id: admin.id, role: 'owner', invited_by: admin.id },
120
129
  { app_id: DEMO_APP_ID, user_id: user.id, role: 'member', invited_by: admin.id },
121
- ], { conflict: undefined, update: false })
122
- console.log(' ✓ 应用: 演示科技有限公司(demo)')
130
+ ], { conflict: ['app_id', 'user_id'], update: true })
131
+ console.log(' ✓ 应用: 演示科技有限公司(_default 单应用租户)+ 登录成员(admin/user)')
123
132
 
124
133
  // ════════════════════════════════════════════════════
125
134
  // 2. Agent — 真实用户映射
@@ -534,7 +543,7 @@ df -h / | awk 'NR==2 {print \"磁盘使用率: \" \$5}'
534
543
  await ins('_weifuwu_app_members', [
535
544
  { app_id: ACME_APP_ID, user_id: boss.id, role: 'owner', invited_by: boss.id },
536
545
  { app_id: ACME_APP_ID, user_id: staff.id, role: 'member', invited_by: boss.id },
537
- ], { conflict: undefined })
546
+ ], { conflict: ['app_id', 'user_id'], update: true })
538
547
  const [bossAgent] = await ins('agents', [{ app_id: ACME_APP_ID, type: 'user', name: boss.name, user_id: boss.id, is_active: true }], { returning: ['id'] })
539
548
  const [staffAgent] = await ins('agents', [{ app_id: ACME_APP_ID, type: 'user', name: staff.name, user_id: staff.id, is_active: true }], { returning: ['id'] })
540
549
  const [acmeAi] = await ins('agents', [{