nova-personal-agent-server 0.0.0-stage → 0.4.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 (345) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +30 -2
  3. package/bin/novapersonal-server.mjs +4 -0
  4. package/package.json +61 -4
  5. package/resources/endpointing/volcengine-v1/LICENSE.silero-vad.txt +21 -0
  6. package/resources/endpointing/volcengine-v1/MANIFEST.json +31 -0
  7. package/resources/endpointing/volcengine-v1/silence-16k-s16le.pcm +0 -0
  8. package/resources/endpointing/volcengine-v1/speech-16k-s16le.pcm +0 -0
  9. package/resources/native/codex-sandbox-probe +0 -0
  10. package/resources/native/project-native/nova_project_native.node +0 -0
  11. package/resources/native-resources-v1.json +1 -0
  12. package/runtime/dist/eval/demos.js +156 -0
  13. package/runtime/dist/eval/fixture-host.js +385 -0
  14. package/runtime/dist/eval/fixtures.js +319 -0
  15. package/runtime/dist/eval/realtime/session-fixtures.js +474 -0
  16. package/runtime/dist/eval/scorecard.js +285 -0
  17. package/runtime/dist/eval/sim.js +43 -0
  18. package/runtime/dist/src/cascaded-text-provider.js +31 -0
  19. package/runtime/dist/src/cli.js +96 -0
  20. package/runtime/dist/src/composition/assembly.js +352 -0
  21. package/runtime/dist/src/composition/cascaded-realtime-assembly.js +455 -0
  22. package/runtime/dist/src/composition/production-composition.js +389 -0
  23. package/runtime/dist/src/composition/realtime-assembly.js +1330 -0
  24. package/runtime/dist/src/config/capability-registry.js +315 -0
  25. package/runtime/dist/src/config/cascaded-realtime-config.js +146 -0
  26. package/runtime/dist/src/config/coding-backends.js +8 -0
  27. package/runtime/dist/src/config/coding-profiles.js +98 -0
  28. package/runtime/dist/src/config/config.js +857 -0
  29. package/runtime/dist/src/config/diagnostics.js +139 -0
  30. package/runtime/dist/src/config/environment-contract.js +202 -0
  31. package/runtime/dist/src/config/self-hosted.js +23 -0
  32. package/runtime/dist/src/connectors/composio/client.js +195 -0
  33. package/runtime/dist/src/connectors/composio/google.js +208 -0
  34. package/runtime/dist/src/connectors/composio/index.js +334 -0
  35. package/runtime/dist/src/connectors/feishu/cli.js +220 -0
  36. package/runtime/dist/src/connectors/feishu/index.js +980 -0
  37. package/runtime/dist/src/connectors/macos/calendar.js +35 -0
  38. package/runtime/dist/src/connectors/macos/mail.js +32 -0
  39. package/runtime/dist/src/connectors/macos/reader.js +62 -0
  40. package/runtime/dist/src/conversation-voice-provider.js +41 -0
  41. package/runtime/dist/src/core/approval-port.js +9 -0
  42. package/runtime/dist/src/core/approval.js +1328 -0
  43. package/runtime/dist/src/core/calls.js +35 -0
  44. package/runtime/dist/src/core/camera-session.js +32 -0
  45. package/runtime/dist/src/core/causal-runtime.js +650 -0
  46. package/runtime/dist/src/core/clock.js +139 -0
  47. package/runtime/dist/src/core/context-view.js +156 -0
  48. package/runtime/dist/src/core/effects.js +62 -0
  49. package/runtime/dist/src/core/events.js +217 -0
  50. package/runtime/dist/src/core/executor-diagnostic.js +9 -0
  51. package/runtime/dist/src/core/ids.js +32 -0
  52. package/runtime/dist/src/core/media-store.js +104 -0
  53. package/runtime/dist/src/core/memory.js +296 -0
  54. package/runtime/dist/src/core/pending-decision.js +64 -0
  55. package/runtime/dist/src/core/ports.js +125 -0
  56. package/runtime/dist/src/core/runtime.js +1459 -0
  57. package/runtime/dist/src/core/schedule-tools.js +15 -0
  58. package/runtime/dist/src/core/sims.js +186 -0
  59. package/runtime/dist/src/core/slots.js +97 -0
  60. package/runtime/dist/src/core/source-processing-instructions.js +3 -0
  61. package/runtime/dist/src/core/source-processing-tools.js +12 -0
  62. package/runtime/dist/src/core/suggestions.js +143 -0
  63. package/runtime/dist/src/core/task-tools.js +22 -0
  64. package/runtime/dist/src/core/tool-schema.js +212 -0
  65. package/runtime/dist/src/core/trace.js +34 -0
  66. package/runtime/dist/src/core/work-tools.js +94 -0
  67. package/runtime/dist/src/desktop/desktop-camera-source.js +31 -0
  68. package/runtime/dist/src/desktop/desktop-camera.js +281 -0
  69. package/runtime/dist/src/desktop/desktop-control.js +140 -0
  70. package/runtime/dist/src/desktop/desktop-progress.js +162 -0
  71. package/runtime/dist/src/desktop/desktop-session.js +2106 -0
  72. package/runtime/dist/src/desktop/desktop-tasks.js +80 -0
  73. package/runtime/dist/src/desktop/desktop-wire.js +605 -0
  74. package/runtime/dist/src/desktop/phone-desktop-entry.js +17 -0
  75. package/runtime/dist/src/desktop/startup-error.js +18 -0
  76. package/runtime/dist/src/desktop/workbench-acceptance.js +262 -0
  77. package/runtime/dist/src/desktop-entry.js +106 -0
  78. package/runtime/dist/src/desktop.js +1092 -0
  79. package/runtime/dist/src/executors/acp/backends.js +105 -0
  80. package/runtime/dist/src/executors/acp/mcp.js +81 -0
  81. package/runtime/dist/src/executors/acp/preflight.js +14 -0
  82. package/runtime/dist/src/executors/acp/process-owner.js +112 -0
  83. package/runtime/dist/src/executors/acp/transport.js +760 -0
  84. package/runtime/dist/src/executors/acp/windows-launch.js +68 -0
  85. package/runtime/dist/src/executors/agent-controller.js +244 -0
  86. package/runtime/dist/src/executors/autoglm.js +376 -0
  87. package/runtime/dist/src/executors/browser-device.js +102 -0
  88. package/runtime/dist/src/executors/browser.js +61 -0
  89. package/runtime/dist/src/executors/camera.js +101 -0
  90. package/runtime/dist/src/executors/chromium-frame-source.js +173 -0
  91. package/runtime/dist/src/executors/codex/adapter-live.js +292 -0
  92. package/runtime/dist/src/executors/codex/adapter-project.js +1306 -0
  93. package/runtime/dist/src/executors/codex/app-server-schema.js +712 -0
  94. package/runtime/dist/src/executors/codex/app-server-transport.js +1798 -0
  95. package/runtime/dist/src/executors/codex/approval-protocol.js +439 -0
  96. package/runtime/dist/src/executors/codex/common.js +655 -0
  97. package/runtime/dist/src/executors/codex/contract.js +581 -0
  98. package/runtime/dist/src/executors/codex/controller.js +141 -0
  99. package/runtime/dist/src/executors/codex/credential-snapshot.js +195 -0
  100. package/runtime/dist/src/executors/codex/factory.js +463 -0
  101. package/runtime/dist/src/executors/codex/host-config.js +238 -0
  102. package/runtime/dist/src/executors/codex/host.js +17 -0
  103. package/runtime/dist/src/executors/codex/index.js +19 -0
  104. package/runtime/dist/src/executors/codex/launch-profile.js +37 -0
  105. package/runtime/dist/src/executors/codex/local-sessions.js +119 -0
  106. package/runtime/dist/src/executors/codex/managed-mcp.js +196 -0
  107. package/runtime/dist/src/executors/codex/process-owner.js +398 -0
  108. package/runtime/dist/src/executors/codex/production-host.js +887 -0
  109. package/runtime/dist/src/executors/codex/progress-instructions.js +10 -0
  110. package/runtime/dist/src/executors/codex/protocol.js +581 -0
  111. package/runtime/dist/src/executors/codex/safe-json.js +87 -0
  112. package/runtime/dist/src/executors/codex/session-title.js +61 -0
  113. package/runtime/dist/src/executors/codex/shared-home.js +29 -0
  114. package/runtime/dist/src/executors/codex/spawn-env.js +162 -0
  115. package/runtime/dist/src/executors/codex/turn-projection.js +435 -0
  116. package/runtime/dist/src/executors/codex/version.js +38 -0
  117. package/runtime/dist/src/executors/codex/windows-guardian.js +716 -0
  118. package/runtime/dist/src/executors/coding/intake-model.js +103 -0
  119. package/runtime/dist/src/executors/coding/intake.js +824 -0
  120. package/runtime/dist/src/executors/coding/json-completion.js +14 -0
  121. package/runtime/dist/src/executors/coding/target-resolution.js +61 -0
  122. package/runtime/dist/src/executors/coding/work-order.js +50 -0
  123. package/runtime/dist/src/executors/coding-executor.js +23 -0
  124. package/runtime/dist/src/executors/computer-backend.js +188 -0
  125. package/runtime/dist/src/executors/computer-device.js +187 -0
  126. package/runtime/dist/src/executors/computer-worker.js +125 -0
  127. package/runtime/dist/src/executors/computer.js +100 -0
  128. package/runtime/dist/src/executors/device-lock.js +127 -0
  129. package/runtime/dist/src/executors/frame-source.js +29 -0
  130. package/runtime/dist/src/executors/gui-evidence.js +30 -0
  131. package/runtime/dist/src/executors/gui-execution.js +237 -0
  132. package/runtime/dist/src/executors/gui-runner.js +88 -0
  133. package/runtime/dist/src/executors/host-executor-capability.js +12 -0
  134. package/runtime/dist/src/executors/index.js +13 -0
  135. package/runtime/dist/src/executors/mcp-client.js +198 -0
  136. package/runtime/dist/src/executors/mcp.js +210 -0
  137. package/runtime/dist/src/executors/mobile-android.js +180 -0
  138. package/runtime/dist/src/executors/mobile-ios.js +303 -0
  139. package/runtime/dist/src/executors/mobile.js +78 -0
  140. package/runtime/dist/src/executors/search-mcp.js +146 -0
  141. package/runtime/dist/src/executors/search.js +524 -0
  142. package/runtime/dist/src/executors/task-resources.js +38 -0
  143. package/runtime/dist/src/executors/vision/assess.js +296 -0
  144. package/runtime/dist/src/executors/vision/controller-core.js +373 -0
  145. package/runtime/dist/src/executors/vision/controller.js +164 -0
  146. package/runtime/dist/src/executors/vision/lifecycle.js +69 -0
  147. package/runtime/dist/src/executors/vision.js +5 -0
  148. package/runtime/dist/src/executors/watcher.js +718 -0
  149. package/runtime/dist/src/http/bounded-response.js +37 -0
  150. package/runtime/dist/src/index.js +56 -0
  151. package/runtime/dist/src/knowledge/assembly.js +60 -0
  152. package/runtime/dist/src/knowledge/documents.js +520 -0
  153. package/runtime/dist/src/knowledge/embeddings.js +201 -0
  154. package/runtime/dist/src/knowledge/mcp.js +218 -0
  155. package/runtime/dist/src/knowledge/parse-worker.js +122 -0
  156. package/runtime/dist/src/knowledge/references.js +51 -0
  157. package/runtime/dist/src/knowledge/service.js +526 -0
  158. package/runtime/dist/src/knowledge/store-client.js +185 -0
  159. package/runtime/dist/src/knowledge/store-worker.js +843 -0
  160. package/runtime/dist/src/knowledge/types.js +2 -0
  161. package/runtime/dist/src/mcp/http-server.js +177 -0
  162. package/runtime/dist/src/mem0/resource.js +35 -0
  163. package/runtime/dist/src/mem0/store-worker.js +330 -0
  164. package/runtime/dist/src/memory/blackboard-session.js +205 -0
  165. package/runtime/dist/src/memory/blackboard-store.js +194 -0
  166. package/runtime/dist/src/memory/blackboard-worker.js +369 -0
  167. package/runtime/dist/src/memory/entry.js +39 -0
  168. package/runtime/dist/src/memory/factory.js +20 -0
  169. package/runtime/dist/src/memory/personal-memory-inspection.js +18 -0
  170. package/runtime/dist/src/memory/personal-memory.js +10 -0
  171. package/runtime/dist/src/memory/prerecall.js +20 -0
  172. package/runtime/dist/src/memory/provenance.js +17 -0
  173. package/runtime/dist/src/memory/remote-personal-memory.js +194 -0
  174. package/runtime/dist/src/memory/retrieval.js +235 -0
  175. package/runtime/dist/src/memory/sensitivity.js +261 -0
  176. package/runtime/dist/src/memory-ledger/models.js +98 -0
  177. package/runtime/dist/src/memory-ledger/store-client.js +210 -0
  178. package/runtime/dist/src/memory-ledger/store-worker.js +130 -0
  179. package/runtime/dist/src/memory-ledger/store.js +597 -0
  180. package/runtime/dist/src/memory-substrate/candidates.js +16 -0
  181. package/runtime/dist/src/memory-substrate/consolidation.js +124 -0
  182. package/runtime/dist/src/memory-substrate/file-authority.js +111 -0
  183. package/runtime/dist/src/memory-substrate/life-operations.js +280 -0
  184. package/runtime/dist/src/memory-substrate/markdown-repository.js +610 -0
  185. package/runtime/dist/src/memory-substrate/migration.js +87 -0
  186. package/runtime/dist/src/memory-substrate/profile-source-input.js +9 -0
  187. package/runtime/dist/src/memory-substrate/purge.js +398 -0
  188. package/runtime/dist/src/memory-substrate/resolution.js +32 -0
  189. package/runtime/dist/src/memory-substrate/resource.js +867 -0
  190. package/runtime/dist/src/memory-substrate/retrieval.js +85 -0
  191. package/runtime/dist/src/memory-substrate/source-operations.js +306 -0
  192. package/runtime/dist/src/memory-substrate/source-processing.js +326 -0
  193. package/runtime/dist/src/memory-substrate/source-state.js +93 -0
  194. package/runtime/dist/src/memory-substrate/store.js +534 -0
  195. package/runtime/dist/src/memory-substrate/workspace-projections.js +106 -0
  196. package/runtime/dist/src/memory-substrate/workspace.js +21 -0
  197. package/runtime/dist/src/model/jev-client.js +25 -0
  198. package/runtime/dist/src/model/model-adapters.js +64 -0
  199. package/runtime/dist/src/model/model-gateway.js +399 -0
  200. package/runtime/dist/src/model/model-lane.js +34 -0
  201. package/runtime/dist/src/model/model-purpose.js +5 -0
  202. package/runtime/dist/src/model/personal-writer.js +361 -0
  203. package/runtime/dist/src/model/proactivity.js +72 -0
  204. package/runtime/dist/src/model/prompting.js +279 -0
  205. package/runtime/dist/src/model/task-verifier.js +217 -0
  206. package/runtime/dist/src/model/vision-capability.js +10 -0
  207. package/runtime/dist/src/news/feeds.js +114 -0
  208. package/runtime/dist/src/news/jev-ranking.js +25 -0
  209. package/runtime/dist/src/news/ranking.js +26 -0
  210. package/runtime/dist/src/news/service.js +262 -0
  211. package/runtime/dist/src/notifications/adapters/feishu.js +10 -0
  212. package/runtime/dist/src/notifications/adapters/nova.js +15 -0
  213. package/runtime/dist/src/notifications/content.js +15 -0
  214. package/runtime/dist/src/notifications/contracts.js +9 -0
  215. package/runtime/dist/src/notifications/feed.js +8 -0
  216. package/runtime/dist/src/notifications/service.js +412 -0
  217. package/runtime/dist/src/notifications/store.js +4 -0
  218. package/runtime/dist/src/personal-agent/app-context.js +113 -0
  219. package/runtime/dist/src/personal-agent/approval-scope.js +8 -0
  220. package/runtime/dist/src/personal-agent/coding-targets.js +82 -0
  221. package/runtime/dist/src/personal-agent/context-candidates.js +94 -0
  222. package/runtime/dist/src/personal-agent/contracts.js +32 -0
  223. package/runtime/dist/src/personal-agent/conversation-runtime.js +536 -0
  224. package/runtime/dist/src/personal-agent/conversations.js +187 -0
  225. package/runtime/dist/src/personal-agent/daily-brief.js +53 -0
  226. package/runtime/dist/src/personal-agent/host.js +2403 -0
  227. package/runtime/dist/src/personal-agent/intake-task.js +37 -0
  228. package/runtime/dist/src/personal-agent/life.js +260 -0
  229. package/runtime/dist/src/personal-agent/memory-overview.js +19 -0
  230. package/runtime/dist/src/personal-agent/profile-sources.js +34 -0
  231. package/runtime/dist/src/personal-agent/profile-warmup.js +244 -0
  232. package/runtime/dist/src/personal-agent/project-digests.js +242 -0
  233. package/runtime/dist/src/personal-agent/sampling.js +20 -0
  234. package/runtime/dist/src/personal-agent/schedule-agent.js +60 -0
  235. package/runtime/dist/src/personal-agent/schedule-api.js +61 -0
  236. package/runtime/dist/src/personal-agent/schedule-presets.js +13 -0
  237. package/runtime/dist/src/personal-agent/schedule-reference.js +3 -0
  238. package/runtime/dist/src/personal-agent/scheduled-response-scope.js +38 -0
  239. package/runtime/dist/src/personal-agent/scheduled-run-authority.js +44 -0
  240. package/runtime/dist/src/personal-agent/scheduled-tasks.js +280 -0
  241. package/runtime/dist/src/personal-agent/scheduled-time.js +99 -0
  242. package/runtime/dist/src/personal-agent/scheduled-tool-runtime.js +109 -0
  243. package/runtime/dist/src/personal-agent/source-priority.js +142 -0
  244. package/runtime/dist/src/personal-agent/source-processing-agent.js +158 -0
  245. package/runtime/dist/src/personal-agent/source-walk.js +25 -0
  246. package/runtime/dist/src/personal-agent/sources.js +1484 -0
  247. package/runtime/dist/src/personal-agent/store-lock-worker.js +17 -0
  248. package/runtime/dist/src/personal-agent/store.js +146 -0
  249. package/runtime/dist/src/personal-agent/task-loop.js +163 -0
  250. package/runtime/dist/src/personal-agent/tasks.js +920 -0
  251. package/runtime/dist/src/personal-agent/turn-deadline.js +55 -0
  252. package/runtime/dist/src/personal-agent/understanding.js +160 -0
  253. package/runtime/dist/src/personal-agent/workbench-context.js +239 -0
  254. package/runtime/dist/src/projects/confirmed-project-capability.js +60 -0
  255. package/runtime/dist/src/projects/host-paths.js +133 -0
  256. package/runtime/dist/src/projects/managed-workspace-maintenance.js +351 -0
  257. package/runtime/dist/src/projects/project-confirmation.js +486 -0
  258. package/runtime/dist/src/projects/project-native-resource.js +284 -0
  259. package/runtime/dist/src/projects/project-node-files.js +169 -0
  260. package/runtime/dist/src/projects/project-root-file.js +16 -0
  261. package/runtime/dist/src/projects/project-state.js +504 -0
  262. package/runtime/dist/src/projects/project-store-files.js +1271 -0
  263. package/runtime/dist/src/projects/project-store.js +1345 -0
  264. package/runtime/dist/src/realtime/aoq.js +141 -0
  265. package/runtime/dist/src/realtime/bridge.js +652 -0
  266. package/runtime/dist/src/realtime/cascaded/adapter.js +1669 -0
  267. package/runtime/dist/src/realtime/cascaded/ark-llm.js +219 -0
  268. package/runtime/dist/src/realtime/cascaded/chat-completions-llm.js +478 -0
  269. package/runtime/dist/src/realtime/cascaded/gemini-speech.js +232 -0
  270. package/runtime/dist/src/realtime/cascaded/llm.js +37 -0
  271. package/runtime/dist/src/realtime/cascaded/ports.js +2 -0
  272. package/runtime/dist/src/realtime/cascaded/provider.js +216 -0
  273. package/runtime/dist/src/realtime/cascaded/qwen-llm.js +7 -0
  274. package/runtime/dist/src/realtime/cascaded/self-hosted-asr.js +110 -0
  275. package/runtime/dist/src/realtime/cascaded/self-hosted-tts.js +137 -0
  276. package/runtime/dist/src/realtime/cascaded/transcribe.js +42 -0
  277. package/runtime/dist/src/realtime/coding-progress-narration.js +28 -0
  278. package/runtime/dist/src/realtime/confirmation-turn-isolation.js +586 -0
  279. package/runtime/dist/src/realtime/dictation.js +28 -0
  280. package/runtime/dist/src/realtime/evidence.js +276 -0
  281. package/runtime/dist/src/realtime/floor.js +43 -0
  282. package/runtime/dist/src/realtime/frontend-instructions.js +195 -0
  283. package/runtime/dist/src/realtime/gemini.js +517 -0
  284. package/runtime/dist/src/realtime/history.js +122 -0
  285. package/runtime/dist/src/realtime/host-delivery.js +1711 -0
  286. package/runtime/dist/src/realtime/integrated-wire-profile.js +128 -0
  287. package/runtime/dist/src/realtime/memory-board.js +105 -0
  288. package/runtime/dist/src/realtime/openai-wire-profile.js +46 -0
  289. package/runtime/dist/src/realtime/playback.js +242 -0
  290. package/runtime/dist/src/realtime/project-confirmation-flow.js +1428 -0
  291. package/runtime/dist/src/realtime/prompt-language.js +17 -0
  292. package/runtime/dist/src/realtime/protocol.js +428 -0
  293. package/runtime/dist/src/realtime/provider-projection.js +526 -0
  294. package/runtime/dist/src/realtime/provider-session.js +491 -0
  295. package/runtime/dist/src/realtime/qwen-transport.js +144 -0
  296. package/runtime/dist/src/realtime/qwen.js +1377 -0
  297. package/runtime/dist/src/realtime/recall.js +341 -0
  298. package/runtime/dist/src/realtime/service-ports.js +8 -0
  299. package/runtime/dist/src/realtime/service-state.js +259 -0
  300. package/runtime/dist/src/realtime/service.js +1726 -0
  301. package/runtime/dist/src/realtime/session-state.js +684 -0
  302. package/runtime/dist/src/realtime/session.js +1976 -0
  303. package/runtime/dist/src/realtime/speech-prep.js +63 -0
  304. package/runtime/dist/src/realtime/streaming-speech.js +120 -0
  305. package/runtime/dist/src/realtime/system-prompts.en.js +136 -0
  306. package/runtime/dist/src/realtime/telemetry.js +144 -0
  307. package/runtime/dist/src/realtime/tool-continuations.js +1510 -0
  308. package/runtime/dist/src/realtime/transport.js +8 -0
  309. package/runtime/dist/src/realtime/usage.js +55 -0
  310. package/runtime/dist/src/realtime/user-origin-binding.js +173 -0
  311. package/runtime/dist/src/realtime/volcengine/ark.js +428 -0
  312. package/runtime/dist/src/realtime/volcengine/asr.js +573 -0
  313. package/runtime/dist/src/realtime/volcengine/audio.js +39 -0
  314. package/runtime/dist/src/realtime/volcengine/endpointing-capability.js +834 -0
  315. package/runtime/dist/src/realtime/volcengine/livekit-endpointing.js +714 -0
  316. package/runtime/dist/src/realtime/volcengine/local-eot-executor.js +33 -0
  317. package/runtime/dist/src/realtime/volcengine/protocol.js +247 -0
  318. package/runtime/dist/src/realtime/volcengine/silence-endpointing.js +237 -0
  319. package/runtime/dist/src/realtime/volcengine/tts.js +444 -0
  320. package/runtime/dist/src/realtime/volcengine/websocket.js +293 -0
  321. package/runtime/dist/src/server/aoq-chat-server.js +497 -0
  322. package/runtime/dist/src/server/client-pairing.js +192 -0
  323. package/runtime/dist/src/server/client-protocol.js +87 -0
  324. package/runtime/dist/src/server/client-server.js +312 -0
  325. package/runtime/dist/src/server/server-config.js +72 -0
  326. package/runtime/dist/src/server-entry.js +135 -0
  327. package/runtime/dist/src/storage/bounded-json.js +63 -0
  328. package/runtime/dist/src/storage/native-file-lock.js +8 -0
  329. package/runtime/dist/src/storage/native-resource-snapshot.js +41 -0
  330. package/runtime/dist/src/storage/private-database.js +120 -0
  331. package/runtime/dist/src/text/canonical-json.js +60 -0
  332. package/runtime/dist/src/text/python-number.js +18 -0
  333. package/runtime/dist/src/text/python-text.js +92 -0
  334. package/runtime/dist/src/text/unicode-casefold.js +29 -0
  335. package/runtime/dist/src/text/unicode-normalize.js +138 -0
  336. package/runtime/dist/src/text/unicode-tables.js +210 -0
  337. package/runtime/dist/src/understanding/candidates.js +77 -0
  338. package/runtime/dist/src/understanding/fixture.js +7 -0
  339. package/runtime/dist/src/understanding/jev.js +20 -0
  340. package/runtime/dist/src/understanding/pipeline.js +38 -0
  341. package/runtime/dist/src/voicemem/store-client.js +476 -0
  342. package/runtime/dist/src/voicemem/store-worker.js +380 -0
  343. package/runtime/dist/src/voicemem/versioned-memory.js +170 -0
  344. package/runtime/scripts/pair-device.mjs +109 -0
  345. package/src/command.mjs +48 -0
