@mitralab.io/functions-sdk 0.2.9 → 0.3.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 +29 -0
- package/README.md +2 -2
- package/contracts/sdk-core-v0.2.14.manifest.json +15 -0
- package/contracts/sdk-core-v0.3.0.manifest.json +15 -0
- package/dist/index.cjs +16 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.3.0
|
|
6
|
+
|
|
7
|
+
- Depend on `@mitralab.io/sdk-core@0.3.0`, the agent session that follows T3. A message sent while
|
|
8
|
+
a reply runs no longer waits in a local queue of the SDK: it goes to the box at once with its
|
|
9
|
+
`clientMessageId` and no mode by default, and T3 decides, steering it into the running turn or
|
|
10
|
+
queueing it. `send(prompt, { mode: "queue" | "steer" })` asks on purpose, and `send` returns the
|
|
11
|
+
message's `clientMessageId`. `session.history` is the live conversation in the box's order, asked
|
|
12
|
+
with `kinds=all`, with a tool's call and result as two items, as in 0.2.13, the question as the
|
|
13
|
+
person wrote it, and T3's approvals and mid-turn questions where they came. `queue` mirrors T3's
|
|
14
|
+
queue, with `steerQueueItem`, `resumeQueue` and `backgroundTasks`. The history keeps the 0.2.13
|
|
15
|
+
format; against an old box the new functions show nothing.
|
|
16
|
+
- Pin the SDK-PARITY-001 corpus to Core `0.3.0` with its digest and immutable source commit.
|
|
17
|
+
|
|
18
|
+
## 0.2.10
|
|
19
|
+
|
|
20
|
+
- Depend on `@mitralab.io/sdk-core@0.2.14`: `apps.update()` (and `currentApp.update()`) takes
|
|
21
|
+
`emailLoginEnabled` and `passwordLoginEnabled`, sent to Code Studio only when supplied, so omission
|
|
22
|
+
keeps the current value; `AppDefinition` and `AppSummary` carry both fields when Code Studio returns
|
|
23
|
+
them. `messenger.sendEmail({ to, subject, html, text?, cc?, bcc?, replyTo? })` sends an email as
|
|
24
|
+
the app's backend through Messenger, with no `from`.
|
|
25
|
+
- Pin the SDK-PARITY-001 corpus to Core `0.2.14` with its digest and immutable source commit.
|
|
26
|
+
|
|
27
|
+
## 0.2.10-beta.0
|
|
28
|
+
|
|
29
|
+
- `MitraApiError` gains `retryAfterSeconds`: how long the server asked to wait, read from
|
|
30
|
+
`retry_after_seconds` in the error body or, without it, from the `Retry-After` header in
|
|
31
|
+
seconds. A value that is not a non-negative integer, or a header in HTTP-date form, leaves it
|
|
32
|
+
unset. Messenger answers the app's daily email quota with a `429` carrying both.
|
|
33
|
+
|
|
5
34
|
## 0.2.9
|
|
6
35
|
|
|
7
36
|
- Depend on `@mitralab.io/sdk-core@0.2.13`: `AgentTurnUsage` gains `contextTokens`, the tokens
|
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 `
|
|
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.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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contract": "SDK-PARITY-001",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"dependency": {
|
|
5
|
+
"package": "@mitralab.io/sdk-core",
|
|
6
|
+
"version": "0.3.0",
|
|
7
|
+
"contractPath": "contracts/v0.3.0/sdk-parity.json"
|
|
8
|
+
},
|
|
9
|
+
"sha256": "dc7dceb99e29810dfd2cf30d76ec80ea8c5d6dbf5c8dac3038f58a2d36cbc793",
|
|
10
|
+
"source": {
|
|
11
|
+
"repository": "https://github.com/mitralab-dev/mitra-core-sdk",
|
|
12
|
+
"commit": "ff356e49af09aa238beaf94043680226edb9de66",
|
|
13
|
+
"path": "contracts/v0.3.0/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.
|
|
3
|
+
"version": "0.3.0",
|
|
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.
|
|
70
|
+
"@mitralab.io/sdk-core": "0.3.0",
|
|
71
71
|
"mitra-sdk": "1.0.63-beta.42"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|