@modelrelay/sdk 5.3.0 → 8.1.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.
- package/README.md +122 -0
- package/dist/{api-7TVb2cnl.d.cts → api-B7SmXjnr.d.cts} +599 -1
- package/dist/{api-7TVb2cnl.d.ts → api-B7SmXjnr.d.ts} +599 -1
- package/dist/api-CdHqjsU_.d.cts +6062 -0
- package/dist/api-CdHqjsU_.d.ts +6062 -0
- package/dist/api-CyuI9lx0.d.cts +6249 -0
- package/dist/api-CyuI9lx0.d.ts +6249 -0
- package/dist/api-DP9MoKHy.d.cts +5993 -0
- package/dist/api-DP9MoKHy.d.ts +5993 -0
- package/dist/api-R_gUMD1L.d.cts +6243 -0
- package/dist/api-R_gUMD1L.d.ts +6243 -0
- package/dist/{api-BRAJe_xm.d.cts → api-c1j5ycVR.d.cts} +0 -54
- package/dist/{api-BRAJe_xm.d.ts → api-c1j5ycVR.d.ts} +0 -54
- package/dist/billing/index.d.cts +1 -1
- package/dist/billing/index.d.ts +1 -1
- package/dist/chunk-27KGKJLT.js +1194 -0
- package/dist/{chunk-5O4NJXLJ.js → chunk-HHBAD7FF.js} +1 -1
- package/dist/{chunk-LZDGY24E.js → chunk-PKGWFDGU.js} +111 -59
- package/dist/{chunk-HLJAMT7F.js → chunk-RVHKBQ7X.js} +1 -1
- package/dist/chunk-SJC7Q4NK.js +1199 -0
- package/dist/chunk-URFLODQC.js +1199 -0
- package/dist/{chunk-JZRSCFQH.js → chunk-YQWOQ74P.js} +53 -20
- package/dist/index.cjs +3468 -1156
- package/dist/index.d.cts +916 -85
- package/dist/index.d.ts +916 -85
- package/dist/index.js +3106 -881
- package/dist/node.cjs +11 -7
- package/dist/node.d.cts +11 -11
- package/dist/node.d.ts +11 -11
- package/dist/node.js +6 -6
- package/dist/{tools-Db-F5rIL.d.cts → tools-Bxdv0Np2.d.cts} +101 -218
- package/dist/{tools-Db-F5rIL.d.ts → tools-Bxdv0Np2.d.ts} +101 -218
- package/dist/tools-DHCGz_lx.d.cts +1041 -0
- package/dist/tools-DHCGz_lx.d.ts +1041 -0
- package/dist/tools-ZpcYacSo.d.cts +1000 -0
- package/dist/tools-ZpcYacSo.d.ts +1000 -0
- package/package.json +6 -1
- package/dist/api-B9x3HA3Z.d.cts +0 -5292
- package/dist/api-B9x3HA3Z.d.ts +0 -5292
- package/dist/api-Bitsm1tl.d.cts +0 -5290
- package/dist/api-Bitsm1tl.d.ts +0 -5290
- package/dist/api-D0wnVpwn.d.cts +0 -5292
- package/dist/api-D0wnVpwn.d.ts +0 -5292
- package/dist/api-HVh8Lusf.d.cts +0 -5300
- package/dist/api-HVh8Lusf.d.ts +0 -5300
- package/dist/chunk-BL7GWXRZ.js +0 -1196
- package/dist/chunk-CV3DTA6P.js +0 -1196
- package/dist/chunk-G5H7EY4F.js +0 -1196
- package/dist/chunk-OJFVI3QJ.js +0 -1133
- package/dist/chunk-Z6R4G2TU.js +0 -1133
package/README.md
CHANGED
|
@@ -4,6 +4,91 @@
|
|
|
4
4
|
bun add @modelrelay/sdk
|
|
5
5
|
```
|
|
6
6
|
|
|
7
|
+
## Convenience API
|
|
8
|
+
|
|
9
|
+
The simplest way to get started. Three methods cover the most common use cases:
|
|
10
|
+
|
|
11
|
+
### Ask — Get a Quick Answer
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ModelRelay } from "@modelrelay/sdk";
|
|
15
|
+
|
|
16
|
+
const mr = ModelRelay.fromSecretKey(process.env.MODELRELAY_API_KEY!);
|
|
17
|
+
|
|
18
|
+
const answer = await mr.ask("claude-sonnet-4-5", "What is 2 + 2?");
|
|
19
|
+
console.log(answer); // "4"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Chat — Full Response with Metadata
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const response = await mr.chat("claude-sonnet-4-5", "Explain quantum computing", {
|
|
26
|
+
system: "You are a physics professor",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
console.log(response.output);
|
|
30
|
+
console.log("Tokens:", response.usage.totalTokens);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Agent — Agentic Tool Loops
|
|
34
|
+
|
|
35
|
+
Run an agent that automatically executes tools until completion:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { z } from "zod";
|
|
39
|
+
|
|
40
|
+
const tools = mr
|
|
41
|
+
.tools()
|
|
42
|
+
.add(
|
|
43
|
+
"read_file",
|
|
44
|
+
"Read a file from the filesystem",
|
|
45
|
+
z.object({ path: z.string().describe("File path to read") }),
|
|
46
|
+
async (args) => {
|
|
47
|
+
const content = await fs.readFile(args.path, "utf-8");
|
|
48
|
+
return content;
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const result = await mr.agent("claude-sonnet-4-5", {
|
|
53
|
+
tools,
|
|
54
|
+
prompt: "Read config.json and summarize it",
|
|
55
|
+
system: "You are a helpful file assistant",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log(result.output);
|
|
59
|
+
console.log("Tool calls:", result.usage.toolCalls);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### User Interaction — `user.ask`
|
|
63
|
+
|
|
64
|
+
Use the built-in `user.ask` tool to request human input in a workflow run:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { ModelRelay, ToolRegistry, ToolRunner, createUserAskTool } from "@modelrelay/sdk";
|
|
68
|
+
|
|
69
|
+
const mr = ModelRelay.fromSecretKey(process.env.MODELRELAY_API_KEY!);
|
|
70
|
+
|
|
71
|
+
const tools = [createUserAskTool()];
|
|
72
|
+
const registry = new ToolRegistry();
|
|
73
|
+
|
|
74
|
+
const runner = new ToolRunner({
|
|
75
|
+
registry,
|
|
76
|
+
runsClient: mr.runs,
|
|
77
|
+
onUserAsk: async (_pending, args) => {
|
|
78
|
+
const answer = await promptUser(args.question); // your UI/input here
|
|
79
|
+
return { answer, is_freeform: true };
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const run = await mr.runs.create(spec);
|
|
84
|
+
|
|
85
|
+
for await (const event of mr.runs.events(run.run_id)) {
|
|
86
|
+
if (event.type === "node_waiting") {
|
|
87
|
+
await runner.handleNodeWaiting(run.run_id, event.node_id, event.waiting);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
7
92
|
## Token Providers (Automatic Bearer Auth)
|
|
8
93
|
|
|
9
94
|
Use token providers when you want the SDK to automatically obtain/refresh **bearer tokens** for data-plane calls like `/responses` and `/runs`.
|
|
@@ -130,6 +215,43 @@ const spec = parallel([
|
|
|
130
215
|
.build();
|
|
131
216
|
```
|
|
132
217
|
|
|
218
|
+
### Precompiled Workflows
|
|
219
|
+
|
|
220
|
+
For workflows that run repeatedly, compile once and reuse:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
// Compile once
|
|
224
|
+
const { plan_hash } = await mr.workflows.compile(spec);
|
|
225
|
+
|
|
226
|
+
// Run multiple times with different inputs
|
|
227
|
+
for (const task of tasks) {
|
|
228
|
+
const run = await mr.runs.createFromPlan(plan_hash, {
|
|
229
|
+
input: { task },
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Plugins (Workflows)
|
|
235
|
+
|
|
236
|
+
Load GitHub-hosted plugins (markdown commands + agents), convert to workflows via `/responses`, then run them with `/runs`:
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
import { ModelRelay, OrchestrationModes } from "@modelrelay/sdk";
|
|
240
|
+
import { createLocalFSTools } from "@modelrelay/sdk/node";
|
|
241
|
+
|
|
242
|
+
const mr = ModelRelay.fromSecretKey(process.env.MODELRELAY_API_KEY!);
|
|
243
|
+
const tools = createLocalFSTools({ root: process.cwd() });
|
|
244
|
+
|
|
245
|
+
const plugin = await mr.plugins.load("github.com/your-org/your-plugin");
|
|
246
|
+
const result = await mr.plugins.run(plugin, "run", {
|
|
247
|
+
userTask: "Summarize the repo and suggest next steps.",
|
|
248
|
+
orchestrationMode: OrchestrationModes.Dynamic,
|
|
249
|
+
toolRegistry: tools,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
console.log(result.outputs?.result);
|
|
253
|
+
```
|
|
254
|
+
|
|
133
255
|
## Chat-Like Text Helpers
|
|
134
256
|
|
|
135
257
|
For the most common path (**system + user → assistant text**):
|