@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.
Files changed (92) hide show
  1. package/README.md +2 -2
  2. package/install-config.js +67 -0
  3. package/install-runtime.js +18 -9
  4. package/install.js +6 -4
  5. package/package.json +2 -1
  6. package/plugin/README.md +2 -2
  7. package/plugin/fridaynext_plugin/__init__.py +10 -0
  8. package/plugin/fridaynext_plugin/adapter.py +231 -12
  9. package/plugin/fridaynext_plugin/agent_management.py +158 -0
  10. package/plugin/fridaynext_plugin/canonical_control.py +12 -4
  11. package/plugin/fridaynext_plugin/compat_v0225.py +1247 -4
  12. package/plugin/fridaynext_plugin/continuations.py +271 -0
  13. package/plugin/fridaynext_plugin/device-tools-v1.json +302 -0
  14. package/plugin/fridaynext_plugin/device_tools.py +144 -0
  15. package/plugin/fridaynext_plugin/history.py +25 -3
  16. package/plugin/fridaynext_plugin/host.py +7 -4
  17. package/plugin/fridaynext_plugin/media_input.py +56 -9
  18. package/plugin/fridaynext_plugin/message_speech.py +143 -0
  19. package/plugin/fridaynext_plugin/multi_agent.py +221 -0
  20. package/plugin/fridaynext_plugin/reply_context.py +39 -0
  21. package/plugin/fridaynext_plugin/runtime_port.py +23 -1
  22. package/plugin/fridaynext_plugin/scheduled_tasks.py +229 -0
  23. package/plugin/fridaynext_plugin/settings.py +7 -3
  24. package/plugin/fridaynext_plugin/slash_commands.py +163 -0
  25. package/plugin/fridaynext_plugin/stream_bridge.py +83 -26
  26. package/plugin/fridaynext_plugin/stream_projection.py +30 -6
  27. package/plugin/fridaynext_plugin/subagents.py +228 -0
  28. package/plugin/plugin.yaml +11 -0
  29. package/plugin/runtime/dist/commands-routes.js +94 -0
  30. package/plugin/runtime/dist/device-tools-v1.json +302 -0
  31. package/plugin/runtime/dist/hosted-backend.js +293 -25
  32. package/plugin/runtime/dist/hosted-continuations.js +41 -0
  33. package/plugin/runtime/dist/hosted-device-tools.js +82 -0
  34. package/plugin/runtime/dist/hosted-media.js +54 -13
  35. package/plugin/runtime/dist/hosted-stream.js +124 -14
  36. package/plugin/runtime/dist/hosted-subagents.js +78 -0
  37. package/plugin/runtime/dist/platform-service.js +4 -0
  38. package/plugin/runtime/dist/plugin-control.js +10 -6
  39. package/plugin/runtime/dist/scheduled-routes.js +63 -0
  40. package/plugin/runtime/dist/service-host.js +40 -5
  41. package/plugin/runtime/dist/speech-routes.js +111 -0
  42. package/plugin/runtime/dist/tool-presentation.js +399 -0
  43. package/plugin/runtime/node_modules/.package-lock.json +6 -6
  44. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/API.md +125 -5
  45. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/README.md +21 -1
  46. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/history.d.ts +1 -0
  47. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/history.js +3 -0
  48. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/operations.d.ts +136 -0
  49. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/operations.js +105 -0
  50. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/settings-schema.d.ts +3 -0
  51. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/settings-schema.js +45 -0
  52. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/tool-presentation.d.ts +10 -0
  53. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/tool-presentation.js +2 -0
  54. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/types.d.ts +27 -2
  55. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/types.js +1 -0
  56. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/work-context.d.ts +56 -0
  57. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/work-context.js +60 -0
  58. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/device-request/pending-store.js +3 -3
  59. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/index.d.ts +5 -0
  60. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/index.js +5 -0
  61. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/canonical-update-batcher.d.ts +26 -0
  62. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/canonical-update-batcher.js +112 -0
  63. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/channel-kernel.d.ts +4 -1
  64. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/channel-kernel.js +30 -5
  65. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/durable-run-store.d.ts +18 -1
  66. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/durable-run-store.js +187 -51
  67. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/runner.d.ts +1 -0
  68. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/runner.js +52 -2
  69. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/work-context.d.ts +13 -0
  70. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/work-context.js +73 -0
  71. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/service/channel-service.js +1 -1
  72. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/command-lifecycle.d.ts +47 -0
  73. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/command-lifecycle.js +184 -0
  74. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/controls.d.ts +1 -1
  75. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/controls.js +11 -0
  76. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/messages.js +12 -6
  77. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/operations.d.ts +13 -0
  78. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/operations.js +336 -0
  79. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/runtime.d.ts +1 -0
  80. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/runtime.js +52 -10
  81. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/session-settings.js +38 -6
  82. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/sessions.js +8 -8
  83. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/package.json +6 -7
  84. package/plugin/runtime/node_modules/tslib/README.md +3 -8
  85. package/plugin/runtime/node_modules/tslib/package.json +1 -1
  86. package/plugin/runtime/node_modules/tslib/tslib.d.ts +4 -2
  87. package/plugin/runtime/node_modules/tslib/tslib.es6.js +10 -1
  88. package/plugin/runtime/node_modules/tslib/tslib.es6.mjs +10 -1
  89. package/plugin/runtime/node_modules/tslib/tslib.js +10 -1
  90. package/plugin/runtime/package-lock.json +7 -7
  91. package/plugin/runtime/package.json +1 -1
  92. package/plugin/tools.py +3 -0
