feat(friday-ai): AI 客服工作台 —— 托管企微、接待 Agent、预约确认
一套**寄生在宿主业务系统上**的 AI 客服能力:读全走 PAC,写留自己, 企微通过 ECom 非官方通道托管。独立库、独立部署,与 PAC 同仓但不焊死。 ## 边界(scripts/check-ai-boundaries.mjs 五道闸) 依赖白名单(分应用)· 独立 prisma schema 与 AI_DATABASE_URL · 跨 app 相对路径 · ECom 调用必带 deviceId(丢了会被当新设备,严重时封号)· 用户侧查询过数据范围。⚠ ️ 做成**可本地运行的脚本**而不是只写在 CI 里 —— 只存在于 CI 的检查没人推之前跑, 实际作用会退化成"合并请求红了才发现"。 ## 两条权限轴,各归各的 托管轴 accountScope() = wecom_accounts.user_id = 我 会话/发送/附件/通讯录 授权轴 orgUnitScope() = user_org_scopes 组织/诊所/无会话待办/PAC 读⚠ ️ 混在一起踩过:新同事绑好自己的号,看到的是**同事号里的**患者对话, 而自己号里的一条都没有。 ## 三层租户隔离 DB 复合外键(写)· Prisma 扩展自动注入 where.tenantId(读)· service 显式 where。⚠ ️ 第二层的受管模型**从 schema 推导**,⛔ 不手写清单 —— 手写那份漏过 4 张表, 而且正如它自己预言的:不报错。 ## Agent 接待(医疗信号规则先行,模型兜底)· 预约确认(扫描 + 会话双腿)。 出站四道闸:账号开关 · 在线 · 租户 AI 自动发送 · 人工接管态。 输出守卫拦医生姓名与金额 —— 不是"暂时",是没有任何工具能返回它们。 ## 前端 会话接待 · 通讯录绑患者 · 预约确认工作台 · 患者面板(PAC 事实 + 回访归并的时间线)。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Showing
apps/ai-service/.env.example
0 → 100644
apps/ai-service/.gitignore
0 → 100644
apps/ai-service/.swcrc
0 → 100644
apps/ai-service/deploy/backup-media.service
0 → 100644
apps/ai-service/deploy/backup-media.sh
0 → 100755
apps/ai-service/deploy/backup-media.timer
0 → 100644
apps/ai-service/jest.config.cjs
0 → 100644
apps/ai-service/nest-cli.json
0 → 100644
apps/ai-service/package.json
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-service/prisma/schema.prisma
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/src/app.module.ts
0 → 100644
apps/ai-service/src/cli/agent-advise.cli.ts
0 → 100644
apps/ai-service/src/cli/agent-context.cli.ts
0 → 100644
apps/ai-service/src/cli/cli-error.ts
0 → 100644
apps/ai-service/src/cli/dev-token.cli.ts
0 → 100644
apps/ai-service/src/cli/gen-jwt-key.cli.ts
0 → 100644
apps/ai-service/src/cli/maintain.cli.ts
0 → 100644
apps/ai-service/src/cli/pac-find.cli.ts
0 → 100644
apps/ai-service/src/cli/seed-org.cli.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/src/cli/send-text.cli.ts
0 → 100644
apps/ai-service/src/cli/sync-contacts.cli.ts
0 → 100644
apps/ai-service/src/cli/sync-rooms.cli.ts
0 → 100644
apps/ai-service/src/cli/sync-sessions.cli.ts
0 → 100644
apps/ai-service/src/cli/user-admin.cli.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/src/common/mask.ts
0 → 100644
apps/ai-service/src/common/tenant-context.ts
0 → 100644
apps/ai-service/src/config/configuration.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/src/health.controller.ts
0 → 100644
apps/ai-service/src/instrument.ts
0 → 100644
apps/ai-service/src/main.ts
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-service/src/prisma/prisma.module.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/src/prisma/prisma.service.ts
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/advice-line.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/agent-activity.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/agent-task.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/ai-replied.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/common-context.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/fact-cache.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/fact-ledger.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/mask-phone.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/org-allowed.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/output-guard.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/takeover.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tests/tenant-guard.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tsconfig.json
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-service/tsconfig.typecheck.json
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/.env.example
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/.gitignore
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/next.config.mjs
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/package.json
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/postcss.config.mjs
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/app/activate/page.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-web/src/app/contacts/page.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/app/globals.css
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/app/layout.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/app/login/page.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/app/page.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/account-gate.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/conv-detail.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/conv-header.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/conv-list.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/patient-panel.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/sidebar.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/avatar.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/badge.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/button.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/card.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/dialog.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/input.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/select.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/sheet.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/sonner.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/ui/textarea.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/components/wecom-bind.tsx
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/lib/api.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/lib/pac-profile.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/lib/use-clinic.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/lib/use-conv-stream.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/lib/utils.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/src/lib/wx-emoji.ts
0 → 100644
This diff is collapsed.
Click to expand it.
apps/ai-web/tsconfig.json
0 → 100644
This diff is collapsed.
Click to expand it.
deploy/deploy-ai.sh
0 → 100755
This diff is collapsed.
Click to expand it.
deploy/systemd/ai-service.service
0 → 100644
This diff is collapsed.
Click to expand it.
deploy/systemd/ai-web.service
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
packages/design-tokens/package.json
0 → 100644
This diff is collapsed.
Click to expand it.
packages/design-tokens/src/tokens.css
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/jest.config.cjs
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/package.json
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/account.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/contact.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/cursor.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/domain.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/index.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/media.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/message.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/paths.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/session.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/state-event.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/src/transport.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/ecom-client/tsconfig.json
0 → 100644
This diff is collapsed.
Click to expand it.
packages/host-connector/package.json
0 → 100644
This diff is collapsed.
Click to expand it.
packages/host-connector/src/index.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/host-connector/tsconfig.json
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/jest.config.cjs
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/package.json
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/src/client.spec.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/src/client.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/src/index.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/src/sign.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/src/types.ts
0 → 100644
This diff is collapsed.
Click to expand it.
packages/pac-client/tsconfig.json
0 → 100644
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
scripts/check-ai-boundaries.mjs
0 → 100755
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
Please
register
or
sign in
to comment