@llmsafespaces/sdk 0.17.0 → 0.18.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/dist/index.cjs CHANGED
@@ -315,14 +315,15 @@ var SessionsAPI = class {
315
315
  rename(workspaceId, sessionId, title) {
316
316
  return this.client.request("PUT", `/workspaces/${workspaceId}/sessions/${sessionId}/title`, { title });
317
317
  }
318
- async sendMessage(workspaceId, sessionId, content) {
319
- const raw = await this.client.request(
318
+ /** Sends synchronously; returns the completed assistant Message (contract shape). */
319
+ sendMessage(workspaceId, sessionId, content) {
320
+ return this.client.request(
320
321
  "POST",
321
322
  `/workspaces/${workspaceId}/sessions/${sessionId}/message`,
322
323
  { content, parts: [{ type: "text", text: content }] }
323
324
  );
324
- return { raw, content: extractTextContent(raw) };
325
325
  }
326
+ /** Returns the session transcript in contract shape. */
326
327
  getHistory(workspaceId, sessionId) {
327
328
  return this.client.request("GET", `/workspaces/${workspaceId}/sessions/${sessionId}/message`);
328
329
  }
@@ -554,12 +555,6 @@ var ProbeAPI = class {
554
555
  return this.client.request("POST", "/probe-models", { apiKey, baseURL });
555
556
  }
556
557
  };
557
- function extractTextContent(raw) {
558
- if (!raw || typeof raw !== "object") return "";
559
- const obj = raw;
560
- if (!Array.isArray(obj.parts)) return "";
561
- return obj.parts.filter((p) => p.type === "text" && p.text).map((p) => p.text).join("");
562
- }
563
558
  var PromptsAPI = class {
564
559
  constructor(client) {
565
560
  this.client = client;
package/dist/index.d.cts CHANGED
@@ -107,10 +107,106 @@ interface ActiveSessionsResponse {
107
107
  active: string[];
108
108
  maxActive: number;
109
109
  }
110
- /** Opencode message response (proxy passthrough). */
111
- interface MessageResponse {
112
- raw: unknown;
113
- content: string;
110
+ /**
111
+ * One entry in a session transcript (pkg/session contract, design 0049).
112
+ * Flat discriminated struct: type selects which fields are meaningful.
113
+ */
114
+ interface Message {
115
+ id: string;
116
+ sessionId?: string;
117
+ type: "user" | "assistant" | "shell" | "agent_switch" | "model_switch" | "compaction" | "system";
118
+ createdAt?: string;
119
+ parts?: Part[];
120
+ model?: ModelRef;
121
+ cost?: Cost;
122
+ /** Plain-text form (user/system/compaction messages). */
123
+ text?: string;
124
+ /** Shell-message fields. */
125
+ command?: string;
126
+ exitCode?: number;
127
+ /** Agent/model-switch fields. */
128
+ fromAgent?: string;
129
+ toAgent?: string;
130
+ fromModel?: ModelRef;
131
+ toModel?: ModelRef;
132
+ error?: {
133
+ code?: string;
134
+ message: string;
135
+ };
136
+ }
137
+ /** One renderable part of a message — the closed 5-type union. */
138
+ interface Part {
139
+ type: "text" | "reasoning" | "tool" | "file-change" | "custom";
140
+ id?: string;
141
+ text?: string;
142
+ reasoning?: string;
143
+ tool?: ToolPart;
144
+ fileChange?: FileDiff;
145
+ custom?: {
146
+ kind: string;
147
+ data?: unknown;
148
+ };
149
+ }
150
+ /** Every tool call is a ToolPart discriminated by name. */
151
+ interface ToolPart {
152
+ callId?: string;
153
+ name: string;
154
+ input?: unknown;
155
+ output?: unknown;
156
+ state: {
157
+ status: "pending" | "running" | "completed" | "error";
158
+ error?: string;
159
+ startedAt?: string;
160
+ completedAt?: string;
161
+ };
162
+ }
163
+ /** Unified-diff payload of a file-change part (patch text is authoritative). */
164
+ interface FileDiff {
165
+ path: string;
166
+ oldPath?: string;
167
+ status: "added" | "modified" | "deleted" | "renamed";
168
+ patch: string;
169
+ additions?: number;
170
+ deletions?: number;
171
+ }
172
+ /** The unified pending-input shape ("the agent needs a human"). */
173
+ interface InputRequest {
174
+ id: string;
175
+ sessionId?: string;
176
+ rootSessionId?: string;
177
+ kind: "question" | "permission";
178
+ question?: string;
179
+ header?: string;
180
+ options?: InputOption[];
181
+ multiple?: boolean;
182
+ custom?: boolean;
183
+ permission?: string;
184
+ patterns?: string[];
185
+ always?: string[];
186
+ metadata?: Record<string, unknown>;
187
+ tool?: ToolRef;
188
+ }
189
+ interface InputOption {
190
+ label: string;
191
+ description?: string;
192
+ }
193
+ interface ToolRef {
194
+ messageId?: string;
195
+ callId?: string;
196
+ }
197
+ interface ModelRef {
198
+ id: string;
199
+ provider?: string;
200
+ }
201
+ /** Display-only token/cost data (never billing). */
202
+ interface Cost {
203
+ inputTokens?: number;
204
+ outputTokens?: number;
205
+ reasoningTokens?: number;
206
+ cacheReadTokens?: number;
207
+ cacheWriteTokens?: number;
208
+ totalTokens?: number;
209
+ costUsd?: number;
114
210
  }
115
211
  interface AuthResponse {
116
212
  token: string;
@@ -278,8 +374,10 @@ declare class SessionsAPI {
278
374
  list(workspaceId: string): Promise<SessionListItem[]>;
279
375
  getActive(workspaceId: string): Promise<ActiveSessionsResponse>;
280
376
  rename(workspaceId: string, sessionId: string, title: string): Promise<void>;
281
- sendMessage(workspaceId: string, sessionId: string, content: string): Promise<MessageResponse>;
282
- getHistory(workspaceId: string, sessionId: string): Promise<unknown[]>;
377
+ /** Sends synchronously; returns the completed assistant Message (contract shape). */
378
+ sendMessage(workspaceId: string, sessionId: string, content: string): Promise<Message>;
379
+ /** Returns the session transcript in contract shape. */
380
+ getHistory(workspaceId: string, sessionId: string): Promise<Message[]>;
283
381
  abort(workspaceId: string, sessionId: string): Promise<void>;
284
382
  get(workspaceId: string, sessionId: string): Promise<Record<string, unknown>>;
285
383
  sendPromptAsync(workspaceId: string, sessionId: string, message: string): Promise<void>;
@@ -580,4 +678,4 @@ declare class ServiceUnavailableError extends LLMSafeSpacesError {
580
678
  constructor(message?: string, reason?: string, retryAfter?: number);
581
679
  }
582
680
 
583
- export { type APIKey, type ActivateWorkspaceResponse, type ActiveSessionsResponse, AuthError, type AuthResponse, type ClientOptions, ConflictError, type CreateProviderCredentialRequest, type CreateSecretRequest, type CreateWorkspaceRequest, type EnsureSessionResponse, type FetchFn, LLMSafeSpaces, LLMSafeSpacesError, type MessageResponse, NotFoundError, type PaginationMetadata, type ProviderCredential, type QueuedMessage, RateLimitError, type RefreshWorkspaceResult, SECRET_NAME_PATTERN, type SecretResponse, ServiceUnavailableError, type SessionListItem, type TerminalTicket, TimeoutError, type UpdateProviderCredentialRequest, type User, type Workspace, type WorkspaceCondition, type WorkspaceListItem, type WorkspaceListResult, type WorkspaceStatusResult };
681
+ export { type APIKey, type ActivateWorkspaceResponse, type ActiveSessionsResponse, AuthError, type AuthResponse, type ClientOptions, ConflictError, type Cost, type CreateProviderCredentialRequest, type CreateSecretRequest, type CreateWorkspaceRequest, type EnsureSessionResponse, type FetchFn, type FileDiff, type InputOption, type InputRequest, LLMSafeSpaces, LLMSafeSpacesError, type Message, type ModelRef, NotFoundError, type PaginationMetadata, type Part, type ProviderCredential, type QueuedMessage, RateLimitError, type RefreshWorkspaceResult, SECRET_NAME_PATTERN, type SecretResponse, ServiceUnavailableError, type SessionListItem, type TerminalTicket, TimeoutError, type ToolPart, type ToolRef, type UpdateProviderCredentialRequest, type User, type Workspace, type WorkspaceCondition, type WorkspaceListItem, type WorkspaceListResult, type WorkspaceStatusResult };
package/dist/index.d.ts CHANGED
@@ -107,10 +107,106 @@ interface ActiveSessionsResponse {
107
107
  active: string[];
108
108
  maxActive: number;
109
109
  }
110
- /** Opencode message response (proxy passthrough). */
111
- interface MessageResponse {
112
- raw: unknown;
113
- content: string;
110
+ /**
111
+ * One entry in a session transcript (pkg/session contract, design 0049).
112
+ * Flat discriminated struct: type selects which fields are meaningful.
113
+ */
114
+ interface Message {
115
+ id: string;
116
+ sessionId?: string;
117
+ type: "user" | "assistant" | "shell" | "agent_switch" | "model_switch" | "compaction" | "system";
118
+ createdAt?: string;
119
+ parts?: Part[];
120
+ model?: ModelRef;
121
+ cost?: Cost;
122
+ /** Plain-text form (user/system/compaction messages). */
123
+ text?: string;
124
+ /** Shell-message fields. */
125
+ command?: string;
126
+ exitCode?: number;
127
+ /** Agent/model-switch fields. */
128
+ fromAgent?: string;
129
+ toAgent?: string;
130
+ fromModel?: ModelRef;
131
+ toModel?: ModelRef;
132
+ error?: {
133
+ code?: string;
134
+ message: string;
135
+ };
136
+ }
137
+ /** One renderable part of a message — the closed 5-type union. */
138
+ interface Part {
139
+ type: "text" | "reasoning" | "tool" | "file-change" | "custom";
140
+ id?: string;
141
+ text?: string;
142
+ reasoning?: string;
143
+ tool?: ToolPart;
144
+ fileChange?: FileDiff;
145
+ custom?: {
146
+ kind: string;
147
+ data?: unknown;
148
+ };
149
+ }
150
+ /** Every tool call is a ToolPart discriminated by name. */
151
+ interface ToolPart {
152
+ callId?: string;
153
+ name: string;
154
+ input?: unknown;
155
+ output?: unknown;
156
+ state: {
157
+ status: "pending" | "running" | "completed" | "error";
158
+ error?: string;
159
+ startedAt?: string;
160
+ completedAt?: string;
161
+ };
162
+ }
163
+ /** Unified-diff payload of a file-change part (patch text is authoritative). */
164
+ interface FileDiff {
165
+ path: string;
166
+ oldPath?: string;
167
+ status: "added" | "modified" | "deleted" | "renamed";
168
+ patch: string;
169
+ additions?: number;
170
+ deletions?: number;
171
+ }
172
+ /** The unified pending-input shape ("the agent needs a human"). */
173
+ interface InputRequest {
174
+ id: string;
175
+ sessionId?: string;
176
+ rootSessionId?: string;
177
+ kind: "question" | "permission";
178
+ question?: string;
179
+ header?: string;
180
+ options?: InputOption[];
181
+ multiple?: boolean;
182
+ custom?: boolean;
183
+ permission?: string;
184
+ patterns?: string[];
185
+ always?: string[];
186
+ metadata?: Record<string, unknown>;
187
+ tool?: ToolRef;
188
+ }
189
+ interface InputOption {
190
+ label: string;
191
+ description?: string;
192
+ }
193
+ interface ToolRef {
194
+ messageId?: string;
195
+ callId?: string;
196
+ }
197
+ interface ModelRef {
198
+ id: string;
199
+ provider?: string;
200
+ }
201
+ /** Display-only token/cost data (never billing). */
202
+ interface Cost {
203
+ inputTokens?: number;
204
+ outputTokens?: number;
205
+ reasoningTokens?: number;
206
+ cacheReadTokens?: number;
207
+ cacheWriteTokens?: number;
208
+ totalTokens?: number;
209
+ costUsd?: number;
114
210
  }
115
211
  interface AuthResponse {
116
212
  token: string;
@@ -278,8 +374,10 @@ declare class SessionsAPI {
278
374
  list(workspaceId: string): Promise<SessionListItem[]>;
279
375
  getActive(workspaceId: string): Promise<ActiveSessionsResponse>;
280
376
  rename(workspaceId: string, sessionId: string, title: string): Promise<void>;
281
- sendMessage(workspaceId: string, sessionId: string, content: string): Promise<MessageResponse>;
282
- getHistory(workspaceId: string, sessionId: string): Promise<unknown[]>;
377
+ /** Sends synchronously; returns the completed assistant Message (contract shape). */
378
+ sendMessage(workspaceId: string, sessionId: string, content: string): Promise<Message>;
379
+ /** Returns the session transcript in contract shape. */
380
+ getHistory(workspaceId: string, sessionId: string): Promise<Message[]>;
283
381
  abort(workspaceId: string, sessionId: string): Promise<void>;
284
382
  get(workspaceId: string, sessionId: string): Promise<Record<string, unknown>>;
285
383
  sendPromptAsync(workspaceId: string, sessionId: string, message: string): Promise<void>;
@@ -580,4 +678,4 @@ declare class ServiceUnavailableError extends LLMSafeSpacesError {
580
678
  constructor(message?: string, reason?: string, retryAfter?: number);
581
679
  }
582
680
 
583
- export { type APIKey, type ActivateWorkspaceResponse, type ActiveSessionsResponse, AuthError, type AuthResponse, type ClientOptions, ConflictError, type CreateProviderCredentialRequest, type CreateSecretRequest, type CreateWorkspaceRequest, type EnsureSessionResponse, type FetchFn, LLMSafeSpaces, LLMSafeSpacesError, type MessageResponse, NotFoundError, type PaginationMetadata, type ProviderCredential, type QueuedMessage, RateLimitError, type RefreshWorkspaceResult, SECRET_NAME_PATTERN, type SecretResponse, ServiceUnavailableError, type SessionListItem, type TerminalTicket, TimeoutError, type UpdateProviderCredentialRequest, type User, type Workspace, type WorkspaceCondition, type WorkspaceListItem, type WorkspaceListResult, type WorkspaceStatusResult };
681
+ export { type APIKey, type ActivateWorkspaceResponse, type ActiveSessionsResponse, AuthError, type AuthResponse, type ClientOptions, ConflictError, type Cost, type CreateProviderCredentialRequest, type CreateSecretRequest, type CreateWorkspaceRequest, type EnsureSessionResponse, type FetchFn, type FileDiff, type InputOption, type InputRequest, LLMSafeSpaces, LLMSafeSpacesError, type Message, type ModelRef, NotFoundError, type PaginationMetadata, type Part, type ProviderCredential, type QueuedMessage, RateLimitError, type RefreshWorkspaceResult, SECRET_NAME_PATTERN, type SecretResponse, ServiceUnavailableError, type SessionListItem, type TerminalTicket, TimeoutError, type ToolPart, type ToolRef, type UpdateProviderCredentialRequest, type User, type Workspace, type WorkspaceCondition, type WorkspaceListItem, type WorkspaceListResult, type WorkspaceStatusResult };
package/dist/index.js CHANGED
@@ -281,14 +281,15 @@ var SessionsAPI = class {
281
281
  rename(workspaceId, sessionId, title) {
282
282
  return this.client.request("PUT", `/workspaces/${workspaceId}/sessions/${sessionId}/title`, { title });
283
283
  }
284
- async sendMessage(workspaceId, sessionId, content) {
285
- const raw = await this.client.request(
284
+ /** Sends synchronously; returns the completed assistant Message (contract shape). */
285
+ sendMessage(workspaceId, sessionId, content) {
286
+ return this.client.request(
286
287
  "POST",
287
288
  `/workspaces/${workspaceId}/sessions/${sessionId}/message`,
288
289
  { content, parts: [{ type: "text", text: content }] }
289
290
  );
290
- return { raw, content: extractTextContent(raw) };
291
291
  }
292
+ /** Returns the session transcript in contract shape. */
292
293
  getHistory(workspaceId, sessionId) {
293
294
  return this.client.request("GET", `/workspaces/${workspaceId}/sessions/${sessionId}/message`);
294
295
  }
@@ -520,12 +521,6 @@ var ProbeAPI = class {
520
521
  return this.client.request("POST", "/probe-models", { apiKey, baseURL });
521
522
  }
522
523
  };
523
- function extractTextContent(raw) {
524
- if (!raw || typeof raw !== "object") return "";
525
- const obj = raw;
526
- if (!Array.isArray(obj.parts)) return "";
527
- return obj.parts.filter((p) => p.type === "text" && p.text).map((p) => p.text).join("");
528
- }
529
524
  var PromptsAPI = class {
530
525
  constructor(client) {
531
526
  this.client = client;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llmsafespaces/sdk",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "TypeScript SDK for LLMSafeSpaces API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",