@haikit/client 0.5.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/package.json +1 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +14 -4
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -114,8 +114,9 @@ export interface Chat {
|
|
|
114
114
|
/**
|
|
115
115
|
* Start the conversation before the user types, so a server with an init
|
|
116
116
|
* tool runs it now and anything it shows is already there. Does nothing once
|
|
117
|
-
*
|
|
118
|
-
* nothing.
|
|
117
|
+
* the conversation has begun, and a server without an init tool creates
|
|
118
|
+
* nothing. If init throws, nothing is recorded, so calling it again tries
|
|
119
|
+
* again. `mountChat` calls it when it opens and after `reset()`.
|
|
119
120
|
*/
|
|
120
121
|
start(): Promise<boolean>;
|
|
121
122
|
interact(handle: string, action: string, value: unknown): Promise<void>;
|
package/src/index.js
CHANGED
|
@@ -332,15 +332,25 @@ export function createChat({ endpoint = "/hai", registry }) {
|
|
|
332
332
|
return enqueue("/chat", { message: text });
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Whether the server has recorded this conversation's opening — init's call,
|
|
337
|
+
* or a first message — as its last `context` shows. Having a conversation id
|
|
338
|
+
* is not enough: `hello` arrives before init runs, and an init that throws
|
|
339
|
+
* leaves the id behind with an empty history.
|
|
340
|
+
*/
|
|
341
|
+
const begun = () => state.context.messages.length > 0;
|
|
342
|
+
|
|
335
343
|
/**
|
|
336
344
|
* Start the conversation before the user types, so a server with an init
|
|
337
345
|
* tool runs it now and whatever it shows is there first. Does nothing once
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
346
|
+
* the conversation has begun. If init throws, the server records nothing,
|
|
347
|
+
* so calling this again tries again — as the first message would. A server
|
|
348
|
+
* without an init tool answers with an empty stream and creates nothing;
|
|
349
|
+
* the first message starts the conversation, as it always has. Resolves
|
|
350
|
+
* like send().
|
|
341
351
|
*/
|
|
342
352
|
async function start() {
|
|
343
|
-
if (
|
|
353
|
+
if (begun() || closed()) return false;
|
|
344
354
|
return enqueue("/start", {});
|
|
345
355
|
}
|
|
346
356
|
|