@ryuhq/sdk 0.1.13 → 0.2.0

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 (90) hide show
  1. package/README.md +19 -6
  2. package/dist/agent-plugin.cjs +46 -0
  3. package/dist/agent-plugin.d.cts +42 -32
  4. package/dist/agent-plugin.d.ts +42 -32
  5. package/dist/agent-plugin.js +1 -1
  6. package/dist/agent.cjs +9 -0
  7. package/dist/agent.d.cts +377 -1
  8. package/dist/agent.d.ts +377 -1
  9. package/dist/agent.js +4 -2
  10. package/dist/app-Bkw7LlCK.d.ts +129 -0
  11. package/dist/app-DNaGmLVf.d.cts +129 -0
  12. package/dist/builder.cjs +1095 -0
  13. package/dist/builder.d.cts +212 -0
  14. package/dist/builder.d.ts +212 -0
  15. package/dist/builder.js +28 -0
  16. package/dist/chunk-A3RGEPDG.js +250 -0
  17. package/dist/chunk-FZSFZOIN.js +200 -0
  18. package/dist/{chunk-ODFEUVPW.js → chunk-HACAGK65.js} +1 -18
  19. package/dist/{chunk-AO2KJRDD.js → chunk-IEUQ3CDG.js} +125 -2
  20. package/dist/chunk-IKEDLLFY.js +19 -0
  21. package/dist/chunk-IOLP5FFE.js +354 -0
  22. package/dist/{chunk-G6FLVEC4.js → chunk-JX6DDRXV.js} +46 -0
  23. package/dist/chunk-T5676WL2.js +240 -0
  24. package/dist/chunk-TLDPEGC7.js +21 -0
  25. package/dist/chunk-TXSHHZF2.js +0 -0
  26. package/dist/{chunk-MTUBUPIV.js → chunk-ULSVL7EC.js} +8 -227
  27. package/dist/chunk-VLIRNNAE.js +154 -0
  28. package/dist/chunk-W3KPP4WN.js +135 -0
  29. package/dist/cli.cjs +258 -14
  30. package/dist/cli.js +96 -16
  31. package/dist/client-D5U6ssPc.d.cts +84 -0
  32. package/dist/client-D5U6ssPc.d.ts +84 -0
  33. package/dist/index.cjs +519 -5
  34. package/dist/index.d.cts +16 -632
  35. package/dist/index.d.ts +16 -632
  36. package/dist/index.js +63 -695
  37. package/dist/manifest.cjs +129 -3
  38. package/dist/manifest.d.cts +105 -2
  39. package/dist/manifest.d.ts +105 -2
  40. package/dist/manifest.js +7 -1
  41. package/dist/mcp/client.cjs +180 -0
  42. package/dist/mcp/client.d.cts +49 -0
  43. package/dist/mcp/client.d.ts +49 -0
  44. package/dist/mcp/client.js +10 -0
  45. package/dist/mcp/server.cjs +370 -0
  46. package/dist/mcp/server.d.cts +126 -0
  47. package/dist/mcp/server.d.ts +126 -0
  48. package/dist/mcp/server.js +9 -0
  49. package/dist/mcp.cjs +376 -0
  50. package/dist/mcp.d.cts +2 -0
  51. package/dist/mcp.d.ts +2 -0
  52. package/dist/mcp.js +17 -0
  53. package/dist/model.cjs +141 -0
  54. package/dist/model.d.cts +33 -0
  55. package/dist/model.d.ts +33 -0
  56. package/dist/model.js +18 -0
  57. package/dist/plugin.cjs +46 -0
  58. package/dist/plugin.d.cts +215 -0
  59. package/dist/plugin.d.ts +215 -0
  60. package/dist/plugin.js +8 -0
  61. package/dist/runnable.cjs +1230 -0
  62. package/dist/runnable.d.cts +271 -0
  63. package/dist/runnable.d.ts +271 -0
  64. package/dist/runnable.js +28 -0
  65. package/dist/{index-B6SkaAjJ.d.ts → tool-DSx2bFx8.d.ts} +35 -458
  66. package/dist/{index-BvAB5eMk.d.cts → tool-u-VR0fLF.d.cts} +35 -458
  67. package/package.json +38 -2
  68. package/src/agent/loop.test.ts +4 -4
  69. package/src/agent/tools.ts +3 -3
  70. package/src/agent-plugin.test.ts +58 -0
  71. package/src/agent-plugin.ts +108 -35
  72. package/src/cli/dev.test.ts +26 -47
  73. package/src/cli/dev.ts +10 -2
  74. package/src/cli.ts +98 -15
  75. package/src/exports-lockstep.test.ts +92 -0
  76. package/src/generated/plugin-manifest.ts +243 -27
  77. package/src/index.ts +35 -0
  78. package/src/manifest-schema.test.ts +30 -1
  79. package/src/manifest.fixtures.test.ts +13 -3
  80. package/src/manifest.test.ts +96 -10
  81. package/src/manifest.ts +334 -187
  82. package/src/mcp/index.ts +18 -0
  83. package/src/model/index.ts +22 -0
  84. package/src/plugin/ryu-plugin.ts +82 -0
  85. package/src/runnable/app.test.ts +2 -0
  86. package/src/runnable/app.ts +5 -2
  87. package/src/runnable/index.ts +2 -0
  88. package/src/runnable/primitives.ts +57 -0
  89. package/src/runnable/tool.ts +1 -1
  90. package/src/runnable/turn-hook.ts +4 -1
