@haikit/server 0.4.0 → 0.6.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 +43 -0
- package/dist/routes.d.ts +4 -2
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +17 -4
- package/dist/routes.js.map +1 -1
- package/dist/runtime.d.ts +33 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +185 -15
- package/dist/runtime.js.map +1 -1
- package/package.json +2 -2
- package/src/routes.ts +17 -4
- package/src/runtime.ts +203 -14
package/README.md
CHANGED
|
@@ -17,6 +17,49 @@ action *means* is resolved server-side from the surface's declared contract. If
|
|
|
17
17
|
the client could name a tool, a prompt injection inside any tool result would
|
|
18
18
|
become a button wired to it.
|
|
19
19
|
|
|
20
|
+
**An action's handler runs only for a click the turn can accept**: a
|
|
21
|
+
`resolve` on the surface the turn is waiting for, or an `inform` while nothing
|
|
22
|
+
waits. Any other click is refused before the handler sees it, so a handler can
|
|
23
|
+
write, and can be async to do it. It gets `{ props, handle, conversationId }`.
|
|
24
|
+
If it throws, nothing is recorded and the user can click again. Once it
|
|
25
|
+
succeeds, the click is saved before the model runs, so it can't be answered
|
|
26
|
+
twice.
|
|
27
|
+
|
|
28
|
+
That makes a handler run at least once per recorded click, not exactly once.
|
|
29
|
+
If saving the click fails after the handler has written (a crash, a newer
|
|
30
|
+
request taking the conversation over, a failed write), nothing is recorded, and
|
|
31
|
+
clicking again runs the handler again, perhaps with a different value. A
|
|
32
|
+
`resolve` is recorded at most once per surface, so a `resolve` handler that
|
|
33
|
+
writes should upsert on `(conversationId, handle)`. Handles are unique only
|
|
34
|
+
within a conversation, and the last attempt is the one recorded. An `inform`
|
|
35
|
+
surface takes any number of clicks, so an `inform` handler that writes needs a
|
|
36
|
+
write that's safe to repeat, or a key of its own.
|
|
37
|
+
|
|
38
|
+
**`init` runs a tool at the start of every conversation**, before the user
|
|
39
|
+
types anything. The runtime makes the call, not the model, so it can't be
|
|
40
|
+
skipped: the call and its result go into the history as if the model had made
|
|
41
|
+
them.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
const hai = createHai({ model, store, tools, surfaces, system, init: loadProfile });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A third route, `POST /hai/start`, opens the conversation and runs `init`
|
|
48
|
+
without calling the model. The client's `start()` calls it, and `mountChat`
|
|
49
|
+
does so when it opens and after *Start a new conversation*. The Messages API
|
|
50
|
+
requires the history to begin with a user message, so it opens with
|
|
51
|
+
`[conversation started]`, followed by init's call and result. Without an
|
|
52
|
+
`init`, `/start` returns an empty stream and creates no conversation. A client
|
|
53
|
+
that never calls `start()` still gets `init`, run with the first message.
|
|
54
|
+
|
|
55
|
+
It gets `{}` as input and can render surfaces. An elicit surface ("which
|
|
56
|
+
account?") parks the conversation before anyone has typed; the answer becomes
|
|
57
|
+
init's result, and the model replies. If it throws, the request is refused and
|
|
58
|
+
nothing is recorded, so the next start or message tries again. It stays in the model's tool list, because changing that list
|
|
59
|
+
mid-conversation invalidates newer models' earlier reasoning. But a later call
|
|
60
|
+
from the model gets "already ran" instead of running it twice. Its result stays
|
|
61
|
+
in context for every turn, so keep it digest-sized.
|
|
62
|
+
|
|
20
63
|
**A conversation closes once any of its surfaces passes its `staleAfterMs`.**
|
|
21
64
|
From then on both routes answer with an `expired` event and the model is not
|
|
22
65
|
called, so a picker left open over a weekend cannot resolve against last week's
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import type { Hai } from "./runtime.js";
|
|
3
3
|
/**
|
|
4
|
-
* Node http handler for the
|
|
4
|
+
* Node http handler for the three routes. Returns true if it handled the
|
|
5
|
+
* request.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
+
* All three stream SSE: chat and interact because both can resume the agent
|
|
8
|
+
* loop, start because the init tool it runs can render surfaces. Note what the
|
|
7
9
|
* interact route accepts: {handle, action, value} and nothing else. The client
|
|
8
10
|
* cannot name a tool, a handler, or an action target.
|
|
9
11
|
*/
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAExC
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGjE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,SAAS,IACxB,KAAK,eAAe,EAAE,KAAK,cAAc,KAAG,OAAO,CAAC,OAAO,CAAC,CA4E1F"}
|
package/dist/routes.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { isConversationBusy, isStaleLease } from "@haikit/core";
|
|
2
2
|
/**
|
|
3
|
-
* Node http handler for the
|
|
3
|
+
* Node http handler for the three routes. Returns true if it handled the
|
|
4
|
+
* request.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
+
* All three stream SSE: chat and interact because both can resume the agent
|
|
7
|
+
* loop, start because the init tool it runs can render surfaces. Note what the
|
|
6
8
|
* interact route accepts: {handle, action, value} and nothing else. The client
|
|
7
9
|
* cannot name a tool, a handler, or an action target.
|
|
8
10
|
*/
|
|
@@ -12,9 +14,17 @@ export function nodeHandler(hai, basePath = "/hai") {
|
|
|
12
14
|
if (req.method !== "POST" || !url.pathname.startsWith(basePath))
|
|
13
15
|
return false;
|
|
14
16
|
const route = url.pathname.slice(basePath.length);
|
|
15
|
-
if (route !== "/chat" && route !== "/interact")
|
|
17
|
+
if (route !== "/chat" && route !== "/interact" && route !== "/start")
|
|
16
18
|
return false;
|
|
17
19
|
const body = await readJson(req);
|
|
20
|
+
// Nothing to run before the first message: answer with an empty stream and
|
|
21
|
+
// create no conversation, so an app without init doesn't get one for every
|
|
22
|
+
// page view. Its first message starts the conversation, as it always has.
|
|
23
|
+
if (route === "/start" && !hai.config.init) {
|
|
24
|
+
openSSE(res);
|
|
25
|
+
res.end();
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
18
28
|
// Before the SSE stream opens, because a rejected load has no stream to
|
|
19
29
|
// report into — and an uncaught throw here would take down the request.
|
|
20
30
|
let conversation;
|
|
@@ -29,7 +39,7 @@ export function nodeHandler(hai, basePath = "/hai") {
|
|
|
29
39
|
return true;
|
|
30
40
|
}
|
|
31
41
|
const emit = openSSE(res);
|
|
32
|
-
if (route === "/chat") {
|
|
42
|
+
if (route === "/chat" || route === "/start") {
|
|
33
43
|
emit({ type: "hello", conversationId: conversation.id, model: hai.config.model.id });
|
|
34
44
|
}
|
|
35
45
|
let superseded = false;
|
|
@@ -37,6 +47,9 @@ export function nodeHandler(hai, basePath = "/hai") {
|
|
|
37
47
|
if (route === "/chat") {
|
|
38
48
|
await hai.send(conversation, String(body.message ?? ""), emit);
|
|
39
49
|
}
|
|
50
|
+
else if (route === "/start") {
|
|
51
|
+
await hai.start(conversation, emit);
|
|
52
|
+
}
|
|
40
53
|
else {
|
|
41
54
|
await hai.interact(conversation, { handle: body.handle, action: body.action, value: body.value }, emit);
|
|
42
55
|
}
|
package/dist/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIhE
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],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CAAC;IAC5D,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,CAAC;AAC9D,CAAC"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -7,6 +7,22 @@ export interface HaiConfig {
|
|
|
7
7
|
surfaces: AnySurfaceImpl[];
|
|
8
8
|
/** Guard against runaway tool loops. */
|
|
9
9
|
maxHops?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Runs at the start of every conversation, before the user's first message
|
|
12
|
+
* when the client calls `start()` (the default UI does, on open), otherwise
|
|
13
|
+
* with that first message. Either way it runs before the model's first turn.
|
|
14
|
+
* The runtime makes the call, not the model, so it cannot be skipped: the
|
|
15
|
+
* call and its result are recorded as if the model had made them. It
|
|
16
|
+
* receives `{}` as input and may render surfaces — an elicit surface parks
|
|
17
|
+
* the conversation before the model runs at all.
|
|
18
|
+
*
|
|
19
|
+
* If it throws, the request is refused and nothing is recorded, so the next
|
|
20
|
+
* message tries again. It stays in the model's tool list for the whole
|
|
21
|
+
* conversation — changing that list mid-conversation invalidates the
|
|
22
|
+
* model's earlier reasoning on newer models — but a later call from the
|
|
23
|
+
* model gets "already ran" back instead of running it again.
|
|
24
|
+
*/
|
|
25
|
+
init?: Tool;
|
|
10
26
|
}
|
|
11
27
|
export declare class Hai {
|
|
12
28
|
readonly config: HaiConfig;
|
|
@@ -17,6 +33,23 @@ export declare class Hai {
|
|
|
17
33
|
private nid;
|
|
18
34
|
private buildQueryUiTool;
|
|
19
35
|
send(conversation: Conversation, text: string, emit: Emit): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Start a conversation before the user has typed anything, so init's result
|
|
38
|
+
* — and any surface it shows — is already there when the first message
|
|
39
|
+
* arrives. The model does not run. Does nothing without an init tool, or
|
|
40
|
+
* once the conversation has begun.
|
|
41
|
+
*/
|
|
42
|
+
start(conversation: Conversation, emit: Emit): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Run the init tool as the conversation's first tool call, after `text` —
|
|
45
|
+
* the user's first message, or STARTED when it runs before one. Returns
|
|
46
|
+
* true when it parked the conversation on an elicit surface.
|
|
47
|
+
*
|
|
48
|
+
* Nothing reaches the history until the tool has succeeded — not even the
|
|
49
|
+
* user's message — so a refused start leaves the conversation exactly as
|
|
50
|
+
* the route found it, and the next message starts it again.
|
|
51
|
+
*/
|
|
52
|
+
private runInit;
|
|
20
53
|
interact(conversation: Conversation, input: {
|
|
21
54
|
handle: string;
|
|
22
55
|
action: string;
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,IAAI,EAIV,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;;;;;;;;;;;OAcG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAcD,qBAAa,GAAG;IACd,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAC9D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;IACjD,OAAO,CAAC,GAAG,CAAK;gBAEJ,MAAM,EAAE,SAAS;IAoB7B,OAAO,CAAC,GAAG;IAMX,OAAO,CAAC,gBAAgB;IAkFlB,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC/E;;;;;OAKG;IACG,KAAK,CAAC,YAAY,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlE;;;;;;;;OAQG;YACW,OAAO;IA+Df,QAAQ,CACZ,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EACzD,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,IAAI,CAAC;IA2GhB;;;;;;;;;;;;;;;;OAgBG;YACW,eAAe;YA4Cf,OAAO;YAuEP,UAAU;YA0FV,WAAW;CAa1B"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { estTokens, isStaleLease, makeCap, } from "@haikit/core";
|
|
2
|
+
/**
|
|
3
|
+
* Opens the history when init runs before the user has said anything: the
|
|
4
|
+
* Messages API requires the first message to be the user's. Bracketed like
|
|
5
|
+
* `[UI interaction]` — framework text, not something the user typed.
|
|
6
|
+
*/
|
|
7
|
+
const STARTED = "[conversation started]";
|
|
8
|
+
/** Appended to the init tool's description in what the model sees. */
|
|
9
|
+
const INIT_NOTE = "This ran automatically at the start of the conversation, and its result is already above. " +
|
|
10
|
+
"Calling it again does not run it.";
|
|
2
11
|
export class Hai {
|
|
3
12
|
config;
|
|
4
13
|
surfaces = new Map();
|
|
@@ -16,6 +25,12 @@ export class Hai {
|
|
|
16
25
|
// that actually exist, and it always exists.
|
|
17
26
|
const queryUi = this.buildQueryUiTool();
|
|
18
27
|
this.tools.set(queryUi.name, queryUi);
|
|
28
|
+
if (config.init) {
|
|
29
|
+
if (this.tools.has(config.init.name)) {
|
|
30
|
+
throw new Error(`init tool "${config.init.name}" has the same name as another tool`);
|
|
31
|
+
}
|
|
32
|
+
this.tools.set(config.init.name, config.init);
|
|
33
|
+
}
|
|
19
34
|
}
|
|
20
35
|
nid(prefix) {
|
|
21
36
|
return `${prefix}_${++this.seq}`;
|
|
@@ -93,6 +108,8 @@ export class Hai {
|
|
|
93
108
|
async send(conversation, text, emit) {
|
|
94
109
|
if (await this.refuseIfExpired(conversation, emit))
|
|
95
110
|
return;
|
|
111
|
+
// The first message is the one that starts the conversation.
|
|
112
|
+
const starting = conversation.messages.length === 0;
|
|
96
113
|
// The user typed while a tool was parked. Every tool_use in a turn must
|
|
97
114
|
// receive a tool_result, so close the pending one out honestly first.
|
|
98
115
|
if (conversation.status === "awaiting" && conversation.pending) {
|
|
@@ -115,9 +132,99 @@ export class Hai {
|
|
|
115
132
|
conversation.pending = null;
|
|
116
133
|
}
|
|
117
134
|
emit({ type: "block_start", block: { kind: "user", id: this.nid("b"), text } });
|
|
118
|
-
|
|
135
|
+
if (starting && this.config.init) {
|
|
136
|
+
if (await this.runInit(conversation, text, emit))
|
|
137
|
+
return; // parked on its surface
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
conversation.messages.push({ role: "user", content: text });
|
|
141
|
+
}
|
|
119
142
|
await this.runTurn(conversation, emit);
|
|
120
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Start a conversation before the user has typed anything, so init's result
|
|
146
|
+
* — and any surface it shows — is already there when the first message
|
|
147
|
+
* arrives. The model does not run. Does nothing without an init tool, or
|
|
148
|
+
* once the conversation has begun.
|
|
149
|
+
*/
|
|
150
|
+
async start(conversation, emit) {
|
|
151
|
+
if (!this.config.init || conversation.messages.length > 0)
|
|
152
|
+
return;
|
|
153
|
+
if (await this.runInit(conversation, STARTED, emit))
|
|
154
|
+
return; // parked on its surface
|
|
155
|
+
conversation.status = "idle";
|
|
156
|
+
emit({ type: "status", status: "idle" });
|
|
157
|
+
await this.emitContext(conversation, emit);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Run the init tool as the conversation's first tool call, after `text` —
|
|
161
|
+
* the user's first message, or STARTED when it runs before one. Returns
|
|
162
|
+
* true when it parked the conversation on an elicit surface.
|
|
163
|
+
*
|
|
164
|
+
* Nothing reaches the history until the tool has succeeded — not even the
|
|
165
|
+
* user's message — so a refused start leaves the conversation exactly as
|
|
166
|
+
* the route found it, and the next message starts it again.
|
|
167
|
+
*/
|
|
168
|
+
async runInit(conversation, text, emit) {
|
|
169
|
+
const init = this.config.init;
|
|
170
|
+
const call = { type: "tool_use", id: `toolu_init_${newId()}`, name: init.name, input: {} };
|
|
171
|
+
const toolBlockId = this.nid("b");
|
|
172
|
+
const before = { handles: conversation.handles.length, status: conversation.status };
|
|
173
|
+
conversation.status = "streaming";
|
|
174
|
+
emit({ type: "status", status: "streaming" });
|
|
175
|
+
emit({ type: "block_start", block: { kind: "tool", id: toolBlockId, name: init.name, input: {}, status: "running" } });
|
|
176
|
+
// Surfaces are held until init succeeds. One shown by a start that is then
|
|
177
|
+
// refused would look live in the browser, and every click on it would be
|
|
178
|
+
// rejected: its handle never reaches the history.
|
|
179
|
+
const held = [];
|
|
180
|
+
const hold = (e) => {
|
|
181
|
+
if (e.type === "ui_open" || e.type === "ui_props")
|
|
182
|
+
held.push(e);
|
|
183
|
+
else
|
|
184
|
+
emit(e);
|
|
185
|
+
};
|
|
186
|
+
const started = Date.now();
|
|
187
|
+
let outcome;
|
|
188
|
+
try {
|
|
189
|
+
outcome = await this.invokeTool(conversation, call, hold, toolBlockId, { init: true });
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
// undo what the tool's renders recorded; their payload rows are orphans
|
|
193
|
+
conversation.handles.length = before.handles;
|
|
194
|
+
conversation.status = before.status;
|
|
195
|
+
if (isStaleLease(err))
|
|
196
|
+
throw err;
|
|
197
|
+
const message = `initialisation failed: ${err.message}`;
|
|
198
|
+
emit({ type: "block_update", id: toolBlockId, status: "error", ms: Date.now() - started, result: message });
|
|
199
|
+
throw new Error(message);
|
|
200
|
+
}
|
|
201
|
+
const { ret, mode } = outcome;
|
|
202
|
+
const ms = Date.now() - started;
|
|
203
|
+
for (const e of held)
|
|
204
|
+
emit(e);
|
|
205
|
+
conversation.messages.push({ role: "user", content: text });
|
|
206
|
+
conversation.messages.push({ role: "assistant", content: [call] });
|
|
207
|
+
if (mode === "elicit" && ret.handle) {
|
|
208
|
+
emit({ type: "block_update", id: toolBlockId, status: "awaiting", ms, result: ret.model });
|
|
209
|
+
conversation.status = "awaiting";
|
|
210
|
+
conversation.pending = { toolUseId: call.id, handle: ret.handle, digest: ret.model, results: [] };
|
|
211
|
+
emit({ type: "status", status: "awaiting" });
|
|
212
|
+
await this.emitContext(conversation, emit);
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
emit({ type: "block_update", id: toolBlockId, status: "ok", ms, result: ret.model });
|
|
216
|
+
conversation.messages.push({
|
|
217
|
+
role: "user",
|
|
218
|
+
content: [{ type: "tool_result", tool_use_id: call.id, content: ret.model }],
|
|
219
|
+
});
|
|
220
|
+
// Commit before the model runs. An init that only returns text makes no
|
|
221
|
+
// fenced write of its own, so a request that outlived its lease while init
|
|
222
|
+
// ran would otherwise go on to call the model for a history its final save
|
|
223
|
+
// will lose. This save is fenced: it throws StaleLease if another request
|
|
224
|
+
// has taken the conversation over, and the model never runs here.
|
|
225
|
+
await this.config.store.saveConversation(conversation);
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
121
228
|
async interact(conversation, input, emit) {
|
|
122
229
|
if (await this.refuseIfExpired(conversation, emit))
|
|
123
230
|
return;
|
|
@@ -149,32 +256,80 @@ export class Hai {
|
|
|
149
256
|
catch (err) {
|
|
150
257
|
throw new Error(`invalid action payload: ${err.message}`);
|
|
151
258
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
259
|
+
// Gated before the handler runs, because a handler may write: only a click
|
|
260
|
+
// this request is going to record can reach it. A resolve answers the
|
|
261
|
+
// question the turn is waiting on and nothing else. An inform adds a user
|
|
262
|
+
// message, and while a turn waits that would land after a tool_use with no
|
|
263
|
+
// tool_result yet — a history the API refuses.
|
|
264
|
+
const pending = conversation.pending;
|
|
265
|
+
if (spec.kind === "resolve" && pending?.handle !== input.handle) {
|
|
266
|
+
throw new Error("nothing awaiting this handle");
|
|
267
|
+
}
|
|
268
|
+
if (spec.kind === "inform" && pending)
|
|
269
|
+
throw new Error("a question is waiting to be answered first");
|
|
270
|
+
// Nothing is recorded until the handler has succeeded, so one that throws
|
|
271
|
+
// refuses the click and leaves the surface live to be clicked again.
|
|
272
|
+
let label;
|
|
273
|
+
try {
|
|
274
|
+
label = await handler(value, { props: record.props, handle: record.handle, conversationId: conversation.id });
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
throw new Error(`action failed: ${err.message}`);
|
|
278
|
+
}
|
|
279
|
+
// what recording the click changes, so a failed save below can undo it
|
|
280
|
+
const before = {
|
|
281
|
+
messages: conversation.messages.length,
|
|
282
|
+
frozen: conversation.frozen.length,
|
|
283
|
+
status: conversation.status,
|
|
284
|
+
};
|
|
285
|
+
if (pending) {
|
|
286
|
+
// resolve: the gate above let it through only for the waiting surface
|
|
156
287
|
conversation.frozen.push(input.handle);
|
|
157
|
-
emit({ type: "ui_state", handle: input.handle, state: "frozen", selection: value });
|
|
158
|
-
emit({ type: "block_start", block: { kind: "interaction", id: this.nid("b"), handle: input.handle, label } });
|
|
159
288
|
conversation.messages.push({
|
|
160
289
|
role: "user",
|
|
161
290
|
content: [
|
|
162
|
-
...
|
|
291
|
+
...pending.results,
|
|
163
292
|
{
|
|
164
293
|
type: "tool_result",
|
|
165
|
-
tool_use_id:
|
|
294
|
+
tool_use_id: pending.toolUseId,
|
|
166
295
|
// The digest rides along: this elicit tool never got a tool_result,
|
|
167
296
|
// so nothing about the search has reached the model yet.
|
|
168
|
-
content: `${
|
|
297
|
+
content: `${pending.digest}\n${label}`,
|
|
169
298
|
},
|
|
170
299
|
],
|
|
171
300
|
});
|
|
172
301
|
conversation.pending = null;
|
|
173
|
-
|
|
302
|
+
conversation.status = "idle"; // answered; the save below records that
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
// inform: enriches the conversation without having blocked it
|
|
306
|
+
conversation.messages.push({ role: "user", content: `[UI interaction] ${label}` });
|
|
174
307
|
}
|
|
175
|
-
//
|
|
308
|
+
// Commit the click before the model runs. The handler may have written,
|
|
309
|
+
// and a model turn can outlast the lease; saved now, the click stays on
|
|
310
|
+
// record however the turn ends, so it cannot be answered — and its handler
|
|
311
|
+
// run — a second time. The save is fenced: if a newer request took the
|
|
312
|
+
// conversation over while the handler ran, this stops here, and the model
|
|
313
|
+
// never runs.
|
|
314
|
+
//
|
|
315
|
+
// If the save fails, the click is undone here too, because the route still
|
|
316
|
+
// saves on the way out, to release the lease. Left in place, a click the
|
|
317
|
+
// browser was told had failed could be recorded by that save anyway, with
|
|
318
|
+
// no model turn and a surface nobody can click again. Undone, the record
|
|
319
|
+
// matches what the browser shows, and the user can simply click again.
|
|
320
|
+
try {
|
|
321
|
+
await this.config.store.saveConversation(conversation);
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
conversation.messages.length = before.messages;
|
|
325
|
+
conversation.frozen.length = before.frozen;
|
|
326
|
+
conversation.pending = pending;
|
|
327
|
+
conversation.status = before.status;
|
|
328
|
+
throw err;
|
|
329
|
+
}
|
|
330
|
+
if (pending)
|
|
331
|
+
emit({ type: "ui_state", handle: input.handle, state: "frozen", selection: value });
|
|
176
332
|
emit({ type: "block_start", block: { kind: "interaction", id: this.nid("b"), handle: input.handle, label } });
|
|
177
|
-
conversation.messages.push({ role: "user", content: `[UI interaction] ${label}` });
|
|
178
333
|
return this.runTurn(conversation, emit);
|
|
179
334
|
}
|
|
180
335
|
/**
|
|
@@ -241,7 +396,7 @@ export class Hai {
|
|
|
241
396
|
emit({ type: "status", status: "streaming" });
|
|
242
397
|
const toolDefs = [...this.tools.values()].map((t) => ({
|
|
243
398
|
name: t.name,
|
|
244
|
-
description: t.description,
|
|
399
|
+
description: t === this.config.init ? `${t.description}\n\n${INIT_NOTE}` : t.description,
|
|
245
400
|
input_schema: t.inputJsonSchema,
|
|
246
401
|
strict: t.strict,
|
|
247
402
|
}));
|
|
@@ -297,10 +452,20 @@ export class Hai {
|
|
|
297
452
|
emit({ type: "status", status: "idle" });
|
|
298
453
|
await this.emitContext(conversation, emit);
|
|
299
454
|
}
|
|
300
|
-
async invokeTool(conversation, call, emit, toolBlockId
|
|
455
|
+
async invokeTool(conversation, call, emit, toolBlockId,
|
|
456
|
+
// the runtime's own start-of-conversation call: failures throw instead of
|
|
457
|
+
// becoming a result for the model, because there is no model turn yet
|
|
458
|
+
options = {}) {
|
|
301
459
|
const tool = this.tools.get(call.name);
|
|
302
460
|
if (!tool)
|
|
303
461
|
return { ret: { model: `Unknown tool: ${call.name}` }, mode: null };
|
|
462
|
+
// the model calling init again: it ran at the start, and does not run twice
|
|
463
|
+
if (tool === this.config.init && !options.init) {
|
|
464
|
+
return {
|
|
465
|
+
ret: { model: `${tool.name} already ran at the start of this conversation; its result is above.` },
|
|
466
|
+
mode: null,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
304
469
|
let mode = null;
|
|
305
470
|
const ctx = {
|
|
306
471
|
conversationId: conversation.id,
|
|
@@ -344,6 +509,8 @@ export class Hai {
|
|
|
344
509
|
input = tool.input.parse(call.input);
|
|
345
510
|
}
|
|
346
511
|
catch (err) {
|
|
512
|
+
if (options.init)
|
|
513
|
+
throw err;
|
|
347
514
|
return { ret: { model: `Invalid input for ${call.name}: ${err.message}` }, mode: null };
|
|
348
515
|
}
|
|
349
516
|
try {
|
|
@@ -351,6 +518,8 @@ export class Hai {
|
|
|
351
518
|
return { ret, mode };
|
|
352
519
|
}
|
|
353
520
|
catch (err) {
|
|
521
|
+
if (options.init)
|
|
522
|
+
throw err;
|
|
354
523
|
// A tool error is information for the model; a lost lease is not. Fencing
|
|
355
524
|
// exists so a superseded turn stops — converting StaleLease into "tool
|
|
356
525
|
// failed" would hand it back to the model and keep paying for hops whose
|
|
@@ -411,6 +580,7 @@ function strictest(recorded, current) {
|
|
|
411
580
|
const finite = known.filter((w) => w !== "never");
|
|
412
581
|
return finite.length ? Math.min(...finite) : "never";
|
|
413
582
|
}
|
|
583
|
+
const newId = () => globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, 16);
|
|
414
584
|
/** "2 hours", "15 minutes" — for a sentence a person reads. */
|
|
415
585
|
function duration(ms) {
|
|
416
586
|
const units = [
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,EACZ,OAAO,GASR,MAAM,cAAc,CAAC;AAYtB,MAAM,OAAO,GAAG;IACL,MAAM,CAAY;IACV,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC7C,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IACzC,GAAG,GAAG,CAAC,CAAC;IAEhB,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YAChC,WAAW,CAAC,CAAC,CAAC,CAAC;YACf,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC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AAC,EAAE,CAAC;YAC5E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBAAE,OAAO,GAAG,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haikit/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The haikit server runtime: agent loop, elicit state machine, derived query_ui, and the interaction security boundary.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"haikit",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepack": "npm --prefix ../.. run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@haikit/core": "0.
|
|
39
|
+
"@haikit/core": "0.6.0",
|
|
40
40
|
"@types/node": ">=22"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
package/src/routes.ts
CHANGED
|
@@ -4,9 +4,11 @@ import type { Emit, WireEvent } from "@haikit/core";
|
|
|
4
4
|
import type { Hai } from "./runtime.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Node http handler for the
|
|
7
|
+
* Node http handler for the three routes. Returns true if it handled the
|
|
8
|
+
* request.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* All three stream SSE: chat and interact because both can resume the agent
|
|
11
|
+
* loop, start because the init tool it runs can render surfaces. Note what the
|
|
10
12
|
* interact route accepts: {handle, action, value} and nothing else. The client
|
|
11
13
|
* cannot name a tool, a handler, or an action target.
|
|
12
14
|
*/
|
|
@@ -16,10 +18,19 @@ export function nodeHandler(hai: Hai, basePath = "/hai") {
|
|
|
16
18
|
if (req.method !== "POST" || !url.pathname.startsWith(basePath)) return false;
|
|
17
19
|
|
|
18
20
|
const route = url.pathname.slice(basePath.length);
|
|
19
|
-
if (route !== "/chat" && route !== "/interact") return false;
|
|
21
|
+
if (route !== "/chat" && route !== "/interact" && route !== "/start") return false;
|
|
20
22
|
|
|
21
23
|
const body = await readJson(req);
|
|
22
24
|
|
|
25
|
+
// Nothing to run before the first message: answer with an empty stream and
|
|
26
|
+
// create no conversation, so an app without init doesn't get one for every
|
|
27
|
+
// page view. Its first message starts the conversation, as it always has.
|
|
28
|
+
if (route === "/start" && !hai.config.init) {
|
|
29
|
+
openSSE(res);
|
|
30
|
+
res.end();
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
// Before the SSE stream opens, because a rejected load has no stream to
|
|
24
35
|
// report into — and an uncaught throw here would take down the request.
|
|
25
36
|
let conversation;
|
|
@@ -33,7 +44,7 @@ export function nodeHandler(hai: Hai, basePath = "/hai") {
|
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
const emit = openSSE(res);
|
|
36
|
-
if (route === "/chat") {
|
|
47
|
+
if (route === "/chat" || route === "/start") {
|
|
37
48
|
emit({ type: "hello", conversationId: conversation.id, model: hai.config.model.id });
|
|
38
49
|
}
|
|
39
50
|
|
|
@@ -41,6 +52,8 @@ export function nodeHandler(hai: Hai, basePath = "/hai") {
|
|
|
41
52
|
try {
|
|
42
53
|
if (route === "/chat") {
|
|
43
54
|
await hai.send(conversation, String(body.message ?? ""), emit);
|
|
55
|
+
} else if (route === "/start") {
|
|
56
|
+
await hai.start(conversation, emit);
|
|
44
57
|
} else {
|
|
45
58
|
await hai.interact(
|
|
46
59
|
conversation,
|
package/src/runtime.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
type Tool,
|
|
11
11
|
type ToolCtx,
|
|
12
12
|
type ToolReturn,
|
|
13
|
+
type WireEvent,
|
|
13
14
|
} from "@haikit/core";
|
|
14
15
|
|
|
15
16
|
export interface HaiConfig {
|
|
@@ -20,8 +21,36 @@ export interface HaiConfig {
|
|
|
20
21
|
surfaces: AnySurfaceImpl[];
|
|
21
22
|
/** Guard against runaway tool loops. */
|
|
22
23
|
maxHops?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Runs at the start of every conversation, before the user's first message
|
|
26
|
+
* when the client calls `start()` (the default UI does, on open), otherwise
|
|
27
|
+
* with that first message. Either way it runs before the model's first turn.
|
|
28
|
+
* The runtime makes the call, not the model, so it cannot be skipped: the
|
|
29
|
+
* call and its result are recorded as if the model had made them. It
|
|
30
|
+
* receives `{}` as input and may render surfaces — an elicit surface parks
|
|
31
|
+
* the conversation before the model runs at all.
|
|
32
|
+
*
|
|
33
|
+
* If it throws, the request is refused and nothing is recorded, so the next
|
|
34
|
+
* message tries again. It stays in the model's tool list for the whole
|
|
35
|
+
* conversation — changing that list mid-conversation invalidates the
|
|
36
|
+
* model's earlier reasoning on newer models — but a later call from the
|
|
37
|
+
* model gets "already ran" back instead of running it again.
|
|
38
|
+
*/
|
|
39
|
+
init?: Tool;
|
|
23
40
|
}
|
|
24
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Opens the history when init runs before the user has said anything: the
|
|
44
|
+
* Messages API requires the first message to be the user's. Bracketed like
|
|
45
|
+
* `[UI interaction]` — framework text, not something the user typed.
|
|
46
|
+
*/
|
|
47
|
+
const STARTED = "[conversation started]";
|
|
48
|
+
|
|
49
|
+
/** Appended to the init tool's description in what the model sees. */
|
|
50
|
+
const INIT_NOTE =
|
|
51
|
+
"This ran automatically at the start of the conversation, and its result is already above. " +
|
|
52
|
+
"Calling it again does not run it.";
|
|
53
|
+
|
|
25
54
|
export class Hai {
|
|
26
55
|
readonly config: HaiConfig;
|
|
27
56
|
private readonly surfaces = new Map<string, AnySurfaceImpl>();
|
|
@@ -39,6 +68,13 @@ export class Hai {
|
|
|
39
68
|
// that actually exist, and it always exists.
|
|
40
69
|
const queryUi = this.buildQueryUiTool();
|
|
41
70
|
this.tools.set(queryUi.name, queryUi);
|
|
71
|
+
|
|
72
|
+
if (config.init) {
|
|
73
|
+
if (this.tools.has(config.init.name)) {
|
|
74
|
+
throw new Error(`init tool "${config.init.name}" has the same name as another tool`);
|
|
75
|
+
}
|
|
76
|
+
this.tools.set(config.init.name, config.init);
|
|
77
|
+
}
|
|
42
78
|
}
|
|
43
79
|
|
|
44
80
|
private nid(prefix: string) {
|
|
@@ -132,6 +168,9 @@ export class Hai {
|
|
|
132
168
|
async send(conversation: Conversation, text: string, emit: Emit): Promise<void> {
|
|
133
169
|
if (await this.refuseIfExpired(conversation, emit)) return;
|
|
134
170
|
|
|
171
|
+
// The first message is the one that starts the conversation.
|
|
172
|
+
const starting = conversation.messages.length === 0;
|
|
173
|
+
|
|
135
174
|
// The user typed while a tool was parked. Every tool_use in a turn must
|
|
136
175
|
// receive a tool_result, so close the pending one out honestly first.
|
|
137
176
|
if (conversation.status === "awaiting" && conversation.pending) {
|
|
@@ -155,10 +194,100 @@ export class Hai {
|
|
|
155
194
|
}
|
|
156
195
|
|
|
157
196
|
emit({ type: "block_start", block: { kind: "user", id: this.nid("b"), text } });
|
|
158
|
-
|
|
197
|
+
if (starting && this.config.init) {
|
|
198
|
+
if (await this.runInit(conversation, text, emit)) return; // parked on its surface
|
|
199
|
+
} else {
|
|
200
|
+
conversation.messages.push({ role: "user", content: text });
|
|
201
|
+
}
|
|
159
202
|
await this.runTurn(conversation, emit);
|
|
160
203
|
}
|
|
161
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Start a conversation before the user has typed anything, so init's result
|
|
207
|
+
* — and any surface it shows — is already there when the first message
|
|
208
|
+
* arrives. The model does not run. Does nothing without an init tool, or
|
|
209
|
+
* once the conversation has begun.
|
|
210
|
+
*/
|
|
211
|
+
async start(conversation: Conversation, emit: Emit): Promise<void> {
|
|
212
|
+
if (!this.config.init || conversation.messages.length > 0) return;
|
|
213
|
+
if (await this.runInit(conversation, STARTED, emit)) return; // parked on its surface
|
|
214
|
+
conversation.status = "idle";
|
|
215
|
+
emit({ type: "status", status: "idle" });
|
|
216
|
+
await this.emitContext(conversation, emit);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Run the init tool as the conversation's first tool call, after `text` —
|
|
221
|
+
* the user's first message, or STARTED when it runs before one. Returns
|
|
222
|
+
* true when it parked the conversation on an elicit surface.
|
|
223
|
+
*
|
|
224
|
+
* Nothing reaches the history until the tool has succeeded — not even the
|
|
225
|
+
* user's message — so a refused start leaves the conversation exactly as
|
|
226
|
+
* the route found it, and the next message starts it again.
|
|
227
|
+
*/
|
|
228
|
+
private async runInit(conversation: Conversation, text: string, emit: Emit): Promise<boolean> {
|
|
229
|
+
const init = this.config.init!;
|
|
230
|
+
const call = { type: "tool_use", id: `toolu_init_${newId()}`, name: init.name, input: {} };
|
|
231
|
+
const toolBlockId = this.nid("b");
|
|
232
|
+
const before = { handles: conversation.handles.length, status: conversation.status };
|
|
233
|
+
|
|
234
|
+
conversation.status = "streaming";
|
|
235
|
+
emit({ type: "status", status: "streaming" });
|
|
236
|
+
emit({ type: "block_start", block: { kind: "tool", id: toolBlockId, name: init.name, input: {}, status: "running" } });
|
|
237
|
+
|
|
238
|
+
// Surfaces are held until init succeeds. One shown by a start that is then
|
|
239
|
+
// refused would look live in the browser, and every click on it would be
|
|
240
|
+
// rejected: its handle never reaches the history.
|
|
241
|
+
const held: WireEvent[] = [];
|
|
242
|
+
const hold: Emit = (e) => {
|
|
243
|
+
if (e.type === "ui_open" || e.type === "ui_props") held.push(e);
|
|
244
|
+
else emit(e);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const started = Date.now();
|
|
248
|
+
let outcome: { ret: ToolReturn; mode: "display" | "elicit" | null };
|
|
249
|
+
try {
|
|
250
|
+
outcome = await this.invokeTool(conversation, call, hold, toolBlockId, { init: true });
|
|
251
|
+
} catch (err) {
|
|
252
|
+
// undo what the tool's renders recorded; their payload rows are orphans
|
|
253
|
+
conversation.handles.length = before.handles;
|
|
254
|
+
conversation.status = before.status;
|
|
255
|
+
if (isStaleLease(err)) throw err;
|
|
256
|
+
const message = `initialisation failed: ${(err as Error).message}`;
|
|
257
|
+
emit({ type: "block_update", id: toolBlockId, status: "error", ms: Date.now() - started, result: message });
|
|
258
|
+
throw new Error(message);
|
|
259
|
+
}
|
|
260
|
+
const { ret, mode } = outcome;
|
|
261
|
+
const ms = Date.now() - started;
|
|
262
|
+
for (const e of held) emit(e);
|
|
263
|
+
|
|
264
|
+
conversation.messages.push({ role: "user", content: text });
|
|
265
|
+
conversation.messages.push({ role: "assistant", content: [call] });
|
|
266
|
+
|
|
267
|
+
if (mode === "elicit" && ret.handle) {
|
|
268
|
+
emit({ type: "block_update", id: toolBlockId, status: "awaiting", ms, result: ret.model });
|
|
269
|
+
conversation.status = "awaiting";
|
|
270
|
+
conversation.pending = { toolUseId: call.id, handle: ret.handle, digest: ret.model, results: [] };
|
|
271
|
+
emit({ type: "status", status: "awaiting" });
|
|
272
|
+
await this.emitContext(conversation, emit);
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
emit({ type: "block_update", id: toolBlockId, status: "ok", ms, result: ret.model });
|
|
277
|
+
conversation.messages.push({
|
|
278
|
+
role: "user",
|
|
279
|
+
content: [{ type: "tool_result", tool_use_id: call.id, content: ret.model }],
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// Commit before the model runs. An init that only returns text makes no
|
|
283
|
+
// fenced write of its own, so a request that outlived its lease while init
|
|
284
|
+
// ran would otherwise go on to call the model for a history its final save
|
|
285
|
+
// will lose. This save is fenced: it throws StaleLease if another request
|
|
286
|
+
// has taken the conversation over, and the model never runs here.
|
|
287
|
+
await this.config.store.saveConversation(conversation);
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
|
|
162
291
|
async interact(
|
|
163
292
|
conversation: Conversation,
|
|
164
293
|
input: { handle: string; action: string; value: unknown },
|
|
@@ -194,34 +323,79 @@ export class Hai {
|
|
|
194
323
|
throw new Error(`invalid action payload: ${(err as Error).message}`);
|
|
195
324
|
}
|
|
196
325
|
|
|
197
|
-
|
|
326
|
+
// Gated before the handler runs, because a handler may write: only a click
|
|
327
|
+
// this request is going to record can reach it. A resolve answers the
|
|
328
|
+
// question the turn is waiting on and nothing else. An inform adds a user
|
|
329
|
+
// message, and while a turn waits that would land after a tool_use with no
|
|
330
|
+
// tool_result yet — a history the API refuses.
|
|
331
|
+
const pending = conversation.pending;
|
|
332
|
+
if (spec.kind === "resolve" && pending?.handle !== input.handle) {
|
|
333
|
+
throw new Error("nothing awaiting this handle");
|
|
334
|
+
}
|
|
335
|
+
if (spec.kind === "inform" && pending) throw new Error("a question is waiting to be answered first");
|
|
198
336
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
337
|
+
// Nothing is recorded until the handler has succeeded, so one that throws
|
|
338
|
+
// refuses the click and leaves the surface live to be clicked again.
|
|
339
|
+
let label: string;
|
|
340
|
+
try {
|
|
341
|
+
label = await handler(value, { props: record.props, handle: record.handle, conversationId: conversation.id });
|
|
342
|
+
} catch (err) {
|
|
343
|
+
throw new Error(`action failed: ${(err as Error).message}`);
|
|
344
|
+
}
|
|
204
345
|
|
|
346
|
+
// what recording the click changes, so a failed save below can undo it
|
|
347
|
+
const before = {
|
|
348
|
+
messages: conversation.messages.length,
|
|
349
|
+
frozen: conversation.frozen.length,
|
|
350
|
+
status: conversation.status,
|
|
351
|
+
};
|
|
352
|
+
if (pending) {
|
|
353
|
+
// resolve: the gate above let it through only for the waiting surface
|
|
354
|
+
conversation.frozen.push(input.handle);
|
|
205
355
|
conversation.messages.push({
|
|
206
356
|
role: "user",
|
|
207
357
|
content: [
|
|
208
|
-
...
|
|
358
|
+
...pending.results,
|
|
209
359
|
{
|
|
210
360
|
type: "tool_result",
|
|
211
|
-
tool_use_id:
|
|
361
|
+
tool_use_id: pending.toolUseId,
|
|
212
362
|
// The digest rides along: this elicit tool never got a tool_result,
|
|
213
363
|
// so nothing about the search has reached the model yet.
|
|
214
|
-
content: `${
|
|
364
|
+
content: `${pending.digest}\n${label}`,
|
|
215
365
|
},
|
|
216
366
|
],
|
|
217
367
|
});
|
|
218
368
|
conversation.pending = null;
|
|
219
|
-
|
|
369
|
+
conversation.status = "idle"; // answered; the save below records that
|
|
370
|
+
} else {
|
|
371
|
+
// inform: enriches the conversation without having blocked it
|
|
372
|
+
conversation.messages.push({ role: "user", content: `[UI interaction] ${label}` });
|
|
220
373
|
}
|
|
221
374
|
|
|
222
|
-
//
|
|
375
|
+
// Commit the click before the model runs. The handler may have written,
|
|
376
|
+
// and a model turn can outlast the lease; saved now, the click stays on
|
|
377
|
+
// record however the turn ends, so it cannot be answered — and its handler
|
|
378
|
+
// run — a second time. The save is fenced: if a newer request took the
|
|
379
|
+
// conversation over while the handler ran, this stops here, and the model
|
|
380
|
+
// never runs.
|
|
381
|
+
//
|
|
382
|
+
// If the save fails, the click is undone here too, because the route still
|
|
383
|
+
// saves on the way out, to release the lease. Left in place, a click the
|
|
384
|
+
// browser was told had failed could be recorded by that save anyway, with
|
|
385
|
+
// no model turn and a surface nobody can click again. Undone, the record
|
|
386
|
+
// matches what the browser shows, and the user can simply click again.
|
|
387
|
+
try {
|
|
388
|
+
await this.config.store.saveConversation(conversation);
|
|
389
|
+
} catch (err) {
|
|
390
|
+
conversation.messages.length = before.messages;
|
|
391
|
+
conversation.frozen.length = before.frozen;
|
|
392
|
+
conversation.pending = pending;
|
|
393
|
+
conversation.status = before.status;
|
|
394
|
+
throw err;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (pending) emit({ type: "ui_state", handle: input.handle, state: "frozen", selection: value });
|
|
223
398
|
emit({ type: "block_start", block: { kind: "interaction", id: this.nid("b"), handle: input.handle, label } });
|
|
224
|
-
conversation.messages.push({ role: "user", content: `[UI interaction] ${label}` });
|
|
225
399
|
return this.runTurn(conversation, emit);
|
|
226
400
|
}
|
|
227
401
|
|
|
@@ -292,7 +466,7 @@ export class Hai {
|
|
|
292
466
|
|
|
293
467
|
const toolDefs = [...this.tools.values()].map((t) => ({
|
|
294
468
|
name: t.name,
|
|
295
|
-
description: t.description,
|
|
469
|
+
description: t === this.config.init ? `${t.description}\n\n${INIT_NOTE}` : t.description,
|
|
296
470
|
input_schema: t.inputJsonSchema,
|
|
297
471
|
strict: t.strict,
|
|
298
472
|
}));
|
|
@@ -362,10 +536,21 @@ export class Hai {
|
|
|
362
536
|
call: any,
|
|
363
537
|
emit: Emit,
|
|
364
538
|
toolBlockId: string,
|
|
539
|
+
// the runtime's own start-of-conversation call: failures throw instead of
|
|
540
|
+
// becoming a result for the model, because there is no model turn yet
|
|
541
|
+
options: { init?: boolean } = {},
|
|
365
542
|
): Promise<{ ret: ToolReturn; mode: "display" | "elicit" | null }> {
|
|
366
543
|
const tool = this.tools.get(call.name);
|
|
367
544
|
if (!tool) return { ret: { model: `Unknown tool: ${call.name}` }, mode: null };
|
|
368
545
|
|
|
546
|
+
// the model calling init again: it ran at the start, and does not run twice
|
|
547
|
+
if (tool === this.config.init && !options.init) {
|
|
548
|
+
return {
|
|
549
|
+
ret: { model: `${tool.name} already ran at the start of this conversation; its result is above.` },
|
|
550
|
+
mode: null,
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
|
|
369
554
|
let mode: "display" | "elicit" | null = null;
|
|
370
555
|
|
|
371
556
|
const ctx: ToolCtx = {
|
|
@@ -418,6 +603,7 @@ export class Hai {
|
|
|
418
603
|
try {
|
|
419
604
|
input = tool.input.parse(call.input);
|
|
420
605
|
} catch (err) {
|
|
606
|
+
if (options.init) throw err;
|
|
421
607
|
return { ret: { model: `Invalid input for ${call.name}: ${(err as Error).message}` }, mode: null };
|
|
422
608
|
}
|
|
423
609
|
|
|
@@ -425,6 +611,7 @@ export class Hai {
|
|
|
425
611
|
const ret = await tool.run(input, ctx);
|
|
426
612
|
return { ret, mode };
|
|
427
613
|
} catch (err) {
|
|
614
|
+
if (options.init) throw err;
|
|
428
615
|
// A tool error is information for the model; a lost lease is not. Fencing
|
|
429
616
|
// exists so a superseded turn stops — converting StaleLease into "tool
|
|
430
617
|
// failed" would hand it back to the model and keep paying for hops whose
|
|
@@ -490,6 +677,8 @@ function strictest(recorded: unknown, current: unknown): number | "never" | unde
|
|
|
490
677
|
return finite.length ? Math.min(...finite) : "never";
|
|
491
678
|
}
|
|
492
679
|
|
|
680
|
+
const newId = () => globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, 16);
|
|
681
|
+
|
|
493
682
|
/** "2 hours", "15 minutes" — for a sentence a person reads. */
|
|
494
683
|
function duration(ms: number): string {
|
|
495
684
|
const units: [number, string][] = [
|