@linxin666/dsh-remote-bridge 0.4.8 → 0.4.9

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 (55) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +50 -17
  3. package/README.zh.md +50 -17
  4. package/lib/client.js +274 -253
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +6690 -2277
  7. package/lib/types/client/PairEntry.d.ts +2 -2
  8. package/lib/types/client/PairPanel.d.ts +10 -2
  9. package/lib/types/client/icons.d.ts +5 -13
  10. package/lib/types/client/locales.d.ts +10 -14
  11. package/lib/types/client/semantic.d.ts +9 -5
  12. package/lib/types/core/commands.d.ts +59 -0
  13. package/lib/types/core/connection.d.ts +68 -0
  14. package/lib/types/core/devices.d.ts +98 -2
  15. package/lib/types/core/hub.d.ts +65 -15
  16. package/lib/types/core/liveactivity.d.ts +324 -0
  17. package/lib/types/core/protocol.d.ts +260 -1
  18. package/lib/types/core/push.d.ts +178 -0
  19. package/lib/types/core/questions.d.ts +61 -9
  20. package/lib/types/core/session-meta.d.ts +55 -1
  21. package/lib/types/core/squads.d.ts +130 -0
  22. package/lib/types/core/usage-stats.d.ts +160 -0
  23. package/lib/types/core/usage.d.ts +294 -0
  24. package/lib/types/host/apns.d.ts +151 -0
  25. package/lib/types/host/squads-ledger.d.ts +39 -0
  26. package/lib/types/host/squads.d.ts +77 -0
  27. package/lib/types/host/usage-stats.d.ts +75 -0
  28. package/lib/types/host/watchers.d.ts +88 -0
  29. package/lib/types/index.d.ts +18 -2
  30. package/package.json +13 -13
  31. package/src/client/PairEntry.tsx +58 -31
  32. package/src/client/PairPanel.tsx +181 -97
  33. package/src/client/icons.tsx +17 -60
  34. package/src/client/locales.ts +15 -23
  35. package/src/client/panel.module.css +239 -186
  36. package/src/client/semantic.ts +10 -6
  37. package/src/core/commands.ts +95 -0
  38. package/src/core/connection.ts +646 -10
  39. package/src/core/devices.ts +221 -3
  40. package/src/core/hub.ts +362 -42
  41. package/src/core/liveactivity.ts +833 -0
  42. package/src/core/protocol.ts +294 -1
  43. package/src/core/push.ts +354 -0
  44. package/src/core/questions.ts +81 -10
  45. package/src/core/session-meta.ts +73 -1
  46. package/src/core/squads.ts +345 -0
  47. package/src/core/usage-stats.ts +424 -0
  48. package/src/core/usage.ts +937 -0
  49. package/src/core/wire.ts +8 -0
  50. package/src/host/apns.ts +320 -0
  51. package/src/host/squads-ledger.ts +105 -0
  52. package/src/host/squads.ts +206 -0
  53. package/src/host/usage-stats.ts +155 -0
  54. package/src/host/watchers.ts +272 -0
  55. package/src/index.ts +257 -8
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The command channel's projection: the host's slash-command registry and one
3
+ * session's skill catalog folded into the single flat directory a phone lists.
4
+ *
5
+ * Nothing here is stateful. Every answer is read from the host on the call that
6
+ * answers it — no cache, no event, no snapshot — so a command a plugin
7
+ * registered a moment ago and a skill the session's own preset withdrew are
8
+ * both reflected in the next answer, and a phone never renders a directory that
9
+ * this bridge remembered on its behalf.
10
+ *
11
+ * The `line` of an item is the whole text a client completes into its draft,
12
+ * separator space included, because both host surfaces resolve a bare gesture
13
+ * only when whitespace or the end of the text follows the name: the command
14
+ * registry splits a line into name and input at that separator, and a skill
15
+ * gesture is `/(^|\s)\/([a-z0-9]+(?:-[a-z0-9]+)*)(?=\s|$)/` in
16
+ * `@deepseek-ai/dsh-tool-skill`. A skill line is therefore text a client writes
17
+ * and the host reads out of the submitted prompt, never a command line: a skill
18
+ * is not registered with the command registry, so `commands/execute` answers
19
+ * `undefined` for it — which is exactly what a caller of `session.command` is
20
+ * told with `matched: false`.
21
+ * @module dsh-remote-bridge/core/commands
22
+ */
23
+
24
+ /** One row of the directory: a slash command or a skill, as the phone renders it. */
25
+ export interface CommandItem {
26
+ /** The host's own name for the row, without a leading slash. */
27
+ readonly name: string
28
+ /** The host's own one-line summary, verbatim. */
29
+ readonly description: string
30
+ /** Which host catalog the row came from; the two never mix order. */
31
+ readonly kind: 'command' | 'skill'
32
+ /** The complete draft text that invokes this row. */
33
+ readonly line: string
34
+ }
35
+
36
+ /** The draft text one host name completes to: the gesture plus its separator. */
37
+ function lineOf(name: string): string {
38
+ return `/${name} `
39
+ }
40
+
41
+ /**
42
+ * The name and description of one host row, or undefined when the row carries
43
+ * neither a name nor a summary a client could render.
44
+ *
45
+ * The host's strict codec already guarantees the shape, so this only keeps a
46
+ * row this bridge could not render out of a phone's directory: a row with no
47
+ * name would cross as `/undefined`, which is worse than a shorter list.
48
+ * @param row - one element of a host catalog answer.
49
+ */
50
+ function namedRow(row: unknown): { readonly name: string; readonly description: string } | undefined {
51
+ if (typeof row !== 'object' || row === null) return undefined
52
+ const { name, description } = row as { name?: unknown; description?: unknown }
53
+ if (typeof name !== 'string' || name === '' || typeof description !== 'string') return undefined
54
+ return { name, description }
55
+ }
56
+
57
+ /**
58
+ * Fold the host's two catalogs into one directory: every command first, in the
59
+ * order the host listed them, then every skill, in the order the host listed
60
+ * them. Neither list is re-sorted, de-duplicated or cut into pages — a name
61
+ * both catalogs carry stays two rows, because the two rows do different things.
62
+ * @param commands - the `commands/list` answer, as it arrived.
63
+ * @param skills - the `skills/list` answer's `skills` array, as it arrived.
64
+ * @returns the rows a client renders, in the one order this protocol promises.
65
+ */
66
+ export function commandItems(commands: readonly unknown[], skills: readonly unknown[]): readonly CommandItem[] {
67
+ const items: CommandItem[] = []
68
+ for (const [kind, rows] of [['command', commands], ['skill', skills]] as const) {
69
+ for (const row of rows) {
70
+ const named = namedRow(row)
71
+ if (named === undefined) continue
72
+ items.push({ name: named.name, description: named.description, kind, line: lineOf(named.name) })
73
+ }
74
+ }
75
+ return items
76
+ }
77
+
78
+ /**
79
+ * Whether a gateway failure means this host serves no endpoint behind the
80
+ * channel at all, rather than refusing this one call.
81
+ *
82
+ * The gateway reports an endpoint nothing exports as `invocation-unavailable`
83
+ * and a withdrawn strict definition as `definition-unavailable`; both leave the
84
+ * call with nowhere to go, which is the one case this bridge answers with its
85
+ * own `commands-unavailable`. A service that is merely still activating keeps
86
+ * its own code: that window is retried before it arrives here, and a retried
87
+ * failure is a broken deployment rather than an absent channel.
88
+ *
89
+ * Both spellings of each code are recognized, exactly as `gateway-errors.ts`
90
+ * recognizes them for the activation window.
91
+ * @param code - the failure's own code, as it crossed to the refusal.
92
+ */
93
+ export function commandsUnavailable(code: string): boolean {
94
+ return ['invocation-unavailable', 'definition-unavailable'].some(bare => code === bare || code === `gateway/${bare}`)
95
+ }