@dylanrussell/agent-router 1.1.1 → 2.0.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/CHANGELOG.md +19 -0
- package/README.md +23 -17
- package/dist/cli.js +70 -20
- package/dist/cli.js.map +1 -1
- package/dist/plugin.d.ts +190 -3
- package/dist/plugin.js +382 -153
- package/dist/plugin.js.map +1 -1
- package/dist/tui.d.ts +3 -1
- package/dist/tui.js +167 -6
- package/dist/tui.js.map +1 -1
- package/index.ts +2 -0
- package/package.json +7 -3
- package/tui.ts +2 -0
package/dist/plugin.d.ts
CHANGED
|
@@ -1,4 +1,79 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Context } from '@opencode/plugin/promise/plugin';
|
|
3
|
+
|
|
4
|
+
/** 2.0.8: model refs are readonly in context hooks; switch only at user admission. */
|
|
5
|
+
declare function setupV2(ctx: Context): Promise<() => Promise<void>>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Zod schemas for agent-router's own files.
|
|
9
|
+
*
|
|
10
|
+
* Two philosophies:
|
|
11
|
+
*
|
|
12
|
+
* 1. `state.json` and `config.json` are OURS — strict schema, fail closed.
|
|
13
|
+
* We control every byte; if malformed something corrupted it and we
|
|
14
|
+
* should refuse to proceed rather than silently rebuild and lose pointers.
|
|
15
|
+
*
|
|
16
|
+
* 2. `stacks/*.json` are user-authored. We validate only the shape we care
|
|
17
|
+
* about (an `agents` record whose entries carry a `model` string) and
|
|
18
|
+
* pass unknown keys through verbatim so future additions survive
|
|
19
|
+
* round-trips.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
declare const RoutingEntrySchema: z.ZodObject<{
|
|
23
|
+
model: z.ZodString;
|
|
24
|
+
variant: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
25
|
+
fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
26
|
+
model: z.ZodString;
|
|
27
|
+
variant: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>>>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
type RoutingEntry = z.infer<typeof RoutingEntrySchema>;
|
|
31
|
+
|
|
32
|
+
declare const Model: z.ZodObject<{
|
|
33
|
+
providerID: z.ZodString;
|
|
34
|
+
modelID: z.ZodString;
|
|
35
|
+
variant: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
type Selection = z.infer<typeof Model>;
|
|
38
|
+
/** No network calls or disk writes: selection happens synchronously at next-turn admission. */
|
|
39
|
+
declare function createFailover(routes: Record<string, RoutingEntry>, notice: (message: string) => Promise<void>): {
|
|
40
|
+
active(sessionID: string): boolean;
|
|
41
|
+
disable(): void;
|
|
42
|
+
message(input: {
|
|
43
|
+
sessionID: string;
|
|
44
|
+
}, output: {
|
|
45
|
+
message: {
|
|
46
|
+
id: string;
|
|
47
|
+
agent: string;
|
|
48
|
+
model: Selection;
|
|
49
|
+
};
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
event(input: {
|
|
52
|
+
event: unknown;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Validate that every model ID referenced by a stack file is reachable
|
|
58
|
+
* through the user's current opencode auth.
|
|
59
|
+
*
|
|
60
|
+
* Strategy: shell out to `opencode models`, capture the line-per-id list,
|
|
61
|
+
* compare to the IDs found in the stack. The model catalogue is
|
|
62
|
+
* auth-state-dependent — a user without an Anthropic key won't see
|
|
63
|
+
* `anthropic/...` IDs even though they exist on the registry — so this gives
|
|
64
|
+
* us a real "will this work" answer instead of a registry sniff.
|
|
65
|
+
*
|
|
66
|
+
* For tests, callers can inject a fake `runOpencodeModels` that returns
|
|
67
|
+
* canned text. See `tests/fixtures/opencode-models-output.txt`.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
interface ValidateOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Override the model lister. Defaults to running `opencode models` via
|
|
73
|
+
* `execFile`. Tests pass a static string.
|
|
74
|
+
*/
|
|
75
|
+
readonly runOpencodeModels?: () => Promise<string>;
|
|
76
|
+
}
|
|
2
77
|
|
|
3
78
|
/**
|
|
4
79
|
* opencode plugin entry for agent-router.
|
|
@@ -25,6 +100,118 @@ import { Plugin } from '@opencode-ai/plugin';
|
|
|
25
100
|
* `output` so the agent can parse our tool responses programmatically.
|
|
26
101
|
*/
|
|
27
102
|
|
|
28
|
-
|
|
103
|
+
interface PluginClientLike {
|
|
104
|
+
app?: {
|
|
105
|
+
log?: (input: {
|
|
106
|
+
body: {
|
|
107
|
+
service: string;
|
|
108
|
+
level: "debug" | "info" | "warn" | "error";
|
|
109
|
+
message: string;
|
|
110
|
+
extra?: Record<string, unknown>;
|
|
111
|
+
};
|
|
112
|
+
}) => Promise<unknown>;
|
|
113
|
+
};
|
|
114
|
+
tui?: {
|
|
115
|
+
showToast?: (input: {
|
|
116
|
+
body: {
|
|
117
|
+
message: string;
|
|
118
|
+
variant: "info" | "success" | "warning";
|
|
119
|
+
duration?: number;
|
|
120
|
+
};
|
|
121
|
+
}) => Promise<unknown>;
|
|
122
|
+
toast?: {
|
|
123
|
+
show?: (input: {
|
|
124
|
+
body: {
|
|
125
|
+
message: string;
|
|
126
|
+
variant: "info" | "success" | "warning";
|
|
127
|
+
};
|
|
128
|
+
}) => Promise<unknown>;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
declare const AgentRouterPlugin: (ctx: {
|
|
133
|
+
client: PluginClientLike;
|
|
134
|
+
}, validateOptions?: ValidateOptions) => Promise<{
|
|
135
|
+
event: (input: {
|
|
136
|
+
event: unknown;
|
|
137
|
+
}) => Promise<void>;
|
|
138
|
+
"chat.message": (input: Parameters<ReturnType<typeof createFailover>["message"]>[0], output: Parameters<ReturnType<typeof createFailover>["message"]>[1]) => Promise<void>;
|
|
139
|
+
tool: {
|
|
140
|
+
router_status: {
|
|
141
|
+
description: string;
|
|
142
|
+
args: {};
|
|
143
|
+
execute: (args: Record<string, never>) => Promise<{
|
|
144
|
+
output: string;
|
|
145
|
+
metadata: Record<string, unknown>;
|
|
146
|
+
}>;
|
|
147
|
+
};
|
|
148
|
+
router_list: {
|
|
149
|
+
description: string;
|
|
150
|
+
args: {};
|
|
151
|
+
execute: (args: Record<string, never>) => Promise<{
|
|
152
|
+
output: string;
|
|
153
|
+
metadata: Record<string, unknown>;
|
|
154
|
+
}>;
|
|
155
|
+
};
|
|
156
|
+
router_use: {
|
|
157
|
+
description: string;
|
|
158
|
+
args: {
|
|
159
|
+
name: z.ZodString;
|
|
160
|
+
validate: z.ZodOptional<z.ZodBoolean>;
|
|
161
|
+
};
|
|
162
|
+
execute: (args: {
|
|
163
|
+
name: string;
|
|
164
|
+
validate?: boolean | undefined;
|
|
165
|
+
}) => Promise<{
|
|
166
|
+
output: string;
|
|
167
|
+
metadata: Record<string, unknown>;
|
|
168
|
+
}>;
|
|
169
|
+
};
|
|
170
|
+
router_capture: {
|
|
171
|
+
description: string;
|
|
172
|
+
args: {
|
|
173
|
+
name: z.ZodString;
|
|
174
|
+
force: z.ZodOptional<z.ZodBoolean>;
|
|
175
|
+
};
|
|
176
|
+
execute: (args: {
|
|
177
|
+
name: string;
|
|
178
|
+
force?: boolean | undefined;
|
|
179
|
+
}) => Promise<{
|
|
180
|
+
output: string;
|
|
181
|
+
metadata: Record<string, unknown>;
|
|
182
|
+
}>;
|
|
183
|
+
};
|
|
184
|
+
router_validate: {
|
|
185
|
+
description: string;
|
|
186
|
+
args: {
|
|
187
|
+
name: z.ZodOptional<z.ZodString>;
|
|
188
|
+
active: z.ZodOptional<z.ZodBoolean>;
|
|
189
|
+
};
|
|
190
|
+
execute: (args: {
|
|
191
|
+
name?: string | undefined;
|
|
192
|
+
active?: boolean | undefined;
|
|
193
|
+
}) => Promise<{
|
|
194
|
+
output: string;
|
|
195
|
+
metadata: Record<string, unknown>;
|
|
196
|
+
}>;
|
|
197
|
+
};
|
|
198
|
+
router_back: {
|
|
199
|
+
description: string;
|
|
200
|
+
args: {
|
|
201
|
+
n: z.ZodOptional<z.ZodNumber>;
|
|
202
|
+
};
|
|
203
|
+
execute: (args: {
|
|
204
|
+
n?: number | undefined;
|
|
205
|
+
}) => Promise<{
|
|
206
|
+
output: string;
|
|
207
|
+
metadata: Record<string, unknown>;
|
|
208
|
+
}>;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
}>;
|
|
212
|
+
declare const _default: {
|
|
213
|
+
id: string;
|
|
214
|
+
setup: typeof setupV2;
|
|
215
|
+
};
|
|
29
216
|
|
|
30
|
-
export { AgentRouterPlugin,
|
|
217
|
+
export { AgentRouterPlugin, _default as default };
|