myagent-ai 1.27.3 → 1.27.4
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/core/agent_storage.py +4 -4
- package/core/utils.py +18 -4
- package/package.json +1 -1
- package/web/api_server.py +7 -6
package/core/agent_storage.py
CHANGED
|
@@ -23,7 +23,7 @@ from pathlib import Path
|
|
|
23
23
|
from typing import Any, Dict, List, Optional
|
|
24
24
|
|
|
25
25
|
from core.logger import get_logger
|
|
26
|
-
from core.utils import generate_id
|
|
26
|
+
from core.utils import next_agent_id, generate_id
|
|
27
27
|
|
|
28
28
|
logger = get_logger("myagent.agent_storage")
|
|
29
29
|
|
|
@@ -243,7 +243,7 @@ class AgentStorage:
|
|
|
243
243
|
conn = self._get_conn()
|
|
244
244
|
now = _now_iso()
|
|
245
245
|
if not cfg.id:
|
|
246
|
-
cfg.id =
|
|
246
|
+
cfg.id = next_agent_id()
|
|
247
247
|
if not cfg.created_at:
|
|
248
248
|
cfg.created_at = now
|
|
249
249
|
if not cfg.updated_at:
|
|
@@ -433,8 +433,8 @@ class AgentStorage:
|
|
|
433
433
|
rel_path = cfg_path.parent.relative_to(agents_dir).as_posix()
|
|
434
434
|
|
|
435
435
|
# 补全缺失字段
|
|
436
|
-
if "id" not in raw or not raw["id"]
|
|
437
|
-
raw["id"] =
|
|
436
|
+
if "id" not in raw or not raw["id"]:
|
|
437
|
+
raw["id"] = next_agent_id()
|
|
438
438
|
if "created_at" not in raw or not raw["created_at"]:
|
|
439
439
|
raw["created_at"] = now
|
|
440
440
|
if "updated_at" not in raw or not raw["updated_at"]:
|
package/core/utils.py
CHANGED
|
@@ -10,6 +10,7 @@ import time
|
|
|
10
10
|
import re
|
|
11
11
|
from datetime import datetime, timezone
|
|
12
12
|
from zoneinfo import ZoneInfo
|
|
13
|
+
from pathlib import Path
|
|
13
14
|
from typing import Any, Dict, Optional, TypeVar
|
|
14
15
|
|
|
15
16
|
T = TypeVar("T")
|
|
@@ -42,12 +43,25 @@ def timestamp_ms() -> int:
|
|
|
42
43
|
return int(time.time() * 1000)
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
_AGENT_ID_SEQ = Path.home() / ".myagent" / "data" / ".agent_id_seq"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def next_agent_id() -> int:
|
|
50
|
+
"""自增数字 Agent ID (1, 2, 3, ...)"""
|
|
51
|
+
_AGENT_ID_SEQ.parent.mkdir(parents=True, exist_ok=True)
|
|
52
|
+
try:
|
|
53
|
+
cur = int(_AGENT_ID_SEQ.read_text().strip())
|
|
54
|
+
except (FileNotFoundError, ValueError):
|
|
55
|
+
cur = 0
|
|
56
|
+
cur += 1
|
|
57
|
+
_AGENT_ID_SEQ.write_text(str(cur))
|
|
58
|
+
return cur
|
|
59
|
+
|
|
60
|
+
|
|
45
61
|
def generate_id(prefix: str = "") -> str:
|
|
46
|
-
"""
|
|
62
|
+
"""生成唯一 ID"""
|
|
47
63
|
import random
|
|
48
|
-
|
|
49
|
-
rand = str(random.randint(10000, 99999))
|
|
50
|
-
uid = f"{ts}{rand}"
|
|
64
|
+
uid = uuid.uuid4().hex[:12]
|
|
51
65
|
return f"{prefix}_{uid}" if prefix else uid
|
|
52
66
|
|
|
53
67
|
|
package/package.json
CHANGED
package/web/api_server.py
CHANGED
|
@@ -14,6 +14,7 @@ from core.llm import Message
|
|
|
14
14
|
from config import ModelEntry, ChatPlatformConfig
|
|
15
15
|
import datetime
|
|
16
16
|
import uuid
|
|
17
|
+
from core.utils import next_agent_id
|
|
17
18
|
from web.tts_handler import synthesize, preprocess_for_tts, AVAILABLE_VOICES
|
|
18
19
|
|
|
19
20
|
logger = get_logger("myagent.api")
|
|
@@ -3181,7 +3182,7 @@ window.addEventListener('beforeunload', function() {{
|
|
|
3181
3182
|
ad.mkdir(parents=True, exist_ok=True)
|
|
3182
3183
|
now = _now_iso()
|
|
3183
3184
|
cfg = {
|
|
3184
|
-
"id":
|
|
3185
|
+
"id": next_agent_id(),
|
|
3185
3186
|
"name": "全权Agent",
|
|
3186
3187
|
"description": "全权Agent - 拥有完整权限的本地助手",
|
|
3187
3188
|
"avatar_color": _agent_color("全权Agent"),
|
|
@@ -3229,7 +3230,7 @@ window.addEventListener('beforeunload', function() {{
|
|
|
3229
3230
|
if ad.exists():
|
|
3230
3231
|
now = _now_iso()
|
|
3231
3232
|
cfg = {
|
|
3232
|
-
"id":
|
|
3233
|
+
"id": next_agent_id(),
|
|
3233
3234
|
"name": path,
|
|
3234
3235
|
"description": "",
|
|
3235
3236
|
"avatar_emoji": "🤖",
|
|
@@ -3243,8 +3244,8 @@ window.addEventListener('beforeunload', function() {{
|
|
|
3243
3244
|
return
|
|
3244
3245
|
changed = False
|
|
3245
3246
|
now = _now_iso()
|
|
3246
|
-
if "id" not in cfg
|
|
3247
|
-
cfg["id"] =
|
|
3247
|
+
if "id" not in cfg:
|
|
3248
|
+
cfg["id"] = next_agent_id()
|
|
3248
3249
|
changed = True
|
|
3249
3250
|
if "created_at" not in cfg:
|
|
3250
3251
|
cfg["created_at"] = now
|
|
@@ -3270,7 +3271,7 @@ window.addEventListener('beforeunload', function() {{
|
|
|
3270
3271
|
ad.mkdir(parents=True, exist_ok=True)
|
|
3271
3272
|
now = _now_iso()
|
|
3272
3273
|
cfg = {
|
|
3273
|
-
"id":
|
|
3274
|
+
"id": next_agent_id(),
|
|
3274
3275
|
"name": "配置助手",
|
|
3275
3276
|
"description": "MyAgent 智能配置助手 - 内置系统Agent,帮助用户完成初始配置和日常配置管理",
|
|
3276
3277
|
"avatar_color": "#4f46e5",
|
|
@@ -3530,7 +3531,7 @@ window.addEventListener('beforeunload', function() {{
|
|
|
3530
3531
|
|
|
3531
3532
|
now = _now_iso()
|
|
3532
3533
|
cfg = {
|
|
3533
|
-
"id":
|
|
3534
|
+
"id": next_agent_id(),
|
|
3534
3535
|
"name": name,
|
|
3535
3536
|
"description": data.get("description", ""),
|
|
3536
3537
|
"avatar_color": data.get("avatar_color") or _agent_color(name),
|