@kooka/agent-sdk 0.1.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 (91) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +293 -0
  3. package/dist/abort.d.ts +2 -0
  4. package/dist/abort.d.ts.map +1 -0
  5. package/dist/abort.js +19 -0
  6. package/dist/abort.js.map +1 -0
  7. package/dist/agent/agent.d.ts +67 -0
  8. package/dist/agent/agent.d.ts.map +1 -0
  9. package/dist/agent/agent.js +1061 -0
  10. package/dist/agent/agent.js.map +1 -0
  11. package/dist/agent/constants.d.ts +6 -0
  12. package/dist/agent/constants.d.ts.map +1 -0
  13. package/dist/agent/constants.js +40 -0
  14. package/dist/agent/constants.js.map +1 -0
  15. package/dist/agent/prompts.d.ts +4 -0
  16. package/dist/agent/prompts.d.ts.map +1 -0
  17. package/dist/agent/prompts.js +31 -0
  18. package/dist/agent/prompts.js.map +1 -0
  19. package/dist/agent/reminders.d.ts +3 -0
  20. package/dist/agent/reminders.d.ts.map +1 -0
  21. package/dist/agent/reminders.js +31 -0
  22. package/dist/agent/reminders.js.map +1 -0
  23. package/dist/agent/retry.d.ts +12 -0
  24. package/dist/agent/retry.d.ts.map +1 -0
  25. package/dist/agent/retry.js +200 -0
  26. package/dist/agent/retry.js.map +1 -0
  27. package/dist/index.d.ts +49 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +50 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/llm/openaiCompatible.d.ts +23 -0
  32. package/dist/llm/openaiCompatible.d.ts.map +1 -0
  33. package/dist/llm/openaiCompatible.js +91 -0
  34. package/dist/llm/openaiCompatible.js.map +1 -0
  35. package/dist/plugins/pluginManager.d.ts +22 -0
  36. package/dist/plugins/pluginManager.d.ts.map +1 -0
  37. package/dist/plugins/pluginManager.js +171 -0
  38. package/dist/plugins/pluginManager.js.map +1 -0
  39. package/dist/plugins/types.d.ts +97 -0
  40. package/dist/plugins/types.d.ts.map +1 -0
  41. package/dist/plugins/types.js +2 -0
  42. package/dist/plugins/types.js.map +1 -0
  43. package/dist/skills.d.ts +28 -0
  44. package/dist/skills.d.ts.map +1 -0
  45. package/dist/skills.js +188 -0
  46. package/dist/skills.js.map +1 -0
  47. package/dist/tools/builtin/bash.d.ts +4 -0
  48. package/dist/tools/builtin/bash.d.ts.map +1 -0
  49. package/dist/tools/builtin/bash.js +364 -0
  50. package/dist/tools/builtin/bash.js.map +1 -0
  51. package/dist/tools/builtin/glob.d.ts +4 -0
  52. package/dist/tools/builtin/glob.d.ts.map +1 -0
  53. package/dist/tools/builtin/glob.js +87 -0
  54. package/dist/tools/builtin/glob.js.map +1 -0
  55. package/dist/tools/builtin/grep.d.ts +4 -0
  56. package/dist/tools/builtin/grep.d.ts.map +1 -0
  57. package/dist/tools/builtin/grep.js +190 -0
  58. package/dist/tools/builtin/grep.js.map +1 -0
  59. package/dist/tools/builtin/index.d.ts +15 -0
  60. package/dist/tools/builtin/index.d.ts.map +1 -0
  61. package/dist/tools/builtin/index.js +37 -0
  62. package/dist/tools/builtin/index.js.map +1 -0
  63. package/dist/tools/builtin/list.d.ts +4 -0
  64. package/dist/tools/builtin/list.d.ts.map +1 -0
  65. package/dist/tools/builtin/list.js +162 -0
  66. package/dist/tools/builtin/list.js.map +1 -0
  67. package/dist/tools/builtin/read.d.ts +4 -0
  68. package/dist/tools/builtin/read.d.ts.map +1 -0
  69. package/dist/tools/builtin/read.js +92 -0
  70. package/dist/tools/builtin/read.js.map +1 -0
  71. package/dist/tools/builtin/skill.d.ts +9 -0
  72. package/dist/tools/builtin/skill.d.ts.map +1 -0
  73. package/dist/tools/builtin/skill.js +126 -0
  74. package/dist/tools/builtin/skill.js.map +1 -0
  75. package/dist/tools/builtin/workspace.d.ts +13 -0
  76. package/dist/tools/builtin/workspace.d.ts.map +1 -0
  77. package/dist/tools/builtin/workspace.js +74 -0
  78. package/dist/tools/builtin/workspace.js.map +1 -0
  79. package/dist/tools/builtin/write.d.ts +4 -0
  80. package/dist/tools/builtin/write.d.ts.map +1 -0
  81. package/dist/tools/builtin/write.js +73 -0
  82. package/dist/tools/builtin/write.js.map +1 -0
  83. package/dist/tools/registry.d.ts +21 -0
  84. package/dist/tools/registry.d.ts.map +1 -0
  85. package/dist/tools/registry.js +150 -0
  86. package/dist/tools/registry.js.map +1 -0
  87. package/dist/types.d.ts +251 -0
  88. package/dist/types.d.ts.map +1 -0
  89. package/dist/types.js +2 -0
  90. package/dist/types.js.map +1 -0
  91. package/package.json +46 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 LingYun contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,293 @@
