@nylorun/runtime 0.5.0-beta → 0.6.0-beta
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 +30 -0
- package/README.md +29 -61
- package/dist/config.d.ts +1 -1
- package/dist/configuration.d.ts +3 -0
- package/dist/configuration.js +3 -0
- package/dist/contracts.d.ts +4 -2
- package/dist/core/main.js +40 -0
- package/dist/core/provider.d.ts +12 -0
- package/dist/core/provider.js +60 -0
- package/dist/core/runtime.d.ts +50 -0
- package/dist/core/runtime.js +877 -0
- package/dist/core/store.d.ts +16 -0
- package/dist/core/store.js +101 -0
- package/dist/index.d.ts +6 -11
- package/dist/index.js +4 -6
- package/dist/model/defaults.d.ts +1 -1
- package/dist/model/http-model.d.ts +1 -1
- package/dist/node/local-sessions.js +17 -0
- package/dist/server/host.d.ts +42 -4
- package/dist/server/host.js +69 -3
- package/dist/session/api.d.ts +10 -0
- package/dist/session/api.js +15 -0
- package/dist/session/default.d.ts +5 -0
- package/dist/session/default.js +30 -0
- package/dist/session/handle.d.ts +27 -0
- package/dist/session/handle.js +199 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.js +2 -0
- package/dist/sessions/host.d.ts +11 -1
- package/dist/sessions/host.js +75 -7
- package/dist/sessions/store.d.ts +1 -0
- package/dist/sessions/store.js +3 -0
- package/package.json +16 -11
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -100
- package/dist/dev-entry.js +0 -2
- package/dist/dev.d.ts +0 -2
- package/dist/dev.js +0 -126
- package/dist/environment.d.ts +0 -2
- package/dist/environment.js +0 -64
- package/dist/launcher.d.ts +0 -1
- package/dist/launcher.js +0 -33
- package/dist/model/configure.d.ts +0 -12
- package/dist/model/configure.js +0 -155
- /package/dist/{dev-entry.d.ts → core/main.d.ts} +0 -0
package/dist/model/configure.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import { createInterface } from "node:readline/promises";
|
|
3
|
-
import { saveEnvironment } from "../environment.js";
|
|
4
|
-
import { ProjectCredentialStore } from "./auth-store.js";
|
|
5
|
-
import { modelsFor } from "./models.js";
|
|
6
|
-
export class ConfigurationCancelled extends Error {
|
|
7
|
-
signal;
|
|
8
|
-
exitCode;
|
|
9
|
-
constructor(signal) {
|
|
10
|
-
super(`Provider configuration cancelled (${signal}).`);
|
|
11
|
-
this.signal = signal;
|
|
12
|
-
this.exitCode = signal === "SIGINT" ? 130 : 143;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
// Internal options also allow isolated prompt tests without changing process globals.
|
|
16
|
-
export async function configureProvider(options = {}) {
|
|
17
|
-
const root = options.root ?? process.cwd();
|
|
18
|
-
const output = options.output ?? process.stdout;
|
|
19
|
-
const controller = new AbortController();
|
|
20
|
-
const signal = controller.signal;
|
|
21
|
-
const forwardAbort = () => controller.abort(options.signal.reason);
|
|
22
|
-
options.signal?.throwIfAborted();
|
|
23
|
-
let enteredKey;
|
|
24
|
-
let enteredEnvironment = {};
|
|
25
|
-
const oauthStore = new ProjectCredentialStore(join(root, ".nylorun", "auth.json"), join(root, ".env", "auth.json"));
|
|
26
|
-
const store = {
|
|
27
|
-
read: (id) => oauthStore.read(id),
|
|
28
|
-
list: () => oauthStore.list(),
|
|
29
|
-
delete: (id) => oauthStore.delete(id),
|
|
30
|
-
async modify(id, fn) {
|
|
31
|
-
const next = await fn(await oauthStore.read(id));
|
|
32
|
-
if (next?.type === "api_key") {
|
|
33
|
-
if (next.key === "")
|
|
34
|
-
throw new Error("An API key is required.");
|
|
35
|
-
enteredKey = next.key;
|
|
36
|
-
enteredEnvironment = { ...next.env };
|
|
37
|
-
return next;
|
|
38
|
-
}
|
|
39
|
-
return oauthStore.modify(id, async () => next);
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
const models = modelsFor({ provider: "", model: "" }, store);
|
|
43
|
-
const providers = models.getProviders();
|
|
44
|
-
const prompt = createInterface({
|
|
45
|
-
input: options.input ?? process.stdin,
|
|
46
|
-
output,
|
|
47
|
-
});
|
|
48
|
-
const onInt = () => controller.abort(new ConfigurationCancelled("SIGINT"));
|
|
49
|
-
const onClose = () => controller.abort(new Error("Configuration input closed before setup completed."));
|
|
50
|
-
const closeOnAbort = () => prompt.close();
|
|
51
|
-
prompt.on("SIGINT", onInt);
|
|
52
|
-
prompt.on("close", onClose);
|
|
53
|
-
signal.addEventListener("abort", closeOnAbort, { once: true });
|
|
54
|
-
options.signal?.addEventListener("abort", forwardAbort, { once: true });
|
|
55
|
-
if (options.signal?.aborted)
|
|
56
|
-
forwardAbort();
|
|
57
|
-
async function question(message) {
|
|
58
|
-
signal.throwIfAborted();
|
|
59
|
-
return prompt.question(message, { signal });
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
signal.throwIfAborted();
|
|
63
|
-
output.write("0. Custom OpenAI-compatible provider\n");
|
|
64
|
-
providers.forEach((provider, index) => output.write(`${index + 1}. ${provider.name} (${provider.id})\n`));
|
|
65
|
-
const choice = Number(await question("Choose a provider: "));
|
|
66
|
-
if (choice === 0) {
|
|
67
|
-
const baseUrl = (await question("OpenAI-compatible base URL: "))
|
|
68
|
-
.trim()
|
|
69
|
-
.replace(/\/$/, "");
|
|
70
|
-
const model = (await question("Model id: ")).trim();
|
|
71
|
-
if (!baseUrl || !model)
|
|
72
|
-
throw new Error("A base URL and model id are required.");
|
|
73
|
-
const selection = {
|
|
74
|
-
provider: "custom",
|
|
75
|
-
model,
|
|
76
|
-
custom: { baseUrl },
|
|
77
|
-
};
|
|
78
|
-
const customModels = modelsFor(selection, store);
|
|
79
|
-
if (!(await customModels.checkAuth("custom", { signal })))
|
|
80
|
-
await customModels.login("custom", "api_key", interaction());
|
|
81
|
-
await save(selection);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
const chosen = providers[choice - 1];
|
|
85
|
-
if (!chosen)
|
|
86
|
-
throw new Error("Choose a listed provider.");
|
|
87
|
-
const available = models.getModels(chosen.id);
|
|
88
|
-
available.forEach((model, index) => output.write(`${index + 1}. ${model.name} (${model.id})\n`));
|
|
89
|
-
const model = available[Number(await question("Choose a model: ")) - 1];
|
|
90
|
-
if (!model)
|
|
91
|
-
throw new Error("Choose a listed model.");
|
|
92
|
-
if (!(await models.checkAuth(chosen.id, { signal }))) {
|
|
93
|
-
let method = chosen.auth.apiKey
|
|
94
|
-
? "api_key"
|
|
95
|
-
: "oauth";
|
|
96
|
-
if (chosen.auth.apiKey && chosen.auth.oauth) {
|
|
97
|
-
const answer = (await question("Choose authentication: 1. API key (default), 2. OAuth: ")).trim();
|
|
98
|
-
if (answer && !["1", "2"].includes(answer))
|
|
99
|
-
throw new Error("Choose authentication 1 or 2.");
|
|
100
|
-
if (answer === "2")
|
|
101
|
-
method = "oauth";
|
|
102
|
-
}
|
|
103
|
-
await models.login(chosen.id, method, interaction());
|
|
104
|
-
}
|
|
105
|
-
await save({ provider: chosen.id, model: model.id });
|
|
106
|
-
}
|
|
107
|
-
signal.throwIfAborted();
|
|
108
|
-
output.write("Provider configuration saved.\n");
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
throw signal.aborted ? signal.reason : error;
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
options.signal?.removeEventListener("abort", forwardAbort);
|
|
115
|
-
signal.removeEventListener("abort", closeOnAbort);
|
|
116
|
-
prompt.removeListener("SIGINT", onInt);
|
|
117
|
-
prompt.removeListener("close", onClose);
|
|
118
|
-
prompt.close();
|
|
119
|
-
}
|
|
120
|
-
function interaction() {
|
|
121
|
-
return {
|
|
122
|
-
signal,
|
|
123
|
-
prompt: async (item) => {
|
|
124
|
-
if (item.type !== "select")
|
|
125
|
-
return question(item.message + ": ");
|
|
126
|
-
item.options.forEach((option, index) => output.write(`${index + 1}. ${option.label}\n`));
|
|
127
|
-
const answer = (await question(item.message + " ")).trim();
|
|
128
|
-
const option = item.options.find((option) => option.id === answer) ??
|
|
129
|
-
item.options[Number(answer) - 1];
|
|
130
|
-
if (!option)
|
|
131
|
-
throw new Error("Choose a listed authentication option.");
|
|
132
|
-
return option.id;
|
|
133
|
-
},
|
|
134
|
-
notify: (event) => {
|
|
135
|
-
output.write(("url" in event
|
|
136
|
-
? event.url
|
|
137
|
-
: "verificationUri" in event
|
|
138
|
-
? event.verificationUri
|
|
139
|
-
: event.message) + "\n");
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
async function save(selection) {
|
|
144
|
-
signal.throwIfAborted();
|
|
145
|
-
await saveEnvironment(root, {
|
|
146
|
-
...enteredEnvironment,
|
|
147
|
-
MODEL_PROVIDER: selection.provider,
|
|
148
|
-
MODEL: selection.model,
|
|
149
|
-
MODEL_PROVIDER_BASE_URL: selection.custom?.baseUrl,
|
|
150
|
-
...(enteredKey === undefined
|
|
151
|
-
? {}
|
|
152
|
-
: { MODEL_PROVIDER_API_KEY: enteredKey }),
|
|
153
|
-
}, signal);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
File without changes
|