@sema-agent/sdk 1.0.0 → 2.0.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.
Files changed (56) hide show
  1. package/README.md +5 -0
  2. package/dist/errors.d.ts +84 -9
  3. package/dist/errors.d.ts.map +1 -1
  4. package/dist/errors.js +158 -16
  5. package/dist/errors.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +6 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/normalize.d.ts +6 -2
  11. package/dist/normalize.d.ts.map +1 -1
  12. package/dist/normalize.js +10 -5
  13. package/dist/normalize.js.map +1 -1
  14. package/dist/resources/approvals.js +2 -2
  15. package/dist/resources/approvals.js.map +1 -1
  16. package/dist/resources/attachments.d.ts.map +1 -1
  17. package/dist/resources/attachments.js +3 -4
  18. package/dist/resources/attachments.js.map +1 -1
  19. package/dist/resources/fleet.d.ts.map +1 -1
  20. package/dist/resources/fleet.js +1 -2
  21. package/dist/resources/fleet.js.map +1 -1
  22. package/dist/resources/images.d.ts +3 -1
  23. package/dist/resources/images.d.ts.map +1 -1
  24. package/dist/resources/images.js +6 -3
  25. package/dist/resources/images.js.map +1 -1
  26. package/dist/resources/ops.d.ts.map +1 -1
  27. package/dist/resources/ops.js +3 -1
  28. package/dist/resources/ops.js.map +1 -1
  29. package/dist/resources/runs.d.ts.map +1 -1
  30. package/dist/resources/runs.js +1 -2
  31. package/dist/resources/runs.js.map +1 -1
  32. package/dist/resources/session-sync.js +4 -13
  33. package/dist/resources/session-sync.js.map +1 -1
  34. package/dist/resources/sessions.d.ts.map +1 -1
  35. package/dist/resources/sessions.js +5 -1
  36. package/dist/resources/sessions.js.map +1 -1
  37. package/dist/resources/tasks.d.ts.map +1 -1
  38. package/dist/resources/tasks.js +1 -2
  39. package/dist/resources/tasks.js.map +1 -1
  40. package/dist/resources/workflows.d.ts.map +1 -1
  41. package/dist/resources/workflows.js +1 -2
  42. package/dist/resources/workflows.js.map +1 -1
  43. package/dist/resources/workspace.d.ts.map +1 -1
  44. package/dist/resources/workspace.js +8 -12
  45. package/dist/resources/workspace.js.map +1 -1
  46. package/dist/sse.d.ts.map +1 -1
  47. package/dist/sse.js +6 -4
  48. package/dist/sse.js.map +1 -1
  49. package/dist/transport.d.ts +25 -0
  50. package/dist/transport.d.ts.map +1 -1
  51. package/dist/transport.js +37 -2
  52. package/dist/transport.js.map +1 -1
  53. package/dist/types.d.ts +49 -31
  54. package/dist/types.d.ts.map +1 -1
  55. package/openapi.yaml +67 -25
  56. package/package.json +1 -1
package/openapi.yaml CHANGED
@@ -515,7 +515,10 @@ paths:
515
515
  '404': { $ref: '#/components/responses/NotFound' }
516
516
  '400': { $ref: '#/components/responses/BadRequest' }
517
517
  '409':
518
- description: 'errorCode "steering.not_running" — the run/subagent is settled or unknown (also: ambiguous agentName).'
518
+ description: >
519
+ errorCode "steering.not_running" — the run/subagent is settled or unknown; or
520
+ "steering.ambiguous_target" when more than one live subagent in this run matches the given
521
+ agentName (address it by parentToolCallId instead — retrying the same target never resolves).
519
522
  content:
520
523
  application/json:
521
524
  schema: { $ref: '#/components/schemas/ErrorResponse' }
@@ -701,7 +704,14 @@ paths:
701
704
  '413':
702
705
  description: 'errorCode "steer.content_too_large" — the revival prompt is over the cap (same gate as subagent steer).'
703
706
  '409':
704
- description: 'core''s typed rejections verbatim as `errorCode`: resume.still_running / resume.retain_off / resume.evicted / resume.cap / resume.session_not_found (design/122 D2).'
707
+ description: >
708
+ core's typed rejections verbatim as `errorCode`: resume.retain_off / resume.evicted / resume.cap /
709
+ resume.session_not_found (design/122 D2), plus "steering.ambiguous_target" (>1 live subagent matches
710
+ the target) and "steering.still_running" — the child (or a prior resume) is STILL IN FLIGHT, so
711
+ revive is not yet legal: steer it instead, or wait for it to settle.
712
+ 🔴 CORRECTION (2026-07-29, read off `src/http/routes/runs.ts` in server 3.x): the in-flight code is
713
+ `steering.still_running`, NOT `resume.still_running` — this line named a code the server never sends.
714
+ The `resume.*` family is the retain/evict/cap/session set only.
705
715
  content:
706
716
  application/json:
707
717
  schema: { $ref: '#/components/schemas/ErrorResponse' }
@@ -5020,19 +5030,33 @@ components:
5020
5030
  "MIRRORS core CheckpointSummary,顶层 gateKind/severity,NEVER a riskDescriptor object"——
5021
5031
  与真实实现完全相反。真实的 `PendingCheckpoint`(service 自定义类型,不是 core 的
5022
5032
  `CheckpointSummary`)**没有 token 字段**(store 层注释:"deliberately NO token")、**没有
5023
- 顶层 gateKind**、**没有顶层 severity**——risk 信息只在 `riskDescriptor` 对象里(§1 的
5033
+ 顶层 severity**——risk 信息只在 `riskDescriptor` 对象里(§1 的
5024
5034
  `CheckpointSummary`/`/v1/assistant/inbox` 才是那个有顶层 severity 标量、无 riskDescriptor
5025
5035
  的姊妹形状,是完全不同的端点,不要混)。按真实实现改写如下,与
5026
5036
  `packages/sdk/src/types.ts` 的 `PendingCheckpoint` interface(已验证与 server 实现一致)
5027
5037
  对齐。
5038
+ 🔴 二次纠正(2026-07-29,server 3.0.0 [1995]③):上一版里"**没有顶层 gateKind**"这句话已经
5039
+ 过期 —— 3.0.0 additive 加了顶层 `gateKind`,两个 checkpoint store(local 文件店 / SQL 店)的
5040
+ 富行投影都发它。"顶层 severity 仍然没有"那半句依旧成立,两件事不要一起读。
5028
5041
  required: [sessionId, scope, createdAt]
5029
5042
  additionalProperties: true
5030
5043
  properties:
5031
5044
  sessionId: { type: string, description: 'The decide handle: POST /v1/approvals/:sessionId/decide.' }
5032
5045
  scope: { type: string, description: 'Principal; "_" = submitted without one.' }
5033
5046
  taskId: { type: ['string', 'null'], description: 'Suspended run holding the session claim (service-pinned) — join key to trace tool-call blocks + context link.' }
5034
- toolName: { type: ['string', 'null'], description: Tool awaiting approval (AskUserQuestion = the question gate; riskDescriptor 无 gateKind 时的类别推断来源). }
5047
+ toolName: { type: ['string', 'null'], description: 'Tool awaiting approval (AskUserQuestion = the question gate). NULL on every non-tool gate — read `gateKind` for the category, do NOT infer it from this.' }
5035
5048
  toolCallId: { type: ['string', 'null'] }
5049
+ gateKind:
5050
+ type: string
5051
+ description: >
5052
+ Which gate this row is parked on (server >=3.0.0, ADDITIVE — both checkpoint stores project it).
5053
+ Lets a durable-recovery consumer route plan / tool / resource off the SAME queue: a plan gate takes
5054
+ the plan_review decision, a tool gate takes /decide, a resource gate takes resume (going through the
5055
+ wrong door yields `gate_not_resumable` / `gate_not_plan_review`).
5056
+ 🔴 OPEN SET — deliberately NOT an enum: observed values include `human`, `irreversible_ask`,
5057
+ `plan_review`, `needs_review`, `resource_limit`, and core keeps adding. Pinning an enum would make a
5058
+ new gate kind "not exist" for generated clients.
5059
+ ABSENT on a pre-`gate_kind` legacy row (SQL column NULL) — degrade honestly, never assume `human`.
5036
5060
  input:
5037
5061
  description: >
5038
5062
  The pending tool call's args (post-hook), REDACTED + size-bounded — for a tool gate the write
@@ -5099,27 +5123,33 @@ components:
5099
5123
 
5100
5124
  InboxRow:
5101
5125
  description: >
5102
- ASSISTANT-WIRE-CONTRACT §2 — an inbox row = a CheckpointSummary + an `objective` (enriched from the
5103
- task ctx; `null` if unavailable).
5104
- allOf:
5105
- - $ref: '#/components/schemas/CheckpointSummary'
5106
- - type: object
5107
- properties:
5108
- objective: { type: ['string', 'null'], description: 'task objective, null if unavailable.' }
5109
- toolName:
5110
- type: ['string', 'null']
5111
- description: 'The gated tool, when the pause came from a tool call (null for non-tool gates).'
5112
- toolCallId: { type: string, description: 'The gated tool-call id.' }
5113
- boundCallId: { type: string, description: 'D-1 decision binding — echo it back on /decide.' }
5114
- boundInputHash:
5115
- type: string
5116
- description: >
5117
- D-1 decision binding — hash of the bound tool input. Echo on /decide so an approval cannot land on
5118
- a DIFFERENT call that was swapped in after the operator looked.
5119
- input:
5120
- description: >
5121
- REDACTED tool input for display. Untyped by design (per-tool shape) — and note the raw `toolInput`
5122
- is deliberately NOT on this row: the handler always strips it (along with `token`) before returning.
5126
+ ASSISTANT-WIRE-CONTRACT §2 — an inbox row (server >=3.4.0 EXPLICIT-projection form): the §1 mirror keys
5127
+ of a CheckpointSummary (token stripped; no rich per-tool fields) + two nullable enrichments.
5128
+ NARROWING RECORD (2026-07-30, board [2027]->[2029]): rows used to also carry
5129
+ toolName/toolCallId/preview/principal/sourceTaskId/contentKind (handler spread the whole projection) and
5130
+ this spec over-declared decide bindings that never appeared on inbox wire at all. Four client repos were
5131
+ structurally zero-consumers, so server 3.4.0 narrowed the wire and this schema follows. For the tool face
5132
+ and decide bindings use /v1/approvals (PendingCheckpoint); for task attribution use /v1/assistant/tasks.
5133
+ type: object
5134
+ required: [sessionId, scope, objective, input]
5135
+ additionalProperties: false
5136
+ properties:
5137
+ sessionId: { type: string, description: 'The suspended task/session id.' }
5138
+ scope: { type: string, description: 'Multi-tenant owner scope.' }
5139
+ createdAt: { type: number, description: 'Ask creation time (epoch ms).' }
5140
+ gateKind:
5141
+ type: string
5142
+ description: 'Same open set as CheckpointSummary.gateKind.'
5143
+ enum: [human, irreversible_ask, resource_limit, needs_review, plan_review, task_done]
5144
+ x-open-enum: true
5145
+ severity: { type: integer, minimum: 1, maximum: 5, description: 'Sort key; only human/irreversible_ask carry it.' }
5146
+ spentMicroUsd: { type: number, description: 'Accumulated spend on the suspend chain (micro-USD).' }
5147
+ deadline: { type: number, description: 'Awaiting-human SLA deadline (epoch ms).' }
5148
+ objective: { type: ['string', 'null'], description: 'task objective, null if unavailable.' }
5149
+ input:
5150
+ description: >
5151
+ REDACTED tool-args preview for display (null on gates without one, e.g. plan_review). Untyped by
5152
+ design (per-tool shape). The raw `toolInput` is deliberately NOT on this row.
5123
5153
 
5124
5154
  InboxList:
5125
5155
  type: object
@@ -5609,6 +5639,18 @@ components:
5609
5639
  `quota_exhausted` (429 — the E4 fleet quota-LEASE budget, distinct from the cost quota).
5610
5640
  NOTE: budget (`budget.precall`/`budget.exceeded`) and `cancelled` are RESULT-level codes on
5611
5641
  TaskResult/RunRecord, NOT HTTP errors (pinned wire contract).
5642
+ 🔴 STABLE PREFIX FAMILIES (wire-contract Appendix A, criterion 3) — nine prefixes are a stable
5643
+ COARSE branch surface, so falling back on the prefix (unknown code → look at its prefix → only then
5644
+ at the status) is always safe: `auth.` `request.` `not_found.` `conflict.` `limit.` `capability.`
5645
+ `feature.` `internal.` `state.`. The SDK maps each family to a typed class, so a code this SDK has
5646
+ never seen still degrades INFORMATIVELY (e.g. a future `capability.xyz_required` already lands on
5647
+ CapabilityUnavailableError). Family examples not named elsewhere in this document:
5648
+ `request.payload_too_large` (413 — a field or the whole body is over the server cap; shorten and
5649
+ resend, retrying verbatim never succeeds), `state.model_roster_pending` (503 — retry shortly),
5650
+ `internal.cancel_not_terminalized` (500 — retry the cancel).
5651
+ The two 501 families are deliberately NOT interchangeable: `capability.*` means this deployment did
5652
+ not wire that surface (change the deployment / hide the entry point), `feature.*` means the surface
5653
+ exists but its switch is off (ask an admin to turn it on).
5612
5654
  error: { type: string }
5613
5655
  errorMessage: { type: string }
5614
5656
  activeTaskId:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sema-agent/sdk",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Typed, zero-runtime-dependency SDK for the Sema agent fleet usage plane. The shared substrate for all doors (CC/Codex MCP façade + web). Server-side only — tokens never enter the browser.",
5
5
  "type": "module",
6
6
  "license": "BUSL-1.1",