@@ -1,9 +1,20 @@
1
1
  name: fridaynext
2
2
  version: 0.2.0-beta.1
3
3
  kind: platform
4
+ provides_tools:
5
+ - fridaynext_location_query
6
+ - fridaynext_health_query
7
+ - fridaynext_health_log
8
+ - fridaynext_calendar_query
9
+ - fridaynext_calendar_log
4
10
  provides_hooks:
5
11
  - api_request_error
6
12
  - on_stream_delta
13
+ - subagent_start
14
+ - subagent_stop
15
+ - on_stream_end
16
+ - post_api_request
17
+ - post_tool_call
7
18
  requires_hermes: "==0.22.5"
8
19
  description: FridayNext 原生客户端平台,复用通用 Channel Kit
9
20
  author: SyengUp
@@ -0,0 +1,94 @@
1
+ const receiptKind = "slash-command-v1";
2
+ const object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
3
+ const identity = (value) => typeof value === "string" && !!value.trim() && value.length <= 1024;
4
+ // 版本化中立命令操作的所属适配器实现:复用Kit回执,不创建第二套队列或重放宿主副作用。
5
+ export function createCommandRoutes(options) {
6
+ const inFlight = new Map();
7
+ return async (req, res) => {
8
+ const path = new URL(req.url ?? "/", "http://localhost").pathname;
9
+ if (path !== "/friday-next/commands/v1/execute")
10
+ return false;
11
+ const reply = (status, body) => {
12
+ res.statusCode = status;
13
+ res.setHeader("content-type", "application/json; charset=utf-8");
14
+ res.setHeader("cache-control", "no-store");
15
+ res.end(JSON.stringify(body));
16
+ return true;
17
+ };
18
+ if (!options.authenticate(req))
19
+ return reply(401, { code: "UNAUTHORIZED" });
20
+ if (!options.available())
21
+ return reply(404, { code: "UNSUPPORTED_CAPABILITY" });
22
+ if (req.method !== "POST")
23
+ return reply(405, { code: "METHOD_NOT_ALLOWED" });
24
+ let body;
25
+ try {
26
+ const chunks = [];
27
+ let size = 0;
28
+ for await (const chunk of req) {
29
+ const bytes = Buffer.from(chunk);
30
+ size += bytes.length;
31
+ if (size > 128 * 1024)
32
+ throw Error();
33
+ chunks.push(bytes);
34
+ }
35
+ const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
36
+ if (!object(parsed))
37
+ throw Error();
38
+ body = parsed;
39
+ }
40
+ catch {
41
+ return reply(400, { code: "INVALID_COMMAND_INPUT" });
42
+ }
43
+ const base = { version: 1, serverInstanceId: options.store.serverInstanceId, operationId: "commands.execute", commandId: body.commandId };
44
+ if (body.version !== 1)
45
+ return reply(426, { code: "UNSUPPORTED_COMMAND_VERSION" });
46
+ if (body.expectedServerInstanceId !== options.store.serverInstanceId)
47
+ return reply(409, { code: "SERVICE_IDENTITY_CHANGED" });
48
+ if (Object.keys(body).some(key => !["version", "expectedServerInstanceId", "agentId", "sessionKey", "deviceId", "commandId", "input"].includes(key))
49
+ || !identity(body.agentId) || !identity(body.commandId) || !identity(body.deviceId)
50
+ || (body.sessionKey !== undefined && !identity(body.sessionKey))
51
+ || body.deviceId !== req.headers["x-fridaynext-device-id"]
52
+ || !object(body.input) || Object.keys(body.input).length !== 1 || typeof body.input.text !== "string"
53
+ || !body.input.text.startsWith("/") || body.input.text.length > 32768)
54
+ return reply(400, { code: "INVALID_COMMAND_INPUT" });
55
+ const key = JSON.stringify([body.deviceId, body.commandId]);
56
+ const payload = body;
57
+ const send = (result) => reply(result.status === "applied" ? 200 : result.status === "conflict" ? 409 : 503, { ...base, ...result });
58
+ const status = options.store.commandReceiptStatus(receiptKind, key, payload);
59
+ if (status === "conflict")
60
+ return send({ status: "conflict", code: "COMMAND_ID_CONFLICT" });
61
+ if (status === "replayed")
62
+ return send(options.store.commandReceipt(receiptKind, key).response);
63
+ const previous = inFlight.get(key);
64
+ if (previous)
65
+ return send(await previous);
66
+ if (status === "prepared")
67
+ return send({ status: "unknown", code: "COMMAND_EXECUTION_UNCONFIRMED" });
68
+ // prepare先落盘;任何IPC/宿主响应丢失都保留原ID为unknown,重试只查此回执。
69
+ options.store.prepareCommandReceipt(receiptKind, key, payload);
70
+ const operation = (async () => {
71
+ try {
72
+ const value = await options.backend.slashCommand({ serviceInstanceId: options.store.serverInstanceId,
73
+ agentId: body.agentId, sessionKey: body.sessionKey, commandId: body.commandId }, body.input);
74
+ const valid = object(value) && ["result", "run", "compaction", "local"].includes(String(value.kind))
75
+ && (["run", "local"].includes(String(value.kind)) ? value.text === body.input.text : typeof value.text === "string");
76
+ if (!valid)
77
+ return { status: "unknown", code: "COMMAND_RESULT_INVALID" };
78
+ const result = { status: "applied", value };
79
+ options.store.completeCommandReceipt(receiptKind, key, payload, result);
80
+ return result;
81
+ }
82
+ catch {
83
+ return { status: "unknown", code: "COMMAND_EXECUTION_UNCONFIRMED" };
84
+ }
85
+ })();
86
+ inFlight.set(key, operation);
87
+ try {
88
+ return send(await operation);
89
+ }
90
+ finally {
91
+ inFlight.delete(key);
92
+ }
93
+ };
94
+ }
@@ -0,0 +1,302 @@
1
+ {
2
+ "version": 1,
3
+ "operations": {
4
+ "location-query": {
5
+ "name": "fridaynext_location_query",
6
+ "description": "单次读取当前App会话绑定iPhone的位置、精度和时间;无位置历史或持续追踪。手机须在线并允许位置共享。",
7
+ "parameters": {
8
+ "type": "object",
9
+ "additionalProperties": false,
10
+ "properties": {}
11
+ }
12
+ },
13
+ "health-query": {
14
+ "name": "fridaynext_health_query",
15
+ "description": "查询当前App会话绑定iPhone的Apple Health聚合数据,指标按用户开启类别返回;默认过去24小时,最多31天。noData仅表示未返回样本,不能据此判断读取权限或编造数据。记录数据请用fridaynext_health_log。",
16
+ "parameters": {
17
+ "type": "object",
18
+ "additionalProperties": false,
19
+ "properties": {
20
+ "metrics": {
21
+ "type": "array",
22
+ "items": {
23
+ "type": "string",
24
+ "enum": [
25
+ "steps",
26
+ "distanceWalkingRunning",
27
+ "distanceCycling",
28
+ "distanceSwimming",
29
+ "activeEnergy",
30
+ "basalEnergy",
31
+ "exerciseMinutes",
32
+ "standHours",
33
+ "flightsClimbed",
34
+ "sleep",
35
+ "heartRate",
36
+ "restingHeartRate",
37
+ "walkingHeartRate",
38
+ "hrv",
39
+ "vo2Max",
40
+ "workouts",
41
+ "bodyMass",
42
+ "leanBodyMass",
43
+ "bodyFat",
44
+ "bmi",
45
+ "height",
46
+ "waistCircumference",
47
+ "mindfulMinutes",
48
+ "dietaryWater",
49
+ "dietaryEnergy",
50
+ "dietaryProtein",
51
+ "dietaryCarbohydrates",
52
+ "dietaryFiber",
53
+ "dietarySugar",
54
+ "dietaryFatTotal",
55
+ "dietaryFatSaturated",
56
+ "dietaryFatMonounsaturated",
57
+ "dietaryFatPolyunsaturated",
58
+ "dietaryCholesterol",
59
+ "dietaryCaffeine",
60
+ "dietarySodium",
61
+ "dietaryPotassium",
62
+ "dietaryCalcium",
63
+ "dietaryMagnesium",
64
+ "dietaryPhosphorus",
65
+ "dietaryChloride",
66
+ "dietaryIron",
67
+ "dietaryZinc",
68
+ "dietaryCopper",
69
+ "dietaryManganese",
70
+ "dietarySelenium",
71
+ "dietaryIodine",
72
+ "dietaryChromium",
73
+ "dietaryMolybdenum",
74
+ "dietaryVitaminA",
75
+ "dietaryVitaminC",
76
+ "dietaryVitaminD",
77
+ "dietaryVitaminE",
78
+ "dietaryVitaminK",
79
+ "dietaryVitaminB6",
80
+ "dietaryVitaminB12",
81
+ "dietaryThiamin",
82
+ "dietaryRiboflavin",
83
+ "dietaryNiacin",
84
+ "dietaryFolate",
85
+ "dietaryBiotin",
86
+ "dietaryPantothenicAcid"
87
+ ]
88
+ }
89
+ },
90
+ "start": {
91
+ "type": "string"
92
+ },
93
+ "end": {
94
+ "type": "string"
95
+ },
96
+ "bucket": {
97
+ "type": "string",
98
+ "enum": [
99
+ "none",
100
+ "hour",
101
+ "day"
102
+ ]
103
+ }
104
+ }
105
+ }
106
+ },
107
+ "health-log": {
108
+ "name": "fridaynext_health_log",
109
+ "description": "在当前App会话绑定iPhone的Apple Health记录营养、饮水、咖啡因、身体测量或正念数据;最多20条,31天内。需独立写入开关、类别及系统权限;读取开关可关闭。不能写入步数、心率、睡眠或运动。结果未知时不要自动重试。",
110
+ "parameters": {
111
+ "type": "object",
112
+ "additionalProperties": false,
113
+ "properties": {
114
+ "samples": {
115
+ "type": "array",
116
+ "items": {
117
+ "type": "object",
118
+ "additionalProperties": false,
119
+ "properties": {
120
+ "metric": {
121
+ "type": "string",
122
+ "enum": [
123
+ "dietaryWater",
124
+ "dietaryEnergy",
125
+ "dietaryProtein",
126
+ "dietaryCarbohydrates",
127
+ "dietaryFiber",
128
+ "dietarySugar",
129
+ "dietaryFatTotal",
130
+ "dietaryFatSaturated",
131
+ "dietaryFatMonounsaturated",
132
+ "dietaryFatPolyunsaturated",
133
+ "dietaryCholesterol",
134
+ "dietaryCaffeine",
135
+ "dietarySodium",
136
+ "dietaryPotassium",
137
+ "dietaryCalcium",
138
+ "dietaryMagnesium",
139
+ "dietaryPhosphorus",
140
+ "dietaryChloride",
141
+ "dietaryIron",
142
+ "dietaryZinc",
143
+ "dietaryCopper",
144
+ "dietaryManganese",
145
+ "dietarySelenium",
146
+ "dietaryIodine",
147
+ "dietaryChromium",
148
+ "dietaryMolybdenum",
149
+ "dietaryVitaminA",
150
+ "dietaryVitaminC",
151
+ "dietaryVitaminD",
152
+ "dietaryVitaminE",
153
+ "dietaryVitaminK",
154
+ "dietaryVitaminB6",
155
+ "dietaryVitaminB12",
156
+ "dietaryThiamin",
157
+ "dietaryRiboflavin",
158
+ "dietaryNiacin",
159
+ "dietaryFolate",
160
+ "dietaryBiotin",
161
+ "dietaryPantothenicAcid",
162
+ "bodyMass",
163
+ "leanBodyMass",
164
+ "bodyFat",
165
+ "bmi",
166
+ "height",
167
+ "waistCircumference",
168
+ "mindfulMinutes"
169
+ ]
170
+ },
171
+ "value": {
172
+ "type": "number",
173
+ "minimum": 0
174
+ },
175
+ "unit": {
176
+ "type": "string"
177
+ },
178
+ "at": {
179
+ "type": "string"
180
+ }
181
+ },
182
+ "required": [
183
+ "metric",
184
+ "value"
185
+ ]
186
+ },
187
+ "minItems": 1,
188
+ "maxItems": 20
189
+ }
190
+ },
191
+ "required": [
192
+ "samples"
193
+ ]
194
+ }
195
+ },
196
+ "calendar-query": {
197
+ "name": "fridaynext_calendar_query",
198
+ "description": "查询当前App会话绑定iPhone的日历事件或提醒事项。默认未来7天,最多31天,按手机当前时区处理未带时区的日期;kinds可分别选择events/reminders。",
199
+ "parameters": {
200
+ "type": "object",
201
+ "additionalProperties": false,
202
+ "properties": {
203
+ "kinds": {
204
+ "type": "array",
205
+ "items": {
206
+ "type": "string",
207
+ "enum": [
208
+ "events",
209
+ "reminders"
210
+ ]
211
+ }
212
+ },
213
+ "start": {
214
+ "type": "string"
215
+ },
216
+ "end": {
217
+ "type": "string"
218
+ },
219
+ "limit": {
220
+ "type": "integer",
221
+ "minimum": 1,
222
+ "maximum": 50
223
+ }
224
+ }
225
+ }
226
+ },
227
+ "calendar-log": {
228
+ "name": "fridaynext_calendar_log",
229
+ "description": "在当前App会话绑定iPhone创建日历事件(kind=event)或待办(kind=reminder),最多10条;只用用户选定的默认日历/提醒列表,不修改删除或创建重复规则。事件使用start/end/allDay/location;提醒使用dueDate/priority;alarmMinutesBefore设置闹钟,0表示不设。事件默认1小时,全天默认次日结束。需相应实体共享和系统权限。Agent后台定时工作使用Hermes自身定时任务。结果未知时不要自动重试。",
230
+ "parameters": {
231
+ "type": "object",
232
+ "additionalProperties": false,
233
+ "properties": {
234
+ "items": {
235
+ "type": "array",
236
+ "items": {
237
+ "type": "object",
238
+ "additionalProperties": false,
239
+ "properties": {
240
+ "kind": {
241
+ "type": "string",
242
+ "enum": [
243
+ "event",
244
+ "reminder"
245
+ ]
246
+ },
247
+ "title": {
248
+ "type": "string",
249
+ "minLength": 1,
250
+ "maxLength": 200
251
+ },
252
+ "notes": {
253
+ "type": "string",
254
+ "maxLength": 2000
255
+ },
256
+ "start": {
257
+ "type": "string"
258
+ },
259
+ "end": {
260
+ "type": "string"
261
+ },
262
+ "allDay": {
263
+ "type": "boolean"
264
+ },
265
+ "location": {
266
+ "type": "string",
267
+ "maxLength": 200
268
+ },
269
+ "dueDate": {
270
+ "type": "string"
271
+ },
272
+ "priority": {
273
+ "type": "string",
274
+ "enum": [
275
+ "none",
276
+ "low",
277
+ "medium",
278
+ "high"
279
+ ]
280
+ },
281
+ "alarmMinutesBefore": {
282
+ "type": "integer",
283
+ "minimum": 0,
284
+ "maximum": 20160
285
+ }
286
+ },
287
+ "required": [
288
+ "kind",
289
+ "title"
290
+ ]
291
+ },
292
+ "minItems": 1,
293
+ "maxItems": 10
294
+ }
295
+ },
296
+ "required": [
297
+ "items"
298
+ ]
299
+ }
300
+ }
301
+ }
302
+ }