@zpi-dev/agent-sdk 0.0.0-stage → 0.1.60

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 (150) hide show
  1. package/NOTICE +1206 -0
  2. package/README.md +54 -2
  3. package/dist/chunk-4WFFCN2C.js +29607 -0
  4. package/dist/chunk-4WFFCN2C.js.map +1 -0
  5. package/dist/chunk-AR5RMMMN.js +24353 -0
  6. package/dist/chunk-AR5RMMMN.js.map +1 -0
  7. package/dist/chunk-RAZL7ZAW.js +13451 -0
  8. package/dist/chunk-RAZL7ZAW.js.map +1 -0
  9. package/dist/chunk-TUOZKHGN.js +21 -0
  10. package/dist/chunk-TUOZKHGN.js.map +1 -0
  11. package/dist/chunk-YBW5XDR7.js +48 -0
  12. package/dist/chunk-YBW5XDR7.js.map +1 -0
  13. package/dist/host.d.ts +1 -0
  14. package/dist/host.js +34 -0
  15. package/dist/host.js.map +1 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +25 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/node-WXHENNL2.js +21 -0
  20. package/dist/node-WXHENNL2.js.map +1 -0
  21. package/dist/node-XSTAMDFW.js +2225 -0
  22. package/dist/node-XSTAMDFW.js.map +1 -0
  23. package/dist/src-7WDJXP5P.js +128 -0
  24. package/dist/src-7WDJXP5P.js.map +1 -0
  25. package/dist/types/agent/src/agent-loop.d.ts +3 -0
  26. package/dist/types/agent/src/agent.d.ts +21 -0
  27. package/dist/types/agent/src/index.d.ts +3 -0
  28. package/dist/types/agent/src/streaming-tool-coordinator.d.ts +10 -0
  29. package/dist/types/agent/src/tool-execution.d.ts +9 -0
  30. package/dist/types/agent/src/types.d.ts +144 -0
  31. package/dist/types/agent-sdk/src/hooks.d.ts +12 -0
  32. package/dist/types/agent-sdk/src/host.d.ts +4 -0
  33. package/dist/types/agent-sdk/src/index.d.ts +4 -0
  34. package/dist/types/agent-sdk/src/messages.d.ts +12 -0
  35. package/dist/types/agent-sdk/src/permissions.d.ts +10 -0
  36. package/dist/types/agent-sdk/src/query-result.d.ts +7 -0
  37. package/dist/types/agent-sdk/src/query.d.ts +6 -0
  38. package/dist/types/agent-sdk/src/resources.d.ts +16 -0
  39. package/dist/types/agent-sdk/src/runtime.d.ts +7 -0
  40. package/dist/types/agent-sdk/src/sessions.d.ts +48 -0
  41. package/dist/types/agent-sdk/src/tasks.d.ts +8 -0
  42. package/dist/types/agent-sdk/src/tools.d.ts +5 -0
  43. package/dist/types/agent-sdk/src/types.d.ts +428 -0
  44. package/dist/types/ai/src/api/anthropic-messages.d.ts +70 -0
  45. package/dist/types/ai/src/api/constrained-sampling.d.ts +5 -0
  46. package/dist/types/ai/src/api/github-copilot-headers.d.ts +7 -0
  47. package/dist/types/ai/src/api/openai-completions.d.ts +10 -0
  48. package/dist/types/ai/src/api/openai-responses.d.ts +5 -0
  49. package/dist/types/ai/src/api/responses-cache.d.ts +6 -0
  50. package/dist/types/ai/src/api/responses-events.d.ts +3 -0
  51. package/dist/types/ai/src/api/responses-session.d.ts +56 -0
  52. package/dist/types/ai/src/api/simple-options.d.ts +14 -0
  53. package/dist/types/ai/src/api/transform-messages.d.ts +3 -0
  54. package/dist/types/ai/src/auth/openai-chatgpt.d.ts +32 -0
  55. package/dist/types/ai/src/index.d.ts +20 -0
  56. package/dist/types/ai/src/providers/discovery.d.ts +14 -0
  57. package/dist/types/ai/src/providers/registry.d.ts +155 -0
  58. package/dist/types/ai/src/stream.d.ts +5 -0
  59. package/dist/types/ai/src/types.d.ts +394 -0
  60. package/dist/types/ai/src/utils/abort.d.ts +2 -0
  61. package/dist/types/ai/src/utils/context-breakdown.d.ts +3 -0
  62. package/dist/types/ai/src/utils/cost.d.ts +2 -0
  63. package/dist/types/ai/src/utils/diagnostics.d.ts +16 -0
  64. package/dist/types/ai/src/utils/error-body.d.ts +24 -0
  65. package/dist/types/ai/src/utils/estimate.d.ts +16 -0
  66. package/dist/types/ai/src/utils/event-stream.d.ts +15 -0
  67. package/dist/types/ai/src/utils/guard-model-stream.d.ts +3 -0
  68. package/dist/types/ai/src/utils/headers.d.ts +1 -0
  69. package/dist/types/ai/src/utils/json-parse.d.ts +7 -0
  70. package/dist/types/ai/src/utils/media-policy.d.ts +68 -0
  71. package/dist/types/ai/src/utils/model-performance.d.ts +23 -0
  72. package/dist/types/ai/src/utils/model-retry.d.ts +3 -0
  73. package/dist/types/ai/src/utils/option-map/compiler.d.ts +2 -0
  74. package/dist/types/ai/src/utils/option-map/evaluator.d.ts +3 -0
  75. package/dist/types/ai/src/utils/option-map/parser.d.ts +40 -0
  76. package/dist/types/ai/src/utils/option-map/tokenizer.d.ts +8 -0
  77. package/dist/types/ai/src/utils/option-map/types.d.ts +15 -0
  78. package/dist/types/ai/src/utils/overflow.d.ts +68 -0
  79. package/dist/types/ai/src/utils/provider-cache.d.ts +11 -0
  80. package/dist/types/ai/src/utils/provider-env.d.ts +2 -0
  81. package/dist/types/ai/src/utils/provider-retry.d.ts +17 -0
  82. package/dist/types/ai/src/utils/reasoning.d.ts +14 -0
  83. package/dist/types/ai/src/utils/redact-error.d.ts +2 -0
  84. package/dist/types/ai/src/utils/retry.d.ts +62 -0
  85. package/dist/types/ai/src/utils/sanitize-unicode.d.ts +21 -0
  86. package/dist/types/ai/src/utils/stream-idle-timeout.d.ts +36 -0
  87. package/dist/types/ai/src/utils/text.d.ts +9 -0
  88. package/dist/types/ai/src/utils/transcript.d.ts +41 -0
  89. package/dist/types/coding-agent/src/core/agent-session.d.ts +174 -0
  90. package/dist/types/coding-agent/src/core/commands.d.ts +19 -0
  91. package/dist/types/coding-agent/src/core/compaction-utils.d.ts +37 -0
  92. package/dist/types/coding-agent/src/core/compaction.d.ts +139 -0
  93. package/dist/types/coding-agent/src/core/file-rewind.d.ts +24 -0
  94. package/dist/types/coding-agent/src/core/fs.d.ts +1 -0
  95. package/dist/types/coding-agent/src/core/http-idle-timeout.d.ts +2 -0
  96. package/dist/types/coding-agent/src/core/image-limits.d.ts +19 -0
  97. package/dist/types/coding-agent/src/core/images.d.ts +18 -0
  98. package/dist/types/coding-agent/src/core/input.d.ts +3 -0
  99. package/dist/types/coding-agent/src/core/markdown-code.d.ts +7 -0
  100. package/dist/types/coding-agent/src/core/markdown.d.ts +13 -0
  101. package/dist/types/coding-agent/src/core/mentions.d.ts +12 -0
  102. package/dist/types/coding-agent/src/core/microcompact.d.ts +40 -0
  103. package/dist/types/coding-agent/src/core/model-performance.d.ts +57 -0
  104. package/dist/types/coding-agent/src/core/model-runtime.d.ts +51 -0
  105. package/dist/types/coding-agent/src/core/read-file-bounded.d.ts +2 -0
  106. package/dist/types/coding-agent/src/core/record-validation.d.ts +6 -0
  107. package/dist/types/coding-agent/src/core/resources.d.ts +51 -0
  108. package/dist/types/coding-agent/src/core/sdk.d.ts +50 -0
  109. package/dist/types/coding-agent/src/core/session-manager.d.ts +137 -0
  110. package/dist/types/coding-agent/src/core/session-state.d.ts +14 -0
  111. package/dist/types/coding-agent/src/core/settings-manager.d.ts +41 -0
  112. package/dist/types/coding-agent/src/core/streaming-tool-journal.d.ts +17 -0
  113. package/dist/types/coding-agent/src/core/system-prompt.d.ts +25 -0
  114. package/dist/types/coding-agent/src/core/tools/file-change.d.ts +21 -0
  115. package/dist/types/coding-agent/src/core/tools/index.d.ts +20 -0
  116. package/dist/types/coding-agent/src/core/tools/pi/bash.d.ts +185 -0
  117. package/dist/types/coding-agent/src/core/tools/pi/edit-diff.d.ts +84 -0
  118. package/dist/types/coding-agent/src/core/tools/pi/edit.d.ts +69 -0
  119. package/dist/types/coding-agent/src/core/tools/pi/file-mutation-queue.d.ts +5 -0
  120. package/dist/types/coding-agent/src/core/tools/pi/file-read-state.d.ts +12 -0
  121. package/dist/types/coding-agent/src/core/tools/pi/output-accumulator.d.ts +68 -0
  122. package/dist/types/coding-agent/src/core/tools/pi/path-utils.d.ts +7 -0
  123. package/dist/types/coding-agent/src/core/tools/pi/read.d.ts +63 -0
  124. package/dist/types/coding-agent/src/core/tools/pi/text-range-reader.d.ts +22 -0
  125. package/dist/types/coding-agent/src/core/tools/pi/tool-definition-wrapper.d.ts +4 -0
  126. package/dist/types/coding-agent/src/core/tools/pi/truncate.d.ts +60 -0
  127. package/dist/types/coding-agent/src/core/tools/pi/utils/bmp-source.d.ts +2 -0
  128. package/dist/types/coding-agent/src/core/tools/pi/utils/child-process.d.ts +13 -0
  129. package/dist/types/coding-agent/src/core/tools/pi/utils/image-budget.d.ts +16 -0
  130. package/dist/types/coding-agent/src/core/tools/pi/utils/image-process.d.ts +18 -0
  131. package/dist/types/coding-agent/src/core/tools/pi/utils/image-resize-core.d.ts +26 -0
  132. package/dist/types/coding-agent/src/core/tools/pi/utils/image-resize.d.ts +3 -0
  133. package/dist/types/coding-agent/src/core/tools/pi/utils/image-source.d.ts +11 -0
  134. package/dist/types/coding-agent/src/core/tools/pi/utils/mime.d.ts +3 -0
  135. package/dist/types/coding-agent/src/core/tools/pi/utils/paths.d.ts +16 -0
  136. package/dist/types/coding-agent/src/core/tools/pi/utils/read-file.d.ts +2 -0
  137. package/dist/types/coding-agent/src/core/tools/pi/utils/shell.d.ts +18 -0
  138. package/dist/types/coding-agent/src/core/tools/pi/utils/text.d.ts +5 -0
  139. package/dist/types/coding-agent/src/core/tools/pi/write.d.ts +44 -0
  140. package/dist/types/coding-agent/src/core/transcript-store.d.ts +71 -0
  141. package/dist/types/coding-agent/src/core/types.d.ts +60 -0
  142. package/dist/types/coding-agent/src/index.d.ts +42 -0
  143. package/dist/types/coding-agent/src/plugins/assembly.d.ts +37 -0
  144. package/dist/types/coding-agent/src/plugins/hooks.d.ts +82 -0
  145. package/dist/types/coding-agent/src/plugins/resources.d.ts +4 -0
  146. package/dist/types/coding-agent/src/plugins/session-hooks.d.ts +26 -0
  147. package/dist/types/coding-agent/src/plugins/types.d.ts +40 -0
  148. package/dist/types/plugin-compat/src/command-hooks.d.ts +184 -0
  149. package/dist/types/plugin-compat/src/index.d.ts +11 -0
  150. package/package.json +53 -4
