@syengup/fridaynext-hermes-channel 0.1.0-beta.2 → 0.1.0-beta.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/README.md +2 -2
- package/install-config.js +67 -0
- package/install-runtime.js +18 -9
- package/install.js +6 -4
- package/package.json +2 -1
- package/plugin/README.md +2 -2
- package/plugin/fridaynext_plugin/__init__.py +10 -0
- package/plugin/fridaynext_plugin/adapter.py +231 -12
- package/plugin/fridaynext_plugin/agent_management.py +158 -0
- package/plugin/fridaynext_plugin/canonical_control.py +12 -4
- package/plugin/fridaynext_plugin/compat_v0225.py +1247 -4
- package/plugin/fridaynext_plugin/continuations.py +271 -0
- package/plugin/fridaynext_plugin/device-tools-v1.json +302 -0
- package/plugin/fridaynext_plugin/device_tools.py +144 -0
- package/plugin/fridaynext_plugin/history.py +25 -3
- package/plugin/fridaynext_plugin/host.py +7 -4
- package/plugin/fridaynext_plugin/media_input.py +56 -9
- package/plugin/fridaynext_plugin/message_speech.py +143 -0
- package/plugin/fridaynext_plugin/multi_agent.py +221 -0
- package/plugin/fridaynext_plugin/reply_context.py +39 -0
- package/plugin/fridaynext_plugin/runtime_port.py +23 -1
- package/plugin/fridaynext_plugin/scheduled_tasks.py +229 -0
- package/plugin/fridaynext_plugin/settings.py +7 -3
- package/plugin/fridaynext_plugin/slash_commands.py +163 -0
- package/plugin/fridaynext_plugin/stream_bridge.py +83 -26
- package/plugin/fridaynext_plugin/stream_projection.py +30 -6
- package/plugin/fridaynext_plugin/subagents.py +228 -0
- package/plugin/plugin.yaml +11 -0
- package/plugin/runtime/dist/commands-routes.js +94 -0
- package/plugin/runtime/dist/device-tools-v1.json +302 -0
- package/plugin/runtime/dist/hosted-backend.js +293 -25
- package/plugin/runtime/dist/hosted-continuations.js +41 -0
- package/plugin/runtime/dist/hosted-device-tools.js +82 -0
- package/plugin/runtime/dist/hosted-media.js +54 -13
- package/plugin/runtime/dist/hosted-stream.js +124 -14
- package/plugin/runtime/dist/hosted-subagents.js +78 -0
- package/plugin/runtime/dist/platform-service.js +4 -0
- package/plugin/runtime/dist/plugin-control.js +10 -6
- package/plugin/runtime/dist/scheduled-routes.js +63 -0
- package/plugin/runtime/dist/service-host.js +40 -5
- package/plugin/runtime/dist/speech-routes.js +111 -0
- package/plugin/runtime/dist/tool-presentation.js +399 -0
- package/plugin/runtime/node_modules/.package-lock.json +6 -6
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/API.md +125 -5
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/README.md +21 -1
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/history.d.ts +1 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/history.js +3 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/operations.d.ts +136 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/operations.js +105 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/settings-schema.d.ts +3 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/settings-schema.js +45 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/tool-presentation.d.ts +10 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/tool-presentation.js +2 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/types.d.ts +27 -2
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/types.js +1 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/work-context.d.ts +56 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/work-context.js +60 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/device-request/pending-store.js +3 -3
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/index.d.ts +5 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/index.js +5 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/canonical-update-batcher.d.ts +26 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/canonical-update-batcher.js +112 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/channel-kernel.d.ts +4 -1
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/channel-kernel.js +30 -5
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/durable-run-store.d.ts +18 -1
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/durable-run-store.js +187 -51
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/runner.d.ts +1 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/runner.js +52 -2
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/work-context.d.ts +13 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/work-context.js +73 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/service/channel-service.js +1 -1
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/command-lifecycle.d.ts +47 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/command-lifecycle.js +184 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/controls.d.ts +1 -1
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/controls.js +11 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/messages.js +12 -6
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/operations.d.ts +13 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/operations.js +336 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/runtime.d.ts +1 -0
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/runtime.js +52 -10
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/session-settings.js +38 -6
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/sessions.js +8 -8
- package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/package.json +6 -7
- package/plugin/runtime/node_modules/tslib/README.md +3 -8
- package/plugin/runtime/node_modules/tslib/package.json +1 -1
- package/plugin/runtime/node_modules/tslib/tslib.d.ts +4 -2
- package/plugin/runtime/node_modules/tslib/tslib.es6.js +10 -1
- package/plugin/runtime/node_modules/tslib/tslib.es6.mjs +10 -1
- package/plugin/runtime/node_modules/tslib/tslib.js +10 -1
- package/plugin/runtime/package-lock.json +7 -7
- package/plugin/runtime/package.json +1 -1
- package/plugin/tools.py +3 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"""Hermes标准平台适配:消息由GatewayRunner授权/执行,Kit仅接收规范端口。"""
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
|
+
import copy
|
|
5
|
+
import contextvars
|
|
4
6
|
import hashlib
|
|
5
7
|
import json
|
|
6
8
|
import logging
|
|
@@ -13,6 +15,8 @@ from pathlib import Path
|
|
|
13
15
|
from gateway.config import Platform
|
|
14
16
|
from gateway.platforms.base import BasePlatformAdapter, SendResult
|
|
15
17
|
from gateway.platforms.event import MessageEvent, MessageType
|
|
18
|
+
from . import reply_context
|
|
19
|
+
from .slash_commands import SlashCommandsPort, split_options as split_command_options
|
|
16
20
|
from gateway.platforms._shared import get_scoped_secret
|
|
17
21
|
from hermes_constants import get_hermes_home
|
|
18
22
|
from plugins.plugin_storage import plugin_data_dir
|
|
@@ -23,8 +27,12 @@ from .history import HistoryReader
|
|
|
23
27
|
from .sessions import SessionDirectory, SessionCatalog
|
|
24
28
|
from .canonical_control import NativeControlError
|
|
25
29
|
from .stream_bridge import StreamBridge
|
|
30
|
+
from .subagents import SubagentObserver
|
|
31
|
+
from .continuations import ContinuationObserver
|
|
26
32
|
from .settings import SettingsPort
|
|
27
33
|
from .agent_defaults import AgentDefaultsPort
|
|
34
|
+
from .agent_management import AgentManagementPort
|
|
35
|
+
from .scheduled_tasks import ScheduledTasksPort
|
|
28
36
|
from .settings_control import SettingsControl
|
|
29
37
|
from .initial_settings import InitialSettings
|
|
30
38
|
from .diagnostics import api_failure
|
|
@@ -33,6 +41,7 @@ from . import media_input
|
|
|
33
41
|
from . import media_output
|
|
34
42
|
from . import inline_media
|
|
35
43
|
from . import compat_v0225
|
|
44
|
+
from .message_speech import MessageSpeechPort
|
|
36
45
|
from .compat_v0225 import MediaDeliveryBoundary
|
|
37
46
|
from .delivery_context import owned_delivery, current_delivery, check_delivery
|
|
38
47
|
from .controls import ControlCoordinator
|
|
@@ -65,6 +74,8 @@ def cancel_event(trace, event, **fields):
|
|
|
65
74
|
|
|
66
75
|
class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
67
76
|
instances = weakref.WeakSet()
|
|
77
|
+
# 本平台负责长文本持久交付;让宿主跳过4000字符备用截断。超过256KiB明确失败,不静默丢尾。
|
|
78
|
+
splits_long_messages = True
|
|
68
79
|
|
|
69
80
|
def __init__(self, config):
|
|
70
81
|
super().__init__(config, Platform("fridaynext"))
|
|
@@ -112,8 +123,16 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
112
123
|
self.stopping = None
|
|
113
124
|
self.session_directory = None
|
|
114
125
|
self.streams = None
|
|
126
|
+
self.subagent_observer = None
|
|
127
|
+
self.continuation_observer = None
|
|
115
128
|
self._carry_allowlist(extra)
|
|
116
129
|
|
|
130
|
+
def _continuations(self):
|
|
131
|
+
if getattr(self, "continuation_observer", None) is None:
|
|
132
|
+
self.continuation_observer = ContinuationObserver(self)
|
|
133
|
+
self.continuation_observer.rebind()
|
|
134
|
+
return self.continuation_observer
|
|
135
|
+
|
|
117
136
|
# 后台重连会重建适配器:此时若已在别的 secret scope 里,`platform_gate_env` 的
|
|
118
137
|
# scoped miss 不再回落到 os.environ,allowlist 读到空值 → 所有入站变 Unauthorized
|
|
119
138
|
# (FN-169)。插件平台本来就把允许列表放在 extra.allowed_users 里由授权层读取,
|
|
@@ -186,7 +205,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
186
205
|
return self.settings_port
|
|
187
206
|
|
|
188
207
|
def _input_media_constraint(self):
|
|
189
|
-
"""
|
|
208
|
+
"""附件输入的公开能力约束:MIME、数量与原 owner profile 的实际字节上限。
|
|
190
209
|
|
|
191
210
|
公开描述面只有这一处声明;读不到限制(运行未就绪、profile 未服务)时返回 None,
|
|
192
211
|
由客户端按能力缺失处理,不声明猜测值。maxBytes 是原 profile 的整批上限,
|
|
@@ -208,7 +227,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
208
227
|
return None
|
|
209
228
|
return {
|
|
210
229
|
"scope": "service",
|
|
211
|
-
"mimeTypes": sorted(media_input.MIMES),
|
|
230
|
+
"mimeTypes": sorted(set(media_input.MIMES) | (set(values.get("fileMimeTypes", ())) & media_input.FILE_MIMES)),
|
|
212
231
|
"maxCount": max_count,
|
|
213
232
|
"maxBytes": max_bytes,
|
|
214
233
|
"permission": "allowed",
|
|
@@ -255,6 +274,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
255
274
|
try:
|
|
256
275
|
self.data.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
257
276
|
self.bindings = Bindings(self.data, self.profile)
|
|
277
|
+
self.subagent_observer = SubagentObserver(self)
|
|
258
278
|
public = self.data / "public-access.json"
|
|
259
279
|
if not public.exists():
|
|
260
280
|
private_json(
|
|
@@ -269,9 +289,19 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
269
289
|
self.host = KitHost(
|
|
270
290
|
self, self.data, self.profile, self.node, self.entry
|
|
271
291
|
)
|
|
272
|
-
|
|
292
|
+
owner = compat_v0225.fridaynext_listener_owner(self)
|
|
293
|
+
if owner is not None:
|
|
294
|
+
from .multi_agent import SharedKitHost
|
|
295
|
+
self.host = SharedKitHost(owner, self)
|
|
296
|
+
self.service_id = owner.service_id
|
|
297
|
+
self.runtime.client.control_profile = str(owner.profile)
|
|
298
|
+
ready = await asyncio.shield(owner.host.ready)
|
|
299
|
+
else:
|
|
300
|
+
ready = await self.host.start()
|
|
273
301
|
self._wire_plugin_handlers(None)
|
|
274
302
|
self._mark_connected(listener_base=ready["origin"])
|
|
303
|
+
self.subagent_observer.restore()
|
|
304
|
+
self._continuations()
|
|
275
305
|
self.media_recovery_task = asyncio.create_task(media_output.restore(self))
|
|
276
306
|
return True
|
|
277
307
|
except Exception as error:
|
|
@@ -315,6 +345,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
315
345
|
|
|
316
346
|
@classmethod
|
|
317
347
|
def record_reasoning_delta(cls, **event):
|
|
348
|
+
cls.record_subagent_event("stream.delta", event)
|
|
318
349
|
# 官方observer已离开token路径,并保留原Profile及输入上下文;不创建逐token异步任务。
|
|
319
350
|
if event.get("kind") != "reasoning":
|
|
320
351
|
return
|
|
@@ -326,6 +357,60 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
326
357
|
if locator is not None:
|
|
327
358
|
locator.publish_reasoning(event)
|
|
328
359
|
|
|
360
|
+
@classmethod
|
|
361
|
+
def record_subagent_event(cls, kind, event):
|
|
362
|
+
profile = Path(get_hermes_home()).resolve()
|
|
363
|
+
for adapter in tuple(cls.instances):
|
|
364
|
+
loop = getattr(adapter, "owner_loop", None)
|
|
365
|
+
if adapter.profile == profile and adapter.plugin_enabled and loop is not None and not loop.is_closed():
|
|
366
|
+
# 公开hook的同tool ID并行门禁不能等待磁盘;保留产生事实的ContextVar后交接。
|
|
367
|
+
fields = ("session_id", "parent_session_id", "child_session_id", "parent_subagent_id", "child_subagent_id",
|
|
368
|
+
"child_goal", "child_status", "child_summary", "kind", "delta", "turn_id", "iteration",
|
|
369
|
+
"final_text", "finished", "tool_call_id", "tool_name", "args", "result", "status", "surface")
|
|
370
|
+
payload = copy.deepcopy({key: event[key] for key in fields if key in event})
|
|
371
|
+
for observer in (getattr(adapter, "subagent_observer", None), getattr(adapter, "continuation_observer", None)):
|
|
372
|
+
if observer is not None:
|
|
373
|
+
loop.call_soon_threadsafe(observer.observe, kind, payload, context=contextvars.copy_context())
|
|
374
|
+
|
|
375
|
+
@classmethod
|
|
376
|
+
def record_subagent_start(cls, **event):
|
|
377
|
+
cls.record_subagent_event("start", event)
|
|
378
|
+
|
|
379
|
+
@classmethod
|
|
380
|
+
def record_subagent_stop(cls, **event):
|
|
381
|
+
cls.record_subagent_event("stop", event)
|
|
382
|
+
|
|
383
|
+
@classmethod
|
|
384
|
+
def record_subagent_stream_end(cls, **event):
|
|
385
|
+
cls.record_subagent_event("stream.end", event)
|
|
386
|
+
|
|
387
|
+
@classmethod
|
|
388
|
+
def record_subagent_tools_planned(cls, **event):
|
|
389
|
+
# pre_tool_call是策略钩子,并行重入会fail-closed;只从公开响应观察工具计划。
|
|
390
|
+
response = event.get("response")
|
|
391
|
+
message = response.get("assistant_message", {}) if isinstance(response, dict) else {}
|
|
392
|
+
calls = message.get("tool_calls", []) if isinstance(message, dict) else []
|
|
393
|
+
for call in calls if isinstance(calls, list) else []:
|
|
394
|
+
if not isinstance(call, dict):
|
|
395
|
+
continue
|
|
396
|
+
function = call.get("function", call)
|
|
397
|
+
if not isinstance(function, dict) or not isinstance(function.get("name"), str) or not function["name"]:
|
|
398
|
+
continue
|
|
399
|
+
args = function.get("arguments", {})
|
|
400
|
+
if isinstance(args, str):
|
|
401
|
+
try:
|
|
402
|
+
args = json.loads(args)
|
|
403
|
+
except ValueError:
|
|
404
|
+
continue
|
|
405
|
+
if not isinstance(args, dict):
|
|
406
|
+
continue
|
|
407
|
+
cls.record_subagent_event("tool.start", {**event, "tool_call_id": call.get("id"),
|
|
408
|
+
"tool_name": function.get("name"), "args": args})
|
|
409
|
+
|
|
410
|
+
@classmethod
|
|
411
|
+
def record_subagent_tool_end(cls, **event):
|
|
412
|
+
cls.record_subagent_event("tool.complete", event)
|
|
413
|
+
|
|
329
414
|
@classmethod
|
|
330
415
|
def record_api_error(cls, **event):
|
|
331
416
|
native = event.get("session_id")
|
|
@@ -394,6 +479,12 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
394
479
|
self.stopping = None
|
|
395
480
|
|
|
396
481
|
async def _stop_host(self):
|
|
482
|
+
if getattr(self, "continuation_observer", None) is not None:
|
|
483
|
+
await self.continuation_observer.close()
|
|
484
|
+
self.continuation_observer = None
|
|
485
|
+
if getattr(self, "subagent_observer", None) is not None:
|
|
486
|
+
await self.subagent_observer.close()
|
|
487
|
+
self.subagent_observer = None
|
|
397
488
|
media_task = getattr(self, "media_recovery_task", None)
|
|
398
489
|
self.media_recovery_task = None
|
|
399
490
|
if media_task is not None and media_task is not asyncio.current_task():
|
|
@@ -408,6 +499,9 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
408
499
|
await host.stop()
|
|
409
500
|
if self.runtime is not None:
|
|
410
501
|
await self.runtime.close()
|
|
502
|
+
release = getattr(getattr(self.runtime, "locator", None), "release_device_identity", None)
|
|
503
|
+
if release is not None:
|
|
504
|
+
release()
|
|
411
505
|
self._release_platform_lock()
|
|
412
506
|
|
|
413
507
|
def worker_event(self, event):
|
|
@@ -569,10 +663,21 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
569
663
|
return {"state": "running"}
|
|
570
664
|
if row["status"] != "terminal":
|
|
571
665
|
return {"state": "unknown", "reason": "HOST_EXECUTION_UNKNOWN"}
|
|
666
|
+
lease = self._recovery().lease()
|
|
572
667
|
try:
|
|
573
668
|
result = await self._result(record)
|
|
574
669
|
except Exception:
|
|
575
670
|
result = None
|
|
671
|
+
if result and not record.get("legacy"):
|
|
672
|
+
try:
|
|
673
|
+
self._recovery().check(lease)
|
|
674
|
+
streams = self._streams()
|
|
675
|
+
if streams is not None:
|
|
676
|
+
await streams.publish_result_metadata(record, row, result)
|
|
677
|
+
except Exception as error:
|
|
678
|
+
# 元信息投递失败不改变宿主权威终态;重查时沿同一source重试。
|
|
679
|
+
logger.warning("presentation.metadata.unavailable runId=%s serviceId=%s errorCode=%s",
|
|
680
|
+
record["run_id"], self.service_id, getattr(error, "code", type(error).__name__))
|
|
576
681
|
if (
|
|
577
682
|
result is None
|
|
578
683
|
and row.get("outcome") == "completed"
|
|
@@ -648,6 +753,56 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
648
753
|
await media_output.media_observations.reconcile(self, record)
|
|
649
754
|
|
|
650
755
|
async def host_request(self, method, params):
|
|
756
|
+
from .multi_agent import route
|
|
757
|
+
return await route(self, method, params)
|
|
758
|
+
|
|
759
|
+
async def _host_request(self, method, params):
|
|
760
|
+
if method in ("commands.list", "commands.prepare", "commands.execute"):
|
|
761
|
+
if getattr(self, "slash_commands_port", None) is None:
|
|
762
|
+
self.slash_commands_port = SlashCommandsPort(self)
|
|
763
|
+
return await self.slash_commands_port.call(method, params)
|
|
764
|
+
if method == "device.check":
|
|
765
|
+
from .device_tools import check_call
|
|
766
|
+
return await check_call(self.host, params)
|
|
767
|
+
if method == "continuation.inspect":
|
|
768
|
+
if params.get("serviceInstanceId") != self.service_id:
|
|
769
|
+
raise NativeControlError("SERVICE_MISMATCH")
|
|
770
|
+
return {"inspection": self._continuations().inspect(params.get("runId"))}
|
|
771
|
+
if method == "subagent.inspect":
|
|
772
|
+
if params.get("serviceInstanceId") != self.service_id:
|
|
773
|
+
raise NativeControlError("SERVICE_MISMATCH")
|
|
774
|
+
observer = getattr(self, "subagent_observer", None)
|
|
775
|
+
return {"inspection": observer.inspect(params.get("runId")) if observer else {"state": "unknown", "reason": "SUBAGENT_OBSERVATION_UNAVAILABLE"}}
|
|
776
|
+
if method in ("schedule.delivery-check", "schedule.inspect"):
|
|
777
|
+
if params.get("serviceInstanceId") != self.service_id:
|
|
778
|
+
raise NativeControlError("SCHEDULE_SCOPE_CHANGED")
|
|
779
|
+
if getattr(self, "scheduled_tasks_port", None) is None:
|
|
780
|
+
self.scheduled_tasks_port = ScheduledTasksPort(self)
|
|
781
|
+
if method == "schedule.delivery-check":
|
|
782
|
+
return self.scheduled_tasks_port.check_delivery(params)
|
|
783
|
+
return {"inspection": await self.scheduled_tasks_port.inspect(params.get("runId"))}
|
|
784
|
+
if method == "schedule.operation":
|
|
785
|
+
if params.get("serviceInstanceId") != self.service_id:
|
|
786
|
+
raise NativeControlError("SCHEDULE_SCOPE_CHANGED")
|
|
787
|
+
if getattr(self, "scheduled_tasks_port", None) is None:
|
|
788
|
+
self.scheduled_tasks_port = ScheduledTasksPort(self)
|
|
789
|
+
return await self.scheduled_tasks_port.call(params.get("operation"), params.get("context", {}),
|
|
790
|
+
params.get("input", {}), params.get("inspect") is True)
|
|
791
|
+
if method == "agent.operation":
|
|
792
|
+
if params.get("serviceInstanceId") != self.service_id:
|
|
793
|
+
raise NativeControlError("SERVICE_MISMATCH")
|
|
794
|
+
if getattr(self, "agent_management_port", None) is None:
|
|
795
|
+
self.agent_management_port = AgentManagementPort(self)
|
|
796
|
+
return await self.agent_management_port.call(params.get("operation"), params.get("context", {}),
|
|
797
|
+
params.get("input", {}), params.get("inspect") is True)
|
|
798
|
+
if method in ("speech.config", "speech.speak"):
|
|
799
|
+
if params.get("serviceInstanceId") != self.service_id:
|
|
800
|
+
raise NativeControlError("SERVICE_MISMATCH")
|
|
801
|
+
if getattr(self, "message_speech_port", None) is None:
|
|
802
|
+
self.message_speech_port = MessageSpeechPort(self)
|
|
803
|
+
if method == "speech.config":
|
|
804
|
+
return await self.message_speech_port.config()
|
|
805
|
+
return await self.message_speech_port.speak(params.get("text"))
|
|
651
806
|
if method == "media.check":
|
|
652
807
|
if self.host is None:
|
|
653
808
|
raise NativeControlError("MEDIA_CALL_RETIRED")
|
|
@@ -710,7 +865,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
710
865
|
"sessions.title", "sessions.pin", "history.message-detail",
|
|
711
866
|
"sessions.settings", "sessions.settings.versioned-v1",
|
|
712
867
|
*(["agents.defaults.versioned-v1"] if defaults_writable else []),
|
|
713
|
-
"runs.resolve-unknown-v1", "approval", "question",
|
|
868
|
+
"runs.resolve-unknown-v1", "approval", "question", "tts", "messages.reply-context-v1", "subagents.observe-v1",
|
|
714
869
|
]
|
|
715
870
|
details = {
|
|
716
871
|
"runs.resolve-unknown-v1": {"scope": "service", "options": ["acknowledge-unknown"], "permission": "allowed"},
|
|
@@ -718,30 +873,54 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
718
873
|
# 只有读到 owner profile 的真实限制才声明 attachments;读不到时不声明,
|
|
719
874
|
# 客户端按能力缺失处理,不用猜测的上限放行。
|
|
720
875
|
media = self._input_media_constraint()
|
|
876
|
+
prepare_devices = getattr(getattr(self.runtime, "locator", None), "prepare_device_identity", None)
|
|
877
|
+
device_tools = bool(getattr(self, "plugin_enabled", False)
|
|
878
|
+
and prepare_devices is not None and prepare_devices())
|
|
879
|
+
if device_tools:
|
|
880
|
+
for capability in ("device.location", "device.health", "device.calendar"):
|
|
881
|
+
capabilities.append(capability)
|
|
882
|
+
details[capability] = {"scope": "service", "permission": "allowed"}
|
|
721
883
|
if media is not None:
|
|
722
884
|
capabilities.append("attachments")
|
|
723
885
|
details["attachments"] = media
|
|
886
|
+
if any(mime in media_input.FILE_MIMES for mime in media["mimeTypes"]):
|
|
887
|
+
capabilities.append("attachments.files-v1")
|
|
724
888
|
return {
|
|
889
|
+
"agentManagement": getattr(self, "profile", None) is not None,
|
|
890
|
+
"deviceTools": device_tools,
|
|
891
|
+
"scheduledTasks": getattr(self, "profile", None) is not None,
|
|
892
|
+
"slashCommands": getattr(self, "profile", None) is not None,
|
|
725
893
|
"runtimeInterface": {
|
|
726
894
|
"mode": getattr(self.runtime, "mode", "public"),
|
|
727
895
|
"publicAPI": False,
|
|
728
896
|
"publicMethods": sorted(
|
|
729
897
|
set(self.runtime.public_methods)
|
|
730
898
|
| set(SettingsControl.public_methods)
|
|
899
|
+
| set(SlashCommandsPort.public_methods)
|
|
731
900
|
),
|
|
732
901
|
"observability": {
|
|
733
|
-
"subagents": "
|
|
902
|
+
"subagents": "public-lifecycle+stream-observers-v1",
|
|
734
903
|
"usage": "optional-authoritative",
|
|
735
904
|
"reasoning": "public-stream-observer+original-receipt",
|
|
736
905
|
},
|
|
737
906
|
"compatibility": [
|
|
738
907
|
"input-binding", "source-scope", "authorized-fifo-admission",
|
|
908
|
+
"multi-profile-registry-v0.22.5",
|
|
909
|
+
"slash-handlers-v0.22.5",
|
|
739
910
|
"original-control-waiter-read-v0.22.5",
|
|
740
911
|
"initial-platform-registration", "platform-authorization",
|
|
741
912
|
"media-source-reference-v0.22.5",
|
|
742
913
|
"model-display-names-v0.22.5",
|
|
743
914
|
"profile-defaults-v0.22.5",
|
|
915
|
+
"reasoning-options-v0.22.5",
|
|
744
916
|
"reasoning-identity-v0.22.5",
|
|
917
|
+
"message-speech-v0.22.5",
|
|
918
|
+
"agent-management-v0.22.5",
|
|
919
|
+
"scheduled-tasks-v0.22.5",
|
|
920
|
+
"reply-context-format-v0.22.5",
|
|
921
|
+
"subagent-identity-v0.22.5",
|
|
922
|
+
"continuation-identity-v0.22.5",
|
|
923
|
+
"device-identity-v0.22.5", "device-execution-v0.22.5",
|
|
745
924
|
],
|
|
746
925
|
},
|
|
747
926
|
"backend": {
|
|
@@ -755,17 +934,24 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
755
934
|
},
|
|
756
935
|
}
|
|
757
936
|
if method == "validate":
|
|
937
|
+
if isinstance(params.get("sessionKey"), str) and params["sessionKey"].startswith("scheduled:"):
|
|
938
|
+
return {"allowed": False, "reason": "REMOTE_SESSION_READ_ONLY", "status": 403}
|
|
758
939
|
if params.get("serviceInstanceId") != self.service_id:
|
|
759
940
|
raise RuntimeError("SERVICE_MISMATCH")
|
|
760
941
|
if not self.plugin_enabled:
|
|
761
942
|
return {"allowed": False, "reason": "PLUGIN_DISABLED"}
|
|
762
943
|
if params.get("agentId", "hermes") != "hermes":
|
|
763
944
|
return {"allowed": False, "reason": "AGENT_NOT_FOUND", "status": 404}
|
|
764
|
-
|
|
945
|
+
try:
|
|
946
|
+
_, command_options = split_command_options(params.get("sessionOptions") or {})
|
|
947
|
+
_, settings = reply_context.split_options(command_options)
|
|
948
|
+
except ValueError as error:
|
|
949
|
+
return {"allowed": False, "reason": str(error), "status": 422}
|
|
950
|
+
if settings:
|
|
765
951
|
return await InitialSettings(self).validate(
|
|
766
952
|
params["sessionKey"],
|
|
767
953
|
params.get("clientRequestId"),
|
|
768
|
-
|
|
954
|
+
settings,
|
|
769
955
|
)
|
|
770
956
|
if self.bindings.has_legacy_session(params["sessionKey"]):
|
|
771
957
|
return {"allowed": False, "reason": "LEGACY_SESSION_REQUIRES_MIGRATION"}
|
|
@@ -797,8 +983,9 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
797
983
|
return {"allowed": False, "reason": "HOST_NOT_READY", "status": 503}
|
|
798
984
|
return {"allowed": True, **({"mediaPolicy": self.runtime.input_media_policy(shared=shared)} if params.get("attachmentCount") else {})}
|
|
799
985
|
if method == "agents":
|
|
986
|
+
ui = await asyncio.to_thread(compat_v0225.profile_agent_presentation, self.profile)
|
|
800
987
|
return {
|
|
801
|
-
"agents": [{"id": "hermes", "name": "
|
|
988
|
+
"agents": [{"id": "hermes", "name": ui["name"], "greeting": ui["greeting"], "isDefault": True}]
|
|
802
989
|
}
|
|
803
990
|
if method in ("session.title", "session.pin"):
|
|
804
991
|
selected = await self._catalog().resolve(params["sessionKey"])
|
|
@@ -815,14 +1002,31 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
815
1002
|
raise RuntimeError("METADATA_RESULT_UNCONFIRMED")
|
|
816
1003
|
return payload
|
|
817
1004
|
if method == "sessions":
|
|
818
|
-
|
|
1005
|
+
port = getattr(self, "scheduled_tasks_port", None)
|
|
1006
|
+
if port is None and getattr(self, "profile", None) is not None:
|
|
1007
|
+
port = self.scheduled_tasks_port = ScheduledTasksPort(self)
|
|
1008
|
+
return {"sessions": [*await self._catalog().list(), *(port.sessions() if port else [])]}
|
|
819
1009
|
if method in ("snapshot", "history", "history.message"):
|
|
820
1010
|
key = params.get("sessionKey")
|
|
1011
|
+
if isinstance(key, str) and key.startswith("scheduled:"):
|
|
1012
|
+
if getattr(self, "scheduled_tasks_port", None) is None:
|
|
1013
|
+
self.scheduled_tasks_port = ScheduledTasksPort(self)
|
|
1014
|
+
port = self.scheduled_tasks_port
|
|
1015
|
+
if method == "history.message":
|
|
1016
|
+
page = port.history(key)
|
|
1017
|
+
return {"message": next((row for row in page["messages"] if row["id"] == params["messageId"]), None)}
|
|
1018
|
+
page = port.history(key, params.get("limit", 200), params.get("offset", 0))
|
|
1019
|
+
if method == "history":
|
|
1020
|
+
return {"page": page}
|
|
1021
|
+
return {"snapshot": {"session": {"sessionKey": key, "agentId": "hermes", "kind": "scheduled", "title": page["title"]},
|
|
1022
|
+
"transcript": page["messages"], "controls": []}}
|
|
821
1023
|
if params.get("agentId", "hermes") != "hermes":
|
|
822
1024
|
raise RuntimeError("AGENT_NOT_FOUND")
|
|
823
1025
|
resolved = await self._catalog().resolve(key)
|
|
824
1026
|
native_id = resolved["native_id"]
|
|
825
|
-
|
|
1027
|
+
observer = getattr(self, "continuation_observer", None)
|
|
1028
|
+
reader = HistoryReader(self.runtime, self.profile, self.bindings,
|
|
1029
|
+
extra_records=observer.history_links() if observer is not None else ())
|
|
826
1030
|
if method == "history.message":
|
|
827
1031
|
return {
|
|
828
1032
|
"message": await reader.message(key, native_id, params["messageId"])
|
|
@@ -867,6 +1071,8 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
867
1071
|
raise RuntimeError("SERVICE_MISMATCH")
|
|
868
1072
|
if record is None and method == "execute":
|
|
869
1073
|
key = run["sessionKey"]
|
|
1074
|
+
command_context, command_options = split_command_options(run.get("sessionOptions") or {})
|
|
1075
|
+
context, settings = reply_context.split_options(command_options)
|
|
870
1076
|
if self.bindings.has_legacy_session(key):
|
|
871
1077
|
raise RuntimeError("LEGACY_SESSION_REQUIRES_MIGRATION")
|
|
872
1078
|
record = {
|
|
@@ -877,7 +1083,9 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
877
1083
|
"input_id": "fridaynext:" + run_id,
|
|
878
1084
|
"text": run["text"],
|
|
879
1085
|
"client_request_id": run.get("clientRequestId"),
|
|
880
|
-
"session_options":
|
|
1086
|
+
"session_options": settings,
|
|
1087
|
+
**({"command_context": command_context} if command_context is not None else {}),
|
|
1088
|
+
**({"reply_context": context} if context is not None else {}),
|
|
881
1089
|
"service_id": self.service_id,
|
|
882
1090
|
"dispatched": True,
|
|
883
1091
|
"created_at": time.time(),
|
|
@@ -928,12 +1136,15 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
928
1136
|
self.bindings.patch(record, {"input_media": images})
|
|
929
1137
|
event = MessageEvent(
|
|
930
1138
|
text=run["text"],
|
|
931
|
-
message_type=MessageType.
|
|
1139
|
+
message_type=(MessageType.DOCUMENT if any(item["mimeType"] not in media_input.MIMES for item in images)
|
|
1140
|
+
else MessageType.PHOTO if images else MessageType.TEXT),
|
|
932
1141
|
source=self._source(record),
|
|
933
1142
|
message_id=record["input_id"],
|
|
934
1143
|
media_urls=[item["path"] for item in images],
|
|
935
1144
|
media_types=[item["mimeType"] for item in images],
|
|
1145
|
+
media_text_inlined=[None if item["mimeType"] in media_input.MIMES else False for item in images],
|
|
936
1146
|
allow_gateway_control=False,
|
|
1147
|
+
**reply_context.native_fields(record.get("reply_context")),
|
|
937
1148
|
)
|
|
938
1149
|
event = await lease[0].prepare_input(event)
|
|
939
1150
|
self._recovery().check(lease)
|
|
@@ -1045,6 +1256,14 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
1045
1256
|
return SendResult(success=True, message_id=clarify_id)
|
|
1046
1257
|
|
|
1047
1258
|
async def send(self, chat_id, content, reply_to=None, metadata=None):
|
|
1259
|
+
if isinstance(metadata, dict) and isinstance(metadata.get("job_id"), str) and reply_to is None and self.host is not None:
|
|
1260
|
+
try:
|
|
1261
|
+
if getattr(self, "scheduled_tasks_port", None) is None:
|
|
1262
|
+
self.scheduled_tasks_port = ScheduledTasksPort(self)
|
|
1263
|
+
message_id = await self.scheduled_tasks_port.deliver(chat_id, content, metadata)
|
|
1264
|
+
return SendResult(success=message_id is not None, message_id=message_id, error=None if message_id else "Scheduled delivery source unavailable")
|
|
1265
|
+
except Exception:
|
|
1266
|
+
return SendResult(success=False, error="Scheduled delivery unconfirmed")
|
|
1048
1267
|
records = [
|
|
1049
1268
|
r
|
|
1050
1269
|
for r in self.bindings.all()
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""智能体设置的宿主端口;身份/命令固定,写后回读,失败不重复执行。"""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from . import compat_v0225
|
|
8
|
+
from .agent_defaults import AgentDefaultsPort
|
|
9
|
+
from .canonical_control import NativeControlError
|
|
10
|
+
from .settings import encoded, model_id
|
|
11
|
+
from .state import private_json
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AgentManagementPort:
|
|
15
|
+
def __init__(self, adapter):
|
|
16
|
+
self.adapter = adapter
|
|
17
|
+
self.profile = adapter.profile.resolve()
|
|
18
|
+
stat = self.profile.stat()
|
|
19
|
+
self.profile_identity = (stat.st_dev, stat.st_ino)
|
|
20
|
+
self.root = adapter.bindings.root / "agent-management-commands"
|
|
21
|
+
self.root.mkdir(exist_ok=True, mode=0o700)
|
|
22
|
+
self.lock = asyncio.Lock()
|
|
23
|
+
|
|
24
|
+
def check(self, context):
|
|
25
|
+
stat = self.profile.stat()
|
|
26
|
+
if (context.get("serviceInstanceId") != self.adapter.service_id
|
|
27
|
+
or context.get("agentId") != "hermes" or not self.adapter.plugin_enabled
|
|
28
|
+
or self.adapter.profile.resolve() != self.profile
|
|
29
|
+
or (stat.st_dev, stat.st_ino) != self.profile_identity):
|
|
30
|
+
raise NativeControlError("AGENT_SCOPE_CHANGED")
|
|
31
|
+
|
|
32
|
+
async def native(self):
|
|
33
|
+
return await asyncio.to_thread(compat_v0225.profile_agent_management, self.profile)
|
|
34
|
+
|
|
35
|
+
@staticmethod
|
|
36
|
+
def config(native):
|
|
37
|
+
defaults = native["defaults"]
|
|
38
|
+
return {"id": "hermes", "exists": True, "version": native["version"],
|
|
39
|
+
"model": model_id(defaults["provider"], defaults["model"]),
|
|
40
|
+
"thinkingDefault": defaults["thinkingLevel"], "skills": native["skills"],
|
|
41
|
+
"availableSkills": native["availableSkills"], "management": {
|
|
42
|
+
"name": native["name"], "greeting": native["greeting"], "writable": native["writable"],
|
|
43
|
+
"modelCanInherit": False, "thinkingCanInherit": False,
|
|
44
|
+
"permissionMode": native["permissionMode"],
|
|
45
|
+
"permissionOptions": [{"id": key, "label": key} for key in native["permissionModes"]],
|
|
46
|
+
"toolGranularity": "toolset"}}
|
|
47
|
+
|
|
48
|
+
async def read(self, operation, value):
|
|
49
|
+
if operation == "agent.config":
|
|
50
|
+
return self.config(await self.native())
|
|
51
|
+
if operation == "agent.greeting":
|
|
52
|
+
native = await self.native()
|
|
53
|
+
return {"greeting": native["greeting"]}
|
|
54
|
+
if operation == "agent.tools":
|
|
55
|
+
native = await self.native()
|
|
56
|
+
return {"id": "hermes", "version": native["version"], "granularity": "toolset", "writable": native["writable"], "profiles": [],
|
|
57
|
+
"groups": [{"id": "toolsets", "label": "工具集", "source": "hermes", "tools": native["toolsets"]}]}
|
|
58
|
+
if operation in ("agent.files", "agent.file"):
|
|
59
|
+
names = await asyncio.to_thread(compat_v0225.profile_agent_file_names, self.profile)
|
|
60
|
+
if operation == "agent.file":
|
|
61
|
+
if value.get("name") not in names:
|
|
62
|
+
raise NativeControlError("INVALID_AGENT_FILE")
|
|
63
|
+
file = await asyncio.to_thread(compat_v0225.profile_agent_file, self.profile, value.get("name"))
|
|
64
|
+
file["writable"] = await asyncio.to_thread(compat_v0225.profile_agent_write_allowed, self.profile)
|
|
65
|
+
return file
|
|
66
|
+
files = [await asyncio.to_thread(compat_v0225.profile_agent_file, self.profile, name) for name in names]
|
|
67
|
+
return {"files": [{k: v for k, v in row.items() if k != "content"} for row in files]}
|
|
68
|
+
raise NativeControlError("AGENT_OPERATION_UNSUPPORTED")
|
|
69
|
+
|
|
70
|
+
async def call(self, operation, context, value, inspect=False):
|
|
71
|
+
self.check(context)
|
|
72
|
+
mutating = operation in ("agent.configure", "agent.identity", "agent.write-file")
|
|
73
|
+
if not mutating:
|
|
74
|
+
return await self.read(operation, value)
|
|
75
|
+
command = context.get("commandId")
|
|
76
|
+
if not isinstance(command, str) or not command.strip() or len(command) > 200:
|
|
77
|
+
raise NativeControlError("INVALID_AGENT_COMMAND")
|
|
78
|
+
key = hashlib.sha256(command.encode()).hexdigest()
|
|
79
|
+
path = self.root / (key + ".json")
|
|
80
|
+
intent = {"operation": operation, "context": context, "input": value}
|
|
81
|
+
async with self.lock:
|
|
82
|
+
self.check(context)
|
|
83
|
+
if path.exists():
|
|
84
|
+
stored = json.loads(path.read_text())
|
|
85
|
+
if encoded(stored.get("intent")) != encoded(intent):
|
|
86
|
+
return {"status": "conflict", "code": "AGENT_COMMAND_CONFLICT"}
|
|
87
|
+
return stored.get("result", {"status": "unknown", "code": "AGENT_WRITE_UNCONFIRMED"})
|
|
88
|
+
if inspect:
|
|
89
|
+
return {"status": "unknown", "code": "AGENT_COMMAND_NOT_FOUND"}
|
|
90
|
+
prepared = False
|
|
91
|
+
def prepare():
|
|
92
|
+
nonlocal prepared
|
|
93
|
+
self.check(context)
|
|
94
|
+
private_json(path, {"intent": intent})
|
|
95
|
+
prepared = True
|
|
96
|
+
try:
|
|
97
|
+
if operation == "agent.write-file":
|
|
98
|
+
if not isinstance(value.get("content"), str):
|
|
99
|
+
return {"status": "conflict", "code": "INVALID_AGENT_FILE"}
|
|
100
|
+
if not await asyncio.to_thread(compat_v0225.profile_agent_write_allowed, self.profile):
|
|
101
|
+
return {"status": "conflict", "code": "AGENT_CONFIG_READ_ONLY"}
|
|
102
|
+
names = await asyncio.to_thread(compat_v0225.profile_agent_file_names, self.profile)
|
|
103
|
+
if value.get("name") not in names:
|
|
104
|
+
raise NativeControlError("INVALID_AGENT_FILE")
|
|
105
|
+
result = await asyncio.to_thread(compat_v0225.profile_agent_file, self.profile,
|
|
106
|
+
value.get("name"), content=value.get("content"), expected_version=value.get("expectedVersion"), prepare=prepare)
|
|
107
|
+
else:
|
|
108
|
+
native = await self.native()
|
|
109
|
+
if operation == "agent.identity":
|
|
110
|
+
patch = {"displayName": value.get("name")}
|
|
111
|
+
version = native["version"]
|
|
112
|
+
else:
|
|
113
|
+
patch = value.get("patch")
|
|
114
|
+
if not isinstance(patch, dict) or not patch:
|
|
115
|
+
return {"status": "conflict", "code": "INVALID_AGENT_PATCH"}
|
|
116
|
+
version = value.get("expectedVersion")
|
|
117
|
+
if native["version"] != version:
|
|
118
|
+
return {"status": "conflict", "code": "AGENT_CONFIG_CHANGED"}
|
|
119
|
+
if isinstance(patch, dict) and patch and set(patch) <= {"model", "thinkingDefault"}:
|
|
120
|
+
# 与首页共用FN-191原子默认配置端口,不另存一份默认。
|
|
121
|
+
if patch.get("model", "present") is None or patch.get("thinkingDefault", "present") is None:
|
|
122
|
+
return {"status": "conflict", "code": "AGENT_DEFAULT_CANNOT_INHERIT"}
|
|
123
|
+
prepare()
|
|
124
|
+
defaults = native["defaults"]
|
|
125
|
+
change = {"commandId": "management:" + command, "expectedServerInstanceId": self.adapter.service_id,
|
|
126
|
+
"expectedVersion": defaults["version"], "values": {
|
|
127
|
+
"modelRef": patch.get("model", model_id(defaults["provider"], defaults["model"])),
|
|
128
|
+
**({"thinkingLevel": patch["thinkingDefault"]} if "thinkingDefault" in patch else {})}}
|
|
129
|
+
if not hasattr(self.adapter, "agent_defaults_port"):
|
|
130
|
+
self.adapter.agent_defaults_port = AgentDefaultsPort(self.adapter)
|
|
131
|
+
result = await self.adapter.agent_defaults_port.mutate("hermes", change)
|
|
132
|
+
else:
|
|
133
|
+
result = await asyncio.to_thread(compat_v0225.profile_agent_management, self.profile,
|
|
134
|
+
patch=patch, expected_version=version, prepare=prepare)
|
|
135
|
+
if result.get("status") == "applied":
|
|
136
|
+
after = await self.native()
|
|
137
|
+
for field, wanted in patch.items():
|
|
138
|
+
actual = (after.get(field) if field in ("permissionMode", "skills") else
|
|
139
|
+
next((row["enabled"] for row in after["toolsets"] if row["id"] == wanted["id"]), None) if field == "toolset" else
|
|
140
|
+
after.get("name") if field == "displayName" else after.get("greeting"))
|
|
141
|
+
if field == "skills" and set(actual) != set(wanted):
|
|
142
|
+
raise NativeControlError("AGENT_READBACK_MISMATCH")
|
|
143
|
+
if field == "permissionMode" and actual != wanted or field == "toolset" and actual != wanted["enabled"]:
|
|
144
|
+
raise NativeControlError("AGENT_READBACK_MISMATCH")
|
|
145
|
+
if field in ("greeting", "displayName") and actual != (wanted.strip() or ("HERMES" if field == "displayName" else "")):
|
|
146
|
+
raise NativeControlError("AGENT_READBACK_MISMATCH")
|
|
147
|
+
result = {"status": "applied", "value": {**self.config(after), "ok": True}}
|
|
148
|
+
if result.get("status") == "applied" and operation == "agent.write-file":
|
|
149
|
+
actual = await asyncio.to_thread(compat_v0225.profile_agent_file, self.profile, value["name"])
|
|
150
|
+
if actual["content"] != value["content"]:
|
|
151
|
+
raise NativeControlError("AGENT_FILE_READBACK_MISMATCH")
|
|
152
|
+
self.check(context)
|
|
153
|
+
private_json(path, {"intent": intent, "result": result})
|
|
154
|
+
return result
|
|
155
|
+
except Exception:
|
|
156
|
+
if prepared:
|
|
157
|
+
return {"status": "unknown", "code": "AGENT_WRITE_UNCONFIRMED"}
|
|
158
|
+
raise
|