@reglow/reglow 0.9.0 → 0.12.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.
- package/dist/reglow/common/errors.js +1 -1
- package/dist/reglow/common/errors.js.map +1 -1
- package/dist/reglow/core/config.js +1 -1
- package/dist/reglow/core/config.js.map +1 -1
- package/dist/reglow/core/entities.d.ts +113 -1
- package/dist/reglow/core/models.d.ts +16 -0
- package/dist/reglow/core/models.js +9 -0
- package/dist/reglow/core/models.js.map +1 -1
- package/dist/reglow/modules/ai/controller.d.ts +15 -0
- package/dist/reglow/modules/ai/controller.js +21 -16
- package/dist/reglow/modules/ai/controller.js.map +1 -1
- package/dist/reglow/modules/ai/service.d.ts +4 -0
- package/dist/reglow/modules/ai/service.js +31 -1
- package/dist/reglow/modules/ai/service.js.map +1 -1
- package/dist/reglow/modules/analytics/collect.d.ts +13 -0
- package/dist/reglow/modules/analytics/collect.js +237 -0
- package/dist/reglow/modules/analytics/collect.js.map +1 -0
- package/dist/reglow/modules/analytics/controller.d.ts +6 -0
- package/dist/reglow/modules/analytics/controller.js +338 -0
- package/dist/reglow/modules/analytics/controller.js.map +1 -0
- package/dist/reglow/modules/analytics/controller_client.d.ts +6 -0
- package/dist/reglow/modules/analytics/controller_client.js +34 -0
- package/dist/reglow/modules/analytics/controller_client.js.map +1 -0
- package/dist/reglow/modules/analytics/gov.d.ts +30 -0
- package/dist/reglow/modules/analytics/gov.js +140 -0
- package/dist/reglow/modules/analytics/gov.js.map +1 -0
- package/dist/reglow/modules/analytics/model.d.ts +190 -0
- package/dist/reglow/modules/analytics/model.js +14 -0
- package/dist/reglow/modules/analytics/model.js.map +1 -0
- package/dist/reglow/modules/analytics/repository.d.ts +66 -0
- package/dist/reglow/modules/analytics/repository.js +451 -0
- package/dist/reglow/modules/analytics/repository.js.map +1 -0
- package/dist/reglow/modules/analytics/rollup.d.ts +17 -0
- package/dist/reglow/modules/analytics/rollup.js +299 -0
- package/dist/reglow/modules/analytics/rollup.js.map +1 -0
- package/dist/reglow/modules/analytics/router.d.ts +16 -0
- package/dist/reglow/modules/analytics/router.js +11 -0
- package/dist/reglow/modules/analytics/router.js.map +1 -0
- package/dist/reglow/modules/analytics/schema.d.ts +275 -0
- package/dist/reglow/modules/analytics/schema.js +7 -0
- package/dist/reglow/modules/analytics/schema.js.map +1 -0
- package/dist/reglow/modules/analytics/service.d.ts +51 -0
- package/dist/reglow/modules/analytics/service.js +653 -0
- package/dist/reglow/modules/analytics/service.js.map +1 -0
- package/dist/reglow/modules/analytics/snapshot.d.ts +10 -0
- package/dist/reglow/modules/analytics/snapshot.js +63 -0
- package/dist/reglow/modules/analytics/snapshot.js.map +1 -0
- package/dist/reglow/modules/article/controller.js +1 -0
- package/dist/reglow/modules/article/controller.js.map +1 -1
- package/dist/reglow/modules/article/schema.d.ts +2 -0
- package/dist/reglow/modules/article/schema.js +2 -0
- package/dist/reglow/modules/article/schema.js.map +1 -1
- package/dist/reglow/modules/article/service.d.ts +5 -0
- package/dist/reglow/modules/article/service.js +26 -1
- package/dist/reglow/modules/article/service.js.map +1 -1
- package/dist/reglow/modules/config/controller.js +3 -1
- package/dist/reglow/modules/config/controller.js.map +1 -1
- package/dist/reglow/modules/customer_service/repository.js +4 -2
- package/dist/reglow/modules/customer_service/repository.js.map +1 -1
- package/dist/reglow/modules/customer_service/sdk_template.html +4 -3
- package/dist/reglow/modules/dashboard/controller.js +7 -1
- package/dist/reglow/modules/dashboard/controller.js.map +1 -1
- package/dist/reglow/modules/dashboard/service.d.ts +1 -0
- package/dist/reglow/modules/dashboard/service.js +152 -0
- package/dist/reglow/modules/dashboard/service.js.map +1 -1
- package/dist/reglow/modules/material/controller.js +16 -0
- package/dist/reglow/modules/material/controller.js.map +1 -1
- package/dist/reglow/modules/material/repository.js +2 -2
- package/dist/reglow/modules/material/repository.js.map +1 -1
- package/dist/reglow/modules/material/service.d.ts +2 -0
- package/dist/reglow/modules/material/service.js +46 -4
- package/dist/reglow/modules/material/service.js.map +1 -1
- package/dist/reglow/modules/payment/service.js +7 -1
- package/dist/reglow/modules/payment/service.js.map +1 -1
- package/dist/reglow/modules/photo/controller.js +81 -55
- package/dist/reglow/modules/photo/controller.js.map +1 -1
- package/dist/reglow/modules/photo/repository.js +1 -1
- package/dist/reglow/modules/photo/repository.js.map +1 -1
- package/dist/reglow/modules/photo/service.d.ts +11 -1
- package/dist/reglow/modules/photo/service.js +65 -3
- package/dist/reglow/modules/photo/service.js.map +1 -1
- package/dist/reglow/modules/skill/controller.d.ts +8 -0
- package/dist/reglow/modules/skill/controller.js +93 -0
- package/dist/reglow/modules/skill/controller.js.map +1 -0
- package/dist/reglow/modules/skill/model.d.ts +19 -0
- package/dist/reglow/modules/skill/model.js +49 -0
- package/dist/reglow/modules/skill/model.js.map +1 -0
- package/dist/reglow/modules/skill/repository.d.ts +8 -0
- package/dist/reglow/modules/skill/repository.js +101 -0
- package/dist/reglow/modules/skill/repository.js.map +1 -0
- package/dist/reglow/modules/skill/router.d.ts +10 -0
- package/dist/reglow/modules/skill/router.js +8 -0
- package/dist/reglow/modules/skill/router.js.map +1 -0
- package/dist/reglow/modules/skill/schema.d.ts +39 -0
- package/dist/reglow/modules/skill/schema.js +38 -0
- package/dist/reglow/modules/skill/schema.js.map +1 -0
- package/dist/reglow/modules/skill/service.d.ts +62 -0
- package/dist/reglow/modules/skill/service.js +285 -0
- package/dist/reglow/modules/skill/service.js.map +1 -0
- package/dist/reglow/modules/studio/controller.d.ts +9 -0
- package/dist/reglow/modules/studio/controller.js +303 -0
- package/dist/reglow/modules/studio/controller.js.map +1 -0
- package/dist/reglow/modules/studio/deps.d.ts +47 -0
- package/dist/reglow/modules/studio/deps.js +175 -0
- package/dist/reglow/modules/studio/deps.js.map +1 -0
- package/dist/reglow/modules/studio/engine.d.ts +85 -0
- package/dist/reglow/modules/studio/engine.js +881 -0
- package/dist/reglow/modules/studio/engine.js.map +1 -0
- package/dist/reglow/modules/studio/llm.d.ts +30 -0
- package/dist/reglow/modules/studio/llm.js +151 -0
- package/dist/reglow/modules/studio/llm.js.map +1 -0
- package/dist/reglow/modules/studio/mcp/client.d.ts +22 -0
- package/dist/reglow/modules/studio/mcp/client.js +99 -0
- package/dist/reglow/modules/studio/mcp/client.js.map +1 -0
- package/dist/reglow/modules/studio/mcp/transport.d.ts +59 -0
- package/dist/reglow/modules/studio/mcp/transport.js +259 -0
- package/dist/reglow/modules/studio/mcp/transport.js.map +1 -0
- package/dist/reglow/modules/studio/media.d.ts +52 -0
- package/dist/reglow/modules/studio/media.js +484 -0
- package/dist/reglow/modules/studio/media.js.map +1 -0
- package/dist/reglow/modules/studio/model.d.ts +23 -0
- package/dist/reglow/modules/studio/model.js +35 -0
- package/dist/reglow/modules/studio/model.js.map +1 -0
- package/dist/reglow/modules/studio/repository.d.ts +31 -0
- package/dist/reglow/modules/studio/repository.js +300 -0
- package/dist/reglow/modules/studio/repository.js.map +1 -0
- package/dist/reglow/modules/studio/router.d.ts +10 -0
- package/dist/reglow/modules/studio/router.js +8 -0
- package/dist/reglow/modules/studio/router.js.map +1 -0
- package/dist/reglow/modules/studio/schema.d.ts +194 -0
- package/dist/reglow/modules/studio/schema.js +739 -0
- package/dist/reglow/modules/studio/schema.js.map +1 -0
- package/dist/reglow/modules/studio/service.d.ts +168 -0
- package/dist/reglow/modules/studio/service.js +673 -0
- package/dist/reglow/modules/studio/service.js.map +1 -0
- package/dist/reglow/modules/studio/tools/builtins.d.ts +9 -0
- package/dist/reglow/modules/studio/tools/builtins.js +162 -0
- package/dist/reglow/modules/studio/tools/builtins.js.map +1 -0
- package/dist/reglow/modules/studio/tools/media_tools.d.ts +31 -0
- package/dist/reglow/modules/studio/tools/media_tools.js +412 -0
- package/dist/reglow/modules/studio/tools/media_tools.js.map +1 -0
- package/dist/reglow/modules/studio/tools/registry.d.ts +46 -0
- package/dist/reglow/modules/studio/tools/registry.js +160 -0
- package/dist/reglow/modules/studio/tools/registry.js.map +1 -0
- package/dist/reglow/modules/studio/tools/runner.d.ts +18 -0
- package/dist/reglow/modules/studio/tools/runner.js +89 -0
- package/dist/reglow/modules/studio/tools/runner.js.map +1 -0
- package/dist/reglow/modules/user/controller_client.js +1 -1
- package/dist/reglow/modules/user/controller_client.js.map +1 -1
- package/dist/reglow/modules/video/controller.js +1 -0
- package/dist/reglow/modules/video/controller.js.map +1 -1
- package/dist/reglow/modules/video/schema.d.ts +2 -0
- package/dist/reglow/modules/video/schema.js +2 -0
- package/dist/reglow/modules/video/schema.js.map +1 -1
- package/dist/reglow/modules/video/service.d.ts +5 -0
- package/dist/reglow/modules/video/service.js +26 -1
- package/dist/reglow/modules/video/service.js.map +1 -1
- package/dist/reglow/scripts/init-data.js +423 -2
- package/dist/reglow/scripts/init-data.js.map +1 -1
- package/dist/reglow/scripts/schema.d.ts +9 -0
- package/dist/reglow/scripts/schema.js +448 -1
- package/dist/reglow/scripts/schema.js.map +1 -1
- package/package.json +83 -83
|
@@ -5,5 +5,14 @@ interface TableSpec {
|
|
|
5
5
|
}
|
|
6
6
|
declare const TABLES: TableSpec[];
|
|
7
7
|
export declare function createTables(): Promise<void>;
|
|
8
|
+
export interface StudioP0MigrateResult {
|
|
9
|
+
added: string[];
|
|
10
|
+
skipped: string[];
|
|
11
|
+
pending?: string[];
|
|
12
|
+
}
|
|
13
|
+
/** 给存量库补齐 P0 新列(幂等)。 */
|
|
14
|
+
export declare function ensureStudioP0Columns(opts?: {
|
|
15
|
+
dryRun?: boolean;
|
|
16
|
+
}): Promise<StudioP0MigrateResult>;
|
|
8
17
|
export declare function autoInitDatabase(): Promise<void>;
|
|
9
18
|
export { TABLES };
|
|
@@ -458,6 +458,7 @@ const TABLES = [
|
|
|
458
458
|
t.integer("view_count").defaultTo(0);
|
|
459
459
|
t.dateTime("published_at");
|
|
460
460
|
bigint(t, "creator_id");
|
|
461
|
+
bigint(t, "cover_material_id");
|
|
461
462
|
addTimestamp(t);
|
|
462
463
|
addSoftDelete(t);
|
|
463
464
|
},
|
|
@@ -493,7 +494,6 @@ const TABLES = [
|
|
|
493
494
|
pk(t);
|
|
494
495
|
bigint(t, "album_id").notNullable().index();
|
|
495
496
|
bigint(t, "category_id");
|
|
496
|
-
bigint(t, "material_id");
|
|
497
497
|
t.string("title", 200);
|
|
498
498
|
t.string("alias", 200);
|
|
499
499
|
t.text("description");
|
|
@@ -501,6 +501,7 @@ const TABLES = [
|
|
|
501
501
|
t.string("thumbnail_url", 512);
|
|
502
502
|
t.boolean("is_cover").defaultTo(false);
|
|
503
503
|
t.integer("status").defaultTo(1);
|
|
504
|
+
t.integer("view_count").defaultTo(0);
|
|
504
505
|
t.integer("sort").defaultTo(0);
|
|
505
506
|
t.integer("width");
|
|
506
507
|
t.integer("height");
|
|
@@ -560,6 +561,7 @@ const TABLES = [
|
|
|
560
561
|
t.integer("sort").defaultTo(0);
|
|
561
562
|
t.dateTime("published_at");
|
|
562
563
|
bigint(t, "creator_id");
|
|
564
|
+
bigint(t, "cover_material_id");
|
|
563
565
|
addTimestamp(t);
|
|
564
566
|
addSoftDelete(t);
|
|
565
567
|
},
|
|
@@ -747,6 +749,373 @@ const TABLES = [
|
|
|
747
749
|
addTimestamp(t);
|
|
748
750
|
},
|
|
749
751
|
},
|
|
752
|
+
// ─────────────────────────── studio_* 智能工坊表 ───────────────────────────
|
|
753
|
+
{
|
|
754
|
+
name: "studio_skill",
|
|
755
|
+
build(t) {
|
|
756
|
+
pk(t);
|
|
757
|
+
t.string("name", 100).notNullable();
|
|
758
|
+
t.string("category", 30).defaultTo("body");
|
|
759
|
+
t.string("stage", 20).defaultTo("generate");
|
|
760
|
+
// 技能可执行模型(P0-1):kind/tool_key/input_schema/output_kind/timeout/runtime
|
|
761
|
+
t.string("kind", 16).defaultTo("prompt");
|
|
762
|
+
t.string("tool_key", 100);
|
|
763
|
+
jsonCol(t, "input_schema");
|
|
764
|
+
t.string("output_kind", 16);
|
|
765
|
+
t.integer("timeout").defaultTo(60);
|
|
766
|
+
t.string("runtime", 20).defaultTo("builtin");
|
|
767
|
+
jsonCol(t, "platforms");
|
|
768
|
+
t.string("description", 255);
|
|
769
|
+
t.text("content").notNullable();
|
|
770
|
+
t.integer("enabled").defaultTo(1);
|
|
771
|
+
t.integer("builtin").defaultTo(0);
|
|
772
|
+
t.integer("sort").defaultTo(0);
|
|
773
|
+
bigint(t, "created_by");
|
|
774
|
+
addTimestamp(t);
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
name: "studio_role",
|
|
779
|
+
build(t) {
|
|
780
|
+
pk(t);
|
|
781
|
+
t.string("key", 50).notNullable().unique();
|
|
782
|
+
t.string("name", 100).notNullable();
|
|
783
|
+
t.string("avatar", 16);
|
|
784
|
+
t.string("category", 30).defaultTo("内容");
|
|
785
|
+
t.string("description", 255);
|
|
786
|
+
t.text("system_prompt").notNullable();
|
|
787
|
+
jsonCol(t, "skill_ids");
|
|
788
|
+
t.string("model", 50);
|
|
789
|
+
t.integer("enabled").defaultTo(1);
|
|
790
|
+
t.integer("builtin").defaultTo(0);
|
|
791
|
+
t.integer("sort").defaultTo(0);
|
|
792
|
+
bigint(t, "created_by");
|
|
793
|
+
addTimestamp(t);
|
|
794
|
+
},
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
name: "studio_workflow",
|
|
798
|
+
build(t) {
|
|
799
|
+
pk(t);
|
|
800
|
+
t.string("name", 120).notNullable();
|
|
801
|
+
t.text("description");
|
|
802
|
+
t.text("goal");
|
|
803
|
+
jsonCol(t, "steps").notNullable();
|
|
804
|
+
t.string("source", 20).defaultTo("auto");
|
|
805
|
+
t.string("status", 20).defaultTo("active");
|
|
806
|
+
t.integer("run_count").defaultTo(0);
|
|
807
|
+
bigint(t, "created_by");
|
|
808
|
+
addTimestamp(t);
|
|
809
|
+
},
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
name: "studio_run",
|
|
813
|
+
build(t) {
|
|
814
|
+
pk(t);
|
|
815
|
+
bigint(t, "workflow_id");
|
|
816
|
+
t.string("workflow_name", 120);
|
|
817
|
+
t.string("title", 120).notNullable();
|
|
818
|
+
t.text("intent");
|
|
819
|
+
t.text("goal");
|
|
820
|
+
t.string("status", 20).defaultTo("pending");
|
|
821
|
+
jsonCol(t, "steps");
|
|
822
|
+
jsonCol(t, "step_states");
|
|
823
|
+
jsonCol(t, "result");
|
|
824
|
+
t.text("error");
|
|
825
|
+
t.string("source", 20).defaultTo("compose");
|
|
826
|
+
bigint(t, "created_by");
|
|
827
|
+
t.boolean("auto").defaultTo(false);
|
|
828
|
+
addTimestamp(t);
|
|
829
|
+
},
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
name: "studio_asset",
|
|
833
|
+
build(t) {
|
|
834
|
+
pk(t);
|
|
835
|
+
bigint(t, "run_id").index();
|
|
836
|
+
t.string("step_key", 64);
|
|
837
|
+
t.string("tool_key", 100);
|
|
838
|
+
t.string("kind", 16).defaultTo("file");
|
|
839
|
+
t.string("name", 200);
|
|
840
|
+
bigint(t, "material_id");
|
|
841
|
+
t.string("url", 512);
|
|
842
|
+
t.string("path", 512);
|
|
843
|
+
jsonCol(t, "meta");
|
|
844
|
+
t.string("source_tool", 100);
|
|
845
|
+
bigint(t, "created_by");
|
|
846
|
+
addTimestamp(t);
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
name: "studio_job",
|
|
851
|
+
build(t) {
|
|
852
|
+
pk(t);
|
|
853
|
+
bigint(t, "run_id").index();
|
|
854
|
+
t.string("step_key", 64);
|
|
855
|
+
t.string("tool_key", 100);
|
|
856
|
+
t.string("provider", 50);
|
|
857
|
+
t.string("external_task_id", 128);
|
|
858
|
+
t.string("status", 20).defaultTo("pending");
|
|
859
|
+
t.integer("progress").defaultTo(0);
|
|
860
|
+
jsonCol(t, "result");
|
|
861
|
+
t.text("error");
|
|
862
|
+
addTimestamp(t);
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
name: "studio_mcp_server",
|
|
867
|
+
build(t) {
|
|
868
|
+
pk(t);
|
|
869
|
+
t.string("name", 100).notNullable();
|
|
870
|
+
t.string("transport", 16).defaultTo("http");
|
|
871
|
+
t.string("url", 512);
|
|
872
|
+
t.string("command", 512);
|
|
873
|
+
t.string("auth_type", 32).defaultTo("none");
|
|
874
|
+
t.string("secret_ref", 255);
|
|
875
|
+
t.integer("enabled").defaultTo(0);
|
|
876
|
+
t.string("status", 20).defaultTo("unknown");
|
|
877
|
+
t.dateTime("last_sync_at");
|
|
878
|
+
bigint(t, "created_by");
|
|
879
|
+
addTimestamp(t);
|
|
880
|
+
},
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
name: "studio_mcp_tool",
|
|
884
|
+
build(t) {
|
|
885
|
+
pk(t);
|
|
886
|
+
bigint(t, "server_id").notNullable().index();
|
|
887
|
+
t.string("name", 100).notNullable();
|
|
888
|
+
t.string("description", 255);
|
|
889
|
+
jsonCol(t, "input_schema");
|
|
890
|
+
t.string("risk_level", 16).defaultTo("low");
|
|
891
|
+
t.integer("enabled").defaultTo(1);
|
|
892
|
+
t.dateTime("synced_at");
|
|
893
|
+
addTimestamp(t);
|
|
894
|
+
},
|
|
895
|
+
},
|
|
896
|
+
// ─────────────────────────── ana_* 数据埋点与分析表 ───────────────────────────
|
|
897
|
+
// 对齐 Python reglow/modules/analytics/model.py(13 张)。
|
|
898
|
+
// tenant_id 列按 L1 列约定保留(可空);本端单租户轨写入恒为 NULL。
|
|
899
|
+
{
|
|
900
|
+
name: "ana_app",
|
|
901
|
+
build(t) {
|
|
902
|
+
pk(t);
|
|
903
|
+
bigint(t, "tenant_id").index();
|
|
904
|
+
t.string("app_id", 64).notNullable().unique().index();
|
|
905
|
+
t.string("name", 128).notNullable();
|
|
906
|
+
t.string("platform_type", 32).defaultTo("web");
|
|
907
|
+
t.string("secret_ref", 255);
|
|
908
|
+
t.integer("enabled").defaultTo(1);
|
|
909
|
+
t.float("sample_rate").defaultTo(1.0);
|
|
910
|
+
t.text("config");
|
|
911
|
+
bigint(t, "created_by");
|
|
912
|
+
addTimestamp(t);
|
|
913
|
+
},
|
|
914
|
+
},
|
|
915
|
+
{
|
|
916
|
+
name: "ana_event",
|
|
917
|
+
build(t) {
|
|
918
|
+
pk(t);
|
|
919
|
+
t.string("app_id", 64).notNullable().index();
|
|
920
|
+
bigint(t, "tenant_id").index();
|
|
921
|
+
t.string("event_code", 128).notNullable().index();
|
|
922
|
+
t.string("event_type", 32);
|
|
923
|
+
t.string("user_id", 64);
|
|
924
|
+
t.string("device_id", 128).index();
|
|
925
|
+
t.string("session_id", 64).index();
|
|
926
|
+
t.string("page_key", 255).index();
|
|
927
|
+
t.string("elem_id", 255);
|
|
928
|
+
t.string("elem_type", 64);
|
|
929
|
+
t.text("props");
|
|
930
|
+
bigint(t, "ts").index();
|
|
931
|
+
bigint(t, "client_ts");
|
|
932
|
+
t.string("day", 10).index();
|
|
933
|
+
t.string("ip", 64);
|
|
934
|
+
t.string("ip_region", 64);
|
|
935
|
+
t.string("platform", 32);
|
|
936
|
+
t.string("app_version", 32);
|
|
937
|
+
t.string("sdk_version", 32);
|
|
938
|
+
t.string("event_uid", 128).index();
|
|
939
|
+
addTimestamp(t);
|
|
940
|
+
},
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
name: "ana_session",
|
|
944
|
+
build(t) {
|
|
945
|
+
pk(t);
|
|
946
|
+
t.string("app_id", 64).notNullable().index();
|
|
947
|
+
bigint(t, "tenant_id").index();
|
|
948
|
+
t.string("session_id", 64).notNullable().index();
|
|
949
|
+
t.string("device_id", 128).index();
|
|
950
|
+
t.string("user_id", 64);
|
|
951
|
+
bigint(t, "start_ts");
|
|
952
|
+
bigint(t, "end_ts");
|
|
953
|
+
bigint(t, "duration").defaultTo(0);
|
|
954
|
+
t.integer("page_views").defaultTo(0);
|
|
955
|
+
t.string("entry_page", 255);
|
|
956
|
+
t.string("exit_page", 255);
|
|
957
|
+
t.integer("is_new_user").defaultTo(0);
|
|
958
|
+
t.string("channel", 128);
|
|
959
|
+
t.integer("is_bounce").defaultTo(0);
|
|
960
|
+
addTimestamp(t);
|
|
961
|
+
},
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
name: "ana_page",
|
|
965
|
+
build(t) {
|
|
966
|
+
pk(t);
|
|
967
|
+
t.string("app_id", 64).notNullable().index();
|
|
968
|
+
bigint(t, "tenant_id").index();
|
|
969
|
+
t.string("page_key", 255).notNullable().index();
|
|
970
|
+
t.string("page_name", 255);
|
|
971
|
+
t.string("page_version", 64);
|
|
972
|
+
t.string("platform", 32);
|
|
973
|
+
t.dateTime("first_seen_at");
|
|
974
|
+
addTimestamp(t);
|
|
975
|
+
},
|
|
976
|
+
},
|
|
977
|
+
{
|
|
978
|
+
name: "ana_element",
|
|
979
|
+
build(t) {
|
|
980
|
+
pk(t);
|
|
981
|
+
t.string("app_id", 64).notNullable().index();
|
|
982
|
+
bigint(t, "tenant_id").index();
|
|
983
|
+
t.string("page_key", 255).index();
|
|
984
|
+
t.string("elem_id", 255).notNullable().index();
|
|
985
|
+
t.string("elem_type", 64);
|
|
986
|
+
t.string("elem_path", 512);
|
|
987
|
+
t.string("content_excerpt", 255);
|
|
988
|
+
t.dateTime("first_seen_at");
|
|
989
|
+
addTimestamp(t);
|
|
990
|
+
},
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
name: "ana_agg_search_day",
|
|
994
|
+
build(t) {
|
|
995
|
+
pk(t);
|
|
996
|
+
t.string("app_id", 64).notNullable().index();
|
|
997
|
+
bigint(t, "tenant_id").index();
|
|
998
|
+
t.string("day", 10).notNullable().index();
|
|
999
|
+
t.string("query_norm", 128).notNullable().index();
|
|
1000
|
+
t.integer("search_cnt").defaultTo(0);
|
|
1001
|
+
t.integer("zero_result_cnt").defaultTo(0);
|
|
1002
|
+
t.integer("click_cnt").defaultTo(0);
|
|
1003
|
+
t.integer("convert_cnt").defaultTo(0);
|
|
1004
|
+
bigint(t, "rank_sum").defaultTo(0);
|
|
1005
|
+
addTimestamp(t);
|
|
1006
|
+
},
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
name: "ana_agg_pref_day",
|
|
1010
|
+
build(t) {
|
|
1011
|
+
pk(t);
|
|
1012
|
+
t.string("app_id", 64).notNullable().index();
|
|
1013
|
+
bigint(t, "tenant_id").index();
|
|
1014
|
+
t.string("day", 10).notNullable().index();
|
|
1015
|
+
t.string("target_type", 64).index();
|
|
1016
|
+
t.string("target_id", 128).index();
|
|
1017
|
+
t.string("action", 32).notNullable().index();
|
|
1018
|
+
t.integer("cnt").defaultTo(0);
|
|
1019
|
+
bigint(t, "score_sum").defaultTo(0);
|
|
1020
|
+
addTimestamp(t);
|
|
1021
|
+
},
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
name: "ana_agg_event",
|
|
1025
|
+
build(t) {
|
|
1026
|
+
pk(t);
|
|
1027
|
+
t.string("app_id", 64).notNullable().index();
|
|
1028
|
+
bigint(t, "tenant_id").index();
|
|
1029
|
+
t.string("granularity", 8).notNullable().index();
|
|
1030
|
+
t.string("ts_key", 16).notNullable().index();
|
|
1031
|
+
t.string("event_code", 128).notNullable().index();
|
|
1032
|
+
t.integer("cnt").defaultTo(0);
|
|
1033
|
+
t.integer("uv").defaultTo(0);
|
|
1034
|
+
bigint(t, "value_sum").defaultTo(0);
|
|
1035
|
+
addTimestamp(t);
|
|
1036
|
+
},
|
|
1037
|
+
},
|
|
1038
|
+
{
|
|
1039
|
+
name: "ana_agg_page_day",
|
|
1040
|
+
build(t) {
|
|
1041
|
+
pk(t);
|
|
1042
|
+
t.string("app_id", 64).notNullable().index();
|
|
1043
|
+
bigint(t, "tenant_id").index();
|
|
1044
|
+
t.string("day", 10).notNullable().index();
|
|
1045
|
+
t.string("page_key", 255).notNullable().index();
|
|
1046
|
+
t.integer("pv").defaultTo(0);
|
|
1047
|
+
t.integer("uv").defaultTo(0);
|
|
1048
|
+
t.integer("entry_cnt").defaultTo(0);
|
|
1049
|
+
t.integer("exit_cnt").defaultTo(0);
|
|
1050
|
+
t.integer("avg_stay_ms").defaultTo(0);
|
|
1051
|
+
t.float("bounce_rate").defaultTo(0.0);
|
|
1052
|
+
addTimestamp(t);
|
|
1053
|
+
},
|
|
1054
|
+
},
|
|
1055
|
+
{
|
|
1056
|
+
name: "ana_heat_grid",
|
|
1057
|
+
build(t) {
|
|
1058
|
+
pk(t);
|
|
1059
|
+
t.string("app_id", 64).notNullable().index();
|
|
1060
|
+
bigint(t, "tenant_id").index();
|
|
1061
|
+
t.string("page_key", 255).notNullable().index();
|
|
1062
|
+
t.string("page_version", 64).index();
|
|
1063
|
+
t.string("kind", 16).notNullable().index();
|
|
1064
|
+
t.integer("grid_x").defaultTo(0);
|
|
1065
|
+
t.integer("grid_y").defaultTo(0);
|
|
1066
|
+
t.integer("cnt").defaultTo(0);
|
|
1067
|
+
addTimestamp(t);
|
|
1068
|
+
},
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
name: "ana_page_snapshot",
|
|
1072
|
+
build(t) {
|
|
1073
|
+
pk(t);
|
|
1074
|
+
t.string("app_id", 64).notNullable().index();
|
|
1075
|
+
bigint(t, "tenant_id").index();
|
|
1076
|
+
t.string("page_key", 255).notNullable().index();
|
|
1077
|
+
t.string("page_version", 64).index();
|
|
1078
|
+
t.string("url", 512);
|
|
1079
|
+
t.integer("width");
|
|
1080
|
+
t.integer("height");
|
|
1081
|
+
t.string("source", 16);
|
|
1082
|
+
t.dateTime("captured_at");
|
|
1083
|
+
addTimestamp(t);
|
|
1084
|
+
},
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
name: "ana_track_rule",
|
|
1088
|
+
build(t) {
|
|
1089
|
+
pk(t);
|
|
1090
|
+
t.string("app_id", 64).notNullable().index();
|
|
1091
|
+
bigint(t, "tenant_id").index();
|
|
1092
|
+
t.string("page_key", 255).index();
|
|
1093
|
+
t.string("elem_selector", 512).notNullable();
|
|
1094
|
+
t.string("elem_id", 255).notNullable();
|
|
1095
|
+
t.string("elem_type", 64);
|
|
1096
|
+
t.string("events", 64).defaultTo("click");
|
|
1097
|
+
t.integer("enabled").defaultTo(1);
|
|
1098
|
+
t.string("remark", 255);
|
|
1099
|
+
bigint(t, "created_by");
|
|
1100
|
+
addTimestamp(t);
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
name: "ana_gov_rule",
|
|
1105
|
+
build(t) {
|
|
1106
|
+
pk(t);
|
|
1107
|
+
bigint(t, "tenant_id").index();
|
|
1108
|
+
t.string("app_id", 64).index();
|
|
1109
|
+
t.string("rule_type", 16).notNullable().index();
|
|
1110
|
+
t.text("target");
|
|
1111
|
+
t.text("value");
|
|
1112
|
+
t.integer("priority").defaultTo(100);
|
|
1113
|
+
t.integer("enabled").defaultTo(1);
|
|
1114
|
+
t.string("remark", 255);
|
|
1115
|
+
bigint(t, "created_by");
|
|
1116
|
+
addTimestamp(t);
|
|
1117
|
+
},
|
|
1118
|
+
},
|
|
750
1119
|
];
|
|
751
1120
|
export async function createTables() {
|
|
752
1121
|
for (const spec of TABLES) {
|
|
@@ -757,9 +1126,87 @@ export async function createTables() {
|
|
|
757
1126
|
logger.info(`[schema] 建表 ${spec.name}`);
|
|
758
1127
|
}
|
|
759
1128
|
}
|
|
1129
|
+
function alterBigint(t, name) {
|
|
1130
|
+
return IS_SQLITE ? t.integer(name) : t.bigInteger(name);
|
|
1131
|
+
}
|
|
1132
|
+
const P0_PLAN = {
|
|
1133
|
+
studio_skill: [
|
|
1134
|
+
{
|
|
1135
|
+
name: "kind",
|
|
1136
|
+
build: (t) => t.string("kind", 16),
|
|
1137
|
+
defaultValue: "prompt",
|
|
1138
|
+
},
|
|
1139
|
+
{ name: "tool_key", build: (t) => t.string("tool_key", 100) },
|
|
1140
|
+
{ name: "input_schema", build: (t) => t.text("input_schema") },
|
|
1141
|
+
{ name: "output_kind", build: (t) => t.string("output_kind", 16) },
|
|
1142
|
+
{ name: "timeout", build: (t) => t.integer("timeout"), defaultValue: 60 },
|
|
1143
|
+
{
|
|
1144
|
+
name: "runtime",
|
|
1145
|
+
build: (t) => t.string("runtime", 20),
|
|
1146
|
+
defaultValue: "builtin",
|
|
1147
|
+
},
|
|
1148
|
+
],
|
|
1149
|
+
cms_article: [
|
|
1150
|
+
{
|
|
1151
|
+
name: "cover_material_id",
|
|
1152
|
+
build: (t) => alterBigint(t, "cover_material_id"),
|
|
1153
|
+
},
|
|
1154
|
+
],
|
|
1155
|
+
cms_video: [
|
|
1156
|
+
{
|
|
1157
|
+
name: "cover_material_id",
|
|
1158
|
+
build: (t) => alterBigint(t, "cover_material_id"),
|
|
1159
|
+
},
|
|
1160
|
+
],
|
|
1161
|
+
cms_photo: [
|
|
1162
|
+
{
|
|
1163
|
+
name: "view_count",
|
|
1164
|
+
build: (t) => t.integer("view_count").defaultTo(0),
|
|
1165
|
+
defaultValue: 0,
|
|
1166
|
+
},
|
|
1167
|
+
],
|
|
1168
|
+
};
|
|
1169
|
+
/** 给存量库补齐 P0 新列(幂等)。 */
|
|
1170
|
+
export async function ensureStudioP0Columns(opts = {}) {
|
|
1171
|
+
const added = [];
|
|
1172
|
+
const skipped = [];
|
|
1173
|
+
const pending = [];
|
|
1174
|
+
for (const [table, columns] of Object.entries(P0_PLAN)) {
|
|
1175
|
+
const exists = await knex.schema.hasTable(table);
|
|
1176
|
+
if (!exists) {
|
|
1177
|
+
skipped.push(`${table}(表不存在)`);
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
for (const col of columns) {
|
|
1181
|
+
const has = await knex.schema.hasColumn(table, col.name);
|
|
1182
|
+
if (has) {
|
|
1183
|
+
skipped.push(`${table}.${col.name}`);
|
|
1184
|
+
continue;
|
|
1185
|
+
}
|
|
1186
|
+
if (opts.dryRun) {
|
|
1187
|
+
pending.push(`${table}.${col.name}`);
|
|
1188
|
+
continue;
|
|
1189
|
+
}
|
|
1190
|
+
await knex.schema.alterTable(table, (t) => col.build(t));
|
|
1191
|
+
added.push(`${table}.${col.name}`);
|
|
1192
|
+
logger.info(`[schema] 已补列 ${table}.${col.name}`);
|
|
1193
|
+
if (col.defaultValue !== undefined) {
|
|
1194
|
+
await knex(table)
|
|
1195
|
+
.whereNull(col.name)
|
|
1196
|
+
.update({ [col.name]: col.defaultValue });
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
const result = { added, skipped };
|
|
1201
|
+
if (opts.dryRun)
|
|
1202
|
+
result.pending = pending;
|
|
1203
|
+
return result;
|
|
1204
|
+
}
|
|
760
1205
|
export async function autoInitDatabase() {
|
|
761
1206
|
try {
|
|
762
1207
|
await createTables();
|
|
1208
|
+
// 存量库补列(P0:技能可执行模型 / 封面素材引用),幂等
|
|
1209
|
+
await ensureStudioP0Columns();
|
|
763
1210
|
logger.info(`[schema] 数据库表初始化完成(${settings.DB_DRIVER})`);
|
|
764
1211
|
// 建表后写入种子数据(幂等)
|
|
765
1212
|
const { seedData } = await import("./init-data.js");
|