@haikeilabs/agentware 0.1.0 → 0.2.1

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 (63) hide show
  1. package/README.md +19 -0
  2. package/dist/executor/agent_loop.d.ts +50 -0
  3. package/dist/executor/agent_loop.d.ts.map +1 -0
  4. package/dist/executor/agent_loop.js +255 -0
  5. package/dist/executor/executor.d.ts.map +1 -1
  6. package/dist/executor/executor.js +6 -2
  7. package/dist/executor/index.d.ts +2 -1
  8. package/dist/executor/index.d.ts.map +1 -1
  9. package/dist/executor/index.js +2 -1
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +2 -0
  13. package/dist/kei/index.d.ts +2 -0
  14. package/dist/kei/index.d.ts.map +1 -0
  15. package/dist/kei/index.js +1 -0
  16. package/dist/kei/runtimeLink.d.ts +281 -0
  17. package/dist/kei/runtimeLink.d.ts.map +1 -0
  18. package/dist/kei/runtimeLink.js +591 -0
  19. package/dist/llm/backend.d.ts +7 -0
  20. package/dist/llm/backend.d.ts.map +1 -1
  21. package/dist/llm/index.d.ts +2 -1
  22. package/dist/llm/index.d.ts.map +1 -1
  23. package/dist/llm/index.js +1 -0
  24. package/dist/llm/openai_backend.d.ts +51 -0
  25. package/dist/llm/openai_backend.d.ts.map +1 -0
  26. package/dist/llm/openai_backend.js +203 -0
  27. package/dist/llm/response.d.ts +5 -0
  28. package/dist/llm/response.d.ts.map +1 -1
  29. package/dist/middleware/guardrails/response_validator.d.ts +1 -1
  30. package/dist/middleware/guardrails/response_validator.d.ts.map +1 -1
  31. package/dist/middleware/guardrails/response_validator.js +1 -1
  32. package/dist/middleware/index.d.ts +5 -0
  33. package/dist/middleware/index.d.ts.map +1 -1
  34. package/dist/middleware/index.js +5 -0
  35. package/dist/middleware/inference.d.ts +8 -0
  36. package/dist/middleware/inference.d.ts.map +1 -1
  37. package/dist/middleware/inference.js +73 -31
  38. package/dist/reasoning/adapter.d.ts +33 -0
  39. package/dist/reasoning/adapter.d.ts.map +1 -0
  40. package/dist/reasoning/adapter.js +365 -0
  41. package/dist/reasoning/errors.d.ts +28 -0
  42. package/dist/reasoning/errors.d.ts.map +1 -0
  43. package/dist/reasoning/errors.js +57 -0
  44. package/dist/reasoning/index.d.ts +6 -0
  45. package/dist/reasoning/index.d.ts.map +1 -0
  46. package/dist/reasoning/index.js +4 -0
  47. package/dist/reasoning/options.d.ts +18 -0
  48. package/dist/reasoning/options.d.ts.map +1 -0
  49. package/dist/reasoning/options.js +18 -0
  50. package/dist/reasoning/types.d.ts +44 -0
  51. package/dist/reasoning/types.d.ts.map +1 -0
  52. package/dist/reasoning/types.js +32 -0
  53. package/dist/toolformat/formatter.d.ts +3 -3
  54. package/dist/toolformat/formatter.d.ts.map +1 -1
  55. package/dist/tools/index.d.ts +2 -2
  56. package/dist/tools/index.d.ts.map +1 -1
  57. package/dist/tools/index.js +2 -2
  58. package/dist/tools/registry.d.ts +4 -4
  59. package/dist/tools/registry.d.ts.map +1 -1
  60. package/dist/tools/tool.d.ts +8 -1
  61. package/dist/tools/tool.d.ts.map +1 -1
  62. package/dist/tools/tool.js +7 -0
  63. package/package.json +17 -1
