@lamplitisles/dsh-nanocodex 0.1.0-beta.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 (276) hide show
  1. package/LICENSE +65 -0
  2. package/NOTICE +2 -0
  3. package/README.md +182 -0
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/cordis.patch.yml +52 -0
  6. package/dist/index.d.ts +435 -0
  7. package/dist/index.js +3405 -0
  8. package/dist/standard-preset.d.ts +7 -0
  9. package/dist/standard-preset.js +25 -0
  10. package/engine-release.json +14 -0
  11. package/package.json +119 -0
  12. package/presets/standard/agent.cordis.yml +6 -0
  13. package/presets/standard/preset.yml +2 -0
  14. package/vendor/nanocodex/README.md +1344 -0
  15. package/vendor/nanocodex/actions/events.d.mts +10 -0
  16. package/vendor/nanocodex/actions/events.mjs +163 -0
  17. package/vendor/nanocodex/actions/index.d.mts +13 -0
  18. package/vendor/nanocodex/actions/index.mjs +35 -0
  19. package/vendor/nanocodex/actions/session.d.mts +66 -0
  20. package/vendor/nanocodex/actions/session.mjs +59 -0
  21. package/vendor/nanocodex/actions/turn.d.mts +59 -0
  22. package/vendor/nanocodex/actions/turn.mjs +37 -0
  23. package/vendor/nanocodex/actions/voice.d.mts +22 -0
  24. package/vendor/nanocodex/actions/voice.mjs +50 -0
  25. package/vendor/nanocodex/browser/Agent.d.mts +55 -0
  26. package/vendor/nanocodex/browser/Agent.mjs +11 -0
  27. package/vendor/nanocodex/browser/ChatGptSubscription.d.mts +7 -0
  28. package/vendor/nanocodex/browser/ChatGptSubscription.mjs +19 -0
  29. package/vendor/nanocodex/browser/InlineAgent.mjs +266 -0
  30. package/vendor/nanocodex/browser/Transport.d.mts +74 -0
  31. package/vendor/nanocodex/browser/Transport.mjs +61 -0
  32. package/vendor/nanocodex/browser/Voice.d.mts +71 -0
  33. package/vendor/nanocodex/browser/Voice.mjs +291 -0
  34. package/vendor/nanocodex/browser/VoiceSession.mjs +688 -0
  35. package/vendor/nanocodex/browser/WorkerAgent.d.mts +65 -0
  36. package/vendor/nanocodex/browser/WorkerAgent.mjs +1472 -0
  37. package/vendor/nanocodex/browser/agent.worker.mjs +3 -0
  38. package/vendor/nanocodex/browser/config.d.mts +36 -0
  39. package/vendor/nanocodex/browser/config.mjs +439 -0
  40. package/vendor/nanocodex/browser/engine.mjs +13 -0
  41. package/vendor/nanocodex/browser/harness.mjs +55 -0
  42. package/vendor/nanocodex/browser/host.d.mts +83 -0
  43. package/vendor/nanocodex/browser/host.mjs +555 -0
  44. package/vendor/nanocodex/browser/hostManagedWebSocket.d.mts +14 -0
  45. package/vendor/nanocodex/browser/hostManagedWebSocket.mjs +110 -0
  46. package/vendor/nanocodex/browser/index.d.mts +92 -0
  47. package/vendor/nanocodex/browser/index.mjs +23 -0
  48. package/vendor/nanocodex/browser/indexeddb-durability-store.mjs +197 -0
  49. package/vendor/nanocodex/browser/workspace.d.mts +16 -0
  50. package/vendor/nanocodex/browser/workspace.mjs +107 -0
  51. package/vendor/nanocodex/cloud/Client.d.mts +83 -0
  52. package/vendor/nanocodex/cloud/Client.mjs +231 -0
  53. package/vendor/nanocodex/cloud/Decorator.d.mts +31 -0
  54. package/vendor/nanocodex/cloud/Decorator.mjs +37 -0
  55. package/vendor/nanocodex/cloud/Dialog.d.mts +113 -0
  56. package/vendor/nanocodex/cloud/Dialog.mjs +366 -0
  57. package/vendor/nanocodex/cloud/Errors.d.mts +22 -0
  58. package/vendor/nanocodex/cloud/Errors.mjs +39 -0
  59. package/vendor/nanocodex/cloud/Principal.d.mts +26 -0
  60. package/vendor/nanocodex/cloud/Principal.mjs +88 -0
  61. package/vendor/nanocodex/cloud/RemoteProvider.mjs +88 -0
  62. package/vendor/nanocodex/cloud/Transport.d.mts +47 -0
  63. package/vendor/nanocodex/cloud/Transport.mjs +454 -0
  64. package/vendor/nanocodex/cloud/actions/account.d.mts +9 -0
  65. package/vendor/nanocodex/cloud/actions/account.mjs +19 -0
  66. package/vendor/nanocodex/cloud/actions/agent.d.mts +18 -0
  67. package/vendor/nanocodex/cloud/actions/agent.mjs +428 -0
  68. package/vendor/nanocodex/cloud/actions/connection.d.mts +133 -0
  69. package/vendor/nanocodex/cloud/actions/connection.mjs +580 -0
  70. package/vendor/nanocodex/cloud/actions/grant.d.mts +10 -0
  71. package/vendor/nanocodex/cloud/actions/grant.mjs +12 -0
  72. package/vendor/nanocodex/cloud/actions/index.d.mts +7 -0
  73. package/vendor/nanocodex/cloud/actions/index.mjs +7 -0
  74. package/vendor/nanocodex/cloud/actions/machineUsd.d.mts +23 -0
  75. package/vendor/nanocodex/cloud/actions/machineUsd.mjs +37 -0
  76. package/vendor/nanocodex/cloud/actions/model.d.mts +12 -0
  77. package/vendor/nanocodex/cloud/actions/model.mjs +50 -0
  78. package/vendor/nanocodex/cloud/actions/mpp.d.mts +28 -0
  79. package/vendor/nanocodex/cloud/actions/mpp.mjs +39 -0
  80. package/vendor/nanocodex/cloud/index.d.mts +30 -0
  81. package/vendor/nanocodex/cloud/index.mjs +9 -0
  82. package/vendor/nanocodex/cloud/internal.mjs +533 -0
  83. package/vendor/nanocodex/cloud/mercator.mjs +108 -0
  84. package/vendor/nanocodex/cloud/server/HostPrincipal.d.mts +34 -0
  85. package/vendor/nanocodex/cloud/server/HostPrincipal.mjs +202 -0
  86. package/vendor/nanocodex/cloud/server/index.d.mts +1 -0
  87. package/vendor/nanocodex/cloud/server/index.mjs +1 -0
  88. package/vendor/nanocodex/cloud/types.d.mts +211 -0
  89. package/vendor/nanocodex/cloudflare/Agent.d.mts +133 -0
  90. package/vendor/nanocodex/cloudflare/Agent.mjs +811 -0
  91. package/vendor/nanocodex/cloudflare/egress-subject.mjs +19 -0
  92. package/vendor/nanocodex/cloudflare/egress.d.mts +41 -0
  93. package/vendor/nanocodex/cloudflare/egress.mjs +119 -0
  94. package/vendor/nanocodex/cloudflare/event-socket.mjs +316 -0
  95. package/vendor/nanocodex/cloudflare/index.d.mts +7 -0
  96. package/vendor/nanocodex/cloudflare/index.mjs +6 -0
  97. package/vendor/nanocodex/host/Agent.d.mts +55 -0
  98. package/vendor/nanocodex/host/Agent.mjs +1 -0
  99. package/vendor/nanocodex/host/index.d.mts +82 -0
  100. package/vendor/nanocodex/host/index.mjs +10 -0
  101. package/vendor/nanocodex/index.d.mts +81 -0
  102. package/vendor/nanocodex/index.mjs +12 -0
  103. package/vendor/nanocodex/internal.mjs +1275 -0
  104. package/vendor/nanocodex/managed/Agent.d.mts +380 -0
  105. package/vendor/nanocodex/managed/Agent.mjs +1694 -0
  106. package/vendor/nanocodex/managed/ManagedError.d.mts +9 -0
  107. package/vendor/nanocodex/managed/ManagedError.mjs +8 -0
  108. package/vendor/nanocodex/managed/README.md +241 -0
  109. package/vendor/nanocodex/managed/Voice.mjs +202 -0
  110. package/vendor/nanocodex/managed/index.d.mts +20 -0
  111. package/vendor/nanocodex/managed/index.mjs +2 -0
  112. package/vendor/nanocodex/managed/internal.mjs +119 -0
  113. package/vendor/nanocodex/node/Agent.d.mts +50 -0
  114. package/vendor/nanocodex/node/Agent.mjs +203 -0
  115. package/vendor/nanocodex/node/ChatGptSubscription.d.mts +9 -0
  116. package/vendor/nanocodex/node/ChatGptSubscription.mjs +17 -0
  117. package/vendor/nanocodex/node/Transport.d.mts +44 -0
  118. package/vendor/nanocodex/node/Transport.mjs +46 -0
  119. package/vendor/nanocodex/node/host.mjs +731 -0
  120. package/vendor/nanocodex/node/index.d.mts +73 -0
  121. package/vendor/nanocodex/node/index.mjs +17 -0
  122. package/vendor/nanocodex/node/workspace.d.mts +10 -0
  123. package/vendor/nanocodex/node/workspace.mjs +198 -0
  124. package/vendor/nanocodex/package.json +200 -0
  125. package/vendor/nanocodex/pkg-node/nanocodex.d.ts +675 -0
  126. package/vendor/nanocodex/pkg-node/nanocodex.js +2628 -0
  127. package/vendor/nanocodex/pkg-node/nanocodex_bg.wasm.d.ts +105 -0
  128. package/vendor/nanocodex/pkg-node/package.json +1 -0
  129. package/vendor/nanocodex/pkg-web/.nanocodex-bindgen-stamp +6 -0
  130. package/vendor/nanocodex/pkg-web/nanocodex-build.json +1 -0
  131. package/vendor/nanocodex/pkg-web/nanocodex.d.ts +805 -0
  132. package/vendor/nanocodex/pkg-web/nanocodex.js +2714 -0
  133. package/vendor/nanocodex/pkg-web/nanocodex_bg.js +2615 -0
  134. package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm +0 -0
  135. package/vendor/nanocodex/pkg-web/nanocodex_bg.wasm.d.ts +105 -0
  136. package/vendor/nanocodex/pkg-web/nanocodex_worker.js +9 -0
  137. package/vendor/nanocodex/pkg-web/package.json +1 -0
  138. package/vendor/nanocodex/runtime/chatgpt-subscription.mjs +212 -0
  139. package/vendor/nanocodex/runtime/cloudflare-durability-store.d.mts +26 -0
  140. package/vendor/nanocodex/runtime/cloudflare-durability-store.mjs +168 -0
  141. package/vendor/nanocodex/runtime/code-evaluator.worker.mjs +137 -0
  142. package/vendor/nanocodex/runtime/code-runtime.mjs +1 -0
  143. package/vendor/nanocodex/runtime/durability-store.d.mts +85 -0
  144. package/vendor/nanocodex/runtime/durability-store.mjs +631 -0
  145. package/vendor/nanocodex/runtime/durability.mjs +153 -0
  146. package/vendor/nanocodex/runtime/managed-transport.mjs +460 -0
  147. package/vendor/nanocodex/runtime/mcp-runtime.mjs +534 -0
  148. package/vendor/nanocodex/runtime/postgres-durability-store.d.mts +64 -0
  149. package/vendor/nanocodex/runtime/postgres-durability-store.mjs +532 -0
  150. package/vendor/nanocodex/runtime/quickjs-evaluator.d.mts +17 -0
  151. package/vendor/nanocodex/runtime/quickjs-evaluator.mjs +236 -0
  152. package/vendor/nanocodex/runtime/responses-transport.mjs +22 -0
  153. package/vendor/nanocodex/runtime/subagents.d.mts +107 -0
  154. package/vendor/nanocodex/runtime/subagents.mjs +54 -0
  155. package/vendor/nanocodex/runtime/subscription-store.d.mts +8 -0
  156. package/vendor/nanocodex/runtime/subscription-store.mjs +42 -0
  157. package/vendor/nanocodex/runtime/tempo-provider.d.mts +125 -0
  158. package/vendor/nanocodex/runtime/tempo-provider.mjs +264 -0
  159. package/vendor/nanocodex/runtime/tool-configuration.mjs +1 -0
  160. package/vendor/nanocodex/runtime/tool-router.mjs +1 -0
  161. package/vendor/nanocodex/runtime/utf8.mjs +1 -0
  162. package/vendor/nanocodex/runtime/worker-evaluator.mjs +162 -0
  163. package/vendor/nanocodex/runtime/workspace.d.mts +1 -0
  164. package/vendor/nanocodex/runtime/workspace.mjs +1 -0
  165. package/vendor/nanocodex/tools/Tools.d.mts +56 -0
  166. package/vendor/nanocodex/tools/Tools.mjs +136 -0
  167. package/vendor/nanocodex/tools/artifact.d.mts +1 -0
  168. package/vendor/nanocodex/tools/artifact.mjs +1 -0
  169. package/vendor/nanocodex/tools/attachment.mjs +1 -0
  170. package/vendor/nanocodex/tools/bash.d.mts +1 -0
  171. package/vendor/nanocodex/tools/bash.mjs +1 -0
  172. package/vendor/nanocodex/tools/browser/accountInfo.mjs +795 -0
  173. package/vendor/nanocodex/tools/browser/browserBuffer.mjs +18 -0
  174. package/vendor/nanocodex/tools/browser/browserCompiler.mjs +155 -0
  175. package/vendor/nanocodex/tools/browser/browserEgress.mjs +161 -0
  176. package/vendor/nanocodex/tools/browser/browserPython.mjs +133 -0
  177. package/vendor/nanocodex/tools/browser/browserShell.mjs +1075 -0
  178. package/vendor/nanocodex/tools/browser/browserSprintf.mjs +4 -0
  179. package/vendor/nanocodex/tools/browser/browserSsh.mjs +201 -0
  180. package/vendor/nanocodex/tools/browser/browserZlib.mjs +136 -0
  181. package/vendor/nanocodex/tools/browser/compiler.worker.mjs +160 -0
  182. package/vendor/nanocodex/tools/browser/devTunnelsSshBrowser.mjs +13 -0
  183. package/vendor/nanocodex/tools/browser/index.d.mts +209 -0
  184. package/vendor/nanocodex/tools/browser/index.mjs +174 -0
  185. package/vendor/nanocodex/tools/browser/opfsGit.mjs +248 -0
  186. package/vendor/nanocodex/tools/browser/python.worker.mjs +114 -0
  187. package/vendor/nanocodex/tools/browser/threadGit.mjs +197 -0
  188. package/vendor/nanocodex/tools/browser/unsupportedNodeRsa.mjs +5 -0
  189. package/vendor/nanocodex/tools/browser/workspace.mjs +83 -0
  190. package/vendor/nanocodex/tools/dataset.d.mts +1 -0
  191. package/vendor/nanocodex/tools/dataset.mjs +1 -0
  192. package/vendor/nanocodex/tools/datasetContract.mjs +1 -0
  193. package/vendor/nanocodex/tools/datasetEngine.mjs +1 -0
  194. package/vendor/nanocodex/tools/hostedCatalog.d.mts +1 -0
  195. package/vendor/nanocodex/tools/hostedCatalog.mjs +1 -0
  196. package/vendor/nanocodex/tools/index.d.mts +49 -0
  197. package/vendor/nanocodex/tools/index.mjs +19 -0
  198. package/vendor/nanocodex/tools/namedTool.mjs +1 -0
  199. package/vendor/nanocodex/tools/repository-workspace.d.mts +1 -0
  200. package/vendor/nanocodex/tools/repository-workspace.mjs +1 -0
  201. package/vendor/nanocodex/tools/ssh.d.mts +1 -0
  202. package/vendor/nanocodex/tools/ssh.mjs +1 -0
  203. package/vendor/nanocodex/tools/standard.mjs +1 -0
  204. package/vendor/nanocodex/tools/standardDescriptions.mjs +1 -0
  205. package/vendor/nanocodex/types.d.mts +663 -0
  206. package/vendor/nanocodex/wasm.d.mts +4 -0
  207. package/vendor/nanocodex/worker/ChatGptSubscription.d.mts +9 -0
  208. package/vendor/nanocodex/worker/ChatGptSubscription.mjs +29 -0
  209. package/vendor/nanocodex/worker/index.d.mts +18 -0
  210. package/vendor/nanocodex/worker/index.mjs +5 -0
  211. package/vendor/nanocodex-tools/README.md +65 -0
  212. package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.d.ts +7 -0
  213. package/vendor/nanocodex-tools/dist/hosted/app-tool-catalog.js +14 -0
  214. package/vendor/nanocodex-tools/dist/hosted/broker-core.d.ts +172 -0
  215. package/vendor/nanocodex-tools/dist/hosted/broker-core.js +1278 -0
  216. package/vendor/nanocodex-tools/dist/hosted/index.d.ts +3 -0
  217. package/vendor/nanocodex-tools/dist/hosted/index.js +3 -0
  218. package/vendor/nanocodex-tools/dist/hosted/protocol.d.ts +120 -0
  219. package/vendor/nanocodex-tools/dist/hosted/protocol.js +415 -0
  220. package/vendor/nanocodex-tools/dist/index.d.ts +19 -0
  221. package/vendor/nanocodex-tools/dist/index.js +14 -0
  222. package/vendor/nanocodex-tools/dist/memory.d.ts +204 -0
  223. package/vendor/nanocodex-tools/dist/memory.js +411 -0
  224. package/vendor/nanocodex-tools/dist/namespace.d.ts +87 -0
  225. package/vendor/nanocodex-tools/dist/namespace.js +338 -0
  226. package/vendor/nanocodex-tools/dist/repository-archive.d.ts +4 -0
  227. package/vendor/nanocodex-tools/dist/repository-archive.js +104 -0
  228. package/vendor/nanocodex-tools/dist/runtime.d.ts +30 -0
  229. package/vendor/nanocodex-tools/dist/runtime.js +37 -0
  230. package/vendor/nanocodex-tools/dist/session.d.ts +167 -0
  231. package/vendor/nanocodex-tools/dist/session.js +286 -0
  232. package/vendor/nanocodex-tools/dist/shell.d.ts +51 -0
  233. package/vendor/nanocodex-tools/dist/shell.js +553 -0
  234. package/vendor/nanocodex-tools/dist/ssh.d.ts +29 -0
  235. package/vendor/nanocodex-tools/dist/ssh.js +66 -0
  236. package/vendor/nanocodex-tools/dist/workspace.d.ts +45 -0
  237. package/vendor/nanocodex-tools/dist/workspace.js +237 -0
  238. package/vendor/nanocodex-tools/package.json +122 -0
  239. package/vendor/nanocodex-tools/runtime/code-runtime.mjs +817 -0
  240. package/vendor/nanocodex-tools/runtime/tool-configuration.mjs +50 -0
  241. package/vendor/nanocodex-tools/runtime/tool-router.mjs +730 -0
  242. package/vendor/nanocodex-tools/runtime/utf8.d.mts +2 -0
  243. package/vendor/nanocodex-tools/runtime/utf8.mjs +25 -0
  244. package/vendor/nanocodex-tools/tools/artifact.d.mts +69 -0
  245. package/vendor/nanocodex-tools/tools/artifact.mjs +270 -0
  246. package/vendor/nanocodex-tools/tools/attachment.mjs +603 -0
  247. package/vendor/nanocodex-tools/tools/bash.d.mts +90 -0
  248. package/vendor/nanocodex-tools/tools/bash.mjs +742 -0
  249. package/vendor/nanocodex-tools/tools/dataset.d.mts +9 -0
  250. package/vendor/nanocodex-tools/tools/dataset.mjs +47 -0
  251. package/vendor/nanocodex-tools/tools/datasetContract.mjs +54 -0
  252. package/vendor/nanocodex-tools/tools/datasetEngine.mjs +1167 -0
  253. package/vendor/nanocodex-tools/tools/execution-contract.d.mts +5 -0
  254. package/vendor/nanocodex-tools/tools/execution-contract.mjs +63 -0
  255. package/vendor/nanocodex-tools/tools/hostedCatalog.d.mts +20 -0
  256. package/vendor/nanocodex-tools/tools/hostedCatalog.mjs +67 -0
  257. package/vendor/nanocodex-tools/tools/hostedMachine.d.mts +10 -0
  258. package/vendor/nanocodex-tools/tools/hostedMachine.mjs +56 -0
  259. package/vendor/nanocodex-tools/tools/just-bash-browser.d.mts +1 -0
  260. package/vendor/nanocodex-tools/tools/just-bash-browser.mjs +1 -0
  261. package/vendor/nanocodex-tools/tools/namedTool.d.mts +3 -0
  262. package/vendor/nanocodex-tools/tools/namedTool.mjs +3 -0
  263. package/vendor/nanocodex-tools/tools/nodeProcess.d.mts +10 -0
  264. package/vendor/nanocodex-tools/tools/nodeProcess.mjs +314 -0
  265. package/vendor/nanocodex-tools/tools/processOutput.mjs +56 -0
  266. package/vendor/nanocodex-tools/tools/repository-workspace.d.mts +55 -0
  267. package/vendor/nanocodex-tools/tools/repository-workspace.mjs +397 -0
  268. package/vendor/nanocodex-tools/tools/ssh.d.mts +56 -0
  269. package/vendor/nanocodex-tools/tools/ssh.mjs +503 -0
  270. package/vendor/nanocodex-tools/tools/standard.mjs +458 -0
  271. package/vendor/nanocodex-tools/tools/standardDescriptions.mjs +3 -0
  272. package/vendor/nanocodex-tools/tools/types.d.mts +83 -0
  273. package/vendor/nanocodex-tools/tools/workspace.d.mts +25 -0
  274. package/vendor/nanocodex-tools/tools/workspace.mjs +282 -0
  275. package/vendor/nanocodex-tools/tools/x.d.mts +30 -0
  276. package/vendor/nanocodex-tools/tools/x.mjs +91 -0
