@ryuhq/sdk 0.0.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.
Files changed (61) hide show
  1. package/LICENSE +179 -0
  2. package/README.md +31 -0
  3. package/dist/agent.cjs +761 -0
  4. package/dist/agent.d.cts +3 -0
  5. package/dist/agent.d.ts +3 -0
  6. package/dist/agent.js +23 -0
  7. package/dist/chunk-GXHL5CO7.js +353 -0
  8. package/dist/chunk-KPKMMGVC.js +671 -0
  9. package/dist/chunk-ODFEUVPW.js +100 -0
  10. package/dist/cli.cjs +858 -0
  11. package/dist/cli.d.cts +1 -0
  12. package/dist/cli.d.ts +1 -0
  13. package/dist/cli.js +454 -0
  14. package/dist/index-CEbS1SlS.d.cts +988 -0
  15. package/dist/index-DAxq7Y0R.d.ts +988 -0
  16. package/dist/index.cjs +1900 -0
  17. package/dist/index.d.cts +759 -0
  18. package/dist/index.d.ts +759 -0
  19. package/dist/index.js +771 -0
  20. package/dist/manifest.cjs +399 -0
  21. package/dist/manifest.d.cts +355 -0
  22. package/dist/manifest.d.ts +355 -0
  23. package/dist/manifest.js +38 -0
  24. package/package.json +56 -0
  25. package/src/agent/agent.ts +208 -0
  26. package/src/agent/index.ts +51 -0
  27. package/src/agent/loop.test.ts +261 -0
  28. package/src/agent/loop.ts +259 -0
  29. package/src/agent/model-call.ts +190 -0
  30. package/src/agent/query.ts +40 -0
  31. package/src/agent/tools.ts +295 -0
  32. package/src/builder.ts +473 -0
  33. package/src/cli/dev.test.ts +178 -0
  34. package/src/cli/dev.ts +425 -0
  35. package/src/cli.ts +390 -0
  36. package/src/contracts-lockstep.test.ts +77 -0
  37. package/src/generated/plugin-manifest.ts +1121 -0
  38. package/src/index.ts +141 -0
  39. package/src/manifest.test.ts +610 -0
  40. package/src/manifest.ts +589 -0
  41. package/src/mcp/bridge.test.ts +196 -0
  42. package/src/mcp/client.ts +253 -0
  43. package/src/mcp/fixture-server.ts +23 -0
  44. package/src/mcp/server.ts +351 -0
  45. package/src/model/client.test.ts +107 -0
  46. package/src/model/client.ts +179 -0
  47. package/src/model/gateway.ts +41 -0
  48. package/src/plugin/ryu-plugin.ts +191 -0
  49. package/src/runnable/agent.ts +338 -0
  50. package/src/runnable/app.ts +233 -0
  51. package/src/runnable/index.ts +61 -0
  52. package/src/runnable/primitives-hostapi.test.ts +73 -0
  53. package/src/runnable/primitives.test.ts +286 -0
  54. package/src/runnable/primitives.ts +610 -0
  55. package/src/runnable/runnable-types.ts +113 -0
  56. package/src/runnable/runnable.test.ts +397 -0
  57. package/src/runnable/skill.ts +60 -0
  58. package/src/runnable/tool.ts +260 -0
  59. package/src/runnable/turn-hook.test.ts +81 -0
  60. package/src/runnable/turn-hook.ts +191 -0
  61. package/src/runnable/workflow.ts +76 -0
