llm-kb 0.4.0 → 0.4.2

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 (58) hide show
  1. package/README.md +183 -42
  2. package/bin/anthropic-5TIU2EED.js +5515 -0
  3. package/bin/azure-openai-responses-ZVUVMK3G.js +190 -0
  4. package/bin/chunk-2WV6TQRI.js +4792 -0
  5. package/bin/chunk-3YMNGUZZ.js +262 -0
  6. package/bin/chunk-5PYKQQLA.js +14295 -0
  7. package/bin/chunk-65KFH7OI.js +31 -0
  8. package/bin/chunk-DHOXVEIR.js +7261 -0
  9. package/bin/chunk-EAQYK3U2.js +41 -0
  10. package/bin/chunk-IFS3OKBN.js +428 -0
  11. package/bin/chunk-LDHOKBJA.js +86 -0
  12. package/bin/chunk-SLYBG6ZQ.js +32681 -0
  13. package/bin/chunk-UEODFF7H.js +17 -0
  14. package/bin/chunk-XCXTZJGO.js +174 -0
  15. package/bin/chunk-XFV534WU.js +7056 -0
  16. package/bin/cli.js +30 -4
  17. package/bin/dist-3YH7P2QF.js +1244 -0
  18. package/bin/google-JFC43EFJ.js +371 -0
  19. package/bin/google-gemini-cli-K4XNMYDI.js +712 -0
  20. package/bin/google-vertex-Y42F254G.js +414 -0
  21. package/bin/indexer-KSYRIVVN.js +10 -0
  22. package/bin/mistral-ZU2JS5XZ.js +38406 -0
  23. package/bin/multipart-parser-CO464TZY.js +371 -0
  24. package/bin/openai-codex-responses-NW2LELBH.js +712 -0
  25. package/bin/openai-completions-TW3VKTHO.js +662 -0
  26. package/bin/openai-responses-VGL522MK.js +198 -0
  27. package/bin/src-Y22OHE3S.js +1408 -0
  28. package/package.json +6 -1
  29. package/PHASE2_SPEC.md +0 -274
  30. package/PHASE3_SPEC.md +0 -245
  31. package/PHASE4_SPEC.md +0 -358
  32. package/SPEC.md +0 -275
  33. package/plan.md +0 -300
  34. package/src/auth.ts +0 -55
  35. package/src/cli.ts +0 -257
  36. package/src/config.ts +0 -61
  37. package/src/eval.ts +0 -548
  38. package/src/indexer.ts +0 -152
  39. package/src/md-stream.ts +0 -133
  40. package/src/pdf.ts +0 -119
  41. package/src/query.ts +0 -408
  42. package/src/resolve-kb.ts +0 -19
  43. package/src/scan.ts +0 -59
  44. package/src/session-store.ts +0 -22
  45. package/src/session-watcher.ts +0 -89
  46. package/src/trace-builder.ts +0 -168
  47. package/src/tui-display.ts +0 -281
  48. package/src/utils.ts +0 -17
  49. package/src/watcher.ts +0 -87
  50. package/src/wiki-updater.ts +0 -136
  51. package/test/auth.test.ts +0 -65
  52. package/test/config.test.ts +0 -96
  53. package/test/md-stream.test.ts +0 -98
  54. package/test/resolve-kb.test.ts +0 -33
  55. package/test/scan.test.ts +0 -65
  56. package/test/trace-builder.test.ts +0 -215
  57. package/tsconfig.json +0 -14
  58. package/vitest.config.ts +0 -8
