@gemies/sdk 10.5.0 → 10.7.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 10.7.0
|
|
4
|
+
|
|
5
|
+
### A turn is sent once
|
|
6
|
+
|
|
7
|
+
Every chat turn request now carries an `Idempotency-Key` equal to the turn's own id, the id the
|
|
8
|
+
server already names the turn by. A request that reaches the API twice (a replay after a token
|
|
9
|
+
refresh, a dropped response, a retry through another instance) starts the turn once. When the server
|
|
10
|
+
answers the second one from its receipt (`Idempotency-Replayed: true`), the SDK resumes the first
|
|
11
|
+
request's stream (`GET /v1/chat/turns/:turnId/stream`, 10.3.0) from its beginning. If that stream
|
|
12
|
+
cannot be followed to its end, the person's message is kept and no Retry is offered, since it would
|
|
13
|
+
send the message again. Requires the API of ADR 0049, which lists the header in CORS and answers
|
|
14
|
+
the replay.
|
|
15
|
+
|
|
16
|
+
## 10.6.0
|
|
17
|
+
|
|
18
|
+
`isDeviceModelId` also accepts `computer/<model>`, the ChatGPT on the person's own computer that
|
|
19
|
+
Gemies lists with their device models when it is switched on and its daemon is connected: it is
|
|
20
|
+
kept as the choice while connected and replaced by `auto` when it is not, like a `local/` model.
|
|
21
|
+
|
|
3
22
|
## 10.5.0
|
|
4
23
|
|
|
5
24
|
### A coding agent's work, as one row, with a command's output
|
package/package.json
CHANGED
|
@@ -22,9 +22,16 @@ export function isPowerLevel(value: unknown): value is PowerLevel {
|
|
|
22
22
|
return typeof value === 'string' && (POWER_LEVELS as readonly string[]).includes(value);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* A model served by one of the person's own devices: `local/<runtime>/<model>`, or the ChatGPT on
|
|
27
|
+
* their computer that Gemies offers when its daemon is connected (`computer/chatgpt`, ADR 0047).
|
|
28
|
+
*/
|
|
26
29
|
export function isDeviceModelId(value: unknown): value is string {
|
|
27
|
-
return
|
|
30
|
+
return (
|
|
31
|
+
typeof value === 'string' &&
|
|
32
|
+
((value.startsWith('local/') && value.length > 'local/'.length) ||
|
|
33
|
+
(value.startsWith('computer/') && value.length > 'computer/'.length))
|
|
34
|
+
);
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
export interface ModeSelection {
|
|
@@ -72,8 +72,12 @@ function sleepUnlessAborted(ms: number, signal: AbortSignal): Promise<void> {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
export interface ResumableFrameSourceOptions {
|
|
75
|
-
/**
|
|
76
|
-
|
|
75
|
+
/**
|
|
76
|
+
* The turn's first response, already known to be `ok` with a body; or null when the server said it
|
|
77
|
+
* already has this turn (ADR 0049) and there is no first stream: reading starts by resuming it
|
|
78
|
+
* from its first frame.
|
|
79
|
+
*/
|
|
80
|
+
response: Response | null;
|
|
77
81
|
/** Open the turn's stream again, after the frame numbered `cursor`. */
|
|
78
82
|
reconnect(cursor: number, signal: AbortSignal): Promise<Response>;
|
|
79
83
|
/** The turn's own signal: a Stop or a detach ends the stream, never a resume. */
|
|
@@ -176,7 +180,7 @@ export function createResumableFrameSource(
|
|
|
176
180
|
else options.signal.addEventListener('abort', followTurn, { once: true });
|
|
177
181
|
const { signal } = lifetime;
|
|
178
182
|
|
|
179
|
-
let reader = options.response
|
|
183
|
+
let reader = options.response?.body?.getReader();
|
|
180
184
|
let decoder = new TextDecoder();
|
|
181
185
|
let frames = createSseFrameReader();
|
|
182
186
|
/** The number of the newest frame passed on. */
|
|
@@ -277,17 +281,20 @@ export function createResumableFrameSource(
|
|
|
277
281
|
while (true) {
|
|
278
282
|
failure = undefined;
|
|
279
283
|
try {
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
284
|
+
if (reader) {
|
|
285
|
+
const { done, value } = await reader.read();
|
|
286
|
+
if (!done) {
|
|
287
|
+
const accepted = accept(frames.push(decoder.decode(value, { stream: true })));
|
|
288
|
+
if (accepted.length > 0) {
|
|
289
|
+
attempts = 0;
|
|
290
|
+
return { done: false, frames: accepted };
|
|
291
|
+
}
|
|
292
|
+
continue;
|
|
287
293
|
}
|
|
288
|
-
|
|
294
|
+
if (sawTerminal) return { done: true };
|
|
295
|
+
} else if (options.response !== null) {
|
|
296
|
+
return { done: true };
|
|
289
297
|
}
|
|
290
|
-
if (sawTerminal) return { done: true };
|
|
291
298
|
} catch (error) {
|
|
292
299
|
if (signal.aborted) throw error;
|
|
293
300
|
failure = error;
|
|
@@ -817,6 +817,9 @@ export function useConversationStream({
|
|
|
817
817
|
...appAssertion,
|
|
818
818
|
Accept: 'text/event-stream',
|
|
819
819
|
'Content-Type': 'application/json',
|
|
820
|
+
// This action's id, the one the turn is named by: a request that reaches the server
|
|
821
|
+
// twice (a replay after a token refresh, a network retry) starts the turn once.
|
|
822
|
+
'Idempotency-Key': turnControl.id,
|
|
820
823
|
...(deviceInfo === undefined ? {} : { 'X-Device-Info': JSON.stringify(deviceInfo) }),
|
|
821
824
|
},
|
|
822
825
|
body: JSON.stringify({
|
|
@@ -942,7 +945,13 @@ export function useConversationStream({
|
|
|
942
945
|
throw new Error(errorMessage);
|
|
943
946
|
}
|
|
944
947
|
|
|
945
|
-
|
|
948
|
+
// The server already has this very turn: this request reached it twice, and it ran nothing
|
|
949
|
+
// again (ADR 0049). The answer is the first request's, so it is read by resuming that turn
|
|
950
|
+
// rather than from this response, which carries only its receipt.
|
|
951
|
+
const replayed = response.headers.get('Idempotency-Replayed') === 'true';
|
|
952
|
+
if (replayed) {
|
|
953
|
+
await response.body?.cancel();
|
|
954
|
+
} else if (!response.body) {
|
|
946
955
|
throw new Error('No response received from server');
|
|
947
956
|
}
|
|
948
957
|
setComposerPhase('streaming');
|
|
@@ -967,7 +976,7 @@ export function useConversationStream({
|
|
|
967
976
|
const turnId = turnControl.id;
|
|
968
977
|
const client = linked.client;
|
|
969
978
|
const source = createResumableFrameSource({
|
|
970
|
-
response,
|
|
979
|
+
response: replayed ? null : response,
|
|
971
980
|
signal: controller.signal,
|
|
972
981
|
reconnect: async (cursor, signal) =>
|
|
973
982
|
client.requestAuthenticatedResponse({
|
|
@@ -993,6 +1002,16 @@ export function useConversationStream({
|
|
|
993
1002
|
// Flush any remaining batched content before checking
|
|
994
1003
|
flushPendingUpdates();
|
|
995
1004
|
|
|
1005
|
+
// A turn the server already had, whose stream cannot be followed to its end (a group
|
|
1006
|
+
// room has none to resume). The message did reach the server, so it is kept and offered
|
|
1007
|
+
// no Retry, which would send it a second time.
|
|
1008
|
+
if (replayed && !sawTerminal) {
|
|
1009
|
+
setError(
|
|
1010
|
+
new Error('This message was already received; its answer will appear here.'),
|
|
1011
|
+
);
|
|
1012
|
+
return keepFailedTurn(false);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
996
1015
|
// The server answered with a stand-in, or with nothing usable at
|
|
997
1016
|
// all: the turn stays, with the error under it. (With real output
|
|
998
1017
|
// AND a synthetic tail, this keeps the output and marks the tail.)
|