@@ -0,0 +1,3 @@
1
+ export { A as Agent, b as AgentConfig, c as AgentEvent, U as AgentEventAuthRequired, V as AgentEventError, W as AgentEventResult, X as AgentEventText, Y as AgentEventToolCall, Z as AgentEventToolResult, d as AgentTool, _ as AssistantMessage, $ as Elicitation, E as Endpoint, h as GenerateResult, a0 as LoopConfig, a1 as LoopMessage, a2 as ModelCallOptions, a3 as ModelCallResult, a4 as ModelUsage, Q as QueryInput, n as QueryOptions, t as RemoteToolRef, a5 as RyuToolOptions, a6 as ToolCall, a7 as ToolExecContext, a8 as ToolExecResult, a9 as ToolFunctionDef, aa as callModelWithTools, y as createAgent, ab as detectElicitation, ac as executeTool, N as query, ad as resolveToolDefs, ae as runAgentLoop, O as ryuTool } from './index-CEbS1SlS.cjs';
2
+ import './manifest.cjs';
3
+ import 'zod';
@@ -0,0 +1,3 @@
1
+ export { A as Agent, b as AgentConfig, c as AgentEvent, U as AgentEventAuthRequired, V as AgentEventError, W as AgentEventResult, X as AgentEventText, Y as AgentEventToolCall, Z as AgentEventToolResult, d as AgentTool, _ as AssistantMessage, $ as Elicitation, E as Endpoint, h as GenerateResult, a0 as LoopConfig, a1 as LoopMessage, a2 as ModelCallOptions, a3 as ModelCallResult, a4 as ModelUsage, Q as QueryInput, n as QueryOptions, t as RemoteToolRef, a5 as RyuToolOptions, a6 as ToolCall, a7 as ToolExecContext, a8 as ToolExecResult, a9 as ToolFunctionDef, aa as callModelWithTools, y as createAgent, ab as detectElicitation, ac as executeTool, N as query, ad as resolveToolDefs, ae as runAgentLoop, O as ryuTool } from './index-DAxq7Y0R.js';
2
+ import './manifest.js';
3
+ import 'zod';
package/dist/agent.js ADDED
@@ -0,0 +1,23 @@
1
+ import {
2
+ Agent,
3
+ callModelWithTools,
4
+ createAgent,
5
+ detectElicitation,
6
+ executeTool,
7
+ query,
8
+ resolveToolDefs,
9
+ runAgentLoop,
10
+ ryuTool
11
+ } from "./chunk-KPKMMGVC.js";
12
+ import "./chunk-ODFEUVPW.js";
13
+ export {
14
+ Agent,
15
+ callModelWithTools,
16
+ createAgent,
17
+ detectElicitation,
18
+ executeTool,
19
+ query,
20
+ resolveToolDefs,
21
+ runAgentLoop,
22
+ ryuTool
23
+ };
@@ -0,0 +1,353 @@
1
+ // src/manifest.ts
2
+ import { createRequire } from "module";
3
+ import { z } from "zod";
4
+ var cachedNative = null;
5
+ var nativeLoadError = null;
6
+ function loadNative() {
7
+ if (cachedNative) {
8
+ return cachedNative;
9
+ }
10
+ if (nativeLoadError) {
11
+ throw nativeLoadError;
12
+ }
13
+ try {
14
+ const req = createRequire(import.meta.url);
15
+ cachedNative = req("@ryuhq/sdk-native");
16
+ return cachedNative;
17
+ } catch (cause) {
18
+ nativeLoadError = new Error(
19
+ "@ryuhq/sdk-native (the Rust-cored napi addon) is not available; Core-strict manifest validation requires it. Build/install the addon, or use PluginManifestSchema (pure-JS zod) for authoring-time validation.",
20
+ { cause }
21
+ );
22
+ throw nativeLoadError;
23
+ }
24
+ }
25
+ var RunnableKindSchema = z.enum([
26
+ "agent",
27
+ "workflow",
28
+ "tool",
29
+ "skill",
30
+ // A companion surface (in-desktop panel). Added so a packable plugin can
31
+ // declare a companion runnable that flows through Core's existing Companion
32
+ // handler → app_contrib → `GET /api/plugins/contributions` → the desktop
33
+ // `/plugin/<id>` route. Its `config.ui_entry` (see `CompanionRunnableConfigSchema`)
34
+ // is what `ryu pack` bundles into `ui_code`.
35
+ "companion"
36
+ ]);
37
+ var RunnableMetaSchema = z.object({
38
+ /** Stable unique identifier (e.g. `"agent-researcher"`). */
39
+ id: z.string().min(1),
40
+ /** Human-readable display name. */
41
+ name: z.string().min(1),
42
+ /** Which kind of runnable this entry describes. */
43
+ kind: RunnableKindSchema,
44
+ /**
45
+ * Optional per-kind config blob. Mirrors Core's `RunnableEntry.config`
46
+ * (`Option<serde_json::Value>`) so a manifest authored here round-trips
47
+ * through Core-strict validation. Left opaque (a record) at this authoring
48
+ * layer; the per-kind shape is enforced by Core's `validate_runnable`.
49
+ *
50
+ * For a `companion` runnable, `config.ui_entry` names the plugin's UI entry
51
+ * module (relative to the manifest dir). `ryu pack` bundles that entry into
52
+ * the emitted `ui_code`; Core's `CompanionConfig.ui_entry` is the lockstep
53
+ * field so a packed companion validates.
54
+ */
55
+ config: z.record(z.string(), z.unknown()).optional()
56
+ });
57
+ function labelImpersonatesSystemChrome(label) {
58
+ const lower = label.toLowerCase();
59
+ return lower.includes("ryu") || lower.includes("system");
60
+ }
61
+ var CompanionSurfaceSchema = z.object({
62
+ /** Display label for the companion panel tab or tooltip. Anti-impersonation:
63
+ * may not pose as first-party Ryu/system chrome (see
64
+ * {@link labelImpersonatesSystemChrome}). */
65
+ label: z.string().min(1).refine((value) => !labelImpersonatesSystemChrome(value), {
66
+ message: "companion label must not impersonate system chrome (must not contain 'ryu' or 'system')"
67
+ }),
68
+ /** Icon identifier resolved by the desktop shell. */
69
+ icon: z.string().optional(),
70
+ /** Keyboard shortcut string (e.g. `"ctrl+shift+r"`). */
71
+ shortcut: z.string().optional()
72
+ });
73
+ var TurnHookContributionSchema = z.object({
74
+ /** Stable id for this hook (unique within the plugin). */
75
+ id: z.string().min(1),
76
+ /** Turn boundary this fires on. Today only `"post_assistant_turn"`. */
77
+ on: z.string().min(1).default("post_assistant_turn"),
78
+ /** The JS hook body executed in the sandbox (returns a directive). */
79
+ code: z.string().min(1)
80
+ });
81
+ var DEFAULT_WIDGET_MIME = "text/html+skybridge";
82
+ var DEFAULT_WIDGET_DISPLAY_MODE = "inline";
83
+ var WidgetContributionSchema = z.object({
84
+ /** The fully-qualified tool id whose result renders this widget. */
85
+ tool_id: z.string().min(1),
86
+ /** `ui://widget/<slug>.html` — the widget resource uri. */
87
+ uri: z.string().min(1),
88
+ /** Source entry (e.g. `src/apps/checklist/index.tsx`) for `ryu pack`. */
89
+ ui_entry: z.string().optional(),
90
+ /** Widget MIME dialect (default `text/html+skybridge`). */
91
+ mime: z.string().default(DEFAULT_WIDGET_MIME),
92
+ /** Default display mode (`inline` | `fullscreen` | `pip`). */
93
+ default_display_mode: z.string().default(DEFAULT_WIDGET_DISPLAY_MODE)
94
+ });
95
+ var ToolAppConfigSchema = z.object({
96
+ /** MCP tool slug this runnable wraps — the fully-qualified `<server>__<name>` id. */
97
+ slug: z.string().min(1),
98
+ /** The tool description the model reads when choosing it. Carried here because a
99
+ * packed app's manifest is the only channel (there is no `generated.rs`); Core's
100
+ * app-tool synthesis reads it back onto the `RegistryTool`. */
101
+ description: z.string(),
102
+ /** JSON Schema for the tool's arguments (used for validation + the LLM tool
103
+ * surface). Snake_case to match `widget_accessible`. Absent = no arguments. */
104
+ input_schema: z.record(z.string(), z.unknown()).optional(),
105
+ /** True when calling this tool renders the app's widget (carries the template). */
106
+ widget: z.boolean().default(false),
107
+ /** True when a mounted widget may `callTool` this tool (a companion), or when a
108
+ * render tool's widget may call any companion the app declares. */
109
+ widget_accessible: z.boolean().default(false),
110
+ /** Optional status label shown while the render tool runs. */
111
+ invoking: z.string().optional(),
112
+ /** Optional status label shown when the render tool finishes. */
113
+ invoked: z.string().optional()
114
+ });
115
+ var ContributesSchema = z.object({
116
+ turn_hooks: z.array(TurnHookContributionSchema).default([]),
117
+ composer_controls: z.array(z.record(z.string(), z.unknown())).default([]),
118
+ settings_tabs: z.array(z.record(z.string(), z.unknown())).default([]),
119
+ slash_commands: z.array(z.record(z.string(), z.unknown())).default([]),
120
+ /** App widgets (Ryu Apps). Each binds a render tool id to its
121
+ * `ui://widget/<slug>.html` template. Mirrors the Rust-side
122
+ * `Contributes.widgets` field, without which the CLI's zod parse would strip
123
+ * every widget an app authored here declares. */
124
+ widgets: z.array(WidgetContributionSchema).default([])
125
+ });
126
+ var SetupStepSchema = z.object({
127
+ /** Card heading (e.g. the companion app name). */
128
+ title: z.string().optional(),
129
+ /** Instruction body shown under the title. */
130
+ description: z.string().optional(),
131
+ /** Label for the optional action button. */
132
+ actionLabel: z.string().optional(),
133
+ /** URL the action button opens (validated server-side on publish). */
134
+ actionUrl: z.string().optional()
135
+ });
136
+ var AppDependencySchema = z.object({
137
+ /** The `id` of the plugin this one depends on. */
138
+ id: z.string().min(1, "dependency id is required"),
139
+ /** Optional MINIMUM version the dependency must satisfy (`"1.2.0"` = `">=1.2.0"`). */
140
+ min_version: z.string().min(1).optional()
141
+ });
142
+ var CapabilityReqSchema = z.object({
143
+ /** Capability name (e.g. `"rag"`, `"memory"`, `"tts"`). Matched against a
144
+ * provider's `provides[].capability`. */
145
+ capability: z.string().min(1, "capability name is required"),
146
+ /** Optional MINIMUM capability version the bound provider must satisfy
147
+ * (`"1.2.0"` = `">=1.2.0"`). Absent = any version. */
148
+ min_version: z.string().min(1).optional()
149
+ });
150
+ var RequiresSchema = z.object({
151
+ /** Other plugins that must be installed + enabled before this one enables. */
152
+ apps: z.array(AppDependencySchema).default([]),
153
+ /**
154
+ * Abstract capability edges the broker resolves to a bound provider at
155
+ * enable time. Mirrors `Requires::capabilities` in
156
+ * `crates/ryu-kernel-contracts` — an `apps` edge names a specific plugin; a
157
+ * `capabilities` edge names a capability and lets the binding registry choose
158
+ * the provider. Each is lowered to an app-id graph edge once bound, so the
159
+ * enable/disable/cycle machinery is shared. Empty for the common case.
160
+ */
161
+ capabilities: z.array(CapabilityReqSchema).default([]),
162
+ /**
163
+ * Permission grants implied by the dependencies. Declaration only — the
164
+ * Gateway remains the sole authority on what a grant *allows*, and Core's
165
+ * dependency graph resolves `apps` only.
166
+ */
167
+ grants: z.array(z.string()).default([])
168
+ });
169
+ var SurfaceSchema = z.enum([
170
+ /** The Ryu Gateway. */
171
+ "gateway",
172
+ /** A headless Core node (no UI). */
173
+ "core",
174
+ /** The Tauri desktop app. */
175
+ "desktop",
176
+ /** The Electron dynamic-island companion. */
177
+ "island",
178
+ /** The Expo/React-Native mobile app. */
179
+ "mobile",
180
+ /** The browser extension. */
181
+ "extension",
182
+ /** The Next.js web app. */
183
+ "web",
184
+ /** The terminal client. */
185
+ "cli"
186
+ ]);
187
+ var PluginManifestSchema = z.object({
188
+ /** Reverse-domain unique identifier (e.g. `"com.example.my-plugin"`). */
189
+ id: z.string().min(1, "id is required"),
190
+ /** Human-readable display name shown in the plugin store / launcher. */
191
+ name: z.string().min(1, "name is required"),
192
+ /**
193
+ * Semver version string (e.g. `"1.0.0"`). Core's loader rejects any manifest
194
+ * whose version is not valid semver; the regex here enforces the same rule at
195
+ * SDK-build time.
196
+ */
197
+ version: z.string().regex(
198
+ /^\d+\.\d+\.\d+(?:-[\w.]+)?(?:\+[\w.]+)?$/,
199
+ "version must be a valid semver string (e.g. 1.0.0)"
200
+ ),
201
+ /**
202
+ * Lower-case hex `sha256(utf8_bytes(ui_code))` binding the plugin's bundled
203
+ * sandboxed-UI code to this manifest. `ryu pack` / `ryu publish` compute it and
204
+ * write it here BEFORE the manifest is signed, so the hash rides INSIDE the
205
+ * Gateway-signed surface while the `ui_code` blob rides OUTSIDE it as payload;
206
+ * Core's install path recomputes the hash over the fetched code and rejects a
207
+ * mismatch fail-closed. Absent for a manifest-only plugin (no bundled UI).
208
+ * Mirrors Core's `PluginManifest.ui_code_sha256`.
209
+ */
210
+ ui_code_sha256: z.string().nullish(),
211
+ /** The Runnables this plugin bundles. */
212
+ runnables: z.array(RunnableMetaSchema).default([]),
213
+ /**
214
+ * Permission grants this plugin declares it needs (e.g. `"mcp:web_search"`).
215
+ * Declarations only — grant enforcement is the Gateway's responsibility.
216
+ */
217
+ permission_grants: z.array(z.string()).default([]),
218
+ /**
219
+ * Optional Companion surface (an in-desktop overlay or sidebar panel).
220
+ * Absent when the plugin has no Companion surface.
221
+ */
222
+ companion: CompanionSurfaceSchema.optional(),
223
+ /**
224
+ * VS-Code-style activation events (`"*"`, `"onStartup"`, `"onChat"`,
225
+ * `"onCommand:<id>"`). Empty = eager. Turn-hook plugins are driven by their
226
+ * enabled flag, so `["*"]` is the usual value.
227
+ */
228
+ activation_events: z.array(z.string()).default([]),
229
+ /**
230
+ * Contribution points: server-side turn hooks + declarative UI widgets.
231
+ * Absent for a plugin that contributes nothing here.
232
+ */
233
+ contributes: ContributesSchema.optional(),
234
+ /**
235
+ * **Plugin-to-plugin dependencies** — the other plugins this one needs. Core
236
+ * resolves them into a topological enable order (dependencies enable first;
237
+ * disabling one is refused while an enabled dependent needs it).
238
+ *
239
+ * Absent = **no dependencies**, the backward-compatible default. Kept
240
+ * `.optional()` (never defaulted) so a manifest that declares none serialises
241
+ * with no `requires` key at all, exactly like Core's
242
+ * `#[serde(skip_serializing_if = "Option::is_none")]`.
243
+ */
244
+ requires: RequiresSchema.optional(),
245
+ /**
246
+ * Host surfaces this plugin runs on. **Empty or absent = runs on EVERY
247
+ * surface** — the backward-compatible default, which must never be read as
248
+ * "runs nowhere". Core filters only when the list is explicitly non-empty, and
249
+ * only at the read boundary (`GET /api/plugins`, keyed on `x-ryu-surface`), so
250
+ * an unsupported-target plugin stays installable and inspectable.
251
+ */
252
+ targets: z.array(SurfaceSchema).default([]),
253
+ /**
254
+ * Optional per-item AFFILIATE terms: the commission paid to a referrer when a
255
+ * referred user buys this (paid) item. `value` is basis points for `percent`
256
+ * (2000 = 20%) or minor units (cents) for `flat`. Absent (or `enabled:false`)
257
+ * falls back to the seller org owner's default affiliate terms. This is the
258
+ * authoring surface for the marketplace publish body's `affiliate` field (the
259
+ * server re-validates it); it only takes effect on a paid item.
260
+ */
261
+ affiliate: z.object({
262
+ enabled: z.boolean().default(false),
263
+ rule: z.object({
264
+ type: z.enum(["percent", "flat"]),
265
+ value: z.number().nonnegative(),
266
+ recurring: z.boolean().default(false),
267
+ durationMonths: z.number().int().positive().nullish(),
268
+ fundedBy: z.enum(["platform", "seller"]).default("platform")
269
+ }).optional()
270
+ }).optional(),
271
+ // ── Rich listing metadata (Phase 1.5) ──────────────────────────────────────
272
+ // Optional store-listing fields a plugin author declares so the marketplace
273
+ // detail dialog renders a richer App-Store-style preview. Field names align
274
+ // with the Claude `.claude-plugin/marketplace.json` plugin-entry standard where
275
+ // one exists (`author`, `homepage`, `keywords`, `category`, `license`); the
276
+ // rest are Ryu extensions. `ryu publish` forwards these FLAT into the publish
277
+ // body (not inside the signed manifest blob) so the control plane stores them.
278
+ // All optional + additive: a manifest omitting them still validates.
279
+ /** Longer plain/markdown description shown in the detail dialog. */
280
+ description: z.string().optional(),
281
+ /** Short one-line pitch shown under the name (Ryu extension). */
282
+ tagline: z.string().optional(),
283
+ /**
284
+ * Publisher identity. A bare string OR a Claude-style object; `ryu publish`
285
+ * resolves it to the display `developer` (`author.name` when an object).
286
+ */
287
+ author: z.union([
288
+ z.string(),
289
+ z.object({
290
+ name: z.string(),
291
+ email: z.string().optional(),
292
+ url: z.string().optional()
293
+ })
294
+ ]).optional(),
295
+ /** Project/marketing homepage — maps to the listing `website` (Claude field). */
296
+ homepage: z.string().optional(),
297
+ /** Free-text search keywords (Claude field). */
298
+ keywords: z.array(z.string()).optional(),
299
+ /** Taxonomy category beyond the runnable kinds (Claude field). */
300
+ category: z.string().optional(),
301
+ /** SPDX-ish license identifier (Claude field). */
302
+ license: z.string().optional(),
303
+ /** Square logo/icon URL for the listing card + detail header. */
304
+ iconUrl: z.string().optional(),
305
+ /** Ordered App-Store-style screenshot gallery URLs (Ryu extension). */
306
+ screenshots: z.array(z.string()).optional(),
307
+ /** Privacy policy URL surfaced on detail (Ryu extension). */
308
+ privacyPolicyUrl: z.string().optional(),
309
+ /** Terms-of-service URL surfaced on detail (Ryu extension). */
310
+ termsOfServiceUrl: z.string().optional(),
311
+ /**
312
+ * Human-readable capability strings (Ryu extension). When omitted the control
313
+ * plane derives a default from `permission_grants`, so declaring this is only
314
+ * needed to override the derived labels.
315
+ */
316
+ capabilities: z.array(z.string()).optional(),
317
+ /** Example prompt chips shown on detail (Ryu extension). */
318
+ examplePrompts: z.array(z.string()).optional(),
319
+ /**
320
+ * Optional companion/config card (Ryu extension): a single setup step or an
321
+ * array of steps guiding the user through post-install configuration.
322
+ */
323
+ setup: z.union([SetupStepSchema, z.array(SetupStepSchema)]).optional()
324
+ });
325
+ function validatePluginId(id) {
326
+ loadNative().validatePluginId(id);
327
+ }
328
+ function validateManifestStrict(manifestJson) {
329
+ return loadNative().parseAndValidateManifest(manifestJson);
330
+ }
331
+ function coreManifestJsonSchema() {
332
+ return JSON.parse(loadNative().pluginManifestJsonSchema());
333
+ }
334
+
335
+ export {
336
+ RunnableKindSchema,
337
+ RunnableMetaSchema,
338
+ labelImpersonatesSystemChrome,
339
+ CompanionSurfaceSchema,
340
+ TurnHookContributionSchema,
341
+ WidgetContributionSchema,
342
+ ToolAppConfigSchema,
343
+ ContributesSchema,
344
+ SetupStepSchema,
345
+ AppDependencySchema,
346
+ CapabilityReqSchema,
347
+ RequiresSchema,
348
+ SurfaceSchema,
349
+ PluginManifestSchema,
350
+ validatePluginId,
351
+ validateManifestStrict,
352
+ coreManifestJsonSchema
353
+ };