@@ -0,0 +1,17 @@
1
+ // node_modules/@mariozechner/pi-ai/dist/utils/hash.js
2
+ function shortHash(str) {
3
+ let h1 = 3735928559;
4
+ let h2 = 1103547991;
5
+ for (let i = 0; i < str.length; i++) {
6
+ const ch = str.charCodeAt(i);
7
+ h1 = Math.imul(h1 ^ ch, 2654435761);
8
+ h2 = Math.imul(h2 ^ ch, 1597334677);
9
+ }
10
+ h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
11
+ h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
12
+ return (h2 >>> 0).toString(36) + (h1 >>> 0).toString(36);
13
+ }
14
+
15
+ export {
16
+ shortHash
17
+ };
@@ -0,0 +1,174 @@
1
+ // node_modules/@mariozechner/pi-ai/dist/utils/sanitize-unicode.js
2
+ function sanitizeSurrogates(text) {
3
+ return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, "");
4
+ }
5
+
6
+ // node_modules/@mariozechner/pi-ai/dist/providers/simple-options.js
7
+ function buildBaseOptions(model, options, apiKey) {
8
+ return {
9
+ temperature: options?.temperature,
10
+ maxTokens: options?.maxTokens || Math.min(model.maxTokens, 32e3),
11
+ signal: options?.signal,
12
+ apiKey: apiKey || options?.apiKey,
13
+ cacheRetention: options?.cacheRetention,
14
+ sessionId: options?.sessionId,
15
+ headers: options?.headers,
16
+ onPayload: options?.onPayload,
17
+ maxRetryDelayMs: options?.maxRetryDelayMs,
18
+ metadata: options?.metadata
19
+ };
20
+ }
21
+ function clampReasoning(effort) {
22
+ return effort === "xhigh" ? "high" : effort;
23
+ }
24
+ function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
25
+ const defaultBudgets = {
26
+ minimal: 1024,
27
+ low: 2048,
28
+ medium: 8192,
29
+ high: 16384
30
+ };
31
+ const budgets = { ...defaultBudgets, ...customBudgets };
32
+ const minOutputTokens = 1024;
33
+ const level = clampReasoning(reasoningLevel);
34
+ let thinkingBudget = budgets[level];
35
+ const maxTokens = Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
36
+ if (maxTokens <= thinkingBudget) {
37
+ thinkingBudget = Math.max(0, maxTokens - minOutputTokens);
38
+ }
39
+ return { maxTokens, thinkingBudget };
40
+ }
41
+
42
+ // node_modules/@mariozechner/pi-ai/dist/providers/transform-messages.js
43
+ function transformMessages(messages, model, normalizeToolCallId) {
44
+ const toolCallIdMap = /* @__PURE__ */ new Map();
45
+ const transformed = messages.map((msg) => {
46
+ if (msg.role === "user") {
47
+ return msg;
48
+ }
49
+ if (msg.role === "toolResult") {
50
+ const normalizedId = toolCallIdMap.get(msg.toolCallId);
51
+ if (normalizedId && normalizedId !== msg.toolCallId) {
52
+ return { ...msg, toolCallId: normalizedId };
53
+ }
54
+ return msg;
55
+ }
56
+ if (msg.role === "assistant") {
57
+ const assistantMsg = msg;
58
+ const isSameModel = assistantMsg.provider === model.provider && assistantMsg.api === model.api && assistantMsg.model === model.id;
59
+ const transformedContent = assistantMsg.content.flatMap((block) => {
60
+ if (block.type === "thinking") {
61
+ if (block.redacted) {
62
+ return isSameModel ? block : [];
63
+ }
64
+ if (isSameModel && block.thinkingSignature)
65
+ return block;
66
+ if (!block.thinking || block.thinking.trim() === "")
67
+ return [];
68
+ if (isSameModel)
69
+ return block;
70
+ return {
71
+ type: "text",
72
+ text: block.thinking
73
+ };
74
+ }
75
+ if (block.type === "text") {
76
+ if (isSameModel)
77
+ return block;
78
+ return {
79
+ type: "text",
80
+ text: block.text
81
+ };
82
+ }
83
+ if (block.type === "toolCall") {
84
+ const toolCall = block;
85
+ let normalizedToolCall = toolCall;
86
+ if (!isSameModel && toolCall.thoughtSignature) {
87
+ normalizedToolCall = { ...toolCall };
88
+ delete normalizedToolCall.thoughtSignature;
89
+ }
90
+ if (!isSameModel && normalizeToolCallId) {
91
+ const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
92
+ if (normalizedId !== toolCall.id) {
93
+ toolCallIdMap.set(toolCall.id, normalizedId);
94
+ normalizedToolCall = { ...normalizedToolCall, id: normalizedId };
95
+ }
96
+ }
97
+ return normalizedToolCall;
98
+ }
99
+ return block;
100
+ });
101
+ return {
102
+ ...assistantMsg,
103
+ content: transformedContent
104
+ };
105
+ }
106
+ return msg;
107
+ });
108
+ const result = [];
109
+ let pendingToolCalls = [];
110
+ let existingToolResultIds = /* @__PURE__ */ new Set();
111
+ for (let i = 0; i < transformed.length; i++) {
112
+ const msg = transformed[i];
113
+ if (msg.role === "assistant") {
114
+ if (pendingToolCalls.length > 0) {
115
+ for (const tc of pendingToolCalls) {
116
+ if (!existingToolResultIds.has(tc.id)) {
117
+ result.push({
118
+ role: "toolResult",
119
+ toolCallId: tc.id,
120
+ toolName: tc.name,
121
+ content: [{ type: "text", text: "No result provided" }],
122
+ isError: true,
123
+ timestamp: Date.now()
124
+ });
125
+ }
126
+ }
127
+ pendingToolCalls = [];
128
+ existingToolResultIds = /* @__PURE__ */ new Set();
129
+ }
130
+ const assistantMsg = msg;
131
+ if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") {
132
+ continue;
133
+ }
134
+ const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
135
+ if (toolCalls.length > 0) {
136
+ pendingToolCalls = toolCalls;
137
+ existingToolResultIds = /* @__PURE__ */ new Set();
138
+ }
139
+ result.push(msg);
140
+ } else if (msg.role === "toolResult") {
141
+ existingToolResultIds.add(msg.toolCallId);
142
+ result.push(msg);
143
+ } else if (msg.role === "user") {
144
+ if (pendingToolCalls.length > 0) {
145
+ for (const tc of pendingToolCalls) {
146
+ if (!existingToolResultIds.has(tc.id)) {
147
+ result.push({
148
+ role: "toolResult",
149
+ toolCallId: tc.id,
150
+ toolName: tc.name,
151
+ content: [{ type: "text", text: "No result provided" }],
152
+ isError: true,
153
+ timestamp: Date.now()
154
+ });
155
+ }
156
+ }
157
+ pendingToolCalls = [];
158
+ existingToolResultIds = /* @__PURE__ */ new Set();
159
+ }
160
+ result.push(msg);
161
+ } else {
162
+ result.push(msg);
163
+ }
164
+ }
165
+ return result;
166
+ }
167
+
168
+ export {
169
+ sanitizeSurrogates,
170
+ buildBaseOptions,
171
+ clampReasoning,
172
+ adjustMaxTokensForThinking,
173
+ transformMessages
174
+ };