@trama-dev/runtime 0.6.1 → 0.8.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/dist/agent-backend.d.ts +100 -0
- package/dist/agent-backend.js +4 -0
- package/dist/agent-host.d.ts +46 -7
- package/dist/agent-host.js +59 -19
- package/dist/agent-hosts.d.ts +8 -0
- package/dist/agent-hosts.js +123 -56
- package/dist/agent.d.ts +18 -5
- package/dist/agent.js +23 -64
- package/dist/bridge-client.d.ts +6 -2
- package/dist/bridge-client.js +7 -1
- package/dist/budget.d.ts +6 -0
- package/dist/budget.js +1 -0
- package/dist/client.d.ts +3 -2
- package/dist/client.js +146 -2
- package/dist/context.js +3 -2
- package/dist/history.d.ts +9 -0
- package/dist/history.js +98 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +73 -41
- package/dist/ipc-server.d.ts +2 -3
- package/dist/ipc-server.js +99 -38
- package/dist/journal-view.d.ts +8 -0
- package/dist/journal-view.js +63 -11
- package/dist/journal.d.ts +10 -4
- package/dist/journal.js +73 -7
- package/dist/merge-deeds.d.ts +22 -0
- package/dist/merge-deeds.js +201 -0
- package/dist/merge-doing.d.ts +9 -0
- package/dist/merge-doing.js +410 -0
- package/dist/merge-settle.d.ts +14 -0
- package/dist/merge-settle.js +166 -0
- package/dist/merge-shared.d.ts +64 -0
- package/dist/merge-shared.js +159 -0
- package/dist/merge.d.ts +150 -0
- package/dist/merge.js +209 -0
- package/dist/model-relay.d.ts +19 -0
- package/dist/model-relay.js +91 -9
- package/dist/model-request.d.ts +9 -0
- package/dist/model-request.js +185 -0
- package/dist/own-tools.d.ts +60 -0
- package/dist/own-tools.js +209 -0
- package/dist/path-guard.js +8 -6
- package/dist/pi-adapter.d.ts +32 -9
- package/dist/pi-adapter.js +198 -51
- package/dist/project.d.ts +39 -0
- package/dist/project.js +270 -0
- package/dist/replace-file.d.ts +13 -2
- package/dist/replace-file.js +23 -6
- package/dist/runner-backend.d.ts +43 -0
- package/dist/runner-backend.js +149 -0
- package/dist/runner-types.d.ts +26 -0
- package/dist/runner.d.ts +10 -125
- package/dist/runner.js +148 -461
- package/dist/schema.d.ts +45 -0
- package/dist/schema.js +113 -0
- package/dist/stopping.js +2 -3
- package/dist/tools.d.ts +8 -1
- package/dist/tools.js +36 -10
- package/dist/tree.d.ts +33 -149
- package/dist/tree.js +43 -1077
- package/dist/types.d.ts +182 -2
- package/dist/workspace.d.ts +28 -1
- package/dist/workspace.js +88 -13
- package/package.json +2 -2
package/dist/agent-backend.d.ts
CHANGED
|
@@ -43,6 +43,51 @@ export declare function addReply(tally: Tally, used: {
|
|
|
43
43
|
export declare function atLeast(usage: AgentUsage | undefined, seen?: Tally): AgentUsage | undefined;
|
|
44
44
|
/** Of a report, what a report is declared to hold — whatever else a backend put beside it. */
|
|
45
45
|
export declare const declaredUsage: ({ model, input, output, cacheRead, cacheWrite, cost }: AgentUsage) => AgentUsage;
|
|
46
|
+
/** The kinds of image a model is shown. */
|
|
47
|
+
export declare const IMAGE_KINDS: readonly ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
48
|
+
export type ImageKind = (typeof IMAGE_KINDS)[number];
|
|
49
|
+
/** An image, as it is handed about: what kind it is, and its bytes in base64. */
|
|
50
|
+
export interface ToolImage {
|
|
51
|
+
mimeType: string;
|
|
52
|
+
data: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* What a tool that was asked says: what the model is to read — and to be
|
|
56
|
+
* shown, where the tool has images for it — and whether that is how it failed.
|
|
57
|
+
*/
|
|
58
|
+
export interface ToolAnswer {
|
|
59
|
+
text: string;
|
|
60
|
+
images?: ToolImage[];
|
|
61
|
+
failed?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** What a tool is taken to have said where it was not waited for: its call was to go no further. (Nobody reads it: the call is over.) */
|
|
64
|
+
export declare const NOT_WAITED_FOR: ToolAnswer;
|
|
65
|
+
/**
|
|
66
|
+
* A tool that is not the backend's: whoever makes the call has it, and is
|
|
67
|
+
* asked by `run` each time the model calls it.
|
|
68
|
+
*/
|
|
69
|
+
export interface OwnTool {
|
|
70
|
+
/** As the model calls it. Nobody else's name: not a tool of the backend's, nor of anything the backend loads. */
|
|
71
|
+
name: string;
|
|
72
|
+
/** What it is for, as the model is told. */
|
|
73
|
+
description: string;
|
|
74
|
+
/** What it is called with: the JSON Schema of an object. A backend holds a call's arguments to it before it asks. */
|
|
75
|
+
parameters: Record<string, unknown>;
|
|
76
|
+
/** It may be run while another tool is. Without it, of the tools a model calls in one reply, one is run after the other. */
|
|
77
|
+
parallel?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* What it answers, where it does not fail, is the end of the agent's work
|
|
80
|
+
* and the answer of the call: the model is not asked again. (Unless the
|
|
81
|
+
* model called, in the same reply, a tool that does not end it.)
|
|
82
|
+
*/
|
|
83
|
+
ends?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Have it run: `id` is the model's call of it. It does not reject — a
|
|
86
|
+
* tool's failure is an answer, for the model to read — and where `signal`
|
|
87
|
+
* says the call is to go no further it is not waited for.
|
|
88
|
+
*/
|
|
89
|
+
run(args: unknown, id: string, signal?: AbortSignal): Promise<ToolAnswer>;
|
|
90
|
+
}
|
|
46
91
|
export interface AgentCall {
|
|
47
92
|
/** The directory the agent works in: what its tools read is here, and what they write lands here. */
|
|
48
93
|
cwd: string;
|
|
@@ -54,6 +99,12 @@ export interface AgentCall {
|
|
|
54
99
|
thinking?: string;
|
|
55
100
|
/** The agent's tools for this call, by name: these and no others. Without it, the agent's own choice. */
|
|
56
101
|
tools?: string[];
|
|
102
|
+
/**
|
|
103
|
+
* Tools of the caller's own, which the agent has beside those: each to be
|
|
104
|
+
* the agent's as it is written, or the call rejects — a name that is
|
|
105
|
+
* another tool's is not taken over, and not passed over.
|
|
106
|
+
*/
|
|
107
|
+
ownTools?: OwnTool[];
|
|
57
108
|
/**
|
|
58
109
|
* The skills the agent has for this call, of those the backend finds for
|
|
59
110
|
* the user and where it works: all of them, or the ones named. Without it,
|
|
@@ -131,6 +182,41 @@ export declare class CutOff extends Error {
|
|
|
131
182
|
readonly text: string;
|
|
132
183
|
constructor(text: string);
|
|
133
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* One request to a model: what it is to be sent — the conversation so far,
|
|
187
|
+
* and beside it what the model is told to be and the tools it may call, each
|
|
188
|
+
* declared — and how it is asked. Plain data, all of it, held to its shape by
|
|
189
|
+
* whoever made it (see model-request.ts): a backend sends it as it is.
|
|
190
|
+
*/
|
|
191
|
+
export interface ModelAsk {
|
|
192
|
+
context: {
|
|
193
|
+
systemPrompt?: string;
|
|
194
|
+
messages: Array<Record<string, unknown>>;
|
|
195
|
+
tools?: Array<{
|
|
196
|
+
name: string;
|
|
197
|
+
description: string;
|
|
198
|
+
parameters: Record<string, unknown>;
|
|
199
|
+
}>;
|
|
200
|
+
};
|
|
201
|
+
/** The model that is to answer, as the backend names its models — in place of the one it would ask. */
|
|
202
|
+
model?: string;
|
|
203
|
+
/** How much the model is to think, as the backend names its levels. */
|
|
204
|
+
thinking?: string;
|
|
205
|
+
/** The most the reply may come to, in tokens. */
|
|
206
|
+
maxTokens?: number;
|
|
207
|
+
temperature?: number;
|
|
208
|
+
/** Whether the model may call the tools it is told of ("auto", as it is without this) or is to answer without ("none"). */
|
|
209
|
+
toolChoice?: "auto" | "none";
|
|
210
|
+
/** How long the provider is waited for, in milliseconds. */
|
|
211
|
+
timeout?: number;
|
|
212
|
+
}
|
|
213
|
+
/** What goes with one request to a model, and is no part of it. */
|
|
214
|
+
export interface ModelCall {
|
|
215
|
+
/** Cancels the request. A cancelled request rejects. */
|
|
216
|
+
signal?: AbortSignal;
|
|
217
|
+
/** Told what the request used, at most once and before it settles — however it ended. (It does not throw.) */
|
|
218
|
+
used?: (usage: AgentUsage) => void;
|
|
219
|
+
}
|
|
134
220
|
export interface AgentBackend {
|
|
135
221
|
/**
|
|
136
222
|
* Run one prompt to completion and return the agent's final text. A final
|
|
@@ -141,4 +227,18 @@ export interface AgentBackend {
|
|
|
141
227
|
* honour something in `call` must reject, never silently ignore it.
|
|
142
228
|
*/
|
|
143
229
|
ask(prompt: string, call: AgentCall): Promise<string>;
|
|
230
|
+
/**
|
|
231
|
+
* Ask the backend's model once, and return its one reply: no agent, no
|
|
232
|
+
* tool run, nothing asked again — whoever asks is the harness. The reply
|
|
233
|
+
* is the model's as the backend has replies: plain data, to be sent back
|
|
234
|
+
* as it came where the conversation goes on. What is the model's doing is
|
|
235
|
+
* a reply, and is read in it: one that was cut off at its limit, and one
|
|
236
|
+
* the provider failed (its `stopReason` is "error", and `errorMessage`
|
|
237
|
+
* says how). What is not rejects: a model the backend has not got, or
|
|
238
|
+
* cannot ask; a level it does not think at; a request that was cancelled.
|
|
239
|
+
*
|
|
240
|
+
* As of `ask`: each stands alone, and what a backend cannot honour of a
|
|
241
|
+
* request it rejects.
|
|
242
|
+
*/
|
|
243
|
+
complete(request: ModelAsk, call: ModelCall): Promise<Record<string, unknown>>;
|
|
144
244
|
}
|
package/dist/agent-backend.js
CHANGED
|
@@ -32,6 +32,10 @@ export function atLeast(usage, seen) {
|
|
|
32
32
|
}
|
|
33
33
|
/** Of a report, what a report is declared to hold — whatever else a backend put beside it. */
|
|
34
34
|
export const declaredUsage = ({ model, input, output, cacheRead, cacheWrite, cost }) => ({ model, input, output, cacheRead, cacheWrite, cost });
|
|
35
|
+
/** The kinds of image a model is shown. */
|
|
36
|
+
export const IMAGE_KINDS = ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
37
|
+
/** What a tool is taken to have said where it was not waited for: its call was to go no further. (Nobody reads it: the call is over.) */
|
|
38
|
+
export const NOT_WAITED_FOR = { text: "The call was stopped before the tool had answered.", failed: true };
|
|
35
39
|
/**
|
|
36
40
|
* A reply that ended at the model's output limit, and not where the model
|
|
37
41
|
* would have ended it. It is not the answer — the call fails with this —
|
package/dist/agent-host.d.ts
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
|
-
import { type AgentCall, type AgentUsage } from "./agent-backend.js";
|
|
1
|
+
import { type AgentCall, type AgentUsage, type OwnTool, type ToolAnswer } from "./agent-backend.js";
|
|
2
2
|
import type { ModelConfig } from "./runner-types.js";
|
|
3
3
|
import { type RelayAnswered, type RelayAsked } from "./model-relay.js";
|
|
4
|
-
/**
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* What a call is made of that can be sent: all of it but where to say what
|
|
6
|
+
* it used, and what cancels it — and, of the tools of its caller's own, what
|
|
7
|
+
* each declares: to have one run, a host asks its runner (below).
|
|
8
|
+
*/
|
|
9
|
+
export type SentCall = Omit<AgentCall, "signal" | "used" | "sofar" | "had" | "relay" | "ownTools"> & {
|
|
10
|
+
ownTools?: Array<Omit<OwnTool, "run">>;
|
|
11
|
+
};
|
|
12
|
+
/** A use of a tool of the caller's own, as a host asks its runner for it: `key` is how the two speak of it. */
|
|
13
|
+
export interface ToolAsked {
|
|
14
|
+
key: string;
|
|
15
|
+
name: string;
|
|
16
|
+
id: string;
|
|
17
|
+
args: unknown;
|
|
18
|
+
}
|
|
6
19
|
/**
|
|
7
20
|
* What a runner says to a host: a call to serve; that the call it is serving
|
|
8
21
|
* may go on, having said what it has used so far; that it is cancelled; and
|
|
9
22
|
* what a model answers that the call had asked by its runner (see
|
|
10
23
|
* model-relay.ts). And to a host that serves no call, but asks models for
|
|
11
24
|
* the calls of others — the runner's own, where the run was given variables,
|
|
12
|
-
* which a process is to be started with to ask by them: what to ask.
|
|
25
|
+
* which a process is to be started with to ask by them: what to ask. And
|
|
26
|
+
* what a tool of the caller's own answered, that the call's model had called.
|
|
13
27
|
*/
|
|
14
28
|
export type ToHost = {
|
|
15
29
|
ask: {
|
|
30
|
+
id: number;
|
|
16
31
|
config: ModelConfig;
|
|
17
32
|
prompt: string;
|
|
18
33
|
call: SentCall;
|
|
19
34
|
};
|
|
20
35
|
} | {
|
|
21
36
|
go: boolean;
|
|
37
|
+
of: number;
|
|
22
38
|
} | {
|
|
23
39
|
abort: true;
|
|
40
|
+
of: number;
|
|
41
|
+
} | {
|
|
42
|
+
tooled: {
|
|
43
|
+
key: string;
|
|
44
|
+
answer: ToolAnswer;
|
|
45
|
+
};
|
|
24
46
|
} | RelayAnswered | RelayAsked;
|
|
25
47
|
/**
|
|
26
48
|
* What a host says to its runner: that it is there; what the call has used
|
|
@@ -30,11 +52,26 @@ export type ToHost = {
|
|
|
30
52
|
* process has to be ended); what it used in the end; how the call ended —
|
|
31
53
|
* its answer, an answer cut off at the output limit (with what there was of
|
|
32
54
|
* it), or its failure; and what the call would have a model asked (or, of a
|
|
33
|
-
* host that asks for others: what the model answered).
|
|
55
|
+
* host that asks for others: what the model answered). And that the call's
|
|
56
|
+
* model has called a tool of the caller's own — which is the runner's to
|
|
57
|
+
* have run. (That such a use is to go no further is not said: it is when the
|
|
58
|
+
* call is cancelled, or over, and the runner knows of both.)
|
|
59
|
+
*
|
|
60
|
+
* What is said of a call is said with the call's number (`of`), as the
|
|
61
|
+
* runner gave it — what the call would have a model asked too. A host
|
|
62
|
+
* serves one call after another, and what it says while nobody listens
|
|
63
|
+
* waits on the channel for whoever listens next: a word that comes late, or
|
|
64
|
+
* was not the host's at all, is not to be the next call's.
|
|
34
65
|
*/
|
|
35
66
|
export type FromHost = {
|
|
36
67
|
ready: true;
|
|
37
|
-
} | {
|
|
68
|
+
} | OfCall | (RelayAsked & {
|
|
69
|
+
of?: number;
|
|
70
|
+
}) | RelayAnswered;
|
|
71
|
+
/** What a host says of the call it is serving. */
|
|
72
|
+
export type OfCall = {
|
|
73
|
+
of: number;
|
|
74
|
+
} & ({
|
|
38
75
|
sofar: AgentUsage;
|
|
39
76
|
answered?: true;
|
|
40
77
|
} | {
|
|
@@ -47,4 +84,6 @@ export type FromHost = {
|
|
|
47
84
|
cutOff: string;
|
|
48
85
|
} | {
|
|
49
86
|
error: string;
|
|
50
|
-
} |
|
|
87
|
+
} | {
|
|
88
|
+
tool: ToolAsked;
|
|
89
|
+
});
|
package/dist/agent-host.js
CHANGED
|
@@ -15,12 +15,14 @@ import { PiAdapter } from "./pi-adapter.js";
|
|
|
15
15
|
import { CutOff } from "./agent-backend.js";
|
|
16
16
|
import { messageOf } from "./errors.js";
|
|
17
17
|
import { createModelRelay, relayClient, relayServer, withRepliesWhole } from "./model-relay.js";
|
|
18
|
-
import { groupsUnder,
|
|
18
|
+
import { groupsUnder, stopGroups } from "./stopping.js";
|
|
19
19
|
const say = (message) => {
|
|
20
20
|
// (A runner that is gone is told nothing: this process is on its way out with it.)
|
|
21
21
|
if (process.connected)
|
|
22
22
|
process.send?.(message);
|
|
23
23
|
};
|
|
24
|
+
/** The call being served, by the number its runner gave it — none, while this process is free. */
|
|
25
|
+
let serving;
|
|
24
26
|
/** Cancels the call being served. */
|
|
25
27
|
let cancel;
|
|
26
28
|
/**
|
|
@@ -33,19 +35,44 @@ const answered = (go) => {
|
|
|
33
35
|
goOn?.(go);
|
|
34
36
|
goOn = undefined;
|
|
35
37
|
};
|
|
36
|
-
/** The end that asks, of what the call being served has its model asked by: this process's runner. */
|
|
37
|
-
const asks = relayClient(say);
|
|
38
|
+
/** The end that asks, of what the call being served has its model asked by: this process's runner — told which call it is for. */
|
|
39
|
+
const asks = relayClient((asked) => say(serving === undefined ? asked : { ...asked, of: serving }));
|
|
38
40
|
/** The end that answers, where this process is one that asks models for the calls of others: with its own pi, and the keys it was started with. */
|
|
39
41
|
let answers;
|
|
42
|
+
/** The uses of the caller's own tools that the call being served waits for, each by its key. */
|
|
43
|
+
const uses = new Map();
|
|
44
|
+
let used = 0;
|
|
45
|
+
/**
|
|
46
|
+
* A tool of the caller's own, as this process has it: each use is asked of
|
|
47
|
+
* the runner, which has the tool. (A use whose call is cancelled meanwhile
|
|
48
|
+
* is not waited for by whoever asked it here — see asPisTool — and its
|
|
49
|
+
* answer, should one come, is nobody's.)
|
|
50
|
+
*/
|
|
51
|
+
const askedOfRunner = (of) => (tool) => ({
|
|
52
|
+
...tool,
|
|
53
|
+
run: (args, id) => new Promise((resolve) => {
|
|
54
|
+
const key = String(++used);
|
|
55
|
+
uses.set(key, resolve);
|
|
56
|
+
say({ of, tool: { key, name: tool.name, id, args } });
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
40
59
|
/** Whether this process has been told to end. What it was serving is then stopped, and how that ended is not said: its runner hears that the process did. */
|
|
41
60
|
let leaving = false;
|
|
42
61
|
process.on("message", (message) => {
|
|
62
|
+
// (What is said of a call that is not the one being served — it is over here, and its runner had not heard — is said of nothing.)
|
|
43
63
|
if ("go" in message)
|
|
44
|
-
return answered(message.go);
|
|
64
|
+
return message.of === serving ? answered(message.go) : undefined;
|
|
45
65
|
if ("abort" in message) {
|
|
66
|
+
if (message.of !== serving)
|
|
67
|
+
return;
|
|
46
68
|
cancel?.abort();
|
|
47
69
|
return answered(false);
|
|
48
70
|
}
|
|
71
|
+
if ("tooled" in message) {
|
|
72
|
+
uses.get(message.tooled.key)?.(message.tooled.answer);
|
|
73
|
+
uses.delete(message.tooled.key);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
49
76
|
if ("relayed" in message)
|
|
50
77
|
return asks.heard(message.relayed);
|
|
51
78
|
if ("relay" in message || "relayAbort" in message)
|
|
@@ -53,45 +80,58 @@ process.on("message", (message) => {
|
|
|
53
80
|
// (A process that has been told to end serves nothing more: whoever asked hears that it ended.)
|
|
54
81
|
if (leaving)
|
|
55
82
|
return;
|
|
56
|
-
|
|
57
|
-
|
|
83
|
+
// A runner asks a host that is free, and a host is free when it has said how its call ended. Asked while it is
|
|
84
|
+
// at a call's work still, something else in this process said that for it — an extension, which has the same
|
|
85
|
+
// channel: this is no process to serve a call by, and it ends. (Whoever asked hears that it did.)
|
|
86
|
+
if (serving !== undefined)
|
|
87
|
+
return leave();
|
|
88
|
+
const { id: of, config, prompt, call } = message.ask;
|
|
89
|
+
const stop = cancel = new AbortController();
|
|
90
|
+
serving = of;
|
|
91
|
+
goOn = undefined;
|
|
92
|
+
uses.clear();
|
|
93
|
+
/** The call is over here: how it ended is said, and this process is free. */
|
|
94
|
+
const over = (how) => {
|
|
95
|
+
serving = undefined;
|
|
96
|
+
if (!leaving)
|
|
97
|
+
say({ of, ...how });
|
|
98
|
+
};
|
|
58
99
|
new PiAdapter(config).serve(prompt, {
|
|
59
100
|
...call,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
101
|
+
ownTools: call.ownTools?.map(askedOfRunner(of)),
|
|
102
|
+
signal: stop.signal,
|
|
103
|
+
used: (usage) => say({ of, used: usage }),
|
|
104
|
+
had: (usage) => say({ of, had: usage }),
|
|
63
105
|
relay: withRepliesWhole(asks.relay),
|
|
64
106
|
sofar: (usage, has) => new Promise((resolve) => {
|
|
65
107
|
goOn = resolve;
|
|
66
|
-
say({ sofar: usage, ...(has && { answered: true }) });
|
|
108
|
+
say({ of, sofar: usage, ...(has && { answered: true }) });
|
|
67
109
|
}),
|
|
68
|
-
}).then((answer) => {
|
|
69
|
-
say({ answer }); }, (err) => { if (!leaving)
|
|
70
|
-
say(err instanceof CutOff ? { cutOff: err.text } : { error: messageOf(err) }); });
|
|
110
|
+
}).then((answer) => over({ answer }), (err) => over(err instanceof CutOff ? { cutOff: err.text } : { error: messageOf(err) }));
|
|
71
111
|
});
|
|
72
112
|
// The runner is gone, or has no more use for this process — it says so, or its watchdog does, by asking
|
|
73
113
|
// this process to end: there is nothing left to serve. What this process has under it in groups of their
|
|
74
114
|
// own — an MCP server, what an agent was running — goes first: nobody else knows of it, once this process
|
|
75
|
-
// is gone.
|
|
115
|
+
// is gone. It is stopped as anything is: asked, given its time, and only then ended. (Whoever asked this
|
|
116
|
+
// process to end may have asked those groups too, having looked for them first: such a group is asked twice.)
|
|
117
|
+
// (This process's own group is its runner's to end, or the watchdog's; and a process that cannot
|
|
76
118
|
// hear either is ended without being asked again, when the time anything asked to stop is given is up.)
|
|
77
119
|
// And the call it is serving is stopped first, where it is: the system takes a moment to say what is
|
|
78
120
|
// under this process, and in that moment the call is not to go on — to ask its model again, or to answer.
|
|
79
|
-
|
|
121
|
+
function leave(asked) {
|
|
80
122
|
if (leaving)
|
|
81
123
|
return;
|
|
82
124
|
leaving = true;
|
|
83
125
|
cancel?.abort();
|
|
84
126
|
answered(false);
|
|
85
|
-
void groupsUnder(process.pid).then((
|
|
86
|
-
for (const group of groups)
|
|
87
|
-
signalGroup(group, "SIGKILL");
|
|
127
|
+
void groupsUnder(process.pid).then(stopGroups).then(() => {
|
|
88
128
|
// (Asked to end, it ends as what was asked to: whoever waits for it is told how it went.)
|
|
89
129
|
if (!asked)
|
|
90
130
|
process.exit(0);
|
|
91
131
|
process.removeAllListeners(asked);
|
|
92
132
|
process.kill(process.pid, asked);
|
|
93
133
|
});
|
|
94
|
-
}
|
|
134
|
+
}
|
|
95
135
|
process.on("disconnect", () => leave());
|
|
96
136
|
process.on("SIGTERM", leave);
|
|
97
137
|
say({ ready: true });
|
package/dist/agent-hosts.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { type AgentCall } from "./agent-backend.js";
|
|
2
|
+
import { type ModelRelay } from "./model-relay.js";
|
|
2
3
|
import type { ModelConfig } from "./runner-types.js";
|
|
3
4
|
export interface AgentHosts {
|
|
4
5
|
/** Have a host serve one call, as the adapter would (see AgentBackend.ask). */
|
|
5
6
|
ask(config: ModelConfig, prompt: string, call: AgentCall): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Who asks the models of the calls these hosts serve, where the hosts were
|
|
9
|
+
* started with variables: a process started with the same, that serves no
|
|
10
|
+
* call. To be asked by for what is no call of an agent's — one request to
|
|
11
|
+
* a model — and is to be asked with a run's variables all the same.
|
|
12
|
+
*/
|
|
13
|
+
readonly asks: ModelRelay;
|
|
6
14
|
/** End every host: what they were for is over. Resolves when none is left. (A call made after this starts one anew.) */
|
|
7
15
|
close(): Promise<void>;
|
|
8
16
|
}
|