@proteos/sdk 0.82.1 → 0.84.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteos/sdk",
3
- "version": "0.82.1",
3
+ "version": "0.84.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "TypeScript SDK for the Proteos platform",
6
6
  "repository": {
@@ -25,9 +25,10 @@ export type { ToolKind } from './types.js'
25
25
  /**
26
26
  * The latest lifecycle state of a session, projected from the `session.status_*`
27
27
  * events. `idle` = ready for the next user message; `running` = a turn is in
28
- * flight; `terminated` = ended; `error` = the last turn failed.
28
+ * flight; `terminated` = the provider session is gone; `error` = the last turn
29
+ * failed; `ended` = a person ended it — the next `user.message` reopens it.
29
30
  */
30
- export type SessionStatus = 'idle' | 'running' | 'terminated' | 'error'
31
+ export type SessionStatus = 'idle' | 'running' | 'terminated' | 'error' | 'ended'
31
32
 
32
33
  /**
33
34
  * The rolled-up token accounting for a session — the sum of every model request's
@@ -62,6 +63,10 @@ export interface Session extends AuditFields {
62
63
  title: string
63
64
  status: SessionStatus
64
65
  usage: SessionUsage
66
+ /** When the session was ended; null unless `status` is `ended`. */
67
+ ended_at: string | null
68
+ /** Who ended it; null unless `status` is `ended` (and on sessions ended by the platform). */
69
+ ended_by: UserRef | null
65
70
  }
66
71
 
67
72
  // ---------------------------------------------------------------------------
@@ -90,6 +95,7 @@ export type EventType =
90
95
  | 'session.status_running'
91
96
  | 'session.status_idle'
92
97
  | 'session.status_terminated'
98
+ | 'session.status_ended'
93
99
  | 'session.error'
94
100
  | 'session.updated'
95
101
  // Span (observability).