1
+ # LingYun Agent SDK (Draft)
2
+
3
+ Goal: provide a **headless**, **Node-first** Agent SDK that reuses LingYun’s core interaction model (OpenCode-aligned “assistant message + parts” history, sequential tool loop, approvals) but can be embedded in non‑VS Code systems.
4
+
5
+ This SDK is intentionally **not** optimized for max parallelism. It follows LingYun’s current step/iteration loop: stream → (optional) tool calls → tool execution → continue until a final assistant response.
6
+
7
+ ## Requirements
8
+
9
+ - Node.js **18+** (Node 20+ recommended)
10
+ - ESM (`"type":"module"` or `.mjs`) is recommended. CommonJS is supported via dynamic import.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm i @kooka/agent-sdk
16
+ ```
17
+
18
+ This package depends on `@kooka/core` (it will be installed automatically).
19
+
20
+ ## Build (from source)
21
+
22
+ ```bash
23
+ pnpm install
24
+ pnpm --filter @kooka/agent-sdk build
25
+ ```
26
+
27
+ ### As a dependency (local path)
28
+
29
+ In another project’s `package.json`:
30
+
31
+ ```json
32
+ {
33
+ "dependencies": {
34
+ "@kooka/agent-sdk": "file:/absolute/path/to/lingyun/packages/agent-sdk"
35
+ }
36
+ }
37
+ ```
38
+
39
+ Then build the SDK once (it ships `dist/` via `files`, so consumers need the built output):
40
+
41
+ ```bash
42
+ pnpm --dir /absolute/path/to/lingyun/packages/agent-sdk run build
43
+ ```
44
+
45
+ ## Publishing
46
+
47
+ `@kooka/core` and `@kooka/agent-sdk` are published together and must share the same version.
48
+
49
+ From the repo root:
50
+
51
+ ```bash
52
+ pnpm --filter @kooka/core publish --no-git-checks
53
+ pnpm --filter @kooka/agent-sdk publish --no-git-checks
54
+ ```
55
+
56
+ ## Quickstart
57
+
58
+ Minimal “stream tokens + get final text” example:
59
+
60
+ ```ts
61
+ import { createLingyunAgent, LingyunSession } from '@kooka/agent-sdk';
62
+
63
+ const { agent, llm } = createLingyunAgent({
64
+ llm: {
65
+ provider: 'openaiCompatible',
66
+ baseURL: process.env.LINGYUN_BASE_URL ?? 'http://localhost:8080/v1',
67
+ apiKey: process.env.LINGYUN_API_KEY,
68
+ model: process.env.LINGYUN_MODEL ?? 'your-model-id',
69
+ },
70
+ agent: {
71
+ mode: 'build',
72
+ maxRetries: 1,
73
+ maxOutputTokens: 2048,
74
+ autoApprove: false,
75
+ },
76
+ workspaceRoot: process.cwd(),
77
+ allowExternalPaths: false,
78
+ });
79
+
80
+ try {
81
+ const session = new LingyunSession({ sessionId: 'demo' });
82
+
83
+ const run = agent.run({
84
+ session,
85
+ input: 'Reply with exactly one word: ok',
86
+ callbacks: {
87
+ onRequestApproval: async () => false,
88
+ },
89
+ });
90
+
91
+ for await (const ev of run.events) {
92
+ if (ev.type === 'assistant_token') process.stdout.write(ev.token);
93
+ }
94
+
95
+ const result = await run.done;
96
+ console.log('\\n\\nFinal:', result.text);
97
+ } finally {
98
+ llm.dispose?.();
99
+ }
100
+ ```
101
+
102
+ CommonJS:
103
+
104
+ ```js
105
+ const { createLingyunAgent, LingyunSession } = await import('@kooka/agent-sdk')
106
+ ```
107
+
108
+ ## Sessions (Multi-Turn)
109
+
110
+ `LingyunSession` holds the OpenCode-aligned “assistant message + parts” history. Reuse the same `session` to continue a conversation:
111
+
112
+ ```ts
113
+ const session = new LingyunSession({ sessionId: 'my-session' });
114
+ await agent.run({ session, input: 'Summarize README' }).done;
115
+ await agent.run({ session, input: 'Now list TODOs' }).done;
116
+ ```
117
+
118
+ Persistence is the host’s responsibility. A simple JSON snapshot looks like:
119
+
120
+ ```ts
121
+ const snapshot = {
122
+ sessionId: session.sessionId,
123
+ pendingPlan: session.pendingPlan,
124
+ history: session.getHistory(),
125
+ };
126
+ ```
127
+
128
+ ## Streaming Events
129
+
130
+ `agent.run(...)` returns:
131
+
132
+ - `events`: `AsyncIterable<LingyunEvent>`
133
+ - `done`: `Promise<{ text, session }>`
134
+
135
+ Useful event types:
136
+
137
+ - `assistant_token`: user-facing assistant text (with `<think>` and tool-call markers removed)
138
+ - `thought_token`: model “thinking” tokens (only if the provider emits them)
139
+ - `tool_call` / `tool_result` / `tool_blocked`: tool lifecycle
140
+ - `compaction_start` / `compaction_end`: context overflow mitigation
141
+
142
+ ## Tools
143
+
144
+ ### Built-in tools
145
+
146
+ By default, `createLingyunAgent(...)` registers these built-ins:
147
+
148
+ - `read`, `write`, `list`, `glob`, `grep`, `bash`, `skill`
149
+
150
+ You can disable built-ins:
151
+
152
+ ```ts
153
+ createLingyunAgent({ llm: { /*...*/ }, tools: { builtin: false } })
154
+ ```
155
+
156
+ ### Approvals
157
+
158
+ Tools can require approval via `ToolDefinition.metadata.requiresApproval`.
159
+
160
+ - In Build mode, you can provide `callbacks.onRequestApproval` or set `agent.autoApprove=true`.
161
+ - In Plan mode, auto-approve is disabled and edit tools are blocked by default.
162
+
163
+ ### Custom tools
164
+
165
+ Register a function-backed tool:
166
+
167
+ ```ts
168
+ import { createLingyunAgent } from '@kooka/agent-sdk';
169
+
170
+ const { registry } = createLingyunAgent({
171
+ llm: { provider: 'openaiCompatible', baseURL: 'http://localhost:8080/v1', model: 'your-model-id' },
172
+ workspaceRoot: process.cwd(),
173
+ });
174
+
175
+ registry.registerTool(
176
+ {
177
+ id: 'demo.echo',
178
+ name: 'Echo',
179
+ description: 'Echo back the message argument',
180
+ parameters: {
181
+ type: 'object',
182
+ properties: { message: { type: 'string' } },
183
+ required: ['message'],
184
+ },
185
+ execution: { type: 'function', handler: 'demo.echo' },
186
+ metadata: { requiresApproval: false, permission: 'read', readOnly: true },
187
+ },
188
+ async (args) => ({ success: true, data: `Echo: ${String(args.message ?? '')}` })
189
+ );
190
+ ```
191
+
192
+ Return formatting hints via `ToolResult.metadata.outputText` / `title` to control what the agent sees.
193
+
194
+ ## Inspiration / Compatibility
195
+
196
+ - **OpenCode SDK**: OpenCode’s JavaScript SDK primarily wraps an HTTP server (client + server helpers). LingYun SDK starts with an **in‑process** agent runtime that can later be wrapped by an HTTP server if needed.
197
+ - **OpenCode patterns**: history model uses “assistant message + parts” so tool outputs cannot be orphaned from their tool calls.
198
+
199
+ ## Concepts
200
+
201
+ ### Agent
202
+
203
+ An agent is configured with:
204
+
205
+ - **LLM**: OpenAI-compatible endpoint config (base URL, API key, model ID).
206
+ - **Tools**: a tool registry (built-ins + user-registered tools).
207
+ - **Skills**: optional `SKILL.md` discovery + `skill` tool.
208
+ - **Plugins**: optional hook system to transform prompts / tool args / tool outputs / approval decisions.
209
+ - **Security**: workspace boundary enforcement (`allowExternalPaths`).
210
+
211
+ ### Session
212
+
213
+ A session holds:
214
+
215
+ - message history (OpenCode-aligned “assistant message + parts”)
216
+ - any pending plan text (optional)
217
+
218
+ Sessions are serializable; persistence is the host application’s responsibility.
219
+
220
+ ### Run + Streaming
221
+
222
+ `agent.run(...)` returns:
223
+
224
+ - `events`: `AsyncIterable<LingyunEvent>` (tokens, tool calls/results, status changes, compaction markers)
225
+ - `done`: a promise that resolves to `{ text, session }`
226
+
227
+ This makes it easy to integrate into CLIs, web servers, or desktop apps without coupling to a UI framework.
228
+
229
+ ## Security Model
230
+
231
+ The SDK enforces workspace boundaries when `allowExternalPaths=false`:
232
+
233
+ - File tools must reject paths outside `workspaceRoot`.
234
+ - Shell tools must reject commands that reference paths outside the workspace (best-effort path detection; **not** a sandbox).
235
+ - Tools may declare `metadata.supportsExternalPaths` and provide `permissionPatterns` so the agent can detect when a call would escape the workspace.
236
+
237
+ Notes:
238
+
239
+ - The built-in `bash` tool **requires approval by default** (headless-safe default).
240
+ - Shell path enforcement is heuristic and can be bypassed (e.g. via shell expansion, interpreted code, or tools that access the network). For strict hosts, disable shell tools entirely via `toolFilter` / custom tool registration.
241
+
242
+ Approvals are handled via a host callback; `autoApprove` can bypass prompts (except for blocked external paths).
243
+
244
+ ## Plugin Hooks (Subset)
245
+
246
+ Plugins can hook:
247
+
248
+ - system prompt shaping
249
+ - per-request params (temperature, provider options)
250
+ - message transforms before sending to the model
251
+ - approval decisions
252
+ - tool args before execution
253
+ - tool outputs before returning to the model
254
+
255
+ Plugins are loaded from module specifiers or file paths; hosts can also register hooks programmatically.
256
+ For security in headless environments, workspace plugin auto-discovery is **disabled by default** in the SDK (opt in via `plugins.autoDiscover: true`).
257
+
258
+ ## Initial Scope (MVP)
259
+
260
+ - OpenAI-compatible LLM provider
261
+ - Tool registry + approvals + external-path enforcement
262
+ - Built-in tools: `read`, `write`, `list`, `glob`, `grep`, `bash`, `skill`
263
+ - Skills discovery compatible with `.lingyun/skills`, `.claude/skills`, `.opencode/skill(s)`, and `~/.codex/skills`
264
+
265
+ ## Future Scope
266
+
267
+ - Optional HTTP server wrapper + client (OpenCode SDK style)
268
+ - More built-in tools (patch/multiedit, structured diff helpers, LSP adapters)
269
+ - Stronger shell/path safety checks (still not a sandbox)
270
+ - Richer step/operation events aligned with LingYun webview UI
271
+
272
+ ## E2E Tests (Real Server)
273
+
274
+ The SDK includes a separate E2E test suite that hits a real OpenAI-compatible server over HTTP/SSE.
275
+ It is **skipped by default** unless you set `LINGYUN_E2E_BASE_URL`.
276
+
277
+ Run:
278
+
279
+ ```bash
280
+ LINGYUN_E2E_BASE_URL="http://localhost:8080/v1" \
281
+ LINGYUN_E2E_MODEL="your-model-id" \
282
+ pnpm --filter @kooka/agent-sdk test:e2e
283
+ ```
284
+
285
+ Environment variables:
286
+
287
+ - `LINGYUN_E2E_BASE_URL` (required): OpenAI-compatible base URL (with or without `/v1`)
288
+ - `LINGYUN_E2E_MODEL` (optional): model id; if omitted, the test will try `GET /models` and use the first returned id
289
+ - `LINGYUN_E2E_API_KEY` (optional): bearer token if required by your server
290
+ - `LINGYUN_E2E_TIMEOUT_MS` (optional): request timeout (default `300000`)
291
+ - `LINGYUN_E2E_MAX_OUTPUT_TOKENS` (optional): output cap for the “large stream” test (default `4096`)
292
+ - `LINGYUN_E2E_LARGE_MIN_CHARS` (optional): minimum characters required by the “large stream” test (default `8000`)
293
+ - `LINGYUN_E2E_ENABLE_TOOLCALLS` (optional): set to `0` to disable the tool-call E2E test (on by default)
@@ -0,0 +1,2 @@
1
+ export declare function combineAbortSignals(signals: AbortSignal[]): AbortSignal;
2
+ //# sourceMappingURL=abort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../src/abort.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,WAAW,CAkBvE"}
package/dist/abort.js ADDED
@@ -0,0 +1,19 @@
1
+ export function combineAbortSignals(signals) {
2
+ const any = AbortSignal?.any;
3
+ if (typeof any === 'function') {
4
+ return any(signals);
5
+ }
6
+ if (signals.length === 1)
7
+ return signals[0];
8
+ const controller = new AbortController();
9
+ const onAbort = () => controller.abort();
10
+ for (const signal of signals) {
11
+ if (signal.aborted) {
12
+ controller.abort();
13
+ break;
14
+ }
15
+ signal.addEventListener('abort', onAbort, { once: true });
16
+ }
17
+ return controller.signal;
18
+ }
19
+ //# sourceMappingURL=abort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abort.js","sourceRoot":"","sources":["../src/abort.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CAAC,OAAsB;IACxD,MAAM,GAAG,GAAI,WAAmB,EAAE,GAAG,CAAC;IACtC,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,CAAC,CAAE,CAAC;IAE7C,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,UAAU,CAAC,KAAK,EAAE,CAAC;YACnB,MAAM;QACR,CAAC;QACD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,UAAU,CAAC,MAAM,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,67 @@
1
+ import type { AgentCallbacks, AgentConfig, LLMProvider, LingyunRun } from '../types.js';
2
+ import { type AgentHistoryMessage, type CompactionConfig, type ModelLimit } from '@kooka/core';
3
+ import { PluginManager } from '../plugins/pluginManager.js';
4
+ import type { ToolRegistry } from '../tools/registry.js';
5
+ export declare class LingyunSession {
6
+ history: AgentHistoryMessage[];
7
+ pendingPlan?: string;
8
+ sessionId?: string;
9
+ fileHandles?: {
10
+ nextId: number;
11
+ byId: Record<string, string>;
12
+ };
13
+ constructor(init?: Partial<Pick<LingyunSession, 'history' | 'pendingPlan' | 'sessionId' | 'fileHandles'>>);
14
+ getHistory(): AgentHistoryMessage[];
15
+ }
16
+ export type LingyunAgentRuntimeOptions = {
17
+ plugins?: PluginManager;
18
+ workspaceRoot?: string;
19
+ allowExternalPaths?: boolean;
20
+ modelLimits?: Record<string, ModelLimit>;
21
+ compaction?: Partial<CompactionConfig>;
22
+ };
23
+ export declare class LingyunAgent {
24
+ private readonly llm;
25
+ private config;
26
+ private readonly registry;
27
+ private readonly plugins;
28
+ private readonly workspaceRoot?;
29
+ private allowExternalPaths;
30
+ private readonly modelLimits?;
31
+ private readonly compactionConfig;
32
+ private registeredPluginTools;
33
+ constructor(llm: LLMProvider, config: AgentConfig, registry: ToolRegistry, runtime?: LingyunAgentRuntimeOptions);
34
+ updateConfig(config: Partial<AgentConfig>): void;
35
+ setAllowExternalPaths(allow: boolean): void;
36
+ private getMode;
37
+ private getModelLimit;
38
+ private getPermissionRuleset;
39
+ private getPermissionName;
40
+ private normalizePermissionPath;
41
+ private getPermissionPatterns;
42
+ private getExternalPathPatterns;
43
+ private combinePermissionActions;
44
+ private getMaxOutputTokens;
45
+ private ensurePluginToolsRegistered;
46
+ private toModelMessages;
47
+ private createToolContext;
48
+ private formatToolResult;
49
+ private pruneToolResultForHistory;
50
+ private normalizeFileHandlePath;
51
+ private ensureFileHandles;
52
+ private resolveFileHandle;
53
+ private getOrCreateFileHandle;
54
+ private decorateGlobResultWithFileHandles;
55
+ private createAISDKTools;
56
+ private filterTools;
57
+ private composeSystemPrompt;
58
+ private compactSessionInternal;
59
+ private runOnce;
60
+ run(params: {
61
+ session: LingyunSession;
62
+ input: string;
63
+ callbacks?: AgentCallbacks;
64
+ signal?: AbortSignal;
65
+ }): LingyunRun;
66
+ }
67
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/agent/agent.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAwC,cAAc,EAAE,WAAW,EAAE,WAAW,EAAgB,UAAU,EAAE,MAAM,aAAa,CAAC;AAE5I,OAAO,EAsBL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAGhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAK5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA8GzD,qBAAa,cAAc;IACzB,OAAO,EAAE,mBAAmB,EAA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