@theopenbee/engine-sdk 0.1.0 → 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.
package/README.md CHANGED
@@ -30,7 +30,7 @@ Request (protocol version `1`):
30
30
 
31
31
  | Field | Description |
32
32
  |---|---|
33
- | `method` | `check`, `run` or `usage` |
33
+ | `method` | `check`, `run`, `usage` or `models` |
34
34
  | `config` | The plugin's configuration as set by the user (for example `path`) |
35
35
  | `data_dir` | Private directory for the plugin, deleted when the plugin is uninstalled |
36
36
  | `state_dir` | Directory for state that must survive an uninstall; openbee never deletes it |
@@ -48,10 +48,11 @@ Response, exactly one line:
48
48
  | Method | `params` | `result` |
49
49
  |---|---|---|
50
50
  | `check` | `{}` | `{ version, path }` |
51
- | `run` | `{ role, work_dir, prompt, session_id, resume, extra_args, log_path, mcp? }` | `{ text, error? }` |
51
+ | `run` | `{ role, work_dir, prompt, session_id, resume, extra_args, log_path, model?, mcp? }` | `{ text, error? }` |
52
52
  | `usage` | `{ session_ids }` | `{ usage: { <session_id>: TokenUsage[] } }` |
53
+ | `models` | `{}` | `{ models: ModelInfo[] }` |
53
54
 
54
- `mcp` is `{ name, url, api_key_env }`: the MCP server the CLI should use and the name of the environment variable that holds its API key. `check` must finish within 30 seconds and `usage` within 60 seconds; `run` is only bounded by openbee stopping the task.
55
+ `model` is the worker's model for this engine; openbee leaves it out when none is set, and the engine then uses its own default. `mcp` is `{ name, url, api_key_env }`: the MCP server the CLI should use and the name of the environment variable that holds its API key. `models` lists the models openbee suggests for a worker; `id` is what openbee later sends as `model`. openbee runs it with the Env settings but without `OPENBEE_API_KEY`, so provider keys set there are visible. `check` and `models` must finish within 30 seconds and `usage` within 60 seconds; `run` is only bounded by openbee stopping the task.
55
56
 
56
57
  ## The Engine interface
57
58
 
@@ -60,6 +61,7 @@ interface Engine {
60
61
  check(req: EngineRequest<Record<string, never>>): Promise<CheckResult>;
61
62
  run(req: EngineRequest<RunParams>): Promise<RunResult>;
62
63
  usage(req: EngineRequest<{ session_ids: string[] }>): Promise<Record<string, TokenUsage[]>>;
64
+ models?(req: EngineRequest<Record<string, never>>): Promise<ModelInfo[]>;
63
65
  }
64
66
 
65
67
  interface CheckResult { version: string; path: string }
@@ -71,9 +73,10 @@ interface TokenUsage {
71
73
  cache_creation_tokens: number;
72
74
  cache_read_tokens: number;
73
75
  }
76
+ interface ModelInfo { id: string; name?: string }
74
77
  ```
75
78
 
76
- `runEngine(engine)` reads the request, dispatches on `method` and writes the response. `usage` returns a map from session id to its token usage; `runEngine` wraps it as `{ "usage": ... }` for you.
79
+ `runEngine(engine)` reads the request, dispatches on `method` and writes the response. `usage` returns a map from session id to its token usage; `runEngine` wraps it as `{ "usage": ... }` for you. `models` is optional and returns the model list, wrapped as `{ "models": ... }`; an engine without it answers `{ "models": [] }`.
77
80
 
78
81
  ## Minimal plugin
79
82
 
@@ -87,12 +90,12 @@ runEngine({
87
90
  },
88
91
 
89
92
  async run(req) {
90
- const { work_dir, prompt, extra_args, log_path } = req.params;
93
+ const { work_dir, prompt, extra_args, log_path, model } = req.params;
91
94
  const command = findCli(req.config, "mycli");
92
95
  let text = "";
93
96
  const res = await spawnCli({
94
97
  command,
95
- args: ["--print", ...extra_args],
98
+ args: ["--print", ...(model ? ["--model", model] : []), ...extra_args],
96
99
  cwd: work_dir,
97
100
  input: prompt,
98
101
  logPath: log_path,
package/dist/main.js CHANGED
@@ -65,6 +65,8 @@ async function dispatch(engine, req) {
65
65
  return engine.run(req);
66
66
  case "usage":
67
67
  return { usage: await engine.usage(req) };
68
+ case "models":
69
+ return { models: engine.models ? await engine.models(req) : [] };
68
70
  default:
69
71
  throw new Error(`unknown method "${String(req.method)}"`);
70
72
  }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export interface EngineRequest<P> {
2
2
  protocol_version: number;
3
- method: "run" | "check" | "usage";
3
+ method: "run" | "check" | "usage" | "models";
4
4
  openbee_version: string;
5
5
  engine_id: string;
6
6
  language: string;
@@ -17,6 +17,7 @@ export interface RunParams {
17
17
  resume: boolean;
18
18
  extra_args: string[];
19
19
  log_path: string;
20
+ model?: string;
20
21
  mcp?: {
21
22
  name: string;
22
23
  url: string;
@@ -38,10 +39,15 @@ export interface TokenUsage {
38
39
  cache_creation_tokens: number;
39
40
  cache_read_tokens: number;
40
41
  }
42
+ export interface ModelInfo {
43
+ id: string;
44
+ name?: string;
45
+ }
41
46
  export interface Engine {
42
47
  check(req: EngineRequest<Record<string, never>>): Promise<CheckResult>;
43
48
  run(req: EngineRequest<RunParams>): Promise<RunResult>;
44
49
  usage(req: EngineRequest<{
45
50
  session_ids: string[];
46
51
  }>): Promise<Record<string, TokenUsage[]>>;
52
+ models?(req: EngineRequest<Record<string, never>>): Promise<ModelInfo[]>;
47
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theopenbee/engine-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "SDK for building openbee engine plugins",
5
5
  "license": "MIT",
6
6
  "repository": {