@ryuhq/sdk 0.1.14 → 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,19 @@
1
+ // src/model/gateway.ts
2
+ import * as native from "@ryuhq/sdk-native";
3
+ var DEFAULT_GATEWAY_URL = "http://127.0.0.1:7981";
4
+ function resolveGatewayUrl2() {
5
+ return native.resolveGatewayUrl();
6
+ }
7
+ function resolveGatewayToken2() {
8
+ return native.resolveGatewayToken() ?? void 0;
9
+ }
10
+ function assertAllowedEgressUrl(baseUrl) {
11
+ native.assertAllowedEgress(baseUrl);
12
+ }
13
+
14
+ export {
15
+ DEFAULT_GATEWAY_URL,
16
+ resolveGatewayUrl2 as resolveGatewayUrl,
17
+ resolveGatewayToken2 as resolveGatewayToken,
18
+ assertAllowedEgressUrl
19
+ };
@@ -0,0 +1,354 @@
1
+ import {
2
+ defineApp
3
+ } from "./chunk-W3KPP4WN.js";
4
+ import {
5
+ PluginManifestSchema,
6
+ RunnableMetaSchema
7
+ } from "./chunk-IEUQ3CDG.js";
8
+
9
+ // src/builder.ts
10
+ var RunnableBuilder = class {
11
+ _id = "";
12
+ _name = "";
13
+ id(value) {
14
+ this._id = value;
15
+ return this;
16
+ }
17
+ name(value) {
18
+ this._name = value;
19
+ return this;
20
+ }
21
+ };
22
+ var AgentBuilder = class extends RunnableBuilder {
23
+ build() {
24
+ const result = RunnableMetaSchema.safeParse({
25
+ id: this._id,
26
+ name: this._name,
27
+ kind: "agent"
28
+ });
29
+ if (!result.success) {
30
+ throw new Error(
31
+ `Invalid agent runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
32
+ );
33
+ }
34
+ return result.data;
35
+ }
36
+ };
37
+ var WorkflowBuilder = class extends RunnableBuilder {
38
+ build() {
39
+ const result = RunnableMetaSchema.safeParse({
40
+ id: this._id,
41
+ name: this._name,
42
+ kind: "workflow"
43
+ });
44
+ if (!result.success) {
45
+ throw new Error(
46
+ `Invalid workflow runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
47
+ );
48
+ }
49
+ return result.data;
50
+ }
51
+ };
52
+ var ToolBuilder = class extends RunnableBuilder {
53
+ build() {
54
+ const result = RunnableMetaSchema.safeParse({
55
+ id: this._id,
56
+ name: this._name,
57
+ kind: "tool"
58
+ });
59
+ if (!result.success) {
60
+ throw new Error(
61
+ `Invalid tool runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
62
+ );
63
+ }
64
+ return result.data;
65
+ }
66
+ };
67
+ var SkillBuilder = class extends RunnableBuilder {
68
+ build() {
69
+ const result = RunnableMetaSchema.safeParse({
70
+ id: this._id,
71
+ name: this._name,
72
+ kind: "skill"
73
+ });
74
+ if (!result.success) {
75
+ throw new Error(
76
+ `Invalid skill runnable: ${result.error.issues.map((i) => i.message).join("; ")}`
77
+ );
78
+ }
79
+ return result.data;
80
+ }
81
+ };
82
+ var agent = () => new AgentBuilder();
83
+ var workflow = () => new WorkflowBuilder();
84
+ var tool = () => new ToolBuilder();
85
+ var skill = () => new SkillBuilder();
86
+ var PluginBuilder = class {
87
+ _id = "";
88
+ _name = "";
89
+ _version = "";
90
+ _runnables = [];
91
+ _grants = [];
92
+ _companion = void 0;
93
+ _dependencies = [];
94
+ _requiredCapabilities = [];
95
+ _requiredGrants = [];
96
+ _targets = [];
97
+ /** Set the reverse-domain app id (e.g. `"com.example.my-app"`). */
98
+ id(value) {
99
+ this._id = value;
100
+ return this;
101
+ }
102
+ /** Set the human-readable display name. */
103
+ name(value) {
104
+ this._name = value;
105
+ return this;
106
+ }
107
+ /** Set the semver version string (e.g. `"1.0.0"`). */
108
+ version(value) {
109
+ this._version = value;
110
+ return this;
111
+ }
112
+ /** Append a pre-built `RunnableMeta` (from any per-kind builder). */
113
+ runnable(meta) {
114
+ this._runnables.push(meta);
115
+ return this;
116
+ }
117
+ /** Declare a permission grant (e.g. `"mcp:web_search"`). */
118
+ grant(permission) {
119
+ this._grants.push(permission);
120
+ return this;
121
+ }
122
+ /** Set an optional Companion surface descriptor. */
123
+ companion(surface) {
124
+ this._companion = surface;
125
+ return this;
126
+ }
127
+ /**
128
+ * Declare a **plugin-to-plugin dependency**: `id` must be installed and is
129
+ * auto-enabled (in dependency order) before this plugin enables.
130
+ *
131
+ * `minVersion` is a MINIMUM — a bare `"1.2.0"` means `">=1.2.0"`, so an
132
+ * installed `2.0.0` satisfies it (comparator syntax like `">=1.2, <2"` is
133
+ * honoured verbatim).
134
+ */
135
+ dependsOn(id, minVersion) {
136
+ this._dependencies.push(
137
+ minVersion ? { id, min_version: minVersion } : { id }
138
+ );
139
+ return this;
140
+ }
141
+ /**
142
+ * Declare a permission grant implied by this plugin's dependencies
143
+ * (`requires.grants`). Declaration only — the Gateway remains the sole
144
+ * authority on what a grant allows. Use {@link PluginBuilder.grant} for the
145
+ * grants this plugin needs in its own right.
146
+ */
147
+ requiredGrant(permission) {
148
+ this._requiredGrants.push(permission);
149
+ return this;
150
+ }
151
+ /**
152
+ * Declare an abstract **capability** edge (`requires.capabilities`) the broker
153
+ * resolves to a bound provider at enable time — e.g. `requiresCapability("rag")`.
154
+ * Distinct from a specific-plugin dependency: a capability edge lets the
155
+ * binding registry choose the provider. `minVersion` is a MINIMUM (`"1.2.0"`
156
+ * = `">=1.2.0"`).
157
+ */
158
+ requiresCapability(capability, minVersion) {
159
+ this._requiredCapabilities.push(
160
+ minVersion ? { capability, min_version: minVersion } : { capability }
161
+ );
162
+ return this;
163
+ }
164
+ /**
165
+ * Restrict this plugin to a host surface (`"desktop"`, `"island"`, …).
166
+ * Declaring NO target is the default and means **every** surface.
167
+ */
168
+ target(surface) {
169
+ this._targets.push(surface);
170
+ return this;
171
+ }
172
+ /**
173
+ * Validate and return the assembled `PluginManifest`. Throws an `Error` with
174
+ * the failing field name and message when validation fails.
175
+ */
176
+ build() {
177
+ const hasRequires = this._dependencies.length > 0 || this._requiredCapabilities.length > 0 || this._requiredGrants.length > 0;
178
+ const raw = {
179
+ id: this._id,
180
+ name: this._name,
181
+ version: this._version,
182
+ runnables: this._runnables,
183
+ permission_grants: this._grants,
184
+ companion: this._companion,
185
+ targets: this._targets,
186
+ ...hasRequires ? {
187
+ requires: {
188
+ apps: this._dependencies,
189
+ capabilities: this._requiredCapabilities,
190
+ grants: this._requiredGrants
191
+ }
192
+ } : {}
193
+ };
194
+ const result = PluginManifestSchema.safeParse(raw);
195
+ if (!result.success) {
196
+ const first = result.error.issues[0];
197
+ const field = first?.path.join(".") ?? "unknown";
198
+ const message = first?.message ?? "validation failed";
199
+ throw new Error(
200
+ `manifest.json validation failed at '${field}': ${message}`
201
+ );
202
+ }
203
+ return result.data;
204
+ }
205
+ };
206
+ var AppBuilder = class {
207
+ _id = "";
208
+ _title = "";
209
+ _version = "";
210
+ _slug = "";
211
+ _server = void 0;
212
+ _displayMode = void 0;
213
+ _mime = void 0;
214
+ _uiEntry = "";
215
+ _grants = [];
216
+ _activationEvents = [];
217
+ _tools = [];
218
+ _dependencies = [];
219
+ _requiredCapabilities = [];
220
+ _requiredGrants = [];
221
+ _targets = [];
222
+ /** Set the reverse-domain app id (e.g. `"com.example.checklist"`). */
223
+ id(value) {
224
+ this._id = value;
225
+ return this;
226
+ }
227
+ /** Set the human-readable display name. */
228
+ title(value) {
229
+ this._title = value;
230
+ return this;
231
+ }
232
+ /** Set the semver version string (e.g. `"1.0.0"`). */
233
+ version(value) {
234
+ this._version = value;
235
+ return this;
236
+ }
237
+ /** Set the app slug (drives `ui://widget/<slug>.html` and the server default). */
238
+ slug(value) {
239
+ this._slug = value;
240
+ return this;
241
+ }
242
+ /** Override the MCP server namespace for tool ids (defaults to the slug). */
243
+ server(value) {
244
+ this._server = value;
245
+ return this;
246
+ }
247
+ /** Set the default widget display mode (`inline` | `fullscreen` | `pip`). */
248
+ displayMode(value) {
249
+ this._displayMode = value;
250
+ return this;
251
+ }
252
+ /** Override the widget MIME dialect (defaults to `text/html+skybridge`). */
253
+ mime(value) {
254
+ this._mime = value;
255
+ return this;
256
+ }
257
+ /** Set the widget UI source entry `ryu pack` bundles into `ui_code`. */
258
+ uiEntry(value) {
259
+ this._uiEntry = value;
260
+ return this;
261
+ }
262
+ /** Declare a permission grant (e.g. `"mcp:web_search"`). */
263
+ grant(permission) {
264
+ this._grants.push(permission);
265
+ return this;
266
+ }
267
+ /** Add a VS-Code-style activation event (empty = eager `["*"]`). */
268
+ activationEvent(event) {
269
+ this._activationEvents.push(event);
270
+ return this;
271
+ }
272
+ /** Append a tool spec (render tool unless `accessible:true`). */
273
+ tool(spec) {
274
+ this._tools.push(spec);
275
+ return this;
276
+ }
277
+ /**
278
+ * Declare a **plugin-to-plugin dependency** (auto-enabled, in dependency order,
279
+ * before this app). `minVersion` is a MINIMUM (`"1.2.0"` = `">=1.2.0"`).
280
+ */
281
+ dependsOn(id, minVersion) {
282
+ this._dependencies.push(
283
+ minVersion ? { id, min_version: minVersion } : { id }
284
+ );
285
+ return this;
286
+ }
287
+ /** Declare a grant implied by this app's dependencies (`requires.grants`). */
288
+ requiredGrant(permission) {
289
+ this._requiredGrants.push(permission);
290
+ return this;
291
+ }
292
+ /**
293
+ * Declare an abstract **capability** edge (`requires.capabilities`) the broker
294
+ * resolves to a bound provider at enable time — e.g. `requiresCapability("rag")`.
295
+ * Distinct from a specific-plugin dependency: a capability edge lets the
296
+ * binding registry choose the provider. `minVersion` is a MINIMUM (`"1.2.0"`
297
+ * = `">=1.2.0"`).
298
+ */
299
+ requiresCapability(capability, minVersion) {
300
+ this._requiredCapabilities.push(
301
+ minVersion ? { capability, min_version: minVersion } : { capability }
302
+ );
303
+ return this;
304
+ }
305
+ /** Restrict this app to a host surface. No target = every surface. */
306
+ target(surface) {
307
+ this._targets.push(surface);
308
+ return this;
309
+ }
310
+ /**
311
+ * Validate and return the assembled `PluginManifest`. Throws an `Error` naming
312
+ * the failing field when validation fails.
313
+ */
314
+ build() {
315
+ const hasRequires = this._dependencies.length > 0 || this._requiredCapabilities.length > 0 || this._requiredGrants.length > 0;
316
+ const options = {
317
+ id: this._id,
318
+ title: this._title,
319
+ version: this._version,
320
+ slug: this._slug,
321
+ uiEntry: this._uiEntry,
322
+ tools: this._tools,
323
+ grants: this._grants,
324
+ ...this._server ? { server: this._server } : {},
325
+ ...this._displayMode ? { displayMode: this._displayMode } : {},
326
+ ...this._mime ? { mime: this._mime } : {},
327
+ ...this._activationEvents.length > 0 ? { activationEvents: this._activationEvents } : {},
328
+ ...hasRequires ? {
329
+ requires: {
330
+ apps: this._dependencies,
331
+ capabilities: this._requiredCapabilities,
332
+ grants: this._requiredGrants
333
+ }
334
+ } : {},
335
+ ...this._targets.length > 0 ? { targets: this._targets } : {}
336
+ };
337
+ return defineApp(options);
338
+ }
339
+ };
340
+ var app = () => new AppBuilder();
341
+
342
+ export {
343
+ AgentBuilder,
344
+ WorkflowBuilder,
345
+ ToolBuilder,
346
+ SkillBuilder,
347
+ agent,
348
+ workflow,
349
+ tool,
350
+ skill,
351
+ PluginBuilder,
352
+ AppBuilder,
353
+ app
354
+ };
@@ -74,6 +74,21 @@ function toSpecEnv(value) {
74
74
  }
75
75
  return Object.keys(env).length > 0 ? env : void 0;
76
76
  }
77
+ function validateRemoteUrl(name, raw) {
78
+ let parsed;
79
+ try {
80
+ parsed = new URL(raw);
81
+ } catch {
82
+ return `mcp server '${name}' remote url ${JSON.stringify(raw)} is invalid and was omitted`;
83
+ }
84
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
85
+ return `mcp server '${name}' remote url must use http or https and was omitted`;
86
+ }
87
+ if (parsed.username || parsed.password || parsed.hash) {
88
+ return `mcp server '${name}' remote url must not contain credentials or a fragment and was omitted`;
89
+ }
90
+ return void 0;
91
+ }
77
92
  function toSpecServer(name, decl) {
78
93
  const extras = {};
79
94
  const commandEnv = asString(decl.command_env);
@@ -91,6 +106,37 @@ function toSpecServer(name, decl) {
91
106
  note: `mcp server '${name}' is disabled in the native manifest and was omitted from ${AGENT_PLUGIN_MCP_FILE}`
92
107
  };
93
108
  }
109
+ const declaredType = asString(decl.type);
110
+ const remoteUrl = asString(decl.url);
111
+ const remoteType = declaredType === "sse" ? "sse" : declaredType === "streamable-http" || declaredType === "streamable_http" || declaredType === "http" || !declaredType && remoteUrl ? "streamable-http" : void 0;
112
+ if (remoteType) {
113
+ if (!remoteUrl) {
114
+ return {
115
+ extras,
116
+ note: `mcp server '${name}' has remote type '${remoteType}' but no url and was omitted`
117
+ };
118
+ }
119
+ const urlNote = validateRemoteUrl(name, remoteUrl);
120
+ if (urlNote) {
121
+ return { extras, note: urlNote };
122
+ }
123
+ const server2 = {
124
+ type: remoteType,
125
+ url: remoteUrl
126
+ };
127
+ const headers = toSpecEnv(decl.headers);
128
+ if (headers) {
129
+ server2.headers = headers;
130
+ }
131
+ const note = decl.auth ? `mcp server '${name}' uses Ryu OAuth metadata that is not portable; static headers were exported` : void 0;
132
+ return { server: server2, extras, note };
133
+ }
134
+ if (declaredType && declaredType !== "stdio") {
135
+ return {
136
+ extras,
137
+ note: `mcp server '${name}' has unsupported transport '${declaredType}' and was omitted`
138
+ };
139
+ }
94
140
  const command = asString(decl.command);
95
141
  if (!command) {
96
142
  return {
@@ -0,0 +1,240 @@
1
+ import {
2
+ PluginManifestSchema
3
+ } from "./chunk-IEUQ3CDG.js";
4
+
5
+ // src/runnable/agent.ts
6
+ var CAPABILITY_SLOTS = ["rag", "memory", "tts", "stt"];
7
+ function lowerChatSlot(chat) {
8
+ if (chat === void 0) {
9
+ return {};
10
+ }
11
+ if (typeof chat === "string") {
12
+ return { model: chat };
13
+ }
14
+ return {
15
+ model: chat.model,
16
+ engine: chat.engine,
17
+ persona: chat.persona,
18
+ modelPrefKey: chat.modelPrefKey
19
+ };
20
+ }
21
+ function lowerCapabilitySlot(capability, slot, card) {
22
+ if (slot === void 0 || slot === false) {
23
+ return;
24
+ }
25
+ if (slot === true) {
26
+ card.capabilities.push({ capability });
27
+ return;
28
+ }
29
+ if (typeof slot === "string") {
30
+ card.capabilities.push({ capability });
31
+ card.providers[capability] = slot;
32
+ return;
33
+ }
34
+ card.capabilities.push(
35
+ slot.minVersion ? { capability, min_version: slot.minVersion } : { capability }
36
+ );
37
+ if (slot.provider) {
38
+ card.providers[capability] = slot.provider;
39
+ }
40
+ }
41
+ function lowerSlots(options) {
42
+ const card = {
43
+ ...lowerChatSlot(options.chat),
44
+ capabilities: [],
45
+ providers: {},
46
+ tools: []
47
+ };
48
+ for (const capability of CAPABILITY_SLOTS) {
49
+ lowerCapabilitySlot(capability, options[capability], card);
50
+ }
51
+ for (const t of options.tools ?? []) {
52
+ card.tools.push(typeof t === "string" ? t : t.id);
53
+ }
54
+ return card;
55
+ }
56
+ function defaultRun(card) {
57
+ return async (input, ctx) => {
58
+ const content = typeof input === "string" ? input : JSON.stringify(input ?? "");
59
+ const messages = card.persona ? [
60
+ { role: "system", content: card.persona },
61
+ { role: "user", content }
62
+ ] : [{ role: "user", content }];
63
+ const result = await ctx.gateway.chat(messages);
64
+ return result.content;
65
+ };
66
+ }
67
+ function cardConfig(card) {
68
+ const config = {};
69
+ if (card.model) {
70
+ config.model = card.model;
71
+ }
72
+ if (card.engine) {
73
+ config.engine = card.engine;
74
+ }
75
+ if (card.persona) {
76
+ config.persona = card.persona;
77
+ }
78
+ if (card.modelPrefKey) {
79
+ config.model_pref_key = card.modelPrefKey;
80
+ }
81
+ if (Object.keys(card.providers).length > 0) {
82
+ config.capability_providers = card.providers;
83
+ }
84
+ if (card.tools.length > 0) {
85
+ config.tools = card.tools;
86
+ }
87
+ return config;
88
+ }
89
+ function agentToManifest(agent, options) {
90
+ const config = cardConfig(agent.card);
91
+ const meta = {
92
+ id: agent.id,
93
+ name: agent.name,
94
+ kind: "agent",
95
+ ...Object.keys(config).length > 0 ? { config } : {}
96
+ };
97
+ const hasRequires = agent.card.capabilities.length > 0 || (options.grants?.length ?? 0) > 0;
98
+ const raw = {
99
+ id: options.id,
100
+ name: options.name ?? agent.name,
101
+ version: options.version,
102
+ runnables: [meta],
103
+ ...hasRequires ? {
104
+ requires: {
105
+ apps: [],
106
+ capabilities: agent.card.capabilities,
107
+ grants: options.grants ?? []
108
+ }
109
+ } : {}
110
+ };
111
+ const result = PluginManifestSchema.safeParse(raw);
112
+ if (!result.success) {
113
+ const first = result.error.issues[0];
114
+ const field = first?.path.join(".") ?? "unknown";
115
+ const message = first?.message ?? "validation failed";
116
+ throw new Error(
117
+ `agent manifest validation failed at '${field}': ${message}`
118
+ );
119
+ }
120
+ return result.data;
121
+ }
122
+ function defineAgent(options) {
123
+ const { id, name } = options;
124
+ const card = lowerSlots(options);
125
+ const run = options.run ?? defaultRun(card);
126
+ return {
127
+ id,
128
+ name,
129
+ kind: "agent",
130
+ run,
131
+ card,
132
+ toManifest(manifestOptions) {
133
+ return agentToManifest(this, manifestOptions);
134
+ }
135
+ };
136
+ }
137
+
138
+ // src/runnable/skill.ts
139
+ function defineSkill(options) {
140
+ const { id, name, run } = options;
141
+ return {
142
+ id,
143
+ name,
144
+ kind: "skill",
145
+ run
146
+ };
147
+ }
148
+
149
+ // src/runnable/tool.ts
150
+ function validateInput(input, schema, toolId) {
151
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
152
+ throw new Error(
153
+ `[ryu-sdk] Tool "${toolId}" input must be an object, got ${JSON.stringify(input)}`
154
+ );
155
+ }
156
+ const record = input;
157
+ for (const requiredKey of schema.required ?? []) {
158
+ if (!(requiredKey in record)) {
159
+ throw new Error(
160
+ `[ryu-sdk] Tool "${toolId}" input missing required field "${requiredKey}"`
161
+ );
162
+ }
163
+ }
164
+ for (const [key, prop] of Object.entries(schema.properties)) {
165
+ if (!(key in record)) {
166
+ continue;
167
+ }
168
+ const value = record[key];
169
+ if (!checkType(value, prop.type)) {
170
+ throw new Error(
171
+ `[ryu-sdk] Tool "${toolId}" input field "${key}" expected type "${prop.type}", got ${JSON.stringify(value)}`
172
+ );
173
+ }
174
+ }
175
+ }
176
+ function checkType(value, type) {
177
+ switch (type) {
178
+ case "string":
179
+ return typeof value === "string";
180
+ case "number":
181
+ case "integer":
182
+ return typeof value === "number";
183
+ case "boolean":
184
+ return typeof value === "boolean";
185
+ case "array":
186
+ return Array.isArray(value);
187
+ case "object":
188
+ return typeof value === "object" && value !== null && !Array.isArray(value);
189
+ default:
190
+ return false;
191
+ }
192
+ }
193
+ function defineTool(options) {
194
+ const { id, name, schema, run } = options;
195
+ const code = `return await (${run.toString()})(input, host);`;
196
+ return {
197
+ id,
198
+ name,
199
+ kind: "tool",
200
+ schema,
201
+ code,
202
+ run(input, ctx) {
203
+ validateInput(input, schema, id);
204
+ return run(input, ctx);
205
+ }
206
+ };
207
+ }
208
+ function inlineToolRunnable(tool, options) {
209
+ return {
210
+ id: tool.id,
211
+ name: tool.name,
212
+ kind: "tool",
213
+ config: {
214
+ slug: tool.id,
215
+ backend: "inline_deno",
216
+ code: tool.code,
217
+ input_schema: tool.schema,
218
+ ...options?.description ? { description: options.description } : {}
219
+ }
220
+ };
221
+ }
222
+
223
+ // src/runnable/workflow.ts
224
+ function defineWorkflow(options) {
225
+ const { id, name, run } = options;
226
+ return {
227
+ id,
228
+ name,
229
+ kind: "workflow",
230
+ run
231
+ };
232
+ }
233
+
234
+ export {
235
+ defineAgent,
236
+ defineSkill,
237
+ defineTool,
238
+ inlineToolRunnable,
239
+ defineWorkflow
240
+ };
@@ -0,0 +1,21 @@
1
+ // src/plugin/ryu-plugin.ts
2
+ function toDisposable(teardown) {
3
+ let done = false;
4
+ return {
5
+ dispose() {
6
+ if (done) {
7
+ return;
8
+ }
9
+ done = true;
10
+ teardown();
11
+ }
12
+ };
13
+ }
14
+ function definePlugin(plugin) {
15
+ return plugin;
16
+ }
17
+
18
+ export {
19
+ toDisposable,
20
+ definePlugin
21
+ };
File without changes