@uru-intelligence/app 2.2.1 → 2.2.5

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.
@@ -1,6 +1,6 @@
1
1
  import { computeRateLimitRetryDelayMs, parseRetryable, parseRetryAfterSeconds, } from "./dampers.js";
2
2
  import { awaitWithAbort } from "./transport-deadline.js";
3
- import { canResend, isLostRequest, isLostResponse, readRuntimeResponseBody, resendDelayMs, waitBeforeResend, } from "./transport-retry.js";
3
+ import { canResend, isLostRequest, isLostResponse, isTemporaryAnswer, readRuntimeResponseBody, resendDelayMs, waitBeforeResend, } from "./transport-retry.js";
4
4
  const FIRST_SEND = { rateLimited: 0, resent: 0 };
5
5
  /** One send. A lost request comes back as an outcome so the caller can decide. */
6
6
  const sendOnce = async (runtimeFetch, url, init, signal) => {
@@ -26,6 +26,17 @@ const sendOnce = async (runtimeFetch, url, init, signal) => {
26
26
  /** Whether a send ended without an answer from the platform. */
27
27
  const isLost = (outcome) => outcome.kind !== "response" ||
28
28
  isLostResponse(outcome.result.response.status, outcome.result.body);
29
+ /**
30
+ * Whether a query got a temporary answer: a 408, or a 503 that is not final
31
+ * ({@link isTemporaryAnswer}), such as the API's 503 when its database pool
32
+ * is full for a moment. A query only reads, so it is sent again, as after a
33
+ * lost answer. A 429 keeps its own rate-limit waits. An action or a job keeps
34
+ * the answer: its key replays a stored run, which may hold that answer.
35
+ */
36
+ const isTemporaryQueryAnswer = (capabilityType, outcome) => capabilityType === "query" &&
37
+ outcome.kind === "response" &&
38
+ outcome.result.response.status !== 429 &&
39
+ isTemporaryAnswer(outcome.result.response.status, outcome.result.body);
29
40
  /** Report the coming resend, then wait for it. */
30
41
  const reconnect = async (damper, resent, signal, report) => {
31
42
  const delayMs = resendDelayMs(resent, damper.config.random);
@@ -42,7 +53,7 @@ export const fetchInvocation = async (args, counts = FIRST_SEND) => {
42
53
  headers: args.headers,
43
54
  method: "POST",
44
55
  }, args.signal);
45
- if (isLost(outcome) &&
56
+ if ((isLost(outcome) || isTemporaryQueryAnswer(args.capabilityType, outcome)) &&
46
57
  args.resendLost &&
47
58
  canResend(args.damper.config, counts.resent)) {
48
59
  await reconnect(args.damper, counts.resent, args.signal, retryAfterSeconds => args.emit({
@@ -159,11 +170,15 @@ export const fetchJobStatus = async (args, counts = FIRST_SEND) => {
159
170
  };
160
171
  /**
161
172
  * Ask for one execution to stop. A cancel names its execution and asks for
162
- * the same end state every time, so a lost response is sent again.
173
+ * the same end state every time, so a lost response is sent again. The route
174
+ * takes no body, but the job gateway accepts only a JSON POST, so the cancel
175
+ * sends an empty JSON object.
163
176
  */
164
177
  export const fetchJobCancel = async (args, resent = 0) => {
165
178
  const { runtimeFetch } = args;
166
- const outcome = await sendOnce(runtimeFetch, args.url, { headers: args.headers, method: "POST" }, args.signal);
179
+ const headers = new Headers(args.headers);
180
+ headers.set("content-type", "application/json");
181
+ const outcome = await sendOnce(runtimeFetch, args.url, { body: "{}", headers, method: "POST" }, args.signal);
167
182
  if (isLost(outcome) && canResend(args.damper.config, resent)) {
168
183
  await reconnect(args.damper, resent, args.signal, retryAfterSeconds => args.emit(jobReconnectingEvent(args, retryAfterSeconds)));
169
184
  return await fetchJobCancel(args, resent + 1);
@@ -1,18 +1,33 @@
1
1
  /**
2
- * Resends for a response the platform never gave.
2
+ * Resends for a response the platform never gave, and for a temporary answer.
3
3
  *
4
4
  * A deploy, a crash or a memory kill of one API replica shows up here as a
5
5
  * failed or reset connection, a reply cut off after its headers, a 502 or 504
6
- * from the edge, or a 503 from an edge with no healthy replica. None of them
6
+ * from the edge, a 503 from an edge with no healthy replica, or Cloudflare's
7
+ * own 520 to 527 or 530 when the origin gave it no valid answer. None of them
7
8
  * is an answer from Uru: the call may not have arrived, or it arrived and its
8
- * reply was lost. Each caller decides whether its request is safe to send
9
- * again (a keyed action is, a Dataset SQL statement is not); this module owns
10
- * what counts as lost and how long to wait.
9
+ * reply was lost. A short database stall shows up as a temporary answer from
10
+ * Uru: a 408, a 429 or a 503. An edge can also answer a plain 500 of its own
11
+ * ({@link isBareServerError}). Each caller decides whether its request is
12
+ * safe to send again (a keyed Dataset write is, a Dataset SQL statement is
13
+ * not); this module owns what counts as lost, what counts as temporary, and
14
+ * how long to wait.
11
15
  */
12
16
  import type { ResolvedDamperConfig } from "./dampers.js";
13
17
  import type { RuntimeFetch } from "./runtime.js";
14
18
  /** A status the edge gives when no replica answered. */
15
19
  export declare const isLostResponse: (status: number, body: unknown) => boolean;
20
+ /**
21
+ * An answer from Uru that it cannot serve the call now but can soon: a 408,
22
+ * a 429 or a 503 (HTTP defines 503 as temporary, RFC 9110 section 15.6.4).
23
+ * Every other status is final, whatever its body says: a 500 with Uru's error
24
+ * code means the call failed in a way that a resend repeats, and a 4xx such
25
+ * as 403, 404, 409 or 422 refuses this request. A body that says
26
+ * `retryable: false` (a Dataset job that ended) or names a missing setup is
27
+ * final too. A 500 with no Uru error code is not Uru's answer
28
+ * ({@link isBareServerError}).
29
+ */
30
+ export declare const isTemporaryAnswer: (status: number, body: unknown) => boolean;
16
31
  /** A fetch that failed before a response, and not because the caller stopped it. */
17
32
  export declare const isLostRequest: (error: unknown, signal: AbortSignal | undefined) => boolean;
18
33
  /** One response body, and whether the connection broke before all of it arrived. */
@@ -38,8 +53,16 @@ export interface PostWithResendsArguments {
38
53
  readonly body: string;
39
54
  readonly config: ResolvedDamperConfig;
40
55
  readonly headers: Headers;
41
- /** Whether a lost response may be sent again with the same body. */
42
- readonly resendLost: boolean;
56
+ /**
57
+ * Whether the same body is safe to send again: the server answers a keyed
58
+ * command from its first run, or the call replaces saved state. Such a call
59
+ * is sent again after a lost response, after a temporary answer
60
+ * ({@link isTemporaryAnswer}) and, a few times, after a bare 500
61
+ * ({@link isBareServerError}), and carries {@link SDK_RESENDS_HEADER} and
62
+ * {@link SDK_RESENDS_BARE_500_HEADER} (unless `maxTransportRetries` is 0).
63
+ * Any other call is sent once.
64
+ */
65
+ readonly repeatable: boolean;
43
66
  readonly runtimeFetch: RuntimeFetch;
44
67
  /** The limit for one send. A send that reaches it counts as lost. */
45
68
  readonly sendTimeoutMs: number;
@@ -51,7 +74,11 @@ export interface PostWithResendsResult {
51
74
  readonly response: Response;
52
75
  }
53
76
  /**
54
- * POST one prepared body. When the platform gave no answer and the caller
55
- * allows it, send the same bytes again after the jittered wait.
77
+ * POST one prepared body. When the platform gave no answer, a temporary
78
+ * answer or a bare 500, and the call is repeatable, send the same bytes again
79
+ * after {@link resendWaitMs}. The resends stop at `maxTransportRetries`, when
80
+ * the wait budget is spent, or after {@link BARE_SERVER_ERROR_RESENDS} bare
81
+ * 500s, and the last answer then goes to the caller. A final answer is never
82
+ * sent again. `bareServerErrors` counts the bare 500s before this send.
56
83
  */
57
- export declare const postWithResends: (args: PostWithResendsArguments, resent?: number) => Promise<PostWithResendsResult>;
84
+ export declare const postWithResends: (args: PostWithResendsArguments, resent?: number, waitedMs?: number, bareServerErrors?: number) => Promise<PostWithResendsResult>;
@@ -1,14 +1,19 @@
1
1
  /**
2
- * Resends for a response the platform never gave.
2
+ * Resends for a response the platform never gave, and for a temporary answer.
3
3
  *
4
4
  * A deploy, a crash or a memory kill of one API replica shows up here as a
5
5
  * failed or reset connection, a reply cut off after its headers, a 502 or 504
6
- * from the edge, or a 503 from an edge with no healthy replica. None of them
6
+ * from the edge, a 503 from an edge with no healthy replica, or Cloudflare's
7
+ * own 520 to 527 or 530 when the origin gave it no valid answer. None of them
7
8
  * is an answer from Uru: the call may not have arrived, or it arrived and its
8
- * reply was lost. Each caller decides whether its request is safe to send
9
- * again (a keyed action is, a Dataset SQL statement is not); this module owns
10
- * what counts as lost and how long to wait.
9
+ * reply was lost. A short database stall shows up as a temporary answer from
10
+ * Uru: a 408, a 429 or a 503. An edge can also answer a plain 500 of its own
11
+ * ({@link isBareServerError}). Each caller decides whether its request is
12
+ * safe to send again (a keyed Dataset write is, a Dataset SQL statement is
13
+ * not); this module owns what counts as lost, what counts as temporary, and
14
+ * how long to wait.
11
15
  */
16
+ import { parseRetryable, parseRetryAfterSeconds } from "./dampers.js";
12
17
  import { abortReason, awaitWithAbort } from "./transport-deadline.js";
13
18
  /** Waits before jitter. With jitter the whole schedule lasts about a minute. */
14
19
  const RESEND_BASE_DELAYS_MS = [
@@ -37,24 +42,93 @@ const safeRecordValue = (record, field) => {
37
42
  return undefined;
38
43
  }
39
44
  };
40
- const isCode = (value) => typeof value === "string" && value.trim() !== "";
45
+ const codeOf = (value) => typeof value === "string" && value.trim() !== "" ? value : null;
41
46
  /**
42
- * A JSON error body with a code: the backend's `{ error: { code } }` envelope
43
- * or the Gem dispatcher's `{ error: "gem_unavailable" }`. Uru wrote it, so the
44
- * answer stands. An edge with no replica answers with text.
47
+ * The code of a JSON error body: the backend's `{ error: { code } }`
48
+ * envelope, the Gem dispatcher's `{ error: "gem_unavailable" }`, or
49
+ * `{ code }`. Uru wrote such a body, so the answer is Uru's. An edge with no
50
+ * replica answers with text.
45
51
  */
46
- const hasOwnedErrorCode = (body) => {
52
+ const ownedErrorCode = (body) => {
47
53
  if (!isRecord(body))
48
- return false;
54
+ return null;
49
55
  const error = safeRecordValue(body, "error");
50
- if (isCode(error) || isCode(safeRecordValue(body, "code")))
51
- return true;
52
- return isRecord(error) && isCode(safeRecordValue(error, "code"));
56
+ return (codeOf(error) ??
57
+ codeOf(safeRecordValue(body, "code")) ??
58
+ (isRecord(error) ? codeOf(safeRecordValue(error, "code")) : null));
53
59
  };
60
+ /**
61
+ * Cloudflare's own statuses for an origin that gave no valid answer: it was
62
+ * down, refused or dropped the connection, or did not answer in time. Uru
63
+ * never sends them.
64
+ */
65
+ const isEdgeOriginStatus = (status) => (status >= 520 && status <= 527) || status === 530;
54
66
  /** A status the edge gives when no replica answered. */
55
67
  export const isLostResponse = (status, body) => status === 502 ||
56
68
  status === 504 ||
57
- (status === 503 && !hasOwnedErrorCode(body));
69
+ isEdgeOriginStatus(status) ||
70
+ (status === 503 && ownedErrorCode(body) === null);
71
+ /** The statuses Uru gives when it cannot serve a call now but can soon. */
72
+ const TEMPORARY_STATUSES = new Set([408, 429, 503]);
73
+ /**
74
+ * 503 codes for a missing setup, which a resend cannot fix. The provider
75
+ * gateway answers this one before any API replica sees the call.
76
+ */
77
+ const SETUP_FAILURE_CODES = new Set([
78
+ "provider_gateway_limiter_unavailable",
79
+ ]);
80
+ /**
81
+ * An answer from Uru that it cannot serve the call now but can soon: a 408,
82
+ * a 429 or a 503 (HTTP defines 503 as temporary, RFC 9110 section 15.6.4).
83
+ * Every other status is final, whatever its body says: a 500 with Uru's error
84
+ * code means the call failed in a way that a resend repeats, and a 4xx such
85
+ * as 403, 404, 409 or 422 refuses this request. A body that says
86
+ * `retryable: false` (a Dataset job that ended) or names a missing setup is
87
+ * final too. A 500 with no Uru error code is not Uru's answer
88
+ * ({@link isBareServerError}).
89
+ */
90
+ export const isTemporaryAnswer = (status, body) => {
91
+ if (!TEMPORARY_STATUSES.has(status))
92
+ return false;
93
+ if (parseRetryable(body) === false)
94
+ return false;
95
+ const code = ownedErrorCode(body);
96
+ return code === null || !SETUP_FAILURE_CODES.has(code);
97
+ };
98
+ /**
99
+ * A 500 with no Uru error code. The API answers every failure of its
100
+ * handlers, an unexpected throw too, in its error envelope with a code. So no
101
+ * API handler wrote this 500: an edge did (Traefik's own 500 for a proxy
102
+ * failure it has no other status for, as while an API replica starts;
103
+ * Cloudflare's own 500; a Worker that threw), or the API process failed
104
+ * outside its handlers. A call that may be sent again is sent again after
105
+ * it, but only a few times ({@link BARE_SERVER_ERROR_RESENDS}), because that
106
+ * last case can repeat.
107
+ */
108
+ const isBareServerError = (status, body) => status === 500 && ownedErrorCode(body) === null;
109
+ /**
110
+ * The most resends that the bare 500s of one call get. They use the
111
+ * lost-answer waits, so a call whose first answer is a bare 500 that repeats
112
+ * ends about 1.5 to 3 seconds later. That covers the 2 seconds or so that
113
+ * Traefik answered 500 while an API replica started (PR #8488), and a 500
114
+ * that repeats costs at most 2 more sends.
115
+ */
116
+ const BARE_SERVER_ERROR_RESENDS = 2;
117
+ /**
118
+ * The request header that tells the provider gateway this client sends a
119
+ * temporary answer again itself, so the gateway passes it straight back
120
+ * instead of sending the call again too. Without it, one call could reach
121
+ * the API once for each SDK send times each gateway send.
122
+ */
123
+ const SDK_RESENDS_HEADER = "x-uru-sdk-resends";
124
+ /**
125
+ * The same for a bare 500 ({@link isBareServerError}). It is a second header
126
+ * and not a second value of {@link SDK_RESENDS_HEADER}, because SDK 2.2.4
127
+ * sends that one too and gives a bare 500 to the caller, so the gateway has
128
+ * to send a bare 500 again for it. A gateway that does not know this header
129
+ * ignores it.
130
+ */
131
+ const SDK_RESENDS_BARE_500_HEADER = "x-uru-sdk-resends-bare-500";
58
132
  /** A fetch that failed before a response, and not because the caller stopped it. */
59
133
  export const isLostRequest = (error, signal) => {
60
134
  if (signal?.aborted === true)
@@ -105,6 +179,19 @@ export const resendDelayMs = (resend, random) => {
105
179
  };
106
180
  /** Whether one more resend is allowed after `resend` earlier ones. */
107
181
  export const canResend = (config, resend) => resend < config.maxTransportRetries;
182
+ /**
183
+ * The most that all the waits of one call may add up to: every allowed
184
+ * resend at its longest jittered wait, 63 seconds by default. A temporary
185
+ * answer's `Retry-After` can make one wait longer than the schedule gives it.
186
+ * A `Retry-After` longer than what is left of this budget ends the resends.
187
+ */
188
+ const resendBudgetMs = (config) => {
189
+ const resends = Math.ceil(config.maxTransportRetries);
190
+ const listed = RESEND_BASE_DELAYS_MS.slice(0, resends).reduce((sum, delay) => sum + delay, 0);
191
+ const lastBase = RESEND_BASE_DELAYS_MS.at(-1) ?? 0;
192
+ const beyond = Math.max(0, resends - RESEND_BASE_DELAYS_MS.length) * lastBase;
193
+ return 2 * (listed + beyond);
194
+ };
108
195
  /** Wait before a resend. The request signal (caller signal or deadline) ends the wait. */
109
196
  export const waitBeforeResend = async (config, delayMs, signal) => {
110
197
  signal?.throwIfAborted();
@@ -113,21 +200,61 @@ export const waitBeforeResend = async (config, delayMs, signal) => {
113
200
  : config.sleep(delayMs, signal), signal);
114
201
  };
115
202
  const reachedSendLimit = (error, sendSignal) => sendSignal.aborted && error === sendSignal.reason;
203
+ /** The server's `Retry-After` (header or envelope) in milliseconds, else 0. */
204
+ const retryAfterMs = (outcome) => {
205
+ const seconds = parseRetryAfterSeconds({
206
+ body: outcome.body,
207
+ header: outcome.response.headers.get("retry-after"),
208
+ });
209
+ return seconds === null ? 0 : Math.ceil(seconds * 1000);
210
+ };
116
211
  /**
117
- * POST one prepared body. When the platform gave no answer and the caller
118
- * allows it, send the same bytes again after the jittered wait.
212
+ * How long to wait before resend `resent`, or null when the call is not sent
213
+ * again: it is not repeatable, it used its resends, the wait budget is spent,
214
+ * or a temporary answer's `Retry-After` is longer than what is left of the
215
+ * budget. The server's limit wins, so the call never goes out before the
216
+ * time it names. Otherwise the wait is the jittered schedule, or the
217
+ * `Retry-After` when that is longer. A lost response (`temporary` null) keeps
218
+ * the schedule as before, because no API replica wrote its headers. A
219
+ * scheduled wait is cut to what is left of the budget.
119
220
  */
120
- export const postWithResends = async (args, resent = 0) => {
221
+ const resendWaitMs = (args, resent, waitedMs, temporary) => {
222
+ if (!args.repeatable || !canResend(args.config, resent))
223
+ return null;
224
+ const left = resendBudgetMs(args.config) - waitedMs;
225
+ if (left <= 0)
226
+ return null;
227
+ const retryAfter = temporary === null ? 0 : retryAfterMs(temporary);
228
+ if (retryAfter > left)
229
+ return null;
230
+ return Math.min(Math.max(resendDelayMs(resent, args.config.random), retryAfter), left);
231
+ };
232
+ /**
233
+ * POST one prepared body. When the platform gave no answer, a temporary
234
+ * answer or a bare 500, and the call is repeatable, send the same bytes again
235
+ * after {@link resendWaitMs}. The resends stop at `maxTransportRetries`, when
236
+ * the wait budget is spent, or after {@link BARE_SERVER_ERROR_RESENDS} bare
237
+ * 500s, and the last answer then goes to the caller. A final answer is never
238
+ * sent again. `bareServerErrors` counts the bare 500s before this send.
239
+ */
240
+ export const postWithResends = async (args, resent = 0, waitedMs = 0, bareServerErrors = 0) => {
121
241
  // Read the fetch out of `args` so it is not called with `args` as `this`.
122
242
  const { runtimeFetch } = args;
123
243
  const sendSignal = AbortSignal.timeout(args.sendTimeoutMs);
244
+ const headers = new Headers(args.headers);
245
+ // The headers say "I send this again myself". With `maxTransportRetries` at
246
+ // 0 that is false, so the gateway keeps its own resends.
247
+ if (args.repeatable && canResend(args.config, 0)) {
248
+ headers.set(SDK_RESENDS_HEADER, "temporary");
249
+ headers.set(SDK_RESENDS_BARE_500_HEADER, "1");
250
+ }
124
251
  let outcome = null;
125
252
  let cut = false;
126
253
  let lostError = null;
127
254
  try {
128
255
  const response = await runtimeFetch(args.url, {
129
256
  body: args.body,
130
- headers: args.headers,
257
+ headers,
131
258
  method: "POST",
132
259
  signal: sendSignal,
133
260
  });
@@ -141,14 +268,31 @@ export const postWithResends = async (args, resent = 0) => {
141
268
  }
142
269
  lostError = error;
143
270
  }
144
- const lost = outcome === null ||
145
- cut ||
146
- isLostResponse(outcome.response.status, outcome.body);
147
- if (lost && args.resendLost && canResend(args.config, resent)) {
148
- await waitBeforeResend(args.config, resendDelayMs(resent, args.config.random), undefined);
149
- return await postWithResends(args, resent + 1);
271
+ let temporary = null;
272
+ let bare = false;
273
+ if (outcome !== null &&
274
+ !cut &&
275
+ !isLostResponse(outcome.response.status, outcome.body)) {
276
+ bare = isBareServerError(outcome.response.status, outcome.body);
277
+ if (bare) {
278
+ // An edge's 500 says nothing about when to send again, so it keeps
279
+ // the lost-answer waits, as a 502 does.
280
+ if (bareServerErrors >= BARE_SERVER_ERROR_RESENDS)
281
+ return outcome;
282
+ }
283
+ else if (isTemporaryAnswer(outcome.response.status, outcome.body)) {
284
+ temporary = outcome;
285
+ }
286
+ else {
287
+ return outcome;
288
+ }
289
+ }
290
+ const delayMs = resendWaitMs(args, resent, waitedMs, temporary);
291
+ if (delayMs === null) {
292
+ if (outcome === null)
293
+ throw lostError;
294
+ return outcome;
150
295
  }
151
- if (outcome === null)
152
- throw lostError;
153
- return outcome;
296
+ await waitBeforeResend(args.config, delayMs, undefined);
297
+ return await postWithResends(args, resent + 1, waitedMs + delayMs, bareServerErrors + (bare ? 1 : 0));
154
298
  };
@@ -18,7 +18,7 @@
18
18
  import type { ForceRefreshThrottle, ResolvedDamperConfig } from "./dampers.js";
19
19
  import type { CallKeys } from "./job-run.js";
20
20
  import type { RuntimeJsonObject } from "./transport-json.js";
21
- import type { CreateUruAppRuntimeClientOptions, UruAppRuntimeCapabilityType, UruAppRuntimeExecutionDiagnostics, UruAppRuntimeExecutionStatus, UruAppRuntimeInvocationOptions, UruAppRuntimeInvocationResponse, UruResultDecoder } from "./types.js";
21
+ import type { CreateUruAppRuntimeClientOptions, UruAppRuntimeCapabilityType, UruAppRuntimeExecutionStatus, UruAppRuntimeInvocationOptions, UruAppRuntimeInvocationResponse, UruResultDecoder } from "./types.js";
22
22
  /** Per-client damper state: the resolved config plus the forceRefresh throttle. */
23
23
  export interface DamperRuntime {
24
24
  readonly config: ResolvedDamperConfig;
@@ -38,26 +38,8 @@ interface AppRuntimeInvocationHttpResponse {
38
38
  pending: boolean;
39
39
  diagnostics?: RuntimeJsonObject;
40
40
  }
41
- interface AppRuntimeExecutionHttpResponse {
42
- success?: boolean;
43
- pending?: boolean;
44
- result?: unknown;
45
- error?: string | null;
46
- state?: string;
47
- status?: string | null;
48
- executionId?: string | null;
49
- statusUrl?: string | null;
50
- retryAfterSeconds?: number | null;
51
- cacheStatus?: string | null;
52
- executor?: string | null;
53
- executorKind?: string | null;
54
- code?: string | null;
55
- diagnostics?: UruAppRuntimeExecutionDiagnostics;
56
- }
57
41
  /** Map the owned camelCase HTTP envelope without copying unknown fields. */
58
42
  export declare const appRuntimeInvocationResponseFromHttp: (value: unknown, decodeResult?: UruResultDecoder<unknown>) => AppRuntimeInvocationHttpResponse;
59
- /** Map the owned camelCase job-status envelope without copying unknown fields. */
60
- export declare const appRuntimeExecutionStatusFromHttp: (value: unknown, decodeResult?: UruResultDecoder<unknown>) => AppRuntimeExecutionHttpResponse;
61
43
  export declare const invokeAppRuntime: (options: CreateUruAppRuntimeClientOptions, damper: DamperRuntime, capabilityType: UruAppRuntimeCapabilityType, name: string, input?: unknown, invocationOptions?: UruAppRuntimeInvocationOptions) => Promise<UruAppRuntimeInvocationResponse>;
62
44
  export declare const getAppRuntimeJobStatus: (options: CreateUruAppRuntimeClientOptions, executionId: string, invocationOptions: UruAppRuntimeInvocationOptions | undefined, damper: DamperRuntime) => Promise<UruAppRuntimeExecutionStatus>;
63
45
  export declare const cancelAppRuntimeJob: (options: CreateUruAppRuntimeClientOptions, executionId: string, invocationOptions: UruAppRuntimeInvocationOptions | undefined, damper: DamperRuntime) => Promise<UruAppRuntimeInvocationResponse>;
package/dist/transport.js CHANGED
@@ -149,7 +149,7 @@ export const appRuntimeInvocationResponseFromHttp = (value, decodeResult) => {
149
149
  return output;
150
150
  };
151
151
  /** Map the owned camelCase job-status envelope without copying unknown fields. */
152
- export const appRuntimeExecutionStatusFromHttp = (value, decodeResult) => {
152
+ const appRuntimeExecutionStatusFromHttp = (value, decodeResult) => {
153
153
  const label = "app runtime job status";
154
154
  const body = httpRecord(value, label);
155
155
  const output = {
@@ -494,7 +494,8 @@ export const invokeAppRuntime = async (options, damper, capabilityType, name, in
494
494
  // `maxRateLimitRetries` extra sends, honoring Retry-After / retry_after_seconds
495
495
  // (capped) before falling through to the normal failure path. A response the
496
496
  // platform never gave (a restarting replica) is sent again separately, at
497
- // most `maxTransportRetries` times, when the call is safe to send again.
497
+ // most `maxTransportRetries` times, when the call is safe to send again. So
498
+ // is a query's temporary answer: a query only reads.
498
499
  const { body, response } = await withRuntimeRequestSignal(invocationOptions, async (requestSignal) => await fetchInvocation({
499
500
  capabilityName,
500
501
  capabilityType,
package/dist/types.d.ts CHANGED
@@ -427,7 +427,7 @@ export type UruUploadOutcome = "verified" | "pending" | "absent" | "expired" | "
427
427
  * A minted grant. `uploadUrl` is a CREDENTIAL: do not log it or store it.
428
428
  *
429
429
  * `requiredHeaders` is not advice. The provider rebuilds the signature from
430
- * what actually arrives, so a PUT that omits or alters either header is
430
+ * what actually arrives, so a PUT that omits or alters any header is
431
431
  * refused.
432
432
  */
433
433
  export interface UruUploadGrant {
@@ -452,20 +452,39 @@ export interface UruUploadResult {
452
452
  /** True only when a refused object could not be removed from storage. */
453
453
  readonly cleanupFailed: boolean;
454
454
  }
455
+ export interface UruUploadStatus {
456
+ readonly uploadId: string;
457
+ readonly state: UruUploadResult['state'];
458
+ readonly outcome: UruUploadOutcome | null;
459
+ readonly filename: string;
460
+ readonly contentType: string;
461
+ readonly sizeBytes: number | null;
462
+ readonly expiresAt: string;
463
+ /** True while the platform still needs to retry object cleanup. */
464
+ readonly cleanupFailed: boolean;
465
+ }
455
466
  /** The file-upload lane a Gem gets with the `storage` capability. */
456
467
  export interface UruUploadsContext {
457
468
  request(input: {
458
469
  filename: string;
459
470
  contentType: string;
460
471
  sizeBytes: number;
472
+ /** Reuse this key after an uncertain response. The SDK also retains an
473
+ * automatic key when its response is uncertain. */
474
+ idempotencyKey?: string;
461
475
  signal?: AbortSignal;
462
476
  }): Promise<UruUploadGrant>;
477
+ /** Read the saved result for a request key without starting another upload. */
478
+ status(idempotencyKey: string, options?: {
479
+ signal?: AbortSignal;
480
+ }): Promise<UruUploadStatus>;
463
481
  complete(uploadId: string, options?: {
464
482
  signal?: AbortSignal;
465
483
  }): Promise<UruUploadResult>;
466
484
  /** Request, PUT and complete in one call. What almost every caller wants. */
467
485
  upload(file: File, options?: {
468
486
  signal?: AbortSignal;
487
+ idempotencyKey?: string;
469
488
  }): Promise<UruUploadResult>;
470
489
  /**
471
490
  * Read one VERIFIED upload back, as a `Blob`.