@gemies/sdk 10.11.0 → 10.13.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,16 @@
|
|
|
1
1
|
# @gemies/sdk
|
|
2
2
|
|
|
3
|
+
## 10.13.0
|
|
4
|
+
|
|
5
|
+
### A usage limit says when it resets
|
|
6
|
+
|
|
7
|
+
`UsageLimitDetails` carries `resetsAt` (ISO 8601) and `autoResume`. A model provider's usage limit
|
|
8
|
+
(`details.limitType: 'provider_usage'`, exported as `PROVIDER_USAGE_LIMIT_TYPE`) is now raised as a
|
|
9
|
+
`UsageLimitError` of type `rate_limit` instead of a failed turn. When `autoResume` is true the
|
|
10
|
+
server has kept the message and answers it after the reset, so the send ends `sent` and the message
|
|
11
|
+
stays in the thread rather than going back to the composer. The plan window's `details` and
|
|
12
|
+
`suggestedAction` now also arrive on the open stream.
|
|
13
|
+
|
|
3
14
|
## 10.11.0
|
|
4
15
|
|
|
5
16
|
### Error rows name the request
|
package/package.json
CHANGED
package/src/runtime/model.ts
CHANGED
|
@@ -38,5 +38,5 @@ export type {
|
|
|
38
38
|
SendOptions,
|
|
39
39
|
ToolInvocation,
|
|
40
40
|
} from './types';
|
|
41
|
-
export { UsageLimitError } from './usage-limit-error';
|
|
41
|
+
export { PROVIDER_USAGE_LIMIT_TYPE, UsageLimitError } from './usage-limit-error';
|
|
42
42
|
export type { UsageLimitDetails, UsageLimitType } from './usage-limit-error';
|
|
@@ -11,6 +11,23 @@ export interface UsageLimitDetails {
|
|
|
11
11
|
current?: number;
|
|
12
12
|
limit?: number;
|
|
13
13
|
tier?: string;
|
|
14
|
+
/** When the limit resets, ISO 8601, when the server knows. */
|
|
15
|
+
resetsAt?: string;
|
|
16
|
+
/** The server keeps the message and answers it by itself once the limit resets. */
|
|
17
|
+
autoResume?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** `details.limitType` of a usage limit of the model's provider, not of the person's plan. */
|
|
21
|
+
export const PROVIDER_USAGE_LIMIT_TYPE = 'provider_usage';
|
|
22
|
+
|
|
23
|
+
/** The two fields a refusal says about its reset, read off whatever carried them. */
|
|
24
|
+
export function usageResetOf(
|
|
25
|
+
error: { resetsAt?: unknown; autoResume?: unknown } | null | undefined,
|
|
26
|
+
): Pick<UsageLimitDetails, 'resetsAt' | 'autoResume'> {
|
|
27
|
+
return {
|
|
28
|
+
...(typeof error?.resetsAt === 'string' ? { resetsAt: error.resetsAt } : {}),
|
|
29
|
+
...(error?.autoResume === true ? { autoResume: true } : {}),
|
|
30
|
+
};
|
|
14
31
|
}
|
|
15
32
|
|
|
16
33
|
export class UsageLimitError extends Error {
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
import { hasUsableStreamOutput, type StreamOutputEvidence } from './stream-outcome';
|
|
50
50
|
import { failureDetail, readGemieMeta, traceIdOf, type FailedTurn } from './turn-failure';
|
|
51
51
|
import type { AgentRun, Message, SendOptions, ToolInvocation } from './types';
|
|
52
|
-
import { UsageLimitError } from './usage-limit-error';
|
|
52
|
+
import { PROVIDER_USAGE_LIMIT_TYPE, UsageLimitError, usageResetOf } from './usage-limit-error';
|
|
53
53
|
import { useGemieRealtime } from '../realtime/react';
|
|
54
54
|
|
|
55
55
|
export type { ToolInvocation };
|
|
@@ -66,7 +66,8 @@ export type { FailedTurn };
|
|
|
66
66
|
* - `failed`: the turn was rolled back to what the list was before the send,
|
|
67
67
|
* so the caller hands the text back to the composer. Only the usage-limit
|
|
68
68
|
* errors end this way now: they open a dialog of their own, and a retry
|
|
69
|
-
* would be the wrong offer next to "upgrade" or "wait".
|
|
69
|
+
* would be the wrong offer next to "upgrade" or "wait". A limit the server
|
|
70
|
+
* will answer after by itself (`autoResume`) is `sent` instead.
|
|
70
71
|
* - `aborted`: the person stopped it; partial output is theirs to keep.
|
|
71
72
|
*/
|
|
72
73
|
export type SendOutcome = 'sent' | 'errored' | 'failed' | 'aborted';
|
|
@@ -80,6 +81,8 @@ interface ThrownErrorBody {
|
|
|
80
81
|
/** Alia's run id, on a turn that failed after the stream began. */
|
|
81
82
|
reference?: string;
|
|
82
83
|
suggestedAction?: 'wait' | 'upgrade';
|
|
84
|
+
resetsAt?: string;
|
|
85
|
+
autoResume?: boolean;
|
|
83
86
|
}
|
|
84
87
|
|
|
85
88
|
/** Structured `error` object the server may embed in a non-OK response / SSE error event. */
|
|
@@ -94,6 +97,9 @@ interface StreamErrorObject {
|
|
|
94
97
|
reference?: string;
|
|
95
98
|
/** The id of the request that produced this error, a refusal's included. */
|
|
96
99
|
traceId?: string;
|
|
100
|
+
/** A usage limit's reset time, and whether the server answers the message then. */
|
|
101
|
+
resetsAt?: string;
|
|
102
|
+
autoResume?: boolean;
|
|
97
103
|
details?: {
|
|
98
104
|
limitType?: string;
|
|
99
105
|
current?: number;
|
|
@@ -488,6 +494,18 @@ export function useConversationStream({
|
|
|
488
494
|
return 'sent';
|
|
489
495
|
};
|
|
490
496
|
|
|
497
|
+
/**
|
|
498
|
+
* A usage limit's end. When the server keeps the message and answers it after the reset,
|
|
499
|
+
* the person's turn stays in the thread; handing it back to the composer would send it twice.
|
|
500
|
+
*/
|
|
501
|
+
const settleUsageLimit = (error: unknown): SendOutcome => {
|
|
502
|
+
const autoResume = (error as Partial<UsageLimitError>).details?.autoResume === true;
|
|
503
|
+
if (!autoResume || hasUsableStreamOutput(outputEvidence)) return settleError();
|
|
504
|
+
dropPendingUpdates();
|
|
505
|
+
setMessagesAndRef((prev) => prev.filter((m) => m.id !== assistantMessage.id));
|
|
506
|
+
return 'sent';
|
|
507
|
+
};
|
|
508
|
+
|
|
491
509
|
/**
|
|
492
510
|
* The server's stand-in for an answer it could not get, if one arrived.
|
|
493
511
|
*
|
|
@@ -868,14 +886,21 @@ export function useConversationStream({
|
|
|
868
886
|
return rollback();
|
|
869
887
|
}
|
|
870
888
|
|
|
871
|
-
// Detect usage limit errors (429 rate limit, 402 insufficient credits, 403 model access
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
889
|
+
// Detect usage limit errors (429 rate limit, 402 insufficient credits, 403 model access,
|
|
890
|
+
// and a provider's limit, which fails the turn with 503 and says when it resets)
|
|
891
|
+
const errObj =
|
|
892
|
+
errorData?.error && typeof errorData.error === 'object' ? errorData.error : null;
|
|
893
|
+
const providerLimit = errObj?.details?.limitType === PROVIDER_USAGE_LIMIT_TYPE;
|
|
894
|
+
if (
|
|
895
|
+
providerLimit ||
|
|
896
|
+
response.status === 429 ||
|
|
897
|
+
response.status === 402 ||
|
|
898
|
+
response.status === 403
|
|
899
|
+
) {
|
|
875
900
|
const isModelAccess = response.status === 403 && errObj?.code === 'MODEL_NOT_IN_PLAN';
|
|
876
901
|
const isCredits = response.status === 402 || errObj?.code === 'INSUFFICIENT_CREDITS';
|
|
877
902
|
|
|
878
|
-
if (isModelAccess || isCredits || response.status === 429) {
|
|
903
|
+
if (providerLimit || isModelAccess || isCredits || response.status === 429) {
|
|
879
904
|
throw new UsageLimitError({
|
|
880
905
|
type: isModelAccess ? 'model_access' : isCredits ? 'credits' : 'rate_limit',
|
|
881
906
|
code:
|
|
@@ -900,6 +925,7 @@ export function useConversationStream({
|
|
|
900
925
|
current: errObj?.details?.current,
|
|
901
926
|
limit: errObj?.details?.limit,
|
|
902
927
|
tier: errObj?.details?.tier,
|
|
928
|
+
...usageResetOf(errObj),
|
|
903
929
|
});
|
|
904
930
|
}
|
|
905
931
|
}
|
|
@@ -1312,13 +1338,15 @@ export function useConversationStream({
|
|
|
1312
1338
|
host.onFeatureLocked?.(lockedFeature);
|
|
1313
1339
|
return settleError();
|
|
1314
1340
|
}
|
|
1315
|
-
// Check for usage limit errors (rate limit, credits, model access)
|
|
1341
|
+
// Check for usage limit errors (rate limit, credits, model access, a provider's)
|
|
1342
|
+
const providerLimit = err.details?.limitType === PROVIDER_USAGE_LIMIT_TYPE;
|
|
1316
1343
|
if (
|
|
1344
|
+
providerLimit ||
|
|
1317
1345
|
errorCode(err) === 'MODEL_NOT_IN_PLAN' ||
|
|
1318
1346
|
errorCode(err) === 'INSUFFICIENT_CREDITS' ||
|
|
1319
1347
|
err.type === 'rate_limit_error'
|
|
1320
1348
|
) {
|
|
1321
|
-
const isRateLimit = err.type === 'rate_limit_error';
|
|
1349
|
+
const isRateLimit = providerLimit || err.type === 'rate_limit_error';
|
|
1322
1350
|
throw new UsageLimitError({
|
|
1323
1351
|
type:
|
|
1324
1352
|
errorCode(err) === 'MODEL_NOT_IN_PLAN'
|
|
@@ -1345,6 +1373,7 @@ export function useConversationStream({
|
|
|
1345
1373
|
current:
|
|
1346
1374
|
typeof err.details?.current === 'number' ? err.details.current : undefined,
|
|
1347
1375
|
limit: typeof err.details?.limit === 'number' ? err.details.limit : undefined,
|
|
1376
|
+
...usageResetOf(err),
|
|
1348
1377
|
});
|
|
1349
1378
|
}
|
|
1350
1379
|
|
|
@@ -1575,7 +1604,7 @@ export function useConversationStream({
|
|
|
1575
1604
|
if (e instanceof UsageLimitError || errorName(e) === 'UsageLimitError') {
|
|
1576
1605
|
setError(e instanceof Error ? e : new Error(getErrorMessage(e)));
|
|
1577
1606
|
setComposerPhase('error');
|
|
1578
|
-
return
|
|
1607
|
+
return settleUsageLimit(e);
|
|
1579
1608
|
}
|
|
1580
1609
|
|
|
1581
1610
|
// A streaming fetch may throw a non-Error object (e.g. the response body)
|
|
@@ -1605,10 +1634,11 @@ export function useConversationStream({
|
|
|
1605
1634
|
retryable: errBody?.retryable ?? !isCredits,
|
|
1606
1635
|
retryAfterSeconds: errBody?.retryAfter,
|
|
1607
1636
|
suggestedAction: errBody?.suggestedAction || (isCredits ? 'upgrade' : 'wait'),
|
|
1637
|
+
...usageResetOf(errBody),
|
|
1608
1638
|
});
|
|
1609
1639
|
setError(usageError);
|
|
1610
1640
|
setComposerPhase('error');
|
|
1611
|
-
return
|
|
1641
|
+
return settleUsageLimit(usageError);
|
|
1612
1642
|
}
|
|
1613
1643
|
}
|
|
1614
1644
|
|