@@ -0,0 +1,1095 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/builder.ts
21
+ var builder_exports = {};
22
+ __export(builder_exports, {
23
+ AgentBuilder: () => AgentBuilder,
24
+ AppBuilder: () => AppBuilder,
25
+ PluginBuilder: () => PluginBuilder,
26
+ SkillBuilder: () => SkillBuilder,
27
+ ToolBuilder: () => ToolBuilder,
28
+ WorkflowBuilder: () => WorkflowBuilder,
29
+ agent: () => agent,
30
+ app: () => app,
31
+ skill: () => skill,
32
+ tool: () => tool,
33
+ workflow: () => workflow
34
+ });
35
+ module.exports = __toCommonJS(builder_exports);
36
+
37
+ // src/manifest.ts
38
+ var import_node_module = require("module");
39
+ var import_zod = require("zod");
40
+ var RunnableKindSchema = import_zod.z.enum([
41
+ "agent",
42
+ "workflow",
43
+ "tool",
44
+ "skill",
45
+ // A companion surface (in-desktop panel). Added so a packable plugin can
46
+ // declare a companion runnable that flows through Core's existing Companion
47
+ // handler → app_contrib → `GET /api/plugins/contributions` → the desktop
48
+ // `/plugin/<id>` route. Its `config.ui_entry` (see `CompanionRunnableConfigSchema`)
49
+ // is what `ryu pack` bundles into `ui_code`.
50
+ "companion"
51
+ ]);
52
+ var RunnableMetaSchema = import_zod.z.object({
53
+ /** Stable unique identifier (e.g. `"agent-researcher"`). */
54
+ id: import_zod.z.string().min(1),
55
+ /** Human-readable display name. */
56
+ name: import_zod.z.string().min(1),
57
+ /** Which kind of runnable this entry describes. */
58
+ kind: RunnableKindSchema,
59
+ /**
60
+ * Optional per-kind config blob. Mirrors Core's `RunnableEntry.config`
61
+ * (`Option<serde_json::Value>`) so a manifest authored here round-trips
62
+ * through Core-strict validation. Left opaque (a record) at this authoring
63
+ * layer; the per-kind shape is enforced by Core's `validate_runnable`.
64
+ *
65
+ * For a `companion` runnable, `config.ui_entry` names the plugin's UI entry
66
+ * module (relative to the manifest dir). `ryu pack` bundles that entry into
67
+ * the emitted `ui_code`; Core's `CompanionConfig.ui_entry` is the lockstep
68
+ * field so a packed companion validates.
69
+ */
70
+ config: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
71
+ });
72
+ function labelImpersonatesSystemChrome(label) {
73
+ const lower = label.toLowerCase();
74
+ return lower.includes("ryu") || lower.includes("system");
75
+ }
76
+ var CompanionSurfaceSchema = import_zod.z.object({
77
+ /** Display label for the companion panel tab or tooltip. Anti-impersonation:
78
+ * may not pose as first-party Ryu/system chrome (see
79
+ * {@link labelImpersonatesSystemChrome}). */
80
+ label: import_zod.z.string().min(1).refine((value) => !labelImpersonatesSystemChrome(value), {
81
+ message: "companion label must not impersonate system chrome (must not contain 'ryu' or 'system')"
82
+ }),
83
+ /** Icon identifier resolved by the desktop shell. */
84
+ icon: import_zod.z.string().optional(),
85
+ /** Keyboard shortcut string (e.g. `"ctrl+shift+r"`). */
86
+ shortcut: import_zod.z.string().optional()
87
+ });
88
+ var TurnHookContributionSchema = import_zod.z.object({
89
+ /** Stable id for this hook (unique within the plugin). */
90
+ id: import_zod.z.string().min(1),
91
+ /** Turn boundary this fires on. Today only `"post_assistant_turn"`. */
92
+ on: import_zod.z.string().min(1).default("post_assistant_turn"),
93
+ /** The JS hook body executed in the sandbox (returns a directive). */
94
+ code: import_zod.z.string().min(1).optional(),
95
+ /** Path to the hook body, relative to the plugin root (`hooks/<name>.js`). */
96
+ code_file: import_zod.z.string().min(1).optional(),
97
+ /**
98
+ * Cheap pre-gate mirroring Core's `HookMatch` (serde name `match` on
99
+ * `TurnHookContribution.run_when`). MUST round-trip through this schema:
100
+ * `ryu pack`/`publish` persist `safeParse(...).data`, so a field missing here
101
+ * is silently STRIPPED before signing — a tool-gated `pre_tool_use` hook
102
+ * (e.g. `tools: ["bash*"]`) would lose its gate and run on EVERY tool call.
103
+ */
104
+ match: import_zod.z.object({
105
+ /** Run only if the request set this composer flag true. */
106
+ flag: import_zod.z.string().optional(),
107
+ /** Run if the last user message starts with any of these prefixes. */
108
+ commands: import_zod.z.array(import_zod.z.string()).default([]),
109
+ /** Run if the plugin has stored state for this conversation. */
110
+ stateful: import_zod.z.boolean().default(false),
111
+ /** Run if `ctx.tool_name` matches any of these `*`-wildcard patterns. */
112
+ tools: import_zod.z.array(import_zod.z.string()).default([])
113
+ }).optional()
114
+ }).refine((h) => Boolean(h.code) !== Boolean(h.code_file), {
115
+ message: "a turn hook must declare exactly one of 'code' (inline body) or 'code_file' (path to hooks/<name>.js)",
116
+ path: ["code_file"]
117
+ });
118
+ var HookEventContributionSchema = import_zod.z.object({
119
+ /** Fully-qualified event id: `<plugin id>#<event name>`, e.g. `@acme/meetings#meeting.ended`. */
120
+ id: import_zod.z.string().min(1),
121
+ /** Human-readable title for the event picker. */
122
+ title: import_zod.z.string().min(1),
123
+ /** What the event means and when it fires. */
124
+ description: import_zod.z.string().optional(),
125
+ /** Example of the `ctx.event` payload. Documentation, not a validated schema. */
126
+ payload_example: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
127
+ });
128
+ var PiExtensionContributionSchema = import_zod.z.object({
129
+ /** Stable id for this extension within the plugin (`[a-z0-9][a-z0-9._-]*`). */
130
+ id: import_zod.z.string().min(1),
131
+ /** Path to the source, relative to the plugin root: `pi-extensions/<name>.ts`. */
132
+ file: import_zod.z.string().min(1),
133
+ /** Optional one-liner describing what the extension adds to the agent. */
134
+ description: import_zod.z.string().optional()
135
+ });
136
+ var OutputStyleContributionSchema = import_zod.z.object({
137
+ /** Stable id for this style within the plugin (`[a-z0-9][a-z0-9._-]*`). It is
138
+ * also the persisted selection key, so it must survive a settings key and a URL
139
+ * path. */
140
+ id: import_zod.z.string().min(1),
141
+ /** SOURCE form: path to the Markdown file, relative to the plugin root —
142
+ * exactly `output-styles/<name>.md`. `ryu pack` replaces this with `source`. */
143
+ file: import_zod.z.string().min(1).optional(),
144
+ /** WIRE form: the file's contents verbatim, frontmatter INCLUDED. The whole file
145
+ * rather than a pre-split body plus mirrored `name`/`description` keys, so a
146
+ * plugin style and a user's own `output-styles/*.md` go through one parser and
147
+ * the frontmatter stays the single source of truth for a style's metadata. */
148
+ source: import_zod.z.string().optional()
149
+ });
150
+ var DEFAULT_WIDGET_MIME = "text/html+skybridge";
151
+ var DEFAULT_WIDGET_DISPLAY_MODE = "inline";
152
+ var WidgetContributionSchema = import_zod.z.object({
153
+ /** The fully-qualified tool id whose result renders this widget. */
154
+ tool_id: import_zod.z.string().min(1),
155
+ /** `ui://widget/<slug>.html` — the widget resource uri. */
156
+ uri: import_zod.z.string().min(1),
157
+ /** Source entry (e.g. `src/apps/checklist/index.tsx`) for `ryu pack`. */
158
+ ui_entry: import_zod.z.string().optional(),
159
+ /** Widget MIME dialect (default `text/html+skybridge`). */
160
+ mime: import_zod.z.string().default(DEFAULT_WIDGET_MIME),
161
+ /** Default display mode (`inline` | `fullscreen` | `pip`). */
162
+ default_display_mode: import_zod.z.string().default(DEFAULT_WIDGET_DISPLAY_MODE)
163
+ });
164
+ var ChatWidgetTemplateSchema = import_zod.z.object({
165
+ id: import_zod.z.string().regex(/^[a-z0-9][a-z0-9._:-]*$/),
166
+ title: import_zod.z.string().min(1),
167
+ description: import_zod.z.string().optional(),
168
+ triggers: import_zod.z.array(import_zod.z.string()).default([]),
169
+ examples: import_zod.z.array(import_zod.z.string()).default([]),
170
+ backing: import_zod.z.object({
171
+ tool_id: import_zod.z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/).optional(),
172
+ view_id: import_zod.z.string().regex(/^[a-z0-9][a-z0-9._:-]*$/).optional()
173
+ }),
174
+ display_mode: import_zod.z.string().min(1),
175
+ safe_action_ids: import_zod.z.array(import_zod.z.string().regex(/^[a-z0-9][a-z0-9._-]*$/)).default([]),
176
+ availability: import_zod.z.string().default("available")
177
+ }).superRefine((value, ctx) => {
178
+ const count = Number(Boolean(value.backing.tool_id)) + Number(Boolean(value.backing.view_id));
179
+ if (count !== 1 && value.availability === "available") {
180
+ ctx.addIssue({ code: "custom", path: ["backing"], message: "available templates need exactly one backing tool_id or view_id" });
181
+ }
182
+ if (count > 1) {
183
+ ctx.addIssue({ code: "custom", path: ["backing"], message: "backing must declare at most one of tool_id or view_id" });
184
+ }
185
+ });
186
+ var ToolAppConfigSchema = import_zod.z.object({
187
+ /** MCP tool slug this runnable wraps — the fully-qualified `<server>.<name>` id. */
188
+ slug: import_zod.z.string().min(1),
189
+ /** The tool description the model reads when choosing it. Carried here because a
190
+ * packed app's manifest is the only channel (there is no `generated.rs`); Core's
191
+ * app-tool synthesis reads it back onto the `RegistryTool`. */
192
+ description: import_zod.z.string(),
193
+ /** JSON Schema for the tool's arguments (used for validation + the LLM tool
194
+ * surface). Snake_case to match `widget_accessible`. Absent = no arguments. */
195
+ input_schema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
196
+ /** True when calling this tool renders the app's widget (carries the template). */
197
+ widget: import_zod.z.boolean().default(false),
198
+ /** True when a mounted widget may `callTool` this tool (a companion), or when a
199
+ * render tool's widget may call any companion the app declares. */
200
+ widget_accessible: import_zod.z.boolean().default(false),
201
+ /** Optional status label shown while the render tool runs. */
202
+ invoking: import_zod.z.string().optional(),
203
+ /** Optional status label shown when the render tool finishes. */
204
+ invoked: import_zod.z.string().optional()
205
+ });
206
+ var ContributesSchema = import_zod.z.object({
207
+ turn_hooks: import_zod.z.array(TurnHookContributionSchema).default([]),
208
+ /** App events this plugin EMITS — the provider half of the hook system, whose
209
+ * consumer half is `turn_hooks`. Mirrors the Rust `Contributes.hook_events`;
210
+ * omitting it here would have `ryu pack` strip every declared event before
211
+ * signing, leaving an app that emits events nothing is allowed to subscribe to. */
212
+ hook_events: import_zod.z.array(HookEventContributionSchema).default([]),
213
+ composer_controls: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
214
+ /** Chat feature descriptors whose behavior is implemented by the host shell.
215
+ * Mirrors the Rust-side `Contributes.chat_features`; keeping this field in the
216
+ * authoring schema prevents `ryu pack` from silently deleting a plugin's chat
217
+ * feature declaration before signing. */
218
+ chat_features: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
219
+ settings_tabs: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
220
+ slash_commands: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
221
+ /** App widgets (Ryu Apps). Each binds a render tool id to its
222
+ * `ui://widget/<slug>.html` template. Mirrors the Rust-side
223
+ * `Contributes.widgets` field, without which the CLI's zod parse would strip
224
+ * every widget an app authored here declares. */
225
+ widgets: import_zod.z.array(WidgetContributionSchema).default([]),
226
+ /** Metadata-only chat widget templates. */
227
+ chat_widget_templates: import_zod.z.array(ChatWidgetTemplateSchema).optional(),
228
+ /** App-registered sidebar sections (header + live list) and buttons (single nav
229
+ * rows). Loosely typed here — the shell owns the spec vocabulary — matching how
230
+ * `composer_controls`/`settings_tabs` are declared. Mirrors the Rust-side
231
+ * `Contributes.sidebar_sections` / `Contributes.sidebar_buttons`. */
232
+ sidebar_sections: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
233
+ sidebar_buttons: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
234
+ /** App-registered workspace dock panels (a tab in the desktop's bottom/right
235
+ * dock). Loosely typed for the same reason as the surfaces above — the shell
236
+ * owns the `panel` render-mode vocabulary and the `spec` payload. Mirrors the
237
+ * Rust-side `Contributes.dock_panels`; without it the CLI's zod parse would
238
+ * strip the dock panel an app declares here. */
239
+ dock_panels: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
240
+ /** App-registered live activities (the desktop "Dynamic Island" cards). Loosely
241
+ * typed for the same reason as the surfaces above — the shell owns the
242
+ * `spec` vocabulary. Mirrors the Rust-side `Contributes.live_activities`;
243
+ * without it the CLI's zod parse would strip every live activity an app
244
+ * declares here, so a packed bundle would ship a dock that silently stays
245
+ * empty. */
246
+ live_activities: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
247
+ /** Deletable data categories the app owns — one "Delete all X" row in Settings
248
+ * → Danger Zone. Mirrors the Rust-side `Contributes.data_categories`; without
249
+ * it the CLI's zod parse would strip the declaration before signing, and the
250
+ * app's danger-zone row would simply never appear on any node that installed
251
+ * the packed bundle. Loosely typed here for the same reason as the surfaces
252
+ * above — Core is the layer that types it, because Core is the layer that has
253
+ * to resolve the id to something that can actually delete the rows. */
254
+ data_categories: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([]),
255
+ /** Language servers the plugin declares, keyed by server name — the mirror of
256
+ * Claude Code's `.lsp.json` / `lspServers`, so a config written for either host
257
+ * loads in the other. Mirrors the Rust-side `Contributes.lsp_servers`; without
258
+ * it the CLI's zod parse would strip every language server a plugin declares,
259
+ * before the manifest is signed.
260
+ *
261
+ * The ENTRY is deliberately a loose record and not a 13-field `z.object()`
262
+ * mirroring `LspServerContribution`. Claude Code owns this field vocabulary,
263
+ * not Ryu: a typed object here would strip a field from a newer Claude release
264
+ * on its way through `ryu pack` — the same silent-deletion bug this field
265
+ * exists to fix, one level down. Core is the layer that types it, because Core
266
+ * is the layer that acts on it. */
267
+ lsp_servers: import_zod.z.record(import_zod.z.string(), import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default({}),
268
+ /** Pi extensions the plugin ships — TypeScript the managed `ryu` (Pi) agent
269
+ * loads at process start. Mirrors the Rust-side `Contributes.pi_extensions`;
270
+ * without it the CLI's zod parse would strip the declaration before signing,
271
+ * and the packed plugin would ship a `pi-extensions/` folder nothing loads.
272
+ *
273
+ * Typed (not a loose record) because Ryu owns this vocabulary — three fields,
274
+ * all of them Core-interpreted — unlike `lsp_servers`, whose entry shape is
275
+ * Claude Code's to extend. */
276
+ pi_extensions: import_zod.z.array(PiExtensionContributionSchema).default([]),
277
+ /** Output styles the plugin ships — Markdown files that rewrite the system
278
+ * prompt's voice. Mirrors the Rust-side `Contributes.output_styles`; without it
279
+ * the CLI's zod parse would strip the declaration, and `ryu pack` would sign a
280
+ * bundle whose styles simply do not exist. Worse than the usual case of that
281
+ * bug: the styles' `.md` files are not carried by the bundle either, so there
282
+ * would be no residue to notice — the plugin would install clean and contribute
283
+ * nothing. */
284
+ output_styles: import_zod.z.array(OutputStyleContributionSchema).default([]),
285
+ /** Per-message actions contributed by an enabled plugin. Kept as loose records
286
+ * so renderer-specific `kind`/`args` payloads survive `ryu pack` unchanged. */
287
+ message_actions: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).default([])
288
+ });
289
+ var SetupStepSchema = import_zod.z.object({
290
+ /** Card heading (e.g. the companion app name). */
291
+ title: import_zod.z.string().optional(),
292
+ /** Instruction body shown under the title. */
293
+ description: import_zod.z.string().optional(),
294
+ /** Label for the optional action button. */
295
+ actionLabel: import_zod.z.string().optional(),
296
+ /** URL the action button opens (validated server-side on publish). */
297
+ actionUrl: import_zod.z.string().optional()
298
+ });
299
+ var AppDependencySchema = import_zod.z.object({
300
+ /** The `id` of the plugin this one depends on. */
301
+ id: import_zod.z.string().min(1, "dependency id is required"),
302
+ /** Optional MINIMUM version the dependency must satisfy (`"1.2.0"` = `">=1.2.0"`). */
303
+ min_version: import_zod.z.string().min(1).optional()
304
+ });
305
+ var CapabilityReqSchema = import_zod.z.object({
306
+ /** Capability name (e.g. `"rag"`, `"memory"`, `"tts"`). Matched against a
307
+ * provider's `provides[].capability`. */
308
+ capability: import_zod.z.string().min(1, "capability name is required"),
309
+ /** Optional MINIMUM capability version the bound provider must satisfy
310
+ * (`"1.2.0"` = `">=1.2.0"`). Absent = any version. */
311
+ min_version: import_zod.z.string().min(1).optional()
312
+ });
313
+ var RequiresSchema = import_zod.z.object({
314
+ /** Other plugins that must be installed + enabled before this one enables. */
315
+ apps: import_zod.z.array(AppDependencySchema).default([]),
316
+ /**
317
+ * Abstract capability edges the broker resolves to a bound provider at
318
+ * enable time. Mirrors `Requires::capabilities` in
319
+ * `crates/ryu-kernel-contracts` — an `apps` edge names a specific plugin; a
320
+ * `capabilities` edge names a capability and lets the binding registry choose
321
+ * the provider. Each is lowered to an app-id graph edge once bound, so the
322
+ * enable/disable/cycle machinery is shared. Empty for the common case.
323
+ */
324
+ capabilities: import_zod.z.array(CapabilityReqSchema).default([]),
325
+ /**
326
+ * Permission grants implied by the dependencies. Declaration only — the
327
+ * Gateway remains the sole authority on what a grant *allows*, and Core's
328
+ * dependency graph resolves `apps` only.
329
+ */
330
+ grants: import_zod.z.array(import_zod.z.string()).default([])
331
+ });
332
+ var SurfaceSchema = import_zod.z.enum([
333
+ /** The Ryu Gateway. */
334
+ "gateway",
335
+ /** A headless Core node (no UI). */
336
+ "core",
337
+ /** The Tauri desktop app. */
338
+ "desktop",
339
+ /** The Electron dynamic-island companion. */
340
+ "island",
341
+ /** The Expo/React-Native mobile app. */
342
+ "mobile",
343
+ /** The browser extension. */
344
+ "extension",
345
+ /** The Next.js web app. */
346
+ "web",
347
+ /** The terminal client. */
348
+ "cli"
349
+ ]);
350
+ var EnginesReqSchema = import_zod.z.object({
351
+ /** Floor for the terminal (`cli`) surface. */
352
+ cli: import_zod.z.string().optional(),
353
+ /** Floor for the Tauri desktop app. */
354
+ desktop: import_zod.z.string().optional(),
355
+ /** Floor for the browser extension. */
356
+ extension: import_zod.z.string().optional(),
357
+ /** Floor for the Ryu Gateway. */
358
+ gateway: import_zod.z.string().optional(),
359
+ /** Floor for the dynamic-island companion. */
360
+ island: import_zod.z.string().optional(),
361
+ /** Floor for the mobile app. */
362
+ mobile: import_zod.z.string().optional(),
363
+ /** Floor for the running **Core** (e.g. `">=0.3.0"`). Required. */
364
+ ryu: import_zod.z.string().min(1, "engines.ryu is required when engines is present"),
365
+ /** Floor for the Next.js web app. */
366
+ web: import_zod.z.string().optional()
367
+ });
368
+ var McpServerAuthSchema = import_zod.z.object({
369
+ client_id: import_zod.z.string().min(1).optional(),
370
+ type: import_zod.z.literal("oauth")
371
+ }).strict();
372
+ var McpServerDeclSchema = import_zod.z.object({
373
+ args: import_zod.z.array(import_zod.z.string()).default([]),
374
+ auth: McpServerAuthSchema.optional(),
375
+ command: import_zod.z.string().optional(),
376
+ command_env: import_zod.z.string().optional(),
377
+ description: import_zod.z.string().optional(),
378
+ enabled: import_zod.z.boolean().default(true),
379
+ env: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({}),
380
+ headers: import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({}),
381
+ type: import_zod.z.enum(["stdio", "http", "streamable-http", "streamable_http", "sse"]).optional(),
382
+ url: import_zod.z.url().optional()
383
+ }).superRefine((server, context) => {
384
+ if (!(server.command || server.url)) {
385
+ context.addIssue({
386
+ code: "custom",
387
+ message: "an MCP server requires command or url"
388
+ });
389
+ }
390
+ if (!server.auth) {
391
+ return;
392
+ }
393
+ if (server.command || server.type === "stdio" || !server.url) {
394
+ context.addIssue({
395
+ code: "custom",
396
+ message: "OAuth is supported only for remote HTTP MCP servers"
397
+ });
398
+ return;
399
+ }
400
+ if (Object.keys(server.headers).some(
401
+ (name) => name.toLowerCase() === "authorization"
402
+ )) {
403
+ context.addIssue({
404
+ code: "custom",
405
+ message: "OAuth cannot be combined with a static Authorization header"
406
+ });
407
+ }
408
+ const url = new URL(server.url);
409
+ const loopback = url.hostname === "localhost" || url.hostname.startsWith("127.") || url.hostname === "[::1]" || url.hostname === "::1";
410
+ if (url.username || url.password || url.hash) {
411
+ context.addIssue({
412
+ code: "custom",
413
+ message: "OAuth MCP URLs cannot contain credentials or fragments"
414
+ });
415
+ }
416
+ if (url.protocol !== "https:" && !(url.protocol === "http:" && loopback)) {
417
+ context.addIssue({
418
+ code: "custom",
419
+ message: "OAuth MCP URLs must use HTTPS except on loopback"
420
+ });
421
+ }
422
+ });
423
+ var PluginManifestSchema = import_zod.z.object({
424
+ /** Reverse-domain unique identifier (e.g. `"com.example.my-plugin"`). */
425
+ id: import_zod.z.string().min(1, "id is required"),
426
+ /** Human-readable display name shown in the plugin store / launcher. */
427
+ name: import_zod.z.string().min(1, "name is required"),
428
+ /**
429
+ * Semver version string (e.g. `"1.0.0"`). Core's loader rejects any manifest
430
+ * whose version is not valid semver; the regex here enforces the same rule at
431
+ * SDK-build time.
432
+ */
433
+ version: import_zod.z.string().regex(
434
+ /^\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$/,
435
+ "version must be a valid semver string (e.g. 1.0.0)"
436
+ ),
437
+ /**
438
+ * Lower-case hex `sha256(utf8_bytes(ui_code))` binding the plugin's bundled
439
+ * sandboxed-UI code to this manifest. `ryu pack` / `ryu publish` compute it and
440
+ * write it here BEFORE the manifest is signed, so the hash rides INSIDE the
441
+ * Gateway-signed surface while the `ui_code` blob rides OUTSIDE it as payload;
442
+ * Core's install path recomputes the hash over the fetched code and rejects a
443
+ * mismatch fail-closed. Absent for a manifest-only plugin (no bundled UI).
444
+ * Mirrors Core's `PluginManifest.ui_code_sha256`.
445
+ */
446
+ ui_code_sha256: import_zod.z.string().nullish(),
447
+ /** The Runnables this plugin bundles. */
448
+ runnables: import_zod.z.array(RunnableMetaSchema).default([]),
449
+ /**
450
+ * Permission grants this plugin declares it needs (e.g. `"mcp:web_search"`).
451
+ * Declarations only — grant enforcement is the Gateway's responsibility.
452
+ */
453
+ permission_grants: import_zod.z.array(import_zod.z.string()).default([]),
454
+ /** Remote or stdio MCP servers registered by this plugin. */
455
+ mcp_servers: import_zod.z.record(import_zod.z.string(), McpServerDeclSchema).optional(),
456
+ /**
457
+ * Optional Companion surface (an in-desktop overlay or sidebar panel).
458
+ * Absent when the plugin has no Companion surface.
459
+ */
460
+ companion: CompanionSurfaceSchema.optional(),
461
+ /**
462
+ * VS-Code-style activation events (`"*"`, `"onStartup"`, `"onChat"`,
463
+ * `"onCommand:<id>"`). Empty = eager. Turn-hook plugins are driven by their
464
+ * enabled flag, so `["*"]` is the usual value.
465
+ */
466
+ activation_events: import_zod.z.array(import_zod.z.string()).default([]),
467
+ /**
468
+ * Contribution points: server-side turn hooks + declarative UI widgets.
469
+ * Absent for a plugin that contributes nothing here.
470
+ */
471
+ contributes: ContributesSchema.optional(),
472
+ /**
473
+ * **Plugin-to-plugin dependencies** — the other plugins this one needs. Core
474
+ * resolves them into a topological enable order (dependencies enable first;
475
+ * disabling one is refused while an enabled dependent needs it).
476
+ *
477
+ * Absent = **no dependencies**, the backward-compatible default. Kept
478
+ * `.optional()` (never defaulted) so a manifest that declares none serialises
479
+ * with no `requires` key at all, exactly like Core's
480
+ * `#[serde(skip_serializing_if = "Option::is_none")]`.
481
+ */
482
+ requires: RequiresSchema.optional(),
483
+ /**
484
+ * Host surfaces this plugin runs on. **Empty or absent = runs on EVERY
485
+ * surface** — the backward-compatible default, which must never be read as
486
+ * "runs nowhere". Core filters only when the list is explicitly non-empty, and
487
+ * only at the read boundary (`GET /api/plugins`, keyed on `x-ryu-surface`), so
488
+ * an unsupported-target plugin stays installable and inspectable.
489
+ */
490
+ targets: import_zod.z.array(SurfaceSchema).default([]),
491
+ /**
492
+ * Host version floors — the semver requirement each surface must satisfy for
493
+ * this plugin to install. Mirrors Core's `EnginesReq`
494
+ * (`crates/core/kernel-contracts/src/manifest.rs`).
495
+ *
496
+ * `ryu` is the **Core** floor and the only required key (it is the legacy
497
+ * spelling; every manifest in the wild carries just that one). The rest are
498
+ * optional per-surface floors.
499
+ *
500
+ * REGRESSION THIS FIXES: `engines` was absent from this schema entirely, and
501
+ * zod strips unlisted keys — so `ryu pack` silently dropped the whole block
502
+ * from every bundle it produced. A plugin could declare a Core floor, publish,
503
+ * and ship a bundle that declared none. Any new host floor MUST be added here
504
+ * as well as in the Rust contract, or it does not survive packing.
505
+ */
506
+ engines: EnginesReqSchema.optional(),
507
+ /**
508
+ * Optional per-item AFFILIATE terms: the commission paid to a referrer when a
509
+ * referred user buys this (paid) item. `value` is basis points for `percent`
510
+ * (2000 = 20%) or minor units (cents) for `flat`. Absent (or `enabled:false`)
511
+ * falls back to the seller org owner's default affiliate terms. This is the
512
+ * authoring surface for the marketplace publish body's `affiliate` field (the
513
+ * server re-validates it); it only takes effect on a paid item.
514
+ */
515
+ affiliate: import_zod.z.object({
516
+ enabled: import_zod.z.boolean().default(false),
517
+ rule: import_zod.z.object({
518
+ type: import_zod.z.enum(["percent", "flat"]),
519
+ value: import_zod.z.number().nonnegative(),
520
+ recurring: import_zod.z.boolean().default(false),
521
+ durationMonths: import_zod.z.number().int().positive().nullish(),
522
+ fundedBy: import_zod.z.enum(["platform", "seller"]).default("platform")
523
+ }).optional()
524
+ }).optional(),
525
+ // ── Rich listing metadata (Phase 1.5) ──────────────────────────────────────
526
+ // Optional store-listing fields a plugin author declares so the marketplace
527
+ // detail dialog renders a richer App-Store-style preview. Field names align
528
+ // with the Claude `.claude-plugin/marketplace.json` plugin-entry standard where
529
+ // one exists (`author`, `homepage`, `keywords`, `category`, `license`); the
530
+ // rest are Ryu extensions. `ryu publish` forwards these FLAT into the publish
531
+ // body (not inside the signed manifest blob) so the control plane stores them.
532
+ // All optional + additive: a manifest omitting them still validates.
533
+ /** Longer plain/markdown description shown in the detail dialog. */
534
+ description: import_zod.z.string().optional(),
535
+ /** Short one-line pitch shown under the name (Ryu extension). */
536
+ tagline: import_zod.z.string().optional(),
537
+ /**
538
+ * Publisher identity. A bare string OR a Claude-style object; `ryu publish`
539
+ * resolves it to the display `developer` (`author.name` when an object).
540
+ */
541
+ author: import_zod.z.union([
542
+ import_zod.z.string(),
543
+ import_zod.z.object({
544
+ name: import_zod.z.string(),
545
+ email: import_zod.z.string().optional(),
546
+ url: import_zod.z.string().optional()
547
+ })
548
+ ]).optional(),
549
+ /** Public source repository URL (Claude/Codex `repository`). */
550
+ repository: import_zod.z.string().url().optional(),
551
+ /** True when the provider operates outside the local Ryu runtime. */
552
+ external: import_zod.z.boolean().optional(),
553
+ /** Project/marketing homepage — maps to the listing `website` (Claude field). */
554
+ homepage: import_zod.z.string().optional(),
555
+ /** Free-text search keywords (Claude field). */
556
+ keywords: import_zod.z.array(import_zod.z.string()).optional(),
557
+ /** Stable Marketplace filter labels (Ryu extension). */
558
+ tags: import_zod.z.array(import_zod.z.string()).optional(),
559
+ /** Taxonomy category beyond the runnable kinds (Claude field). */
560
+ category: import_zod.z.string().optional(),
561
+ /** SPDX-ish license identifier (Claude field). */
562
+ license: import_zod.z.string().optional(),
563
+ /** Square logo/icon URL for the listing card + detail header. */
564
+ iconUrl: import_zod.z.string().optional(),
565
+ /**
566
+ * Icon-primitive id for the listing card (Ryu extension): an Iconify/icons0
567
+ * `prefix:name`, a bare Hugeicons name, or a URL, resolved by the shared `Icon`
568
+ * primitive. A monochrome GLYPH masked with the current text colour — distinct
569
+ * from `iconUrl` (a raster logo). Falls back to `iconUrl` when omitted.
570
+ */
571
+ icon: import_zod.z.string().optional(),
572
+ /** Optional detail-page hero banner metadata forwarded to the marketplace. */
573
+ banner: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional(),
574
+ /**
575
+ * Dithered-gradient background for the card's icon square (Ryu extension),
576
+ * mirroring dither-kit's `DitherGradient` props. `from`/`to` are a palette-colour
577
+ * name (`green`, `blue`, `purple`, `pink`, `orange`, `red`, `grey`) or a hue
578
+ * number (0–360); `direction` is where `to` ends up. Renders behind the glyph in
579
+ * place of a flat `iconBackground`; the render layer validates + falls back.
580
+ */
581
+ iconDither: import_zod.z.object({
582
+ from: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]),
583
+ to: import_zod.z.union([import_zod.z.string(), import_zod.z.number()]).optional(),
584
+ direction: import_zod.z.enum(["up", "down", "left", "right"]).optional()
585
+ }).optional(),
586
+ /** Ordered App-Store-style screenshot gallery URLs (Ryu extension). */
587
+ screenshots: import_zod.z.array(import_zod.z.string()).optional(),
588
+ /** Privacy policy URL surfaced on detail (Ryu extension). */
589
+ privacyPolicyUrl: import_zod.z.string().optional(),
590
+ /** Terms-of-service URL surfaced on detail (Ryu extension). */
591
+ termsOfServiceUrl: import_zod.z.string().optional(),
592
+ /**
593
+ * Human-readable capability strings (Ryu extension). When omitted the control
594
+ * plane derives a default from `permission_grants`, so declaring this is only
595
+ * needed to override the derived labels.
596
+ */
597
+ capabilities: import_zod.z.array(import_zod.z.string()).optional(),
598
+ /** Example prompt chips shown on detail (Ryu extension). */
599
+ examplePrompts: import_zod.z.array(import_zod.z.string()).optional(),
600
+ /**
601
+ * Optional companion/config card (Ryu extension): a single setup step or an
602
+ * array of steps guiding the user through post-install configuration.
603
+ */
604
+ setup: import_zod.z.union([SetupStepSchema, import_zod.z.array(SetupStepSchema)]).optional()
605
+ }).superRefine((manifest, context) => {
606
+ const hasOAuthServer = Object.values(manifest.mcp_servers ?? {}).some(
607
+ (server) => server.auth?.type === "oauth"
608
+ );
609
+ if (!hasOAuthServer) {
610
+ return;
611
+ }
612
+ for (const grant of ["mcp:server", "identity.read"]) {
613
+ if (!manifest.permission_grants.includes(grant)) {
614
+ context.addIssue({
615
+ code: "custom",
616
+ message: `OAuth MCP servers require the ${grant} permission grant`,
617
+ path: ["permission_grants"]
618
+ });
619
+ }
620
+ }
621
+ });
622
+
623
+ // src/runnable/app.ts
624
+ var DEFAULT_APP_WIDGET_MIME = "text/html+skybridge";
625
+ var DEFAULT_APP_DISPLAY_MODE = "inline";
626
+ var WIDGET_RENDER_GRANT = "widget:render";
627
+ function withWidgetRenderGrant(grants, widgets) {
628
+ const out = [...grants];
629
+ if (widgets.length > 0 && !out.includes(WIDGET_RENDER_GRANT)) {
630
+ out.push(WIDGET_RENDER_GRANT);
631
+ }
632
+ return out;
633
+ }
634
+ function appToolId(server, name) {
635
+ return `${server}.${name}`;
636
+ }
637
+ function defineApp(options) {
638
+ const server = options.server ?? options.slug;
639
+ const uri = `ui://widget/${options.slug}.html`;
640
+ const mime = options.mime ?? DEFAULT_APP_WIDGET_MIME;
641
+ const displayMode = options.displayMode ?? DEFAULT_APP_DISPLAY_MODE;
642
+ const hasCompanions = options.tools.some((t) => t.accessible === true);
643
+ const runnables = [];
644
+ const widgets = [];
645
+ for (const spec of options.tools) {
646
+ const isRender = spec.accessible !== true;
647
+ const id = appToolId(server, spec.name);
648
+ const config = {
649
+ slug: id,
650
+ description: spec.description,
651
+ widget: isRender,
652
+ widget_accessible: isRender ? hasCompanions : true,
653
+ ...spec.inputSchema ? { input_schema: spec.inputSchema } : {},
654
+ ...spec.invoking ? { invoking: spec.invoking } : {},
655
+ ...spec.invoked ? { invoked: spec.invoked } : {}
656
+ };
657
+ runnables.push({
658
+ id,
659
+ name: spec.name,
660
+ kind: "tool",
661
+ config
662
+ });
663
+ if (isRender) {
664
+ widgets.push({
665
+ tool_id: id,
666
+ uri,
667
+ ui_entry: options.uiEntry,
668
+ mime,
669
+ default_display_mode: displayMode
670
+ });
671
+ }
672
+ }
673
+ const contributes = {
674
+ turn_hooks: [],
675
+ chat_features: [],
676
+ // This builder synthesises an app from its runnables; an app that emits
677
+ // events declares them in a hand-authored `manifest.json`, same as
678
+ // `lsp_servers` below.
679
+ hook_events: [],
680
+ composer_controls: [],
681
+ settings_tabs: [],
682
+ slash_commands: [],
683
+ sidebar_sections: [],
684
+ sidebar_buttons: [],
685
+ dock_panels: [],
686
+ live_activities: [],
687
+ // Empty for the same reason as every sibling family above: this builder
688
+ // synthesises `widgets` from the app's own runnables and nothing else, and
689
+ // takes no `contributes` passthrough. An app that wants to declare language
690
+ // servers writes them in a hand-authored `manifest.json`.
691
+ lsp_servers: {},
692
+ // Same reason again: a danger-zone category, a Pi extension and an output
693
+ // style are all hand-authored declarations, not something derivable from
694
+ // runnables. An output style in particular points at a Markdown file next
695
+ // to the manifest, which this builder never writes.
696
+ data_categories: [],
697
+ pi_extensions: [],
698
+ output_styles: [],
699
+ message_actions: [],
700
+ widgets
701
+ };
702
+ const raw = {
703
+ id: options.id,
704
+ name: options.title,
705
+ version: options.version,
706
+ runnables,
707
+ // An app that synthesises widgets MUST hold `widget:render`, so this
708
+ // builder declares it rather than leaving the author to discover it.
709
+ //
710
+ // Core gates widget promotion on declared-AND-enabled-AND-granted, and a
711
+ // missing grant fails as `DeniedNoGrant` — which is an `info!` log and
712
+ // nothing else. The widget silently renders as plain text, with no error
713
+ // in the UI and nothing pointing at the manifest. Every app scaffolded
714
+ // through `defineApp` hit that, because the only fix was a grant string
715
+ // the templates never mention and the builder never added; the one
716
+ // working example on disk hand-writes it.
717
+ //
718
+ // Added only when there is a widget to render, and unioned rather than
719
+ // overwritten so an author's own `grants` list survives and re-declaring
720
+ // it is not an error.
721
+ permission_grants: withWidgetRenderGrant(options.grants ?? [], widgets),
722
+ activation_events: options.activationEvents ?? ["*"],
723
+ contributes,
724
+ // `targets: []` means EVERY surface, so an app that declares none is
725
+ // unrestricted — the backward-compatible default.
726
+ targets: options.targets ?? [],
727
+ // `requires` stays ABSENT (not `{apps:[],grants:[]}`) when undeclared, so the
728
+ // emitted manifest carries no key at all — matching Core's
729
+ // `Option<Requires>` + `skip_serializing_if = "Option::is_none"`.
730
+ ...options.requires ? {
731
+ requires: {
732
+ apps: options.requires.apps ?? [],
733
+ capabilities: options.requires.capabilities ?? [],
734
+ grants: options.requires.grants ?? []
735
+ }
736
+ } : {}
737
+ };
738
+ const result = PluginManifestSchema.safeParse(raw);
739
+ if (!result.success) {
740
+ const first = result.error.issues[0];
741
+ const field = first?.path.join(".") ?? "unknown";
742
+ const message = first?.message ?? "validation failed";
743
+ throw new Error(
744
+ `manifest.json validation failed at '${field}': ${message}`
745
+ );
746
+ }
747
+ return result.data;
748
+ }
749
+
750
+ // src/builder.ts
751
+ var RunnableBuilder = class {
752
+ _id = "";
753
+ _name = "";
754
+ id(value) {
755
+ this._id = value;
756
+ return this;
757
+ }
758
+ name(value) {
759
+ this._name = value;
760
+ return this;
761
+ }
762
+ };
763
+ var AgentBuilder = class extends RunnableBuilder {
764
+ build() {
765
+ const result = RunnableMetaSchema.safeParse({
766
+ id: this._id,
767
+ name: this._name,
768
+ kind: "agent"
769
+ });
770
+ if (!result.success) {
771
+ throw new Error(
772
+ `Invalid agent runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
773
+ );
774
+ }
775
+ return result.data;
776
+ }
777
+ };
778
+ var WorkflowBuilder = class extends RunnableBuilder {
779
+ build() {
780
+ const result = RunnableMetaSchema.safeParse({
781
+ id: this._id,
782
+ name: this._name,
783
+ kind: "workflow"
784
+ });
785
+ if (!result.success) {
786
+ throw new Error(
787
+ `Invalid workflow runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
788
+ );
789
+ }
790
+ return result.data;
791
+ }
792
+ };
793
+ var ToolBuilder = class extends RunnableBuilder {
794
+ build() {
795
+ const result = RunnableMetaSchema.safeParse({
796
+ id: this._id,
797
+ name: this._name,
798
+ kind: "tool"
799
+ });
800
+ if (!result.success) {
801
+ throw new Error(
802
+ `Invalid tool runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
803
+ );
804
+ }
805
+ return result.data;
806
+ }
807
+ };
808
+ var SkillBuilder = class extends RunnableBuilder {
809
+ build() {
810
+ const result = RunnableMetaSchema.safeParse({
811
+ id: this._id,
812
+ name: this._name,
813
+ kind: "skill"
814
+ });
815
+ if (!result.success) {
816
+ throw new Error(
817
+ `Invalid skill runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
818
+ );
819
+ }
820
+ return result.data;
821
+ }
822
+ };
823
+ var agent = () => new AgentBuilder();
824
+ var workflow = () => new WorkflowBuilder();
825
+ var tool = () => new ToolBuilder();
826
+ var skill = () => new SkillBuilder();
827
+ var PluginBuilder = class {
828
+ _id = "";
829
+ _name = "";
830
+ _version = "";
831
+ _runnables = [];
832
+ _grants = [];
833
+ _companion = void 0;
834
+ _dependencies = [];
835
+ _requiredCapabilities = [];
836
+ _requiredGrants = [];
837
+ _targets = [];
838
+ /** Set the reverse-domain app id (e.g. `"com.example.my-app"`). */
839
+ id(value) {
840
+ this._id = value;
841
+ return this;
842
+ }
843
+ /** Set the human-readable display name. */
844
+ name(value) {
845
+ this._name = value;
846
+ return this;
847
+ }
848
+ /** Set the semver version string (e.g. `"1.0.0"`). */
849
+ version(value) {
850
+ this._version = value;
851
+ return this;
852
+ }
853
+ /** Append a pre-built `RunnableMeta` (from any per-kind builder). */
854
+ runnable(meta) {
855
+ this._runnables.push(meta);
856
+ return this;
857
+ }
858
+ /** Declare a permission grant (e.g. `"mcp:web_search"`). */
859
+ grant(permission) {
860
+ this._grants.push(permission);
861
+ return this;
862
+ }
863
+ /** Set an optional Companion surface descriptor. */
864
+ companion(surface) {
865
+ this._companion = surface;
866
+ return this;
867
+ }
868
+ /**
869
+ * Declare a **plugin-to-plugin dependency**: `id` must be installed and is
870
+ * auto-enabled (in dependency order) before this plugin enables.
871
+ *
872
+ * `minVersion` is a MINIMUM — a bare `"1.2.0"` means `">=1.2.0"`, so an
873
+ * installed `2.0.0` satisfies it (comparator syntax like `">=1.2, <2"` is
874
+ * honoured verbatim).
875
+ */
876
+ dependsOn(id, minVersion) {
877
+ this._dependencies.push(
878
+ minVersion ? { id, min_version: minVersion } : { id }
879
+ );
880
+ return this;
881
+ }
882
+ /**
883
+ * Declare a permission grant implied by this plugin's dependencies
884
+ * (`requires.grants`). Declaration only — the Gateway remains the sole
885
+ * authority on what a grant allows. Use {@link PluginBuilder.grant} for the
886
+ * grants this plugin needs in its own right.
887
+ */
888
+ requiredGrant(permission) {
889
+ this._requiredGrants.push(permission);
890
+ return this;
891
+ }
892
+ /**
893
+ * Declare an abstract **capability** edge (`requires.capabilities`) the broker
894
+ * resolves to a bound provider at enable time — e.g. `requiresCapability("rag")`.
895
+ * Distinct from a specific-plugin dependency: a capability edge lets the
896
+ * binding registry choose the provider. `minVersion` is a MINIMUM (`"1.2.0"`
897
+ * = `">=1.2.0"`).
898
+ */
899
+ requiresCapability(capability, minVersion) {
900
+ this._requiredCapabilities.push(
901
+ minVersion ? { capability, min_version: minVersion } : { capability }
902
+ );
903
+ return this;
904
+ }
905
+ /**
906
+ * Restrict this plugin to a host surface (`"desktop"`, `"island"`, …).
907
+ * Declaring NO target is the default and means **every** surface.
908
+ */
909
+ target(surface) {
910
+ this._targets.push(surface);
911
+ return this;
912
+ }
913
+ /**
914
+ * Validate and return the assembled `PluginManifest`. Throws an `Error` with
915
+ * the failing field name and message when validation fails.
916
+ */
917
+ build() {
918
+ const hasRequires = this._dependencies.length > 0 || this._requiredCapabilities.length > 0 || this._requiredGrants.length > 0;
919
+ const raw = {
920
+ id: this._id,
921
+ name: this._name,
922
+ version: this._version,
923
+ runnables: this._runnables,
924
+ permission_grants: this._grants,
925
+ companion: this._companion,
926
+ targets: this._targets,
927
+ ...hasRequires ? {
928
+ requires: {
929
+ apps: this._dependencies,
930
+ capabilities: this._requiredCapabilities,
931
+ grants: this._requiredGrants
932
+ }
933
+ } : {}
934
+ };
935
+ const result = PluginManifestSchema.safeParse(raw);
936
+ if (!result.success) {
937
+ const first = result.error.issues[0];
938
+ const field = first?.path.join(".") ?? "unknown";
939
+ const message = first?.message ?? "validation failed";
940
+ throw new Error(
941
+ `manifest.json validation failed at '${field}': ${message}`
942
+ );
943
+ }
944
+ return result.data;
945
+ }
946
+ };
947
+ var AppBuilder = class {
948
+ _id = "";
949
+ _title = "";
950
+ _version = "";
951
+ _slug = "";
952
+ _server = void 0;
953
+ _displayMode = void 0;
954
+ _mime = void 0;
955
+ _uiEntry = "";
956
+ _grants = [];
957
+ _activationEvents = [];
958
+ _tools = [];
959
+ _dependencies = [];
960
+ _requiredCapabilities = [];
961
+ _requiredGrants = [];
962
+ _targets = [];
963
+ /** Set the reverse-domain app id (e.g. `"com.example.checklist"`). */
964
+ id(value) {
965
+ this._id = value;
966
+ return this;
967
+ }
968
+ /** Set the human-readable display name. */
969
+ title(value) {
970
+ this._title = value;
971
+ return this;
972
+ }
973
+ /** Set the semver version string (e.g. `"1.0.0"`). */
974
+ version(value) {
975
+ this._version = value;
976
+ return this;
977
+ }
978
+ /** Set the app slug (drives `ui://widget/<slug>.html` and the server default). */
979
+ slug(value) {
980
+ this._slug = value;
981
+ return this;
982
+ }
983
+ /** Override the MCP server namespace for tool ids (defaults to the slug). */
984
+ server(value) {
985
+ this._server = value;
986
+ return this;
987
+ }
988
+ /** Set the default widget display mode (`inline` | `fullscreen` | `pip`). */
989
+ displayMode(value) {
990
+ this._displayMode = value;
991
+ return this;
992
+ }
993
+ /** Override the widget MIME dialect (defaults to `text/html+skybridge`). */
994
+ mime(value) {
995
+ this._mime = value;
996
+ return this;
997
+ }
998
+ /** Set the widget UI source entry `ryu pack` bundles into `ui_code`. */
999
+ uiEntry(value) {
1000
+ this._uiEntry = value;
1001
+ return this;
1002
+ }
1003
+ /** Declare a permission grant (e.g. `"mcp:web_search"`). */
1004
+ grant(permission) {
1005
+ this._grants.push(permission);
1006
+ return this;
1007
+ }
1008
+ /** Add a VS-Code-style activation event (empty = eager `["*"]`). */
1009
+ activationEvent(event) {
1010
+ this._activationEvents.push(event);
1011
+ return this;
1012
+ }
1013
+ /** Append a tool spec (render tool unless `accessible:true`). */
1014
+ tool(spec) {
1015
+ this._tools.push(spec);
1016
+ return this;
1017
+ }
1018
+ /**
1019
+ * Declare a **plugin-to-plugin dependency** (auto-enabled, in dependency order,
1020
+ * before this app). `minVersion` is a MINIMUM (`"1.2.0"` = `">=1.2.0"`).
1021
+ */
1022
+ dependsOn(id, minVersion) {
1023
+ this._dependencies.push(
1024
+ minVersion ? { id, min_version: minVersion } : { id }
1025
+ );
1026
+ return this;
1027
+ }
1028
+ /** Declare a grant implied by this app's dependencies (`requires.grants`). */
1029
+ requiredGrant(permission) {
1030
+ this._requiredGrants.push(permission);
1031
+ return this;
1032
+ }
1033
+ /**
1034
+ * Declare an abstract **capability** edge (`requires.capabilities`) the broker
1035
+ * resolves to a bound provider at enable time — e.g. `requiresCapability("rag")`.
1036
+ * Distinct from a specific-plugin dependency: a capability edge lets the
1037
+ * binding registry choose the provider. `minVersion` is a MINIMUM (`"1.2.0"`
1038
+ * = `">=1.2.0"`).
1039
+ */
1040
+ requiresCapability(capability, minVersion) {
1041
+ this._requiredCapabilities.push(
1042
+ minVersion ? { capability, min_version: minVersion } : { capability }
1043
+ );
1044
+ return this;
1045
+ }
1046
+ /** Restrict this app to a host surface. No target = every surface. */
1047
+ target(surface) {
1048
+ this._targets.push(surface);
1049
+ return this;
1050
+ }
1051
+ /**
1052
+ * Validate and return the assembled `PluginManifest`. Throws an `Error` naming
1053
+ * the failing field when validation fails.
1054
+ */
1055
+ build() {
1056
+ const hasRequires = this._dependencies.length > 0 || this._requiredCapabilities.length > 0 || this._requiredGrants.length > 0;
1057
+ const options = {
1058
+ id: this._id,
1059
+ title: this._title,
1060
+ version: this._version,
1061
+ slug: this._slug,
1062
+ uiEntry: this._uiEntry,
1063
+ tools: this._tools,
1064
+ grants: this._grants,
1065
+ ...this._server ? { server: this._server } : {},
1066
+ ...this._displayMode ? { displayMode: this._displayMode } : {},
1067
+ ...this._mime ? { mime: this._mime } : {},
1068
+ ...this._activationEvents.length > 0 ? { activationEvents: this._activationEvents } : {},
1069
+ ...hasRequires ? {
1070
+ requires: {
1071
+ apps: this._dependencies,
1072
+ capabilities: this._requiredCapabilities,
1073
+ grants: this._requiredGrants
1074
+ }
1075
+ } : {},
1076
+ ...this._targets.length > 0 ? { targets: this._targets } : {}
1077
+ };
1078
+ return defineApp(options);
1079
+ }
1080
+ };
1081
+ var app = () => new AppBuilder();
1082
+ // Annotate the CommonJS export names for ESM import in node:
1083
+ 0 && (module.exports = {
1084
+ AgentBuilder,
1085
+ AppBuilder,
1086
+ PluginBuilder,
1087
+ SkillBuilder,
1088
+ ToolBuilder,
1089
+ WorkflowBuilder,
1090
+ agent,
1091
+ app,
1092
+ skill,
1093
+ tool,
1094
+ workflow
1095
+ });