@linnlabs/linnkit 0.8.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 (123) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +21 -0
  3. package/README.md +178 -0
  4. package/README.zh-CN.md +182 -0
  5. package/dist/agent-invocation-BHcNfrBV.d.cts +30 -0
  6. package/dist/agent-invocation-BznDaXDs.d.ts +30 -0
  7. package/dist/agentEvents-DEB7Fy_J.d.cts +81 -0
  8. package/dist/agentEvents-DEB7Fy_J.d.ts +81 -0
  9. package/dist/agentSpec-EkmviZjy.d.cts +2621 -0
  10. package/dist/agentSpec-EkmviZjy.d.ts +2621 -0
  11. package/dist/ai-engine.types-BpeU_XQG.d.cts +158 -0
  12. package/dist/ai-engine.types-vZRnQcJa.d.ts +158 -0
  13. package/dist/audit-BaRUGaqv.d.cts +307 -0
  14. package/dist/audit-BaRUGaqv.d.ts +307 -0
  15. package/dist/audit-CtcfART1.d.ts +33 -0
  16. package/dist/audit-LeOrm2hX.d.cts +33 -0
  17. package/dist/checkpointMarker-DAI3wUQu.d.cts +8 -0
  18. package/dist/checkpointMarker-DAI3wUQu.d.ts +8 -0
  19. package/dist/cli.cjs +8028 -0
  20. package/dist/cli.cjs.map +1 -0
  21. package/dist/cli.d.cts +4 -0
  22. package/dist/cli.d.ts +4 -0
  23. package/dist/cli.js +8025 -0
  24. package/dist/cli.js.map +1 -0
  25. package/dist/context-manager.cjs +8704 -0
  26. package/dist/context-manager.cjs.map +1 -0
  27. package/dist/context-manager.d.cts +2190 -0
  28. package/dist/context-manager.d.ts +2190 -0
  29. package/dist/context-manager.js +8650 -0
  30. package/dist/context-manager.js.map +1 -0
  31. package/dist/context-trace-DRi5M4lX.d.ts +239 -0
  32. package/dist/context-trace-HE2qY5Q-.d.cts +239 -0
  33. package/dist/contracts.cjs +1333 -0
  34. package/dist/contracts.cjs.map +1 -0
  35. package/dist/contracts.d.cts +8 -0
  36. package/dist/contracts.d.ts +8 -0
  37. package/dist/contracts.js +1214 -0
  38. package/dist/contracts.js.map +1 -0
  39. package/dist/defaultGraphExecutor-BBswR8wn.d.ts +624 -0
  40. package/dist/defaultGraphExecutor-BIjJj7WF.d.cts +624 -0
  41. package/dist/execution-CAIypb41.d.cts +129 -0
  42. package/dist/execution-CAIypb41.d.ts +129 -0
  43. package/dist/index-CHqwkvGp.d.ts +149 -0
  44. package/dist/index-CJeWHopy.d.ts +584 -0
  45. package/dist/index-Cm-JbzTH.d.cts +1450 -0
  46. package/dist/index-Cvr23YCl.d.cts +23 -0
  47. package/dist/index-DDzuSb0n.d.ts +23 -0
  48. package/dist/index-DO4dQgf2.d.cts +584 -0
  49. package/dist/index-DRBWi1fy.d.ts +1450 -0
  50. package/dist/index-Dl5PLgAv.d.cts +149 -0
  51. package/dist/index.cjs +9577 -0
  52. package/dist/index.cjs.map +1 -0
  53. package/dist/index.d.cts +89 -0
  54. package/dist/index.d.ts +89 -0
  55. package/dist/index.js +9563 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/messages-XthmnHZ3.d.cts +8007 -0
  58. package/dist/messages-XthmnHZ3.d.ts +8007 -0
  59. package/dist/ports-DaatKJXp.d.cts +90 -0
  60. package/dist/ports-DnLuKfpE.d.ts +90 -0
  61. package/dist/ports.cjs +4 -0
  62. package/dist/ports.cjs.map +1 -0
  63. package/dist/ports.d.cts +7 -0
  64. package/dist/ports.d.ts +7 -0
  65. package/dist/ports.js +3 -0
  66. package/dist/ports.js.map +1 -0
  67. package/dist/quickstart.cjs +7697 -0
  68. package/dist/quickstart.cjs.map +1 -0
  69. package/dist/quickstart.d.cts +24 -0
  70. package/dist/quickstart.d.ts +24 -0
  71. package/dist/quickstart.js +7691 -0
  72. package/dist/quickstart.js.map +1 -0
  73. package/dist/runAgent-CPj_9e58.d.ts +88 -0
  74. package/dist/runAgent-HYKlXbVr.d.cts +88 -0
  75. package/dist/runHandle-CyXvzgzk.d.ts +239 -0
  76. package/dist/runHandle-D3gPsD7B.d.cts +239 -0
  77. package/dist/runtime-kernel/events.cjs +1485 -0
  78. package/dist/runtime-kernel/events.cjs.map +1 -0
  79. package/dist/runtime-kernel/events.d.cts +8 -0
  80. package/dist/runtime-kernel/events.d.ts +8 -0
  81. package/dist/runtime-kernel/events.js +1475 -0
  82. package/dist/runtime-kernel/events.js.map +1 -0
  83. package/dist/runtime-kernel.cjs +8656 -0
  84. package/dist/runtime-kernel.cjs.map +1 -0
  85. package/dist/runtime-kernel.d.cts +19 -0
  86. package/dist/runtime-kernel.d.ts +19 -0
  87. package/dist/runtime-kernel.js +8568 -0
  88. package/dist/runtime-kernel.js.map +1 -0
  89. package/dist/sse-vPyrOPa0.d.cts +1687 -0
  90. package/dist/sse-vPyrOPa0.d.ts +1687 -0
  91. package/dist/testkit.cjs +10613 -0
  92. package/dist/testkit.cjs.map +1 -0
  93. package/dist/testkit.d.cts +284 -0
  94. package/dist/testkit.d.ts +284 -0
  95. package/dist/testkit.js +10593 -0
  96. package/dist/testkit.js.map +1 -0
  97. package/dist/todo-B1PmDlp3.d.cts +2253 -0
  98. package/dist/todo-B1PmDlp3.d.ts +2253 -0
  99. package/dist/tokenizer-DFL4I7-I.d.ts +28 -0
  100. package/dist/tokenizer-DH_JXv-H.d.cts +28 -0
  101. package/dist/toolContracts-Blll0241.d.ts +463 -0
  102. package/dist/toolContracts-CLkQmhTG.d.cts +463 -0
  103. package/docs/README.md +76 -0
  104. package/docs/integration/01-installation.md +94 -0
  105. package/docs/integration/02-quickstart.md +104 -0
  106. package/docs/integration/README.md +223 -0
  107. package/docs/integration/agent-registration-guide.md +330 -0
  108. package/docs/integration/audit.md +64 -0
  109. package/docs/integration/child-runs.md +87 -0
  110. package/docs/integration/constraints-and-pitfalls.md +87 -0
  111. package/docs/integration/context-engineering.md +650 -0
  112. package/docs/integration/context-fences.md +289 -0
  113. package/docs/integration/glossary.md +69 -0
  114. package/docs/integration/llm-provider.md +76 -0
  115. package/docs/integration/persistence.md +44 -0
  116. package/docs/integration/realtime.md +76 -0
  117. package/docs/integration/run-supervisor.md +69 -0
  118. package/docs/integration/telemetry.md +48 -0
  119. package/docs/integration/testing.md +95 -0
  120. package/docs/integration/tool-development-guide.md +362 -0
  121. package/docs/integration/tool-history.md +202 -0
  122. package/docs/integration/tools.md +188 -0
  123. package/package.json +115 -0
