1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
import type { ApiKeyCredentials, Extension, HostAPI, Manifest } from "@dispatch/kernel";
import { createOpenAICompatProvider } from "@dispatch/openai-stream";
import { transformBody } from "./reasoning.js";
import { type EnvSource, resolveUmansConfig } from "./resolver.js";
export const manifest: Manifest = {
id: "provider-umans",
name: "Umans AI Coding Plan",
version: "0.0.0",
apiVersion: "^0.1.0",
trust: "bundled",
activation: "eager",
capabilities: { network: true },
contributes: { providers: ["umans"] },
};
/**
* Activate the Umans provider. Reads `UMANS_API_KEY` / `UMANS_BASE_URL` /
* `UMANS_MODEL` from the environment (the imperative shell — at the edge) and
* `provider.umans.model` from host config, resolves the config via the pure
* `resolveUmansConfig`, then builds + registers the `"umans"` provider through
* `@dispatch/openai-stream`'s `createOpenAICompatProvider`.
*
* `env` defaults to `process.env` and is a parameter only so tests can inject a
* fake environment (faking the outermost edge) without mutating the real one.
* No `UMANS_API_KEY` is a config state, not an error — warn + skip registration.
*/
export async function activate(host: HostAPI, env: EnvSource = process.env): Promise<void> {
const configModel = host.config.get<string>("provider.umans.model");
const cfg = resolveUmansConfig(env, configModel);
if (!cfg) {
host.logger.warn("provider-umans: no UMANS_API_KEY. Provider not registered.");
return;
}
const credentials: ApiKeyCredentials = {
type: "api-key",
apiKey: cfg.apiKey,
baseURL: cfg.baseURL,
};
const provider = createOpenAICompatProvider({
credentials,
model: cfg.model,
id: "umans",
transformBody,
});
host.defineProvider(provider);
host.logger.info(`provider-umans: registered (model=${cfg.model})`);
}
export const extension: Extension = {
manifest,
activate,
};
|