@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.
- package/LICENSE +179 -0
- package/README.md +31 -0
- package/dist/agent.cjs +761 -0
- package/dist/agent.d.cts +3 -0
- package/dist/agent.d.ts +3 -0
- package/dist/agent.js +23 -0
- package/dist/chunk-GXHL5CO7.js +353 -0
- package/dist/chunk-KPKMMGVC.js +671 -0
- package/dist/chunk-ODFEUVPW.js +100 -0
- package/dist/cli.cjs +858 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +454 -0
- package/dist/index-CEbS1SlS.d.cts +988 -0
- package/dist/index-DAxq7Y0R.d.ts +988 -0
- package/dist/index.cjs +1900 -0
- package/dist/index.d.cts +759 -0
- package/dist/index.d.ts +759 -0
- package/dist/index.js +771 -0
- package/dist/manifest.cjs +399 -0
- package/dist/manifest.d.cts +355 -0
- package/dist/manifest.d.ts +355 -0
- package/dist/manifest.js +38 -0
- package/package.json +56 -0
- package/src/agent/agent.ts +208 -0
- package/src/agent/index.ts +51 -0
- package/src/agent/loop.test.ts +261 -0
- package/src/agent/loop.ts +259 -0
- package/src/agent/model-call.ts +190 -0
- package/src/agent/query.ts +40 -0
- package/src/agent/tools.ts +295 -0
- package/src/builder.ts +473 -0
- package/src/cli/dev.test.ts +178 -0
- package/src/cli/dev.ts +425 -0
- package/src/cli.ts +390 -0
- package/src/contracts-lockstep.test.ts +77 -0
- package/src/generated/plugin-manifest.ts +1121 -0
- package/src/index.ts +141 -0
- package/src/manifest.test.ts +610 -0
- package/src/manifest.ts +589 -0
- package/src/mcp/bridge.test.ts +196 -0
- package/src/mcp/client.ts +253 -0
- package/src/mcp/fixture-server.ts +23 -0
- package/src/mcp/server.ts +351 -0
- package/src/model/client.test.ts +107 -0
- package/src/model/client.ts +179 -0
- package/src/model/gateway.ts +41 -0
- package/src/plugin/ryu-plugin.ts +191 -0
- package/src/runnable/agent.ts +338 -0
- package/src/runnable/app.ts +233 -0
- package/src/runnable/index.ts +61 -0
- package/src/runnable/primitives-hostapi.test.ts +73 -0
- package/src/runnable/primitives.test.ts +286 -0
- package/src/runnable/primitives.ts +610 -0
- package/src/runnable/runnable-types.ts +113 -0
- package/src/runnable/runnable.test.ts +397 -0
- package/src/runnable/skill.ts +60 -0
- package/src/runnable/tool.ts +260 -0
- package/src/runnable/turn-hook.test.ts +81 -0
- package/src/runnable/turn-hook.ts +191 -0
- package/src/runnable/workflow.ts +76 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/model/client.ts
|
|
2
|
+
import * as native from "@ryuhq/sdk-native";
|
|
3
|
+
var ModelClient2 = class {
|
|
4
|
+
model;
|
|
5
|
+
baseUrl;
|
|
6
|
+
native;
|
|
7
|
+
constructor(model, options = {}) {
|
|
8
|
+
this.native = new native.ModelClient(
|
|
9
|
+
model,
|
|
10
|
+
options.baseUrl ?? null,
|
|
11
|
+
options.token ?? null
|
|
12
|
+
);
|
|
13
|
+
this.model = model;
|
|
14
|
+
this.baseUrl = options.baseUrl ?? native.resolveGatewayUrl();
|
|
15
|
+
}
|
|
16
|
+
/** Send a non-streaming chat completion request to the gateway. */
|
|
17
|
+
async chat(messages) {
|
|
18
|
+
const res = await this.native.chat(messages);
|
|
19
|
+
const usage = res.promptTokens === void 0 && res.completionTokens === void 0 && res.totalTokens === void 0 ? void 0 : {
|
|
20
|
+
promptTokens: res.promptTokens ?? 0,
|
|
21
|
+
completionTokens: res.completionTokens ?? 0,
|
|
22
|
+
totalTokens: res.totalTokens ?? 0
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
content: res.content,
|
|
26
|
+
finishReason: res.finishReason ?? null,
|
|
27
|
+
usage
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Send a streaming chat completion request, yielding deltas as they arrive. */
|
|
31
|
+
async *stream(messages) {
|
|
32
|
+
const queue = [];
|
|
33
|
+
let done = false;
|
|
34
|
+
let failure = null;
|
|
35
|
+
let wake = null;
|
|
36
|
+
const notify = () => {
|
|
37
|
+
if (wake) {
|
|
38
|
+
const w = wake;
|
|
39
|
+
wake = null;
|
|
40
|
+
w();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.native.stream(messages, (err, delta) => {
|
|
44
|
+
if (err) {
|
|
45
|
+
failure = err;
|
|
46
|
+
done = true;
|
|
47
|
+
} else if (delta === null || delta === void 0) {
|
|
48
|
+
done = true;
|
|
49
|
+
} else {
|
|
50
|
+
queue.push({
|
|
51
|
+
content: delta.content ?? null,
|
|
52
|
+
finishReason: delta.finishReason ?? null
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
notify();
|
|
56
|
+
});
|
|
57
|
+
while (true) {
|
|
58
|
+
while (queue.length > 0) {
|
|
59
|
+
const next = queue.shift();
|
|
60
|
+
if (next) {
|
|
61
|
+
yield next;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (failure) {
|
|
65
|
+
throw failure;
|
|
66
|
+
}
|
|
67
|
+
if (done) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
await new Promise((resolve) => {
|
|
71
|
+
wake = resolve;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
function defineModel(modelId, options = {}) {
|
|
77
|
+
return new ModelClient2(modelId, options);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/model/gateway.ts
|
|
81
|
+
import * as native2 from "@ryuhq/sdk-native";
|
|
82
|
+
var DEFAULT_GATEWAY_URL = "http://127.0.0.1:7981";
|
|
83
|
+
function resolveGatewayUrl3() {
|
|
84
|
+
return native2.resolveGatewayUrl();
|
|
85
|
+
}
|
|
86
|
+
function resolveGatewayToken2() {
|
|
87
|
+
return native2.resolveGatewayToken() ?? void 0;
|
|
88
|
+
}
|
|
89
|
+
function assertAllowedEgressUrl(baseUrl) {
|
|
90
|
+
native2.assertAllowedEgress(baseUrl);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
ModelClient2 as ModelClient,
|
|
95
|
+
defineModel,
|
|
96
|
+
DEFAULT_GATEWAY_URL,
|
|
97
|
+
resolveGatewayUrl3 as resolveGatewayUrl,
|
|
98
|
+
resolveGatewayToken2 as resolveGatewayToken,
|
|
99
|
+
assertAllowedEgressUrl
|
|
100
|
+
};
|