@@ -0,0 +1,167 @@
1
+ export type SessionPromptInput = string | readonly (Readonly<{
2
+ type: "text";
3
+ text: string;
4
+ }> | Readonly<{
5
+ type: "image";
6
+ imageUrl?: string;
7
+ }> | Readonly<{
8
+ type: "audio";
9
+ audioUrl?: string;
10
+ }>)[];
11
+ export declare const MAX_HISTORY_SEARCH_LIMIT = 20;
12
+ export declare const HISTORY_VECTOR_MATCH_THRESHOLD = 0.5;
13
+ export declare const MAX_HISTORY_QUERY_BYTES = 4096;
14
+ export declare const MAX_HISTORY_TOOL_TEXT_BYTES = 4096;
15
+ export declare const MAX_HISTORY_TOOL_TITLE_BYTES = 512;
16
+ export declare const MAX_HISTORY_TOOL_SNIPPET_BYTES = 1024;
17
+ export type HistoryFindSessionsInput = Readonly<{
18
+ query: string;
19
+ limit: number;
20
+ }>;
21
+ export type HistoryReadSessionInput = Readonly<{
22
+ session_id: string;
23
+ turn_ids?: readonly string[];
24
+ }>;
25
+ export type HistorySource = Readonly<{
26
+ turn_id: string;
27
+ cursor: string;
28
+ }>;
29
+ export type HistoryCitation = Readonly<{
30
+ thread_id: string;
31
+ title: string;
32
+ sources: readonly HistorySource[];
33
+ }>;
34
+ export type HistorySearchHit = Readonly<{
35
+ thread_id: string;
36
+ title: string;
37
+ turn_id: string;
38
+ cursor: string;
39
+ score: number;
40
+ snippet: string;
41
+ }>;
42
+ export type HistoryFindSessionsResponse = Readonly<{
43
+ query: string;
44
+ results: readonly HistorySearchHit[];
45
+ citations: readonly HistoryCitation[];
46
+ }>;
47
+ export type HistoryThreadTurn = Readonly<{
48
+ thread_id: string;
49
+ title: string;
50
+ turn_id: string;
51
+ cursor: string;
52
+ user: string;
53
+ assistant: string;
54
+ }>;
55
+ export type HistoryReadSessionResponse = Readonly<{
56
+ turns: readonly HistoryThreadTurn[];
57
+ citations: readonly HistoryCitation[];
58
+ }>;
59
+ export type HistoryProjection = Readonly<{
60
+ thread_id: string;
61
+ turn_id: string;
62
+ cursor: string;
63
+ title: string;
64
+ input: SessionPromptInput;
65
+ final_message: string;
66
+ created_at: number;
67
+ }>;
68
+ export declare class HistorySearchError extends Error {
69
+ readonly status: number;
70
+ readonly code: string;
71
+ constructor(status: number, code: string, message: string);
72
+ }
73
+ export declare function parseHistoryFindSessionsInput(value: unknown): HistoryFindSessionsInput;
74
+ export declare function parseHistoryReadSessionInput(value: unknown): HistoryReadSessionInput;
75
+ /** Exact identifiers are better served by FTS than semantic similarity. */
76
+ export declare function isExactHistoryIdentifierQuery(query: string): boolean;
77
+ export declare function historyVectorRetrieval(organizationId: string, teamId: string, limit: number): {
78
+ retrieval_type: "vector";
79
+ match_threshold: number;
80
+ max_num_results: number;
81
+ filters: {
82
+ organization_id: {
83
+ $eq: string;
84
+ };
85
+ team_id: {
86
+ $eq: string;
87
+ };
88
+ };
89
+ return_on_failure: boolean;
90
+ };
91
+ export declare function historySearchTerms(query: string, { includeStopWords, maxTerms }?: {
92
+ includeStopWords?: boolean | undefined;
93
+ maxTerms?: number | undefined;
94
+ }): string[];
95
+ export declare function historyFtsQuery(query: string): string;
96
+ export declare function isAcceptedHistoryLexicalMatch(query: string, content: string): boolean;
97
+ export declare function groupHistoryCitations(results: readonly Pick<HistorySearchHit, "thread_id" | "title" | "turn_id" | "cursor">[]): HistoryCitation[];
98
+ export declare function mergeHistoryCitations(current: readonly HistoryCitation[], added: readonly HistoryCitation[]): HistoryCitation[];
99
+ export declare function promptInputText(input: SessionPromptInput): string;
100
+ export declare const FIND_SESSIONS_TOOL_DESCRIPTION: string;
101
+ export declare const READ_SESSION_TOOL_DESCRIPTION: string;
102
+ export declare function findSessionsToolInputSchema(): {
103
+ readonly type: "object";
104
+ readonly properties: {
105
+ readonly query: {
106
+ readonly type: "string";
107
+ readonly minLength: 1;
108
+ readonly maxLength: 4096;
109
+ };
110
+ readonly limit: {
111
+ readonly type: "integer";
112
+ readonly minimum: 1;
113
+ readonly maximum: 20;
114
+ readonly default: 8;
115
+ };
116
+ };
117
+ readonly required: readonly ["query"];
118
+ readonly additionalProperties: false;
119
+ };
120
+ export declare function readSessionToolInputSchema(): {
121
+ readonly type: "object";
122
+ readonly properties: {
123
+ readonly session_id: {
124
+ readonly type: "string";
125
+ readonly pattern: string;
126
+ };
127
+ readonly turn_ids: {
128
+ readonly type: "array";
129
+ readonly items: {
130
+ readonly type: "string";
131
+ readonly pattern: string;
132
+ };
133
+ readonly maxItems: 20;
134
+ };
135
+ };
136
+ readonly required: readonly ["session_id"];
137
+ readonly additionalProperties: false;
138
+ };
139
+ export type FindSessionsToolResult = Readonly<{
140
+ sessions: readonly Readonly<{
141
+ session_id: string;
142
+ title: string;
143
+ turn_id: string;
144
+ cursor: string;
145
+ score: number;
146
+ preview: string;
147
+ }>[];
148
+ }>;
149
+ export type ReadSessionToolResult = Readonly<{
150
+ turns: readonly Readonly<{
151
+ session_id: string;
152
+ title: string;
153
+ turn_id: string;
154
+ cursor: string;
155
+ user: string;
156
+ assistant: string;
157
+ }>[];
158
+ }>;
159
+ /**
160
+ * Projects the internal search response onto the model-visible contract. The
161
+ * allowlist and UTF-8 truncation prevent storage/provider metadata or a single
162
+ * oversized transcript from leaking into a tool result.
163
+ */
164
+ export declare function projectFindSessionsToolResult(value: unknown, limit: number): FindSessionsToolResult;
165
+ /** Projects only bounded transcript fields; citations remain Worker-owned. */
166
+ export declare function projectReadSessionToolResult(value: unknown): ReadSessionToolResult;
167
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
@@ -0,0 +1,286 @@
1
+ const DEFAULT_LIMIT = 8;
2
+ export const MAX_HISTORY_SEARCH_LIMIT = 20;
3
+ export const HISTORY_VECTOR_MATCH_THRESHOLD = 0.5;
4
+ export const MAX_HISTORY_QUERY_BYTES = 4_096;
5
+ export const MAX_HISTORY_TOOL_TEXT_BYTES = 4_096;
6
+ export const MAX_HISTORY_TOOL_TITLE_BYTES = 512;
7
+ export const MAX_HISTORY_TOOL_SNIPPET_BYTES = 1_024;
8
+ const THREAD_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[78][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
9
+ const TURN_ID = /^[A-Za-z0-9._:-]{1,128}$/;
10
+ const EXACT_IDENTIFIER = /^(?=.{2,128}$)(?=.*[_:])[\p{L}\p{N}][\p{L}\p{N}._:-]*$/u;
11
+ const HISTORY_TERM = /[\p{L}\p{N}_-]+/gu;
12
+ const HISTORY_SEARCH_STOP_WORDS = new Set([
13
+ "a", "about", "an", "and", "are", "be", "been", "being", "did", "do", "does",
14
+ "for", "from", "how", "i", "in", "is", "it", "me", "my", "of", "on", "or",
15
+ "our", "that", "the", "this", "to", "was", "we", "were", "what", "when", "where",
16
+ "which", "who", "why", "with", "you", "your",
17
+ ]);
18
+ export class HistorySearchError extends Error {
19
+ status;
20
+ code;
21
+ constructor(status, code, message) {
22
+ super(message);
23
+ this.status = status;
24
+ this.code = code;
25
+ }
26
+ }
27
+ export function parseHistoryFindSessionsInput(value) {
28
+ if (!isRecord(value)) {
29
+ throw new HistorySearchError(400, "invalid_request", "session search body must be a JSON object");
30
+ }
31
+ if (Object.keys(value).some((key) => !["query", "limit"].includes(key))) {
32
+ throw new HistorySearchError(400, "invalid_request", "supported fields are query and limit");
33
+ }
34
+ if (typeof value.query !== "string" || !value.query.trim()) {
35
+ throw new HistorySearchError(400, "invalid_query", "query must be a non-empty string");
36
+ }
37
+ if (new TextEncoder().encode(value.query).byteLength > MAX_HISTORY_QUERY_BYTES) {
38
+ throw new HistorySearchError(400, "invalid_query", `query must not exceed ${MAX_HISTORY_QUERY_BYTES} bytes`);
39
+ }
40
+ if (value.limit !== undefined && (!Number.isSafeInteger(value.limit)
41
+ || Number(value.limit) < 1 || Number(value.limit) > MAX_HISTORY_SEARCH_LIMIT)) {
42
+ throw new HistorySearchError(400, "invalid_limit", `limit must be an integer from 1 to ${MAX_HISTORY_SEARCH_LIMIT}`);
43
+ }
44
+ return {
45
+ query: value.query.trim(),
46
+ limit: value.limit === undefined ? DEFAULT_LIMIT : Number(value.limit),
47
+ };
48
+ }
49
+ export function parseHistoryReadSessionInput(value) {
50
+ if (!isRecord(value)
51
+ || Object.keys(value).some((key) => !["session_id", "turn_ids"].includes(key))) {
52
+ throw new HistorySearchError(400, "invalid_request", "supported fields are session_id and turn_ids");
53
+ }
54
+ if (typeof value.session_id !== "string" || !THREAD_ID.test(value.session_id)) {
55
+ throw new HistorySearchError(400, "invalid_session_id", "invalid session id");
56
+ }
57
+ if (value.turn_ids !== undefined && (!Array.isArray(value.turn_ids)
58
+ || value.turn_ids.length > MAX_HISTORY_SEARCH_LIMIT
59
+ || value.turn_ids.some((turnId) => typeof turnId !== "string" || !TURN_ID.test(turnId)))) {
60
+ throw new HistorySearchError(400, "invalid_turn_ids", `turn_ids must contain at most ${MAX_HISTORY_SEARCH_LIMIT} valid turn ids`);
61
+ }
62
+ return {
63
+ session_id: value.session_id,
64
+ ...(value.turn_ids === undefined ? {} : { turn_ids: value.turn_ids }),
65
+ };
66
+ }
67
+ /** Exact identifiers are better served by FTS than semantic similarity. */
68
+ export function isExactHistoryIdentifierQuery(query) {
69
+ return EXACT_IDENTIFIER.test(query.normalize("NFKC").trim());
70
+ }
71
+ export function historyVectorRetrieval(organizationId, teamId, limit) {
72
+ return {
73
+ retrieval_type: "vector",
74
+ // AI Search applies this to vector similarity before result limiting. A
75
+ // query with no sufficiently related memory therefore returns no direct
76
+ // results instead of filling the response with nearest-but-irrelevant
77
+ // turns.
78
+ match_threshold: HISTORY_VECTOR_MATCH_THRESHOLD,
79
+ max_num_results: Math.min(50, Math.max(limit, limit * 3)),
80
+ filters: {
81
+ organization_id: { $eq: organizationId },
82
+ team_id: { $eq: teamId },
83
+ },
84
+ return_on_failure: false,
85
+ };
86
+ }
87
+ export function historySearchTerms(query, { includeStopWords = false, maxTerms = 24 } = {}) {
88
+ const terms = query.normalize("NFKC").match(HISTORY_TERM) ?? [];
89
+ return [...new Set(terms.map((term) => term.toLocaleLowerCase()))]
90
+ .filter((term) => includeStopWords || !HISTORY_SEARCH_STOP_WORDS.has(term))
91
+ .slice(0, maxTerms);
92
+ }
93
+ export function historyFtsQuery(query) {
94
+ const terms = historySearchTerms(query, {
95
+ includeStopWords: isExactHistoryIdentifierQuery(query),
96
+ });
97
+ return terms.map((term) => `"${term.replaceAll('"', '""')}"`).join(" OR ");
98
+ }
99
+ export function isAcceptedHistoryLexicalMatch(query, content) {
100
+ if (isExactHistoryIdentifierQuery(query)) {
101
+ const identifier = query.normalize("NFKC").trim()
102
+ .replace(/[.*+?^$\{\}()|[\]\\]/gu, "\\$&");
103
+ return new RegExp(`(?:^|[^\\p{L}\\p{N}._:-])${identifier}`
104
+ + "(?=$|[^\\p{L}\\p{N}._:-]|\\.(?=$|\\s))", "iu").test(content.normalize("NFKC"));
105
+ }
106
+ const terms = historySearchTerms(query, {
107
+ includeStopWords: false,
108
+ });
109
+ if (terms.length === 0)
110
+ return false;
111
+ const contentTerms = new Set(historySearchTerms(content, {
112
+ includeStopWords: true,
113
+ maxTerms: Number.MAX_SAFE_INTEGER,
114
+ }));
115
+ for (const term of [...contentTerms]) {
116
+ for (const part of term.split(/[_-]+/u)) {
117
+ if (part)
118
+ contentTerms.add(part);
119
+ }
120
+ }
121
+ const matched = terms.reduce((count, term) => count + Number(contentTerms.has(term)), 0);
122
+ if (terms.length === 1)
123
+ return matched === 1;
124
+ if (terms.length === 2) {
125
+ const words = content.normalize("NFKC").toLocaleLowerCase()
126
+ .replace(/[_-]+/gu, " ")
127
+ .match(/[\p{L}\p{N}]+/gu) ?? [];
128
+ return words.some((word, index) => word === terms[0] && words[index + 1] === terms[1]);
129
+ }
130
+ return matched >= Math.max(2, Math.ceil(terms.length * 0.6));
131
+ }
132
+ export function groupHistoryCitations(results) {
133
+ const grouped = new Map();
134
+ for (const result of results) {
135
+ let citation = grouped.get(result.thread_id);
136
+ if (!citation) {
137
+ citation = { title: result.title, sources: [] };
138
+ grouped.set(result.thread_id, citation);
139
+ }
140
+ if (!citation.sources.some((source) => source.turn_id === result.turn_id
141
+ && source.cursor === result.cursor)) {
142
+ citation.sources.push({ turn_id: result.turn_id, cursor: result.cursor });
143
+ }
144
+ }
145
+ return [...grouped].map(([thread_id, citation]) => ({ thread_id, ...citation }));
146
+ }
147
+ export function mergeHistoryCitations(current, added) {
148
+ return groupHistoryCitations([...current, ...added].flatMap((citation) => (citation.sources.map((source) => ({
149
+ thread_id: citation.thread_id,
150
+ title: citation.title,
151
+ turn_id: source.turn_id,
152
+ cursor: source.cursor,
153
+ })))));
154
+ }
155
+ export function promptInputText(input) {
156
+ if (typeof input === "string")
157
+ return input;
158
+ return input.flatMap((item) => {
159
+ if (item.type === "text")
160
+ return [item.text];
161
+ if (item.type === "image")
162
+ return ["[image]"];
163
+ if (item.type === "audio")
164
+ return ["[audio]"];
165
+ return [];
166
+ }).join("\n");
167
+ }
168
+ export const FIND_SESSIONS_TOOL_DESCRIPTION = [
169
+ "Find bounded candidate completed sessions in the active team's Nanocodex history.",
170
+ "Use read_session to verify relevant candidates before answering.",
171
+ ].join(" ");
172
+ export const READ_SESSION_TOOL_DESCRIPTION = [
173
+ "Read exact completed turns from one candidate Nanocodex session in the active team.",
174
+ "Pass turn_ids to select exact search hits, or omit them to read the newest bounded context.",
175
+ ].join(" ");
176
+ export function findSessionsToolInputSchema() {
177
+ return {
178
+ type: "object",
179
+ properties: {
180
+ query: { type: "string", minLength: 1, maxLength: MAX_HISTORY_QUERY_BYTES },
181
+ limit: {
182
+ type: "integer",
183
+ minimum: 1,
184
+ maximum: MAX_HISTORY_SEARCH_LIMIT,
185
+ default: DEFAULT_LIMIT,
186
+ },
187
+ },
188
+ required: ["query"],
189
+ additionalProperties: false,
190
+ };
191
+ }
192
+ export function readSessionToolInputSchema() {
193
+ return {
194
+ type: "object",
195
+ properties: {
196
+ session_id: { type: "string", pattern: THREAD_ID.source },
197
+ turn_ids: {
198
+ type: "array",
199
+ items: { type: "string", pattern: TURN_ID.source },
200
+ maxItems: MAX_HISTORY_SEARCH_LIMIT,
201
+ },
202
+ },
203
+ required: ["session_id"],
204
+ additionalProperties: false,
205
+ };
206
+ }
207
+ /**
208
+ * Projects the internal search response onto the model-visible contract. The
209
+ * allowlist and UTF-8 truncation prevent storage/provider metadata or a single
210
+ * oversized transcript from leaking into a tool result.
211
+ */
212
+ export function projectFindSessionsToolResult(value, limit) {
213
+ if (!isRecord(value) || !Array.isArray(value.results)
214
+ || value.results.length > MAX_HISTORY_SEARCH_LIMIT
215
+ || !Number.isSafeInteger(limit) || limit < 1 || limit > MAX_HISTORY_SEARCH_LIMIT) {
216
+ throw new HistorySearchError(502, "invalid_response", "session search response is malformed");
217
+ }
218
+ return {
219
+ sessions: value.results.slice(0, limit).map((candidate) => {
220
+ if (!isRecord(candidate)
221
+ || typeof candidate.thread_id !== "string" || !THREAD_ID.test(candidate.thread_id)
222
+ || typeof candidate.turn_id !== "string" || !TURN_ID.test(candidate.turn_id)
223
+ || typeof candidate.cursor !== "string" || !/^\d+$/.test(candidate.cursor)
224
+ || typeof candidate.title !== "string"
225
+ || typeof candidate.snippet !== "string"
226
+ || typeof candidate.score !== "number" || !Number.isFinite(candidate.score)
227
+ || candidate.score < 0 || candidate.score > 1) {
228
+ throw new HistorySearchError(502, "invalid_response", "session search result is malformed");
229
+ }
230
+ return {
231
+ session_id: candidate.thread_id,
232
+ title: truncateUtf8(candidate.title, MAX_HISTORY_TOOL_TITLE_BYTES),
233
+ turn_id: candidate.turn_id,
234
+ cursor: candidate.cursor,
235
+ score: candidate.score,
236
+ preview: truncateUtf8(candidate.snippet, MAX_HISTORY_TOOL_SNIPPET_BYTES),
237
+ };
238
+ }),
239
+ };
240
+ }
241
+ /** Projects only bounded transcript fields; citations remain Worker-owned. */
242
+ export function projectReadSessionToolResult(value) {
243
+ if (!isRecord(value) || !Array.isArray(value.turns)
244
+ || value.turns.length > MAX_HISTORY_SEARCH_LIMIT) {
245
+ throw new HistorySearchError(502, "invalid_response", "session read response is malformed");
246
+ }
247
+ return {
248
+ turns: value.turns.map((candidate) => {
249
+ if (!isRecord(candidate)
250
+ || typeof candidate.thread_id !== "string" || !THREAD_ID.test(candidate.thread_id)
251
+ || typeof candidate.turn_id !== "string" || !TURN_ID.test(candidate.turn_id)
252
+ || typeof candidate.cursor !== "string" || !/^\d+$/.test(candidate.cursor)
253
+ || typeof candidate.title !== "string"
254
+ || typeof candidate.user !== "string"
255
+ || typeof candidate.assistant !== "string") {
256
+ throw new HistorySearchError(502, "invalid_response", "session turn is malformed");
257
+ }
258
+ return {
259
+ session_id: candidate.thread_id,
260
+ title: truncateUtf8(candidate.title, MAX_HISTORY_TOOL_TITLE_BYTES),
261
+ turn_id: candidate.turn_id,
262
+ cursor: candidate.cursor,
263
+ user: truncateUtf8(candidate.user, MAX_HISTORY_TOOL_TEXT_BYTES),
264
+ assistant: truncateUtf8(candidate.assistant, MAX_HISTORY_TOOL_TEXT_BYTES),
265
+ };
266
+ }),
267
+ };
268
+ }
269
+ function truncateUtf8(value, maximum) {
270
+ const encoder = new TextEncoder();
271
+ if (encoder.encode(value).byteLength <= maximum)
272
+ return value;
273
+ let result = "";
274
+ let bytes = 0;
275
+ for (const character of value) {
276
+ const width = encoder.encode(character).byteLength;
277
+ if (bytes + width > maximum)
278
+ break;
279
+ result += character;
280
+ bytes += width;
281
+ }
282
+ return result;
283
+ }
284
+ export function isRecord(value) {
285
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
286
+ }
@@ -0,0 +1,51 @@
1
+ import type { Workspace } from "../tools/types.mjs";
2
+ export type ShellFetchOptions = Readonly<{
3
+ method?: string | undefined;
4
+ headers?: Headers | Record<string, string> | undefined;
5
+ body?: string | Uint8Array | undefined;
6
+ signal?: AbortSignal | undefined;
7
+ }>;
8
+ export type ShellFetchResult = Readonly<{
9
+ status: number;
10
+ statusText: string;
11
+ headers: Record<string, string>;
12
+ body: Uint8Array;
13
+ url: string;
14
+ }>;
15
+ export type ShellFetch = ((url: string, options?: ShellFetchOptions) => Promise<ShellFetchResult>) & Readonly<{
16
+ /** Optional streaming transport for source archives and Git packfiles. */
17
+ stream?: (url: string, options?: ShellFetchOptions) => Promise<Omit<ShellFetchResult, "body"> & {
18
+ body: AsyncIterable<Uint8Array>;
19
+ }>;
20
+ }>;
21
+ type CommandContext = Readonly<{
22
+ cwd?: unknown;
23
+ signal?: AbortSignal;
24
+ }>;
25
+ type CommandResult = Readonly<{
26
+ stdout: string;
27
+ stderr: string;
28
+ exitCode: number;
29
+ }>;
30
+ type GitClone = (args: string[], context: CommandContext) => Promise<CommandResult>;
31
+ /** gh compatibility command backed by the connected GitHub account. */
32
+ export declare function createGhCommand(fetch: ShellFetch, clone?: GitClone): {
33
+ name: string;
34
+ trusted: boolean;
35
+ execute(args: string[], context?: CommandContext): Promise<Readonly<{
36
+ stdout: string;
37
+ stderr: string;
38
+ exitCode: number;
39
+ }>>;
40
+ };
41
+ /** Git compatibility command backed by durable storage and host-authorized GitHub downloads. */
42
+ export declare function createGitCommand(fetch: ShellFetch, workspace: () => Workspace): {
43
+ name: string;
44
+ trusted: boolean;
45
+ execute(args: string[], context?: CommandContext): Promise<{
46
+ stdout: string;
47
+ stderr: string;
48
+ exitCode: number;
49
+ }>;
50
+ };
51
+ export {};