Initial commit: weather demo
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: chart
|
||||||
|
description: 把天气数据(含 city 和 days 数组)生成温度曲线图 HTML 文件,返回文件名。
|
||||||
|
tools: Write, Bash
|
||||||
|
agentMode: agentic
|
||||||
|
enabled: true
|
||||||
|
enabledAutoRun: true
|
||||||
|
---
|
||||||
|
你是图表生成 Agent。收到天气 JSON(含 city 和 days,每天有 date/max/min/desc),生成温度曲线图 HTML 文件。
|
||||||
|
|
||||||
|
步骤:
|
||||||
|
1. 用 Bash 执行 `node -e "console.log(Date.now())"` 得到毫秒时间戳 T。
|
||||||
|
2. 用 Write 把下面模板写入文件 `public/charts/weather-T.html`(T 换成时间戳)。把模板里的 __TITLE__ 换成"城市名 未来3天温度变化",把 __DAYS__ 换成 days 数组的 JSON(原样)。
|
||||||
|
3. 只输出一个 JSON:{"file":"weather-T.html"},不要其他文字。
|
||||||
|
|
||||||
|
模板(照抄,仅替换 __TITLE__ 与 __DAYS__):
|
||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>__TITLE__</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=__DAYS__;const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'__TITLE__',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
name: weather
|
||||||
|
description: 查询某城市未来3天天气,返回结构化JSON供后续绘图使用。
|
||||||
|
tools: Bash
|
||||||
|
agentMode: agentic
|
||||||
|
enabled: true
|
||||||
|
enabledAutoRun: true
|
||||||
|
---
|
||||||
|
你是天气查询 Agent。用 Bash 执行 curl 命令直连 Open-Meteo API 获取未来3天天气。
|
||||||
|
|
||||||
|
严格按以下两步执行,总共只允许调用 Bash 两次(第一步一次、第二步一次),禁止重复重试。
|
||||||
|
|
||||||
|
第一步·地理编码(城市名若为中文,name 用拼音,例如"北京"→"beijing"):
|
||||||
|
curl -s "https://geocoding-api.open-meteo.com/v1/search?name={拼音或英文}&count=1&format=json"
|
||||||
|
从返回 JSON 的 results[0] 里取 latitude、longitude。
|
||||||
|
|
||||||
|
第二步·查天气:
|
||||||
|
curl -s "https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=weather_code,temperature_2m_max,temperature_2m_min&timezone=auto&forecast_days=3"
|
||||||
|
从 daily 里取 time、temperature_2m_max、temperature_2m_min、weather_code。
|
||||||
|
|
||||||
|
weather_code 转中文:0晴 1大致晴朗 2多云 3阴 45/48雾 51/53/55毛毛雨 61/63/65雨 71/73/75雪 80/81/82阵雨 95/96/99雷暴,其余记"多云"。
|
||||||
|
|
||||||
|
拿到数据后立即输出,禁止再调用任何工具。只输出一个 JSON 对象,不要解释、不要代码块标记。格式:
|
||||||
|
{"city":"城市名","days":[{"date":"2026-10-24","max":15,"min":8,"desc":"多云"}]}
|
||||||
|
|
||||||
|
规则:
|
||||||
|
- days 取 3 天(time 数组的全部 3 项),date 用 time 的 YYYY-MM-DD,max/min 用 temperature_2m_max/min 四舍五入成整数,desc 用 weather_code 映射的中文。
|
||||||
|
- 所有数值必须是数字类型。
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京·中国 未来3天温度变化</title>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script>
|
||||||
|
<style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui,sans-serif}#c{width:100vw;height:100vh}</style></head>
|
||||||
|
<body><div id="c"></div><script>
|
||||||
|
const rows=[{"t":"2026-10-24 00:00","temp":10.2,"hum":82,"precip":0},{"t":"2026-10-24 01:00","temp":9.9,"hum":83,"precip":0},{"t":"2026-10-24 02:00","temp":9.1,"hum":88,"precip":0},{"t":"2026-10-24 03:00","temp":8.9,"hum":88,"precip":0},{"t":"2026-10-24 04:00","temp":8.7,"hum":89,"precip":0},{"t":"2026-10-24 05:00","temp":8.9,"hum":87,"precip":0},{"t":"2026-10-24 06:00","temp":9,"hum":86,"precip":0},{"t":"2026-10-24 07:00","temp":8.9,"hum":84,"precip":0},{"t":"2026-10-24 08:00","temp":10.2,"hum":83,"precip":0},{"t":"2026-10-24 09:00","temp":11.7,"hum":76,"precip":0},{"t":"2026-10-24 10:00","temp":13.1,"hum":73,"precip":0},{"t":"2026-10-24 11:00","temp":13.9,"hum":69,"precip":0},{"t":"2026-10-24 12:00","temp":14.6,"hum":68,"precip":0},{"t":"2026-10-24 13:00","temp":15.3,"hum":67,"precip":0},{"t":"2026-10-24 14:00","temp":15.6,"hum":66,"precip":0},{"t":"2026-10-24 15:00","temp":15.8,"hum":66,"precip":0},{"t":"2026-10-24 16:00","temp":15.8,"hum":68,"precip":0},{"t":"2026-10-24 17:00","temp":15.5,"hum":75,"precip":0},{"t":"2026-10-24 18:00","temp":15.1,"hum":76,"precip":0},{"t":"2026-10-24 19:00","temp":15,"hum":76,"precip":1},{"t":"2026-10-24 20:00","temp":14.5,"hum":80,"precip":2},{"t":"2026-10-24 21:00","temp":14.1,"hum":83,"precip":4},{"t":"2026-10-24 22:00","temp":13.7,"hum":84,"precip":7},{"t":"2026-10-24 23:00","temp":13.5,"hum":84,"precip":10},{"t":"2026-10-25 00:00","temp":13.3,"hum":86,"precip":14},{"t":"2026-10-25 01:00","temp":13.2,"hum":87,"precip":19},{"t":"2026-10-25 02:00","temp":13.1,"hum":90,"precip":25},{"t":"2026-10-25 03:00","temp":12.9,"hum":92,"precip":34},{"t":"2026-10-25 04:00","temp":12.7,"hum":94,"precip":44},{"t":"2026-10-25 05:00","temp":12.4,"hum":93,"precip":49},{"t":"2026-10-25 06:00","temp":12.1,"hum":93,"precip":43},{"t":"2026-10-25 07:00","temp":12.1,"hum":91,"precip":32},{"t":"2026-10-25 08:00","temp":12.3,"hum":89,"precip":22},{"t":"2026-10-25 09:00","temp":12.5,"hum":88,"precip":16},{"t":"2026-10-25 10:00","temp":12.7,"hum":88,"precip":12},{"t":"2026-10-25 11:00","temp":13,"hum":86,"precip":10},{"t":"2026-10-25 12:00","temp":13.1,"hum":83,"precip":9},{"t":"2026-10-25 13:00","temp":12.9,"hum":81,"precip":9},{"t":"2026-10-25 14:00","temp":12.9,"hum":79,"precip":12},{"t":"2026-10-25 15:00","temp":12.7,"hum":77,"precip":20},{"t":"2026-10-25 16:00","temp":12.3,"hum":78,"precip":32},{"t":"2026-10-25 17:00","temp":11.8,"hum":80,"precip":43},{"t":"2026-10-25 18:00","temp":11.3,"hum":83,"precip":54},{"t":"2026-10-25 19:00","temp":11.1,"hum":84,"precip":65},{"t":"2026-10-25 20:00","temp":10.8,"hum":86,"precip":71},{"t":"2026-10-25 21:00","temp":10.5,"hum":88,"precip":67},{"t":"2026-10-25 22:00","temp":10.3,"hum":87,"precip":58},{"t":"2026-10-25 23:00","temp":10.2,"hum":88,"precip":49},{"t":"2026-10-26 00:00","temp":10,"hum":89,"precip":43},{"t":"2026-10-26 01:00","temp":9.9,"hum":92,"precip":38},{"t":"2026-10-26 02:00","temp":9.8,"hum":93,"precip":33},{"t":"2026-10-26 03:00","temp":9.7,"hum":93,"precip":29},{"t":"2026-10-26 04:00","temp":9.6,"hum":93,"precip":25},{"t":"2026-10-26 05:00","temp":9.8,"hum":92,"precip":22},{"t":"2026-10-26 06:00","temp":9.8,"hum":92,"precip":21},{"t":"2026-10-26 07:00","temp":9.4,"hum":94,"precip":20},{"t":"2026-10-26 08:00","temp":9.9,"hum":92,"precip":18},{"t":"2026-10-26 09:00","temp":10.7,"hum":87,"precip":13},{"t":"2026-10-26 10:00","temp":11.8,"hum":80,"precip":7},{"t":"2026-10-26 11:00","temp":12.7,"hum":76,"precip":2},{"t":"2026-10-26 12:00","temp":13.9,"hum":71,"precip":0},{"t":"2026-10-26 13:00","temp":14.5,"hum":69,"precip":0},{"t":"2026-10-26 14:00","temp":14.9,"hum":68,"precip":0},{"t":"2026-10-26 15:00","temp":15.2,"hum":67,"precip":0},{"t":"2026-10-26 16:00","temp":14.9,"hum":71,"precip":0},{"t":"2026-10-26 17:00","temp":14,"hum":76,"precip":0},{"t":"2026-10-26 18:00","temp":13,"hum":80,"precip":0},{"t":"2026-10-26 19:00","temp":12.8,"hum":81,"precip":0},{"t":"2026-10-26 20:00","temp":12.6,"hum":70,"precip":0},{"t":"2026-10-26 21:00","temp":13.1,"hum":35,"precip":0},{"t":"2026-10-26 22:00","temp":13,"hum":30,"precip":0},{"t":"2026-10-26 23:00","temp":12.6,"hum":28,"precip":0}];
|
||||||
|
const ch=echarts.init(document.getElementById('c'));
|
||||||
|
ch.setOption({title:{text:"北京·中国 未来3天温度变化",left:'center',textStyle:{color:'#e2e8f0'}},
|
||||||
|
tooltip:{trigger:'axis',formatter:p=>{const r=rows[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C<br>湿度 '+r.hum+'%<br>降水概率 '+r.precip+'%';}},
|
||||||
|
grid:{left:55,right:40,top:80,bottom:55},
|
||||||
|
xAxis:{type:'category',data:rows.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:5}},
|
||||||
|
yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},
|
||||||
|
series:[{name:'温度',type:'line',smooth:true,data:rows.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});
|
||||||
|
window.addEventListener('resize',()=>ch.resize());
|
||||||
|
</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const hours=[{"t":"10-24 00:00","temp":13},{"t":"10-24 03:00","temp":12},{"t":"10-24 06:00","temp":12},{"t":"10-24 09:00","temp":14},{"t":"10-24 12:00","temp":17},{"t":"10-24 15:00","temp":18},{"t":"10-24 18:00","temp":17},{"t":"10-24 21:00","temp":17},{"t":"10-25 00:00","temp":16},{"t":"10-25 03:00","temp":14},{"t":"10-25 06:00","temp":14},{"t":"10-25 09:00","temp":14},{"t":"10-25 12:00","temp":13},{"t":"10-25 15:00","temp":13},{"t":"10-25 18:00","temp":12},{"t":"10-25 21:00","temp":11},{"t":"10-26 00:00","temp":12},{"t":"10-26 03:00","temp":12},{"t":"10-26 06:00","temp":12},{"t":"10-26 09:00","temp":14},{"t":"10-26 12:00","temp":16},{"t":"10-26 15:00","temp":18},{"t":"10-26 18:00","temp":16},{"t":"10-26 21:00","temp":15}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis',formatter:p=>{const r=hours[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:hours.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:3}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{type:'line',smooth:true,data:hours.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const hours=[{"t":"10-24 00:00","temp":13},{"t":"10-24 03:00","temp":12},{"t":"10-24 06:00","temp":12},{"t":"10-24 09:00","temp":14},{"t":"10-24 12:00","temp":17},{"t":"10-24 15:00","temp":18},{"t":"10-24 18:00","temp":17},{"t":"10-24 21:00","temp":17},{"t":"10-25 00:00","temp":16},{"t":"10-25 03:00","temp":14},{"t":"10-25 06:00","temp":14},{"t":"10-25 09:00","temp":14},{"t":"10-25 12:00","temp":13},{"t":"10-25 15:00","temp":13},{"t":"10-25 18:00","temp":12},{"t":"10-25 21:00","temp":11},{"t":"10-26 00:00","temp":12},{"t":"10-26 03:00","temp":12},{"t":"10-26 06:00","temp":12},{"t":"10-26 09:00","temp":14},{"t":"10-26 12:00","temp":16},{"t":"10-26 15:00","temp":18},{"t":"10-26 18:00","temp":16},{"t":"10-26 21:00","temp":15}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis',formatter:p=>{const r=hours[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:hours.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:3}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{type:'line',smooth:true,data:hours.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const hours=[{"t":"10-24 00:00","temp":13},{"t":"10-24 03:00","temp":12},{"t":"10-24 06:00","temp":12},{"t":"10-24 09:00","temp":14},{"t":"10-24 12:00","temp":17},{"t":"10-24 15:00","temp":18},{"t":"10-24 18:00","temp":17},{"t":"10-24 21:00","temp":17},{"t":"10-25 00:00","temp":16},{"t":"10-25 03:00","temp":14},{"t":"10-25 06:00","temp":14},{"t":"10-25 09:00","temp":14},{"t":"10-25 12:00","temp":13},{"t":"10-25 15:00","temp":13},{"t":"10-25 18:00","temp":12},{"t":"10-25 21:00","temp":11},{"t":"10-26 00:00","temp":12},{"t":"10-26 03:00","temp":12},{"t":"10-26 06:00","temp":12},{"t":"10-26 09:00","temp":14},{"t":"10-26 12:00","temp":16},{"t":"10-26 15:00","temp":18},{"t":"10-26 18:00","temp":16},{"t":"10-26 21:00","temp":15}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis',formatter:p=>{const r=hours[p[0].dataIndex];return r.t+'<br>温度 '+r.temp+'°C'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:hours.map(r=>r.t),axisLabel:{color:'#94a3b8',interval:3}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{type:'line',smooth:true,data:hours.map(r=>r.temp),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'},areaStyle:{color:'rgba(56,189,248,.2)'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>北京 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":16,"min":9,"desc":"毛毛雨"},{"date":"2026-10-25","max":13,"min":10,"desc":"毛毛雨"},{"date":"2026-10-26","max":15,"min":9,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'北京 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>深圳 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":32,"min":22,"desc":"阴"},{"date":"2026-10-25","max":32,"min":22,"desc":"阴"},{"date":"2026-10-26","max":30,"min":23,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'深圳 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<!DOCTYPE html><html><head><meta charset="utf-8"><title>深圳 未来3天温度变化</title><script src="https://cdn.jsdelivr.net/npm/echarts@5.5.0/dist/echarts.min.js"></script><style>body{margin:0;background:#0f172a;color:#e2e8f0;font-family:system-ui}#c{width:100vw;height:100vh}</style></head><body><div id="c"></div><script>const days=[{"date":"2026-10-24","max":32,"min":22,"desc":"阴"},{"date":"2026-10-25","max":32,"min":22,"desc":"阴"},{"date":"2026-10-26","max":30,"min":23,"desc":"毛毛雨"}];const ch=echarts.init(document.getElementById('c'));ch.setOption({title:{text:'深圳 未来3天温度变化',left:'center',textStyle:{color:'#e2e8f0'}},tooltip:{trigger:'axis'},legend:{data:['最高温','最低温'],textStyle:{color:'#e2e8f0'}},grid:{left:55,right:40,top:80,bottom:55},xAxis:{type:'category',data:days.map(r=>r.date),axisLabel:{color:'#94a3b8'}},yAxis:{type:'value',name:'°C',axisLabel:{color:'#94a3b8'}},series:[{name:'最高温',type:'line',smooth:true,data:days.map(r=>r.max),lineStyle:{width:3,color:'#fb7185'},itemStyle:{color:'#fb7185'}},{name:'最低温',type:'line',smooth:true,data:days.map(r=>r.min),lineStyle:{width:3,color:'#38bdf8'},itemStyle:{color:'#38bdf8'}}]});addEventListener('resize',()=>ch.resize());</script></body></html>
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>AI 天气工作流</title>
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #f4f6fb;
|
||||||
|
--primary: #3b6ef6;
|
||||||
|
--text: #1f2937;
|
||||||
|
--muted: #6b7280;
|
||||||
|
--border: #e5e9f0;
|
||||||
|
}
|
||||||
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||||
|
background: linear-gradient(160deg, #eef2ff, #f4f6fb 45%, #e6f7f5);
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 24px;
|
||||||
|
color: var(--text);
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 600px;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 20px;
|
||||||
|
box-shadow: 0 20px 60px rgba(31, 45, 90, .12);
|
||||||
|
padding: 36px 32px;
|
||||||
|
}
|
||||||
|
.badge {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--primary);
|
||||||
|
background: #eef2ff;
|
||||||
|
border: 1px solid #dbe3ff;
|
||||||
|
padding: 4px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
h1 { font-size: 23px; }
|
||||||
|
.subtitle { color: var(--muted); font-size: 14px; margin-top: 8px; line-height: 1.6; }
|
||||||
|
.form { display: flex; gap: 10px; margin-top: 22px; }
|
||||||
|
.form input {
|
||||||
|
flex: 1;
|
||||||
|
height: 48px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 0 16px;
|
||||||
|
font-size: 15px;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
.form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 110, 246, .15); }
|
||||||
|
.form button {
|
||||||
|
height: 48px;
|
||||||
|
padding: 0 22px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: var(--primary);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.form button:disabled { opacity: .6; cursor: not-allowed; }
|
||||||
|
.result { margin-top: 24px; display: none; }
|
||||||
|
.result.show { display: block; }
|
||||||
|
.days { display: flex; gap: 10px; margin-top: 14px; }
|
||||||
|
.day {
|
||||||
|
flex: 1;
|
||||||
|
background: #f8fafc;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 14px 12px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.day .w { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
|
||||||
|
.day .ico { font-size: 22px; margin-bottom: 6px; }
|
||||||
|
.day .tmp { font-size: 15px; font-weight: 700; }
|
||||||
|
.day .range { font-size: 12px; color: var(--muted); margin-top: 4px; }
|
||||||
|
.link {
|
||||||
|
margin-top: 18px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
color: #fff;
|
||||||
|
background: #10b981;
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
.link:hover { background: #059669; }
|
||||||
|
.err {
|
||||||
|
margin-top: 18px;
|
||||||
|
color: #c0392b;
|
||||||
|
background: #fdf2f2;
|
||||||
|
border: 1px solid #f5c6c6;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 14px;
|
||||||
|
font-size: 14px;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.load { margin-top: 18px; color: var(--muted); font-size: 14px; display: none; }
|
||||||
|
.spin {
|
||||||
|
display: inline-block;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border: 2px solid #c7d2fe;
|
||||||
|
border-top-color: var(--primary);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: s .7s linear infinite;
|
||||||
|
vertical-align: -2px;
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
@keyframes s { to { transform: rotate(360deg); } }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main class="card">
|
||||||
|
<span class="badge">工作流:查天气 → 生成曲线图</span>
|
||||||
|
<h1>未来3天天气曲线</h1>
|
||||||
|
<p class="subtitle">输入城市提交后,系统自动查询未来3天天气并生成温度变化曲线图。</p>
|
||||||
|
<form class="form" id="form">
|
||||||
|
<input id="city" placeholder="例如:北京 / 上海 / 深圳" autocomplete="off">
|
||||||
|
<button id="btn" type="submit">提交</button>
|
||||||
|
</form>
|
||||||
|
<div class="load" id="load"><span class="spin"></span>正在查询并生成曲线图…</div>
|
||||||
|
<div class="err" id="err"></div>
|
||||||
|
<div class="result" id="result"></div>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
const ICO = {
|
||||||
|
晴: '☀️', 大致晴朗: '🌤️', 多云: '⛅', 阴: '☁️',
|
||||||
|
雾: '🌫️', 雾凇: '🌫️', 小毛毛雨: '🌦️', 毛毛雨: '🌦️',
|
||||||
|
强毛毛雨: '🌧️', 小雨: '🌧️', 中雨: '🌧️', 大雨: '🌧️',
|
||||||
|
冻雨: '🌧️', 小雪: '🌨️', 中雪: '🌨️', 大雪: '❄️',
|
||||||
|
小阵雨: '🌦️', 中阵雨: '🌧️', 强阵雨: '⛈️', 小阵雪: '🌨️',
|
||||||
|
大阵雪: '❄️', 雷雨: '⛈️', 雷雨伴冰雹: '⛈️', 强雷雨伴冰雹: '⛈️',
|
||||||
|
未知: '🌡️'
|
||||||
|
};
|
||||||
|
|
||||||
|
const form = document.getElementById('form');
|
||||||
|
const city = document.getElementById('city');
|
||||||
|
const btn = document.getElementById('btn');
|
||||||
|
const load = document.getElementById('load');
|
||||||
|
const err = document.getElementById('err');
|
||||||
|
const result = document.getElementById('result');
|
||||||
|
|
||||||
|
let summary = null;
|
||||||
|
let chartUrl = null;
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
if (!summary && !chartUrl) return;
|
||||||
|
let h = '';
|
||||||
|
if (summary) {
|
||||||
|
h += '<div class="days">' + summary.summary.map(s =>
|
||||||
|
`<div class="day"><div class="w">${s.week} ${s.date.slice(5)}</div><div class="ico">${ICO[s.weather] || '🌡️'}</div><div class="tmp">${s.weather}</div><div class="range">${s.min}° ~ ${s.max}°</div></div>`
|
||||||
|
).join('') + '</div>';
|
||||||
|
}
|
||||||
|
if (chartUrl) {
|
||||||
|
h += '<a class="link" href="' + chartUrl + '" target="_blank">查看温度变化曲线图 →</a>';
|
||||||
|
}
|
||||||
|
result.innerHTML = h;
|
||||||
|
result.classList.add('show');
|
||||||
|
}
|
||||||
|
|
||||||
|
form.addEventListener('submit', async e => {
|
||||||
|
e.preventDefault();
|
||||||
|
const c = city.value.trim();
|
||||||
|
if (!c) {
|
||||||
|
err.textContent = '请输入城市名称';
|
||||||
|
err.style.display = 'block';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
btn.disabled = true;
|
||||||
|
err.style.display = 'none';
|
||||||
|
result.classList.remove('show');
|
||||||
|
result.innerHTML = '';
|
||||||
|
summary = null;
|
||||||
|
chartUrl = null;
|
||||||
|
load.style.display = 'block';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const r = await fetch('/api/weather', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ city: c })
|
||||||
|
});
|
||||||
|
if (!r.ok) throw new Error('请求失败 HTTP ' + r.status);
|
||||||
|
|
||||||
|
const reader = r.body.getReader();
|
||||||
|
const dec = new TextDecoder();
|
||||||
|
let buf = '';
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
buf += dec.decode(value, { stream: true });
|
||||||
|
let idx;
|
||||||
|
while ((idx = buf.indexOf('\n\n')) >= 0) {
|
||||||
|
const block = buf.slice(0, idx);
|
||||||
|
buf = buf.slice(idx + 2);
|
||||||
|
let ev = 'message';
|
||||||
|
let data = '';
|
||||||
|
for (const line of block.split('\n')) {
|
||||||
|
if (line.startsWith('event:')) ev = line.slice(6).trim();
|
||||||
|
else if (line.startsWith('data:')) data += line.slice(5).trim();
|
||||||
|
}
|
||||||
|
if (ev === 'meta') {
|
||||||
|
try { load.innerHTML = '<span class="spin"></span>' + JSON.parse(data).message; } catch {}
|
||||||
|
} else if (ev === 'summary') {
|
||||||
|
try { summary = JSON.parse(data); render(); } catch {}
|
||||||
|
} else if (ev === 'chart') {
|
||||||
|
try { chartUrl = JSON.parse(data).chartUrl; render(); } catch {}
|
||||||
|
} else if (ev === 'error') {
|
||||||
|
try { err.textContent = '出错了:' + JSON.parse(data).message; err.style.display = 'block'; } catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e2) {
|
||||||
|
err.textContent = '出错了:' + e2.message;
|
||||||
|
err.style.display = 'block';
|
||||||
|
} finally {
|
||||||
|
btn.disabled = false;
|
||||||
|
load.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
const http = require('http');
|
||||||
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
const BASE = process.env.CODEBUDDY_BASE || 'http://127.0.0.1:8080';
|
||||||
|
const WORKSPACE = process.env.WORKSPACE || path.resolve(__dirname);
|
||||||
|
const WEEK = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||||
|
|
||||||
|
function getPassword() {
|
||||||
|
if (process.env.CODEBUDDY_PASSWORD) return process.env.CODEBUDDY_PASSWORD;
|
||||||
|
try {
|
||||||
|
const s = JSON.parse(fs.readFileSync(path.join(os.homedir(), '.codebuddy', 'settings.json'), 'utf8'));
|
||||||
|
return s.gateway?.password || s.password || null;
|
||||||
|
} catch { return null; }
|
||||||
|
}
|
||||||
|
function getAuthHeaders() {
|
||||||
|
const p = getPassword();
|
||||||
|
if (!p) throw new Error('无法读取 CodeBuddy 鉴权密码');
|
||||||
|
return { 'X-CodeBuddy-Request': '1', Authorization: 'Bearer ' + p };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createJob(prompt, agent) {
|
||||||
|
const res = await fetch(`${BASE}/api/v1/jobs`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json', ...getAuthHeaders() },
|
||||||
|
body: JSON.stringify({ prompt, cwd: WORKSPACE, agent }),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error('创建任务失败 HTTP ' + res.status);
|
||||||
|
const j = await res.json();
|
||||||
|
const id = j.data?.id || j.id;
|
||||||
|
if (!id) throw new Error('创建任务失败:无任务ID');
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseSSE(chunk, onData) {
|
||||||
|
let buf = chunk, idx;
|
||||||
|
while ((idx = buf.indexOf('\n\n')) >= 0) {
|
||||||
|
const block = buf.slice(0, idx);
|
||||||
|
buf = buf.slice(idx + 2);
|
||||||
|
for (const line of block.split('\n')) if (line.startsWith('data:')) onData(line.slice(5).trim());
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function collectText(jobId) {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const res = await fetch(`${BASE}/api/v1/jobs/${jobId}/stream`, { headers: getAuthHeaders(), signal: controller.signal });
|
||||||
|
if (!res.ok) throw new Error('订阅流失败 HTTP ' + res.status);
|
||||||
|
|
||||||
|
const poll = setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const r = await fetch(`${BASE}/api/v1/jobs/${jobId}`, { headers: getAuthHeaders() });
|
||||||
|
const d = (await r.json()).data || {};
|
||||||
|
const job = d.job || d;
|
||||||
|
if (job.settled) { clearInterval(poll); setTimeout(() => controller.abort(), 800); }
|
||||||
|
} catch {}
|
||||||
|
}, 2000);
|
||||||
|
const timeout = setTimeout(() => controller.abort(), 300000);
|
||||||
|
|
||||||
|
const reader = res.body.getReader();
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
let buf = '', text = '';
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
buf += decoder.decode(value, { stream: true });
|
||||||
|
buf = parseSSE(buf, (d) => {
|
||||||
|
try {
|
||||||
|
const o = JSON.parse(d);
|
||||||
|
if (o.type === 'message' && o.role === 'assistant' && Array.isArray(o.content))
|
||||||
|
for (const c of o.content) if (c.type === 'output_text' && c.text) text += c.text;
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) { if (e.name !== 'AbortError') throw e; }
|
||||||
|
finally { clearInterval(poll); clearTimeout(timeout); }
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractJson(text) {
|
||||||
|
const f = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
||||||
|
const a = text.indexOf('{'), b = text.lastIndexOf('}');
|
||||||
|
const cands = [];
|
||||||
|
if (f) cands.push(f[1].trim());
|
||||||
|
if (a >= 0 && b > a) cands.push(text.slice(a, b + 1));
|
||||||
|
for (const c of cands) { try { return JSON.parse(c); } catch {} }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
||||||
|
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
|
||||||
|
if (req.method === 'OPTIONS') { res.writeHead(204); return res.end(); }
|
||||||
|
const url = new URL(req.url, 'http://localhost');
|
||||||
|
|
||||||
|
if (req.method === 'GET') {
|
||||||
|
let file = null;
|
||||||
|
if (url.pathname === '/' || url.pathname === '/index.html') file = path.join(__dirname, 'public', 'index.html');
|
||||||
|
else if (url.pathname.startsWith('/charts/')) file = path.join(__dirname, 'public', 'charts', path.basename(url.pathname));
|
||||||
|
if (file && fs.existsSync(file)) { res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end(fs.readFileSync(file)); }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.method === 'POST' && url.pathname === '/api/weather') {
|
||||||
|
let body = '';
|
||||||
|
req.on('data', c => body += c);
|
||||||
|
req.on('end', async () => {
|
||||||
|
let city = '';
|
||||||
|
try { city = (JSON.parse(body || '{}').city || '').trim(); } catch {}
|
||||||
|
if (!city) { res.writeHead(400, { 'Content-Type': 'application/json; charset=utf-8' }); return res.end(JSON.stringify({ error: '请提供城市名称' })); }
|
||||||
|
res.writeHead(200, { 'Content-Type': 'text/event-stream; charset=utf-8', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
|
||||||
|
const send = (event, data) => res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
|
||||||
|
(async () => {
|
||||||
|
const t0 = Date.now();
|
||||||
|
try {
|
||||||
|
send('meta', { stage: 'node1', message: '节点1:调用 weather Agent 查询未来3天天气…' });
|
||||||
|
const id1 = await createJob(`请查询「${city}」未来3天的天气,并按你的输出格式返回 JSON。`, 'weather');
|
||||||
|
const t1 = Date.now();
|
||||||
|
const wtext = await collectText(id1);
|
||||||
|
const t2 = Date.now();
|
||||||
|
const weather = extractJson(wtext);
|
||||||
|
if (!weather || !Array.isArray(weather.days)) throw new Error('天气数据解析失败');
|
||||||
|
|
||||||
|
const summary = weather.days.map(d => ({
|
||||||
|
date: d.date, week: WEEK[new Date(d.date + 'T00:00:00').getDay()],
|
||||||
|
max: d.max, min: d.min, weather: d.desc || '未知',
|
||||||
|
}));
|
||||||
|
send('summary', { city: weather.city || city, summary });
|
||||||
|
|
||||||
|
send('meta', { stage: 'node2', message: '节点2:调用 chart Agent 生成曲线图…' });
|
||||||
|
const id2 = await createJob(`请把以下天气数据生成温度曲线图:\n${JSON.stringify(weather)}`, 'chart');
|
||||||
|
const t3 = Date.now();
|
||||||
|
const ctext = await collectText(id2);
|
||||||
|
const t4 = Date.now();
|
||||||
|
const info = extractJson(ctext);
|
||||||
|
const file = info?.file;
|
||||||
|
if (!file) throw new Error('图表生成失败');
|
||||||
|
|
||||||
|
send('chart', { chartUrl: '/charts/' + file });
|
||||||
|
send('done', {});
|
||||||
|
console.log(`[计时] 节点1 创建=${t1 - t0}ms 执行=${t2 - t1}ms | 节点2 创建=${t3 - t2}ms 执行=${t4 - t3}ms | 总计=${t4 - t0}ms`);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`[计时] 失败于 ${Date.now() - t0}ms: ${e && e.message}`);
|
||||||
|
send('error', { message: String(e && e.message || e) });
|
||||||
|
} finally {
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.writeHead(404, { 'Content-Type': 'application/json; charset=utf-8' });
|
||||||
|
res.end(JSON.stringify({ error: 'not found' }));
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(PORT, () => console.log(`页面: http://localhost:${PORT}`));
|
||||||
Reference in New Issue
Block a user