@gemies/sdk 10.10.0 → 10.11.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,15 @@
1
1
  # @gemies/sdk
2
2
 
3
+ ## 10.11.0
4
+
5
+ ### Error rows name the request
6
+
7
+ Every error body and stream error frame of the API now carries `traceId`, the id its logs are
8
+ written under (for a chat turn, the same value as the run `reference`). The line under a failed
9
+ turn ends in `Ref <id>` for a refused request too, after the server's message, and for a request
10
+ that failed outside the turn (`Something went wrong! · Ref req_…`). A turn that failed still reads
11
+ `CODE · Ref <reference>`. `failureDetail` (`@gemies/sdk/model`) takes `message` and `traceId`.
12
+
3
13
  ## 10.10.0
4
14
 
5
15
  ### Comments on diff lines go with the next message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gemies/sdk",
3
- "version": "10.10.0",
3
+ "version": "10.11.0",
4
4
  "description": "The Gemies SDK: the conversation runtime, chat UI, voice calls and dictation for Oxy apps that talk to a gemie",
5
5
  "main": "src/index.ts",
6
6
  "react-native": "src/index.ts",
@@ -91,17 +91,34 @@ export function readGemieMeta(chunk: unknown): GemieMeta {
91
91
  }
92
92
 
93
93
  /**
94
- * The line under a failed turn's card: the stable code and the run reference.
94
+ * The trace id of an error body or frame: `error.traceId` in the OpenAI shape, or beside an
95
+ * `error` that is a string.
96
+ */
97
+ export function traceIdOf(body: unknown): string | undefined {
98
+ const outer = body as { error?: unknown; traceId?: unknown } | null | undefined;
99
+ const inner = outer?.error as { traceId?: unknown } | null | undefined;
100
+ const id = inner?.traceId ?? outer?.traceId;
101
+ return typeof id === 'string' && id !== '' ? id : undefined;
102
+ }
103
+
104
+ /**
105
+ * The line under a failed turn's card: what failed, and the id support can trace it by.
95
106
  *
96
- * Never the server's prose. The card's own line is the app's, in the reader's
97
- * language; this is what support needs, and both halves are language-free.
98
- * Empty when the server sent neither.
107
+ * A turn that failed carries a run `reference`, and its line is the stable code and that
108
+ * reference, never the server's prose: the card's own line is the app's, in the reader's
109
+ * language, and this half is language-free. A refusal has no `reference`; its `message` says
110
+ * what to change, so it is kept, followed by the id of the request (`traceId`) when the server
111
+ * sent one. Empty when there is nothing to say.
99
112
  */
100
- export function failureDetail(failure: { code?: string; reference?: string }): string | undefined {
101
- const detail = [
102
- failure.code,
103
- failure.reference === undefined ? undefined : `Ref ${failure.reference}`,
104
- ]
113
+ export function failureDetail(failure: {
114
+ code?: string;
115
+ reference?: string;
116
+ message?: string;
117
+ traceId?: string;
118
+ }): string | undefined {
119
+ const lead = failure.reference === undefined && failure.message ? failure.message : failure.code;
120
+ const id = failure.reference ?? failure.traceId;
121
+ const detail = [lead, id ? `Ref ${id}` : undefined]
105
122
  .filter((value): value is string => typeof value === 'string' && value !== '')
106
123
  .join(' · ');
107
124
  return detail === '' ? undefined : detail;
@@ -47,7 +47,7 @@ import {
47
47
  parseHostAction,
48
48
  } from './stream-events';
49
49
  import { hasUsableStreamOutput, type StreamOutputEvidence } from './stream-outcome';
50
- import { failureDetail, readGemieMeta, type FailedTurn } from './turn-failure';
50
+ import { failureDetail, readGemieMeta, traceIdOf, type FailedTurn } from './turn-failure';
51
51
  import type { AgentRun, Message, SendOptions, ToolInvocation } from './types';
52
52
  import { UsageLimitError } from './usage-limit-error';
53
53
  import { useGemieRealtime } from '../realtime/react';
@@ -92,6 +92,8 @@ interface StreamErrorObject {
92
92
  type?: string;
93
93
  /** Alia's run id, on a turn that failed (before any output or part-way). */
94
94
  reference?: string;
95
+ /** The id of the request that produced this error, a refusal's included. */
96
+ traceId?: string;
95
97
  details?: {
96
98
  limitType?: string;
97
99
  current?: number;
@@ -494,6 +496,8 @@ export function useConversationStream({
494
496
  * read as. The flag is remembered here and answered when the stream ends.
495
497
  */
496
498
  let syntheticTail: { retryable: boolean; detail?: string } | null = null;
499
+ /** The id of a refused request, for the error row of the failure thrown from its body. */
500
+ let refusedTraceId: string | undefined;
497
501
  /** The reply's text as the model produced it: what the host previews when the turn settles. */
498
502
  let replyText = '';
499
503
  // A room can deliberately remain quiet. Only its server frame establishes this,
@@ -924,6 +928,7 @@ export function useConversationStream({
924
928
  failureDetail({
925
929
  code: typeof failed.code === 'string' ? failed.code : undefined,
926
930
  reference: typeof failed.reference === 'string' ? failed.reference : undefined,
931
+ traceId: traceIdOf(errorData),
927
932
  }),
928
933
  );
929
934
  }
@@ -942,6 +947,7 @@ export function useConversationStream({
942
947
  } else {
943
948
  errorMessage = response.statusText || errorMessage;
944
949
  }
950
+ refusedTraceId = traceIdOf(errorData);
945
951
  throw new Error(errorMessage);
946
952
  }
947
953
 
@@ -1352,15 +1358,17 @@ export function useConversationStream({
1352
1358
  // A turn that failed after it started carries a run reference:
1353
1359
  // its card says code and reference, never the server's English
1354
1360
  // prose. A refusal without one (a gate, a bad request) keeps its
1355
- // message, which is the only thing that says what to change.
1356
- const detail =
1357
- typeof err.reference === 'string'
1358
- ? failureDetail({
1359
- code: typeof err.code === 'string' ? err.code : undefined,
1360
- reference: err.reference,
1361
- })
1362
- : getErrorMessage(err) || undefined;
1363
- return keepFailedTurn(err.retryable !== false, detail);
1361
+ // message, which is the only thing that says what to change, with
1362
+ // the request's id after it.
1363
+ return keepFailedTurn(
1364
+ err.retryable !== false,
1365
+ failureDetail({
1366
+ code: typeof err.code === 'string' ? err.code : undefined,
1367
+ reference: typeof err.reference === 'string' ? err.reference : undefined,
1368
+ message: getErrorMessage(err) || undefined,
1369
+ traceId: traceIdOf(parsed),
1370
+ }),
1371
+ );
1364
1372
  }
1365
1373
 
1366
1374
  // Handle usage/credits info (comes at the end of stream).
@@ -1615,7 +1623,10 @@ export function useConversationStream({
1615
1623
  );
1616
1624
  setError(finalError);
1617
1625
  setComposerPhase('error');
1618
- return keepFailedTurn(true, finalError.message);
1626
+ return keepFailedTurn(
1627
+ true,
1628
+ failureDetail({ message: finalError.message, traceId: refusedTraceId }),
1629
+ );
1619
1630
  } finally {
1620
1631
  // Batches belong to the current turn. An older finally must not flush or clear
1621
1632
  // the next turn's shared timer, even when its controller ref has been cleared.