@theway-ai/sdk 2.2.0 → 2.2.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.
@@ -0,0 +1,126 @@
1
+ # @theway-ai/sdk Protocol Reference
2
+
3
+ This document describes the wire protocol and the main typed APIs exposed by
4
+ `@theway-ai/sdk`. It is intended for developers integrating with the theway
5
+ daemon (`thewayd`).
6
+
7
+ ## Services
8
+
9
+ The SDK wraps the theway gRPC services:
10
+
11
+ | Service | Purpose |
12
+ | --- | --- |
13
+ | `CommandService` | Prompt submission, abort, model/thinking control, control-plane approval |
14
+ | `SessionService` | Session lifecycle, snapshot, history, collapse, graph node reads |
15
+ | `SettingsService` | Daemon settings |
16
+ | `GraphEngineService` | DAG/goal run control and node output |
17
+ | `EventService` | Streaming snapshot/event frames |
18
+ | `Health` | gRPC health checks |
19
+
20
+ ## Session identity
21
+
22
+ - New session resource objects use `id`.
23
+ - `session_id` is retained on requests and legacy responses for compatibility.
24
+ - New clients should prefer `SessionInfo.id` / `SessionSummary.id`.
25
+
26
+ ## SessionSnapshot
27
+
28
+ `getSnapshot(sessionId)` returns a nested `SessionSnapshot`:
29
+
30
+ ```text
31
+ SessionSnapshot
32
+ ├── session: SessionInfo # id, name, cwd, created_at, metadata
33
+ ├── runtime: SessionRuntime # ModelRef, ThinkingLevel, supported_thinking_levels
34
+ ├── feed: SessionFeed # FeedBlock list + incremental cursors
35
+ ├── graphs: SessionGraphState # dags, subagents
36
+ └── lineage: SessionLineage # parent_id, child_ids, collapsed_node_ids
37
+ ```
38
+
39
+ ### Thinking levels
40
+
41
+ The protocol defines a canonical `ThinkingLevel` enum:
42
+
43
+ ```text
44
+ off | minimal | low | medium | high | xhigh
45
+ ```
46
+
47
+ A model may not support every level. `SessionRuntime.supported_thinking_levels`
48
+ is derived from the model's `thinkingLevelMap`; `thinking_level` must be one of
49
+ the supported values.
50
+
51
+ ## Pagination
52
+
53
+ ### GetHistory
54
+
55
+ Reads a session feed page by page.
56
+
57
+ ```ts
58
+ const res = await client.getHistory({
59
+ sessionId: 'sess-1',
60
+ offset: 0,
61
+ limit: 50,
62
+ });
63
+ // res.blocks: FeedBlock[]
64
+ // res.nextOffset
65
+ // res.total?
66
+ ```
67
+
68
+ ### ListSessionGraphNodeMessages
69
+
70
+ Reads one graph node's structured messages (`FeedBlock` list).
71
+
72
+ ```ts
73
+ const res = await client.listSessionGraphNodeMessages(
74
+ 'sess-1',
75
+ 'node-1',
76
+ 0,
77
+ 50,
78
+ );
79
+ ```
80
+
81
+ ## Graph nodes
82
+
83
+ Graph nodes are not all sessions. `SessionGraphNodeType`:
84
+
85
+ | Type | Meaning |
86
+ | --- | --- |
87
+ | `SESSION` | A collapsed session |
88
+ | `DAG_RUN` | A DAG run |
89
+ | `DAG_NODE` | A single DAG node |
90
+ | `SUBAGENT_JOB` | A subagent job |
91
+ | `GOAL_RUN` | A goal run |
92
+
93
+ `getSessionGraphNode(sessionId, nodeId)` returns one node's status/summary.
94
+ `streamSessionGraphNode(sessionId, nodeId)` returns a stream of
95
+ `SessionGraphNodeStreamFrame`:
96
+
97
+ ```text
98
+ node: SessionGraphNode # initial/periodic state
99
+ block: FeedBlock # new structured output
100
+ status: SessionGraphNodeStatus # running/completed/failed/...
101
+ ```
102
+
103
+ ## Collapse
104
+
105
+ `collapseSession(request)` turns the current session into a graph node and
106
+ creates a new session with a compact context.
107
+
108
+ ```ts
109
+ const res = await client.collapseSession({
110
+ sessionId: 'sess-1',
111
+ name: 'phase-2',
112
+ adoptRunningGraphs: false,
113
+ });
114
+ // res.childSessionId
115
+ // res.nodeId
116
+ // res.snapshot
117
+ ```
118
+
119
+ - Default: the old session's running DAG/subagent graph keeps running.
120
+ - `adoptRunningGraphs: true` migrates ownership to the new session.
121
+
122
+ ## Compatibility
123
+
124
+ - `getState()` remains available and returns the legacy `SessionState`.
125
+ - New code should prefer `getSnapshot()`.
126
+ - `session_id` fields on request messages remain the routing identifier.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theway-ai/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "TypeScript SDK for the theway gRPC daemon (five theway.grpc.v1 domain services + grpc.health.v1). Typed client for all RPCs, generated from the domain proto files via ts-proto.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -21,6 +21,7 @@
21
21
  "files": [
22
22
  "dist",
23
23
  "proto",
24
+ "docs",
24
25
  "README.md"
25
26
  ],
