@reglow/reglow 0.13.0 → 0.14.1
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/README.md +101 -41
- package/dist/reglow/core/config.js +1 -1
- package/dist/reglow/core/entities.d.ts +135 -0
- package/dist/reglow/core/models.d.ts +22 -0
- package/dist/reglow/core/models.js +15 -0
- package/dist/reglow/core/models.js.map +1 -1
- package/dist/reglow/core/storage.js +6 -2
- package/dist/reglow/core/storage.js.map +1 -1
- package/dist/reglow/core/tenant_context.d.ts +45 -0
- package/dist/reglow/core/tenant_context.js +77 -0
- package/dist/reglow/core/tenant_context.js.map +1 -0
- package/dist/reglow/core/tenant_guard.js +17 -5
- package/dist/reglow/core/tenant_guard.js.map +1 -1
- package/dist/reglow/modules/ai/controller.js +129 -0
- package/dist/reglow/modules/ai/controller.js.map +1 -1
- package/dist/reglow/modules/ai_usage/controller.d.ts +8 -0
- package/dist/reglow/modules/ai_usage/controller.js +278 -0
- package/dist/reglow/modules/ai_usage/controller.js.map +1 -0
- package/dist/reglow/modules/ai_usage/model.d.ts +216 -0
- package/dist/reglow/modules/ai_usage/model.js +25 -0
- package/dist/reglow/modules/ai_usage/model.js.map +1 -0
- package/dist/reglow/modules/ai_usage/pricing.d.ts +80 -0
- package/dist/reglow/modules/ai_usage/pricing.js +276 -0
- package/dist/reglow/modules/ai_usage/pricing.js.map +1 -0
- package/dist/reglow/modules/ai_usage/reconcile.d.ts +34 -0
- package/dist/reglow/modules/ai_usage/reconcile.js +179 -0
- package/dist/reglow/modules/ai_usage/reconcile.js.map +1 -0
- package/dist/reglow/modules/ai_usage/recorder.d.ts +14 -0
- package/dist/reglow/modules/ai_usage/recorder.js +227 -0
- package/dist/reglow/modules/ai_usage/recorder.js.map +1 -0
- package/dist/reglow/modules/ai_usage/router.d.ts +10 -0
- package/dist/reglow/modules/ai_usage/router.js +10 -0
- package/dist/reglow/modules/ai_usage/router.js.map +1 -0
- package/dist/reglow/modules/ai_usage/schema.d.ts +152 -0
- package/dist/reglow/modules/ai_usage/schema.js +8 -0
- package/dist/reglow/modules/ai_usage/schema.js.map +1 -0
- package/dist/reglow/modules/ai_usage/service.d.ts +40 -0
- package/dist/reglow/modules/ai_usage/service.js +654 -0
- package/dist/reglow/modules/ai_usage/service.js.map +1 -0
- package/dist/reglow/modules/ai_usage/sync.d.ts +98 -0
- package/dist/reglow/modules/ai_usage/sync.js +954 -0
- package/dist/reglow/modules/ai_usage/sync.js.map +1 -0
- package/dist/reglow/modules/ai_usage/xlsx_io.d.ts +35 -0
- package/dist/reglow/modules/ai_usage/xlsx_io.js +494 -0
- package/dist/reglow/modules/ai_usage/xlsx_io.js.map +1 -0
- package/dist/reglow/modules/billing/controller.d.ts +6 -0
- package/dist/reglow/modules/billing/controller.js +112 -0
- package/dist/reglow/modules/billing/controller.js.map +1 -0
- package/dist/reglow/modules/billing/repository.d.ts +20 -0
- package/dist/reglow/modules/billing/repository.js +101 -0
- package/dist/reglow/modules/billing/repository.js.map +1 -0
- package/dist/reglow/modules/billing/router.d.ts +10 -0
- package/dist/reglow/modules/billing/router.js +8 -0
- package/dist/reglow/modules/billing/router.js.map +1 -0
- package/dist/reglow/modules/billing/schema.d.ts +38 -0
- package/dist/reglow/modules/billing/schema.js +42 -0
- package/dist/reglow/modules/billing/schema.js.map +1 -0
- package/dist/reglow/modules/billing/service.d.ts +22 -0
- package/dist/reglow/modules/billing/service.js +179 -0
- package/dist/reglow/modules/billing/service.js.map +1 -0
- package/dist/reglow/modules/customer_service/controller.js +81 -3
- package/dist/reglow/modules/customer_service/controller.js.map +1 -1
- package/dist/reglow/modules/customer_service/repository.d.ts +9 -1
- package/dist/reglow/modules/customer_service/repository.js +56 -2
- package/dist/reglow/modules/customer_service/repository.js.map +1 -1
- package/dist/reglow/modules/customer_service/schema.d.ts +2 -0
- package/dist/reglow/modules/customer_service/schema.js +8 -0
- package/dist/reglow/modules/customer_service/schema.js.map +1 -1
- package/dist/reglow/modules/customer_service/sdk_template.html +276 -5
- package/dist/reglow/modules/customer_service/service.d.ts +45 -4
- package/dist/reglow/modules/customer_service/service.js +352 -96
- package/dist/reglow/modules/customer_service/service.js.map +1 -1
- package/dist/reglow/modules/customer_service/ws.d.ts +8 -1
- package/dist/reglow/modules/customer_service/ws.js +38 -1
- package/dist/reglow/modules/customer_service/ws.js.map +1 -1
- package/dist/reglow/modules/open_api/auth.d.ts +28 -0
- package/dist/reglow/modules/open_api/auth.js +65 -0
- package/dist/reglow/modules/open_api/auth.js.map +1 -0
- package/dist/reglow/modules/open_api/controller.d.ts +8 -0
- package/dist/reglow/modules/open_api/controller.js +109 -0
- package/dist/reglow/modules/open_api/controller.js.map +1 -0
- package/dist/reglow/modules/open_api/repository.d.ts +20 -0
- package/dist/reglow/modules/open_api/repository.js +111 -0
- package/dist/reglow/modules/open_api/repository.js.map +1 -0
- package/dist/reglow/modules/open_api/router.d.ts +10 -0
- package/dist/reglow/modules/open_api/router.js +8 -0
- package/dist/reglow/modules/open_api/router.js.map +1 -0
- package/dist/reglow/modules/open_api/schema.d.ts +24 -0
- package/dist/reglow/modules/open_api/schema.js +26 -0
- package/dist/reglow/modules/open_api/schema.js.map +1 -0
- package/dist/reglow/modules/open_api/security.d.ts +19 -0
- package/dist/reglow/modules/open_api/security.js +53 -0
- package/dist/reglow/modules/open_api/security.js.map +1 -0
- package/dist/reglow/modules/open_api/service.d.ts +28 -0
- package/dist/reglow/modules/open_api/service.js +158 -0
- package/dist/reglow/modules/open_api/service.js.map +1 -0
- package/dist/reglow/modules/principal/controller.d.ts +6 -0
- package/dist/reglow/modules/principal/controller.js +158 -0
- package/dist/reglow/modules/principal/controller.js.map +1 -0
- package/dist/reglow/modules/principal/repository.d.ts +20 -0
- package/dist/reglow/modules/principal/repository.js +76 -0
- package/dist/reglow/modules/principal/repository.js.map +1 -0
- package/dist/reglow/modules/principal/router.d.ts +9 -0
- package/dist/reglow/modules/principal/router.js +7 -0
- package/dist/reglow/modules/principal/router.js.map +1 -0
- package/dist/reglow/modules/principal/schema.d.ts +81 -0
- package/dist/reglow/modules/principal/schema.js +85 -0
- package/dist/reglow/modules/principal/schema.js.map +1 -0
- package/dist/reglow/modules/principal/service.d.ts +21 -0
- package/dist/reglow/modules/principal/service.js +193 -0
- package/dist/reglow/modules/principal/service.js.map +1 -0
- package/dist/reglow/modules/principal_member/controller.d.ts +6 -0
- package/dist/reglow/modules/principal_member/controller.js +64 -0
- package/dist/reglow/modules/principal_member/controller.js.map +1 -0
- package/dist/reglow/modules/principal_member/repository.d.ts +13 -0
- package/dist/reglow/modules/principal_member/repository.js +80 -0
- package/dist/reglow/modules/principal_member/repository.js.map +1 -0
- package/dist/reglow/modules/principal_member/router.d.ts +10 -0
- package/dist/reglow/modules/principal_member/router.js +8 -0
- package/dist/reglow/modules/principal_member/router.js.map +1 -0
- package/dist/reglow/modules/principal_member/schema.d.ts +27 -0
- package/dist/reglow/modules/principal_member/schema.js +28 -0
- package/dist/reglow/modules/principal_member/schema.js.map +1 -0
- package/dist/reglow/modules/principal_member/service.d.ts +16 -0
- package/dist/reglow/modules/principal_member/service.js +135 -0
- package/dist/reglow/modules/principal_member/service.js.map +1 -0
- package/dist/reglow/modules/studio/mcp/client.js +2 -2
- package/dist/reglow/modules/tenant/controller.d.ts +6 -0
- package/dist/reglow/modules/tenant/controller.js +99 -0
- package/dist/reglow/modules/tenant/controller.js.map +1 -0
- package/dist/reglow/modules/tenant/repository.d.ts +18 -0
- package/dist/reglow/modules/tenant/repository.js +71 -0
- package/dist/reglow/modules/tenant/repository.js.map +1 -0
- package/dist/reglow/modules/tenant/router.d.ts +9 -0
- package/dist/reglow/modules/tenant/router.js +7 -0
- package/dist/reglow/modules/tenant/router.js.map +1 -0
- package/dist/reglow/modules/tenant/schema.d.ts +33 -0
- package/dist/reglow/modules/tenant/schema.js +42 -0
- package/dist/reglow/modules/tenant/schema.js.map +1 -0
- package/dist/reglow/modules/tenant/service.d.ts +16 -0
- package/dist/reglow/modules/tenant/service.js +75 -0
- package/dist/reglow/modules/tenant/service.js.map +1 -0
- package/dist/reglow/modules/workflow/controller.d.ts +7 -0
- package/dist/reglow/modules/workflow/controller.js +133 -0
- package/dist/reglow/modules/workflow/controller.js.map +1 -0
- package/dist/reglow/modules/workflow/dsl.d.ts +41 -0
- package/dist/reglow/modules/workflow/dsl.js +173 -0
- package/dist/reglow/modules/workflow/dsl.js.map +1 -0
- package/dist/reglow/modules/workflow/model.d.ts +15 -0
- package/dist/reglow/modules/workflow/model.js +16 -0
- package/dist/reglow/modules/workflow/model.js.map +1 -0
- package/dist/reglow/modules/workflow/repository.d.ts +27 -0
- package/dist/reglow/modules/workflow/repository.js +151 -0
- package/dist/reglow/modules/workflow/repository.js.map +1 -0
- package/dist/reglow/modules/workflow/router.d.ts +10 -0
- package/dist/reglow/modules/workflow/router.js +8 -0
- package/dist/reglow/modules/workflow/router.js.map +1 -0
- package/dist/reglow/modules/workflow/schema.d.ts +32 -0
- package/dist/reglow/modules/workflow/schema.js +39 -0
- package/dist/reglow/modules/workflow/schema.js.map +1 -0
- package/dist/reglow/modules/workflow/service.d.ts +65 -0
- package/dist/reglow/modules/workflow/service.js +209 -0
- package/dist/reglow/modules/workflow/service.js.map +1 -0
- package/dist/reglow/scripts/init-data.js +157 -1
- package/dist/reglow/scripts/init-data.js.map +1 -1
- package/dist/reglow/scripts/schema.js +360 -0
- package/dist/reglow/scripts/schema.js.map +1 -1
- package/dist/server.js +3 -0
- package/dist/server.js.map +1 -1
- package/package.json +21 -21
|
@@ -696,6 +696,7 @@ const TABLES = [
|
|
|
696
696
|
t.integer("enabled").defaultTo(1);
|
|
697
697
|
t.string("status", 20).defaultTo("offline");
|
|
698
698
|
t.dateTime("last_active_at");
|
|
699
|
+
t.integer("max_sessions");
|
|
699
700
|
addTimestamp(t);
|
|
700
701
|
addSoftDelete(t);
|
|
701
702
|
},
|
|
@@ -1197,6 +1198,359 @@ const TABLES = [
|
|
|
1197
1198
|
addTimestamp(t);
|
|
1198
1199
|
},
|
|
1199
1200
|
},
|
|
1201
|
+
// ─────────────────────────── sys_ai_* AI 用量统计表 ───────────────────────────
|
|
1202
|
+
// 对齐 Python reglow/modules/ai_usage/model.py(3 张)。
|
|
1203
|
+
// 存量库补表沿用 createTables 的 hasTable 幂等机制(等价 CREATE TABLE IF NOT EXISTS)。
|
|
1204
|
+
{
|
|
1205
|
+
name: "sys_ai_usage",
|
|
1206
|
+
build(t) {
|
|
1207
|
+
pk(t);
|
|
1208
|
+
bigint(t, "tenant_id");
|
|
1209
|
+
t.string("request_id", 64).notNullable().unique();
|
|
1210
|
+
t.string("parent_request_id", 64);
|
|
1211
|
+
t.integer("attempt_no").defaultTo(1);
|
|
1212
|
+
t.integer("upstream_calls").defaultTo(1);
|
|
1213
|
+
t.string("provider", 32).notNullable();
|
|
1214
|
+
t.string("model", 128).notNullable();
|
|
1215
|
+
t.string("model_type", 20).defaultTo("t2t");
|
|
1216
|
+
t.string("billing_unit", 16).defaultTo("token");
|
|
1217
|
+
t.string("pricing_mode", 20);
|
|
1218
|
+
t.string("variant", 64);
|
|
1219
|
+
t.string("variant_raw", 64);
|
|
1220
|
+
t.string("resolution", 32);
|
|
1221
|
+
t.string("scene", 32).notNullable();
|
|
1222
|
+
t.string("source", 20).defaultTo("admin");
|
|
1223
|
+
bigint(t, "employee_id");
|
|
1224
|
+
bigint(t, "dept_id");
|
|
1225
|
+
bigint(t, "user_id");
|
|
1226
|
+
t.string("app_id", 64);
|
|
1227
|
+
t.string("session_id", 64);
|
|
1228
|
+
bigint(t, "run_id");
|
|
1229
|
+
bigint(t, "workflow_id");
|
|
1230
|
+
t.string("step_key", 64);
|
|
1231
|
+
t.string("external_task_id", 128);
|
|
1232
|
+
t.string("provider_request_id", 128);
|
|
1233
|
+
t.boolean("is_stream").defaultTo(false);
|
|
1234
|
+
t.string("status", 20).defaultTo("success");
|
|
1235
|
+
t.integer("http_status");
|
|
1236
|
+
t.string("error_code", 64);
|
|
1237
|
+
t.string("error_category", 32);
|
|
1238
|
+
t.string("error_message", 512);
|
|
1239
|
+
t.integer("latency_ms");
|
|
1240
|
+
t.integer("first_token_ms");
|
|
1241
|
+
t.integer("request_count").defaultTo(1);
|
|
1242
|
+
t.integer("prompt_tokens").defaultTo(0);
|
|
1243
|
+
t.integer("completion_tokens").defaultTo(0);
|
|
1244
|
+
t.integer("cached_tokens").defaultTo(0);
|
|
1245
|
+
t.integer("cache_write_tokens").defaultTo(0);
|
|
1246
|
+
t.integer("reasoning_tokens").defaultTo(0);
|
|
1247
|
+
t.integer("total_tokens").defaultTo(0);
|
|
1248
|
+
t.integer("quantity").defaultTo(0);
|
|
1249
|
+
t.integer("requested_quantity").defaultTo(0);
|
|
1250
|
+
t.integer("actual_quantity").defaultTo(0);
|
|
1251
|
+
t.decimal("duration_seconds", 10, 2).defaultTo(0);
|
|
1252
|
+
t.decimal("requested_duration", 10, 2).defaultTo(0);
|
|
1253
|
+
t.decimal("actual_duration", 10, 2).defaultTo(0);
|
|
1254
|
+
t.string("duration_source", 16);
|
|
1255
|
+
t.integer("video_tokens").defaultTo(0);
|
|
1256
|
+
t.decimal("billing_quantity", 18, 6).defaultTo(0);
|
|
1257
|
+
t.string("usage_source", 16).defaultTo("provider");
|
|
1258
|
+
t.decimal("input_price", 18, 8).defaultTo(0);
|
|
1259
|
+
t.decimal("output_price", 18, 8).defaultTo(0);
|
|
1260
|
+
t.decimal("cached_input_price", 18, 8).defaultTo(0);
|
|
1261
|
+
t.decimal("unit_price", 18, 8).defaultTo(0);
|
|
1262
|
+
t.decimal("cost_amount", 18, 8).defaultTo(0);
|
|
1263
|
+
t.decimal("sale_amount", 18, 8);
|
|
1264
|
+
t.string("currency", 8).defaultTo("CNY");
|
|
1265
|
+
t.string("price_currency", 8);
|
|
1266
|
+
t.decimal("fx_rate", 18, 8);
|
|
1267
|
+
t.string("fx_date", 10);
|
|
1268
|
+
t.string("pricing_status", 16).defaultTo("missing");
|
|
1269
|
+
t.string("price_source", 16);
|
|
1270
|
+
bigint(t, "price_id");
|
|
1271
|
+
t.string("billable", 16).defaultTo("unknown");
|
|
1272
|
+
t.dateTime("submitted_at");
|
|
1273
|
+
t.dateTime("completed_at");
|
|
1274
|
+
t.dateTime("next_poll_at");
|
|
1275
|
+
t.integer("poll_count").defaultTo(0);
|
|
1276
|
+
jsonCol(t, "raw_usage");
|
|
1277
|
+
jsonCol(t, "meta");
|
|
1278
|
+
t.string("day", 10).notNullable();
|
|
1279
|
+
addTimestamp(t);
|
|
1280
|
+
t.index(["tenant_id", "created_at"], "idx_ai_usage_tenant_created");
|
|
1281
|
+
t.index(["employee_id", "created_at"], "idx_ai_usage_employee_created");
|
|
1282
|
+
t.index(["provider", "model", "created_at"], "idx_ai_usage_provider_model_created");
|
|
1283
|
+
t.index(["scene", "created_at"], "idx_ai_usage_scene_created");
|
|
1284
|
+
t.index(["day", "provider"], "idx_ai_usage_day_provider");
|
|
1285
|
+
t.index(["day", "employee_id"], "idx_ai_usage_day_employee");
|
|
1286
|
+
t.index(["status", "next_poll_at"], "idx_ai_usage_status_next_poll");
|
|
1287
|
+
t.index(["session_id"], "idx_ai_usage_session");
|
|
1288
|
+
t.index(["run_id"], "idx_ai_usage_run");
|
|
1289
|
+
t.unique(["provider", "external_task_id"], {
|
|
1290
|
+
indexName: "uq_ai_usage_provider_task",
|
|
1291
|
+
});
|
|
1292
|
+
},
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
name: "sys_ai_model_price",
|
|
1296
|
+
build(t) {
|
|
1297
|
+
pk(t);
|
|
1298
|
+
t.string("provider", 32).notNullable();
|
|
1299
|
+
t.string("model", 128).notNullable();
|
|
1300
|
+
t.string("model_type", 20).defaultTo("t2t");
|
|
1301
|
+
t.string("billing_unit", 16).defaultTo("token");
|
|
1302
|
+
t.string("pricing_mode", 20).defaultTo("per_token");
|
|
1303
|
+
t.decimal("unit_size", 18, 6).defaultTo(1);
|
|
1304
|
+
jsonCol(t, "tier_rule");
|
|
1305
|
+
t.string("rounding", 8).defaultTo("exact");
|
|
1306
|
+
t.string("variant", 64).notNullable().defaultTo("");
|
|
1307
|
+
t.string("currency", 8).defaultTo("CNY");
|
|
1308
|
+
t.decimal("cost_input_per_1m", 18, 8).defaultTo(0);
|
|
1309
|
+
t.decimal("cost_output_per_1m", 18, 8).defaultTo(0);
|
|
1310
|
+
t.decimal("cost_cached_input_per_1m", 18, 8);
|
|
1311
|
+
t.decimal("cost_unit_price", 18, 8).defaultTo(0);
|
|
1312
|
+
t.decimal("sale_input_per_1m", 18, 8);
|
|
1313
|
+
t.decimal("sale_output_per_1m", 18, 8);
|
|
1314
|
+
t.decimal("sale_unit_price", 18, 8);
|
|
1315
|
+
t.string("source", 16).defaultTo("manual");
|
|
1316
|
+
t.string("source_url", 512);
|
|
1317
|
+
t.dateTime("synced_at");
|
|
1318
|
+
t.dateTime("effective_from").notNullable();
|
|
1319
|
+
t.dateTime("effective_to");
|
|
1320
|
+
t.string("checksum", 64);
|
|
1321
|
+
t.smallint("status").defaultTo(1);
|
|
1322
|
+
t.string("remark", 255);
|
|
1323
|
+
addTimestamp(t);
|
|
1324
|
+
t.index([
|
|
1325
|
+
"provider",
|
|
1326
|
+
"model",
|
|
1327
|
+
"model_type",
|
|
1328
|
+
"billing_unit",
|
|
1329
|
+
"pricing_mode",
|
|
1330
|
+
"variant",
|
|
1331
|
+
"effective_from",
|
|
1332
|
+
], "idx_ai_price_lookup");
|
|
1333
|
+
t.unique([
|
|
1334
|
+
"provider",
|
|
1335
|
+
"model",
|
|
1336
|
+
"model_type",
|
|
1337
|
+
"billing_unit",
|
|
1338
|
+
"pricing_mode",
|
|
1339
|
+
"variant",
|
|
1340
|
+
"effective_from",
|
|
1341
|
+
], { indexName: "uq_ai_price_version" });
|
|
1342
|
+
},
|
|
1343
|
+
},
|
|
1344
|
+
{
|
|
1345
|
+
name: "sys_ai_price_sync_log",
|
|
1346
|
+
build(t) {
|
|
1347
|
+
pk(t);
|
|
1348
|
+
t.string("provider", 32).notNullable();
|
|
1349
|
+
t.string("job_id", 64);
|
|
1350
|
+
t.dateTime("started_at");
|
|
1351
|
+
t.dateTime("finished_at");
|
|
1352
|
+
t.string("status", 16).defaultTo("running");
|
|
1353
|
+
t.integer("changed_count").defaultTo(0);
|
|
1354
|
+
t.text("error");
|
|
1355
|
+
addTimestamp(t);
|
|
1356
|
+
},
|
|
1357
|
+
},
|
|
1358
|
+
// ─────────────── 主体认证 / 主体成员 / 多租户(对齐 Python modules) ───────────────
|
|
1359
|
+
{
|
|
1360
|
+
name: "sys_principal",
|
|
1361
|
+
build(t) {
|
|
1362
|
+
pk(t);
|
|
1363
|
+
t.string("principal_type", 32).notNullable().defaultTo("enterprise");
|
|
1364
|
+
t.string("name", 100).notNullable();
|
|
1365
|
+
t.string("code", 64).notNullable().unique();
|
|
1366
|
+
t.string("contact_name", 50);
|
|
1367
|
+
t.string("contact_phone", 20);
|
|
1368
|
+
t.string("contact_email", 128);
|
|
1369
|
+
t.string("cert_type", 32);
|
|
1370
|
+
t.string("cert_status", 20).defaultTo("unverified");
|
|
1371
|
+
t.string("reject_reason", 255);
|
|
1372
|
+
t.string("credit_code", 64);
|
|
1373
|
+
t.string("legal_person", 50);
|
|
1374
|
+
t.string("residence", 255);
|
|
1375
|
+
t.string("business_address", 255);
|
|
1376
|
+
t.string("license_url", 512);
|
|
1377
|
+
t.text("business_permit_urls");
|
|
1378
|
+
t.string("id_card_no", 32);
|
|
1379
|
+
t.string("legal_id_front_url", 512);
|
|
1380
|
+
t.string("legal_id_back_url", 512);
|
|
1381
|
+
t.string("account_name", 100);
|
|
1382
|
+
t.string("settlement_type", 20);
|
|
1383
|
+
t.string("receipt_mode", 20);
|
|
1384
|
+
t.string("bank_name", 100);
|
|
1385
|
+
t.string("bank_branch", 100);
|
|
1386
|
+
t.string("bank_card_no", 64);
|
|
1387
|
+
t.string("bank_card_front_url", 512);
|
|
1388
|
+
t.string("corporate_account_doc_url", 512);
|
|
1389
|
+
bigint(t, "reviewer_id");
|
|
1390
|
+
t.dateTime("reviewed_at");
|
|
1391
|
+
t.string("remark", 255);
|
|
1392
|
+
t.smallint("status").defaultTo(1);
|
|
1393
|
+
addTimestamp(t);
|
|
1394
|
+
addSoftDelete(t);
|
|
1395
|
+
},
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
name: "sys_principal_member",
|
|
1399
|
+
build(t) {
|
|
1400
|
+
pk(t);
|
|
1401
|
+
bigint(t, "principal_id").notNullable().index();
|
|
1402
|
+
bigint(t, "user_id");
|
|
1403
|
+
bigint(t, "employee_id");
|
|
1404
|
+
t.string("member_role", 20).notNullable().defaultTo("staff");
|
|
1405
|
+
t.string("status", 20).defaultTo("active");
|
|
1406
|
+
bigint(t, "invited_by");
|
|
1407
|
+
t.dateTime("joined_at");
|
|
1408
|
+
addTimestamp(t);
|
|
1409
|
+
addSoftDelete(t);
|
|
1410
|
+
t.check("(user_id IS NOT NULL AND employee_id IS NULL) OR (user_id IS NULL AND employee_id IS NOT NULL)", {}, "ck_principal_member_dual_track");
|
|
1411
|
+
t.unique(["principal_id", "user_id"], {
|
|
1412
|
+
indexName: "uq_principal_member_user",
|
|
1413
|
+
});
|
|
1414
|
+
t.unique(["principal_id", "employee_id"], {
|
|
1415
|
+
indexName: "uq_principal_member_employee",
|
|
1416
|
+
});
|
|
1417
|
+
},
|
|
1418
|
+
},
|
|
1419
|
+
{
|
|
1420
|
+
name: "sys_tenant",
|
|
1421
|
+
build(t) {
|
|
1422
|
+
pk(t);
|
|
1423
|
+
t.string("name", 100).notNullable();
|
|
1424
|
+
t.string("code", 64).notNullable().unique();
|
|
1425
|
+
bigint(t, "principal_id").index();
|
|
1426
|
+
t.string("package", 50).defaultTo("free");
|
|
1427
|
+
t.smallint("status").defaultTo(1);
|
|
1428
|
+
t.string("contact_name", 50);
|
|
1429
|
+
t.string("contact_phone", 20);
|
|
1430
|
+
t.dateTime("expire_at");
|
|
1431
|
+
t.string("remark", 255);
|
|
1432
|
+
t.integer("max_apps").defaultTo(1);
|
|
1433
|
+
addTimestamp(t);
|
|
1434
|
+
addSoftDelete(t);
|
|
1435
|
+
},
|
|
1436
|
+
},
|
|
1437
|
+
// ─────────────── 计量计费 / 开放平台(对齐 Python modules) ───────────────
|
|
1438
|
+
{
|
|
1439
|
+
name: "sys_billing_plan",
|
|
1440
|
+
build(t) {
|
|
1441
|
+
pk(t);
|
|
1442
|
+
t.string("code", 64).notNullable().unique();
|
|
1443
|
+
t.string("name", 100).notNullable();
|
|
1444
|
+
t.string("plan_type", 20).defaultTo("free");
|
|
1445
|
+
t.decimal("price", 10, 2).defaultTo(0);
|
|
1446
|
+
jsonCol(t, "quota_json");
|
|
1447
|
+
t.smallint("status").defaultTo(1);
|
|
1448
|
+
t.string("remark", 255);
|
|
1449
|
+
addTimestamp(t);
|
|
1450
|
+
addSoftDelete(t);
|
|
1451
|
+
},
|
|
1452
|
+
},
|
|
1453
|
+
{
|
|
1454
|
+
name: "sys_billing_account",
|
|
1455
|
+
build(t) {
|
|
1456
|
+
pk(t);
|
|
1457
|
+
t.string("owner_type", 20).defaultTo("tenant");
|
|
1458
|
+
bigint(t, "owner_id").index();
|
|
1459
|
+
t.string("plan_code", 64).defaultTo("free");
|
|
1460
|
+
t.decimal("balance", 14, 4).defaultTo(0);
|
|
1461
|
+
t.dateTime("expire_at");
|
|
1462
|
+
addTimestamp(t);
|
|
1463
|
+
addSoftDelete(t);
|
|
1464
|
+
},
|
|
1465
|
+
},
|
|
1466
|
+
{
|
|
1467
|
+
name: "sys_billing_usage",
|
|
1468
|
+
build(t) {
|
|
1469
|
+
pk(t);
|
|
1470
|
+
bigint(t, "account_id").index();
|
|
1471
|
+
t.string("item_type", 32).defaultTo("tokens");
|
|
1472
|
+
t.string("model", 64);
|
|
1473
|
+
bigint(t, "tokens").defaultTo(0);
|
|
1474
|
+
bigint(t, "quantity").defaultTo(1);
|
|
1475
|
+
t.text("remark");
|
|
1476
|
+
addTimestamp(t);
|
|
1477
|
+
},
|
|
1478
|
+
},
|
|
1479
|
+
{
|
|
1480
|
+
name: "sys_open_api_app",
|
|
1481
|
+
build(t) {
|
|
1482
|
+
pk(t);
|
|
1483
|
+
t.string("app_key", 64).notNullable().unique();
|
|
1484
|
+
t.string("app_secret", 128).notNullable();
|
|
1485
|
+
t.string("name", 100).notNullable();
|
|
1486
|
+
t.smallint("status").defaultTo(1);
|
|
1487
|
+
t.integer("daily_quota").defaultTo(10000);
|
|
1488
|
+
t.integer("rate_limit").defaultTo(60);
|
|
1489
|
+
t.dateTime("expire_at");
|
|
1490
|
+
t.string("remark", 255);
|
|
1491
|
+
addTimestamp(t);
|
|
1492
|
+
addSoftDelete(t);
|
|
1493
|
+
},
|
|
1494
|
+
},
|
|
1495
|
+
{
|
|
1496
|
+
name: "sys_open_api_log",
|
|
1497
|
+
build(t) {
|
|
1498
|
+
pk(t);
|
|
1499
|
+
bigint(t, "app_id").index();
|
|
1500
|
+
t.string("app_key", 64).index();
|
|
1501
|
+
t.string("method", 10);
|
|
1502
|
+
t.string("path", 255);
|
|
1503
|
+
t.string("ip", 64);
|
|
1504
|
+
t.integer("status_code");
|
|
1505
|
+
t.smallint("success").defaultTo(1);
|
|
1506
|
+
t.text("error");
|
|
1507
|
+
addTimestamp(t);
|
|
1508
|
+
},
|
|
1509
|
+
},
|
|
1510
|
+
// ─────────────── 流程审批(对齐 Python modules/workflow) ───────────────
|
|
1511
|
+
{
|
|
1512
|
+
name: "sys_workflow_def",
|
|
1513
|
+
build(t) {
|
|
1514
|
+
pk(t);
|
|
1515
|
+
t.string("code", 64).notNullable().unique();
|
|
1516
|
+
t.string("name", 100).notNullable();
|
|
1517
|
+
t.string("description", 255);
|
|
1518
|
+
jsonCol(t, "form_schema");
|
|
1519
|
+
jsonCol(t, "node_json");
|
|
1520
|
+
t.smallint("status").defaultTo(1);
|
|
1521
|
+
addTimestamp(t);
|
|
1522
|
+
addSoftDelete(t);
|
|
1523
|
+
},
|
|
1524
|
+
},
|
|
1525
|
+
{
|
|
1526
|
+
name: "sys_workflow_instance",
|
|
1527
|
+
build(t) {
|
|
1528
|
+
pk(t);
|
|
1529
|
+
bigint(t, "def_id").notNullable().index();
|
|
1530
|
+
t.string("title", 200).notNullable();
|
|
1531
|
+
t.string("status", 20).defaultTo("running");
|
|
1532
|
+
t.string("current_node", 64);
|
|
1533
|
+
jsonCol(t, "form_data");
|
|
1534
|
+
bigint(t, "creator_id");
|
|
1535
|
+
addTimestamp(t);
|
|
1536
|
+
addSoftDelete(t);
|
|
1537
|
+
},
|
|
1538
|
+
},
|
|
1539
|
+
{
|
|
1540
|
+
name: "sys_workflow_task",
|
|
1541
|
+
build(t) {
|
|
1542
|
+
pk(t);
|
|
1543
|
+
bigint(t, "instance_id").notNullable().index();
|
|
1544
|
+
t.string("node_key", 64).notNullable();
|
|
1545
|
+
t.string("node_name", 100);
|
|
1546
|
+
t.string("assignee_type", 20).defaultTo("role");
|
|
1547
|
+
t.string("assignee_value", 64);
|
|
1548
|
+
t.string("action", 20).defaultTo("pending");
|
|
1549
|
+
t.text("comment");
|
|
1550
|
+
bigint(t, "operator_id");
|
|
1551
|
+
addTimestamp(t);
|
|
1552
|
+
},
|
|
1553
|
+
},
|
|
1200
1554
|
];
|
|
1201
1555
|
export async function createTables() {
|
|
1202
1556
|
for (const spec of TABLES) {
|
|
@@ -1246,6 +1600,12 @@ const P0_PLAN = {
|
|
|
1246
1600
|
defaultValue: 0,
|
|
1247
1601
|
},
|
|
1248
1602
|
],
|
|
1603
|
+
cs_agent: [
|
|
1604
|
+
{
|
|
1605
|
+
name: "max_sessions",
|
|
1606
|
+
build: (t) => t.integer("max_sessions"),
|
|
1607
|
+
},
|
|
1608
|
+
],
|
|
1249
1609
|
};
|
|
1250
1610
|
/** 给存量库补齐 P0 新列(幂等)。 */
|
|
1251
1611
|
export async function ensureStudioP0Columns(opts = {}) {
|