@@ -274,7 +280,7 @@ export interface ModelRequestEndPayload {
274
280
 
275
281
  /**
276
282
  * The body of events that carry no fields (`user.interrupt`,
277
- * `session.status_running`, `session.status_terminated`).
283
+ * `session.status_running`, `session.status_terminated`, `session.status_ended`).
278
284
  */
279
285
  export type EmptyPayload = Record<string, never>
280
286
 
@@ -318,6 +324,7 @@ export type SessionEvent = SessionEventEnvelope &
318
324
  | { type: 'session.status_running'; payload: EmptyPayload }
319
325
  | { type: 'session.status_idle'; payload: SessionIdlePayload }
320
326
  | { type: 'session.status_terminated'; payload: EmptyPayload }
327
+ | { type: 'session.status_ended'; payload: EmptyPayload }
321
328
  | { type: 'session.error'; payload: ErrorPayload }
322
329
  | { type: 'session.updated'; payload: SessionUpdatedPayload }
323
330
  | { type: 'span.model_request_start'; payload: ModelRequestStartPayload }
@@ -394,6 +401,15 @@ export interface AppendEventRequest {
394
401
  export interface ListSessionsOptions extends ListOptions {
395
402
  /** Filter by the agent the session runs. */
396
403
  agent_key?: string
404
+ /** Keep sessions in this status, or in any of several. */
405
+ status?: SessionStatus | SessionStatus[]
406
+ /** Keep sessions whose title contains this text, ignoring case. */
407
+ title?: string
408
+ /**
409
+ * Keep the sessions one user started: a user id, or `'me'` for the caller.
410
+ * It narrows what the caller may see and never widens it.
411
+ */
412
+ created_by?: string
397
413
  }
398
414
 
399
415
  /**
@@ -79,6 +79,12 @@ export interface SessionService {
79
79
  ): Promise<SessionEvent>
80
80
  /** Convenience: appends a `user.interrupt` to halt the running turn. */
81
81
  interrupt(id: string): Promise<SessionEvent>
82
+ /**
83
+ * Ends the session (`status: 'ended'`). A running turn is interrupted first and
84
+ * the session ends once it has closed, so the returned session can still read
85
+ * `running`. The next `user.message` reopens an ended session.
86
+ */
87
+ end(id: string): Promise<Session>
82
88
  /**
83
89
  * Convenience: appends a `user.tool_result` answering a client tool the agent
84
90
  * called (an `agent.tool_use` with `tool_kind: 'client'`). `toolUseId` is that
@@ -100,7 +106,12 @@ export class SessionServiceImpl implements SessionService {
100
106
  }
101
107
 
102
108
  async listPage(options: ListSessionsOptions = {}): Promise<ListResult<Session>> {
103
- return this.client.requestWithQuery<ListResult<Session>>('GET', SESSIONS_BASE_PATH, options)
109
+ // The API takes several statuses as one comma-separated value, not as a
110
+ // repeated parameter.
111
+ const query = Array.isArray(options.status)
112
+ ? { ...options, status: options.status.join(',') }
113
+ : options
114
+ return this.client.requestWithQuery<ListResult<Session>>('GET', SESSIONS_BASE_PATH, query)
104
115
  }
105
116
 
106
117
  async get(id: string): Promise<Session> {
@@ -186,6 +197,10 @@ export class SessionServiceImpl implements SessionService {
186
197
  return this.appendEvent(id, { type: 'user.interrupt' })
187
198
  }
188
199
 
200
+ async end(id: string): Promise<Session> {
201
+ return this.client.request<Session>('POST', `${SESSIONS_BASE_PATH}/${id}/end`)
202
+ }
203
+
189
204
  async submitToolResult(
190
205
  id: string,
191
206
  input: { toolUseId: string; result: ResultBlock[]; outcome?: 'success' | 'error' },
package/src/data/index.ts CHANGED
@@ -78,13 +78,18 @@ export type {
78
78
  RecordDraftIntent,
79
79
  RecordDraftItem,
80
80
  RecordDraftItemError,
81
+ RecordDraftItemInput,
81
82
  RecordDraftItemResult,
82
83
  RecordDraftItemResultStatus,
83
84
  RecordDraftStatus,
85
+ RecordDraftVersion,
86
+ RecordDraftVersionKind,
87
+ RecordDraftVersions,
84
88
  RecordDuplicate,
85
89
  RecordDuplicateSource,
86
90
  RecordDuplicateStatus,
87
91
  RejectRecordDraftRequest,
92
+ UpdateRecordDraftRequest,
88
93
  } from './types.js'
89
94
 
90
95
  // Re-export Zod schemas
@@ -5,7 +5,9 @@ import type {
5
5
  CreateRecordDraftRequest,
6
6
  ListRecordDraftsQuery,
7
7
  RecordDraft,
8
+ RecordDraftVersions,
8
9
  RejectRecordDraftRequest,
10
+ UpdateRecordDraftRequest,
9
11
  } from './types.js'
10
12
 
11
13
  const RECORD_DRAFTS_BASE_PATH = '/data/v1/record-drafts'
@@ -22,8 +24,17 @@ export interface RecordDraftService {
22
24
  get(id: string): Promise<RecordDraft>
23
25
  create(request: CreateRecordDraftRequest): Promise<RecordDraft>
24
26
  /**
25
- * Applies the draft as the caller. No `items` = as proposed; `items` = the
26
- * reviewer's edited proposal. Always 200 with the draft: `status` is
27
+ * Saves a proposed draft's items (a proposer's revision or a reviewer's
28
+ * edit) — nothing is written to the records. 409 `record_draft_conflict`
29
+ * when `expected_updated_at` is stale, `record_draft_not_proposed` once
30
+ * resolved.
31
+ */
32
+ update(id: string, request: UpdateRecordDraftRequest): Promise<RecordDraft>
33
+ /** The draft's history and what reviewers changed so far. */
34
+ listVersions(id: string): Promise<RecordDraftVersions>
35
+ /**
36
+ * Applies the draft as the caller. No `items` = its items as they stand;
37
+ * `items` = the reviewer's edit, saved first. Always 200 with the draft: `status` is
27
38
  * `approved` / `approved_with_changes` when every item succeeded, else still
28
39
  * `proposed` with per-item `results` to fix and re-approve. 409
29
40
  * `record_draft_not_proposed` once resolved.
@@ -55,6 +66,21 @@ export class RecordDraftServiceImpl implements RecordDraftService {
55
66
  return this.client.request<RecordDraft>('POST', RECORD_DRAFTS_BASE_PATH, request)
56
67
  }
57
68
 
69
+ async update(id: string, request: UpdateRecordDraftRequest): Promise<RecordDraft> {
70
+ return this.client.request<RecordDraft>(
71
+ 'PUT',
72
+ `${RECORD_DRAFTS_BASE_PATH}/${encodeURIComponent(id)}`,
73
+ request,
74
+ )
75
+ }
76
+
77
+ async listVersions(id: string): Promise<RecordDraftVersions> {
78
+ return this.client.request<RecordDraftVersions>(
79
+ 'GET',
80
+ `${RECORD_DRAFTS_BASE_PATH}/${encodeURIComponent(id)}/versions`,
81
+ )
82
+ }
83
+
58
84
  async approve(id: string, request: ApproveRecordDraftRequest = {}): Promise<RecordDraft> {
59
85
  return this.client.request<RecordDraft>(
60
86
  'POST',
package/src/data/types.ts CHANGED
@@ -192,9 +192,12 @@ export type RecordDraftChangeKind =
192
192
  | 'attribute_changed'
193
193
  | 'attribute_removed'
194
194
  | 'attribute_added'
195
+ /** The reviewer added a whole item (a row); `applied` carries its data. */
196
+ | 'item_added'
195
197
 
196
198
  /**
197
- * One entry of the reviewer's delta, diffed against the ORIGINAL proposal.
199
+ * One entry of the reviewer's delta, diffed against the proposer's LATEST
200
+ * version (the proposal, or the proposer's last revision of it).
198
201
  * `proposed` and `applied` are always present — `null` means "cleared".
199
202
  * `current` is the record's value BEFORE the write, captured for existing
200
203
  * targets (`has_current` says whether it was); it is STORED for the proposer
@@ -214,8 +217,10 @@ export interface RecordDraftChange {
214
217
 
215
218
  /**
216
219
  * A PROPOSED record write awaiting a verdict — the record sibling of a draft
217
- * message. `items` is the proposal (immutable); `applied_items` what the
218
- * resolver actually sent; `results` the latest outcome per transaction_id (a
220
+ * message. `items` is the draft as it stands now: the proposal, as revised by
221
+ * its proposer and edited by reviewers while proposed (each save is a
222
+ * {@link RecordDraftVersion}; `version` is the newest one's number);
223
+ * `applied_items` what the last approve attempt sent; `results` the latest outcome per transaction_id (a
219
224
  * re-approve after a partial failure re-sends only the items that have not
220
225
  * succeeded); `changes` the reviewer's delta. `source` is caller-supplied
221
226
  * provenance (`agent_key`, `session_id`, …); `created_by` is the acting user.
@@ -228,6 +233,7 @@ export interface RecordDraft {
228
233
  status: RecordDraftStatus
229
234
  summary: string
230
235
  items: RecordDraftItem[]
236
+ version: number
231
237
  applied_items?: RecordDraftItem[]
232
238
  results?: RecordDraftItemResult[]
233
239
  changes?: RecordDraftChange[]
@@ -239,6 +245,9 @@ export interface RecordDraft {
239
245
  created_by: { type: string; id: string }
240
246
  updated_at: string
241
247
  updated_by: { type: string; id: string }
248
+ /** Set while an approve is writing the draft's records: saves, rejects and
249
+ * other approves get 409 `record_draft_applying` until it is done. */
250
+ applying_since?: string
242
251
  }
243
252
 
244
253
  export interface CreateRecordDraftRequest {
@@ -251,11 +260,66 @@ export interface CreateRecordDraftRequest {
251
260
  source?: Record<string, unknown>
252
261
  }
253
262
 
254
- /** `items` absent = apply as proposed; present = the reviewer's edited
255
- * proposal (values changed, fields removed/added, rows dropped — never new
256
- * transaction_ids). */
263
+ /** An item as a save or an approve sends it: an existing item keeps its
264
+ * `transaction_id`; an added one leaves it out and the server assigns one. */
265
+ export type RecordDraftItemInput = Omit<RecordDraftItem, 'transaction_id'> & {
266
+ transaction_id?: string
267
+ }
268
+
269
+ /** `items` absent = apply the draft's items as they stand; present = save them
270
+ * first as the reviewer's edit, then apply them. */
257
271
  export interface ApproveRecordDraftRequest {
258
- items?: RecordDraftItem[]
272
+ items?: RecordDraftItemInput[]
273
+ /** The `updated_at` the reviewer last saw: a draft that moved on since fails
274
+ * with 409 `record_draft_conflict` instead of applying what they never saw. */
275
+ expected_updated_at?: string
276
+ }
277
+
278
+ /**
279
+ * How a version of a draft came to be: `proposed` (version 1), `revised` (the
280
+ * proposer changed its proposal — it becomes the baseline reviewer changes
281
+ * are measured against) or `edited` (a reviewer's edit; one reviewer's
282
+ * consecutive saves update one version).
283
+ */
284
+ export type RecordDraftVersionKind = 'proposed' | 'revised' | 'edited'
285
+
286
+ /** One step of a draft's history: its complete items as they stood after it. */
287
+ export interface RecordDraftVersion {
288
+ id: string
289
+ org_id: string
290
+ record_draft_id: string
291
+ version: number
292
+ kind: RecordDraftVersionKind
293
+ summary: string
294
+ items: RecordDraftItem[]
295
+ created_at: string
296
+ created_by: { type: string; id: string }
297
+ updated_at: string
298
+ updated_by: { type: string; id: string }
299
+ }
300
+
301
+ /**
302
+ * Saves a PROPOSED draft's items — the complete set: an item left out is
303
+ * dropped, an item without `transaction_id` is added (the server gives it a
304
+ * fresh one). An existing item keeps its record `id`; an item an earlier
305
+ * approve already wrote must stay exactly as applied. Nothing is written to
306
+ * the records.
307
+ */
308
+ export interface UpdateRecordDraftRequest {
309
+ items: RecordDraftItemInput[]
310
+ /** Absent keeps the summary. */
311
+ summary?: string
312
+ /** `revised` = the proposer; `edited` = a reviewer. */
313
+ kind: Exclude<RecordDraftVersionKind, 'proposed'>
314
+ /** The `updated_at` the editor last saw: a draft that moved on since fails
315
+ * with 409 `record_draft_conflict`. Omit for last write wins. */
316
+ expected_updated_at?: string
317
+ }
318
+
319
+ /** A draft's history (oldest first) and what reviewers changed so far. */
320
+ export interface RecordDraftVersions {
321
+ data: RecordDraftVersion[]
322
+ changes: RecordDraftChange[]
259
323
  }
260
324
 
261
325
  export interface RejectRecordDraftRequest {
@@ -295,7 +359,13 @@ export const RecordDraftItemResultSchema = z.object({
295
359
 
296
360
  export const RecordDraftChangeSchema = z.object({
297
361
  transaction_id: z.string(),
298
- kind: z.enum(['item_dropped', 'attribute_changed', 'attribute_removed', 'attribute_added']),
362
+ kind: z.enum([
363
+ 'item_dropped',
364
+ 'attribute_changed',
365
+ 'attribute_removed',
366
+ 'attribute_added',
367
+ 'item_added',
368
+ ]),
299
369
  attribute: z.string().optional(),
300
370
  has_current: z.boolean(),
301
371
  current: z.unknown(),
package/src/index.ts CHANGED
@@ -581,16 +581,21 @@ export type {
581
581
  RecordDraftIntent,
582
582
  RecordDraftItem,
583
583
  RecordDraftItemError,
584
+ RecordDraftItemInput,
584
585
  RecordDraftItemResult,
585
586
  RecordDraftItemResultStatus,
586
587
  RecordDraftService,
587
588
  RecordDraftStatus,
589
+ RecordDraftVersion,
590
+ RecordDraftVersionKind,
591
+ RecordDraftVersions,
588
592
  RecordDuplicate,
589
593
  RecordDuplicateService,
590
594
  RecordDuplicateSource,
591
595
  RecordDuplicateStatus,
592
596
  RecordService,
593
597
  RejectRecordDraftRequest,
598
+ UpdateRecordDraftRequest,
594
599
  } from './data/index.js'
595
600
  // Data client (data-service)
596
601
  export {