@@ -0,0 +1,135 @@
1
+ import { ClientPairing } from './server/client-pairing.js';
2
+ /** Headless production service. No Electron, parent-port, or stdin lifecycle dependency. */
3
+ import { pathToFileURL } from 'node:url';
4
+ import { renamedEnvironmentWarnings } from './config/config.js';
5
+ import { initializeServerToken, loadServerConfig } from './server/server-config.js';
6
+ export async function runServerEntry(options = {}) {
7
+ const onDiagnostic = options.onDiagnostic ?? (line => { process.stderr.write(`${line}\n`); });
8
+ // Before the configuration check, so a stale name is reported even when it is the reason startup fails.
9
+ for (const warning of renamedEnvironmentWarnings(options.environment ?? process.env))
10
+ onDiagnostic(warning);
11
+ let config;
12
+ let pairing;
13
+ try {
14
+ config = loadServerConfig(options.environment);
15
+ const environment = options.environment ?? process.env;
16
+ pairing = new ClientPairing(config.token, `${environment.SERVER_TOKEN_FILE}.devices.json`);
17
+ }
18
+ catch {
19
+ onDiagnostic('[runtime-diagnostic] configuration_required');
20
+ return 2;
21
+ }
22
+ const stop = options.stop ?? new AbortController();
23
+ const events = options.processEvents ?? process;
24
+ const requestStop = () => stop.abort();
25
+ events.once('SIGINT', requestStop);
26
+ events.once('SIGTERM', requestStop);
27
+ try {
28
+ if (config.mediaMode === 'aoq_chat') {
29
+ const { AoqChatServer, issueAoqCredential, aoqCredentialURL } = await import('./server/aoq-chat-server.js');
30
+ const environment = options.environment ?? process.env;
31
+ const apiHost = environment.AOQ_API_HOST ?? '';
32
+ try {
33
+ aoqCredentialURL(apiHost);
34
+ }
35
+ catch {
36
+ onDiagnostic('[runtime-diagnostic] aoq_api_host_required');
37
+ return 2;
38
+ }
39
+ const server = new AoqChatServer({ token: config.token, pairing, port: config.port,
40
+ ...(config.language === undefined ? {} : { language: config.language }),
41
+ issueCredential: signal => issueAoqCredential(environment.DASHSCOPE_API_KEY ?? '', signal, apiHost) });
42
+ try {
43
+ if (stop.signal.aborted)
44
+ return 0;
45
+ const readiness = await server.start();
46
+ onDiagnostic(`[server-ready] ws://${readiness.host}:${readiness.port}/client/v1`);
47
+ if (!stop.signal.aborted)
48
+ await new Promise(resolve => stop.signal.addEventListener('abort', () => resolve(), { once: true }));
49
+ return 0;
50
+ }
51
+ catch {
52
+ onDiagnostic('[runtime-diagnostic] aoq_server_unavailable');
53
+ return 2;
54
+ }
55
+ finally {
56
+ await server.close();
57
+ }
58
+ }
59
+ const { runDesktopEntry } = await import('./desktop/desktop-session.js');
60
+ const aoq = config.mediaMode === 'aoq_runtime';
61
+ const environment = options.environment ?? process.env;
62
+ const aoqModule = aoq ? await import('./server/aoq-chat-server.js') : undefined;
63
+ const aoqProvider = aoq ? await import('./realtime/aoq.js') : undefined;
64
+ const link = aoqProvider === undefined ? undefined : new aoqProvider.AoqRuntimeLink();
65
+ const apiHost = environment.AOQ_API_HOST ?? '';
66
+ if (aoq) {
67
+ try {
68
+ aoqModule.aoqCredentialURL(apiHost);
69
+ }
70
+ catch {
71
+ onDiagnostic('[runtime-diagnostic] aoq_api_host_required');
72
+ return 2;
73
+ }
74
+ }
75
+ return await runDesktopEntry({
76
+ token: config.token, stop, onDiagnostic, listenBeforeRealtime: aoq,
77
+ announce: (_endpoint, readiness) => {
78
+ onDiagnostic(`[server-ready] ws://${readiness.host}:${readiness.port}/client/v1`);
79
+ return Promise.resolve();
80
+ },
81
+ construct: options.construct ?? (async (ownership) => {
82
+ const { buildProductionComposition } = await import('./composition/production-composition.js');
83
+ const { ClientServer } = await import('./server/client-server.js');
84
+ return buildProductionComposition({
85
+ token: config.token, stop, ownership, onDiagnostic, remote: true,
86
+ environment: aoq ? { ...environment, PIPELINE_MODE: 'integrated',
87
+ INTEGRATED_PROVIDER: 'qwen',
88
+ QWEN_REALTIME_MODEL: 'qwen-audio-3.0-realtime-plus',
89
+ QWEN_REALTIME_VOICE: 'longanqian' } : environment,
90
+ ...(link === undefined ? {} : { integratedProviders: { qwen: input => new aoqProvider.AoqRealtimeAdapter({
91
+ ...input.config, ...(input.language === undefined ? {} : { language: input.language }), link, onDiagnostic, idFactory: input.idFactory, now: input.now,
92
+ executorApproval: input.executorApproval,
93
+ ...(input.modules === undefined ? {} : { modules: input.modules }),
94
+ }) } }),
95
+ createServer: (serverOptions, media) => link === undefined
96
+ ? new ClientServer({ ...serverOptions, pairing, ...(media === undefined ? {} : { media }), port: config.port })
97
+ : new aoqModule.AoqChatServer({ token: config.token, pairing, port: config.port, onDiagnostic,
98
+ issueCredential: signal => aoqModule.issueAoqCredential(environment.DASHSCOPE_API_KEY ?? '', signal, apiHost),
99
+ runtime: { ...serverOptions,
100
+ onProviderConnect: attachment => link.attach(attachment),
101
+ onProviderEvent: (id, event) => link.receive(id, event),
102
+ onProviderDisconnect: id => link.detach(id),
103
+ }, }),
104
+ });
105
+ }),
106
+ });
107
+ }
108
+ finally {
109
+ for (const event of ['SIGINT', 'SIGTERM']) {
110
+ if (events.off !== undefined)
111
+ events.off(event, requestStop);
112
+ else
113
+ events.removeListener?.(event, requestStop);
114
+ }
115
+ }
116
+ }
117
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
118
+ if (process.argv[2] === 'token-init') {
119
+ try {
120
+ initializeServerToken(process.env.SERVER_TOKEN_FILE ?? '');
121
+ process.stderr.write('[server-token] initialized local credential file\n');
122
+ }
123
+ catch {
124
+ process.stderr.write('[runtime-diagnostic] token_initialization_failed\n');
125
+ process.exitCode = 2;
126
+ }
127
+ }
128
+ else if (process.argv.length > 2) {
129
+ process.stderr.write('Usage: server-entry.js [token-init]\n');
130
+ process.exitCode = 2;
131
+ }
132
+ else
133
+ process.exitCode = await runServerEntry();
134
+ }
135
+ //# sourceMappingURL=server-entry.js.map
@@ -0,0 +1,63 @@
1
+ import { open, rename, unlink } from 'node:fs/promises';
2
+ import { constants } from 'node:fs';
3
+ import { dirname } from 'node:path';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { preparePrivateDatabasePath } from './private-database.js';
6
+ /** Caller owns serialization and the PersonalAgentHost process lock. */
7
+ export class BoundedJsonStore {
8
+ path;
9
+ schema;
10
+ limit;
11
+ constructor(path, schema, limit = 4 * 1024 * 1024) {
12
+ this.path = path;
13
+ this.schema = schema;
14
+ this.limit = limit;
15
+ }
16
+ async read(fallback) {
17
+ preparePrivateDatabasePath(this.path);
18
+ const file = await open(this.path, constants.O_RDONLY | constants.O_NOFOLLOW);
19
+ try {
20
+ if ((await file.stat()).size > this.limit)
21
+ throw Error('store_capacity');
22
+ const text = await file.readFile('utf8');
23
+ return text ? this.schema.parse(JSON.parse(text)) : fallback;
24
+ }
25
+ finally {
26
+ await file.close();
27
+ }
28
+ }
29
+ async write(state) {
30
+ const text = JSON.stringify(this.schema.parse(state));
31
+ if (Buffer.byteLength(text) > this.limit)
32
+ throw Error('store_capacity');
33
+ const tmp = this.path + '.' + randomUUID() + '.tmp';
34
+ let renamed = false;
35
+ try {
36
+ const file = await open(tmp, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
37
+ try {
38
+ await file.writeFile(text);
39
+ await file.sync();
40
+ }
41
+ finally {
42
+ await file.close();
43
+ }
44
+ await rename(tmp, this.path);
45
+ renamed = true;
46
+ // Node cannot fsync directories on Windows; the file was synced before rename.
47
+ if (process.platform !== 'win32') {
48
+ const dir = await open(dirname(this.path), constants.O_RDONLY);
49
+ try {
50
+ await dir.sync();
51
+ }
52
+ finally {
53
+ await dir.close();
54
+ }
55
+ }
56
+ }
57
+ finally {
58
+ if (!renamed)
59
+ await unlink(tmp).catch(() => { });
60
+ }
61
+ }
62
+ }
63
+ //# sourceMappingURL=bounded-json.js.map
@@ -0,0 +1,8 @@
1
+ /** Production stays fail-closed until Task 8 supplies and audits the packaged Node-API module. */
2
+ export const unsupportedNativeFileLocks = Object.freeze({
3
+ acquire: (descriptor) => {
4
+ void descriptor;
5
+ return { status: 'unsupported' };
6
+ },
7
+ });
8
+ //# sourceMappingURL=native-file-lock.js.map
@@ -0,0 +1,41 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { constants as fsConstants, closeSync, fstatSync, openSync, readSync } from 'node:fs';
3
+ export function snapshotRegularFile(path, maximumBytes) {
4
+ const descriptor = openSync(path, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0));
5
+ try {
6
+ const before = fstatSync(descriptor, { bigint: true });
7
+ if (!before.isFile() || before.size <= 0n || before.size > BigInt(maximumBytes))
8
+ throw new Error();
9
+ const size = Number(before.size);
10
+ const bytes = Buffer.allocUnsafe(size);
11
+ let offset = 0;
12
+ while (offset < size) {
13
+ const count = readSync(descriptor, bytes, offset, size - offset, offset);
14
+ if (count === 0)
15
+ throw new Error();
16
+ offset += count;
17
+ }
18
+ const after = fstatSync(descriptor, { bigint: true });
19
+ if (before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size)
20
+ throw new Error();
21
+ return Object.freeze({
22
+ bytes,
23
+ device: before.dev,
24
+ inode: before.ino,
25
+ mode: before.mode,
26
+ size,
27
+ sha256: createHash('sha256').update(bytes).digest('hex'),
28
+ });
29
+ }
30
+ finally {
31
+ closeSync(descriptor);
32
+ }
33
+ }
34
+ export function sameSnapshot(left, right) {
35
+ return left.device === right.device
36
+ && left.inode === right.inode
37
+ && left.mode === right.mode
38
+ && left.size === right.size
39
+ && left.sha256 === right.sha256;
40
+ }
41
+ //# sourceMappingURL=native-resource-snapshot.js.map
@@ -0,0 +1,120 @@
1
+ import { closeSync, constants, fchmodSync, fstatSync, lstatSync, mkdirSync, openSync, realpathSync } from 'node:fs';
2
+ import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
3
+ import { hostProjectRootFromConfig } from '../projects/project-store-files.js';
4
+ export class PrivateDatabaseError extends Error {
5
+ code;
6
+ constructor(code) {
7
+ super(code);
8
+ this.code = code;
9
+ }
10
+ }
11
+ export function preparePrivateDatabasePath(path) {
12
+ if (!isAbsolute(path) || path.includes('\0') || resolve(path) !== path)
13
+ throw new PrivateDatabaseError('STORE_INVALID_INPUT');
14
+ const file = basename(path);
15
+ if (file === '' || file === '.' || file === '..')
16
+ throw new PrivateDatabaseError('STORE_INVALID_INPUT');
17
+ const parent = ensurePrivateParent(dirname(path));
18
+ const databasePath = join(parent, file);
19
+ if (databasePath !== path)
20
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
21
+ ensurePrivateDatabaseFile(databasePath);
22
+ return databasePath;
23
+ }
24
+ function ensurePrivateParent(parent) {
25
+ const missing = [];
26
+ let ancestor = parent;
27
+ for (;;) {
28
+ try {
29
+ lstatSync(ancestor);
30
+ break;
31
+ }
32
+ catch {
33
+ const next = dirname(ancestor);
34
+ if (next === ancestor)
35
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
36
+ missing.unshift(basename(ancestor));
37
+ ancestor = next;
38
+ }
39
+ }
40
+ try {
41
+ hostProjectRootFromConfig(ancestor);
42
+ }
43
+ catch {
44
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
45
+ }
46
+ let current = realpathSync(ancestor);
47
+ for (const child of missing) {
48
+ const next = join(current, child);
49
+ try {
50
+ mkdirSync(next, { mode: 0o700 });
51
+ }
52
+ catch { /* existing child is validated below */ }
53
+ try {
54
+ hostProjectRootFromConfig(next);
55
+ }
56
+ catch {
57
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
58
+ }
59
+ current = realpathSync(next);
60
+ if (current !== next)
61
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
62
+ }
63
+ return current;
64
+ }
65
+ function ensurePrivateDatabaseFile(path) {
66
+ let descriptor;
67
+ try {
68
+ try {
69
+ const info = lstatSync(path);
70
+ if (info.isSymbolicLink() || !info.isFile() || !privateFile(info))
71
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
72
+ descriptor = openSync(path, constants.O_RDWR | constants.O_NOFOLLOW);
73
+ }
74
+ catch (error) {
75
+ if (error instanceof PrivateDatabaseError)
76
+ throw error;
77
+ descriptor = openSync(path, constants.O_RDWR | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
78
+ }
79
+ const fromDescriptor = fstatSync(descriptor);
80
+ const fromPath = lstatSync(path);
81
+ if (!fromDescriptor.isFile() || !privateFile(fromDescriptor) || fromDescriptor.dev !== fromPath.dev || fromDescriptor.ino !== fromPath.ino) {
82
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
83
+ }
84
+ }
85
+ catch (error) {
86
+ if (error instanceof PrivateDatabaseError)
87
+ throw error;
88
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
89
+ }
90
+ finally {
91
+ if (descriptor !== undefined)
92
+ closeSync(descriptor);
93
+ }
94
+ }
95
+ export function secureSidecar(databasePath, suffix) {
96
+ const path = `${databasePath}${suffix}`;
97
+ let descriptor;
98
+ try {
99
+ descriptor = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
100
+ const info = fstatSync(descriptor);
101
+ if (!info.isFile() || !ownedByCurrentUser(info.uid))
102
+ throw new PrivateDatabaseError('STORE_WRITE_FAILED');
103
+ fchmodSync(descriptor, 0o600);
104
+ }
105
+ catch (error) {
106
+ if (error.code !== 'ENOENT')
107
+ throw error;
108
+ }
109
+ finally {
110
+ if (descriptor !== undefined)
111
+ closeSync(descriptor);
112
+ }
113
+ }
114
+ function privateFile(info) {
115
+ return info.isFile() && ownedByCurrentUser(info.uid) && (process.platform === 'win32' || (info.mode & 0o7777) === 0o600);
116
+ }
117
+ function ownedByCurrentUser(uid) {
118
+ return process.platform === 'win32' || typeof process.getuid !== 'function' || uid === process.getuid();
119
+ }
120
+ //# sourceMappingURL=private-database.js.map
@@ -0,0 +1,60 @@
1
+ import { jsonValueSchema } from '../core/events.js';
2
+ const JSON_NUMBER_TOKEN = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/u;
3
+ export function canonicalJson(value) {
4
+ return serializeJson(jsonValueSchema.parse(value), [], undefined);
5
+ }
6
+ /** Canonical JSON with a validated, path-aware spelling override for selected finite numbers. */
7
+ export function canonicalJsonWithNumberFormatter(value, formatter) {
8
+ return serializeJson(jsonValueSchema.parse(value), [], formatter);
9
+ }
10
+ function serializeJson(value, path, formatter) {
11
+ if (value === null)
12
+ return 'null';
13
+ if (typeof value === 'string')
14
+ return JSON.stringify(value);
15
+ if (typeof value === 'number')
16
+ return serializeJsonNumber(value, path, formatter);
17
+ if (typeof value === 'boolean')
18
+ return value ? 'true' : 'false';
19
+ if (Array.isArray(value)) {
20
+ return `[${value.map((item, index) => serializeJson(item, [...path, index], formatter)).join(',')}]`;
21
+ }
22
+ const fields = Object.keys(value)
23
+ .sort(compareCodePoints)
24
+ .map(key => `${JSON.stringify(key)}:${serializeJson(value[key], [...path, key], formatter)}`);
25
+ return `{${fields.join(',')}}`;
26
+ }
27
+ function serializeJsonNumber(value, path, formatter) {
28
+ // JSON has one numeric kind, so canonical bytes depend on numeric value, not
29
+ // whether a source language originally parsed an integral token as int or float.
30
+ // `jsonValueSchema` already rejected NaN and the infinities, which are the only
31
+ // numbers JSON.stringify would refuse to render as a number.
32
+ const token = formatter?.(value, path);
33
+ if (token === undefined)
34
+ return JSON.stringify(value);
35
+ const parsed = JSON_NUMBER_TOKEN.test(token) ? Number(token) : Number.NaN;
36
+ const equivalent = Object.is(value, -0) ? Object.is(parsed, -0) : Object.is(parsed, value);
37
+ if (!equivalent)
38
+ throw new TypeError('canonical number formatter returned an unsafe token');
39
+ return token;
40
+ }
41
+ /**
42
+ * Order two strings by Unicode code point, the way Python `sorted` does.
43
+ *
44
+ * JavaScript's `<` compares UTF-16 code units, so a BMP character above the
45
+ * surrogate range (U+E000, say) sorts before an astral character (U+10000) there
46
+ * and after it by code point. Every ordering the two runtimes must agree on --
47
+ * canonical object keys and sorted identities alike -- goes through this.
48
+ */
49
+ export function compareCodePoints(left, right) {
50
+ const leftPoints = Array.from(left, character => character.codePointAt(0));
51
+ const rightPoints = Array.from(right, character => character.codePointAt(0));
52
+ const length = Math.min(leftPoints.length, rightPoints.length);
53
+ for (let index = 0; index < length; index += 1) {
54
+ const difference = leftPoints[index] - rightPoints[index];
55
+ if (difference !== 0)
56
+ return difference;
57
+ }
58
+ return leftPoints.length - rightPoints.length;
59
+ }
60
+ //# sourceMappingURL=canonical-json.js.map
@@ -0,0 +1,18 @@
1
+ /** Python `str(float)` for a finite IEEE-754 binary64 value. */
2
+ export function pythonFloat(value) {
3
+ if (!Number.isFinite(value)) {
4
+ throw new TypeError(`prompt float must be finite: ${value}`);
5
+ }
6
+ if (value === 0)
7
+ return Object.is(value, -0) ? '-0.0' : '0.0';
8
+ const magnitude = Math.abs(value);
9
+ if (magnitude >= 1e16 || magnitude < 1e-4) {
10
+ const [mantissa, exponent] = value.toExponential().split('e');
11
+ const sign = exponent.startsWith('-') ? '-' : '+';
12
+ const digits = exponent.replace(/^[+-]/, '').padStart(2, '0');
13
+ return `${mantissa}e${sign}${digits}`;
14
+ }
15
+ const rendered = String(value);
16
+ return rendered.includes('.') ? rendered : `${rendered}.0`;
17
+ }
18
+ //# sourceMappingURL=python-number.js.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * String operations that have to agree with CPython's, character for character.
3
+ *
4
+ * These live together because each one is a place the two runtimes look identical and are not, and
5
+ * because each has now been needed more than once -- the first was found in recall, the second in
6
+ * Search, and re-deriving them per module is how one of them ends up subtly different.
7
+ */
8
+ /**
9
+ * Code points `str.isspace()` calls whitespace and `String.prototype.trim` does not.
10
+ *
11
+ * The two predicates disagree in *both* directions across the whole code space, and exactly six code
12
+ * points are involved: these five, plus U+FEFF in the other direction. A test derives the same set from
13
+ * the two predicates rather than trusting this list.
14
+ */
15
+ const PYTHON_ONLY_SPACE = new Set([
16
+ '\u001c',
17
+ '\u001d',
18
+ '\u001e',
19
+ '\u001f',
20
+ '\u0085',
21
+ ]);
22
+ /** Source for a regular-expression character class matching CPython `str.isspace()`. */
23
+ export const PYTHON_WHITESPACE_REGEX_CLASS = String.raw `\u0009-\u000d\u001c-\u0020\u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000`;
24
+ /** Whether Python's `str.isspace()` would be true for this character. */
25
+ export function isPythonSpace(character) {
26
+ // U+FEFF is whitespace to `trim` and a format character to Python.
27
+ if (character === '\ufeff')
28
+ return false;
29
+ return PYTHON_ONLY_SPACE.has(character) || character.trim() === '';
30
+ }
31
+ /**
32
+ * Strip leading and trailing whitespace the way Python's `str.strip()` does.
33
+ *
34
+ * Using `trim()` instead leaves U+001C..U+001F and U+0085 attached and removes U+FEFF, so a value the
35
+ * oracle considers blank arrives here non-blank and vice versa. Where that value decides whether a
36
+ * result is usable evidence, the two runtimes then disagree about what the provider returned.
37
+ */
38
+ export function stripLikePython(text) {
39
+ const characters = [...text];
40
+ let start = 0;
41
+ let end = characters.length;
42
+ while (start < end && isPythonSpace(characters[start]))
43
+ start += 1;
44
+ while (end > start && isPythonSpace(characters[end - 1]))
45
+ end -= 1;
46
+ return characters.slice(start, end).join('');
47
+ }
48
+ /** Collapse Python `\s+` runs to one ASCII space without treating U+FEFF as whitespace. */
49
+ export function collapsePythonWhitespace(text) {
50
+ let result = '';
51
+ let inWhitespace = false;
52
+ for (const character of text) {
53
+ if (isPythonSpace(character)) {
54
+ if (!inWhitespace)
55
+ result += ' ';
56
+ inWhitespace = true;
57
+ }
58
+ else {
59
+ result += character;
60
+ inWhitespace = false;
61
+ }
62
+ }
63
+ return result;
64
+ }
65
+ /** Count Unicode code points exactly as Python's `len(str)` does. */
66
+ export function codePointLengthLikePython(text) {
67
+ return [...text].length;
68
+ }
69
+ /**
70
+ * Whether a string can be encoded as UTF-8 at all.
71
+ *
72
+ * A lone surrogate cannot: Python's `.encode()` raises `UnicodeEncodeError`, while JavaScript's
73
+ * `JSON.stringify` quietly escapes it and `TextEncoder` substitutes U+FFFD. So the same provider
74
+ * response either fails outright or produces a digest, depending on the runtime -- and that digest is a
75
+ * citation the model would then be handed.
76
+ */
77
+ export function isWellFormed(text) {
78
+ for (let index = 0; index < text.length; index += 1) {
79
+ const unit = text.charCodeAt(index);
80
+ if (unit >= 0xd8_00 && unit <= 0xdb_ff) {
81
+ const next = text.charCodeAt(index + 1);
82
+ if (Number.isNaN(next) || next < 0xdc_00 || next > 0xdf_ff)
83
+ return false;
84
+ index += 1;
85
+ }
86
+ else if (unit >= 0xdc_00 && unit <= 0xdf_ff) {
87
+ return false;
88
+ }
89
+ }
90
+ return true;
91
+ }
92
+ //# sourceMappingURL=python-text.js.map
@@ -0,0 +1,29 @@
1
+ // GENERATED FILE -- do not edit by hand.
2
+ // Immutable Unicode 15.0.0 compatibility data retained from the completed runtime migration.
3
+ import { toLowerPinned } from './unicode-normalize.js';
4
+ /*
5
+ * Unicode 15.0.0 full-casefold mappings whose result differs from lowercase.
6
+ * Derived from the same Unicode 15.0.0 database as the committed project fixtures. Ordinary mappings use
7
+ * the already-pinned per-code-point lowercase helper; processing one scalar at a time deliberately
8
+ * avoids JavaScript's contextual final-sigma lowercasing.
9
+ */
10
+ const CASEFOLD_EXCEPTIONS = 'b5:3bc;df:73,73;149:2bc,6e;17f:73;1f0:6a,30c;345:3b9;390:3b9,308,301;3b0:3c5,308,301;3c2:3c3;3d0:3b2;3d1:3b8;3d5:3c6;3d6:3c0;3f0:3ba;3f1:3c1;3f5:3b5;587:565,582;13a0:13a0;13a1:13a1;13a2:13a2;13a3:13a3;13a4:13a4;13a5:13a5;13a6:13a6;13a7:13a7;13a8:13a8;13a9:13a9;13aa:13aa;13ab:13ab;13ac:13ac;13ad:13ad;13ae:13ae;13af:13af;13b0:13b0;13b1:13b1;13b2:13b2;13b3:13b3;13b4:13b4;13b5:13b5;13b6:13b6;13b7:13b7;13b8:13b8;13b9:13b9;13ba:13ba;13bb:13bb;13bc:13bc;13bd:13bd;13be:13be;13bf:13bf;13c0:13c0;13c1:13c1;13c2:13c2;13c3:13c3;13c4:13c4;13c5:13c5;13c6:13c6;13c7:13c7;13c8:13c8;13c9:13c9;13ca:13ca;13cb:13cb;13cc:13cc;13cd:13cd;13ce:13ce;13cf:13cf;13d0:13d0;13d1:13d1;13d2:13d2;13d3:13d3;13d4:13d4;13d5:13d5;13d6:13d6;13d7:13d7;13d8:13d8;13d9:13d9;13da:13da;13db:13db;13dc:13dc;13dd:13dd;13de:13de;13df:13df;13e0:13e0;13e1:13e1;13e2:13e2;13e3:13e3;13e4:13e4;13e5:13e5;13e6:13e6;13e7:13e7;13e8:13e8;13e9:13e9;13ea:13ea;13eb:13eb;13ec:13ec;13ed:13ed;13ee:13ee;13ef:13ef;13f0:13f0;13f1:13f1;13f2:13f2;13f3:13f3;13f4:13f4;13f5:13f5;13f8:13f0;13f9:13f1;13fa:13f2;13fb:13f3;13fc:13f4;13fd:13f5;1c80:432;1c81:434;1c82:43e;1c83:441;1c84:442;1c85:442;1c86:44a;1c87:463;1c88:a64b;1e96:68,331;1e97:74,308;1e98:77,30a;1e99:79,30a;1e9a:61,2be;1e9b:1e61;1e9e:73,73;1f50:3c5,313;1f52:3c5,313,300;1f54:3c5,313,301;1f56:3c5,313,342;1f80:1f00,3b9;1f81:1f01,3b9;1f82:1f02,3b9;1f83:1f03,3b9;1f84:1f04,3b9;1f85:1f05,3b9;1f86:1f06,3b9;1f87:1f07,3b9;1f88:1f00,3b9;1f89:1f01,3b9;1f8a:1f02,3b9;1f8b:1f03,3b9;1f8c:1f04,3b9;1f8d:1f05,3b9;1f8e:1f06,3b9;1f8f:1f07,3b9;1f90:1f20,3b9;1f91:1f21,3b9;1f92:1f22,3b9;1f93:1f23,3b9;1f94:1f24,3b9;1f95:1f25,3b9;1f96:1f26,3b9;1f97:1f27,3b9;1f98:1f20,3b9;1f99:1f21,3b9;1f9a:1f22,3b9;1f9b:1f23,3b9;1f9c:1f24,3b9;1f9d:1f25,3b9;1f9e:1f26,3b9;1f9f:1f27,3b9;1fa0:1f60,3b9;1fa1:1f61,3b9;1fa2:1f62,3b9;1fa3:1f63,3b9;1fa4:1f64,3b9;1fa5:1f65,3b9;1fa6:1f66,3b9;1fa7:1f67,3b9;1fa8:1f60,3b9;1fa9:1f61,3b9;1faa:1f62,3b9;1fab:1f63,3b9;1fac:1f64,3b9;1fad:1f65,3b9;1fae:1f66,3b9;1faf:1f67,3b9;1fb2:1f70,3b9;1fb3:3b1,3b9;1fb4:3ac,3b9;1fb6:3b1,342;1fb7:3b1,342,3b9;1fbc:3b1,3b9;1fbe:3b9;1fc2:1f74,3b9;1fc3:3b7,3b9;1fc4:3ae,3b9;1fc6:3b7,342;1fc7:3b7,342,3b9;1fcc:3b7,3b9;1fd2:3b9,308,300;1fd3:3b9,308,301;1fd6:3b9,342;1fd7:3b9,308,342;1fe2:3c5,308,300;1fe3:3c5,308,301;1fe4:3c1,313;1fe6:3c5,342;1fe7:3c5,308,342;1ff2:1f7c,3b9;1ff3:3c9,3b9;1ff4:3ce,3b9;1ff6:3c9,342;1ff7:3c9,342,3b9;1ffc:3c9,3b9;ab70:13a0;ab71:13a1;ab72:13a2;ab73:13a3;ab74:13a4;ab75:13a5;ab76:13a6;ab77:13a7;ab78:13a8;ab79:13a9;ab7a:13aa;ab7b:13ab;ab7c:13ac;ab7d:13ad;ab7e:13ae;ab7f:13af;ab80:13b0;ab81:13b1;ab82:13b2;ab83:13b3;ab84:13b4;ab85:13b5;ab86:13b6;ab87:13b7;ab88:13b8;ab89:13b9;ab8a:13ba;ab8b:13bb;ab8c:13bc;ab8d:13bd;ab8e:13be;ab8f:13bf;ab90:13c0;ab91:13c1;ab92:13c2;ab93:13c3;ab94:13c4;ab95:13c5;ab96:13c6;ab97:13c7;ab98:13c8;ab99:13c9;ab9a:13ca;ab9b:13cb;ab9c:13cc;ab9d:13cd;ab9e:13ce;ab9f:13cf;aba0:13d0;aba1:13d1;aba2:13d2;aba3:13d3;aba4:13d4;aba5:13d5;aba6:13d6;aba7:13d7;aba8:13d8;aba9:13d9;abaa:13da;abab:13db;abac:13dc;abad:13dd;abae:13de;abaf:13df;abb0:13e0;abb1:13e1;abb2:13e2;abb3:13e3;abb4:13e4;abb5:13e5;abb6:13e6;abb7:13e7;abb8:13e8;abb9:13e9;abba:13ea;abbb:13eb;abbc:13ec;abbd:13ed;abbe:13ee;abbf:13ef;fb00:66,66;fb01:66,69;fb02:66,6c;fb03:66,66,69;fb04:66,66,6c;fb05:73,74;fb06:73,74;fb13:574,576;fb14:574,565;fb15:574,56b;fb16:57e,576;fb17:574,56d';
11
+ const exceptionMap = new Map(CASEFOLD_EXCEPTIONS.split(';').map(entry => {
12
+ const [source, folded] = entry.split(':');
13
+ return [
14
+ Number.parseInt(source, 16),
15
+ String.fromCodePoint(...folded.split(',').map(value => Number.parseInt(value, 16))),
16
+ ];
17
+ }));
18
+ /** CPython `str.casefold()` pinned to Unicode 15.0.0 for well-formed scalar text. */
19
+ export function casefoldLikePython(text) {
20
+ let result = '';
21
+ for (const character of text) {
22
+ const codePoint = character.codePointAt(0);
23
+ if (codePoint === undefined)
24
+ continue;
25
+ result += exceptionMap.get(codePoint) ?? toLowerPinned(character);
26
+ }
27
+ return result;
28
+ }
29
+ //# sourceMappingURL=unicode-casefold.js.map