@flowy-agent-store/protocol 0.1.0-beta.3 → 0.1.0-beta.5

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/dist/index.mjs CHANGED
@@ -5,7 +5,59 @@
5
5
  * The chat surface uses only opaque public conversation/message IDs. Internal
6
6
  * execution/session/step/attempt IDs never appear in this module.
7
7
  */
8
- const APP_SERVER_PROTOCOL_VERSION = "2026-08-26";
8
+ /**
9
+ * A contract **fingerprint**, not a version number: it must differ from the
10
+ * previous value on any wire change at all, additive included. The shape is
11
+ * `fp-<n>` — a plain counter, so a bump just increments it and no value is ever
12
+ * reused by accident.
13
+ *
14
+ * So it is a **label, not a version**: neither a release number nor a date.
15
+ * Until `fp-1` the values were date stamps (kept below as history), and those
16
+ * dates were **not** the day of the change: consecutive changes advanced the
17
+ * stamp a day each, so they ran ahead of the calendar. The list below is keyed
18
+ * by *value* — read it as "which wire change is this?", never as "when did this
19
+ * ship".
20
+ *
21
+ * `2026-09-16` carried `StoreItem.published_at`; `2026-09-17` added the two MCP
22
+ * declaration write methods (`config/set-mcp`, `config/set-mcp-enabled`);
23
+ * `2026-09-18` adds `config/get-mcp`, the file editor's read of the same file;
24
+ * `2026-09-19` adds the `conversation/list-changed` notification; `2026-09-20`
25
+ * adds the Skill **file tree** read face (`skill/files`, `skill/file`) so a
26
+ * Skill's companion files are readable, not just its bounded manifest summary;
27
+ * `2026-09-21` adds the connector **call proxy** (`connector/call`), so a third
28
+ * party can run an installed MCP tool while the connection and its credentials
29
+ * stay on the host. **`fp-1` changes the shape only** (date stamp → counter): a
30
+ * `2026-…` value invites being read as a release date, and no wire behaviour
31
+ * changed with the rename. **`fp-2` carries the tools' parameters**
32
+ * (`ConnectorTool.input_schema`, plus `tools_truncated` on `ConnectorDetail`
33
+ * and `ConnectorProbeResult`): a caller that must *name* a tool to be granted it
34
+ * should be able to read what that tool takes. It is the counterpart of the
35
+ * host's `[connector_proxy]` grant moving from one tool at a time to the
36
+ * connector (doc `26`). **`fp-3` makes a Skill selectable per turn**:
37
+ * `conversation/send` gains an optional `mentions` list whose only honoured kind
38
+ * is `skill`, so one turn can mount a Skill's instructions without rewriting the
39
+ * conversation's create-time snapshot (doc `27` 阶段 1). **`fp-4` lets a
40
+ * conversation be created as an installed expert**: `conversation/create` gains
41
+ * an optional `agent_id`, whose Definition supplies the chat's preset identity
42
+ * plus its own Skill and Connector fences — frozen at creation, since none of
43
+ * those keys is mutable afterwards (doc `27` 阶段 2a). **`fp-5` opens a Team's
44
+ * Leader the same way**: an optional `team_id` runs the `team/run` orchestration
45
+ * (members, template, fences) but stops before the goal turn, so the client
46
+ * speaks first; `agent_id` and `team_id` are mutually exclusive (阶段 2b).
47
+ * **`fp-6` makes the model and the reasoning level selectable per call**:
48
+ * `conversation/send` and `agent/run` each gain an optional `model` and
49
+ * `reasoning_effort`. The scope is deliberately the **conversation** (send) and
50
+ * the **run** (agent/run), not "just this turn": the Nomi runtime is built from
51
+ * the persisted row, so a send-carried value is a sticky switch that takes
52
+ * effect on that very turn (doc `29` §4). `ConversationView` also gains
53
+ * `reasoning_effort`, because a setting that can be written by three methods but
54
+ * read back by none is not a setting a client can honour (doc `29` §5.5).
55
+ * **`fp-7` adds the `zip` marketplace source kind**: `market/add` accepts
56
+ * `source_kind: "zip"`, one archive whose root *is* the market root. The
57
+ * official bundles move to it because the old `url` form made a first fetch
58
+ * mirror 14,714 files (611 MiB) for `experts` alone (doc `30`).
59
+ */
60
+ const APP_SERVER_PROTOCOL_VERSION = "fp-7";
9
61
  //#endregion
10
62
  //#region src/errors.ts