@@ -0,0 +1,463 @@
1
+ import { e as RuntimeEvent, g as SubRunTraceEvent, a as AgentTodoSnapshot } from './todo-B1PmDlp3.cjs';
2
+
3
+ interface ToolContextConversationView {
4
+ /**
5
+ * 当前工具执行可见的 working history
6
+ *
7
+ * 中文备注:
8
+ * - 该视图允许工具读取“本轮 run 中已产生、但可能尚未持久化”的最新事实事件;
9
+ * - ToolNode / graph runtime 后续只应更新这一层背后的 source,而不是覆写顶层 getter。
10
+ */
11
+ getWorkingHistoryEvents(): ReadonlyArray<RuntimeEvent>;
12
+ /**
13
+ * run 启动时的 persisted history 视图
14
+ *
15
+ * 中文备注:
16
+ * - 该视图对应 EventStore 回放得到的稳定历史;
17
+ * - 与 working history 显式区分,避免调用方误把“最新运行态”当成“已持久化事实”。
18
+ */
19
+ getPersistedHistoryEvents(): ReadonlyArray<RuntimeEvent>;
20
+ }
21
+
22
+ /**
23
+ * 子 run trace 的“业务无关”发布载荷。
24
+ *
25
+ * 说明:
26
+ * - 该结构刻意只包含 subrun_trace 的 payload 字段(不包含 conversation_id/turn_id 等基础字段)
27
+ * - parent_tool_call_id/subrun_id 是发布器构造时绑定的,不需要每次 publish 重复提供
28
+ */
29
+ interface SubRunTraceEnvelope {
30
+ /** 分片类型 */
31
+ kind: SubRunTraceEvent['kind'];
32
+ /** 增量文本(kind=*_delta 时使用) */
33
+ delta?: string;
34
+ /** 完整文本(kind=*_complete/final_answer 时使用) */
35
+ content?: string;
36
+ /** 关联工具名(kind=tool_call_decision/tool_process/tool_output 时使用) */
37
+ tool_name?: string;
38
+ /** 关联工具调用 ID(子 run 内部的 tool_call_id,用于展示步骤) */
39
+ tool_call_id?: string;
40
+ /** 工具调用阶段(kind=tool_call_decision/tool_process 时使用) */
41
+ phase?: SubRunTraceEvent['phase'];
42
+ /** 工具调用状态(kind=tool_call_decision/tool_process/tool_output 时使用) */
43
+ status?: SubRunTraceEvent['status'];
44
+ /** 工具参数(结构不做强约束,避免与业务强耦合) */
45
+ args?: unknown;
46
+ /** 工具输出(结构不做强约束,避免与业务强耦合) */
47
+ output?: unknown;
48
+ /** 执行耗时(毫秒) */
49
+ duration_ms?: number;
50
+ /** 可选调试/渲染元信息 */
51
+ meta?: Record<string, unknown>;
52
+ }
53
+ /**
54
+ * 子 run trace 发布器接口(面向业务工具层)。
55
+ *
56
+ * 约束:
57
+ * - 发布器必须确保生成的 RuntimeEvent 为 `type='subrun_trace'` 且 `ephemeral=true`
58
+ * - 发布器应保证每条事件的 id 唯一(用于前端 processedEvents 幂等去重)
59
+ */
60
+ interface SubRunTracePublisher {
61
+ publish(envelope: SubRunTraceEnvelope): void;
62
+ }
63
+
64
+ /**
65
+ * @file src/agent/runtime-kernel/run-context/types.ts
66
+ * @description 统一运行上下文定义
67
+ *
68
+ * 核心目标:
69
+ * - 统一管理跨 Run(Graph执行)的链路追踪信息
70
+ * - 支持父子任务(SubAgent)与审阅等长程业务的上下文贯穿
71
+ * - 替代散落在各处的 review_run_id 等专用字段
72
+ */
73
+ interface RunContext {
74
+ /**
75
+ * 当前 Run 的唯一标识(对应一次 Graph 执行 / 一次 conversation turn)
76
+ * - 通常对应 `turnId` 或 `messageId`
77
+ */
78
+ runId: string;
79
+ /**
80
+ * 链路追踪 ID(贯穿业务全流程)
81
+ * - Review场景:对应 review_run_id(一次审阅包含多次 AI 调用)
82
+ * - 简单对话场景:可与 conversationId 或 runId 相同
83
+ */
84
+ traceId: string;
85
+ /**
86
+ * 父级 Run ID(用于子 Agent / 嵌套图)
87
+ * - 如果是顶层任务,则为 undefined
88
+ */
89
+ parentId?: string;
90
+ /**
91
+ * 根 Run ID(业务发起的原点)
92
+ */
93
+ rootRunId?: string;
94
+ /**
95
+ * 业务标签/元数据(业务特定的上下文挂载点)
96
+ * - 例如:{ agentId: 'logicCheck', chunkIndex: 0 }
97
+ * - 替代原先散落在 ToolContext 顶层的 loose fields
98
+ */
99
+ tags: Record<string, string | number | boolean | undefined>;
100
+ }
101
+ /**
102
+ * 创建默认的 RunContext
103
+ */
104
+ declare function createDefaultRunContext(overrides?: Partial<RunContext>): RunContext;
105
+
106
+ interface ToolContextCompatibilityFields {
107
+ /**
108
+ * 兼容字段:原始用户请求
109
+ *
110
+ * 中文备注:
111
+ * - 当前由 host context injection 写入;
112
+ * - 仍有少量 deep_search 调用方在读取;
113
+ * - 后续应继续收窄,不再扩散新的读取点。
114
+ */
115
+ user_query?: string;
116
+ /**
117
+ * 兼容字段:当前 run 选定模型 ID
118
+ *
119
+ * 中文备注:
120
+ * - 当前主要给 child-run 调用方继承父模型选择;
121
+ * - 后续应继续收窄到显式 child-run execution policy。
122
+ */
123
+ modelId?: string;
124
+ /**
125
+ * 兼容字段:当前 runContext
126
+ *
127
+ * 中文备注:
128
+ * - 当前主要由 host 注入;尚未在工具侧广泛直接读取;
129
+ * - 保留显式字段是为了停止继续依赖 string-index loose access。
130
+ */
131
+ run_context?: RunContext;
132
+ }
133
+ type CompatibilityCarrier = ToolContextCompatibilityFields | Record<string, unknown> | undefined;
134
+ declare function readToolContextUserQuery(context: CompatibilityCarrier): string | undefined;
135
+ declare function readToolContextModelId(context: CompatibilityCarrier): string | undefined;
136
+ declare function readToolContextRunContext(context: CompatibilityCarrier): RunContext | undefined;
137
+
138
+ /**
139
+ * child-run 父上下文的 runtime-owned 最小合同
140
+ *
141
+ * 中文备注:
142
+ * - 这里只声明 child-run 协议真正需要的 runtime capability / compatibility fields;
143
+ * - 不显式依赖完整 ToolContext,避免 child-run 主链编译期吃进整套 host/product 服务类型;
144
+ * - 仍保留 index signature,用于在创建 child ToolContext 时透传宿主/产品层 patch。
145
+ */
146
+ interface ChildRunParentContext extends ToolExecutionContext, ToolContextCompatibilityFields {
147
+ deepSearchDepth?: number;
148
+ [key: string]: unknown;
149
+ }
150
+ interface ChildRunHistoryPolicy {
151
+ inheritTurns: number;
152
+ eventFilter?: (event: RuntimeEvent) => boolean;
153
+ }
154
+ interface ChildRunTracePolicy {
155
+ parentToolCallId?: string;
156
+ subrunId?: string;
157
+ source?: string;
158
+ metadata?: Record<string, unknown>;
159
+ persistForReplay?: boolean;
160
+ }
161
+ interface ChildRunExecutionPolicy {
162
+ /**
163
+ * 显式 child-run runId。默认由 host adapter 取 subrunId。
164
+ */
165
+ runId?: string;
166
+ /**
167
+ * 父 runId。默认从 parentToolContext.runId 继承。
168
+ */
169
+ parentRunId?: string;
170
+ maxSteps?: number;
171
+ modelId?: string;
172
+ abortSignal?: AbortSignal;
173
+ }
174
+ interface ChildRunRequest<TParentToolContext = ChildRunParentContext> {
175
+ userMessage: string;
176
+ parentToolContext: TParentToolContext;
177
+ historyPolicy?: ChildRunHistoryPolicy;
178
+ tracePolicy?: ChildRunTracePolicy;
179
+ executionPolicy?: ChildRunExecutionPolicy;
180
+ }
181
+ interface ChildRunResult {
182
+ runId?: string;
183
+ parentRunId?: string;
184
+ subrunId: string;
185
+ success: boolean;
186
+ finalAnswer: string;
187
+ events: RuntimeEvent[];
188
+ stepCount: number;
189
+ error?: string;
190
+ judgeToolOutput?: string;
191
+ }
192
+ interface ChildRunInvokerPort<TRequest extends ChildRunRequest = ChildRunRequest, TResult extends ChildRunResult = ChildRunResult> {
193
+ invoke(params: TRequest): Promise<TResult>;
194
+ }
195
+
196
+ /**
197
+ * runtime-owned 工具执行上下文最小合同
198
+ *
199
+ * 中文备注:
200
+ * - 这里只保留 graph-engine / tool runtime / child-run 真正需要解释执行的字段;
201
+ * - 不包含 KnowledgeBase / Workspace / DB 等宿主服务类型;
202
+ * - 不包含 deepSearch / research / workspaceProject 等产品语义字段。
203
+ */
204
+ interface ToolExecutionContext {
205
+ /**
206
+ * 当前对话 run 的唯一标识(由 FlowOrchestrator 注入)
207
+ * 说明:Workspace 工具 vNext 协议已不再依赖 index 快照,但 runId 仍可用于其他链路的追踪/调试。
208
+ */
209
+ runId?: string;
210
+ /**
211
+ * 父级 run 标识。
212
+ *
213
+ * 中文备注:
214
+ * - 顶层 run 通常为空;
215
+ * - 同步 child-run 会把自己的 `runId` 设为子 run / subrun ID,同时把父 run 写到这里;
216
+ * - Telemetry / Audit / Cost 聚合依赖这个字段建立父子关系,但 graph-engine 不解释产品语义。
217
+ */
218
+ parentRunId?: string;
219
+ /**
220
+ * 🔥 引用编号偏移量(用于多次工具调用时的连续编号)
221
+ *
222
+ * 工作原理:
223
+ * - 每次调用知识库工具时,由 ToolNode 传入当前轮次已使用的引用数量
224
+ * - 工具在格式化 observation 和构建 citations 时使用此偏移量
225
+ * - 确保 AI 看到的编号和引用元数据的编号都是连续且一致的
226
+ *
227
+ * @default 0 - 表示从 1 开始编号
228
+ */
229
+ citationOffset?: number;
230
+ /**
231
+ * 🔥 取消信号(贯穿一次对话请求)
232
+ *
233
+ * 约定:
234
+ * - 工具实现必须在合适的边界检查 `abortSignal.aborted` 并尽快退出;
235
+ * - 该字段属于“执行期上下文”,不应被写入持久化事件。
236
+ */
237
+ abortSignal?: AbortSignal;
238
+ /**
239
+ * 🔥 当前这次工具调用的 tool_call_id(由 ToolNode 在执行前注入)
240
+ *
241
+ * 说明:
242
+ * - tool_call_id 属于“事件层/执行层”的稳定关联键;
243
+ * - 工具内部如果需要发布 subrun_trace(子 run 过程),必须使用该字段作为 parent_tool_call_id。
244
+ * - 该字段仅在工具执行期间有效,不应被工具写入持久化历史。
245
+ */
246
+ parentToolCallId?: string;
247
+ /**
248
+ * 🔥 当前对话 ID(由 GraphExecutor/ToolNode 注入,用于工具内部做链路追踪)
249
+ */
250
+ conversationId?: string;
251
+ /**
252
+ * 🔥 当前轮次 ID(由 GraphExecutor/ToolNode 注入,用于工具内部做链路追踪)
253
+ */
254
+ turnId?: string;
255
+ /**
256
+ * 🔥 Agent ToDo(working memory)快照(对话级)
257
+ *
258
+ * 设计说明:
259
+ * - ToDo 的权威状态应落到 RuntimeEvent(todo_updated)以便截断/回放一致;
260
+ * - 但工具执行期间需要“读到本轮最新状态”(尚未落库),因此把最新快照同时缓存到 ToolContext。
261
+ * - AgentRunnerService 会在每次 run 开始时用历史事件回放的最后一条 todo_updated 为其初始化。
262
+ */
263
+ agentTodo?: AgentTodoSnapshot;
264
+ /**
265
+ * 🔥 显式会话视图 capability
266
+ *
267
+ * 中文备注:
268
+ * - `conversationView` 是后续统一承载 working/persisted history 的稳定协议面;
269
+ * - 迁移期仍保留 `getConversationHistoryEvents()` 兼容旧工具。
270
+ */
271
+ conversationView?: ToolContextConversationView;
272
+ /**
273
+ * 🔥 获取父会话的历史事件(兼容 getter)
274
+ *
275
+ * 约束:
276
+ * - 返回值必须被视为只读:工具不得修改数组内容;
277
+ * - 迁移期该 getter 语义固定为 `conversationView.getWorkingHistoryEvents()`;
278
+ * - 新代码优先直接使用 `conversationView`,避免继续把 working/persisted history 混为一个概念。
279
+ */
280
+ getConversationHistoryEvents?: () => ReadonlyArray<RuntimeEvent>;
281
+ /**
282
+ * 🔥 发布 todo_updated RuntimeEvent(低耦合注入)
283
+ */
284
+ publishAgentTodoUpdated?: (snapshot: AgentTodoSnapshot) => void;
285
+ /**
286
+ * 🔥 SubRun Trace Channel:为工具提供 publisher 工厂(低耦合)
287
+ */
288
+ createSubRunTracePublisher?: (opts: {
289
+ parentToolCallId: string;
290
+ subrunId: string;
291
+ subrunParentId?: string;
292
+ source?: string;
293
+ metadata?: Record<string, unknown>;
294
+ persistForReplay?: boolean;
295
+ }) => SubRunTracePublisher;
296
+ /**
297
+ * 显式 child-run invoker 注入(迁移期优先入口)
298
+ */
299
+ registeredChildRunInvoker?: ChildRunInvokerPort;
300
+ /**
301
+ * 与 ConversationArtifactContext 等「可扩展宿主字段」交织时的结构兼容:
302
+ * - 运行期 toolContext 常为普通对象,可能携带 sharedMemory / research 等附加键;
303
+ * - 无此索引签名时,`ToolExecutionContext` 无法赋给 `ToolExecutionContext & ConversationArtifactContext`(strict 下报错)。
304
+ */
305
+ [key: string]: unknown;
306
+ }
307
+
308
+ /**
309
+ * @file src/agent/runtime-kernel/tools/ui-types.ts
310
+ *
311
+ * @brief 定义工具在前端UI展示时所需的元数据类型
312
+ *
313
+ * @description
314
+ * 这个文件中的类型专门用于 "后端驱动UI (Backend-Driven UI)" 架构。
315
+ * 当后端Agent执行一个工具时,它会附带这些UI元数据。
316
+ * 前端则根据这些元数据,动态地、智能地渲染出对应的UI组件,
317
+ * 从而实现工具展示逻辑与前端渲染逻辑的解耦。
318
+ */
319
+ interface ToolLayoutOptions {
320
+ contentPadding?: boolean;
321
+ showBorder?: boolean;
322
+ showBackground?: boolean;
323
+ }
324
+ interface ToolDisplayOptions {
325
+ viewType: string;
326
+ titleTemplate?: string;
327
+ icon?: string;
328
+ layout?: ToolLayoutOptions;
329
+ }
330
+ interface ToolControlInfo {
331
+ requireUser?: boolean;
332
+ questionnaireId?: string;
333
+ resumeStrategy?: 'continue';
334
+ terminateRun?: boolean;
335
+ reason?: string;
336
+ }
337
+ interface StructuredToolResult<T = Record<string, unknown>> {
338
+ data: T;
339
+ observation?: string;
340
+ control?: ToolControlInfo;
341
+ }
342
+
343
+ type ToolIdempotencyScope = 'conversation' | 'turn';
344
+ type ToolIdempotencyPolicy = {
345
+ scope: ToolIdempotencyScope;
346
+ };
347
+ declare function computeToolIdempotencyKey(params: {
348
+ policy: ToolIdempotencyPolicy;
349
+ toolName: string;
350
+ args: Record<string, unknown>;
351
+ context: ToolExecutionContext;
352
+ }): string;
353
+ declare function findCachedToolOutputByIdempotencyKey(params: {
354
+ history: ReadonlyArray<RuntimeEvent>;
355
+ toolName: string;
356
+ idempotencyKey: string;
357
+ }): {
358
+ output: string;
359
+ } | undefined;
360
+
361
+ type ToolArgs = Record<string, unknown>;
362
+ type JsonObjectSchema = Record<string, unknown>;
363
+ interface ToolParameterProperty {
364
+ type: string;
365
+ description: string;
366
+ default?: unknown;
367
+ enum?: string[];
368
+ properties?: Record<string, ToolParameterProperty>;
369
+ items?: ToolParameterProperty;
370
+ required?: string[];
371
+ }
372
+ interface ToolParameterSchema {
373
+ type: 'object';
374
+ properties: Record<string, ToolParameterProperty>;
375
+ required?: string[];
376
+ additionalProperties?: boolean;
377
+ }
378
+ interface ToolResult {
379
+ success: boolean;
380
+ data: string;
381
+ metadata?: Record<string, unknown>;
382
+ }
383
+ type UnifiedToolResult = {
384
+ kind: 'ok';
385
+ output: unknown;
386
+ } | {
387
+ kind: 'need_user';
388
+ spec: unknown;
389
+ } | {
390
+ kind: 'async';
391
+ run_id: string;
392
+ };
393
+ declare abstract class BaseTool<TArgs extends ToolArgs = ToolArgs, TResult extends string = string> {
394
+ abstract readonly name: string;
395
+ abstract readonly description: string;
396
+ abstract readonly parameters: ToolParameterSchema;
397
+ readonly idempotency?: ToolIdempotencyPolicy;
398
+ readonly displayOptions?: ToolDisplayOptions;
399
+ getExecutionSummary?(output: string): string;
400
+ abstract run(args: TArgs, context: ToolExecutionContext): Promise<TResult>;
401
+ protected validateArguments(args: TArgs): {
402
+ success: boolean;
403
+ error?: string;
404
+ };
405
+ getMetadata(): {
406
+ name: string;
407
+ description: string;
408
+ parameters: ToolParameterSchema;
409
+ };
410
+ }
411
+ interface ToolRegistryEntry {
412
+ name: string;
413
+ toolClass: new () => BaseTool<ToolArgs, string>;
414
+ metadata: ReturnType<BaseTool['getMetadata']>;
415
+ }
416
+ declare const CommonParameterTypes: {
417
+ readonly docId: {
418
+ readonly type: "string";
419
+ readonly description: "The unique ID of the document";
420
+ };
421
+ readonly query: {
422
+ readonly type: "string";
423
+ readonly description: "The search query text";
424
+ };
425
+ readonly topK: {
426
+ readonly type: "integer";
427
+ readonly description: "The maximum number of results to return";
428
+ readonly default: 5;
429
+ };
430
+ readonly blockId: {
431
+ readonly type: "string";
432
+ readonly description: "The unique ID of a content block";
433
+ };
434
+ readonly pageNumber: {
435
+ readonly type: "integer";
436
+ readonly description: "Page number (1-indexed)";
437
+ readonly default: 1;
438
+ };
439
+ };
440
+ interface AgentTool<TArgs extends ToolArgs = ToolArgs, TResult = unknown> {
441
+ name: string;
442
+ description: string;
443
+ parameters: JsonObjectSchema;
444
+ execute(args: TArgs): Promise<TResult>;
445
+ }
446
+ interface OpenAIToolSchema {
447
+ type: 'function';
448
+ function: {
449
+ name: string;
450
+ description: string;
451
+ parameters: JsonObjectSchema;
452
+ };
453
+ }
454
+ interface ToolCallResult<TResult = unknown> {
455
+ toolName: string;
456
+ args: ToolArgs;
457
+ result: TResult;
458
+ success: boolean;
459
+ error?: string;
460
+ durationMs: number;
461
+ }
462
+
463
+ export { type AgentTool as A, BaseTool as B, CommonParameterTypes as C, type JsonObjectSchema as J, type OpenAIToolSchema as O, type RunContext as R, type StructuredToolResult as S, type ToolExecutionContext as T, type UnifiedToolResult as U, type ToolArgs as a, type ToolParameterSchema as b, type ToolParameterProperty as c, type ToolContextConversationView as d, type ToolCallResult as e, type ToolContextCompatibilityFields as f, type ToolControlInfo as g, type ToolDisplayOptions as h, type ToolLayoutOptions as i, type ToolRegistryEntry as j, type ToolResult as k, computeToolIdempotencyKey as l, findCachedToolOutputByIdempotencyKey as m, readToolContextRunContext as n, readToolContextUserQuery as o, createDefaultRunContext as p, type ChildRunParentContext as q, readToolContextModelId as r, type SubRunTracePublisher as s, type ChildRunHistoryPolicy as t, type ChildRunInvokerPort as u, type ChildRunRequest as v, type ChildRunResult as w, type SubRunTraceEnvelope as x, type ToolIdempotencyPolicy as y };
package/docs/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # linnkit Docs
2
+
3
+ `linnkit` 是一个通用 Agent 框架。它提供 runtime、context engineering、ports、testkit 和 quickstart;具体 LLM provider、工具集、存储、实时通道、权限、业务上下文都由 host 自己装配。
4
+
5
+ 这份目录只保留公开接入者需要长期阅读的内容。内部路线图、研究笔记和历史 runbook 不属于公开文档面。
6
+
7
+ ## 推荐阅读顺序
8
+
9
+ 1. [包根 README](../README.md)
10
+ 先看 linnkit 的定位、能力边界和 quickstart。
11
+ 2. [Integration Guide](./integration/README.md)
12
+ 按主题接入 LLM、工具、上下文、持久化、RunSupervisor、AuditPort、Telemetry 和测试。
13
+ 3. [Changelog](../CHANGELOG.md)
14
+ 查看公开版本变化和兼容性说明。
15
+
16
+ ## 公开 API
17
+
18
+ `package.json#exports` 锁定当前公开入口。任何没有出现在 exports 里的 deep import 都不稳定。
19
+
20
+ | 子入口 | 用途 | 环境 |
21
+ |---|---|---|
22
+ | `@linnlabs/linnkit` | 根入口,常用 namespace 与 helper | Node-only |
23
+ | `@linnlabs/linnkit/ports` | host 需要实现的接口 | Node-only |
24
+ | `@linnlabs/linnkit/contracts` | 消息、事件、SSE 等稳定合同 | Node-only |
25
+ | `@linnlabs/linnkit/runtime-kernel` | graph、tool、run、llm 等 runtime 能力 | Node-only |
26
+ | `@linnlabs/linnkit/runtime-kernel/events` | 浏览器安全的事件治理函数 | Browser-safe |
27
+ | `@linnlabs/linnkit/context-manager` | context pipeline、fence、profile 能力 | Node-only |
28
+ | `@linnlabs/linnkit/testkit` | 测试夹具与协议不变量 | Test-only |
29
+ | `@linnlabs/linnkit/quickstart` | `defineAgent` / `runAgent` / `defineConfig` demo helper | Node-only |
30
+
31
+ ## 分层边界
32
+
33
+ | 层 | linnkit 负责 | host 负责 |
34
+ |---|---|---|
35
+ | runtime-kernel | graph loop、tool runtime、run lifecycle、事件治理 | 默认工具、SSE/WebSocket/IPC、业务执行策略 |
36
+ | context-manager | 上下文窗口构建、预算裁剪、fence、摘要、checkpoint、trace | 业务上下文注入、must-keep 策略、provider registry 配置 |
37
+ | ports | 稳定接入接口 | 具体 LLM、存储、tokenizer、telemetry、audit 实现 |
38
+ | testkit | 通用 fixture、harness、不变量校验 | host-bound harness 与生产装配回归 |
39
+
40
+ ## 关键约束
41
+
42
+ 1. 生产代码不要 import `@linnlabs/linnkit/testkit`。
43
+ 2. 浏览器代码不要 import `@linnlabs/linnkit/runtime-kernel`,只用 `@linnlabs/linnkit/runtime-kernel/events` 或按需使用 contracts。
44
+ 3. 不要 deep import。公开入口以 `package.json#exports` 为准。
45
+ 4. 不要把 provider/tool/adapter 写回 linnkit。它们应该留在 host 仓库,通过 ports 和 registry 接入。
46
+ 5. 业务上下文走 fence 机制注册,linnkit 不硬编码任何产品词汇。
47
+
48
+ ## 文档地图
49
+
50
+ ### 起步
51
+
52
+ - [installation](./integration/01-installation.md)
53
+ - [quickstart](./integration/02-quickstart.md)
54
+ - [constraints and pitfalls](./integration/constraints-and-pitfalls.md)
55
+ - [glossary](./integration/glossary.md)
56
+
57
+ ### 接入主题
58
+
59
+ - [LLM provider](./integration/llm-provider.md)
60
+ - [tools](./integration/tools.md)
61
+ - [tool development guide](./integration/tool-development-guide.md)
62
+ - [agent registration](./integration/agent-registration-guide.md)
63
+ - [context engineering](./integration/context-engineering.md)
64
+ - [context fences](./integration/context-fences.md)
65
+ - [tool history](./integration/tool-history.md)
66
+ - [persistence](./integration/persistence.md)
67
+ - [run supervisor](./integration/run-supervisor.md)
68
+ - [child runs](./integration/child-runs.md)
69
+ - [audit](./integration/audit.md)
70
+ - [telemetry](./integration/telemetry.md)
71
+ - [realtime](./integration/realtime.md)
72
+ - [testing](./integration/testing.md)
73
+
74
+ ## 维护说明
75
+
76
+ 公开文档只写长期稳定的接入事实。一次性升级计划、内部取舍、调研笔记和发布 runbook 不放进公开仓;公开版本变化统一写到仓根 `CHANGELOG.md`。
@@ -0,0 +1,94 @@
1
+ # Installation · 装包
2
+
3
+ > **What** · 把 `@linnlabs/linnkit` 装到自己仓库 + 跑通装包 smoke。
4
+ > **When to read** · 第一次接入 linnkit;新加 CI 环境;遇到 `Missing tiktoken_bg.wasm` 类装包错误想排查。
5
+ > **Prerequisites** · 无(这是接入第 1 篇)。
6
+ > **Key exports** · 无(本文不涉及 import)。
7
+ > **Related** · [`02-quickstart.md`](./02-quickstart.md) · [`constraints-and-pitfalls.md`](./constraints-and-pitfalls.md)
8
+
9
+ ## 1. 这个包发布在哪
10
+
11
+ `@linnlabs/linnkit` 发布到 **npmjs.com 公开 registry**(`https://registry.npmjs.org/`),scope 是 `@linnlabs`。正常 npm 项目不需要额外 `.npmrc`。
12
+
13
+ 如果你以前接过 GitHub Packages 私有版本,请删除项目 `.npmrc` 里的旧配置:
14
+
15
+ ```ini
16
+ @linnlabs:registry=https://npm.pkg.github.com/
17
+ ```
18
+
19
+ 这条旧 registry override 会让 npm 继续去 GitHub Packages 找包,公开版本反而装不到。
20
+
21
+ ## 2. 安装
22
+
23
+ ```bash
24
+ npm install @linnlabs/linnkit
25
+ ```
26
+
27
+ 如果你只想先跑 quickstart,也可以全局安装 CLI:
28
+
29
+ ```bash
30
+ npm install -g @linnlabs/linnkit
31
+ linnkit init hello-linnkit
32
+ ```
33
+
34
+ CLI v0 只包含三个命令:
35
+
36
+ | 命令 | 用途 |
37
+ |---|---|
38
+ | `linnkit init <name>` | 生成一个自包含 demo host(JS ESM + OpenAI-compatible fetch adapter + memory runtime) |
39
+ | `linnkit doctor [--config linnkit.config.mjs]` | 检查 Node / npm registry 配置 / env / config / LLM adapter 形状 |
40
+ | `linnkit run <agent-id> --input "..." [--model "..."]` | 运行 quickstart config 里的 agent,打印 final answer 和 cost 摘要 |
41
+
42
+ `replay` / `inspect` 不在 CLI v0 范围内。真要做生产级 replay / inspect,请接入自己的 EventStore / RunSupervisor,并按 [testing.md](./testing.md) 与 [run-supervisor.md](./run-supervisor.md) 做 host 侧工具。
43
+
44
+ `peerDependencies`:
45
+
46
+ | peer | 说明 |
47
+ |---|---|
48
+ | `zod` (`^3.22.0`) | 必需。`@linnlabs/linnkit/contracts` 用 zod 定义所有消息/事件 schema,运行时也会校验 |
49
+ | `vitest` (`^2 \|\| ^3`) | 可选。**只有当你打算 import `@linnlabs/linnkit/testkit` 写测试时才需要装** |
50
+
51
+ `@linnlabs/linnkit/testkit` 在源码顶层 `import { vi, expect } from 'vitest'`,所以生产代码 **绝对不能** import 这个子入口(详见 [constraints-and-pitfalls.md](./constraints-and-pitfalls.md))。
52
+
53
+ ## 3. 验证装包成功
54
+
55
+ 新建一个 `smoke.ts`:
56
+
57
+ ```ts
58
+ import { runtimeKernel, generateMessageId } from '@linnlabs/linnkit';
59
+ import type { AgentInvocationRequest, AgentAiEngine } from '@linnlabs/linnkit/ports';
60
+ import type { AiMessage, RuntimeEvent } from '@linnlabs/linnkit/contracts';
61
+
62
+ console.log(generateMessageId());
63
+ console.log(typeof runtimeKernel.graph);
64
+ ```
65
+
66
+ `tsc --noEmit` 通过 + 运行无报错 = 装包成功。如果你在前端项目里这么写会拖进 `node:async_hooks`,请先看 [README.md §5 浏览器规则](./README.md#5-浏览器使用规则硬约束)。
67
+
68
+ 如果想验证 CLI:
69
+
70
+ ```bash
71
+ npx linnkit --help
72
+ ```
73
+
74
+ ---
75
+
76
+ ## 常见装包问题(FAQ)
77
+
78
+ **Q:我装的是 `@linnlabs/linnkit`,但 npm/yarn 报 401 / 404?**
79
+
80
+ 优先检查项目或用户级 `.npmrc` 是否还把 `@linnlabs` 指到了旧的 GitHub Packages:
81
+
82
+ ```bash
83
+ npm config get @linnlabs:registry
84
+ ```
85
+
86
+ 如果输出是 `https://npm.pkg.github.com/`,请删掉这条配置,让 npm 回到默认的 `https://registry.npmjs.org/`。
87
+
88
+ **Q:我能不能 fork linnkit、改它内部然后用我自己的 fork?**
89
+
90
+ 技术上可以,但你要自己负担"和上游同步 + boundary guard 自维护"的成本。99% 你想做的事都能通过依赖注入在 host 层完成;如果你发现某个改动只能 fork 才能做,那大概率说明你应该来跟 linnkit 维护方提 issue / PR。
91
+
92
+ **Q:import `@linnlabs/linnkit/runtime-kernel` 报 "Missing tiktoken_bg.wasm"?**
93
+
94
+ 确认你装的版本 ≥ `0.1.3`。0.1.0~0.1.2 三个版本里 tiktoken wasm 被错误 inline 进 dist,已在 0.1.3 修复(external + 在 `dependencies` 声明)。