@mitralab.io/functions-sdk 0.2.8 → 0.2.10

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
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 0.2.10
6
+
7
+ - Depend on `@mitralab.io/sdk-core@0.2.14`: `apps.update()` (and `currentApp.update()`) takes
8
+ `emailLoginEnabled` and `passwordLoginEnabled`, sent to Code Studio only when supplied, so omission
9
+ keeps the current value; `AppDefinition` and `AppSummary` carry both fields when Code Studio returns
10
+ them. `messenger.sendEmail({ to, subject, html, text?, cc?, bcc?, replyTo? })` sends an email as
11
+ the app's backend through Messenger, with no `from`.
12
+ - Pin the SDK-PARITY-001 corpus to Core `0.2.14` with its digest and immutable source commit.
13
+
14
+ ## 0.2.10-beta.0
15
+
16
+ - `MitraApiError` gains `retryAfterSeconds`: how long the server asked to wait, read from
17
+ `retry_after_seconds` in the error body or, without it, from the `Retry-After` header in
18
+ seconds. A value that is not a non-negative integer, or a header in HTTP-date form, leaves it
19
+ unset. Messenger answers the app's daily email quota with a `429` carrying both.
20
+
21
+ ## 0.2.9
22
+
23
+ - Depend on `@mitralab.io/sdk-core@0.2.13`: `AgentTurnUsage` gains `contextTokens`, the tokens
24
+ occupying the chat's context window at the end of the turn (subagents excluded), and
25
+ `contextWindow`, the model's window size. Both are absent when the box does not report them.
26
+ - Pin the SDK-PARITY-001 corpus to Core `0.2.13` with its digest and immutable source commit.
27
+
5
28
  ## 0.2.8
6
29
 
7
30
  Stable release of the 0.2.8-beta.0 line, already on the `beta` tag and running in the dev Functions