@@ -0,0 +1,365 @@
1
+ // Model-agnostic reasoning adapter (mirrors go/reasoning/adapter.go).
2
+ //
3
+ // The adapter recognizes three shapes of model output:
4
+ // - native reasoning_content fields (DeepSeek/Qwen/Kimi/GLM-style JSON)
5
+ // - generic thinking tags (<thinking>...</thinking>, [THINK]...[/THINK])
6
+ // - model-specific reasoning fields (registered per model name)
7
+ //
8
+ // Reasoning is stripped before ordinary tool-call parsing, and the extracted
9
+ // reasoning text is normalized into a versioned context tree. Raw reasoning is
10
+ // never exposed in normal replies or default audits: tree nodes carry only
11
+ // bounded summaries. The adapter fails closed on malformed or unbounded input.
12
+ import { createHash } from "node:crypto";
13
+ import { MalformedContentError, MalformedInputError, MalformedJSONError, MalformedReasoningFieldError, ReasoningError, ReasoningTooLargeError, TooDeepError, TooManyNodesError, UnbalancedThinkingError, } from "./errors.js";
14
+ import { normalizeOptions } from "./options.js";
15
+ import { CONTRACT_VERSION, Format, NodeKind, NodeStatus } from "./types.js";
16
+ export { ReasoningError };
17
+ // Known reasoning field names on a structured response, in priority order.
18
+ // reasoning_content is the de-facto native field (DeepSeek, Qwen/QwQ, Kimi,
19
+ // GLM); the others cover common model-specific names.
20
+ const KNOWN_REASONING_FIELDS = ["reasoning_content", "thinking", "thinking_content", "reasoning"];
21
+ // Keys that make a structured response worth entering the structured path. A
22
+ // mapping without any of these is treated as opaque text and returned
23
+ // unchanged.
24
+ const RECOGNIZED_KEYS = new Set([
25
+ "message",
26
+ "content",
27
+ "reasoning_content",
28
+ "thinking",
29
+ "thinking_content",
30
+ "reasoning",
31
+ ]);
32
+ const THINKING_OPEN = /<thinking>|\[THINK\]/i;
33
+ const THINKING_CLOSE = /<\/thinking>|\[\/THINK\]/i;
34
+ const PARAGRAPH_SEP = /\n[ \t]*\n/;
35
+ const LIST_ORNAMENT = /^\s*(?:[-*+•]|\d+[.)])\s+/;
36
+ const KIND_PREFIX = /^\s*(goal|observation|decision|tool-call|tool_call|tool-result|tool_result|tool|conclusion|blocker)\s*[:=]\s*/i;
37
+ const STATUS_MARKER = /\s*\[(blocked|pending|active|superseded|complete)\]\s*$/i;
38
+ const EVIDENCE_PATTERNS = [
39
+ /\[E\d+\]/g,
40
+ /\bref\s*[=:]\s*(\S+)/g,
41
+ /\bevidence\s*[=:]\s*(\S+)/g,
42
+ ];
43
+ const TOOL_REF = /\b(?:tool|call)\s*[=:]\s*([a-zA-Z_][a-zA-Z0-9_.-]*)/;
44
+ const LEADING_IDENTIFIER = /^([a-zA-Z_][a-zA-Z0-9_.-]*)\s*[:=]/;
45
+ const BARE_IDENTIFIER = /^[a-zA-Z_][a-zA-Z0-9_.-]*$/;
46
+ const KIND_BY_LABEL = {
47
+ goal: NodeKind.GOAL,
48
+ observation: NodeKind.OBSERVATION,
49
+ decision: NodeKind.DECISION,
50
+ "tool-call": NodeKind.TOOL_CALL,
51
+ tool_call: NodeKind.TOOL_CALL,
52
+ tool: NodeKind.TOOL_CALL,
53
+ "tool-result": NodeKind.TOOL_RESULT,
54
+ tool_result: NodeKind.TOOL_RESULT,
55
+ conclusion: NodeKind.CONCLUSION,
56
+ blocker: NodeKind.BLOCKER,
57
+ };
58
+ const STATUS_BY_LABEL = {
59
+ blocked: NodeStatus.BLOCKED,
60
+ pending: NodeStatus.ACTIVE,
61
+ active: NodeStatus.ACTIVE,
62
+ superseded: NodeStatus.SUPERSEDED,
63
+ complete: NodeStatus.COMPLETE,
64
+ };
65
+ function isRecord(v) {
66
+ return typeof v === "object" && v !== null && !Array.isArray(v);
67
+ }
68
+ export class ReasoningAdapter {
69
+ opts;
70
+ modelFields;
71
+ constructor(options) {
72
+ this.opts = normalizeOptions(options);
73
+ this.modelFields = new Map();
74
+ }
75
+ get options() {
76
+ return this.opts;
77
+ }
78
+ /** Map a model name to a model-specific reasoning field name. Fields
79
+ * registered here are consulted before the known field set. */
80
+ registerModelField(model, fieldName) {
81
+ if (model && fieldName) {
82
+ this.modelFields.set(model.toLowerCase(), fieldName);
83
+ }
84
+ }
85
+ /** Remove reasoning from raw and return the clean content that ordinary
86
+ * tool-call parsers should see. Fails closed. */
87
+ strip(raw) {
88
+ return this.analyze(raw, "").clean;
89
+ }
90
+ /** Normalize reasoning found in raw into a versioned context tree. Raw
91
+ * reasoning is never stored on the tree: nodes carry bounded summaries. */
92
+ extract(raw, model = "", backend = "") {
93
+ const analysis = this.analyze(raw, model);
94
+ const now = this.opts.clock();
95
+ const tree = {
96
+ version: CONTRACT_VERSION,
97
+ format: analysis.format,
98
+ model,
99
+ backend,
100
+ created_at: now,
101
+ root_id: "",
102
+ nodes: [],
103
+ };
104
+ if (analysis.reasoning.trim() === "") {
105
+ return tree;
106
+ }
107
+ const nodes = this.parseNodes(analysis.reasoning, now);
108
+ tree.nodes = nodes;
109
+ if (nodes.length > 0) {
110
+ tree.root_id = nodes[0].id;
111
+ }
112
+ return tree;
113
+ }
114
+ /** Strip and extract in one call: return the clean content and tree. */
115
+ parse(raw, model = "", backend = "") {
116
+ const analysis = this.analyze(raw, model);
117
+ return { clean: analysis.clean, tree: this.extract(raw, model, backend) };
118
+ }
119
+ analyze(raw, model) {
120
+ if (typeof raw === "string") {
121
+ return this.analyzeString(raw, model);
122
+ }
123
+ if (raw instanceof Uint8Array) {
124
+ return this.analyzeBytes(raw, model);
125
+ }
126
+ if (isRecord(raw)) {
127
+ return this.analyzeStructured(raw, model);
128
+ }
129
+ throw new MalformedInputError(`unsupported raw type ${typeof raw}`);
130
+ }
131
+ analyzeString(raw, model) {
132
+ const trimmed = raw.trim();
133
+ if (trimmed.startsWith("{")) {
134
+ let parsed;
135
+ try {
136
+ parsed = JSON.parse(trimmed);
137
+ }
138
+ catch (e) {
139
+ throw new MalformedJSONError(e instanceof Error ? e.message : String(e));
140
+ }
141
+ if (isRecord(parsed) && this.hasRecognizedKey(parsed)) {
142
+ return this.analyzeStructured(parsed, model);
143
+ }
144
+ }
145
+ return this.analyzeText(raw);
146
+ }
147
+ analyzeBytes(raw, model) {
148
+ const trimmed = raw.length > 0 ? new TextDecoder().decode(raw).trim() : "";
149
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
150
+ let parsed;
151
+ try {
152
+ parsed = JSON.parse(trimmed);
153
+ }
154
+ catch (e) {
155
+ throw new MalformedJSONError(e instanceof Error ? e.message : String(e));
156
+ }
157
+ if (isRecord(parsed) && this.hasRecognizedKey(parsed)) {
158
+ return this.analyzeStructured(parsed, model);
159
+ }
160
+ }
161
+ return this.analyzeText(trimmed);
162
+ }
163
+ analyzeStructured(m, model) {
164
+ const message = m["message"];
165
+ if (isRecord(message)) {
166
+ return this.analyzeStructured(message, model);
167
+ }
168
+ let content = "";
169
+ if ("content" in m) {
170
+ const value = m["content"];
171
+ if (value === null || value === undefined) {
172
+ content = "";
173
+ }
174
+ else if (typeof value === "string") {
175
+ content = value;
176
+ }
177
+ else {
178
+ throw new MalformedContentError(`content field is ${typeof value}, not a string`);
179
+ }
180
+ }
181
+ const [reasoning, format] = this.extractReasoningField(m, model);
182
+ if (reasoning !== "") {
183
+ return { reasoning, clean: splitThinkingTags(content).clean, format };
184
+ }
185
+ const result = splitThinkingTags(content);
186
+ if (result.reasoning !== "") {
187
+ return { reasoning: result.reasoning, clean: result.clean, format: Format.THINKING };
188
+ }
189
+ return { reasoning: "", clean: content, format: Format.NONE };
190
+ }
191
+ extractReasoningField(m, model) {
192
+ if (model) {
193
+ const fieldName = this.modelFields.get(model.toLowerCase());
194
+ if (fieldName) {
195
+ const value = m[fieldName];
196
+ if (value !== null && value !== undefined) {
197
+ if (typeof value !== "string") {
198
+ throw new MalformedReasoningFieldError(`field "${fieldName}" is ${typeof value}, not a string`);
199
+ }
200
+ if (value !== "") {
201
+ return [value, Format.MODEL_SPECIFIC];
202
+ }
203
+ }
204
+ }
205
+ }
206
+ for (const fieldName of KNOWN_REASONING_FIELDS) {
207
+ const value = m[fieldName];
208
+ if (value === null || value === undefined) {
209
+ continue;
210
+ }
211
+ if (typeof value !== "string") {
212
+ throw new MalformedReasoningFieldError(`field "${fieldName}" is ${typeof value}, not a string`);
213
+ }
214
+ if (value !== "") {
215
+ return [value, Format.NATIVE];
216
+ }
217
+ }
218
+ return ["", Format.NONE];
219
+ }
220
+ analyzeText(raw) {
221
+ const result = splitThinkingTags(raw);
222
+ if (result.reasoning !== "") {
223
+ return { reasoning: result.reasoning, clean: result.clean, format: Format.THINKING };
224
+ }
225
+ return { reasoning: "", clean: raw, format: Format.NONE };
226
+ }
227
+ hasRecognizedKey(m) {
228
+ return Object.keys(m).some((k) => RECOGNIZED_KEYS.has(k));
229
+ }
230
+ parseNodes(reasoning, now) {
231
+ if (Buffer.byteLength(reasoning, "utf8") > this.opts.max_reasoning_bytes) {
232
+ throw new ReasoningTooLargeError();
233
+ }
234
+ const paragraphs = splitParagraphs(reasoning);
235
+ if (paragraphs.length > this.opts.max_nodes) {
236
+ throw new TooManyNodesError();
237
+ }
238
+ const nodes = [];
239
+ let parentId = "";
240
+ let depth = 0;
241
+ for (const para of paragraphs) {
242
+ depth += 1;
243
+ if (depth > this.opts.max_depth) {
244
+ throw new TooDeepError();
245
+ }
246
+ let kind = NodeKind.OBSERVATION;
247
+ let summary = para.replace(LIST_ORNAMENT, "");
248
+ const kindMatch = KIND_PREFIX.exec(summary);
249
+ if (kindMatch) {
250
+ kind = KIND_BY_LABEL[kindMatch[1].toLowerCase()] ?? NodeKind.OBSERVATION;
251
+ summary = summary.slice(kindMatch[0].length).trim();
252
+ }
253
+ let status = NodeStatus.COMPLETE;
254
+ const statusMatch = STATUS_MARKER.exec(summary);
255
+ if (statusMatch) {
256
+ status = STATUS_BY_LABEL[statusMatch[1].toLowerCase()] ?? NodeStatus.COMPLETE;
257
+ summary = summary.slice(0, statusMatch.index).trim();
258
+ }
259
+ else if (kind === NodeKind.BLOCKER) {
260
+ status = NodeStatus.BLOCKED;
261
+ }
262
+ summary = truncateCodePoints(summary, this.opts.max_summary_chars);
263
+ if (summary === "") {
264
+ depth -= 1;
265
+ continue;
266
+ }
267
+ const id = nodeId(kind, parentId, summary);
268
+ nodes.push({
269
+ id,
270
+ parent_id: parentId,
271
+ kind,
272
+ status,
273
+ summary,
274
+ evidence_refs: extractEvidence(summary),
275
+ tool_call_refs: extractToolRefs(kind, summary),
276
+ created_at: now,
277
+ updated_at: now,
278
+ });
279
+ parentId = id;
280
+ }
281
+ return nodes;
282
+ }
283
+ }
284
+ function splitThinkingTags(text) {
285
+ if (!THINKING_OPEN.test(text) && !THINKING_CLOSE.test(text)) {
286
+ return { clean: text, reasoning: "" };
287
+ }
288
+ const parts = [];
289
+ const reasons = [];
290
+ let rest = text;
291
+ for (;;) {
292
+ const open = THINKING_OPEN.exec(rest);
293
+ if (open === null) {
294
+ if (THINKING_CLOSE.test(rest)) {
295
+ throw new UnbalancedThinkingError();
296
+ }
297
+ parts.push(rest);
298
+ break;
299
+ }
300
+ parts.push(rest.slice(0, open.index));
301
+ const inner = rest.slice(open.index + open[0].length);
302
+ const close = THINKING_CLOSE.exec(inner);
303
+ if (close === null) {
304
+ throw new UnbalancedThinkingError();
305
+ }
306
+ reasons.push(inner.slice(0, close.index));
307
+ rest = inner.slice(close.index + close[0].length);
308
+ }
309
+ return { clean: parts.join(""), reasoning: reasons.join("\n").trim() };
310
+ }
311
+ function splitParagraphs(text) {
312
+ return text
313
+ .split(PARAGRAPH_SEP)
314
+ .map((p) => p.trim())
315
+ .filter((p) => p !== "");
316
+ }
317
+ function extractEvidence(summary) {
318
+ const out = [];
319
+ const seen = new Set();
320
+ for (const pattern of EVIDENCE_PATTERNS) {
321
+ pattern.lastIndex = 0;
322
+ let match;
323
+ while ((match = pattern.exec(summary)) !== null) {
324
+ const ref = (match[1] ?? match[0]).replace(/^\[|\]$/g, "");
325
+ if (ref !== "" && !seen.has(ref)) {
326
+ seen.add(ref);
327
+ out.push(ref);
328
+ }
329
+ }
330
+ }
331
+ return out;
332
+ }
333
+ function extractToolRefs(kind, summary) {
334
+ if (kind !== NodeKind.TOOL_CALL && kind !== NodeKind.TOOL_RESULT) {
335
+ return [];
336
+ }
337
+ const leading = LEADING_IDENTIFIER.exec(summary);
338
+ if (leading) {
339
+ return [leading[1]];
340
+ }
341
+ const ref = TOOL_REF.exec(summary);
342
+ if (ref) {
343
+ return [ref[1]];
344
+ }
345
+ if (BARE_IDENTIFIER.test(summary)) {
346
+ return [summary];
347
+ }
348
+ return [];
349
+ }
350
+ function truncateCodePoints(s, n) {
351
+ if (n <= 0) {
352
+ return "";
353
+ }
354
+ const points = Array.from(s);
355
+ if (points.length <= n) {
356
+ return s;
357
+ }
358
+ return points.slice(0, n).join("");
359
+ }
360
+ function nodeId(kind, parentId, summary) {
361
+ return createHash("sha256")
362
+ .update(`${kind}\0${parentId}\0${summary}`)
363
+ .digest("hex")
364
+ .slice(0, 16);
365
+ }
@@ -0,0 +1,28 @@
1
+ export declare class ReasoningError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class MalformedInputError extends ReasoningError {
5
+ constructor(message: string);
6
+ }
7
+ export declare class MalformedJSONError extends ReasoningError {
8
+ constructor(message: string);
9
+ }
10
+ export declare class MalformedReasoningFieldError extends ReasoningError {
11
+ constructor(message: string);
12
+ }
13
+ export declare class MalformedContentError extends ReasoningError {
14
+ constructor(message: string);
15
+ }
16
+ export declare class UnbalancedThinkingError extends ReasoningError {
17
+ constructor(message?: string);
18
+ }
19
+ export declare class ReasoningTooLargeError extends ReasoningError {
20
+ constructor(message?: string);
21
+ }
22
+ export declare class TooManyNodesError extends ReasoningError {
23
+ constructor(message?: string);
24
+ }
25
+ export declare class TooDeepError extends ReasoningError {
26
+ constructor(message?: string);
27
+ }
28
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/reasoning/errors.ts"],"names":[],"mappings":"AAIA,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,4BAA6B,SAAQ,cAAc;gBAClD,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,qBAAsB,SAAQ,cAAc;gBAC3C,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,uBAAwB,SAAQ,cAAc;gBAC7C,OAAO,SAAuC;CAI3D;AAED,qBAAa,sBAAuB,SAAQ,cAAc;gBAC5C,OAAO,SAA8C;CAIlE;AAED,qBAAa,iBAAkB,SAAQ,cAAc;gBACvC,OAAO,SAAwC;CAI5D;AAED,qBAAa,YAAa,SAAQ,cAAc;gBAClC,OAAO,SAAuC;CAI3D"}
@@ -0,0 +1,57 @@
1
+ // Fail-closed errors raised by the reasoning adapter.
2
+ // Every error represents a fail-closed outcome: malformed or unbounded input
3
+ // never produces a partial tree or partially-stripped content.
4
+ export class ReasoningError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "ReasoningError";
8
+ }
9
+ }
10
+ export class MalformedInputError extends ReasoningError {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = "MalformedInputError";
14
+ }
15
+ }
16
+ export class MalformedJSONError extends ReasoningError {
17
+ constructor(message) {
18
+ super(message);
19
+ this.name = "MalformedJSONError";
20
+ }
21
+ }
22
+ export class MalformedReasoningFieldError extends ReasoningError {
23
+ constructor(message) {
24
+ super(message);
25
+ this.name = "MalformedReasoningFieldError";
26
+ }
27
+ }
28
+ export class MalformedContentError extends ReasoningError {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = "MalformedContentError";
32
+ }
33
+ }
34
+ export class UnbalancedThinkingError extends ReasoningError {
35
+ constructor(message = "reasoning: unbalanced thinking tag") {
36
+ super(message);
37
+ this.name = "UnbalancedThinkingError";
38
+ }
39
+ }
40
+ export class ReasoningTooLargeError extends ReasoningError {
41
+ constructor(message = "reasoning: reasoning exceeds maximum size") {
42
+ super(message);
43
+ this.name = "ReasoningTooLargeError";
44
+ }
45
+ }
46
+ export class TooManyNodesError extends ReasoningError {
47
+ constructor(message = "reasoning: too many reasoning nodes") {
48
+ super(message);
49
+ this.name = "TooManyNodesError";
50
+ }
51
+ }
52
+ export class TooDeepError extends ReasoningError {
53
+ constructor(message = "reasoning: reasoning tree too deep") {
54
+ super(message);
55
+ this.name = "TooDeepError";
56
+ }
57
+ }
@@ -0,0 +1,6 @@
1
+ export { ReasoningAdapter, ReasoningError } from "./adapter.js";
2
+ export { MalformedContentError, MalformedInputError, MalformedJSONError, MalformedReasoningFieldError, ReasoningTooLargeError, TooDeepError, TooManyNodesError, UnbalancedThinkingError, } from "./errors.js";
3
+ export { ReasoningOptions, normalizeOptions } from "./options.js";
4
+ export { CONTRACT_VERSION, Format, NodeKind, NodeStatus, isContextTreeEmpty, } from "./types.js";
5
+ export type { Node, ContextTree } from "./types.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reasoning/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,4BAA4B,EAC5B,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EACL,gBAAgB,EAChB,MAAM,EACN,QAAQ,EACR,UAAU,EACV,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { ReasoningAdapter, ReasoningError } from "./adapter.js";
2
+ export { MalformedContentError, MalformedInputError, MalformedJSONError, MalformedReasoningFieldError, ReasoningTooLargeError, TooDeepError, TooManyNodesError, UnbalancedThinkingError, } from "./errors.js";
3
+ export { normalizeOptions } from "./options.js";
4
+ export { CONTRACT_VERSION, Format, NodeKind, NodeStatus, isContextTreeEmpty, } from "./types.js";
@@ -0,0 +1,18 @@
1
+ export interface ReasoningOptions {
2
+ /** Cap on the size of the extracted reasoning text, in bytes. */
3
+ max_reasoning_bytes?: number;
4
+ /** Cap on the number of nodes a single tree may contain. */
5
+ max_nodes?: number;
6
+ /** Cap on the depth of the node chain. */
7
+ max_depth?: number;
8
+ /** Cap on the length of every node summary, in code points. */
9
+ max_summary_chars?: number;
10
+ /** Clock supplying timestamps for tree and nodes. Defaults to Date.now. */
11
+ clock?: () => Date;
12
+ }
13
+ export declare const DEFAULT_MAX_REASONING_BYTES: number;
14
+ export declare const DEFAULT_MAX_NODES = 64;
15
+ export declare const DEFAULT_MAX_DEPTH = 32;
16
+ export declare const DEFAULT_MAX_SUMMARY_CHARS = 512;
17
+ export declare function normalizeOptions(opts?: ReasoningOptions): Required<ReasoningOptions>;
18
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/reasoning/options.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,gBAAgB;IAC/B,iEAAiE;IACjE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,2BAA2B,QAAY,CAAC;AACrD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAQpF"}
@@ -0,0 +1,18 @@
1
+ // Bounds for the reasoning adapter (mirrors go/reasoning/options.go).
2
+ //
3
+ // All limits fail closed: an input that exceeds a bound raises an error rather
4
+ // than being truncated into a partial tree (summaries are the one bounded
5
+ // field by design; they are truncated, never the parse aborted).
6
+ export const DEFAULT_MAX_REASONING_BYTES = 64 * 1024;
7
+ export const DEFAULT_MAX_NODES = 64;
8
+ export const DEFAULT_MAX_DEPTH = 32;
9
+ export const DEFAULT_MAX_SUMMARY_CHARS = 512;
10
+ export function normalizeOptions(opts) {
11
+ return {
12
+ max_reasoning_bytes: opts?.max_reasoning_bytes ?? DEFAULT_MAX_REASONING_BYTES,
13
+ max_nodes: opts?.max_nodes ?? DEFAULT_MAX_NODES,
14
+ max_depth: opts?.max_depth ?? DEFAULT_MAX_DEPTH,
15
+ max_summary_chars: opts?.max_summary_chars ?? DEFAULT_MAX_SUMMARY_CHARS,
16
+ clock: opts?.clock ?? (() => new Date()),
17
+ };
18
+ }
@@ -0,0 +1,44 @@
1
+ export declare const CONTRACT_VERSION = "1";
2
+ export declare enum Format {
3
+ NATIVE = "native",
4
+ THINKING = "thinking",
5
+ MODEL_SPECIFIC = "model_specific",
6
+ NONE = "none"
7
+ }
8
+ export declare enum NodeKind {
9
+ GOAL = "goal",
10
+ OBSERVATION = "observation",
11
+ DECISION = "decision",
12
+ TOOL_CALL = "tool-call",
13
+ TOOL_RESULT = "tool-result",
14
+ CONCLUSION = "conclusion",
15
+ BLOCKER = "blocker"
16
+ }
17
+ export declare enum NodeStatus {
18
+ ACTIVE = "active",
19
+ COMPLETE = "complete",
20
+ BLOCKED = "blocked",
21
+ SUPERSEDED = "superseded"
22
+ }
23
+ export interface Node {
24
+ id: string;
25
+ parent_id: string;
26
+ kind: NodeKind;
27
+ status: NodeStatus;
28
+ summary: string;
29
+ evidence_refs: string[];
30
+ tool_call_refs: string[];
31
+ created_at: Date;
32
+ updated_at: Date;
33
+ }
34
+ export interface ContextTree {
35
+ version: string;
36
+ format: Format;
37
+ model: string;
38
+ backend: string;
39
+ created_at: Date;
40
+ root_id: string;
41
+ nodes: Node[];
42
+ }
43
+ export declare function isContextTreeEmpty(tree: ContextTree | null | undefined): boolean;
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/reasoning/types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,oBAAY,MAAM;IAChB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,cAAc,mBAAmB;IACjC,IAAI,SAAS;CACd;AAGD,oBAAY,QAAQ;IAClB,IAAI,SAAS;IACb,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;IACzB,OAAO,YAAY;CACpB;AAGD,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAID,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB;AAKD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,IAAI,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAEhF"}
@@ -0,0 +1,32 @@
1
+ // Versioned context-tree contract for normalized reasoning.
2
+ // Mirrors go/reasoning/types.go and python/src/pedro_agentware/reasoning/types.py.
3
+ export const CONTRACT_VERSION = "1";
4
+ export var Format;
5
+ (function (Format) {
6
+ Format["NATIVE"] = "native";
7
+ Format["THINKING"] = "thinking";
8
+ Format["MODEL_SPECIFIC"] = "model_specific";
9
+ Format["NONE"] = "none";
10
+ })(Format || (Format = {}));
11
+ // NodeKind is the closed vocabulary of context-tree node kinds.
12
+ export var NodeKind;
13
+ (function (NodeKind) {
14
+ NodeKind["GOAL"] = "goal";
15
+ NodeKind["OBSERVATION"] = "observation";
16
+ NodeKind["DECISION"] = "decision";
17
+ NodeKind["TOOL_CALL"] = "tool-call";
18
+ NodeKind["TOOL_RESULT"] = "tool-result";
19
+ NodeKind["CONCLUSION"] = "conclusion";
20
+ NodeKind["BLOCKER"] = "blocker";
21
+ })(NodeKind || (NodeKind = {}));
22
+ // NodeStatus is the closed vocabulary of context-tree node statuses.
23
+ export var NodeStatus;
24
+ (function (NodeStatus) {
25
+ NodeStatus["ACTIVE"] = "active";
26
+ NodeStatus["COMPLETE"] = "complete";
27
+ NodeStatus["BLOCKED"] = "blocked";
28
+ NodeStatus["SUPERSEDED"] = "superseded";
29
+ })(NodeStatus || (NodeStatus = {}));
30
+ export function isContextTreeEmpty(tree) {
31
+ return !tree || tree.nodes.length === 0;
32
+ }
@@ -1,4 +1,4 @@
1
- import type { Tool, Result } from "../tools/index.js";
1
+ import type { AnyTool, Result } from "../tools/index.js";
2
2
  export interface ParsedToolCall {
3
3
  id: string;
4
4
  name: string;
@@ -6,13 +6,13 @@ export interface ParsedToolCall {
6
6
  raw: string;
7
7
  }
8
8
  export interface ToolFormatter {
9
- formatToolDefinitions(tools: Tool[]): string;
9
+ formatToolDefinitions(tools: AnyTool[]): string;
10
10
  parseToolCalls(response: string): ParsedToolCall[];
11
11
  formatToolResult(name: string, result: Result): string;
12
12
  modelFamily(): string;
13
13
  }
14
14
  export declare class GenericFormatter implements ToolFormatter {
15
- formatToolDefinitions(tools: Tool[]): string;
15
+ formatToolDefinitions(tools: AnyTool[]): string;
16
16
  parseToolCalls(_response: string): ParsedToolCall[];
17
17
  formatToolResult(name: string, result: Result): string;
18
18
  modelFamily(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/toolformat/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAC7C,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAAC;IACnD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACvD,WAAW,IAAI,MAAM,CAAC;CACvB;AAED,qBAAa,gBAAiB,YAAW,aAAa;IACpD,qBAAqB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM;IAU5C,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,EAAE;IAInD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAMtD,WAAW,IAAI,MAAM;CAGtB"}
1
+ {"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../src/toolformat/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAChD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAAC;IACnD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACvD,WAAW,IAAI,MAAM,CAAC;CACvB;AAED,qBAAa,gBAAiB,YAAW,aAAa;IACpD,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM;IAU/C,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,EAAE;IAInD,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAMtD,WAAW,IAAI,MAAM;CAGtB"}
@@ -1,5 +1,5 @@
1
- export { Tool, BaseTool, Result, ToolExample } from "./tool.js";
1
+ export { Tool, ToolBase, AsyncTool, AnyTool, BaseTool, Result, ToolExample, executeTool, } from "./tool.js";
2
2
  export { ToolRegistry } from "./registry.js";
3
- export { wrapTool, ToolAbortedError, ToolTimeoutError, } from "./async.js";
3
+ export { wrapTool, ToolAbortedError, ToolTimeoutError } from "./async.js";
4
4
  export type { AsyncToolHandler, ToolInvocationOptions, ToolLifecycleEvent, ToolLifecycleHook, WrapToolOptions, WrappedTool, } from "./async.js";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,MAAM,EACN,WAAW,EACX,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC1E,YAAY,EACV,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC"}
@@ -1,3 +1,3 @@
1
- export { BaseTool, Result } from "./tool.js";
1
+ export { BaseTool, Result, executeTool, } from "./tool.js";
2
2
  export { ToolRegistry } from "./registry.js";
3
- export { wrapTool, ToolAbortedError, ToolTimeoutError, } from "./async.js";
3
+ export { wrapTool, ToolAbortedError, ToolTimeoutError } from "./async.js";
@@ -1,9 +1,9 @@
1
- import type { Tool } from "./tool.js";
1
+ import type { AnyTool } from "./tool.js";
2
2
  export declare class ToolRegistry {
3
3
  private tools;
4
- register(tool: Tool): void;
5
- get(name: string): Tool | undefined;
6
- all(): Tool[];
4
+ register(tool: AnyTool): void;
5
+ get(name: string): AnyTool | undefined;
6
+ all(): AnyTool[];
7
7
  names(): string[];
8
8
  schemas(): Record<string, Record<string, unknown>>;
9
9
  clear(): void;