26
27
  "engines": {
@@ -59,12 +59,15 @@ message FeedBlockPatch {
59
59
 
60
60
  // Token usage for the current/last turn, plus the model's context window size.
61
61
  message ContextUsage {
62
- uint64 input_tokens = 1;
63
- uint64 output_tokens = 2;
64
- uint64 cache_read_tokens = 3;
65
- uint64 cache_write_tokens = 4;
66
- uint64 total_tokens = 5;
67
- uint32 context_window = 6;
62
+ uint64 cached_tokens = 1;
63
+ uint64 new_tokens = 2;
64
+ uint64 total_input_tokens = 3;
65
+ uint64 output_tokens = 4;
66
+ uint64 cache_write_tokens = 5;
67
+ optional double provider_cache_hit_rate = 6;
68
+ optional double prefix_cache_hit_rate = 7;
69
+ optional uint64 prefix_hit_tokens = 8;
70
+ uint32 context_window = 9;
68
71
  }
69
72
 
70
73
  message ProviderGroup {
@@ -187,9 +190,10 @@ message FeedBlock {
187
190
  UserBlock user = 1;
188
191
  AssistantBlock assistant = 2;
189
192
  ThinkingBlock thinking = 3;
190
- ToolBlock tool = 4;
191
193
  ToolResultBlock tool_result = 5;
192
194
  PlainBlock plain = 6;
195
+ ToolCallBlock tool_call = 7;
196
+ ErrorBlock error = 8;
193
197
  }
194
198
  }
195
199
 
@@ -208,10 +212,18 @@ message ThinkingBlock {
208
212
  optional string timestamp = 2; // RFC3339 / ISO-8601 with offset (UTC), null when absent.
209
213
  }
210
214
 
211
- message ToolBlock {
215
+ message ToolCallBlock {
212
216
  string name = 1;
213
217
  string args = 2;
214
- optional string timestamp = 3; // RFC3339 / ISO-8601 with offset (UTC), null when absent.
218
+ optional string metadata = 3; // Optional tool-call metadata (JSON string).
219
+ optional string timestamp = 4; // RFC3339 / ISO-8601 with offset (UTC), null when absent.
220
+ }
221
+
222
+ message ErrorBlock {
223
+ string message = 1;
224
+ optional string code = 2;
225
+ bool recoverable = 3;
226
+ optional string timestamp = 4; // RFC3339 / ISO-8601 with offset (UTC), null when absent.
215
227
  }
216
228
 
217
229
  message ToolResultBlock {
@@ -243,6 +255,7 @@ message SessionSummary {
243
255
  optional string preview = 10;
244
256
  map<string, string> metadata = 11;
245
257
  optional string last_activity_at_rfc3339 = 12; // RFC3339 / ISO-8601 with offset (UTC), null when absent.
258
+ string tree_prefix = 14; // Pi-style tree prefix (`├─ ` / `└─ ` / `│ `) for fork-lineage display.
246
259
  }
247
260
 
248
261
  // Thinking levels supported by the runtime.