geqintan commited on
Commit
db7fef9
·
1 Parent(s): 4b2a02f
Files changed (2) hide show
  1. apps/airs_tasks.py +87 -44
  2. memory-bank/progress.md +1 -0
apps/airs_tasks.py CHANGED
@@ -91,58 +91,58 @@ class Tasks(Base): # Tasks 类继承自 Base 类
91
  except Exception as e:
92
  return {"success": False, "error": str(e)}
93
 
94
- @self.mcp.tool()
95
- def get_tasks(
96
- status: Optional[str] = None,
97
- priority: Optional[str] = None
98
- ) -> dict:
99
- """
100
- 获取数据库中的任务列表(可选状态/优先级过滤)
101
- Get a list of tasks from the database, with optional filtering by status or priority.
102
 
103
- Args:
104
- status: 任务状态过滤值(可选)
105
- priority: 任务优先级过滤值(可选)
106
 
107
- Returns:
108
- {
109
- "success": True,
110
- "tasks": [...] # 成功时返回任务列表
111
- } or {
112
- "success": False,
113
- "error": "错误描述" # 失败时返回错误原因
114
- }
115
- """
116
- try:
117
- # 构造基础查询
118
- query = self.supabase.table('tasks').select('*')
119
 
120
- # 动态添加过滤条件
121
- if status:
122
- query = query.eq('status', status.lower()) # 添加状态小写转换保证一致性
123
- if priority:
124
- query = query.eq('priority', priority.lower())
125
 
126
- print("正在执行 Supabase 查询...")
127
- response = query.execute()
128
- print("Supabase 查询执行完成。")
129
 
130
- # 明确处理空结果(非错误状态)
131
- if not response.data:
132
- print("未找到任务。")
133
- return {"success": True, "tasks": []}
134
 
135
- print(f"找到 {len(response.data)} 个任务。")
136
 
137
- return {"success": True, "tasks": response.data}
138
 
139
- except Exception as e:
140
- # 捕获具体异常类型
141
- error_msg = (
142
- f"Database query failed: {str(e)}. "
143
- f"Params: status={status}, priority={priority}"
144
- )
145
- return {"success": False, "error": error_msg}
146
 
147
 
148
  @self.mcp.tool()
@@ -178,3 +178,46 @@ class Tasks(Base): # Tasks 类继承自 Base 类
178
  return {"success": False, "error": response.error.message if response.error else "Task not found or unknown error"}
179
  except Exception as e:
180
  return {"success": False, "error": str(e)}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  except Exception as e:
92
  return {"success": False, "error": str(e)}
93
 
94
+ # @self.mcp.tool()
95
+ # def get_tasks(
96
+ # status: Optional[str] = None,
97
+ # priority: Optional[str] = None
98
+ # ) -> dict:
99
+ # """
100
+ # 获取数据库中的任务列表(可选状态/优先级过滤)
101
+ # Get a list of tasks from the database, with optional filtering by status or priority.
102
 
103
+ # Args:
104
+ # status: 任务状态过滤值(可选)
105
+ # priority: 任务优先级过滤值(可选)
106
 
107
+ # Returns:
108
+ # {
109
+ # "success": True,
110
+ # "tasks": [...] # 成功时返回任务列表
111
+ # } or {
112
+ # "success": False,
113
+ # "error": "错误描述" # 失败时返回错误原因
114
+ # }
115
+ # """
116
+ # try:
117
+ # # 构造基础查询
118
+ # query = self.supabase.table('tasks').select('*')
119
 
120
+ # # 动态添加过滤条件
121
+ # if status:
122
+ # query = query.eq('status', status.lower()) # 添加状态小写转换保证一致性
123
+ # if priority:
124
+ # query = query.eq('priority', priority.lower())
125
 
126
+ # print("正在执行 Supabase 查询...")
127
+ # response = query.execute()
128
+ # print("Supabase 查询执行完成。")
129
 
130
+ # # 明确处理空结果(非错误状态)
131
+ # if not response.data:
132
+ # print("未找到任务。")
133
+ # return {"success": True, "tasks": []}
134
 
135
+ # print(f"找到 {len(response.data)} 个任务。")
136
 
137
+ # return {"success": True, "tasks": response.data}
138
 
139
+ # except Exception as e:
140
+ # # 捕获具体异常类型
141
+ # error_msg = (
142
+ # f"Database query failed: {str(e)}. "
143
+ # f"Params: status={status}, priority={priority}"
144
+ # )
145
+ # return {"success": False, "error": error_msg}
146
 
147
 
148
  @self.mcp.tool()
 
178
  return {"success": False, "error": response.error.message if response.error else "Task not found or unknown error"}
179
  except Exception as e:
180
  return {"success": False, "error": str(e)}
181
+
182
+
183
+
184
+
185
+ @self.mcp.tool()
186
+ def get_tasks(
187
+ status: Optional[str] = None,
188
+ priority: Optional[str] = None
189
+ ) -> dict:
190
+ """
191
+ 获取数据库中的任务列表(可选状态/优先级过滤)
192
+ """
193
+ try:
194
+ return {"success": True, "tasks": [{"title": "示例任务", "description": "这是一个示例任务"}]}
195
+ # 构造基础查询
196
+ query = self.supabase.table('tasks').select('*')
197
+
198
+ # 动态添加过滤条件
199
+ if status:
200
+ query = query.eq('status', status.lower()) # 添加状态小写转换保证一致性
201
+ if priority:
202
+ query = query.eq('priority', priority.lower())
203
+
204
+ print("正在执行 Supabase 查询...")
205
+ response = query.execute()
206
+ print("Supabase 查询执行完成。")
207
+
208
+ # 明确处理空结果(非错误状态)
209
+ if not response.data:
210
+ print("未找到任务。")
211
+ return {"success": True, "tasks": []}
212
+
213
+ print(f"找到 {len(response.data)} 个任务。")
214
+
215
+ return {"success": True, "tasks": response.data}
216
+
217
+ except Exception as e:
218
+ # 捕获具体异常类型
219
+ error_msg = (
220
+ f"Database query failed: {str(e)}. "
221
+ f"Params: status={status}, priority={priority}"
222
+ )
223
+ return {"success": False, "error": error_msg}
memory-bank/progress.md CHANGED
@@ -18,3 +18,4 @@
18
 
19
  **已知问题:**
20
  - 在服务重启后,可能需要短暂等待才能成功调用新添加的工具(可能是初始化时间)。
 
 
18
 
19
  **已知问题:**
20
  - 在服务重启后,可能需要短暂等待才能成功调用新添加的工具(可能是初始化时间)。
21
+ - `get_tasks`工具在n8n环境中出现错误。