@syengup/fridaynext-hermes-channel 0.1.0-beta.3 → 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 +17 -5
- 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 +221 -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 +1174 -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/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 +250 -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 +27 -3
- 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
|
|
@@ -66,6 +74,8 @@ def cancel_event(trace, event, **fields):
|
|
|
66
74
|
|
|
67
75
|
class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
68
76
|
instances = weakref.WeakSet()
|
|
77
|
+
# 本平台负责长文本持久交付;让宿主跳过4000字符备用截断。超过256KiB明确失败,不静默丢尾。
|
|
78
|
+
splits_long_messages = True
|
|
69
79
|
|
|
70
80
|
def __init__(self, config):
|
|
71
81
|
super().__init__(config, Platform("fridaynext"))
|
|
@@ -113,8 +123,16 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
113
123
|
self.stopping = None
|
|
114
124
|
self.session_directory = None
|
|
115
125
|
self.streams = None
|
|
126
|
+
self.subagent_observer = None
|
|
127
|
+
self.continuation_observer = None
|
|
116
128
|
self._carry_allowlist(extra)
|
|
117
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
|
+
|
|
118
136
|
# 后台重连会重建适配器:此时若已在别的 secret scope 里,`platform_gate_env` 的
|
|
119
137
|
# scoped miss 不再回落到 os.environ,allowlist 读到空值 → 所有入站变 Unauthorized
|
|
120
138
|
# (FN-169)。插件平台本来就把允许列表放在 extra.allowed_users 里由授权层读取,
|
|
@@ -187,7 +205,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
187
205
|
return self.settings_port
|
|
188
206
|
|
|
189
207
|
def _input_media_constraint(self):
|
|
190
|
-
"""
|
|
208
|
+
"""附件输入的公开能力约束:MIME、数量与原 owner profile 的实际字节上限。
|
|
191
209
|
|
|
192
210
|
公开描述面只有这一处声明;读不到限制(运行未就绪、profile 未服务)时返回 None,
|
|
193
211
|
由客户端按能力缺失处理,不声明猜测值。maxBytes 是原 profile 的整批上限,
|
|
@@ -209,7 +227,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
209
227
|
return None
|
|
210
228
|
return {
|
|
211
229
|
"scope": "service",
|
|
212
|
-
"mimeTypes": sorted(media_input.MIMES),
|
|
230
|
+
"mimeTypes": sorted(set(media_input.MIMES) | (set(values.get("fileMimeTypes", ())) & media_input.FILE_MIMES)),
|
|
213
231
|
"maxCount": max_count,
|
|
214
232
|
"maxBytes": max_bytes,
|
|
215
233
|
"permission": "allowed",
|
|
@@ -256,6 +274,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
256
274
|
try:
|
|
257
275
|
self.data.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
258
276
|
self.bindings = Bindings(self.data, self.profile)
|
|
277
|
+
self.subagent_observer = SubagentObserver(self)
|
|
259
278
|
public = self.data / "public-access.json"
|
|
260
279
|
if not public.exists():
|
|
261
280
|
private_json(
|
|
@@ -270,9 +289,19 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
270
289
|
self.host = KitHost(
|
|
271
290
|
self, self.data, self.profile, self.node, self.entry
|
|
272
291
|
)
|
|
273
|
-
|
|
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()
|
|
274
301
|
self._wire_plugin_handlers(None)
|
|
275
302
|
self._mark_connected(listener_base=ready["origin"])
|
|
303
|
+
self.subagent_observer.restore()
|
|
304
|
+
self._continuations()
|
|
276
305
|
self.media_recovery_task = asyncio.create_task(media_output.restore(self))
|
|
277
306
|
return True
|
|
278
307
|
except Exception as error:
|
|
@@ -316,6 +345,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
316
345
|
|
|
317
346
|
@classmethod
|
|
318
347
|
def record_reasoning_delta(cls, **event):
|
|
348
|
+
cls.record_subagent_event("stream.delta", event)
|
|
319
349
|
# 官方observer已离开token路径,并保留原Profile及输入上下文;不创建逐token异步任务。
|
|
320
350
|
if event.get("kind") != "reasoning":
|
|
321
351
|
return
|
|
@@ -327,6 +357,60 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
327
357
|
if locator is not None:
|
|
328
358
|
locator.publish_reasoning(event)
|
|
329
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
|
+
|
|
330
414
|
@classmethod
|
|
331
415
|
def record_api_error(cls, **event):
|
|
332
416
|
native = event.get("session_id")
|
|
@@ -395,6 +479,12 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
395
479
|
self.stopping = None
|
|
396
480
|
|
|
397
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
|
|
398
488
|
media_task = getattr(self, "media_recovery_task", None)
|
|
399
489
|
self.media_recovery_task = None
|
|
400
490
|
if media_task is not None and media_task is not asyncio.current_task():
|
|
@@ -409,6 +499,9 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
409
499
|
await host.stop()
|
|
410
500
|
if self.runtime is not None:
|
|
411
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()
|
|
412
505
|
self._release_platform_lock()
|
|
413
506
|
|
|
414
507
|
def worker_event(self, event):
|
|
@@ -570,10 +663,21 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
570
663
|
return {"state": "running"}
|
|
571
664
|
if row["status"] != "terminal":
|
|
572
665
|
return {"state": "unknown", "reason": "HOST_EXECUTION_UNKNOWN"}
|
|
666
|
+
lease = self._recovery().lease()
|
|
573
667
|
try:
|
|
574
668
|
result = await self._result(record)
|
|
575
669
|
except Exception:
|
|
576
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__))
|
|
577
681
|
if (
|
|
578
682
|
result is None
|
|
579
683
|
and row.get("outcome") == "completed"
|
|
@@ -649,6 +753,48 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
649
753
|
await media_output.media_observations.reconcile(self, record)
|
|
650
754
|
|
|
651
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)
|
|
652
798
|
if method in ("speech.config", "speech.speak"):
|
|
653
799
|
if params.get("serviceInstanceId") != self.service_id:
|
|
654
800
|
raise NativeControlError("SERVICE_MISMATCH")
|
|
@@ -719,7 +865,7 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
719
865
|
"sessions.title", "sessions.pin", "history.message-detail",
|
|
720
866
|
"sessions.settings", "sessions.settings.versioned-v1",
|
|
721
867
|
*(["agents.defaults.versioned-v1"] if defaults_writable else []),
|
|
722
|
-
"runs.resolve-unknown-v1", "approval", "question", "tts",
|
|
868
|
+
"runs.resolve-unknown-v1", "approval", "question", "tts", "messages.reply-context-v1", "subagents.observe-v1",
|
|
723
869
|
]
|
|
724
870
|
details = {
|
|
725
871
|
"runs.resolve-unknown-v1": {"scope": "service", "options": ["acknowledge-unknown"], "permission": "allowed"},
|
|
@@ -727,31 +873,54 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
727
873
|
# 只有读到 owner profile 的真实限制才声明 attachments;读不到时不声明,
|
|
728
874
|
# 客户端按能力缺失处理,不用猜测的上限放行。
|
|
729
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"}
|
|
730
883
|
if media is not None:
|
|
731
884
|
capabilities.append("attachments")
|
|
732
885
|
details["attachments"] = media
|
|
886
|
+
if any(mime in media_input.FILE_MIMES for mime in media["mimeTypes"]):
|
|
887
|
+
capabilities.append("attachments.files-v1")
|
|
733
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,
|
|
734
893
|
"runtimeInterface": {
|
|
735
894
|
"mode": getattr(self.runtime, "mode", "public"),
|
|
736
895
|
"publicAPI": False,
|
|
737
896
|
"publicMethods": sorted(
|
|
738
897
|
set(self.runtime.public_methods)
|
|
739
898
|
| set(SettingsControl.public_methods)
|
|
899
|
+
| set(SlashCommandsPort.public_methods)
|
|
740
900
|
),
|
|
741
901
|
"observability": {
|
|
742
|
-
"subagents": "
|
|
902
|
+
"subagents": "public-lifecycle+stream-observers-v1",
|
|
743
903
|
"usage": "optional-authoritative",
|
|
744
904
|
"reasoning": "public-stream-observer+original-receipt",
|
|
745
905
|
},
|
|
746
906
|
"compatibility": [
|
|
747
907
|
"input-binding", "source-scope", "authorized-fifo-admission",
|
|
908
|
+
"multi-profile-registry-v0.22.5",
|
|
909
|
+
"slash-handlers-v0.22.5",
|
|
748
910
|
"original-control-waiter-read-v0.22.5",
|
|
749
911
|
"initial-platform-registration", "platform-authorization",
|
|
750
912
|
"media-source-reference-v0.22.5",
|
|
751
913
|
"model-display-names-v0.22.5",
|
|
752
914
|
"profile-defaults-v0.22.5",
|
|
915
|
+
"reasoning-options-v0.22.5",
|
|
753
916
|
"reasoning-identity-v0.22.5",
|
|
754
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",
|
|
755
924
|
],
|
|
756
925
|
},
|
|
757
926
|
"backend": {
|
|
@@ -765,17 +934,24 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
765
934
|
},
|
|
766
935
|
}
|
|
767
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}
|
|
768
939
|
if params.get("serviceInstanceId") != self.service_id:
|
|
769
940
|
raise RuntimeError("SERVICE_MISMATCH")
|
|
770
941
|
if not self.plugin_enabled:
|
|
771
942
|
return {"allowed": False, "reason": "PLUGIN_DISABLED"}
|
|
772
943
|
if params.get("agentId", "hermes") != "hermes":
|
|
773
944
|
return {"allowed": False, "reason": "AGENT_NOT_FOUND", "status": 404}
|
|
774
|
-
|
|
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:
|
|
775
951
|
return await InitialSettings(self).validate(
|
|
776
952
|
params["sessionKey"],
|
|
777
953
|
params.get("clientRequestId"),
|
|
778
|
-
|
|
954
|
+
settings,
|
|
779
955
|
)
|
|
780
956
|
if self.bindings.has_legacy_session(params["sessionKey"]):
|
|
781
957
|
return {"allowed": False, "reason": "LEGACY_SESSION_REQUIRES_MIGRATION"}
|
|
@@ -807,8 +983,9 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
807
983
|
return {"allowed": False, "reason": "HOST_NOT_READY", "status": 503}
|
|
808
984
|
return {"allowed": True, **({"mediaPolicy": self.runtime.input_media_policy(shared=shared)} if params.get("attachmentCount") else {})}
|
|
809
985
|
if method == "agents":
|
|
986
|
+
ui = await asyncio.to_thread(compat_v0225.profile_agent_presentation, self.profile)
|
|
810
987
|
return {
|
|
811
|
-
"agents": [{"id": "hermes", "name": "
|
|
988
|
+
"agents": [{"id": "hermes", "name": ui["name"], "greeting": ui["greeting"], "isDefault": True}]
|
|
812
989
|
}
|
|
813
990
|
if method in ("session.title", "session.pin"):
|
|
814
991
|
selected = await self._catalog().resolve(params["sessionKey"])
|
|
@@ -825,14 +1002,31 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
825
1002
|
raise RuntimeError("METADATA_RESULT_UNCONFIRMED")
|
|
826
1003
|
return payload
|
|
827
1004
|
if method == "sessions":
|
|
828
|
-
|
|
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 [])]}
|
|
829
1009
|
if method in ("snapshot", "history", "history.message"):
|
|
830
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": []}}
|
|
831
1023
|
if params.get("agentId", "hermes") != "hermes":
|
|
832
1024
|
raise RuntimeError("AGENT_NOT_FOUND")
|
|
833
1025
|
resolved = await self._catalog().resolve(key)
|
|
834
1026
|
native_id = resolved["native_id"]
|
|
835
|
-
|
|
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 ())
|
|
836
1030
|
if method == "history.message":
|
|
837
1031
|
return {
|
|
838
1032
|
"message": await reader.message(key, native_id, params["messageId"])
|
|
@@ -877,6 +1071,8 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
877
1071
|
raise RuntimeError("SERVICE_MISMATCH")
|
|
878
1072
|
if record is None and method == "execute":
|
|
879
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)
|
|
880
1076
|
if self.bindings.has_legacy_session(key):
|
|
881
1077
|
raise RuntimeError("LEGACY_SESSION_REQUIRES_MIGRATION")
|
|
882
1078
|
record = {
|
|
@@ -887,7 +1083,9 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
887
1083
|
"input_id": "fridaynext:" + run_id,
|
|
888
1084
|
"text": run["text"],
|
|
889
1085
|
"client_request_id": run.get("clientRequestId"),
|
|
890
|
-
"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 {}),
|
|
891
1089
|
"service_id": self.service_id,
|
|
892
1090
|
"dispatched": True,
|
|
893
1091
|
"created_at": time.time(),
|
|
@@ -938,12 +1136,15 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
938
1136
|
self.bindings.patch(record, {"input_media": images})
|
|
939
1137
|
event = MessageEvent(
|
|
940
1138
|
text=run["text"],
|
|
941
|
-
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),
|
|
942
1141
|
source=self._source(record),
|
|
943
1142
|
message_id=record["input_id"],
|
|
944
1143
|
media_urls=[item["path"] for item in images],
|
|
945
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],
|
|
946
1146
|
allow_gateway_control=False,
|
|
1147
|
+
**reply_context.native_fields(record.get("reply_context")),
|
|
947
1148
|
)
|
|
948
1149
|
event = await lease[0].prepare_input(event)
|
|
949
1150
|
self._recovery().check(lease)
|
|
@@ -1055,6 +1256,14 @@ class FridayNextAdapter(MediaDeliveryBoundary, BasePlatformAdapter):
|
|
|
1055
1256
|
return SendResult(success=True, message_id=clarify_id)
|
|
1056
1257
|
|
|
1057
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")
|
|
1058
1267
|
records = [
|
|
1059
1268
|
r
|
|
1060
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
|