@mitralab.io/sdk-core 0.2.8-beta.0 → 0.2.9-beta.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 CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 0.2.9-beta.0
6
+
7
+ - Take the chat's direct channel to its box as the Agent session transport. Sessions ask the
8
+ Copilot for the channel (`agentTasks.channel`, `POST /api/v1/tasks/{id}/channel`) and send
9
+ messages and interrupts to the box: on its socket for `websocket`, on its HTTP routes (POST to
10
+ send, SSE to read) for `http`, and on the socket when available or HTTP otherwise for `auto`.
11
+ Same host rule, redial with backoff and replay, and raw `channelDeclined`,
12
+ `channelReconnecting` and `channelConnected` events as the platform SDK 1.2.0.
13
+ - Fall back to the concrete SDK's event source and REST inputs only when the channel cannot be
14
+ followed, and always say so with `channelDeclined` (`unavailable`, `body`, `host`,
15
+ `websocket`, `http_unsupported`).
16
+ - Accept a WebSocket implementation through `directChannel.WebSocket` and a fetch through
17
+ `directChannel.fetch` for runtimes without a global one. No new dependency.
18
+ - Count a message as sent only when the box starts the admitted turn (`stepStart`, or the 200 of
19
+ the HTTP POST), and emit the new `accepted` session event then, or after the Copilot's 202 on
20
+ REST. A refusal in the HTTP answer rejects with `AgentTaskTurnError` and the box's code.
21
+ - Create new chats with `runtime: "T3"` when the session can reach the box and names no runtime.
22
+ - The HTTP transport is not yet proven against a real box: it waits for the box routes
23
+ (t3code-mitra#180) and a gateway route behind the dev proxy.
24
+ - Publish contract corpus `0.2.9-beta.0` with the same parity cases.
25
+
5
26
  ## 0.2.0-beta.1
6
27
 
7
28
  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,71 @@ 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`; without it the
89
+ session stays on the event source and REST inputs, with no channel request and no T3 default.
90
+ Every session then asks the Copilot once where the chat is served (`POST /api/v1/tasks/{id}/channel`,
91
+ through `agentTasks.channel`) and talks to the box that answers. The box runs the turn; the
92
+ Copilot hands out the channel, admits every turn and receives the box log. A new chat is created
93
+ with `runtime: "T3"` so it is born on its box, unless the session names a runtime.
94
+
95
+ - **Transport.** `websocket` uses the box socket. `http` uses the box's HTTP routes next to the
96
+ socket path: `POST .../api/mitra/chat/messages` to send and `GET .../api/mitra/chat/events`
97
+ (SSE, from a sequence) to read, keeping the `grant` and `ticket` query of the channel URL.
98
+ `auto` uses the socket when a WebSocket implementation is available and HTTP otherwise, which
99
+ is the case of a Serverless Function.
100
+ The grant in those URLs lasts 10 minutes and the dev proxy ticket 60 seconds: a 401 or 403 without
101
+ an `error_code` on the POST or on opening the stream asks the Copilot for the channel again and
102
+ retries once on the fresh URLs; a second rejection is an error. One with an `error_code` is a
103
+ refusal and is answered once, as it came.
104
+ - **Host rule.** The channel URL carries a grant, so Core only reaches the API gateway host
105
+ (`directChannel.apiUrl`, over `wss:` when the API is `https:`) or a fleet box host over `wss:` (`*.e2b.app`,
106
+ `*.e2b-<env>.mitralab.ai`), on either transport.
107
+ - **Fallback, always visible.** When the Copilot answers 202 or an error (a Copilot without
108
+ `/channel`), the body has no `wsUrl`, the host is outside the rule, a `websocket` session has
109
+ no WebSocket, the box cannot be reached (a handshake that times out or is refused, a proxy
110
+ blocking its host, a network error on the HTTP stream), or the box answers 404 on its HTTP
111
+ routes (a template older than them), the
112
+ session stays on the event source and REST inputs and first emits a raw `channelDeclined`
113
+ event with `reason` `unavailable`, `body`, `host`, `websocket`, or `http_unsupported`.
114
+ - **Runtimes without WebSocket.** Core uses `directChannel.WebSocket` when given, otherwise
115
+ `globalThis.WebSocket`; Node 18 and 20 have none, so inject one such as `ws` or let `auto` take
116
+ HTTP. The socket type only asks for `readyState`, the four `on*` handlers, `send`, and `close`.
117
+ HTTP uses `directChannel.fetch` when given, otherwise `globalThis.fetch`.
118
+ - **Admission.** The session counts a message as sent only when the box answers for it: the
119
+ `stepStart` frame on the stream, or the 200 of the HTTP POST, both the box starting the turn
120
+ the Copilot admitted. The session then emits `accepted`, and from there the turn runs and
121
+ reaches the Copilot's log even if this process goes away. A refusal is reported once through
122
+ `error`: an `error` frame on the stream, or the 4xx of the POST, which also rejects
123
+ `sendAndWait` with `AgentTaskTurnError` and the box's `error_code`. A 504, or a box silent for
124
+ 35 s with the wire up, fails the send; a redial pauses that clock and a successful one
125
+ restarts it. Over REST, `accepted` follows the Copilot's 202. A caller that does not
126
+ wait for the answer, such as a Serverless Function, awaits `accepted` before it returns;
127
+ `sendAndWait` waits for the whole turn.
128
+ - **Drops.** A socket or stream lost in the middle of a turn, or while a message waits for
129
+ admission, is redialed with backoff (1, 2, 4, 8, 16 s), asking the Copilot for the channel on
130
+ each attempt and replaying the box log from the last sequence seen, so an admission that
131
+ happened during the drop still arrives. A POST the network lost is not sent again for the same
132
+ reason. The raw `channelReconnecting` and `channelConnected` events report the redial. An idle
133
+ wire that closes, a socket superseded by another open (4409), a redial that gives up, or a
134
+ Copilot that stops offering the channel is a disconnect for the session. Opening never replays
135
+ older frames: what an idle chat missed is history.
136
+ - Interrupts go to the box too; approvals stay on REST.
137
+ - **Status of the HTTP transport.** Not yet proven against a real box. It needs the box HTTP
138
+ routes in the t3code-mitra fork (mitralab-dev/t3code-mitra#180, in progress) and, behind the
139
+ dev proxy, a gateway route for them: the gateway only routes `.../api/mitra/chat/ws` today.
140
+ Until both ship, an `http` session, or an `auto` one without WebSocket, falls back to the
141
+ Copilot with `channelDeclined`. The WebSocket transport was proven against a dev box.
142
+
80
143
  ## Installation
81
144
 
82
145
  ```bash
83
146
  npm install @mitralab.io/sdk-core
84
147
  ```
85
148
 
86
- Node.js 18 or newer is required. The package has no runtime dependencies.
149
+ Node.js 18 or newer is required. The package has no runtime dependencies; the direct channel
150
+ needs a WebSocket implementation on runtimes without a global one.
87
151
 
88
152
  ## Transport contract
89
153
 
@@ -24,6 +24,14 @@ publishes.
24
24
 
25
25
  ## Versions
26
26
 
27
+ - `0.2.9-beta.0` is the `0.2.8` parity surface republished with the direct box channel on the
28
+ Agent session and `agentTasks.channel`, which the parity cases do not cover. Same parity cases;
29
+ the version exists so a consumer pinning the package can pin a corpus with the same number.
30
+
31
+ - `0.2.8` is the stable release of the `0.2.8-beta.0` surface: the credential scope, the
32
+ person's custom providers, and task creation without the model field. Same parity cases;
33
+ the version exists so a consumer pinning the stable package can pin a corpus with the same number.
34
+
27
35
  - `0.2.8-beta.0` is the `0.2.7-beta.0` parity surface republished without the model field on
28
36
  task creation and messages: the agent type carries the custom provider selection. Same parity
29
37
  cases; the version exists so a consumer pinning the 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-beta.0",
3
+ "current": "0.2.9-beta.0",
4
4
  "versions": [
5
5
  {
6
6
  "version": "0.1.0",
@@ -65,6 +65,16 @@
65
65
  "version": "0.2.8-beta.0",
66
66
  "path": "v0.2.8-beta.0/sdk-parity.json",
67
67
  "sha256": "587122273ad4e248e924dade7a1ccba611d5387588520e95838c4b71b63eb00e"
68
+ },
69
+ {
70
+ "version": "0.2.8",
71
+ "path": "v0.2.8/sdk-parity.json",
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"
68
78
  }
69
79
  ]
70
80
  }