diff --git a/mysql.ddl.sql b/mysql.ddl.sql new file mode 100644 index 0000000..5a337b8 --- /dev/null +++ b/mysql.ddl.sql @@ -0,0 +1,115 @@ + +-- models/pipeline_versions.json + + + + + +-- 建库时请用以下语句,支持emoji字符 +-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +drop table if exists pipeline_versions; +CREATE TABLE pipeline_versions +( + + `id` VARCHAR(32) NOT NULL comment 'id', + `pipeline_id` VARCHAR(32) NOT NULL comment '产线ID', + `version` VARCHAR(20) NOT NULL comment '版本号', + `publish_status` VARCHAR(20) NOT NULL DEFAULT 'pending' comment '发布状态', + `published_by` VARCHAR(32) comment '发布人', + `published_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '发布时间', + `changelog` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '变更说明', + `config_snapshot` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '配置快照JSON', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间' + + +,primary key(id) + + +) +CHARACTER SET utf8mb4 +COLLATE utf8mb4_unicode_ci +engine=innodb +comment '产线发布记录表' +; + +CREATE INDEX pipeline_versions_idx_versions_pipeline ON pipeline_versions(pipeline_id); + +-- models/pipelines.json + + + + + +-- 建库时请用以下语句,支持emoji字符 +-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +drop table if exists pipelines; +CREATE TABLE pipelines +( + + `id` VARCHAR(32) NOT NULL comment 'id', + `name` VARCHAR(200) NOT NULL comment '产线名称', + `description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '产线描述', + `pipeline_type` VARCHAR(50) NOT NULL comment '产线类型', + `version` VARCHAR(20) DEFAULT '1.0.0' comment '当前版本', + `status` VARCHAR(20) NOT NULL DEFAULT 'draft' comment '状态', + `pipeline_config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '产线配置JSON', + `model_api_url` VARCHAR(500) comment '模型API地址', + `model_api_key` VARCHAR(500) comment '模型API密钥', + `org_id` VARCHAR(32) DEFAULT '0' comment '所属机构ID', + `created_by` VARCHAR(32) comment '创建人', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间', + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新时间' + + +,primary key(id) + + +) +CHARACTER SET utf8mb4 +COLLATE utf8mb4_unicode_ci +engine=innodb +comment '产线定义表' +; + +CREATE INDEX pipelines_idx_pipelines_name ON pipelines(name); +CREATE INDEX pipelines_idx_pipelines_status ON pipelines(status); + +-- models/pipeline_steps.json + + + + + +-- 建库时请用以下语句,支持emoji字符 +-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +drop table if exists pipeline_steps; +CREATE TABLE pipeline_steps +( + + `id` VARCHAR(32) NOT NULL comment 'id', + `pipeline_id` VARCHAR(32) NOT NULL comment '所属产线', + `step_order` int NOT NULL comment '步骤序号', + `step_name` VARCHAR(100) NOT NULL comment '步骤名称', + `step_type` VARCHAR(50) NOT NULL comment '步骤类型', + `model_name` VARCHAR(100) comment '调用模型名称', + `step_config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '步骤配置JSON', + `input_schema` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '输入定义JSON', + `output_schema` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '输出定义JSON', + `timeout_seconds` int DEFAULT '300' comment '超时秒数', + `retry_count` int DEFAULT '0' comment '重试次数', + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间' + + +,primary key(id) + + +) +CHARACTER SET utf8mb4 +COLLATE utf8mb4_unicode_ci +engine=innodb +comment '产线步骤表' +; + +CREATE INDEX pipeline_steps_idx_steps_pipeline ON pipeline_steps(pipeline_id); +CREATE UNIQUE INDEX pipeline_steps_idx_steps_order ON pipeline_steps(pipeline_id,step_order); + diff --git a/pyproject.toml b/pyproject.toml index 8654564..a80fdb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,9 @@ [project] name = "pipeline_core" version = "0.1.0" -description = "产线管理核心模块 - 产线定义、步骤配置与发布管理" -dependencies = [ - "sqlor", - "bricks_for_python", -] +description = "产线管理核心模块" +dependencies = ["sqlor", "bricks_for_python"] + +[tool.setuptools.packages.find] +where = ["."] +include = ["pipeline_core*"] diff --git a/wwwroot/pipeline_steps/add_pipeline_steps.dspy b/wwwroot/pipeline_steps/add_pipeline_steps.dspy new file mode 100644 index 0000000..098b2fc --- /dev/null +++ b/wwwroot/pipeline_steps/add_pipeline_steps.dspy @@ -0,0 +1,37 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('pipeline_steps', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipeline_steps/delete_pipeline_steps.dspy b/wwwroot/pipeline_steps/delete_pipeline_steps.dspy new file mode 100644 index 0000000..d659f20 --- /dev/null +++ b/wwwroot/pipeline_steps/delete_pipeline_steps.dspy @@ -0,0 +1,33 @@ + +ns = { + 'id':params_kw['id'], +} + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('pipeline_steps', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipeline_steps/get_pipeline_steps.dspy b/wwwroot/pipeline_steps/get_pipeline_steps.dspy new file mode 100644 index 0000000..48c6209 --- /dev/null +++ b/wwwroot/pipeline_steps/get_pipeline_steps.dspy @@ -0,0 +1,130 @@ + +ns = params_kw.copy() + + +debug(f'get_pipeline_steps.dspy:{ns=}') +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'step_order' + + + +sql = '''select a.*, b.pipeline_id_text +from (select * from pipeline_steps where 1=1 [[filterstr]]) a left join (select id as pipeline_id, + name as pipeline_id_text from pipelines where 1 = 1) b on a.pipeline_id = b.pipeline_id''' + +filterjson = params_kw.get('data_filter') +if filterjson and isinstance(filterjson, str): + try: + filterjson = json.loads(filterjson) + except (json.JSONDecodeError, TypeError): + filterjson = None +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "pipeline_id", + "title": "所属产线", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "step_order", + "title": "步骤序号", + "type": "int", + "nullable": "no" + }, + { + "name": "step_name", + "title": "步骤名称", + "type": "str", + "length": 100, + "nullable": "no" + }, + { + "name": "step_type", + "title": "步骤类型", + "type": "str", + "length": 50, + "nullable": "no" + }, + { + "name": "model_name", + "title": "调用模型名称", + "type": "str", + "length": 100 + }, + { + "name": "step_config", + "title": "步骤配置JSON", + "type": "text" + }, + { + "name": "input_schema", + "title": "输入定义JSON", + "type": "text" + }, + { + "name": "output_schema", + "title": "输出定义JSON", + "type": "text" + }, + { + "name": "timeout_seconds", + "title": "超时秒数", + "type": "int", + "default": "300" + }, + { + "name": "retry_count", + "title": "重试次数", + "type": "int", + "default": "0" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + filterjson = default_filterjson(fields, ns) + +filterdic = ns.copy() +filterdic['filterstr'] = '' +filterdic['userorgid'] = '${userorgid}$' +filterdic['userid'] = '${userid}$' +if filterjson: + dbf = DBFilter(filterjson) + conds = dbf.gen(ns) + if conds: + ns.update(dbf.consts) + conds = f' and {conds}' + filterdic['filterstr'] = conds +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' } +filterdic.update(NameSpace) +sql = ac.convert(sql, filterdic) + +debug(f'{sql=}') +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/pipeline_steps/index.ui b/wwwroot/pipeline_steps/index.ui new file mode 100644 index 0000000..4e2f82d --- /dev/null +++ b/wwwroot/pipeline_steps/index.ui @@ -0,0 +1,241 @@ + +{ + "widgettype":"VBox", + "options":{"cheight":40,"width":"100%"}, + "subwidgets":[{ + "id":"pipeline_steps_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"产线步骤表", + + + + + "toolbar":{ + "tools": [ + { + "selected_row": true, + "name": "pipelines", + "icon": "{{entire_url('/imgs/pipelines.svg')}}", + "label": "所属产线" + } + ] +}, + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_pipeline_steps.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_pipeline_steps.dspy')}}", + + + "update_data_url":"{{entire_url('update_pipeline_steps.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_pipeline_steps.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id", + "step_config", + "input_schema", + "output_schema" + ], + "cwidth": {} +}, + + + "editexclouded":[ + "id", + "created_at" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "pipeline_id", + "title": "所属产线", + "type": "str", + "length": 32, + "nullable": "no", + "label": "所属产线", + "uitype": "code", + "valueField": "pipeline_id", + "textField": "pipeline_id_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_core')}}", + "table": "pipelines", + "tblvalue": "id", + "tbltext": "name", + "valueField": "pipeline_id", + "textField": "pipeline_id_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "step_order", + "title": "步骤序号", + "type": "int", + "nullable": "no", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "步骤序号" + }, + { + "name": "step_name", + "title": "步骤名称", + "type": "str", + "length": 100, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "步骤名称" + }, + { + "name": "step_type", + "title": "步骤类型", + "type": "str", + "length": 50, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "步骤类型" + }, + { + "name": "model_name", + "title": "调用模型名称", + "type": "str", + "length": 100, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "调用模型名称" + }, + { + "name": "step_config", + "title": "步骤配置JSON", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "步骤配置JSON" + }, + { + "name": "input_schema", + "title": "输入定义JSON", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "输入定义JSON" + }, + { + "name": "output_schema", + "title": "输出定义JSON", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "输出定义JSON" + }, + { + "name": "timeout_seconds", + "title": "超时秒数", + "type": "int", + "default": "300", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "超时秒数" + }, + { + "name": "retry_count", + "title": "重试次数", + "type": "int", + "default": "0", + "length": 0, + "uitype": "int", + "datatype": "int", + "label": "重试次数" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "创建时间" + } +] + }, + + + + + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[ + { + "wid": "self", + "event": "pipelines", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "所属产线", + "icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=pipelines", + "resizable": true, + "height": "70%", + "width": "70%" + }, + "params_mapping": { + "mapping": { + "id": "pipeline_id", + "referer_widget": "referer_widget" + }, + "need_other": false + }, + "options": { + "method": "POST", + "params": {}, + "url": "{{entire_url('../pipelines')}}" + } + } +] + +}] +} \ No newline at end of file diff --git a/wwwroot/pipeline_steps/update_pipeline_steps.dspy b/wwwroot/pipeline_steps/update_pipeline_steps.dspy new file mode 100644 index 0000000..9c095da --- /dev/null +++ b/wwwroot/pipeline_steps/update_pipeline_steps.dspy @@ -0,0 +1,36 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + + r = await sor.U('pipeline_steps', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipeline_versions/add_pipeline_versions.dspy b/wwwroot/pipeline_versions/add_pipeline_versions.dspy new file mode 100644 index 0000000..15c2ddb --- /dev/null +++ b/wwwroot/pipeline_versions/add_pipeline_versions.dspy @@ -0,0 +1,37 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('pipeline_versions', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipeline_versions/delete_pipeline_versions.dspy b/wwwroot/pipeline_versions/delete_pipeline_versions.dspy new file mode 100644 index 0000000..42a6efb --- /dev/null +++ b/wwwroot/pipeline_versions/delete_pipeline_versions.dspy @@ -0,0 +1,33 @@ + +ns = { + 'id':params_kw['id'], +} + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('pipeline_versions', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipeline_versions/get_pipeline_versions.dspy b/wwwroot/pipeline_versions/get_pipeline_versions.dspy new file mode 100644 index 0000000..b039ebd --- /dev/null +++ b/wwwroot/pipeline_versions/get_pipeline_versions.dspy @@ -0,0 +1,113 @@ + +ns = params_kw.copy() + + +debug(f'get_pipeline_versions.dspy:{ns=}') +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'created_at' + + + +sql = '''select a.*, b.pipeline_id_text +from (select * from pipeline_versions where 1=1 [[filterstr]]) a left join (select id as pipeline_id, + name as pipeline_id_text from pipelines where 1 = 1) b on a.pipeline_id = b.pipeline_id''' + +filterjson = params_kw.get('data_filter') +if filterjson and isinstance(filterjson, str): + try: + filterjson = json.loads(filterjson) + except (json.JSONDecodeError, TypeError): + filterjson = None +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "pipeline_id", + "title": "产线ID", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "version", + "title": "版本号", + "type": "str", + "length": 20, + "nullable": "no" + }, + { + "name": "publish_status", + "title": "发布状态", + "type": "str", + "length": 20, + "nullable": "no", + "default": "pending" + }, + { + "name": "published_by", + "title": "发布人", + "type": "str", + "length": 32 + }, + { + "name": "published_at", + "title": "发布时间", + "type": "timestamp" + }, + { + "name": "changelog", + "title": "变更说明", + "type": "text" + }, + { + "name": "config_snapshot", + "title": "配置快照JSON", + "type": "text" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + filterjson = default_filterjson(fields, ns) + +filterdic = ns.copy() +filterdic['filterstr'] = '' +filterdic['userorgid'] = '${userorgid}$' +filterdic['userid'] = '${userid}$' +if filterjson: + dbf = DBFilter(filterjson) + conds = dbf.gen(ns) + if conds: + ns.update(dbf.consts) + conds = f' and {conds}' + filterdic['filterstr'] = conds +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' } +filterdic.update(NameSpace) +sql = ac.convert(sql, filterdic) + +debug(f'{sql=}') +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/pipeline_versions/index.ui b/wwwroot/pipeline_versions/index.ui new file mode 100644 index 0000000..05c27a9 --- /dev/null +++ b/wwwroot/pipeline_versions/index.ui @@ -0,0 +1,210 @@ + +{ + "widgettype":"VBox", + "options":{"cheight":40,"width":"100%"}, + "subwidgets":[{ + "id":"pipeline_versions_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"产线发布记录表", + + + + + "toolbar":{ + "tools": [ + { + "selected_row": true, + "name": "pipelines", + "icon": "{{entire_url('/imgs/pipelines.svg')}}", + "label": "所属产线" + } + ] +}, + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_pipeline_versions.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_pipeline_versions.dspy')}}", + + + "update_data_url":"{{entire_url('update_pipeline_versions.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_pipeline_versions.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id", + "config_snapshot" + ], + "cwidth": {} +}, + + + "editexclouded":[ + "id", + "created_at" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "pipeline_id", + "title": "产线ID", + "type": "str", + "length": 32, + "nullable": "no", + "label": "产线ID", + "uitype": "code", + "valueField": "pipeline_id", + "textField": "pipeline_id_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_core')}}", + "table": "pipelines", + "tblvalue": "id", + "tbltext": "name", + "valueField": "pipeline_id", + "textField": "pipeline_id_text" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "version", + "title": "版本号", + "type": "str", + "length": 20, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "版本号" + }, + { + "name": "publish_status", + "title": "发布状态", + "type": "str", + "length": 20, + "nullable": "no", + "default": "pending", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "发布状态" + }, + { + "name": "published_by", + "title": "发布人", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "发布人" + }, + { + "name": "published_at", + "title": "发布时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "发布时间" + }, + { + "name": "changelog", + "title": "变更说明", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "变更说明" + }, + { + "name": "config_snapshot", + "title": "配置快照JSON", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "配置快照JSON" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "创建时间" + } +] + }, + + + + + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[ + { + "wid": "self", + "event": "pipelines", + "actiontype": "urlwidget", + "target": "PopupWindow", + "popup_options": { + "title": "所属产线", + "icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=pipelines", + "resizable": true, + "height": "70%", + "width": "70%" + }, + "params_mapping": { + "mapping": { + "id": "pipeline_id", + "referer_widget": "referer_widget" + }, + "need_other": false + }, + "options": { + "method": "POST", + "params": {}, + "url": "{{entire_url('../pipelines')}}" + } + } +] + +}] +} \ No newline at end of file diff --git a/wwwroot/pipeline_versions/update_pipeline_versions.dspy b/wwwroot/pipeline_versions/update_pipeline_versions.dspy new file mode 100644 index 0000000..74b8082 --- /dev/null +++ b/wwwroot/pipeline_versions/update_pipeline_versions.dspy @@ -0,0 +1,36 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + + r = await sor.U('pipeline_versions', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipelines/add_pipelines.dspy b/wwwroot/pipelines/add_pipelines.dspy new file mode 100644 index 0000000..9972d78 --- /dev/null +++ b/wwwroot/pipelines/add_pipelines.dspy @@ -0,0 +1,54 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None +id = params_kw.id +if not id or len(id) > 32: + id = uuid() +ns['id'] = id + +if params_kw.get('model_api_key'): + ns['model_api_key'] = password_encode(params_kw.get('model_api_key')) + + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['org_id'] = userorgid + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.C('pipelines', ns.copy()) + return { + "widgettype":"Message", + "options":{ + "cwidth":16, + "cheight":9, + "title":"Add Success", + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Add Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipelines/delete_pipelines.dspy b/wwwroot/pipelines/delete_pipelines.dspy new file mode 100644 index 0000000..f2318f0 --- /dev/null +++ b/wwwroot/pipelines/delete_pipelines.dspy @@ -0,0 +1,47 @@ + +ns = { + 'id':params_kw['id'], +} + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['org_id'] = userorgid + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.D('pipelines', ns) + debug('delete success'); + return { + "widgettype":"Message", + "options":{ + "title":"Delete Success", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"ok" + } + } + +debug('Delete failed'); +return { + "widgettype":"Error", + "options":{ + "title":"Delete Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"failed" + } +} \ No newline at end of file diff --git a/wwwroot/pipelines/get_pipelines.dspy b/wwwroot/pipelines/get_pipelines.dspy new file mode 100644 index 0000000..129b5d1 --- /dev/null +++ b/wwwroot/pipelines/get_pipelines.dspy @@ -0,0 +1,165 @@ + +ns = params_kw.copy() + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['org_id'] = userorgid +ns['userorgid'] = userorgid + +debug(f'get_pipelines.dspy:{ns=}') +if not ns.get('page'): + ns['page'] = 1 +if not ns.get('sort'): + + + ns['sort'] = 'created_at' + + + +sql = '''select a.*, b.pipeline_type_text, c.status_text +from (select * from pipelines where 1=1 [[filterstr]]) a left join (select k as pipeline_type, + v as pipeline_type_text from appcodes_kv where parentid='pipeline_type') b on a.pipeline_type = b.pipeline_type left join (select k as status, + v as status_text from appcodes_kv where parentid='pipeline_status') c on a.status = c.status''' + +filterjson = params_kw.get('data_filter') +if filterjson and isinstance(filterjson, str): + try: + filterjson = json.loads(filterjson) + except (json.JSONDecodeError, TypeError): + filterjson = None +fields_str=r'''[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "nullable": "no" + }, + { + "name": "name", + "title": "产线名称", + "type": "str", + "length": 200, + "nullable": "no" + }, + { + "name": "description", + "title": "产线描述", + "type": "text" + }, + { + "name": "pipeline_type", + "title": "产线类型", + "type": "str", + "length": 50, + "nullable": "no" + }, + { + "name": "version", + "title": "当前版本", + "type": "str", + "length": 20, + "default": "1.0.0" + }, + { + "name": "status", + "title": "状态", + "type": "str", + "length": 20, + "nullable": "no", + "default": "draft" + }, + { + "name": "pipeline_config", + "title": "产线配置JSON", + "type": "text" + }, + { + "name": "model_api_url", + "title": "模型API地址", + "type": "str", + "length": 500 + }, + { + "name": "model_api_key", + "title": "模型API密钥", + "type": "str", + "length": 500 + }, + { + "name": "org_id", + "title": "所属机构ID", + "type": "str", + "length": 32, + "default": "0" + }, + { + "name": "created_by", + "title": "创建人", + "type": "str", + "length": 32 + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp" + }, + { + "name": "updated_at", + "title": "更新时间", + "type": "timestamp" + } +]''' +ori_fields = json.loads(fields_str) +if not filterjson: + fields = [ f['name'] for f in ori_fields ] + filterjson = default_filterjson(fields, ns) + +# 确保 logined 过滤条件始终生效 +if filterjson: + if not isinstance(filterjson, dict) or 'AND' not in filterjson: + filterjson = {'AND': [filterjson] if filterjson else []} + + filterjson['AND'].append({'field': 'org_id', 'op': '=', 'var': '__logined_orgid__'}) + ns['__logined_orgid__'] = userorgid + + + +filterdic = ns.copy() +filterdic['filterstr'] = '' +filterdic['userorgid'] = '${userorgid}$' +filterdic['userid'] = '${userid}$' +if filterjson: + dbf = DBFilter(filterjson) + conds = dbf.gen(ns) + if conds: + ns.update(dbf.consts) + conds = f' and {conds}' + filterdic['filterstr'] = conds +ac = ArgsConvert('[[', ']]') +vars = ac.findAllVariables(sql) +NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' } +filterdic.update(NameSpace) +sql = ac.convert(sql, filterdic) + +debug(f'{sql=}') +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + r = await sor.sqlPaging(sql, ns) + return r +return { + "total":0, + "rows":[] +} \ No newline at end of file diff --git a/wwwroot/pipelines/index.ui b/wwwroot/pipelines/index.ui new file mode 100644 index 0000000..436c9b7 --- /dev/null +++ b/wwwroot/pipelines/index.ui @@ -0,0 +1,228 @@ + +{ + "widgettype":"VBox", + "options":{"cheight":40,"width":"100%"}, + "subwidgets":[{ + "id":"pipelines_tbl", + "widgettype":"Tabular", + "options":{ + "width":"100%", + "height":"100%", + + + "title":"产线定义表", + + + + + "css":"card", + + + "editable":{ + + "new_data_url":"{{entire_url('add_pipelines.dspy')}}", + + + "delete_data_url":"{{entire_url('delete_pipelines.dspy')}}", + + + "update_data_url":"{{entire_url('update_pipelines.dspy')}}" + + }, + + + "data_url":"{{entire_url('./get_pipelines.dspy')}}", + + "data_method":"GET", + "data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}}, + "row_options":{ + + + + "browserfields": { + "exclouded": [ + "id", + "model_api_key", + "pipeline_config" + ], + "cwidth": {} +}, + + + "editexclouded":[ + "id", + "created_at", + "updated_at" +], + + "fields":[ + { + "name": "id", + "title": "id", + "type": "str", + "length": 32, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "id" + }, + { + "name": "name", + "title": "产线名称", + "type": "str", + "length": 200, + "nullable": "no", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "产线名称" + }, + { + "name": "description", + "title": "产线描述", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "产线描述" + }, + { + "name": "pipeline_type", + "title": "产线类型", + "type": "str", + "length": 50, + "nullable": "no", + "label": "产线类型", + "uitype": "code", + "valueField": "pipeline_type", + "textField": "pipeline_type_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_core')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "pipeline_type", + "textField": "pipeline_type_text", + "cond": "parentid='pipeline_type'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "version", + "title": "当前版本", + "type": "str", + "length": 20, + "default": "1.0.0", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "当前版本" + }, + { + "name": "status", + "title": "状态", + "type": "str", + "length": 20, + "nullable": "no", + "default": "draft", + "label": "状态", + "uitype": "code", + "valueField": "status", + "textField": "status_text", + "params": { + "dbname": "{{get_module_dbname('pipeline_core')}}", + "table": "appcodes_kv", + "tblvalue": "k", + "tbltext": "v", + "valueField": "status", + "textField": "status_text", + "cond": "parentid='pipeline_status'" + }, + "dataurl": "{{entire_url('/appbase/get_code.dspy')}}" + }, + { + "name": "pipeline_config", + "title": "产线配置JSON", + "type": "text", + "length": 0, + "uitype": "text", + "datatype": "text", + "label": "产线配置JSON" + }, + { + "name": "model_api_url", + "title": "模型API地址", + "type": "str", + "length": 500, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "模型API地址" + }, + { + "name": "model_api_key", + "title": "模型API密钥", + "type": "str", + "length": 500, + "cwidth": 18, + "uitype": "password", + "datatype": "str", + "label": "模型API密钥" + }, + { + "name": "org_id", + "title": "所属机构ID", + "type": "str", + "length": 32, + "default": "0", + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "所属机构ID" + }, + { + "name": "created_by", + "title": "创建人", + "type": "str", + "length": 32, + "cwidth": 18, + "uitype": "str", + "datatype": "str", + "label": "创建人" + }, + { + "name": "created_at", + "title": "创建时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "创建时间" + }, + { + "name": "updated_at", + "title": "更新时间", + "type": "timestamp", + "length": 0, + "uitype": "str", + "datatype": "timestamp", + "label": "更新时间" + } +] + }, + + + + + + + + "page_rows":160, + "cache_limit":5 + } + + ,"binds":[] + +}] +} \ No newline at end of file diff --git a/wwwroot/pipelines/update_pipelines.dspy b/wwwroot/pipelines/update_pipelines.dspy new file mode 100644 index 0000000..b777b85 --- /dev/null +++ b/wwwroot/pipelines/update_pipelines.dspy @@ -0,0 +1,73 @@ + +ns = params_kw.copy() +for k,v in ns.items(): + if v == 'NaN' or v == 'null': + ns[k] = None + + +userorgid = await get_userorgid() +if not userorgid: + return { + "widgettype":"Error", + "options":{ + "title":"Authorization Error", + "timeout":3, + "cwidth":16, + "cheight":9, + "message":"Please login" + } + } +ns['org_id'] = userorgid + + +if params_kw.get('model_api_key'): + ns['model_api_key'] = password_encode(params_kw.get('model_api_key')) + + +db = DBPools() +dbname = get_module_dbname('pipeline_core') +async with db.sqlorContext(dbname) as sor: + + ns1 = { + + "org_id": userorgid, + + + "id": params_kw.id + } + recs = await sor.R('pipelines', ns1) + if len(recs) < 1: + return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"Record no exist or with wrong ownership" + } + } + + r = await sor.U('pipelines', ns) + debug('update success'); + return { + "widgettype":"Message", + "options":{ + "title":"Update Success", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"ok" + } + } + +return { + "widgettype":"Error", + "options":{ + "title":"Update Error", + "cwidth":16, + "cheight":9, + "timeout":3, + "message":"failed" + } +} \ No newline at end of file