11
63
  var AppServerError = class extends Error {
@@ -77,4 +129,324 @@ function isRetryableError(error) {
77
129
  return (error instanceof AppServerError || error instanceof TransportError) && error.retryable;
78
130
  }
79
131
  //#endregion
80
- export { APP_SERVER_PROTOCOL_VERSION, AppServerError, ProtocolError, RequestTimeoutError, TransportError, formatError, isAppServerError, isRetryableError, isRetryableTransportError };
132
+ //#region src/localized.ts
133
+ /** The other language, i.e. the second link of every fallback chain. */
134
+ function otherLocalizedLang(lang) {
135
+ return lang === "zh" ? "en" : "zh";
136
+ }
137
+ /**
138
+ * Map an i18n language tag (`zh-CN`, `en-US`, `en`) to a variant language.
139
+ * Anything that is not English resolves to `zh`, matching the app default.
140
+ */
141
+ function toLocalizedLang(language) {
142
+ return (language ?? "").toLowerCase().startsWith("en") ? "en" : "zh";
143
+ }
144
+ /** `{field}_{lang}` → `{field}_{other}` → `""`. */
145
+ function pickLocalized(text, lang) {
146
+ if (!text) return "";
147
+ return text[lang]?.trim() || text[otherLocalizedLang(lang)]?.trim() || "";
148
+ }
149
+ /** Resolve a list of localized values, dropping the ones that resolve empty. */
150
+ function pickLocalizedList(list, lang) {
151
+ return (list ?? []).map((item) => pickLocalized(item, lang)).filter((value) => value.length > 0);
152
+ }
153
+ /** Non-empty string variants in fallback order. */
154
+ function variantKeys(field, lang) {
155
+ return [`${field}_${lang}`, `${field}_${otherLocalizedLang(lang)}`];
156
+ }
157
+ /** `{field}_{lang}` → `{field}_{other}` as a string, when either carries text. */
158
+ function pickVariantText(variants, field, lang) {
159
+ for (const key of variantKeys(field, lang)) {
160
+ const value = variants?.[key];
161
+ if (typeof value === "string" && value.trim().length > 0) return value;
162
+ }
163
+ }
164
+ /** `{field}_{lang}` → `{field}_{other}` as a string list, when either is non-empty. */
165
+ function pickVariantList(variants, field, lang) {
166
+ for (const key of variantKeys(field, lang)) {
167
+ const value = variants?.[key];
168
+ if (Array.isArray(value)) {
169
+ const items = value.filter((item) => typeof item === "string" && item.length > 0);
170
+ if (items.length > 0) return items;
171
+ }
172
+ }
173
+ }
174
+ /**
175
+ * Market entry tags. Per D8=A `tags_{lang}` outranks `legacy_tags_{lang}` —
176
+ * the legacy field only fills in when the current one is absent, in either
177
+ * language.
178
+ */
179
+ function pickEntryTags(variants, lang) {
180
+ return pickVariantList(variants, "tags", lang) ?? pickVariantList(variants, "legacy_tags", lang);
181
+ }
182
+ /**
183
+ * A market entry text field: variant first, then the baseline field
184
+ * (`entry.description`, `entry.name`, …) as the last link of the chain.
185
+ */
186
+ function pickEntryText(variants, field, lang, baseline) {
187
+ return pickVariantText(variants, field, lang) ?? baseline ?? void 0;
188
+ }
189
+ //#endregion
190
+ //#region src/conversation-events.ts
191
+ function stringValue(value) {
192
+ return typeof value === "string" ? value : null;
193
+ }
194
+ function numberValue(value) {
195
+ return typeof value === "number" ? value : null;
196
+ }
197
+ function isRecord(value) {
198
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
199
+ }
200
+ /**
201
+ * Strict boolean reader: a wire value that is not a real boolean reads as
202
+ * `null` (unknown) rather than being coerced — "retryable" must never be
203
+ * guessed from a truthy string.
204
+ */
205
+ function booleanValue(value) {
206
+ return typeof value === "boolean" ? value : null;
207
+ }
208
+ /** Flatten a message/activity body to plain text, JSON-encoding anything else. */
209
+ function contentToText(value) {
210
+ if (typeof value === "string") return value;
211
+ if (isRecord(value) && typeof value.content === "string") return value.content;
212
+ return value == null ? "" : JSON.stringify(value);
213
+ }
214
+ /** Activity bodies may be nested one level down or JSON-encoded as a string. */
215
+ function unwrapContent(value) {
216
+ if (typeof value === "string") try {
217
+ return JSON.parse(value);
218
+ } catch {
219
+ return value;
220
+ }
221
+ if (isRecord(value)) {
222
+ const content = value.content;
223
+ if (typeof content === "string") try {
224
+ return JSON.parse(content);
225
+ } catch {
226
+ return value;
227
+ }
228
+ }
229
+ return value;
230
+ }
231
+ /** Shape a thinking body (`message.thinking`, or `message.activity` kind `thinking`). */
232
+ function thinkingData(value) {
233
+ if (isRecord(value) && typeof value.content === "string") return {
234
+ content: value.content,
235
+ subject: stringValue(value.subject),
236
+ status: stringValue(value.status),
237
+ duration: numberValue(value.duration) ?? numberValue(value.duration_ms)
238
+ };
239
+ const candidate = unwrapContent(value);
240
+ if (!isRecord(candidate)) return {
241
+ content: typeof candidate === "string" ? candidate : "",
242
+ subject: null,
243
+ status: null,
244
+ duration: null
245
+ };
246
+ return {
247
+ content: stringValue(candidate.content) ?? "",
248
+ subject: stringValue(candidate.subject),
249
+ status: stringValue(candidate.status),
250
+ duration: numberValue(candidate.duration) ?? numberValue(candidate.duration_ms)
251
+ };
252
+ }
253
+ /** Shape a tips body; `type` is accepted as an alias of `tip_type`. */
254
+ function tipsData(value) {
255
+ const readTip = (data) => {
256
+ const content = stringValue(data.content);
257
+ const tipType = stringValue(data.tip_type) ?? stringValue(data.type);
258
+ if (content === null && tipType === null) return null;
259
+ return {
260
+ content: content ?? "",
261
+ tipType: tipType ?? "info"
262
+ };
263
+ };
264
+ if (isRecord(value)) {
265
+ const direct = readTip(value);
266
+ if (direct) return direct;
267
+ }
268
+ const candidate = unwrapContent(value);
269
+ if (isRecord(candidate)) {
270
+ const parsed = readTip(candidate);
271
+ if (parsed) return parsed;
272
+ }
273
+ if (candidate != null && !isRecord(candidate)) return {
274
+ content: String(candidate),
275
+ tipType: "info"
276
+ };
277
+ return {
278
+ content: "",
279
+ tipType: "info"
280
+ };
281
+ }
282
+ /** Shape a tool-call body; `null` when the body carries nothing tool-shaped. */
283
+ function toolCallData(value) {
284
+ const candidate = unwrapContent(value);
285
+ if (!isRecord(candidate)) return null;
286
+ const name = stringValue(candidate.name) ?? stringValue(candidate.tool_name) ?? stringValue(candidate.tool);
287
+ if (!name && candidate.args === void 0 && candidate.arguments === void 0 && candidate.output === void 0 && candidate.result === void 0) return null;
288
+ return {
289
+ name,
290
+ args: candidate.args ?? candidate.arguments ?? candidate.input,
291
+ output: candidate.output ?? candidate.result,
292
+ status: stringValue(candidate.status)
293
+ };
294
+ }
295
+ /**
296
+ * Shape a plan body; `null` when there is no usable step list.
297
+ *
298
+ * `step` is accepted as an alias of `content`: the tool's own argument is named
299
+ * `step`, and the producer normalizes it to `content` for the plan row — a row
300
+ * written before that normalization (or by a producer that skipped it) would
301
+ * otherwise render as an empty plan.
302
+ */
303
+ function planData(value) {
304
+ const candidate = unwrapContent(value);
305
+ if (!isRecord(candidate) || !Array.isArray(candidate.entries)) return null;
306
+ const entries = candidate.entries.flatMap((raw) => {
307
+ if (!isRecord(raw)) return [];
308
+ const content = stringValue(raw.content) ?? stringValue(raw.step);
309
+ if (!content) return [];
310
+ return [{
311
+ content,
312
+ status: planStepStatus(raw.status)
313
+ }];
314
+ });
315
+ return entries.length > 0 ? { entries } : null;
316
+ }
317
+ /** Unknown/absent step statuses read as `pending` — never as "done". */
318
+ function planStepStatus(value) {
319
+ return value === "completed" || value === "in_progress" ? value : "pending";
320
+ }
321
+ /** Shape a `context.usage` payload; `null` when nothing was actually measured. */
322
+ function parseContextUsage(value) {
323
+ if (!isRecord(value)) return null;
324
+ const used = typeof value.used_tokens === "number" ? value.used_tokens : 0;
325
+ const window = typeof value.window_tokens === "number" ? value.window_tokens : 0;
326
+ if (used <= 0 || window <= 0) return null;
327
+ const rawPercent = typeof value.percent === "number" ? value.percent : used / window * 100;
328
+ return {
329
+ used_tokens: used,
330
+ window_tokens: window,
331
+ percent: Math.min(100, Math.max(0, rawPercent)),
332
+ updated_at: typeof value.updated_at === "number" ? value.updated_at : Date.now(),
333
+ source: typeof value.source === "string" ? value.source : "measured"
334
+ };
335
+ }
336
+ /**
337
+ * Shape a per-turn `usage` body (W9 / R14); `null` when the runtime reported
338
+ * nothing usable.
339
+ *
340
+ * A missing side is **unknown**, not zero: half a bill is not a bill, so a
341
+ * frame that only carries `input_tokens` decodes to `null` rather than to a
342
+ * total that silently drops the output side. Same rule for an all-zero report —
343
+ * "no tokens reported" must never render as "this turn was free".
344
+ */
345
+ function parseTurnUsage(value) {
346
+ if (!isRecord(value)) return null;
347
+ const input = typeof value.input_tokens === "number" ? value.input_tokens : null;
348
+ const output = typeof value.output_tokens === "number" ? value.output_tokens : null;
349
+ if (input === null || output === null) return null;
350
+ if (input <= 0 && output <= 0) return null;
351
+ return {
352
+ input_tokens: input,
353
+ output_tokens: output,
354
+ total_tokens: typeof value.total_tokens === "number" ? value.total_tokens : input + output
355
+ };
356
+ }
357
+ /**
358
+ * Decode one `conversation/event` frame into a typed body.
359
+ *
360
+ * An activity frame whose `kind` is `thinking` is normalized to
361
+ * `message.thinking` (the server has two spellings for the same thing).
362
+ */
363
+ function decodeConversationEvent(event) {
364
+ const payload = event.payload ?? {};
365
+ const messageId = () => stringValue(payload.message_id);
366
+ const createdAt = () => numberValue(payload.created_at);
367
+ if (event.event_type === "message.activity" && stringValue(payload.kind) === "thinking") return {
368
+ kind: "message.thinking",
369
+ event,
370
+ messageId: messageId(),
371
+ createdAt: createdAt(),
372
+ thinking: thinkingData(payload),
373
+ replace: payload.replace === true
374
+ };
375
+ switch (event.event_type) {
376
+ case "message.created": return {
377
+ kind: "message.created",
378
+ event,
379
+ messageId: messageId(),
380
+ createdAt: createdAt(),
381
+ content: payload.content ?? ""
382
+ };
383
+ case "message.delta": return {
384
+ kind: "message.delta",
385
+ event,
386
+ messageId: messageId(),
387
+ createdAt: createdAt(),
388
+ delta: stringValue(payload.content) ?? "",
389
+ replace: payload.replace === true
390
+ };
391
+ case "message.thinking": return {
392
+ kind: "message.thinking",
393
+ event,
394
+ messageId: messageId(),
395
+ createdAt: createdAt(),
396
+ thinking: thinkingData(payload),
397
+ replace: payload.replace === true
398
+ };
399
+ case "message.tool": return {
400
+ kind: "message.tool",
401
+ event,
402
+ messageId: messageId(),
403
+ createdAt: createdAt(),
404
+ tool: toolCallData(payload)
405
+ };
406
+ case "message.tips": return {
407
+ kind: "message.tips",
408
+ event,
409
+ messageId: messageId(),
410
+ createdAt: createdAt(),
411
+ tips: tipsData(payload)
412
+ };
413
+ case "message.error": return {
414
+ kind: "message.error",
415
+ event,
416
+ messageId: messageId(),
417
+ createdAt: createdAt(),
418
+ message: stringValue(payload.message),
419
+ code: stringValue(payload.code),
420
+ retryable: booleanValue(payload.retryable)
421
+ };
422
+ case "message.activity": {
423
+ const activityKind = stringValue(payload.kind) ?? "activity";
424
+ return {
425
+ kind: "message.activity",
426
+ event,
427
+ messageId: messageId(),
428
+ createdAt: createdAt(),
429
+ activityKind,
430
+ content: payload.content ?? "",
431
+ usage: activityKind === "turn_completed" ? parseTurnUsage(payload.usage) : null
432
+ };
433
+ }
434
+ case "turn.status": return {
435
+ kind: "turn.status",
436
+ event,
437
+ running: stringValue(payload.status) === "running"
438
+ };
439
+ case "context.usage": return {
440
+ kind: "context.usage",
441
+ event,
442
+ usage: parseContextUsage(payload.context_usage)
443
+ };
444
+ default: return {
445
+ kind: "unknown",
446
+ event,
447
+ eventType: event.event_type
448
+ };
449
+ }
450
+ }
451
+ //#endregion
452
+ export { APP_SERVER_PROTOCOL_VERSION, AppServerError, ProtocolError, RequestTimeoutError, TransportError, booleanValue, contentToText, decodeConversationEvent, formatError, isAppServerError, isRecord, isRetryableError, isRetryableTransportError, numberValue, otherLocalizedLang, parseContextUsage, parseTurnUsage, pickEntryTags, pickEntryText, pickLocalized, pickLocalizedList, pickVariantList, pickVariantText, planData, stringValue, thinkingData, tipsData, toLocalizedLang, toolCallData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowy-agent-store/protocol",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.5",
4
4
  "description": "Versioned App Server Protocol types and wire errors (no runtime, no DOM/Node deps)",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",