安全性提升:TID动态生成+Streamlit页面排除+工作记忆修复
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -67,3 +67,5 @@ restore_commit.txt
|
||||
|
||||
sche_tasks/
|
||||
QUICK_START.md
|
||||
# CDP Bridge 密钥配置(首次运行自动生成)
|
||||
assets/tmwd_cdp_bridge/config.js
|
||||
12
agentmain.py
12
agentmain.py
@@ -13,13 +13,17 @@ with open('assets/tools_schema.json', 'r', encoding='utf-8') as f:
|
||||
TS = f.read()
|
||||
TOOLS_SCHEMA = json.loads(TS if os.name == 'nt' else TS.replace('powershell', 'bash'))
|
||||
|
||||
def get_system_prompt():
|
||||
if not os.path.exists('memory'): os.makedirs('memory')
|
||||
if not os.path.exists('memory/global_mem.txt'):
|
||||
if not os.path.exists('memory'): os.makedirs('memory')
|
||||
if not os.path.exists('memory/global_mem.txt'):
|
||||
with open('memory/global_mem.txt', 'w', encoding='utf-8') as f: f.write('')
|
||||
if not os.path.exists('memory/global_mem_insight.txt'):
|
||||
if not os.path.exists('memory/global_mem_insight.txt'):
|
||||
t = 'assets/global_mem_insight_template.txt'
|
||||
open('memory/global_mem_insight.txt', 'w', encoding='utf-8').write(open(t, encoding='utf-8').read() if os.path.exists(t) else '')
|
||||
if not os.path.exists('assets/tmwd_cdp_bridge/config.js'):
|
||||
with open('assets/tmwd_cdp_bridge/config.js', 'w', encoding='utf-8') as f:
|
||||
f.write(f"const TID = '__ljq_{hex(random.randint(0, 99999999))[2:8]}';")
|
||||
|
||||
def get_system_prompt():
|
||||
with open('assets/sys_prompt.txt', 'r', encoding='utf-8') as f: prompt = f.read()
|
||||
prompt += f"\nToday: {time.strftime('%Y-%m-%d %a')}\n"
|
||||
prompt += get_global_memory()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
const log_prefix = "ljq_driver: ";
|
||||
if (document.querySelector('[data-testid="stApp"],.stApp')) return;
|
||||
|
||||
if (window.self !== window.top) {
|
||||
window.addEventListener('message',e=>{if(e.data?.type==='ljq_exec'){try{let r=eval(e.data.code);parent.postMessage({type:'ljq_result',id:e.data.id,result:String(r)},'*')}catch(err){parent.postMessage({type:'ljq_result',id:e.data.id,error:err.message},'*')}}});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// content.js - DOM trigger bridge
|
||||
const TID = '__ljq_ctrl';
|
||||
|
||||
new MutationObserver(muts => {
|
||||
for (const m of muts) for (const n of m.addedNodes) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["<all_urls>"],
|
||||
"js": ["content.js"],
|
||||
"js": ["config.js", "content.js"],
|
||||
"run_at": "document_idle",
|
||||
"all_frames": true
|
||||
}
|
||||
|
||||
4
ga.py
4
ga.py
@@ -407,8 +407,8 @@ class GenericAgentHandler(BaseHandler):
|
||||
'''
|
||||
key_info = args.get("key_info", "")
|
||||
related_sop = args.get("related_sop", "")
|
||||
if key_info: self.key_info = key_info
|
||||
if related_sop: self.related_sop = related_sop
|
||||
if "key_info" in args: self.key_info = key_info
|
||||
if "related_sop" in args: self.related_sop = related_sop
|
||||
yield f"[Info] Updated key_info and related_sop.\n"
|
||||
yield f"key_info:\n{self.key_info}\n\n"
|
||||
yield f"related_sop:\n{self.related_sop}\n\n"
|
||||
|
||||
@@ -46,12 +46,14 @@ fetch('PDF_URL').then(r=>r.blob()).then(b=>{
|
||||
|
||||
## CDP桥(tmwd_cdp_bridge扩展) ⭐首选
|
||||
扩展路径:`assets/tmwd_cdp_bridge/`(需安装,含debugger权限)
|
||||
调用:MutationObserver监听addedNodes(id=`__ljq_ctrl`),⚠每次必须remove旧→createElement新→设textContent JSON→appendChild
|
||||
⚠TID密钥:首次运行自动生成到`assets/tmwd_cdp_bridge/config.js`(已gitignore),扩展通过manifest引用
|
||||
调用:MutationObserver监听addedNodes(id=TID),⚠每次必须remove旧→createElement新→设textContent JSON→appendChild
|
||||
```js
|
||||
const old = document.getElementById('__ljq_ctrl');
|
||||
// TID从assets/tmwd_cdp_bridge/config.js读取,示例用'__ljq_ctrl'占位
|
||||
const old = document.getElementById(TID);
|
||||
if (old) old.remove();
|
||||
const el = document.createElement('div');
|
||||
el.id = '__ljq_ctrl'; el.style.display = 'none';
|
||||
el.id = TID; el.style.display = 'none';
|
||||
el.textContent = JSON.stringify({cmd:'...', ...});
|
||||
document.body.appendChild(el); // 响应写回el.textContent
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user