@mitralab.io/sdk-core 0.2.12 → 0.3.0-beta.2

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,115 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 0.3.0-beta.2
6
+
7
+ - `messenger.sendEmail({ to, subject, html, text?, cc?, bcc?, replyTo? })` sends an email through
8
+ Messenger's `POST /api/v1/messages/send` as a `RAW` payload on the `EMAIL` channel and resolves
9
+ with the `messageId` of the accepted message. There is no `from`: Messenger sends with the
10
+ sender of the app in the token, so only the app's backend sends (a token exchanged from an api
11
+ key or the Server Function token). `to`, `cc` and `bcc` are lists with one address per entry;
12
+ absent optional fields are left out of the body.
13
+ - Recipient limits, the app's daily quota and the token check stay on Messenger. Their errors
14
+ (`400` above Messenger's recipient cap, `429` with `Retry-After` above the quota, `403` for an
15
+ app end-user token) come from the transport unchanged.
16
+ - `apps.update()` takes `emailLoginEnabled` and `passwordLoginEnabled`, sent on Code Studio's
17
+ `PATCH /api/v1/apps/{id}` only when supplied, so omission keeps the current value. Code Studio
18
+ rejects `passwordLoginEnabled: true` while the app inherits the platform login, with a `400`
19
+ and `PASSWORD_LOGIN_REQUIRES_EXCLUSIVE_MODE`, which comes from the transport unchanged.
20
+ - `AppDefinition` and `AppSummary` carry both fields when Code Studio returns them. The response
21
+ validator accepts their absence, as a Code Studio that predates them sends, and rejects a value
22
+ that is not a boolean.
23
+
24
+ ## 0.3.0
25
+
26
+ Rollout gate: this version goes into the app SDKs (`@mitralab.io/platform-sdk` and the Functions
27
+ SDK) only once the environment has no old agent box left, that is, no box still running on the
28
+ `experimental` fork template. An old box takes a message sent during a turn as a new turn start:
29
+ it resets the turn's usage and identity, and nothing reports it as an error. The SDK cannot tell
30
+ an old box from a new one, so the gate is the bump in the app SDKs, which pin this package to an
31
+ exact version.
32
+
33
+ - The agent session no longer holds messages. Every `send` and `sendAndWait` goes out at once,
34
+ also while a turn runs, before it reached the box, after a delivered `cancel()`, while the
35
+ socket redials and on the Copilot stream. The box steers it into the running turn, queues it
36
+ for a turn of its own, or gives it one when that turn ended, and `sendAndWait` resolves with
37
+ the turn that answered it.
38
+ - On the direct channel each message carries `mode: "steer"`, which the new box needs to take
39
+ it into the running turn (without it, the box puts the message in T3's queue), and a
40
+ `clientMessageId`. The box echoes it on the
41
+ `stepStart` that takes it, on the `messageQueued` frame when the provider queues it (the
42
+ message counts as accepted then, with no admission timeout), and on the `error` that refuses
43
+ it, which rejects that message only and leaves the running turn alone. A box that names no
44
+ message keeps the old rule: the oldest one waiting is the one answered.
45
+ - While the socket redials, and without the direct channel, a message goes to the Copilot's
46
+ `POST /inputs`, which holds it while the box boots. A failed send rejects and emits `error`.
47
+ - A message sent while a turn runs keeps its `agentType` and `reasoningEffort` on the box, which
48
+ leaves the running turn's model alone and applies them when the message gets a turn of its
49
+ own. Only when it goes to the Copilot with a turn running are they dropped, because the
50
+ Copilot restarts the live session for another model. A refusal the Copilot answers with an
51
+ error status rejects that message and emits `error`.
52
+ - A message still waiting to go out when the session closes is rejected and not sent. The first
53
+ message of a task that already exists still goes out over REST after a close, as before.
54
+ - T3's mid-turn input request reaches the app as a `raw` event of type `user_input_request`,
55
+ with T3's item as payload. `session.respondUserInput(requestId, answers, attachmentsByQuestionId?)`
56
+ sends the answer to the box as T3's own `runtime-request.respond`, on the socket or the box's
57
+ `POST /messages`; `AgentTaskInput` gains that variant. The turn waits for the answer without a
58
+ timeout of its own. An `error` the box sends with a `requestId` refuses that answer only: the
59
+ event is emitted and the turn and the messages waiting for the box are left alone. With the box
60
+ channel down, the answer is not sent and an `error` says so; the Copilot does not take it.
61
+ - A turn whose box went away while the socket redialed (the Copilot points the chat to another
62
+ box, or the same address comes back with an empty log) ends as `interrupted` with the text it
63
+ had, so the next message opens a turn of its own. A terminal the new box sends for that turn
64
+ is ignored.
65
+ - The box's `steer` frame marks where T3 took a message into the running turn, with no turn of
66
+ its own: the session answers that message with the running turn and emits the new `steered`
67
+ event with its `text` and `messageId`, for the app to show it at that point. The frame also
68
+ confirms the message, as `messageQueued` does, and keeps the redial. A message the box steers
69
+ into a turn another client opened follows that turn from the `steer` on.
70
+ - A turn whose `sendAndWait` already gave up on `timeoutMs` or `signal` is still closed from the
71
+ history when the stream drops: the recovery no longer stops with the waiter, and the session
72
+ does not stay `streaming` forever.
73
+ - A turn the session closes from the history after the stream dropped closes only on the row
74
+ that ends it: the agent row carrying the turn's usage, or an `ERROR` row. The Copilot writes a
75
+ turn's rows while it runs, so the first new row was often a comment from the middle of the
76
+ turn, and an earlier turn's answer written late looked new; both closed the turn with text that
77
+ was not its answer. A closing row whose usage names a prompt the session had already seen
78
+ answers that earlier prompt and is skipped. Once the live terminal was heard, a terminal with
79
+ usage waits about 3 s for its closing row and one without takes the turn's newest row, as before.
80
+ - After a drop, the Copilot stream replays the running turn from what its history had. Frames of
81
+ that turn whose box `sequence` the session already saw are skipped, so text and tools are not
82
+ shown twice.
83
+ - A stopped turn the session closes from the history ends as `interrupted`, not `reconciled`. A
84
+ message sent after `cancel()`, while the stop is unanswered, goes out as any other; the box
85
+ holds it until the stopped turn ends and gives it a turn of its own, which its `sendAndWait`
86
+ resolves with.
87
+ - On the direct channel, turn frames naming a turn that arrive before the opening message's
88
+ `stepStart` are the tail of an earlier turn (one already closed from the history) and are
89
+ ignored, so its answer is not delivered to the next message.
90
+ - Subagents: the `subagent` event and `session.subagents` carry `subagentId`, `toolId`, `status`,
91
+ `progress`, `startedAt`, `endedAt` (epoch ms) and `childThreadId` from the box's
92
+ `subagentUpdate` frame; an update with no status keeps the one before. Frames of the child
93
+ thread, marked with `parentToolId`, come as `subagentDelta` and `subagentTool` and never touch
94
+ the chat's turn: they open none, end none, admit no message, stay out of `content` and do not
95
+ change the redial. `stopSubagent(subagentId)` stops one over the box channel; without it an
96
+ `error` says so and nothing goes out. `AgentTaskInput` gains `mode` and `subagent.stop`,
97
+ `AgentToolEvent` gains `parentToolId`, and `AgentSubagent` and `AgentSubagentStatus` are
98
+ exported.
99
+ - `queue`, `editQueueItem`, `removeQueueItem`, `clearQueue`, `queueChange` and `AgentQueueItem`
100
+ are deprecated and kept only for compatibility: the queue is always empty, the methods do
101
+ nothing and the event is never emitted.
102
+
103
+ ## 0.2.13
104
+
105
+ - `AgentTurnUsage` gains `contextTokens` and `contextWindow`. `contextTokens` is the number of
106
+ tokens occupying the chat's context window at the end of the turn: the prompt of the last
107
+ model request of the main conversation, input plus cache read and cache creation, with
108
+ subagents excluded. `contextWindow` is the model's window size, in tokens, and is kept only
109
+ as a positive integer: the box omits it when it does not know it.
110
+ - Both come from the box in `stepFinish`, so they show live in `turnEnd` and in the result
111
+ `sendAndWait` resolves, and in the `agent` item of the history. An invalid value is dropped
112
+ on its own; the rest of the usage stays.
113
+
5
114
  ## 0.2.11-beta.0
6
115
 
7
116
  - Agent turn usage (`AgentTurnUsage`): `inputTokens` and `outputTokens`, and when the harness
package/README.md CHANGED
@@ -66,7 +66,8 @@ const { data: tasks, hasMore } = await core.entities.getTable("Task").list({ lim
66
66
  - `functions`, `publicFunctions`, `functionsAdmin` e `workflows`: executar e administrar Server Functions e workflows.
67
67
  - `integration`, `integrationAdmin`, `integrationResources` e `integrationTemplates`: chamadas a APIs externas e a configuração delas.
68
68
  - `agentTasks`, com `createAgentTaskSessionManager` e `withAgentTaskSessions`: chats de agente com `send`, `sendAndWait`, `cancel` e eventos. O gerenciador recebe `tasks`, o `eventSource` do seu SDK e `directChannel`, com o `apiUrl` do gateway e, se quiser, `WebSocket` e `fetch`.
69
- - `apps`, `context`, `agents`, `agentConnections`, `agentCredentials`, `members`, `messenger`, `imports`, `dataSources` e `auth`: o app em si, a configuração de agentes e os demais recursos.
69
+ - `apps`, `context`, `agents`, `agentConnections`, `agentCredentials`, `members`, `imports`, `dataSources` e `auth`: o app em si, a configuração de agentes e os demais recursos.
70
+ - `messenger`: `notify` avisa o usuário autenticado e `sendEmail` manda e-mail com o remetente do app.
70
71
  - `resolveApiKeyToken`, `readTokenAppId` e `tokenAuthorizesApp`: contrato da troca de API key por token, para o SDK que autentica por chave.
71
72
 
72
73
  ## Configuração
@@ -95,8 +96,13 @@ const { data: tasks, hasMore } = await core.entities.getTable("Task").list({ lim
95
96
  - Fixe o app no adaptador: `getAppId` e o header `X-App-Id` vêm do valor configurado no seu SDK, nunca de um argumento de quem chama. Aplique as credenciais depois dos headers de `options`, como no exemplo, para que eles não as substituam.
96
97
  - O Core não repete requisição nem renova token. Se o seu transporte repetir, repita só o que não grava.
97
98
  - `publicFunctions` precisa de um transporte sem credencial. O Core não usa o transporte autenticado no lugar dele.
98
- - `sendAndWait` com `timeoutMs` ou `signal` só para de esperar; o turno continua no servidor. Para interromper, chame `cancel()`.
99
- - `cancel()` chamado antes de a box aceitar o prompt espera esse aceite e só então manda o stop; a promise resolve depois disso. Se o prompt não chegar a virar turno, nada é enviado e o status não passa por `cancelled`.
99
+ - `sendEmail({ to, subject, html, text?, cc?, bcc?, replyTo? })` não tem `from`: o Messenger usa o remetente do app do token. Por isso só o backend do app manda e-mail, com o token trocado pela API key ou o token da Server Function; token de usuário final do app recebe `403`. `to`, `cc` e `bcc` são listas com um endereço por item. Os limites ficam no Messenger e chegam como erro do seu `Transport`: `400` acima do limite de destinatários dele somando os três campos e `429` acima da cota diária do app, com o header `Retry-After` e `retry_after_seconds` no corpo.
100
+ - `sendAndWait` com `timeoutMs` ou `signal` só para de esperar; o turno continua no servidor. Para interromper, chame `cancel()`. A sessão continua acompanhando esse turno: se o canal cair depois do prazo, ela ainda fecha o turno pelo histórico, como faz com um `send`. Pelo histórico, o turno só fecha na linha que o termina: a do agente com o uso do turno, ou uma linha `ERROR`. As linhas que o Copilot grava com o turno rodando e a resposta atrasada da pergunta anterior não fecham nada. O stream do Copilot repete o turno em andamento a partir do que o histórico dele tem; o que a sessão já viu, pelo `sequence` da box, não sai de novo.
101
+ - `cancel()` chamado antes de a box aceitar o prompt espera esse aceite e só então manda o stop; a promise resolve depois disso. Se o prompt não chegar a virar turno, nada é enviado e o status não passa por `cancelled`. Mensagem mandada depois do `cancel()`, com o stop ainda sem resposta, sai como qualquer outra; a box espera o turno parado terminar e dá a ela um turno próprio, e o `sendAndWait` dela resolve com esse turno. Turno parado que a sessão fecha pelo histórico termina com `reason` `interrupted`.
102
+ - Toda mensagem sai na hora, com ou sem turno rodando; a sessão não guarda fila. Com turno rodando, a box coloca a mensagem dentro do turno em andamento (steering nativo do provedor), põe na fila do provedor para um turno próprio, ou dá a ela um turno próprio se o turno já acabou; o `sendAndWait` de cada mensagem resolve com o turno que a respondeu. No canal direto ela vai pelo socket com `mode: "steer"` (sem ele, a box põe a mensagem na fila do T3) e um `clientMessageId`, que a box devolve no frame que a aceita (`stepStart` ou `messageQueued`, este sem o prazo de 35 s). Quando o T3 entrega a mensagem ao turno em andamento, a box marca o ponto com um frame `steer`, sem turno novo: a sessão emite `steered` com `text` e `messageId`, para o app mostrar a mensagem ali, e o `turnEnd` daquele turno responde a ela. Se o turno acabar antes, ela ganha turno próprio, que abre com `stepStart`. O `clientMessageId` também volta no `error` que a recusa, que rejeita só aquela mensagem. Com o socket reconectando, ou sem canal direto, vai ao Copilot (`POST /inputs`), que a guarda como pendente enquanto a box liga. A mensagem mandada com turno rodando leva `agentType` e `reasoningEffort` para a box, que não troca o modelo do turno em andamento e os usa se a mensagem virar turno próprio; só quando vai ao Copilot com turno rodando eles são tirados, porque o Copilot reinicia a sessão viva para outro modelo. Recusa do Copilot com status de erro rejeita aquela mensagem e emite `error`. Falha no envio rejeita o `sendAndWait` e emite `error`; mensagem que ainda não saiu quando a sessão fecha é rejeitada e não é enviada. `queue`, `editQueueItem`, `removeQueueItem`, `clearQueue` e `queueChange` continuam na API só por compatibilidade, marcados como deprecated: a fila é sempre vazia, os métodos não fazem nada e o evento não é emitido.
103
+ - Subagentes: o evento `subagent` traz `subagentId`, `toolId` (o `toolId` do `tool` que o criou), `status` (os do T3: `pending`, `running`, `waiting`, `completed`, `failed`, `cancelled`, `interrupted`, `idle`; quando o T3 não manda status, fica o anterior), `progress`, `startedAt`, `endedAt` (epoch ms) e `childThreadId`; `session.subagents` guarda o último estado de cada um. A conversa do subagente vem em `subagentDelta` e `subagentTool`, com `parentToolId`, e nunca entra em `delta`, `content` nem no ciclo do turno do chat. `stopSubagent(subagentId)` para só ele e deixa o turno seguir; vai só pelo canal direto, e sem ele sai um `error` e nada é enviado.
104
+ - Pergunta do agente no meio do turno: o T3 pode pedir uma resposta à pessoa. O pedido chega como evento `raw` de tipo `user_input_request`, com o item do T3 no `payload` (perguntas e `requestId`); o turno fica esperando, sem prazo da SDK. Responda com `session.respondUserInput(requestId, answers, attachmentsByQuestionId?)`, que vai direto para a box. Se a box recusar a resposta, sai um `error` e o turno continua; com o canal direto fora (reconectando ou chat sem box), a resposta não é enviada e sai um `error` dizendo isso, para o app mandar de novo depois do `channelConnected`.
105
+ - Portão de rollout da 0.3.0: ela só entra nas SDKs de app (`platform-sdk` e SDK de Functions) quando o ambiente tiver zero box antiga (template do fork `experimental`). A box antiga trata a mensagem do meio do turno como início de turno novo, zera o uso e a identidade do turno, e nada disso aparece como erro. A SDK não distingue box antiga de box nova; o portão é o bump nas SDKs de app, que fixam a versão exata desta.
100
106
  - O `open()` do seu `eventSource` só deve resolver depois que o stream estiver conectado, para nenhum evento do turno se perder.
101
107
 
102
108
  ## Desenvolvimento
@@ -24,6 +24,26 @@ publishes.
24
24
 
25
25
  ## Versions
26
26
 
27
+ - `0.3.0-beta.2` is the `0.3.0-beta.1` parity surface republished with `messenger.sendEmail()` and the
28
+ `emailLoginEnabled` and `passwordLoginEnabled` fields of `apps.update()`, which the parity cases do
29
+ not cover. Same parity cases; the version exists so a consumer pinning the package can pin a corpus
30
+ with the same number.
31
+
32
+ - `0.3.0-beta.1` is the `0.3.0` parity surface published as a beta: the agent session that holds
33
+ no messages. Same parity cases; the version exists so a consumer pinning the package can pin a
34
+ corpus with the same number. `0.3.0-beta.0` shipped the same code without its own corpus and has
35
+ no entry here.
36
+
37
+ - `0.3.0` is the `0.2.13` parity surface republished with the agent session that holds no
38
+ messages: every message goes out at once and the queue API is deprecated and always empty.
39
+ Same parity cases; the version exists so a consumer pinning the package can pin a corpus with
40
+ the same number.
41
+
42
+ - `0.2.13` is the `0.2.12` parity surface republished with the occupied context of the chat:
43
+ `contextTokens` and `contextWindow` on `AgentTurnUsage`, which the parity cases do not cover.
44
+ Same parity cases; the version exists so a consumer pinning the package can pin a corpus with
45
+ the same number.
46
+
27
47
  - `0.2.12` is the stable release of the `0.2.12-beta.1` surface: a `cancel()` pressed before the turn
28
48
  starts waits for the box to admit the prompt and goes out right after it. Same parity cases; the
29
49
  version exists so a consumer pinning the stable package can pin a corpus with the same number.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "contract": "SDK-PARITY-001",
3
- "current": "0.2.12",
3
+ "current": "0.3.0-beta.2",
4
4
  "versions": [
5
5
  {
6
6
  "version": "0.1.0",
@@ -115,6 +115,26 @@
115
115
  "version": "0.2.12",
116
116
  "path": "v0.2.12/sdk-parity.json",
117
117
  "sha256": "685238cadcf898128a5dad60c30bcdd8dcc9a02f03077d765aee01f8d6e34709"
118
+ },
119
+ {
120
+ "version": "0.2.13",
121
+ "path": "v0.2.13/sdk-parity.json",
122
+ "sha256": "36a1dd5b8d0ab604a8baa68ce19823c9b2f2745cdf57fad9000917b83c60be20"
123
+ },
124
+ {
125
+ "version": "0.3.0",
126
+ "path": "v0.3.0/sdk-parity.json",
127
+ "sha256": "dc7dceb99e29810dfd2cf30d76ec80ea8c5d6dbf5c8dac3038f58a2d36cbc793"
128
+ },
129
+ {
130
+ "version": "0.3.0-beta.1",
131
+ "path": "v0.3.0-beta.1/sdk-parity.json",
132
+ "sha256": "ee6f6e828771cdb8a6bfdbe33734ba9c0bb287d57c711ec87cdaf2b72a643cc0"
133
+ },
134
+ {
135
+ "version": "0.3.0-beta.2",
136
+ "path": "v0.3.0-beta.2/sdk-parity.json",
137
+ "sha256": "0bc945032e37eddd4418dc5178af404975c38da27f35d31e8a13f2fda77cffd1"
118
138
  }
119
139
  ]
120
140
  }