package/README.md CHANGED
@@ -1,3 +1,55 @@
1
- # Temporary Holding Version
1
+ # @zpi-dev/agent-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript SDK for the ZPI agent runtime. Node.js 24 is required. Its supported API follows the [Claude Agent SDK TypeScript reference](https://code.claude.com/docs/zh-CN/agent-sdk/typescript); it runs ZPI directly and does not require Claude Code or an Anthropic subscription.
4
+
5
+ ```ts
6
+ import { query } from "@zpi-dev/agent-sdk";
7
+
8
+ for await (const message of query({
9
+ prompt: "Explain this project",
10
+ options: {
11
+ model: "deepseek",
12
+ tools: ["Read", "Glob", "Grep"],
13
+ allowedTools: ["Read", "Glob", "Grep"],
14
+ maxTurns: 8,
15
+ },
16
+ })) {
17
+ if (message.type === "result" && message.subtype === "success") {
18
+ console.log(message.result);
19
+ }
20
+ }
21
+ ```
22
+
23
+ Set `DEEPSEEK_API_KEY` for the example. `model` accepts a registered provider, model ID, or `provider/model`. Anthropic requires `ANTHROPIC_API_KEY` and an explicit model ID (`options.model` or `ANTHROPIC_MODEL`). Additional providers, pricing, fetch implementations and existing host services can be supplied under the `zpi` namespace. Credentials are never supplied to the renderer by the SDK.
24
+
25
+ ## Supported contract
26
+
27
+ | Area | Supported surface |
28
+ | --- | --- |
29
+ | Query | `query({ prompt, options })`, string or `AsyncIterable<SDKUserMessage>` input; `system`, `user`, `assistant`, `stream_event`, `result` messages |
30
+ | Conversation | In-memory or persisted sessions; `resume`, `continue`, `forkSession`, `resumeSessionAt`, session listing/history/title/tag APIs |
31
+ | Tools | `tools`, `allowedTools`, `disallowedTools`, `canUseTool`; canonical `Read`, `Write`, `Edit`, `Bash`, `Glob`, `Grep`, `Skill`, `Agent`, `TaskOutput`, `TaskStop` |
32
+ | Controls | `interrupt`, `close`, `setModel`, `setMaxThinkingTokens`, supported command/model/agent discovery, initialization result |
33
+ | Limits | `maxTurns`, `maxBudgetUsd`, `thinking`, `effort`, `maxThinkingTokens`, abort signals |
34
+ | Output | Partial streaming, usage/cost/model totals, JSON schema validation with up to three attempts |
35
+ | Hooks | TypeScript callbacks for session start/end, prompt submit, pre/post tool, tool failure, stop, subagent start/stop, pre/post compaction |
36
+ | Resources | Explicit local plugins: command hooks, prompt commands, skills, Agent markdown definitions. `settingSources` explicitly opts into user/project/local instruction and skill discovery |
37
+ | Files | Opt-in `enableFileCheckpointing` and `rewindFiles`, with external edit checks |
38
+
39
+ `tools` chooses which tools the model sees. `allowedTools` pre-approves matching calls; it does not hide other tools. `disallowedTools` wins over allow rules. A bare deny removes a tool from the model's context; an argument-qualified deny checks calls. Other calls go to `canUseTool`, or execute directly when no callback is configured. This embedded runtime has no interactive permission dialog and is not a sandbox. Configure `tools: []` for text/image chat without local capabilities. `Grep` requires `rg` on PATH. Tool results use canonical parameter names such as `file_path` and `tool_use_id`.
40
+
41
+ `systemPrompt` replaces the default prompt. The `claude_code` preset selects ZPI's coding assistant prompt, not Anthropic's proprietary prompt. Default `settingSources` is empty. Only explicitly supplied local plugins execute command hooks; adding a plugin authorizes its code in the host process environment. Agent model aliases must resolve to registered models. `forwardSubagentText` defaults to false. Background tasks belong to their parent Query and are cancelled when it closes.
42
+
43
+ Pricing is provider configuration. Environment-based presets use zero prices until accurate pricing is supplied through `zpi.providers`; `maxBudgetUsd` requires those prices to enforce a useful monetary budget. Token usage is reported independently of pricing. `rewindFiles` covers SDK Write/Edit checkpoints, not arbitrary shell side effects or external edits. Forks start a new checkpoint history.
44
+
45
+ ## Deliberately omitted
46
+
47
+ Only TypeScript is supported. `permissionMode`, sandbox/permission UI, MCP, LSP, plugin UI, marketplaces, remote sessions, account authentication flows, managed enterprise settings, prewarming/CLI transport and other advanced Claude Code services are not implemented. Unsupported top-level options fail explicitly rather than acting as no-ops. Message shapes align for the supported subset; this is not a complete drop-in replacement for every Claude Code capability.
48
+
49
+ ## Native desktop host
50
+
51
+ `@zpi-dev/agent-sdk/host` exposes the native session creation port for hosts needing indexed storage, background services and plugin assembly. ZPI desktop creates its sessions there, then drives them through `query` with `zpi.session`, `zpi.sessionManager`, `zpi.modelRuntime` and optional prepared `zpi.input`. The host retains ownership and subscriptions. Configure tool/loop policies at session creation for this mode. Ordinary applications should use `query` alone.
52
+
53
+ ## Build and distribution
54
+
55
+ From the ZPI repository, run `npm run build:sdk`, then `npm pack --workspace @zpi-dev/agent-sdk`. Published output bundles the private ZPI runtime and ships rewritten standalone declaration files; consumers do not need the desktop package or private workspace modules. Local builds are not automatically published to npm.