@wawjs/ai-host 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +77 -2
- package/dist/definitions.d.ts +151 -0
- package/dist/definitions.js +2 -0
- package/dist/definitions.js.map +1 -0
- package/dist/electron.d.ts +66 -0
- package/dist/electron.js +109 -0
- package/dist/electron.js.map +1 -0
- package/dist/host.d.ts +135 -0
- package/dist/host.js +519 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/electron/dist/plugin.mjs +2 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 IT Kamianets
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wawjs/ai-host
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turns the desktop app of an [IT Kamianets AI Framework](https://ai.itkamianets.com) (AI ITKP) agent app into
|
|
4
|
+
an agent host, like a small server on your own computer:
|
|
5
|
+
|
|
6
|
+
- installs agent CLIs from npm (from the [catalog](https://ai.itkamianets.com/agents.json) or by package
|
|
7
|
+
name) and runs them, each on its own port with its own token, data folder and environment;
|
|
8
|
+
- installs [Ollama](https://ollama.com), shows the models that fit this computer and downloads them.
|
|
9
|
+
|
|
10
|
+
It is a Capacitor plugin with an Electron implementation for
|
|
11
|
+
[`@capawesome/capacitor-electron`](https://capawesome.io): the work runs in Electron's main process, and the
|
|
12
|
+
web app calls it as `AiHost`. In a browser the plugin is not available and the app connects to agents by
|
|
13
|
+
address and token as before.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @wawjs/ai-host @capacitor/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { AiHost, hostAvailable } from '@wawjs/ai-host';
|
|
21
|
+
import { AgentClient } from '@wawjs/ai-client';
|
|
22
|
+
|
|
23
|
+
if (hostAvailable()) {
|
|
24
|
+
const { agents } = await AiHost.catalog();
|
|
25
|
+
const agent = await AiHost.install({ name: 'waw-code' });
|
|
26
|
+
await AiHost.setEnv({ name: 'waw-code', set: { WAW_CODE_PROVIDER: 'ollama' } });
|
|
27
|
+
const running = await AiHost.start({ name: 'waw-code' });
|
|
28
|
+
const client = new AgentClient({ url: running.url, token: running.token });
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`capacitor sync` (the app's `electron:sync`) finds the plugin in the app's dependencies; nothing else is
|
|
33
|
+
needed in `electron/main.ts`.
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
| Method | What it does |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `status()` | Node.js and npm on this computer, the data folder. |
|
|
40
|
+
| `catalog()` | The installable agents (`https://ai.itkamianets.com/agents.json`). |
|
|
41
|
+
| `agents()` | Installed agents: version, port, `url`, `token`, running, the variables set (names only). |
|
|
42
|
+
| `install({ name })`, `install({ package, name? })` | `npm install` into the host's folder; the catalog port, or the next free one. |
|
|
43
|
+
| `update({ name })` | The newest version; restarts it when it ran. |
|
|
44
|
+
| `uninstall({ name, purge? })` | Removes the package; sessions and projects stay unless `purge`. |
|
|
45
|
+
| `start`, `stop`, `setAutostart` | Runs the agent; autostart agents start with the app and stop when it quits. |
|
|
46
|
+
| `setEnv({ name, set?, unset? })` | Provider, model and API keys (`WAW_CODE_PROVIDER=ollama`, `ANTHROPIC_API_KEY=...`); restarts a running agent. Values never come back. |
|
|
47
|
+
| `logs({ name })` | The agent's latest output lines. |
|
|
48
|
+
| `ollama()` | Installed, running, version, downloaded models and the models that fit this computer. |
|
|
49
|
+
| `installOllama()`, `startOllama()` | winget, Homebrew or the official script, then `ollama serve`. Ask the user first. |
|
|
50
|
+
| `pullModel({ name })`, `removeModel({ name })` | Downloads in the background with `pullProgress` events. Ask the user first: models are large. |
|
|
51
|
+
|
|
52
|
+
Events: `agentsChanged` (an agent started, stopped or changed) and `pullProgress`.
|
|
53
|
+
|
|
54
|
+
## How agents run
|
|
55
|
+
|
|
56
|
+
Every agent is started with the [CLI Agent starter](https://github.com/IT-Kamianets/ai-constructor-cli)'s
|
|
57
|
+
flags:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
<agent> --serve --port <port> --home <data>/agents/<name>/home --workspaces ~/AI/<name>
|
|
61
|
+
--token-file <data>/agents/<name>/token --no-setup --cors capacitor-electron://localhost,...
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`<data>` is the app's user data folder plus `ai-host`. Agents listen on 127.0.0.1 only; the token stays on
|
|
65
|
+
this computer and goes only to the app. Installing needs npm (it comes with
|
|
66
|
+
[Node.js](https://nodejs.org)); running uses Node.js 24 when it is installed, else Electron's own Node.
|
|
67
|
+
|
|
68
|
+
For Node.js without Electron, `@wawjs/ai-host/node` exports the `Host` class that does the work.
|
|
69
|
+
|
|
70
|
+
## Development
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm test # builds, then installs a fake agent CLI, runs, updates and removes it
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
MIT
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/** An agent the framework catalog offers (https://ai.itkamianets.com/agents.json). */
|
|
2
|
+
export interface CatalogAgent {
|
|
3
|
+
name: string;
|
|
4
|
+
title: string;
|
|
5
|
+
/** The npm package with the agent's command. */
|
|
6
|
+
package: string;
|
|
7
|
+
/** The port the agent listens on by default. */
|
|
8
|
+
port: number;
|
|
9
|
+
description: string;
|
|
10
|
+
/** Prefix of the agent's environment variables, such as WAW_CODE (WAW_CODE_PROVIDER, WAW_CODE_MODEL). */
|
|
11
|
+
envPrefix?: string;
|
|
12
|
+
/** Variables the agent needs, such as ANTHROPIC_API_KEY. */
|
|
13
|
+
env?: string[];
|
|
14
|
+
}
|
|
15
|
+
/** An agent installed on this computer by the host. */
|
|
16
|
+
export interface HostAgent {
|
|
17
|
+
name: string;
|
|
18
|
+
title: string;
|
|
19
|
+
package: string;
|
|
20
|
+
version: string;
|
|
21
|
+
port: number;
|
|
22
|
+
/** Its API address on this computer, for AgentClient. */
|
|
23
|
+
url: string;
|
|
24
|
+
/** Its API token. It stays on this computer: only the app on this computer receives it. */
|
|
25
|
+
token: string;
|
|
26
|
+
running: boolean;
|
|
27
|
+
/** Started with the app. */
|
|
28
|
+
autostart: boolean;
|
|
29
|
+
envPrefix?: string;
|
|
30
|
+
/** Names of the variables set for it (never the values). */
|
|
31
|
+
envSet: string[];
|
|
32
|
+
/** Variables the catalog says it needs. */
|
|
33
|
+
envNeeded: string[];
|
|
34
|
+
/** Where its projects get their folders. */
|
|
35
|
+
workspaces: string;
|
|
36
|
+
/** Why it stopped, when it stopped on its own. */
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface HostStatus {
|
|
40
|
+
/** Node.js runs the agents: the one on this computer, else the app's own (Electron as Node). */
|
|
41
|
+
node: {
|
|
42
|
+
found: boolean;
|
|
43
|
+
version?: string;
|
|
44
|
+
builtIn: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** npm installs the agents; it comes with Node.js. */
|
|
47
|
+
npm: {
|
|
48
|
+
found: boolean;
|
|
49
|
+
version?: string;
|
|
50
|
+
};
|
|
51
|
+
/** The host's data folder. */
|
|
52
|
+
root: string;
|
|
53
|
+
platform: string;
|
|
54
|
+
}
|
|
55
|
+
export interface OllamaModel {
|
|
56
|
+
id: string;
|
|
57
|
+
sizeBytes: number;
|
|
58
|
+
}
|
|
59
|
+
export interface RecommendedModel {
|
|
60
|
+
name: string;
|
|
61
|
+
sizeBytes: number;
|
|
62
|
+
runsOn: 'gpu' | 'unified' | 'cpu';
|
|
63
|
+
reason: string;
|
|
64
|
+
downloaded: boolean;
|
|
65
|
+
}
|
|
66
|
+
export interface OllamaState {
|
|
67
|
+
installed: boolean;
|
|
68
|
+
running: boolean;
|
|
69
|
+
version?: string;
|
|
70
|
+
host: string;
|
|
71
|
+
/** The command that installs it on this OS, to show before installing. */
|
|
72
|
+
installCommand: string;
|
|
73
|
+
models: OllamaModel[];
|
|
74
|
+
/** Models that fit this computer, best first. */
|
|
75
|
+
recommended: RecommendedModel[];
|
|
76
|
+
}
|
|
77
|
+
export interface PullProgressEvent {
|
|
78
|
+
name: string;
|
|
79
|
+
status: string;
|
|
80
|
+
percent: number;
|
|
81
|
+
completedBytes: number;
|
|
82
|
+
totalBytes: number;
|
|
83
|
+
done?: boolean;
|
|
84
|
+
error?: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The host's API, as the web app sees it. Every method runs in the desktop app's main process; in a
|
|
88
|
+
* browser the plugin is not available (check hostAvailable()).
|
|
89
|
+
*/
|
|
90
|
+
export interface AiHostPlugin {
|
|
91
|
+
status(): Promise<HostStatus>;
|
|
92
|
+
catalog(): Promise<{
|
|
93
|
+
agents: CatalogAgent[];
|
|
94
|
+
}>;
|
|
95
|
+
agents(): Promise<{
|
|
96
|
+
agents: HostAgent[];
|
|
97
|
+
}>;
|
|
98
|
+
/** Installs a catalog agent by name, or any agent by npm package (with a name for it). */
|
|
99
|
+
install(options: {
|
|
100
|
+
name?: string;
|
|
101
|
+
package?: string;
|
|
102
|
+
}): Promise<HostAgent>;
|
|
103
|
+
/** Installs the newest version and restarts the agent when it ran. */
|
|
104
|
+
update(options: {
|
|
105
|
+
name: string;
|
|
106
|
+
}): Promise<HostAgent>;
|
|
107
|
+
/** Removes the agent; its sessions and projects stay unless purge is true. */
|
|
108
|
+
uninstall(options: {
|
|
109
|
+
name: string;
|
|
110
|
+
purge?: boolean;
|
|
111
|
+
}): Promise<void>;
|
|
112
|
+
start(options: {
|
|
113
|
+
name: string;
|
|
114
|
+
}): Promise<HostAgent>;
|
|
115
|
+
stop(options: {
|
|
116
|
+
name: string;
|
|
117
|
+
}): Promise<HostAgent>;
|
|
118
|
+
setAutostart(options: {
|
|
119
|
+
name: string;
|
|
120
|
+
autostart: boolean;
|
|
121
|
+
}): Promise<HostAgent>;
|
|
122
|
+
/** Sets or removes environment variables (provider, model, API keys) and restarts a running agent. */
|
|
123
|
+
setEnv(options: {
|
|
124
|
+
name: string;
|
|
125
|
+
set?: Record<string, string>;
|
|
126
|
+
unset?: string[];
|
|
127
|
+
}): Promise<HostAgent>;
|
|
128
|
+
/** The agent's latest output lines. */
|
|
129
|
+
logs(options: {
|
|
130
|
+
name: string;
|
|
131
|
+
}): Promise<{
|
|
132
|
+
lines: string[];
|
|
133
|
+
}>;
|
|
134
|
+
ollama(): Promise<OllamaState>;
|
|
135
|
+
/** Installs Ollama with the OS package manager. Ask the user first. */
|
|
136
|
+
installOllama(): Promise<OllamaState>;
|
|
137
|
+
startOllama(): Promise<OllamaState>;
|
|
138
|
+
/** Starts a model download; progress arrives as pullProgress events. Ask the user first: models are large. */
|
|
139
|
+
pullModel(options: {
|
|
140
|
+
name: string;
|
|
141
|
+
}): Promise<void>;
|
|
142
|
+
removeModel(options: {
|
|
143
|
+
name: string;
|
|
144
|
+
}): Promise<OllamaState>;
|
|
145
|
+
addListener(event: 'pullProgress', listener: (event: PullProgressEvent) => void): Promise<{
|
|
146
|
+
remove: () => Promise<void>;
|
|
147
|
+
}>;
|
|
148
|
+
addListener(event: 'agentsChanged', listener: () => void): Promise<{
|
|
149
|
+
remove: () => Promise<void>;
|
|
150
|
+
}>;
|
|
151
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../src/definitions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
interface PluginContext {
|
|
2
|
+
config: unknown;
|
|
3
|
+
notifyListeners: (eventName: string, data?: unknown, options?: {
|
|
4
|
+
retain?: boolean;
|
|
5
|
+
}) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare class AiHost {
|
|
8
|
+
private readonly context;
|
|
9
|
+
static __capacitorElectronPlugin: {
|
|
10
|
+
name: string;
|
|
11
|
+
methods: string[];
|
|
12
|
+
};
|
|
13
|
+
private readonly host;
|
|
14
|
+
constructor(context: PluginContext);
|
|
15
|
+
/** Starts the autostart agents in the background, so the window does not wait for them. */
|
|
16
|
+
load(): Promise<void>;
|
|
17
|
+
status(): Promise<import("./definitions.js").HostStatus>;
|
|
18
|
+
catalog(): Promise<{
|
|
19
|
+
agents: import("./definitions.js").CatalogAgent[];
|
|
20
|
+
}>;
|
|
21
|
+
agents(): Promise<{
|
|
22
|
+
agents: import("./definitions.js").HostAgent[];
|
|
23
|
+
}>;
|
|
24
|
+
install(options: {
|
|
25
|
+
name?: string;
|
|
26
|
+
package?: string;
|
|
27
|
+
}): Promise<import("./definitions.js").HostAgent>;
|
|
28
|
+
update(options: {
|
|
29
|
+
name: string;
|
|
30
|
+
}): Promise<import("./definitions.js").HostAgent>;
|
|
31
|
+
uninstall(options: {
|
|
32
|
+
name: string;
|
|
33
|
+
purge?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
start(options: {
|
|
36
|
+
name: string;
|
|
37
|
+
}): Promise<import("./definitions.js").HostAgent>;
|
|
38
|
+
stop(options: {
|
|
39
|
+
name: string;
|
|
40
|
+
}): Promise<import("./definitions.js").HostAgent>;
|
|
41
|
+
setAutostart(options: {
|
|
42
|
+
name: string;
|
|
43
|
+
autostart: boolean;
|
|
44
|
+
}): Promise<import("./definitions.js").HostAgent>;
|
|
45
|
+
setEnv(options: {
|
|
46
|
+
name: string;
|
|
47
|
+
set?: Record<string, string>;
|
|
48
|
+
unset?: string[];
|
|
49
|
+
}): Promise<import("./definitions.js").HostAgent>;
|
|
50
|
+
logs(options: {
|
|
51
|
+
name: string;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
lines: string[];
|
|
54
|
+
}>;
|
|
55
|
+
ollama(): Promise<import("./definitions.js").OllamaState>;
|
|
56
|
+
installOllama(): Promise<import("./definitions.js").OllamaState>;
|
|
57
|
+
startOllama(): Promise<import("./definitions.js").OllamaState>;
|
|
58
|
+
/** Returns at once; progress and the end arrive as pullProgress events. */
|
|
59
|
+
pullModel(options: {
|
|
60
|
+
name: string;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
removeModel(options: {
|
|
63
|
+
name: string;
|
|
64
|
+
}): Promise<import("./definitions.js").OllamaState>;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
package/dist/electron.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// The Electron implementation of the AiHost plugin, loaded by @capawesome/capacitor-electron in the
|
|
2
|
+
// main process (electron/dist/plugin.mjs re-exports it). Each method takes one options object, like
|
|
3
|
+
// every Capacitor plugin method.
|
|
4
|
+
import electron from 'electron';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { Host } from './host.js';
|
|
7
|
+
/** The desktop app's own origin and, in development, the dev server's, so agents answer the app. */
|
|
8
|
+
function appOrigins() {
|
|
9
|
+
const origins = ['capacitor-electron://localhost', 'http://localhost:4200'];
|
|
10
|
+
const dev = process.env['CAPACITOR_ELECTRON_DEV_SERVER_URL'] ?? process.env['CAP_DEV_SERVER_URL'];
|
|
11
|
+
if (dev) {
|
|
12
|
+
try {
|
|
13
|
+
origins.push(new URL(dev).origin);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// Not a URL: ignored.
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return [...new Set(origins)];
|
|
20
|
+
}
|
|
21
|
+
export class AiHost {
|
|
22
|
+
context;
|
|
23
|
+
static __capacitorElectronPlugin = {
|
|
24
|
+
name: 'AiHost',
|
|
25
|
+
methods: [
|
|
26
|
+
'status',
|
|
27
|
+
'catalog',
|
|
28
|
+
'agents',
|
|
29
|
+
'install',
|
|
30
|
+
'update',
|
|
31
|
+
'uninstall',
|
|
32
|
+
'start',
|
|
33
|
+
'stop',
|
|
34
|
+
'setAutostart',
|
|
35
|
+
'setEnv',
|
|
36
|
+
'logs',
|
|
37
|
+
'ollama',
|
|
38
|
+
'installOllama',
|
|
39
|
+
'startOllama',
|
|
40
|
+
'pullModel',
|
|
41
|
+
'removeModel',
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
host;
|
|
45
|
+
constructor(context) {
|
|
46
|
+
this.context = context;
|
|
47
|
+
const { app } = electron;
|
|
48
|
+
this.host = new Host({
|
|
49
|
+
root: join(app.getPath('userData'), 'ai-host'),
|
|
50
|
+
corsOrigins: appOrigins(),
|
|
51
|
+
onChange: () => this.context.notifyListeners('agentsChanged', {}),
|
|
52
|
+
});
|
|
53
|
+
app.on('before-quit', () => this.host.stopAll());
|
|
54
|
+
}
|
|
55
|
+
/** Starts the autostart agents in the background, so the window does not wait for them. */
|
|
56
|
+
async load() {
|
|
57
|
+
void this.host.startAutostart();
|
|
58
|
+
}
|
|
59
|
+
status() {
|
|
60
|
+
return this.host.status();
|
|
61
|
+
}
|
|
62
|
+
async catalog() {
|
|
63
|
+
return { agents: await this.host.catalog() };
|
|
64
|
+
}
|
|
65
|
+
async agents() {
|
|
66
|
+
return { agents: await this.host.list() };
|
|
67
|
+
}
|
|
68
|
+
install(options) {
|
|
69
|
+
return this.host.add(options ?? {});
|
|
70
|
+
}
|
|
71
|
+
update(options) {
|
|
72
|
+
return this.host.update(options.name);
|
|
73
|
+
}
|
|
74
|
+
async uninstall(options) {
|
|
75
|
+
await this.host.remove(options.name, options.purge === true);
|
|
76
|
+
}
|
|
77
|
+
start(options) {
|
|
78
|
+
return this.host.start(options.name);
|
|
79
|
+
}
|
|
80
|
+
stop(options) {
|
|
81
|
+
return this.host.stop(options.name);
|
|
82
|
+
}
|
|
83
|
+
setAutostart(options) {
|
|
84
|
+
return this.host.setAutostart(options.name, options.autostart === true);
|
|
85
|
+
}
|
|
86
|
+
setEnv(options) {
|
|
87
|
+
return this.host.setEnv(options.name, options.set ?? {}, options.unset ?? []);
|
|
88
|
+
}
|
|
89
|
+
async logs(options) {
|
|
90
|
+
return { lines: this.host.logLines(options.name) };
|
|
91
|
+
}
|
|
92
|
+
ollama() {
|
|
93
|
+
return this.host.ollama();
|
|
94
|
+
}
|
|
95
|
+
installOllama() {
|
|
96
|
+
return this.host.installOllama();
|
|
97
|
+
}
|
|
98
|
+
startOllama() {
|
|
99
|
+
return this.host.startOllama();
|
|
100
|
+
}
|
|
101
|
+
/** Returns at once; progress and the end arrive as pullProgress events. */
|
|
102
|
+
async pullModel(options) {
|
|
103
|
+
void this.host.pullModel(options.name, (event) => this.context.notifyListeners('pullProgress', event));
|
|
104
|
+
}
|
|
105
|
+
removeModel(options) {
|
|
106
|
+
return this.host.removeModel(options.name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=electron.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"electron.js","sourceRoot":"","sources":["../src/electron.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,oGAAoG;AACpG,iCAAiC;AACjC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAOjC,oGAAoG;AACpG,SAAS,UAAU;IAClB,MAAM,OAAO,GAAG,CAAC,gCAAgC,EAAE,uBAAuB,CAAC,CAAC;IAC5E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAClG,IAAI,GAAG,EAAE,CAAC;QACT,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACR,sBAAsB;QACvB,CAAC;IACF,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,OAAO,MAAM;IAyBW,OAAO;IAxBpC,MAAM,CAAC,yBAAyB,GAAG;QAClC,IAAI,EAAE,QAAQ;QACd,OAAO,EAAE;YACR,QAAQ;YACR,SAAS;YACT,QAAQ;YACR,SAAS;YACT,QAAQ;YACR,WAAW;YACX,OAAO;YACP,MAAM;YACN,cAAc;YACd,QAAQ;YACR,MAAM;YACN,QAAQ;YACR,eAAe;YACf,aAAa;YACb,WAAW;YACX,aAAa;SACb;KACD,CAAC;IAEe,IAAI,CAAO;IAE5B,YAA6B,OAAsB;uBAAtB,OAAO;QACnC,MAAM,EAAE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OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;CACD"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import type { CatalogAgent, HostAgent, HostStatus, OllamaState, PullProgressEvent } from './definitions.js';
|
|
3
|
+
export type * from './definitions.js';
|
|
4
|
+
/** The framework catalog of installable agents. */
|
|
5
|
+
export declare const CATALOG_URL = "https://ai.itkamianets.com/agents.json";
|
|
6
|
+
/** Runs a command and resolves with its output, or null when it is missing or fails. */
|
|
7
|
+
export type Runner = (file: string, args: string[], options?: {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
ok: boolean;
|
|
12
|
+
output: string;
|
|
13
|
+
}>;
|
|
14
|
+
export interface HostOptions {
|
|
15
|
+
/** The host's data folder: installed packages, agent homes, tokens and settings. */
|
|
16
|
+
root: string;
|
|
17
|
+
/** Where agents' projects get their folders: <workspaces>/<agent>. Default ~/AI. */
|
|
18
|
+
workspaces?: string;
|
|
19
|
+
/** Origins of the app that calls the agents (the desktop app's own origin, the dev server). */
|
|
20
|
+
corsOrigins?: string[];
|
|
21
|
+
catalogUrl?: string;
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
run?: Runner;
|
|
24
|
+
spawnProcess?: typeof spawn;
|
|
25
|
+
/** Installs a package into a folder. Default: npm install --prefix. */
|
|
26
|
+
installPackage?: (packageName: string, prefix: string) => Promise<void>;
|
|
27
|
+
/** Called when an agent starts, stops or changes. */
|
|
28
|
+
onChange?: () => void;
|
|
29
|
+
/** Ollama functions; default @wawjs/ai-ollama (loaded when first used). */
|
|
30
|
+
ollama?: OllamaApi;
|
|
31
|
+
}
|
|
32
|
+
export interface OllamaApi {
|
|
33
|
+
detect(): Promise<{
|
|
34
|
+
installed: boolean;
|
|
35
|
+
running: boolean;
|
|
36
|
+
version?: string;
|
|
37
|
+
host: string;
|
|
38
|
+
}>;
|
|
39
|
+
installCommand(): string;
|
|
40
|
+
install(): Promise<void>;
|
|
41
|
+
start(): Promise<void>;
|
|
42
|
+
list(): Promise<Array<{
|
|
43
|
+
name: string;
|
|
44
|
+
sizeBytes: number;
|
|
45
|
+
}>>;
|
|
46
|
+
pull(name: string, onProgress: (p: {
|
|
47
|
+
status: string;
|
|
48
|
+
percent: number;
|
|
49
|
+
completedBytes: number;
|
|
50
|
+
totalBytes: number;
|
|
51
|
+
}) => void): Promise<void>;
|
|
52
|
+
remove(name: string): Promise<void>;
|
|
53
|
+
recommend(): Promise<Array<{
|
|
54
|
+
name: string;
|
|
55
|
+
sizeBytes: number;
|
|
56
|
+
runsOn: 'gpu' | 'unified' | 'cpu';
|
|
57
|
+
reason: string;
|
|
58
|
+
}>>;
|
|
59
|
+
}
|
|
60
|
+
/** An error the app can show as it is. */
|
|
61
|
+
export declare class HostError extends Error {
|
|
62
|
+
readonly code: 'bad_request' | 'not_found' | 'node_missing' | 'npm_missing' | 'install_failed' | 'start_failed';
|
|
63
|
+
readonly name = "HostError";
|
|
64
|
+
constructor(code: 'bad_request' | 'not_found' | 'node_missing' | 'npm_missing' | 'install_failed' | 'start_failed', message: string);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Installs agent CLIs from npm and runs them on this computer, each with its own port, token, data
|
|
68
|
+
* folder and environment, the way the CLI Agent starter's flags expect:
|
|
69
|
+
* `<agent> --serve --port N --home H --workspaces W --token-file T --no-setup --cors ORIGINS`.
|
|
70
|
+
*/
|
|
71
|
+
export declare class Host {
|
|
72
|
+
private readonly options;
|
|
73
|
+
readonly root: string;
|
|
74
|
+
readonly workspaces: string;
|
|
75
|
+
private readonly run;
|
|
76
|
+
private readonly fetchImpl;
|
|
77
|
+
private readonly running;
|
|
78
|
+
private readonly logs;
|
|
79
|
+
private readonly errors;
|
|
80
|
+
private readonly pulls;
|
|
81
|
+
private nodeCommand?;
|
|
82
|
+
private stateCache?;
|
|
83
|
+
private ollamaApi?;
|
|
84
|
+
constructor(options: HostOptions);
|
|
85
|
+
private agentDir;
|
|
86
|
+
private packageDir;
|
|
87
|
+
private homeDir;
|
|
88
|
+
private tokenFile;
|
|
89
|
+
private envFile;
|
|
90
|
+
private state;
|
|
91
|
+
private save;
|
|
92
|
+
private record;
|
|
93
|
+
private readEnv;
|
|
94
|
+
private token;
|
|
95
|
+
private view;
|
|
96
|
+
private changed;
|
|
97
|
+
/** Node.js on this computer when it is 24 or newer, else Electron's own Node (ELECTRON_RUN_AS_NODE). */
|
|
98
|
+
node(): Promise<{
|
|
99
|
+
file: string;
|
|
100
|
+
env: Record<string, string>;
|
|
101
|
+
version: string;
|
|
102
|
+
builtIn: boolean;
|
|
103
|
+
}>;
|
|
104
|
+
status(): Promise<HostStatus>;
|
|
105
|
+
private install;
|
|
106
|
+
catalog(): Promise<CatalogAgent[]>;
|
|
107
|
+
list(): Promise<HostAgent[]>;
|
|
108
|
+
get(name: string): Promise<HostAgent>;
|
|
109
|
+
/** Installs a catalog agent by name, or an npm package (named after the package unless a name is given). */
|
|
110
|
+
add(target: {
|
|
111
|
+
name?: string;
|
|
112
|
+
package?: string;
|
|
113
|
+
}): Promise<HostAgent>;
|
|
114
|
+
update(name: string): Promise<HostAgent>;
|
|
115
|
+
remove(name: string, purge?: boolean): Promise<void>;
|
|
116
|
+
setAutostart(name: string, autostart: boolean): Promise<HostAgent>;
|
|
117
|
+
setEnv(name: string, set?: Record<string, string>, unset?: string[]): Promise<HostAgent>;
|
|
118
|
+
logLines(name: string): string[];
|
|
119
|
+
private packageMeta;
|
|
120
|
+
start(name: string): Promise<HostAgent>;
|
|
121
|
+
stop(name: string): Promise<HostAgent>;
|
|
122
|
+
/** Starts every agent marked autostart; failures are kept as the agent's error. */
|
|
123
|
+
startAutostart(): Promise<void>;
|
|
124
|
+
/** Stops every agent at once, for the app's exit. */
|
|
125
|
+
stopAll(): void;
|
|
126
|
+
private ollamaFns;
|
|
127
|
+
ollama(): Promise<OllamaState>;
|
|
128
|
+
installOllama(): Promise<OllamaState>;
|
|
129
|
+
startOllama(): Promise<OllamaState>;
|
|
130
|
+
/** Downloads a model in the background, reporting progress; resolves when it finished or failed. */
|
|
131
|
+
pullModel(name: string, onProgress: (event: PullProgressEvent) => void): Promise<void>;
|
|
132
|
+
removeModel(name: string): Promise<OllamaState>;
|
|
133
|
+
}
|
|
134
|
+
/** The wanted port when nothing uses it, else the next free one. */
|
|
135
|
+
export declare function freePort(wanted: number, taken?: Set<number>): Promise<number>;
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { createServer } from 'node:net';
|
|
5
|
+
import { homedir } from 'node:os';
|
|
6
|
+
import { dirname, join, resolve } from 'node:path';
|
|
7
|
+
/** The framework catalog of installable agents. */
|
|
8
|
+
export const CATALOG_URL = 'https://ai.itkamianets.com/agents.json';
|
|
9
|
+
const PACKAGE_NAME = /^(@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
|
|
10
|
+
const AGENT_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
11
|
+
const ENV_NAME = /^[A-Z_][A-Z0-9_]*$/;
|
|
12
|
+
const LOG_LINES = 300;
|
|
13
|
+
const defaultRunner = (file, args, options = {}) => new Promise((done) => {
|
|
14
|
+
execFile(file, args,
|
|
15
|
+
// npm is npm.cmd on Windows, which needs a shell. Arguments are checked before they get here.
|
|
16
|
+
{ cwd: options.cwd, timeout: options.timeoutMs ?? 15_000, windowsHide: true, shell: process.platform === 'win32', maxBuffer: 16 * 1024 * 1024 }, (error, stdout, stderr) => done({ ok: !error, output: `${stdout ?? ''}${stderr ?? ''}` }));
|
|
17
|
+
});
|
|
18
|
+
/** An error the app can show as it is. */
|
|
19
|
+
export class HostError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
name = 'HostError';
|
|
22
|
+
constructor(code, message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.code = code;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Installs agent CLIs from npm and runs them on this computer, each with its own port, token, data
|
|
29
|
+
* folder and environment, the way the CLI Agent starter's flags expect:
|
|
30
|
+
* `<agent> --serve --port N --home H --workspaces W --token-file T --no-setup --cors ORIGINS`.
|
|
31
|
+
*/
|
|
32
|
+
export class Host {
|
|
33
|
+
options;
|
|
34
|
+
root;
|
|
35
|
+
workspaces;
|
|
36
|
+
run;
|
|
37
|
+
fetchImpl;
|
|
38
|
+
running = new Map();
|
|
39
|
+
logs = new Map();
|
|
40
|
+
errors = new Map();
|
|
41
|
+
pulls = new Set();
|
|
42
|
+
nodeCommand;
|
|
43
|
+
stateCache;
|
|
44
|
+
ollamaApi;
|
|
45
|
+
constructor(options) {
|
|
46
|
+
this.options = options;
|
|
47
|
+
this.root = resolve(options.root);
|
|
48
|
+
this.workspaces = resolve(options.workspaces ?? join(homedir(), 'AI'));
|
|
49
|
+
this.run = options.run ?? defaultRunner;
|
|
50
|
+
this.fetchImpl = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
51
|
+
}
|
|
52
|
+
// Paths
|
|
53
|
+
agentDir(name) {
|
|
54
|
+
return join(this.root, 'agents', name);
|
|
55
|
+
}
|
|
56
|
+
packageDir(name) {
|
|
57
|
+
return join(this.agentDir(name), 'package');
|
|
58
|
+
}
|
|
59
|
+
homeDir(name) {
|
|
60
|
+
return join(this.agentDir(name), 'home');
|
|
61
|
+
}
|
|
62
|
+
tokenFile(name) {
|
|
63
|
+
return join(this.agentDir(name), 'token');
|
|
64
|
+
}
|
|
65
|
+
envFile(name) {
|
|
66
|
+
return join(this.agentDir(name), 'env.json');
|
|
67
|
+
}
|
|
68
|
+
// State
|
|
69
|
+
async state() {
|
|
70
|
+
if (this.stateCache)
|
|
71
|
+
return this.stateCache;
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(await readFile(join(this.root, 'host.json'), 'utf8'));
|
|
74
|
+
this.stateCache = { agents: parsed.agents ?? {} };
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
this.stateCache = { agents: {} };
|
|
78
|
+
}
|
|
79
|
+
return this.stateCache;
|
|
80
|
+
}
|
|
81
|
+
async save() {
|
|
82
|
+
const state = await this.state();
|
|
83
|
+
await writeJson(join(this.root, 'host.json'), state);
|
|
84
|
+
}
|
|
85
|
+
async record(name) {
|
|
86
|
+
const record = (await this.state()).agents[name];
|
|
87
|
+
if (!record)
|
|
88
|
+
throw new HostError('not_found', `No agent ${name} is installed.`);
|
|
89
|
+
return record;
|
|
90
|
+
}
|
|
91
|
+
async readEnv(name) {
|
|
92
|
+
try {
|
|
93
|
+
return JSON.parse(await readFile(this.envFile(name), 'utf8'));
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async token(name) {
|
|
100
|
+
try {
|
|
101
|
+
const saved = (await readFile(this.tokenFile(name), 'utf8')).trim();
|
|
102
|
+
if (saved.length >= 32)
|
|
103
|
+
return saved;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// Made below.
|
|
107
|
+
}
|
|
108
|
+
const token = randomBytes(32).toString('base64url');
|
|
109
|
+
await mkdir(this.agentDir(name), { recursive: true });
|
|
110
|
+
await writeFile(this.tokenFile(name), `${token}\n`, { mode: 0o600 });
|
|
111
|
+
await chmod(this.tokenFile(name), 0o600).catch(() => undefined);
|
|
112
|
+
return token;
|
|
113
|
+
}
|
|
114
|
+
async view(record) {
|
|
115
|
+
const env = await this.readEnv(record.name);
|
|
116
|
+
const error = this.errors.get(record.name);
|
|
117
|
+
return {
|
|
118
|
+
name: record.name,
|
|
119
|
+
title: record.title,
|
|
120
|
+
package: record.package,
|
|
121
|
+
version: record.version,
|
|
122
|
+
port: record.port,
|
|
123
|
+
url: `http://127.0.0.1:${record.port}`,
|
|
124
|
+
token: await this.token(record.name),
|
|
125
|
+
running: this.running.has(record.name),
|
|
126
|
+
autostart: record.autostart,
|
|
127
|
+
...(record.envPrefix ? { envPrefix: record.envPrefix } : {}),
|
|
128
|
+
envSet: Object.keys(env).sort(),
|
|
129
|
+
envNeeded: record.envNeeded,
|
|
130
|
+
workspaces: join(this.workspaces, record.name),
|
|
131
|
+
...(error ? { error } : {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
changed() {
|
|
135
|
+
this.options.onChange?.();
|
|
136
|
+
}
|
|
137
|
+
// Node.js and npm
|
|
138
|
+
/** Node.js on this computer when it is 24 or newer, else Electron's own Node (ELECTRON_RUN_AS_NODE). */
|
|
139
|
+
async node() {
|
|
140
|
+
if (this.nodeCommand)
|
|
141
|
+
return this.nodeCommand;
|
|
142
|
+
const found = await this.run('node', ['--version']);
|
|
143
|
+
const version = found.ok ? found.output.trim().replace(/^v/, '') : '';
|
|
144
|
+
if (found.ok && Number(version.split('.')[0]) >= 24) {
|
|
145
|
+
this.nodeCommand = { file: 'node', env: {}, version, builtIn: false };
|
|
146
|
+
}
|
|
147
|
+
else if (process.versions.electron) {
|
|
148
|
+
this.nodeCommand = { file: process.execPath, env: { ELECTRON_RUN_AS_NODE: '1' }, version: process.versions.node, builtIn: true };
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
throw new HostError('node_missing', 'Agents need Node.js 24 or newer. Install it from https://nodejs.org.');
|
|
152
|
+
}
|
|
153
|
+
return this.nodeCommand;
|
|
154
|
+
}
|
|
155
|
+
async status() {
|
|
156
|
+
let node = { found: false, builtIn: false };
|
|
157
|
+
try {
|
|
158
|
+
const n = await this.node();
|
|
159
|
+
node = { found: true, version: n.version, builtIn: n.builtIn };
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Not found: reported as such.
|
|
163
|
+
}
|
|
164
|
+
const npm = await this.run('npm', ['--version']);
|
|
165
|
+
return {
|
|
166
|
+
node,
|
|
167
|
+
npm: npm.ok ? { found: true, version: npm.output.trim() } : { found: false },
|
|
168
|
+
root: this.root,
|
|
169
|
+
platform: process.platform,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async install(packageName, prefix) {
|
|
173
|
+
if (this.options.installPackage)
|
|
174
|
+
return this.options.installPackage(packageName, prefix);
|
|
175
|
+
const npm = await this.run('npm', ['--version']);
|
|
176
|
+
if (!npm.ok)
|
|
177
|
+
throw new HostError('npm_missing', 'Installing agents needs npm, which comes with Node.js. Install Node.js 24 from https://nodejs.org, then try again.');
|
|
178
|
+
await mkdir(prefix, { recursive: true });
|
|
179
|
+
const result = await this.run('npm', ['install', '--prefix', prefix, '--omit=dev', '--no-audit', '--no-fund', `${packageName}@latest`], { timeoutMs: 10 * 60_000 });
|
|
180
|
+
if (!result.ok)
|
|
181
|
+
throw new HostError('install_failed', `npm could not install ${packageName}:\n${result.output.trim().split('\n').slice(-8).join('\n')}`);
|
|
182
|
+
}
|
|
183
|
+
// Catalog
|
|
184
|
+
async catalog() {
|
|
185
|
+
const response = await this.fetchImpl(this.options.catalogUrl ?? CATALOG_URL);
|
|
186
|
+
if (!response.ok)
|
|
187
|
+
throw new Error(`The agent catalog answered ${response.status}.`);
|
|
188
|
+
const body = (await response.json());
|
|
189
|
+
return (body.agents ?? []).filter((a) => AGENT_NAME.test(a.name) && PACKAGE_NAME.test(a.package));
|
|
190
|
+
}
|
|
191
|
+
// Agents
|
|
192
|
+
async list() {
|
|
193
|
+
const state = await this.state();
|
|
194
|
+
return Promise.all(Object.values(state.agents).map((r) => this.view(r)));
|
|
195
|
+
}
|
|
196
|
+
async get(name) {
|
|
197
|
+
return this.view(await this.record(name));
|
|
198
|
+
}
|
|
199
|
+
/** Installs a catalog agent by name, or an npm package (named after the package unless a name is given). */
|
|
200
|
+
async add(target) {
|
|
201
|
+
let entry;
|
|
202
|
+
if (target.package) {
|
|
203
|
+
if (!PACKAGE_NAME.test(target.package))
|
|
204
|
+
throw new HostError('bad_request', `${target.package} is not an npm package name.`);
|
|
205
|
+
entry = (await this.catalog().catch(() => [])).find((a) => a.package === target.package);
|
|
206
|
+
}
|
|
207
|
+
else if (target.name) {
|
|
208
|
+
entry = (await this.catalog()).find((a) => a.name === target.name);
|
|
209
|
+
if (!entry)
|
|
210
|
+
throw new HostError('not_found', `The catalog has no agent ${target.name}. Install it by npm package instead.`);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
throw new HostError('bad_request', 'Give a catalog name or an npm package.');
|
|
214
|
+
}
|
|
215
|
+
const packageName = target.package ?? entry.package;
|
|
216
|
+
const name = target.name ?? entry?.name ?? packageName.split('/').pop();
|
|
217
|
+
if (!AGENT_NAME.test(name))
|
|
218
|
+
throw new HostError('bad_request', `${name} cannot be an agent name: use lowercase letters, digits and dashes.`);
|
|
219
|
+
const state = await this.state();
|
|
220
|
+
if (state.agents[name])
|
|
221
|
+
throw new HostError('bad_request', `${name} is already installed.`);
|
|
222
|
+
await this.install(packageName, this.packageDir(name));
|
|
223
|
+
const meta = await this.packageMeta(name, packageName);
|
|
224
|
+
const taken = new Set(Object.values(state.agents).map((a) => a.port));
|
|
225
|
+
const record = {
|
|
226
|
+
name,
|
|
227
|
+
title: entry?.title ?? name,
|
|
228
|
+
package: packageName,
|
|
229
|
+
version: meta.version,
|
|
230
|
+
port: await freePort(entry?.port ?? 53100, taken),
|
|
231
|
+
autostart: true,
|
|
232
|
+
...(entry?.envPrefix ? { envPrefix: entry.envPrefix } : {}),
|
|
233
|
+
envNeeded: entry?.env ?? [],
|
|
234
|
+
};
|
|
235
|
+
state.agents[name] = record;
|
|
236
|
+
await this.save();
|
|
237
|
+
await this.token(name);
|
|
238
|
+
await mkdir(join(this.workspaces, name), { recursive: true });
|
|
239
|
+
this.changed();
|
|
240
|
+
return this.view(record);
|
|
241
|
+
}
|
|
242
|
+
async update(name) {
|
|
243
|
+
const record = await this.record(name);
|
|
244
|
+
const wasRunning = this.running.has(name);
|
|
245
|
+
if (wasRunning)
|
|
246
|
+
await this.stop(name);
|
|
247
|
+
await this.install(record.package, this.packageDir(name));
|
|
248
|
+
record.version = (await this.packageMeta(name, record.package)).version;
|
|
249
|
+
await this.save();
|
|
250
|
+
if (wasRunning)
|
|
251
|
+
return this.start(name);
|
|
252
|
+
this.changed();
|
|
253
|
+
return this.view(record);
|
|
254
|
+
}
|
|
255
|
+
async remove(name, purge = false) {
|
|
256
|
+
await this.record(name);
|
|
257
|
+
await this.stop(name);
|
|
258
|
+
const state = await this.state();
|
|
259
|
+
delete state.agents[name];
|
|
260
|
+
await this.save();
|
|
261
|
+
await rm(this.packageDir(name), { recursive: true, force: true });
|
|
262
|
+
if (purge)
|
|
263
|
+
await rm(this.agentDir(name), { recursive: true, force: true });
|
|
264
|
+
this.logs.delete(name);
|
|
265
|
+
this.errors.delete(name);
|
|
266
|
+
this.changed();
|
|
267
|
+
}
|
|
268
|
+
async setAutostart(name, autostart) {
|
|
269
|
+
const record = await this.record(name);
|
|
270
|
+
record.autostart = autostart;
|
|
271
|
+
await this.save();
|
|
272
|
+
return this.view(record);
|
|
273
|
+
}
|
|
274
|
+
async setEnv(name, set = {}, unset = []) {
|
|
275
|
+
const record = await this.record(name);
|
|
276
|
+
const env = await this.readEnv(name);
|
|
277
|
+
for (const key of [...Object.keys(set), ...unset]) {
|
|
278
|
+
if (!ENV_NAME.test(key))
|
|
279
|
+
throw new HostError('bad_request', `${key} is not a variable name.`);
|
|
280
|
+
}
|
|
281
|
+
for (const [key, value] of Object.entries(set)) {
|
|
282
|
+
if (value === '')
|
|
283
|
+
delete env[key];
|
|
284
|
+
else
|
|
285
|
+
env[key] = String(value);
|
|
286
|
+
}
|
|
287
|
+
for (const key of unset)
|
|
288
|
+
delete env[key];
|
|
289
|
+
await writeJson(this.envFile(name), env, 0o600);
|
|
290
|
+
if (this.running.has(name)) {
|
|
291
|
+
await this.stop(name);
|
|
292
|
+
return this.start(name);
|
|
293
|
+
}
|
|
294
|
+
return this.view(record);
|
|
295
|
+
}
|
|
296
|
+
logLines(name) {
|
|
297
|
+
return [...(this.logs.get(name) ?? [])];
|
|
298
|
+
}
|
|
299
|
+
async packageMeta(name, packageName) {
|
|
300
|
+
const dir = join(this.packageDir(name), 'node_modules', ...packageName.split('/'));
|
|
301
|
+
let pkg;
|
|
302
|
+
try {
|
|
303
|
+
pkg = JSON.parse(await readFile(join(dir, 'package.json'), 'utf8'));
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
throw new HostError('install_failed', `${packageName} is not installed in ${this.packageDir(name)}.`);
|
|
307
|
+
}
|
|
308
|
+
const short = packageName.split('/').pop();
|
|
309
|
+
const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin ? (pkg.bin[short] ?? Object.values(pkg.bin)[0]) : undefined;
|
|
310
|
+
if (!bin)
|
|
311
|
+
throw new HostError('install_failed', `${packageName} has no command (no "bin" in its package.json), so it is not an agent CLI.`);
|
|
312
|
+
return { version: pkg.version ?? '0.0.0', bin: join(dir, bin) };
|
|
313
|
+
}
|
|
314
|
+
async start(name) {
|
|
315
|
+
const record = await this.record(name);
|
|
316
|
+
if (this.running.has(name))
|
|
317
|
+
return this.view(record);
|
|
318
|
+
const node = await this.node();
|
|
319
|
+
const { bin } = await this.packageMeta(name, record.package);
|
|
320
|
+
const token = await this.token(name);
|
|
321
|
+
const workspaces = join(this.workspaces, name);
|
|
322
|
+
await mkdir(this.homeDir(name), { recursive: true });
|
|
323
|
+
await mkdir(workspaces, { recursive: true });
|
|
324
|
+
const args = [
|
|
325
|
+
bin,
|
|
326
|
+
'--serve',
|
|
327
|
+
'--port',
|
|
328
|
+
String(record.port),
|
|
329
|
+
'--home',
|
|
330
|
+
this.homeDir(name),
|
|
331
|
+
'--workspaces',
|
|
332
|
+
workspaces,
|
|
333
|
+
'--token-file',
|
|
334
|
+
this.tokenFile(name),
|
|
335
|
+
'--no-setup',
|
|
336
|
+
...(this.options.corsOrigins?.length ? ['--cors', this.options.corsOrigins.join(',')] : []),
|
|
337
|
+
];
|
|
338
|
+
const env = { ...process.env, ...(await this.readEnv(name)), ...node.env };
|
|
339
|
+
const child = (this.options.spawnProcess ?? spawn)(node.file, args, { env, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
340
|
+
const entry = { child, stopping: false, startedAt: Date.now() };
|
|
341
|
+
this.running.set(name, entry);
|
|
342
|
+
this.errors.delete(name);
|
|
343
|
+
const lines = this.logs.get(name) ?? [];
|
|
344
|
+
this.logs.set(name, lines);
|
|
345
|
+
const push = (chunk) => {
|
|
346
|
+
for (const line of chunk.toString('utf8').split(/\r?\n/)) {
|
|
347
|
+
if (!line.trim())
|
|
348
|
+
continue;
|
|
349
|
+
lines.push(line);
|
|
350
|
+
if (lines.length > LOG_LINES)
|
|
351
|
+
lines.splice(0, lines.length - LOG_LINES);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
child.stdout?.on('data', push);
|
|
355
|
+
child.stderr?.on('data', push);
|
|
356
|
+
const exited = new Promise((done) => {
|
|
357
|
+
child.on('error', (error) => {
|
|
358
|
+
lines.push(error.message);
|
|
359
|
+
done(-1);
|
|
360
|
+
});
|
|
361
|
+
child.on('exit', (code) => done(code));
|
|
362
|
+
});
|
|
363
|
+
void exited.then((code) => {
|
|
364
|
+
if (this.running.get(name) !== entry)
|
|
365
|
+
return;
|
|
366
|
+
this.running.delete(name);
|
|
367
|
+
if (!entry.stopping)
|
|
368
|
+
this.errors.set(name, `Stopped with code ${code}. ${lines.slice(-3).join(' ')}`.trim());
|
|
369
|
+
this.changed();
|
|
370
|
+
});
|
|
371
|
+
// Ready when GET /v1/info answers with the token.
|
|
372
|
+
const deadline = Date.now() + 30_000;
|
|
373
|
+
while (Date.now() < deadline) {
|
|
374
|
+
if (!this.running.has(name))
|
|
375
|
+
break;
|
|
376
|
+
try {
|
|
377
|
+
const r = await this.fetchImpl(`http://127.0.0.1:${record.port}/v1/info`, { headers: { authorization: `Bearer ${token}` } });
|
|
378
|
+
if (r.ok) {
|
|
379
|
+
this.changed();
|
|
380
|
+
return this.view(record);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
// Not listening yet.
|
|
385
|
+
}
|
|
386
|
+
await sleep(250);
|
|
387
|
+
}
|
|
388
|
+
const why = this.errors.get(name) ?? lines.slice(-5).join('\n');
|
|
389
|
+
await this.stop(name);
|
|
390
|
+
this.errors.set(name, why || 'It did not answer in 30 seconds.');
|
|
391
|
+
throw new HostError('start_failed', `${record.title} did not start. ${why}`.trim());
|
|
392
|
+
}
|
|
393
|
+
async stop(name) {
|
|
394
|
+
const record = await this.record(name);
|
|
395
|
+
const entry = this.running.get(name);
|
|
396
|
+
if (entry) {
|
|
397
|
+
entry.stopping = true;
|
|
398
|
+
const exited = new Promise((done) => entry.child.once('exit', () => done()));
|
|
399
|
+
entry.child.kill();
|
|
400
|
+
await Promise.race([exited, sleep(5000)]);
|
|
401
|
+
if (this.running.get(name) === entry) {
|
|
402
|
+
entry.child.kill('SIGKILL');
|
|
403
|
+
this.running.delete(name);
|
|
404
|
+
}
|
|
405
|
+
this.changed();
|
|
406
|
+
}
|
|
407
|
+
return this.view(record);
|
|
408
|
+
}
|
|
409
|
+
/** Starts every agent marked autostart; failures are kept as the agent's error. */
|
|
410
|
+
async startAutostart() {
|
|
411
|
+
const state = await this.state();
|
|
412
|
+
for (const record of Object.values(state.agents)) {
|
|
413
|
+
if (record.autostart)
|
|
414
|
+
await this.start(record.name).catch(() => undefined);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** Stops every agent at once, for the app's exit. */
|
|
418
|
+
stopAll() {
|
|
419
|
+
for (const entry of this.running.values()) {
|
|
420
|
+
entry.stopping = true;
|
|
421
|
+
entry.child.kill();
|
|
422
|
+
}
|
|
423
|
+
this.running.clear();
|
|
424
|
+
}
|
|
425
|
+
// Ollama
|
|
426
|
+
async ollamaFns() {
|
|
427
|
+
if (this.options.ollama)
|
|
428
|
+
return this.options.ollama;
|
|
429
|
+
if (this.ollamaApi)
|
|
430
|
+
return this.ollamaApi;
|
|
431
|
+
const o = await import('@wawjs/ai-ollama');
|
|
432
|
+
const { detectSystem } = await import('@wawjs/ai-core');
|
|
433
|
+
this.ollamaApi = {
|
|
434
|
+
detect: () => o.detectOllama(),
|
|
435
|
+
installCommand: () => o.installPlan().display,
|
|
436
|
+
install: () => o.installOllama(),
|
|
437
|
+
start: () => o.startOllama(),
|
|
438
|
+
list: () => o.listModels(),
|
|
439
|
+
pull: (name, onProgress) => o.pullModel(name, onProgress),
|
|
440
|
+
remove: (name) => o.removeModel(name),
|
|
441
|
+
recommend: async () => o.recommendModels(await detectSystem()),
|
|
442
|
+
};
|
|
443
|
+
return this.ollamaApi;
|
|
444
|
+
}
|
|
445
|
+
async ollama() {
|
|
446
|
+
const o = await this.ollamaFns();
|
|
447
|
+
const status = await o.detect();
|
|
448
|
+
const models = status.running ? (await o.list().catch(() => [])).map((m) => ({ id: m.name, sizeBytes: m.sizeBytes })) : [];
|
|
449
|
+
const names = new Set(models.map((m) => m.id));
|
|
450
|
+
const recommended = (await o.recommend().catch(() => [])).map((r) => ({
|
|
451
|
+
name: r.name,
|
|
452
|
+
sizeBytes: Math.round(r.sizeBytes),
|
|
453
|
+
runsOn: r.runsOn,
|
|
454
|
+
reason: r.reason,
|
|
455
|
+
downloaded: names.has(r.name),
|
|
456
|
+
}));
|
|
457
|
+
return { ...status, installCommand: o.installCommand(), models, recommended };
|
|
458
|
+
}
|
|
459
|
+
async installOllama() {
|
|
460
|
+
const o = await this.ollamaFns();
|
|
461
|
+
await o.install();
|
|
462
|
+
await o.start().catch(() => undefined);
|
|
463
|
+
return this.ollama();
|
|
464
|
+
}
|
|
465
|
+
async startOllama() {
|
|
466
|
+
await (await this.ollamaFns()).start();
|
|
467
|
+
return this.ollama();
|
|
468
|
+
}
|
|
469
|
+
/** Downloads a model in the background, reporting progress; resolves when it finished or failed. */
|
|
470
|
+
async pullModel(name, onProgress) {
|
|
471
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,199}$/.test(name))
|
|
472
|
+
throw new HostError('bad_request', `${name} is not a model name.`);
|
|
473
|
+
if (this.pulls.has(name))
|
|
474
|
+
return;
|
|
475
|
+
this.pulls.add(name);
|
|
476
|
+
const o = await this.ollamaFns();
|
|
477
|
+
try {
|
|
478
|
+
await o.pull(name, (p) => onProgress({ name, ...p }));
|
|
479
|
+
onProgress({ name, status: 'success', percent: 100, completedBytes: 0, totalBytes: 0, done: true });
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
onProgress({ name, status: 'error', percent: 0, completedBytes: 0, totalBytes: 0, done: true, error: error instanceof Error ? error.message : String(error) });
|
|
483
|
+
}
|
|
484
|
+
finally {
|
|
485
|
+
this.pulls.delete(name);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
async removeModel(name) {
|
|
489
|
+
await (await this.ollamaFns()).remove(name);
|
|
490
|
+
return this.ollama();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async function writeJson(file, value, mode) {
|
|
494
|
+
await mkdir(dirname(file), { recursive: true });
|
|
495
|
+
const temp = `${file}.${process.pid}.tmp`;
|
|
496
|
+
await writeFile(temp, JSON.stringify(value, null, '\t'), mode ? { mode } : undefined);
|
|
497
|
+
await rename(temp, file);
|
|
498
|
+
if (mode)
|
|
499
|
+
await chmod(file, mode).catch(() => undefined);
|
|
500
|
+
}
|
|
501
|
+
function sleep(ms) {
|
|
502
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
503
|
+
}
|
|
504
|
+
function portFree(port) {
|
|
505
|
+
return new Promise((done) => {
|
|
506
|
+
const server = createServer();
|
|
507
|
+
server.once('error', () => done(false));
|
|
508
|
+
server.listen(port, '127.0.0.1', () => server.close(() => done(true)));
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
/** The wanted port when nothing uses it, else the next free one. */
|
|
512
|
+
export async function freePort(wanted, taken = new Set()) {
|
|
513
|
+
for (let port = wanted; port < wanted + 200 && port < 65536; port++) {
|
|
514
|
+
if (!taken.has(port) && (await portFree(port)))
|
|
515
|
+
return port;
|
|
516
|
+
}
|
|
517
|
+
throw new HostError('start_failed', `No free port near ${wanted}.`);
|
|
518
|
+
}
|
|
519
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKnD,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,wCAAwC,CAAC;AAEpE,MAAM,YAAY,GAAG,oDAAoD,CAAC;AAC1E,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAC/C,MAAM,QAAQ,GAAG,oBAAoB,CAAC;AACtC,MAAM,SAAS,GAAG,GAAG,CAAC;AAKtB,MAAM,aAAa,GAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAC1D,IAAI,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;IACpB,QAAQ,CACP,IAAI,EACJ,IAAI;IACJ,8FAA8F;IAC9F,EAAE,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IAAI,GAAG,EAAE;IAC5E,KAAK,IAAI,IAAI,GAAG,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,GAAG,IAAI,IAAI,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC;QACrE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;IAC7D,CAAC;IACD,MAAM,IAAI,SAAS,CAAC,cAAc,EAAE,qBAAqB,MAAM,GAAG,CAAC,CAAC;AACrE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AiHostPlugin } from './definitions.js';
|
|
2
|
+
export type * from './definitions.js';
|
|
3
|
+
/** The npm name of this package. */
|
|
4
|
+
export declare const packageName = "@wawjs/ai-host";
|
|
5
|
+
/** The host in the desktop app. Use it only when hostAvailable() is true. */
|
|
6
|
+
export declare const AiHost: AiHostPlugin;
|
|
7
|
+
/** True in the desktop app (Electron), where agents and models can be installed on this computer. */
|
|
8
|
+
export declare function hostAvailable(): boolean;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Capacitor, registerPlugin } from '@capacitor/core';
|
|
2
|
+
/** The npm name of this package. */
|
|
3
|
+
export const packageName = '@wawjs/ai-host';
|
|
4
|
+
/** The host in the desktop app. Use it only when hostAvailable() is true. */
|
|
5
|
+
export const AiHost = registerPlugin('AiHost');
|
|
6
|
+
/** True in the desktop app (Electron), where agents and models can be installed on this computer. */
|
|
7
|
+
export function hostAvailable() {
|
|
8
|
+
return Capacitor.isPluginAvailable('AiHost');
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAK5D,oCAAoC;AACpC,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAE5C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,MAAM,GAAG,cAAc,CAAe,QAAQ,CAAC,CAAC;AAE7D,qGAAqG;AACrG,MAAM,UAAU,aAAa;IAC5B,OAAO,SAAS,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wawjs/ai-host",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Turns the desktop app of the IT Kamianets AI Framework into an agent host: installs agent CLIs from npm and runs them, installs Ollama and downloads models. A Capacitor plugin with an Electron implementation.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./node": {
|
|
15
|
+
"types": "./dist/host.d.ts",
|
|
16
|
+
"import": "./dist/host.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"electron/dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"capacitor": {
|
|
28
|
+
"electron": {
|
|
29
|
+
"src": "electron"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=24"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/IT-Kamianets/ai-host.git"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://ai.itkamianets.com/packages/ai-host",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/IT-Kamianets/ai-host/issues"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"agent",
|
|
45
|
+
"ai",
|
|
46
|
+
"electron",
|
|
47
|
+
"capacitor-plugin",
|
|
48
|
+
"ollama",
|
|
49
|
+
"itkamianets",
|
|
50
|
+
"ai-itkp"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
57
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
58
|
+
"test": "npm run build && node --test \"test/**/*.test.ts\"",
|
|
59
|
+
"prepublishOnly": "npm test"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@wawjs/ai-core": "^0.4.2",
|
|
63
|
+
"@wawjs/ai-ollama": "^0.1.2"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@capacitor/core": ">=7"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@capacitor/core": "^9.1.0",
|
|
70
|
+
"@types/node": "^24.10.0",
|
|
71
|
+
"typescript": "^7.0.2"
|
|
72
|
+
}
|
|
73
|
+
}
|