package/README.md CHANGED
@@ -65,13 +65,13 @@ async function loadOrder(orderId) {
65
65
 
66
66
  ## Erros
67
67
 
68
- `MitraApiError` traz `status`, `code`, `details`, `requestId` e `retryable`. O token não aparece na mensagem nem nos detalhes.
68
+ `MitraApiError` traz `status`, `code`, `details`, `requestId`, `retryable` e `retryAfterSeconds`. O token não aparece na mensagem nem nos detalhes. `retryAfterSeconds` é quanto o servidor pediu para esperar, lido de `retry_after_seconds` no corpo ou do header `Retry-After` em segundos; sem valor inteiro válido, fica vazio.
69
69
 
70
70
  | Erro | Quando | O que fazer |
71
71
  | ---------------------------------------------- | --------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
72
72
  | `MitraConfigurationError` | configuração ausente ou inválida, ou `apps` usado com outro app | confira variáveis e argumentos; para o próprio app, use `currentApp` |
73
73
  | `MitraApiError` `401` ou `403` | o token não dá acesso ao recurso | confira as permissões do app; nem todo módulo está liberado para o token do runtime |
74
- | `MitraApiError` `429` ou `5xx` | limite de requisições ou falha no servidor | repita só se a operação puder ser repetida |
74
+ | `MitraApiError` `429` ou `5xx` | limite de requisições ou falha no servidor | repita só se a operação puder ser repetida; espere `retryAfterSeconds`, se vier |
75
75
  | `REQUEST_TIMEOUT`, `NETWORK_ERROR` | prazo estourado ou falha de rede, com `status` `0` | aumente `timeoutMs` ou repita, se a operação permitir |
76
76
  | `INVALID_CREDENTIALS`, `AUTHENTICATION_FAILED` | a troca da API key falhou | confira a chave e o `appId` |
77
77
  | `INVALID_RESPONSE` | resposta fora do formato esperado | atualize o SDK; se continuar, abra uma issue |
@@ -0,0 +1,15 @@
1
+ {
2
+ "contract": "SDK-PARITY-001",
3
+ "version": "0.2.13",
4
+ "dependency": {
5
+ "package": "@mitralab.io/sdk-core",
6
+ "version": "0.2.13",
7
+ "contractPath": "contracts/v0.2.13/sdk-parity.json"
8
+ },
9
+ "sha256": "36a1dd5b8d0ab604a8baa68ce19823c9b2f2745cdf57fad9000917b83c60be20",
10
+ "source": {
11
+ "repository": "https://github.com/mitralab-dev/mitra-core-sdk",
12
+ "commit": "f597990cadc3af3092ca727e1bc7aa2eab7a1513",
13
+ "path": "contracts/v0.2.13/sdk-parity.json"
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "contract": "SDK-PARITY-001",
3
+ "version": "0.2.14",
4
+ "dependency": {
5
+ "package": "@mitralab.io/sdk-core",
6
+ "version": "0.2.14",
7
+ "contractPath": "contracts/v0.2.14/sdk-parity.json"
8
+ },
9
+ "sha256": "112e7eb52bd4362737ef03efff2cad4f529e41d5ac8ccda442e57c09b2e3c459",
10
+ "source": {
11
+ "repository": "https://github.com/mitralab-dev/mitra-core-sdk",
12
+ "commit": "51ddb3ed7c7efd6f28aaa6c31a585227d245995b",
13
+ "path": "contracts/v0.2.14/sdk-parity.json"
14
+ }
15
+ }
package/dist/index.cjs CHANGED
@@ -119,6 +119,7 @@ var MitraApiError = class extends Error {
119
119
  details;
120
120
  requestId;
121
121
  retryable;
122
+ retryAfterSeconds;
122
123
  constructor(message, status, options = {}) {
123
124
  super(message);
124
125
  this.name = "MitraApiError";
@@ -127,6 +128,7 @@ var MitraApiError = class extends Error {
127
128
  this.details = options.details;
128
129
  this.requestId = options.requestId;
129
130
  this.retryable = options.retryable;
131
+ this.retryAfterSeconds = options.retryAfterSeconds;
130
132
  }
131
133
  };
132
134
 
@@ -155,6 +157,17 @@ function redactDetails(value, accessToken) {
155
157
  function optionalString(value) {
156
158
  return typeof value === "string" ? value : void 0;
157
159
  }
160
+ var retryAfterHeaderPattern = /^\d+$/;
161
+ function retryAfterSeconds(errorPayload, response) {
162
+ const fromBody = errorPayload.retry_after_seconds;
163
+ if (typeof fromBody === "number" && Number.isSafeInteger(fromBody) && fromBody >= 0) {
164
+ return fromBody;
165
+ }
166
+ const fromHeader = response.headers.get("Retry-After");
167
+ if (fromHeader === null || !retryAfterHeaderPattern.test(fromHeader)) return void 0;
168
+ const seconds = Number(fromHeader);
169
+ return Number.isSafeInteger(seconds) ? seconds : void 0;
170
+ }
158
171
  function appendQueryParameters(url, params) {
159
172
  for (const [key, value] of Object.entries(params)) {
160
173
  if (value === void 0) continue;
@@ -207,11 +220,13 @@ function createApiError(response, payload, accessToken) {
207
220
  const requestId = rawRequestId === void 0 ? void 0 : redactText(rawRequestId, accessToken);
208
221
  const code = rawCode === void 0 ? void 0 : redactText(rawCode, accessToken);
209
222
  const retryable = typeof errorPayload.retryable === "boolean" ? errorPayload.retryable : response.status >= 500;
223
+ const retryAfter = retryAfterSeconds(errorPayload, response);
210
224
  return new MitraApiError(message, response.status, {
211
225
  ...code === void 0 ? {} : { code },
212
226
  ...errorPayload.details === void 0 ? {} : { details: redactDetails(errorPayload.details, accessToken) },
213
227
  ...requestId === void 0 ? {} : { requestId },
214
- ...retryable === void 0 ? {} : { retryable }
228
+ ...retryable === void 0 ? {} : { retryable },
229
+ ...retryAfter === void 0 ? {} : { retryAfterSeconds: retryAfter }
215
230
  });
216
231
  }
217
232
  function isUnauthorized(error) {
package/dist/index.d.cts CHANGED
@@ -115,6 +115,7 @@ interface MitraApiErrorOptions {
115
115
  details?: unknown;
116
116
  requestId?: string;
117
117
  retryable?: boolean;
118
+ retryAfterSeconds?: number;
118
119
  }
119
120
  declare class MitraApiError extends Error {
120
121
  readonly status: number;
@@ -122,6 +123,7 @@ declare class MitraApiError extends Error {
122
123
  readonly details: unknown;
123
124
  readonly requestId: string | undefined;
124
125
  readonly retryable: boolean | undefined;
126
+ readonly retryAfterSeconds: number | undefined;
125
127
  constructor(message: string, status: number, options?: MitraApiErrorOptions);
126
128
  }
127
129
 
package/dist/index.d.ts CHANGED
@@ -115,6 +115,7 @@ interface MitraApiErrorOptions {
115
115
  details?: unknown;
116
116
  requestId?: string;
117
117
  retryable?: boolean;
118
+ retryAfterSeconds?: number;
118
119
  }
119
120
  declare class MitraApiError extends Error {
120
121
  readonly status: number;
@@ -122,6 +123,7 @@ declare class MitraApiError extends Error {
122
123
  readonly details: unknown;
123
124
  readonly requestId: string | undefined;
124
125
  readonly retryable: boolean | undefined;
126
+ readonly retryAfterSeconds: number | undefined;
125
127
  constructor(message: string, status: number, options?: MitraApiErrorOptions);
126
128
  }
127
129
 
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ var MitraApiError = class extends Error {
23
23
  details;
24
24
  requestId;
25
25
  retryable;
26
+ retryAfterSeconds;
26
27
  constructor(message, status, options = {}) {
27
28
  super(message);
28
29
  this.name = "MitraApiError";
@@ -31,6 +32,7 @@ var MitraApiError = class extends Error {
31
32
  this.details = options.details;
32
33
  this.requestId = options.requestId;
33
34
  this.retryable = options.retryable;
35
+ this.retryAfterSeconds = options.retryAfterSeconds;
34
36
  }
35
37
  };
36
38
 
@@ -59,6 +61,17 @@ function redactDetails(value, accessToken) {
59
61
  function optionalString(value) {
60
62
  return typeof value === "string" ? value : void 0;
61
63
  }
64
+ var retryAfterHeaderPattern = /^\d+$/;
65
+ function retryAfterSeconds(errorPayload, response) {
66
+ const fromBody = errorPayload.retry_after_seconds;
67
+ if (typeof fromBody === "number" && Number.isSafeInteger(fromBody) && fromBody >= 0) {
68
+ return fromBody;
69
+ }
70
+ const fromHeader = response.headers.get("Retry-After");
71
+ if (fromHeader === null || !retryAfterHeaderPattern.test(fromHeader)) return void 0;
72
+ const seconds = Number(fromHeader);
73
+ return Number.isSafeInteger(seconds) ? seconds : void 0;
74
+ }
62
75
  function appendQueryParameters(url, params) {
63
76
  for (const [key, value] of Object.entries(params)) {
64
77
  if (value === void 0) continue;
@@ -111,11 +124,13 @@ function createApiError(response, payload, accessToken) {
111
124
  const requestId = rawRequestId === void 0 ? void 0 : redactText(rawRequestId, accessToken);
112
125
  const code = rawCode === void 0 ? void 0 : redactText(rawCode, accessToken);
113
126
  const retryable = typeof errorPayload.retryable === "boolean" ? errorPayload.retryable : response.status >= 500;
127
+ const retryAfter = retryAfterSeconds(errorPayload, response);
114
128
  return new MitraApiError(message, response.status, {
115
129
  ...code === void 0 ? {} : { code },
116
130
  ...errorPayload.details === void 0 ? {} : { details: redactDetails(errorPayload.details, accessToken) },
117
131
  ...requestId === void 0 ? {} : { requestId },
118
- ...retryable === void 0 ? {} : { retryable }
132
+ ...retryable === void 0 ? {} : { retryable },
133
+ ...retryAfter === void 0 ? {} : { retryAfterSeconds: retryAfter }
119
134
  });
120
135
  }
121
136
  function isUnauthorized(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/functions-sdk",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "JavaScript and TypeScript SDK for Mitra Server Functions",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -67,7 +67,7 @@
67
67
  "node": ">=18.0.0"
68
68
  },
69
69
  "dependencies": {
70
- "@mitralab.io/sdk-core": "0.2.12",
70
+ "@mitralab.io/sdk-core": "0.2.14",
71
71
  "mitra-sdk": "1.0.63-beta.42"
72
72
  },
73
73
  "devDependencies": {