@mitralab.io/sdk-core 0.2.8 → 0.2.9-beta.1

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,39 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 0.2.9-beta.1
6
+
7
+ - Only a business agent's chat (one with an `agentId`) is created with `runtime: "T3"` and asks
8
+ the Copilot for the direct channel. Any other chat is created and streamed as before: 0.2.9-beta.0
9
+ put T3 on every new chat, which the Copilot refuses outside an agent chat
10
+ (`RUNTIME_REQUIRES_AGENT_APP`).
11
+ - A box event stream answered 200 with a type other than `text/event-stream` is a box without
12
+ the HTTP routes: `channelDeclined` `http_unsupported`, without reading it as a stream.
13
+ `AgentFetchResponse` now carries `headers`.
14
+ - Box refusals follow the final POST contract: 409, 400, 413, 503 and 504 reject with
15
+ `AgentTaskTurnError` and the box's `error_code` and `message`, the 504 included.
16
+
17
+ ## 0.2.9-beta.0
18
+
19
+ - Take the chat's direct channel to its box as the Agent session transport. Sessions ask the
20
+ Copilot for the channel (`agentTasks.channel`, `POST /api/v1/tasks/{id}/channel`) and send
21
+ messages and interrupts to the box: on its socket for `websocket`, on its HTTP routes (POST to
22
+ send, SSE to read) for `http`, and on the socket when available or HTTP otherwise for `auto`.
23
+ Same host rule, redial with backoff and replay, and raw `channelDeclined`,
24
+ `channelReconnecting` and `channelConnected` events as the platform SDK 1.2.0.
25
+ - Fall back to the concrete SDK's event source and REST inputs only when the channel cannot be
26
+ followed, and always say so with `channelDeclined` (`unavailable`, `body`, `host`,
27
+ `websocket`, `http_unsupported`).
28
+ - Accept a WebSocket implementation through `directChannel.WebSocket` and a fetch through
29
+ `directChannel.fetch` for runtimes without a global one. No new dependency.
30
+ - Count a message as sent only when the box starts the admitted turn (`stepStart`, or the 200 of
31
+ the HTTP POST), and emit the new `accepted` session event then, or after the Copilot's 202 on
32
+ REST. A refusal in the HTTP answer rejects with `AgentTaskTurnError` and the box's code.
33
+ - Create new chats with `runtime: "T3"` when the session can reach the box and names no runtime.
34
+ - The HTTP transport is not yet proven against a real box: it waits for the box routes
35
+ (t3code-mitra#180) and a gateway route behind the dev proxy.
36
+ - Publish contract corpus `0.2.9-beta.0` with the same parity cases.
37
+
5
38
  ## 0.2.0-beta.1
6
39
 
7
40
  This working tree prepares the `0.2.0-beta.1` package. Publication provenance remains
package/README.md CHANGED
@@ -33,14 +33,15 @@ The package contains:
33
33
  - business agents and workflows
34
34
  - integration configs, resources, templates, tests, proxying, and executions
35
35
  - Copilot tasks, messages, credentials, models, and app connections
36
- - a transport-agnostic Agent task live-session state machine with bounded queue and `sendAndWait`
36
+ - an Agent task live-session state machine with bounded queue and `sendAndWait`, and the direct
37
+ channel to the chat's box
37
38
  - Messenger notifications and composed safe app context
38
39
  - anonymous public Function execution
39
40
  - a minimal transport interface injected by each concrete SDK
40
41
 
41
42
  The package does not contain:
42
43
 
43
- - `fetch` or any other HTTP implementation
44
+ - `fetch` or any other HTTP implementation, or a WebSocket implementation
44
45
  - tokens, authorization headers, or environment variables
45
46
  - login, sign-up, logout, refresh, browser storage, or auth listeners
46
47
  - retry, redirect, timeout, or client lifecycle policy
@@ -49,8 +50,9 @@ Those concerns stay in the concrete SDK because browser sessions and Server Func
49
50
 
50
51
  ## Agent task live sessions
51
52
 
52
- Core owns the state machine but never opens a network connection. A concrete SDK implements
53
- `AgentTaskEventSource`, then composes it with the REST task module:
53
+ Core owns the state machine and the direct channel to the chat's box. A concrete SDK implements
54
+ `AgentTaskEventSource`, the Copilot stream a chat falls back to, then composes it with the REST
55
+ task module:
54
56
 
55
57
  ```typescript
56
58
  import {
@@ -63,7 +65,11 @@ import {
63
65
  declare const eventSource: AgentTaskEventSource
64
66
  declare const core: SdkCore
65
67
 
66
- const sessions = createAgentTaskSessionManager({ tasks: core.agentTasks, eventSource })
68
+ const sessions = createAgentTaskSessionManager({
69
+ tasks: core.agentTasks,
70
+ eventSource,
71
+ directChannel: { apiUrl: "https://api.mitralab.ai" },
72
+ })
67
73
  const agentTasks = withAgentTaskSessions(core.agentTasks, sessions)
68
74
  const session = agentTasks.session({ taskId: "task-id", transport: "http" })
69
75
  const result = await session.sendAndWait("Summarize the app", { timeoutMs: 120_000 })
@@ -77,13 +83,75 @@ reconnection and reconciles persisted messages; live deltas across that gap are
77
83
  be lossless. Abort and timeout stop the local `sendAndWait` waiter but do not interrupt the remote
78
84
  turn. Use `cancel()` when interruption is intended.
79
85
 
86
+ ### Direct channel
87
+
88
+ The direct channel is on when the concrete SDK passes `directChannel.apiUrl`, and it serves a
89
+ business agent's chat, the one with an `agentId`: only those have a box. Any other chat, or any
90
+ chat without `apiUrl`, stays on the event source and REST inputs, with no channel request and
91
+ no T3 default. A business agent's chat asks the Copilot once where it is served
92
+ (`POST /api/v1/tasks/{id}/channel`, through `agentTasks.channel`) and talks to the box that
93
+ answers. The box runs the turn; the Copilot hands out the channel, admits every turn and
94
+ receives the box log. A new business agent's chat is created with `runtime: "T3"` so it is born
95
+ on its box, unless the session names a runtime; the Copilot refuses T3 for any other chat
96
+ (`RUNTIME_REQUIRES_AGENT_APP`).
97
+
98
+ - **Transport.** `websocket` uses the box socket. `http` uses the box's HTTP routes next to the
99
+ socket path: `POST .../api/mitra/chat/messages` to send and `GET .../api/mitra/chat/events`
100
+ (SSE, from a sequence) to read, keeping the `grant` and `ticket` query of the channel URL.
101
+ `auto` uses the socket when a WebSocket implementation is available and HTTP otherwise, which
102
+ is the case of a Serverless Function.
103
+ The grant in those URLs lasts 10 minutes and the dev proxy ticket 60 seconds: a 401 or 403 without
104
+ an `error_code` on the POST or on opening the stream asks the Copilot for the channel again and
105
+ retries once on the fresh URLs; a second rejection is an error. One with an `error_code` is a
106
+ refusal and is answered once, as it came.
107
+ - **Host rule.** The channel URL carries a grant, so Core only reaches the API gateway host
108
+ (`directChannel.apiUrl`, over `wss:` when the API is `https:`) or a fleet box host over `wss:` (`*.e2b.app`,
109
+ `*.e2b-<env>.mitralab.ai`), on either transport.
110
+ - **Fallback, always visible.** When the Copilot answers 202 or an error (a Copilot without
111
+ `/channel`), the body has no `wsUrl`, the host is outside the rule, a `websocket` session has
112
+ no WebSocket, the box cannot be reached (a handshake that times out or is refused, a proxy
113
+ blocking its host, a network error on the HTTP stream), or the box has no HTTP routes (a 404,
114
+ or a stream that is not `text/event-stream`, from a template older than them), the
115
+ session stays on the event source and REST inputs and first emits a raw `channelDeclined`
116
+ event with `reason` `unavailable`, `body`, `host`, `websocket`, or `http_unsupported`.
117
+ - **Runtimes without WebSocket.** Core uses `directChannel.WebSocket` when given, otherwise
118
+ `globalThis.WebSocket`; Node 18 and 20 have none, so inject one such as `ws` or let `auto` take
119
+ HTTP. The socket type only asks for `readyState`, the four `on*` handlers, `send`, and `close`.
120
+ HTTP uses `directChannel.fetch` when given, otherwise `globalThis.fetch`.
121
+ - **Admission.** The session counts a message as sent only when the box answers for it: the
122
+ `stepStart` frame on the stream, or the 200 of the HTTP POST, both the box starting the turn
123
+ the Copilot admitted. The session then emits `accepted`, and from there the turn runs and
124
+ reaches the Copilot's log even if this process goes away. A refusal is reported once through
125
+ `error`: an `error` frame on the stream, or a POST answered 409 (not admitted), 400 (bad
126
+ frame), 413 (too large), 503 (nobody to admit) or 504 (no admission or turn within 30 s), each
127
+ with `{error_code, message}`, which rejects `sendAndWait` with `AgentTaskTurnError` carrying
128
+ that code and message. A box silent for 35 s with the wire up fails the send; a redial pauses that clock and a successful one
129
+ restarts it. Over REST, `accepted` follows the Copilot's 202. A caller that does not
130
+ wait for the answer, such as a Serverless Function, awaits `accepted` before it returns;
131
+ `sendAndWait` waits for the whole turn.
132
+ - **Drops.** A socket or stream lost in the middle of a turn, or while a message waits for
133
+ admission, is redialed with backoff (1, 2, 4, 8, 16 s), asking the Copilot for the channel on
134
+ each attempt and replaying the box log from the last sequence seen, so an admission that
135
+ happened during the drop still arrives. A POST the network lost is not sent again for the same
136
+ reason. The raw `channelReconnecting` and `channelConnected` events report the redial. An idle
137
+ wire that closes, a socket superseded by another open (4409), a redial that gives up, or a
138
+ Copilot that stops offering the channel is a disconnect for the session. Opening never replays
139
+ older frames: what an idle chat missed is history.
140
+ - Interrupts go to the box too; approvals stay on REST.
141
+ - **Status of the HTTP transport.** Not yet proven against a real box. It needs the box HTTP
142
+ routes in the t3code-mitra fork (mitralab-dev/t3code-mitra#180, in progress) and, behind the
143
+ dev proxy, a gateway route for them: the gateway only routes `.../api/mitra/chat/ws` today.
144
+ Until both ship, an `http` session, or an `auto` one without WebSocket, falls back to the
145
+ Copilot with `channelDeclined`. The WebSocket transport was proven against a dev box.
146
+
80
147
  ## Installation
81
148
 
82
149
  ```bash
83
150
  npm install @mitralab.io/sdk-core
84
151
  ```
85
152
 
86
- Node.js 18 or newer is required. The package has no runtime dependencies.
153
+ Node.js 18 or newer is required. The package has no runtime dependencies; the direct channel
154
+ needs a WebSocket implementation on runtimes without a global one.
87
155
 
88
156
  ## Transport contract
89
157
 
@@ -24,6 +24,14 @@ publishes.
24
24
 
25
25
  ## Versions
26
26
 
27
+ - `0.2.9-beta.1` is the `0.2.9-beta.0` parity surface republished with the direct channel
28
+ limited to business agent chats and the box refusals of the final contract. Same parity
29
+ cases; the version exists so a consumer pinning the package can pin a corpus with the same number.
30
+
31
+ - `0.2.9-beta.0` is the `0.2.8` parity surface republished with the direct box channel on the
32
+ Agent session and `agentTasks.channel`, which the parity cases do not cover. Same parity cases;
33
+ the version exists so a consumer pinning the package can pin a corpus with the same number.
34
+
27
35
  - `0.2.8` is the stable release of the `0.2.8-beta.0` surface: the credential scope, the
28
36
  person's custom providers, and task creation without the model field. Same parity cases;
29
37
  the 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.8",
3
+ "current": "0.2.9-beta.1",
4
4
  "versions": [
5
5
  {
6
6
  "version": "0.1.0",
@@ -70,6 +70,16 @@
70
70
  "version": "0.2.8",
71
71
  "path": "v0.2.8/sdk-parity.json",
72
72
  "sha256": "85f48fa684d2f0bf44ab818d69f53c1802b6699b78cf49ab0c64c442891354cf"
73
+ },
74
+ {
75
+ "version": "0.2.9-beta.0",
76
+ "path": "v0.2.9-beta.0/sdk-parity.json",
77
+ "sha256": "393142e56660b2fd90d51ab5e00fadd8c4454164783da23f0c1fbb264ccf92e0"
78
+ },
79
+ {
80
+ "version": "0.2.9-beta.1",
81
+ "path": "v0.2.9-beta.1/sdk-parity.json",
82
+ "sha256": "f0ec4130c399f7102ad20b6dc54ed50da957003d19d3ab811d013ce89b5cde06"
73
83
  }
74
84
  ]
75
85
  }