@ours.network/sdk 1.6.0 → 2.0.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 (80) hide show
  1. package/README.md +48 -29
  2. package/dist/api/contacts.js +1 -1
  3. package/dist/api/conversations.js +1 -1
  4. package/dist/api/files.js +1 -1
  5. package/dist/api/identity.js +1 -1
  6. package/dist/api/messaging.js +1 -1
  7. package/dist/api/profile.js +1 -1
  8. package/dist/book.js +1 -1
  9. package/dist/boot.js +1 -1
  10. package/dist/chunk-3KI5FM4I.js +2 -0
  11. package/dist/{chunk-5UEWBTIG.js → chunk-4IGLXDJS.js} +1 -1
  12. package/dist/{chunk-2AGDAI76.js → chunk-6SMQG6NV.js} +1 -1
  13. package/dist/chunk-CHDY74S7.js +3 -0
  14. package/dist/{chunk-6MGSS5ZO.js → chunk-CQDCCH6N.js} +1 -1
  15. package/dist/{chunk-3CS6SGYE.js → chunk-CUMFIDHH.js} +1 -1
  16. package/dist/{chunk-RNIN2NDZ.js → chunk-DVYJ3STO.js} +1 -1
  17. package/dist/{chunk-IU6MOFTJ.js → chunk-EHCBEY52.js} +1 -1
  18. package/dist/{chunk-AGWCGBCT.js → chunk-ENJRQKGS.js} +1 -1
  19. package/dist/chunk-OCHXHPQZ.js +2 -0
  20. package/dist/{chunk-4TASOWGY.js → chunk-OPCXNIGD.js} +1 -1
  21. package/dist/{chunk-ZNDBLX5J.js → chunk-QSDEMIZQ.js} +1 -1
  22. package/dist/{chunk-EVP7IDZJ.js → chunk-SGTVMU5E.js} +1 -1
  23. package/dist/{chunk-G2ODDJ4Z.js → chunk-TIIFYDXJ.js} +1 -1
  24. package/dist/{chunk-FYYBC5Q4.js → chunk-TNTHPI3A.js} +1 -1
  25. package/dist/{chunk-D7I2EFNP.js → chunk-UH4CZUMI.js} +1 -1
  26. package/dist/{chunk-JAT7EOYH.js → chunk-VJGMISQ5.js} +1 -1
  27. package/dist/chunk-WS6UFNKF.js +5 -0
  28. package/dist/{chunk-JGOJHX3P.js → chunk-WU5WT7LA.js} +1 -1
  29. package/dist/{chunk-FC4ERYFN.js → chunk-WWTR33CX.js} +1 -1
  30. package/dist/{chunk-POTB37MR.js → chunk-XL6UKHPU.js} +1 -1
  31. package/dist/chunk-Y3VPZJTG.js +2 -0
  32. package/dist/{chunk-RJ36BIMK.js → chunk-YDCAL5R3.js} +1 -1
  33. package/dist/{chunk-MGCRONNT.js → chunk-YDWSAX43.js} +1 -1
  34. package/dist/chunk-ZGPYTIOX.js +2 -0
  35. package/dist/client/http.d.ts +5 -0
  36. package/dist/client/select.d.ts +29 -1
  37. package/dist/client/select.js +1 -1
  38. package/dist/client.js +1 -1
  39. package/dist/cluster/control.js +1 -1
  40. package/dist/cluster/manifest.js +1 -1
  41. package/dist/config.d.ts +0 -1
  42. package/dist/config.js +1 -1
  43. package/dist/connector.js +1 -1
  44. package/dist/constants.d.ts +2 -0
  45. package/dist/constants.js +2 -0
  46. package/dist/gc.js +1 -1
  47. package/dist/http/api-routes.js +1 -1
  48. package/dist/http/server.d.ts +2 -0
  49. package/dist/http/server.js +1 -1
  50. package/dist/identity/hierarchy.js +1 -1
  51. package/dist/identity/lease.js +1 -1
  52. package/dist/identity/lifecycle.js +1 -1
  53. package/dist/identity/model.d.ts +1 -2
  54. package/dist/identity/model.js +1 -1
  55. package/dist/identity/provision.js +1 -1
  56. package/dist/index.d.ts +3 -11
  57. package/dist/index.js +1 -1
  58. package/dist/internal/daemon.d.ts +11 -0
  59. package/dist/internal/daemon.js +2 -0
  60. package/dist/internal/state-root-lock.d.ts +25 -0
  61. package/dist/internal/state-root-lock.js +2 -0
  62. package/dist/messaging/send.js +1 -1
  63. package/dist/mufl/handlers.js +1 -1
  64. package/dist/mufl/tx.js +1 -1
  65. package/dist/mufl_code/7962BB01B1D3E782A1F80B083A900AEC30BAC8F8CE79282B31821802B94A39B6.muflo +0 -0
  66. package/dist/notify.js +1 -1
  67. package/dist/render/adapt-to-json.js +1 -1
  68. package/dist/runtime/config-drift.js +1 -1
  69. package/dist/runtime/env.js +1 -1
  70. package/dist/state.js +1 -1
  71. package/dist/sweeps.js +1 -1
  72. package/dist/uploads.js +1 -1
  73. package/package.json +3 -7
  74. package/dist/chunk-4L37F7EA.js +0 -2
  75. package/dist/chunk-FNASW6T5.js +0 -2
  76. package/dist/chunk-IB2U7K6Y.js +0 -5
  77. package/dist/chunk-IDH22QWU.js +0 -2
  78. package/dist/chunk-V7OPRCZ3.js +0 -2
  79. package/dist/daemon.d.ts +0 -5
  80. package/dist/daemon.js +0 -2
package/dist/notify.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q}from"./chunk-POTB37MR.js";import"./chunk-YRPUM6JG.js";import"./chunk-JGOJHX3P.js";import"./chunk-DIRW7I4S.js";import"./chunk-RJ36BIMK.js";import"./chunk-FNASW6T5.js";import"./chunk-4TASOWGY.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-IB2U7K6Y.js";export{e as NOTIFY_KIND_SETS,j as appendNotifyLog,l as binHexField,b as clearNotifyHook,c as fireNotify,h as fireNotifyWaiters,g as notifyEventMatches,d as notifyHooks,m as notifyLogSize,f as parseNotifyKinds,k as readE2eWireIds,n as readNotifyRange,p as refreshUnread,o as serveNotifications,a as setNotifyHook,q as unreadSummary,i as waitForNotify};
2
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q}from"./chunk-XL6UKHPU.js";import"./chunk-YRPUM6JG.js";import"./chunk-WU5WT7LA.js";import"./chunk-DIRW7I4S.js";import"./chunk-YDCAL5R3.js";import"./chunk-OCHXHPQZ.js";import"./chunk-OPCXNIGD.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-Y3VPZJTG.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-WS6UFNKF.js";export{e as NOTIFY_KIND_SETS,j as appendNotifyLog,l as binHexField,b as clearNotifyHook,c as fireNotify,h as fireNotifyWaiters,g as notifyEventMatches,d as notifyHooks,m as notifyLogSize,f as parseNotifyKinds,k as readE2eWireIds,n as readNotifyRange,p as refreshUnread,o as serveNotifications,a as setNotifyHook,q as unreadSummary,i as waitForNotify};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a,b,c,d,e,f,g,h,i,j,k,l}from"../chunk-JGOJHX3P.js";import"../chunk-DIRW7I4S.js";import"../chunk-FNASW6T5.js";import"../chunk-4TASOWGY.js";import"../chunk-ZHH3PWEW.js";import"../chunk-P55RJGZU.js";import"../chunk-IB2U7K6Y.js";export{l as adaptValueToJson,k as decodeWireBin,j as encodeWireBin,i as fmtContactRoot,h as renderContactRoots,a as renderContacts,d as renderFileMetadata,e as renderFiles,b as renderImportRenames,c as renderInbox,g as renderPending,f as writeIncomingFiles};
2
+ import{a,b,c,d,e,f,g,h,i,j,k,l}from"../chunk-WU5WT7LA.js";import"../chunk-DIRW7I4S.js";import"../chunk-OCHXHPQZ.js";import"../chunk-OPCXNIGD.js";import"../chunk-ZHH3PWEW.js";import"../chunk-Y3VPZJTG.js";import"../chunk-P55RJGZU.js";import"../chunk-WS6UFNKF.js";export{l as adaptValueToJson,k as decodeWireBin,j as encodeWireBin,i as fmtContactRoot,h as renderContactRoots,a as renderContacts,d as renderFileMetadata,e as renderFiles,b as renderImportRenames,c as renderInbox,g as renderPending,f as writeIncomingFiles};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a}from"../chunk-IU6MOFTJ.js";import"../chunk-IB2U7K6Y.js";export{a as assertConfigNotDrifted};
2
+ import{a}from"../chunk-EHCBEY52.js";import"../chunk-WS6UFNKF.js";export{a as assertConfigNotDrifted};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}from"../chunk-4TASOWGY.js";import"../chunk-ZHH3PWEW.js";import"../chunk-IB2U7K6Y.js";export{j as API_TOKEN,g as API_VISIBILITY,o as BOOK_DIR_NAME,d as BROKER_URL,b as CONFIG,f as GC_INTERVAL_MS,n as NAME_RE,e as PORT,c as STATE_DIR,a as VERSION,l as authOk,i as log,m as requireAuth,h as startupProgress,k as tokenFromReq,p as validateName};
2
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}from"../chunk-OPCXNIGD.js";import"../chunk-ZHH3PWEW.js";import"../chunk-WS6UFNKF.js";export{j as API_TOKEN,g as API_VISIBILITY,o as BOOK_DIR_NAME,d as BROKER_URL,b as CONFIG,f as GC_INTERVAL_MS,n as NAME_RE,e as PORT,c as STATE_DIR,a as VERSION,l as authOk,i as log,m as requireAuth,h as startupProgress,k as tokenFromReq,p as validateName};
package/dist/state.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{D as a,E as b,F as c,G as d}from"./chunk-POTB37MR.js";import"./chunk-YRPUM6JG.js";import"./chunk-JGOJHX3P.js";import"./chunk-DIRW7I4S.js";import"./chunk-RJ36BIMK.js";import"./chunk-FNASW6T5.js";import"./chunk-4TASOWGY.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-IB2U7K6Y.js";export{a as ensureRegistrar,b as hasSavedState,c as saveState,d as saveStateFailClosed};
2
+ import{D as a,E as b,F as c,G as d}from"./chunk-XL6UKHPU.js";import"./chunk-YRPUM6JG.js";import"./chunk-WU5WT7LA.js";import"./chunk-DIRW7I4S.js";import"./chunk-YDCAL5R3.js";import"./chunk-OCHXHPQZ.js";import"./chunk-OPCXNIGD.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-Y3VPZJTG.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-WS6UFNKF.js";export{a as ensureRegistrar,b as hasSavedState,c as saveState,d as saveStateFailClosed};
package/dist/sweeps.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{r as a,s as b,t as c,u as d,v as e,w as f,x as g}from"./chunk-POTB37MR.js";import"./chunk-YRPUM6JG.js";import"./chunk-JGOJHX3P.js";import"./chunk-DIRW7I4S.js";import"./chunk-RJ36BIMK.js";import"./chunk-FNASW6T5.js";import"./chunk-4TASOWGY.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-IB2U7K6Y.js";export{e as capabilityReconcileSweep,d as contactRestoreSweep,g as e2eRecoverySweep,c as flushDeferredFor,b as renderDeferredQueues,a as renderDegraded,f as scheduleCapabilityReconcile};
2
+ import{r as a,s as b,t as c,u as d,v as e,w as f,x as g}from"./chunk-XL6UKHPU.js";import"./chunk-YRPUM6JG.js";import"./chunk-WU5WT7LA.js";import"./chunk-DIRW7I4S.js";import"./chunk-YDCAL5R3.js";import"./chunk-OCHXHPQZ.js";import"./chunk-OPCXNIGD.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-Y3VPZJTG.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-WS6UFNKF.js";export{e as capabilityReconcileSweep,d as contactRestoreSweep,g as e2eRecoverySweep,c as flushDeferredFor,b as renderDeferredQueues,a as renderDegraded,f as scheduleCapabilityReconcile};
package/dist/uploads.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a,b,c,d,e,f,g,h}from"./chunk-FC4ERYFN.js";import"./chunk-FNASW6T5.js";import"./chunk-4TASOWGY.js";import"./chunk-ZHH3PWEW.js";import"./chunk-IB2U7K6Y.js";export{b as UPLOAD_TTL_MS,e as UploadRefused,g as consumeStagedUpload,c as isUploadId,d as sanitizeUploadFilename,f as stageUpload,h as sweepStaleUploads,a as uploadsDirFor};
2
+ import{a,b,c,d,e,f,g,h}from"./chunk-WWTR33CX.js";import"./chunk-OCHXHPQZ.js";import"./chunk-OPCXNIGD.js";import"./chunk-ZHH3PWEW.js";import"./chunk-Y3VPZJTG.js";import"./chunk-WS6UFNKF.js";export{b as UPLOAD_TTL_MS,e as UploadRefused,g as consumeStagedUpload,c as isUploadId,d as sanitizeUploadFilename,f as stageUpload,h as sweepStaleUploads,a as uploadsDirFor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ours.network/sdk",
3
- "version": "1.6.0",
3
+ "version": "2.0.0",
4
4
  "types": "./dist/index.d.ts",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-Apache-2.0",
@@ -20,10 +20,6 @@
20
20
  "types": "./dist/client.d.ts",
21
21
  "default": "./dist/client.js"
22
22
  },
23
- "./daemon": {
24
- "types": "./dist/daemon.d.ts",
25
- "default": "./dist/daemon.js"
26
- },
27
23
  "./connector": {
28
24
  "types": "./dist/connector.d.ts",
29
25
  "default": "./dist/connector.js"
@@ -41,9 +37,9 @@
41
37
  "build:cli": "npm run build --workspace @ours.network/cli",
42
38
  "typecheck": "tsc -p tsconfig.json --noEmit",
43
39
  "pretest": "npm run build --workspace @ours.network/cli",
44
- "test:cli": "node build.mjs && npm run build --workspace @ours.network/cli && node test/cli-operations.test.mjs && node test/cli-lifecycle.test.mjs && node test/cli-service-instance.test.mjs && node test/cli-command.test.mjs && node test/cli-help.test.mjs",
40
+ "test:cli": "node build.mjs && npm run build --workspace @ours.network/cli && node test/cli-operations.test.mjs && node test/cli-lifecycle.test.mjs && node test/cli-service-instance.test.mjs && node test/cli-service-launchd.test.mjs && node test/cli-command.test.mjs && node test/cli-help.test.mjs",
45
41
  "//test": "test/ux-strings.test.mjs is DELIBERATELY NOT CHAINED HERE: it is red by design until the split completes (687 of 1205 strings still missing — the test prints that number itself) and would make CI permanently red. The missing strings are MCP tool copy and CLI copy that belongs in ours-mcp; the gate only goes green in PR 2, with OURS_MCP_SPLIT pointing at the refactored ours-mcp. Please do not 'helpfully' add it before then.",
46
- "test": "node build.mjs && bash scripts/test-receipts-mufl.sh && bash scripts/test-notifications-mufl.sh && bash scripts/test-contact-uniqueness-mufl.sh && bash scripts/test-temp-remove-me-mufl.sh && node test/bump-version.test.mjs && node test/cli-publish-workflow.test.mjs && node test/mufl-integrity.test.mjs && node test/verbatim-moves.test.mjs && node test/errors.test.mjs && node test/file-limit.test.mjs && node test/validate-name.test.mjs && node test/locate-unit.test.mjs && node test/lease-unit.test.mjs && node test/tx-lock.test.mjs && node test/wire-handlers-integrity.test.mjs && node test/moved-blocks-integrity.test.mjs && node test/ux-literals.test.mjs && node test/dist-shared-state.test.mjs && node test/api-error-parity.test.mjs && node test/files-helpers.test.mjs && node test/inbox-encryption.test.mjs && node test/notification-events.test.mjs && node test/notify-kinds.test.mjs && node test/process-state.test.mjs && node test/startup-progress.test.mjs && node test/transcribe-detect.test.mjs && node test/transcribe-stt.test.mjs && node test/voice-setup-config.test.mjs && node test/cli-operations.test.mjs && node test/cli-lifecycle.test.mjs && node test/cli-service-instance.test.mjs && node test/cli-command.test.mjs && node test/cli-help.test.mjs && node test/mig1867-verify.test.mjs && node test/boot-smoke.test.mjs && node test/boot-guards.test.mjs && node test/api-identity.test.mjs && node test/api-contacts.test.mjs && node test/api-messaging.test.mjs && node test/conversations.test.mjs && node test/conversation-restart.test.mjs && node test/api-files.test.mjs && node test/file-upload.test.mjs && node test/defer-files.test.mjs && node test/daemon-routes.test.mjs && node test/daemon-lifecycle.test.mjs && node test/notify-hook.test.mjs && node test/daemon-events.test.mjs && node test/cross-entry-singleton.test.mjs && node test/client-parity.test.mjs && node test/daemon-selection.test.mjs && node test/api-auth.test.mjs && node test/release-lease.test.mjs && node test/delegation-survives.test.mjs && node test/proxy-annotate-hook.test.mjs && node test/connector-exit-on-stdin-eof.test.mjs && node test/version-advisory.test.mjs && node test/session-restore.test.mjs && node test/loopback-bind.test.mjs && node test/port-visibility.test.mjs && node test/unread-http-api.test.mjs && node test/lease-binding.test.mjs"
42
+ "test": "node build.mjs && bash scripts/test-receipts-mufl.sh && bash scripts/test-notifications-mufl.sh && bash scripts/test-contact-uniqueness-mufl.sh && bash scripts/test-temp-remove-me-mufl.sh && node test/state-root-singleton.test.mjs && node test/bump-version.test.mjs && node test/cli-publish-workflow.test.mjs && node test/mufl-integrity.test.mjs && node test/verbatim-moves.test.mjs && node test/errors.test.mjs && node test/file-limit.test.mjs && node test/validate-name.test.mjs && node test/locate-unit.test.mjs && node test/lease-unit.test.mjs && node test/tx-lock.test.mjs && node test/wire-handlers-integrity.test.mjs && node test/moved-blocks-integrity.test.mjs && node test/ux-literals.test.mjs && node test/dist-shared-state.test.mjs && node test/public-boundary.test.mjs && node test/api-error-parity.test.mjs && node test/files-helpers.test.mjs && node test/inbox-encryption.test.mjs && node test/notification-events.test.mjs && node test/notify-kinds.test.mjs && node test/process-state.test.mjs && node test/startup-progress.test.mjs && node test/transcribe-detect.test.mjs && node test/transcribe-stt.test.mjs && node test/voice-setup-config.test.mjs && node test/cli-operations.test.mjs && node test/cli-lifecycle.test.mjs && node test/cli-service-instance.test.mjs && node test/cli-service-launchd.test.mjs && node test/cli-command.test.mjs && node test/cli-help.test.mjs && node test/mig1867-verify.test.mjs && node test/boot-smoke.test.mjs && node test/boot-guards.test.mjs && node test/api-identity.test.mjs && node test/api-contacts.test.mjs && node test/api-messaging.test.mjs && node test/conversations.test.mjs && node test/conversation-restart.test.mjs && node test/api-files.test.mjs && node test/file-upload.test.mjs && node test/defer-files.test.mjs && node test/daemon-routes.test.mjs && node test/daemon-lifecycle.test.mjs && node test/notify-hook.test.mjs && node test/daemon-events.test.mjs && node test/cross-entry-singleton.test.mjs && node test/client-parity.test.mjs && node test/daemon-selection.test.mjs && node test/api-auth.test.mjs && node test/release-lease.test.mjs && node test/delegation-survives.test.mjs && node test/proxy-annotate-hook.test.mjs && node test/connector-exit-on-stdin-eof.test.mjs && node test/version-advisory.test.mjs && node test/session-restore.test.mjs && node test/loopback-bind.test.mjs && node test/port-visibility.test.mjs && node test/unread-http-api.test.mjs && node test/lease-binding.test.mjs"
47
43
  },
48
44
  "dependencies": {
49
45
  "@adapt-toolkit/sdk": "0.10.12",
@@ -1,2 +0,0 @@
1
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a as s}from"./chunk-AGWCGBCT.js";import{I as h,J as y,K as x,L as F,M as l}from"./chunk-65KGEJBX.js";import{H as S,I as d,J as _,M as f,p as c}from"./chunk-POTB37MR.js";import{d as g,f as p}from"./chunk-JGOJHX3P.js";import{t as m,u as a,v as w}from"./chunk-FNASW6T5.js";async function M(n){let r=s(n);try{return S(t=>g(_(r,"::actor::list_incoming_files",t)))}catch(t){throw l("list_incoming_files",String(t))}}async function N(n,r={}){let t=s(n),{wire_ids:e}=r;if(e!==void 0){if(e.length<1||e.length>a)throw h(a);if(e.some(i=>!m(i)))throw y();if(new Set(e).size!==e.length)throw x()}try{let i=await d(async o=>{let u=await f(t,"::actor::get_files",e===void 0?{}:{wire_ids:e},o);return await p(t,u.Reduce("files"))});return c(t),{files:i.files,text:i.text,mode:e===void 0?"all_unread":"selected",requested:e??null}}catch(i){let o=String(i);throw e!==void 0&&/unknown, stale, or no longer unread/i.test(o)?F():l("get_files",o)}}function P(n,r){let t=s(n);return{existsOnDisk:w(t,r.wire_id)!==null}}async function T(n,r){let t=s(n),{file_ids:e}=r;try{let i=await d(async o=>(await f(t,"::actor::defer_files",{file_ids:e},o)).Reduce("deferred").Visualize());return c(t),{deferred:i}}catch(i){throw l("defer_files",String(i))}}export{M as a,N as b,P as c,T as d};
@@ -1,2 +0,0 @@
1
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{c as i,i as a}from"./chunk-4TASOWGY.js";import{join as n}from"node:path";import{createHash as u}from"node:crypto";import*as r from"node:fs";var m;function P(t){m=t}var v=new Map,g=null,y=null;function T(t){g=t}function I(t){y=t}var _=t=>n(i,t),d=t=>n(t,"identity.key"),h=t=>n(t,"state_data.bin"),F=t=>n(t,"notifications.log"),W=t=>n(t,"unread.json"),x=t=>n(t.dir,"files"),c=t=>n(t,"temp.json"),E=t=>u("sha256").update(t).digest("hex");function H(t,e){r.writeFileSync(c(t),JSON.stringify({v:1,owner:{token_sha256:e.owner.tokenHash,pid:e.owner.pid},created_at:e.createdAt}),{mode:384})}function M(t){try{let e=JSON.parse(r.readFileSync(c(t),"utf8"));return e.v!==1||typeof e.owner?.token_sha256!="string"||typeof e.owner?.pid!="number"?null:{owner:{tokenHash:e.owner.token_sha256,pid:e.owner.pid},createdAt:typeof e.created_at=="number"?e.created_at:0}}catch{return null}}function R(){for(let t of w()){let e=n(i,t);try{r.chmodSync(e,448)}catch(o){a(`[${t}] chmod 0700 failed:`,String(o))}for(let o of[h(e),d(e)])if(r.existsSync(o))try{r.chmodSync(o,384)}catch(s){a(`[${t}] chmod 0600 ${o} failed:`,String(s))}}}var k=t=>/^[A-Za-z0-9]+$/.test(t)&&t.length>0&&t.length<=128,$=t=>/^[A-Fa-f0-9]{64}$/.test(t),j=32;function B(t,e){if(!k(e))return null;let o=x(t),s;try{s=r.readdirSync(o)}catch{return null}let l=`${e}-`,p=s.find(f=>f.startsWith(l));return p?n(o,p):null}function w(){return r.existsSync(i)?r.readdirSync(i,{withFileTypes:!0}).filter(t=>t.isDirectory()&&r.existsSync(d(n(i,t.name)))).map(t=>t.name):[]}export{m as a,P as b,v as c,g as d,y as e,T as f,I as g,_ as h,d as i,h as j,F as k,W as l,x as m,c as n,E as o,H as p,M as q,R as r,k as s,$ as t,j as u,B as v,w};
@@ -1,5 +0,0 @@
1
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import*as o from"node:fs";import{randomBytes as S}from"node:crypto";import{homedir as g}from"node:os";import{resolve as a,join as c,dirname as u,basename as b}from"node:path";var d=["owner","shared","open"],s={brokerUrl:"wss://broker1.ours.network",port:3050,stateDir:a(g(),".ours"),gcIntervalMs:36e5,autoStart:!1,apiVisibility:"owner"};function y(){return process.env.OURS_CONFIG??c(g(),".ours","config.json")}function T(){let t;try{t=o.readFileSync(y(),"utf8")}catch{return{}}let e;try{e=JSON.parse(t)}catch{return{}}let i={};if(typeof e.brokerUrl=="string"&&(i.brokerUrl=e.brokerUrl),typeof e.port=="number"&&Number.isFinite(e.port)&&(i.port=e.port),typeof e.stateDir=="string"&&(i.stateDir=a(e.stateDir)),typeof e.gcIntervalMs=="number"&&Number.isFinite(e.gcIntervalMs)&&(i.gcIntervalMs=e.gcIntervalMs),typeof e.autoStart=="boolean"&&(i.autoStart=e.autoStart),typeof e.apiVisibility=="string"&&d.includes(e.apiVisibility)&&(i.apiVisibility=e.apiVisibility),typeof e.apiToken=="string"&&e.apiToken.trim()&&(i.apiToken=e.apiToken.trim()),e.stt&&typeof e.stt=="object"){let r=e.stt,n={};typeof r.provider=="string"&&(n.provider=r.provider),typeof r.apiKey=="string"&&(n.apiKey=r.apiKey),typeof r.model=="string"&&(n.model=r.model),typeof r.baseUrl=="string"&&(n.baseUrl=r.baseUrl),typeof r.language=="string"&&(n.language=r.language),typeof r.maxBytes=="number"&&Number.isFinite(r.maxBytes)&&(n.maxBytes=r.maxBytes),typeof r.timeoutMs=="number"&&Number.isFinite(r.timeoutMs)&&(n.timeoutMs=r.timeoutMs),r.custom&&typeof r.custom=="object"&&(n.custom=r.custom),i.stt=n}return i}function v(){let t=process.env.OURS_API_VISIBILITY?.trim().toLowerCase();return t&&d.includes(t)?t:void 0}function _(t){let e=process.env[t];if(e!==void 0)return e==="1"||e.toLowerCase()==="true"}function l(t){let e=process.env[t];if(e===void 0)return;let i=parseInt(e,10);return Number.isNaN(i)?void 0:i}function C(){let t=T();return{brokerUrl:process.env.OURS_BROKER_URL??t.brokerUrl??s.brokerUrl,port:l("OURS_PORT")??t.port??s.port,stateDir:a(process.env.OURS_STATE_DIR??t.stateDir??s.stateDir),gcIntervalMs:l("OURS_GC_INTERVAL_MS")??t.gcIntervalMs??s.gcIntervalMs,autoStart:_("OURS_AUTOSTART")??t.autoStart??s.autoStart,apiVisibility:v()??t.apiVisibility??s.apiVisibility,apiToken:process.env.OURS_API_TOKEN?.trim()||t.apiToken,stt:O(t.stt)}}function O(t){let e={};process.env.OURS_STT_PROVIDER?.trim()&&(e.provider=process.env.OURS_STT_PROVIDER.trim()),process.env.OURS_STT_API_KEY?.trim()&&(e.apiKey=process.env.OURS_STT_API_KEY.trim()),process.env.OURS_STT_MODEL?.trim()&&(e.model=process.env.OURS_STT_MODEL.trim()),process.env.OURS_STT_BASE_URL?.trim()&&(e.baseUrl=process.env.OURS_STT_BASE_URL.trim()),process.env.OURS_STT_LANGUAGE?.trim()&&(e.language=process.env.OURS_STT_LANGUAGE.trim());let i={...t??{},...e};return Object.keys(i).length?i:void 0}var U="daemon-token";function k(t){return c(t.stateDir,U)}function w(t){let e=process.env.OURS_API_TOKEN?.trim();return e||t.apiToken?.trim()||void 0}function F(t,e={}){let i=process.env.OURS_API_TOKEN?.trim();if(i)return{token:i,source:"env"};let r=t.apiToken?.trim();if(r)return{token:r,source:"config"};let n=k(t);try{let p=o.readFileSync(n,"utf8").trim();if(p)return{token:p,source:"file"}}catch{}if(!e.generate)return null;let f=S(32).toString("hex");try{o.mkdirSync(u(n),{recursive:!0}),o.writeFileSync(n,f+`
3
- `,{mode:384}),o.chmodSync(n,384)}catch{}return{token:f,source:"generated"}}function N(t){let e=y();o.mkdirSync(u(e),{recursive:!0}),o.writeFileSync(e,JSON.stringify(t,null,2)+`
4
- `,{mode:384});try{o.chmodSync(e,384)}catch{}return e}var m=".ours-identity";function I(t){if(!t.name.trim())throw new Error("identity name must not be empty");let e={identity:t.name.trim()};return t.force&&(e.force=!0),e.expose_local=t.exposeLocal??!0,e.local_auto_accept=t.localAutoAccept??!0,e}function R(t){let e=a(t);return b(e)===m?e:c(e,m)}function V(t,e,i=!1){let r=I(e),n=R(t);if(!i&&o.existsSync(n))throw new Error(`${n} already exists \u2014 pass overwrite to replace it`);return o.mkdirSync(u(n),{recursive:!0}),o.writeFileSync(n,JSON.stringify(r,null,2)+`
5
- `),n}export{d as a,s as b,y as c,C as d,U as e,k as f,w as g,F as h,N as i,m as j,I as k,R as l,V as m};
@@ -1,2 +0,0 @@
1
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{b as m,e as N}from"./chunk-IB2U7K6Y.js";import{readFileSync as v}from"node:fs";import{homedir as I}from"node:os";import{join as E,resolve as p}from"node:path";var r=class extends Error{constructor(s,n){super(n);this.code=s;this.name="DaemonSelectionError"}},O=m.port,b=N,R=".ours",w=["explicit","environment","config-file"];function $(e={}){let t=e.env??process.env,s=e.readTextFile??(h=>v(h,"utf8")),n=e.homeDir??I(),l=f(t,"OURS_INSTANCE");if(l!==void 0)throw new r("INCOHERENT_SELECTION",`OURS_INSTANCE=${JSON.stringify(l)} is set, but named daemon instances are not implemented. Select the daemon with an explicit endpoint/port option or with OURS_PORT, and unset OURS_INSTANCE.`);if(e.stateDir!==void 0&&e.expectStateDir!==void 0){let h=p(e.stateDir),y=p(e.expectStateDir);if(h!==y)throw new r("INCOHERENT_SELECTION",`stateDir ${JSON.stringify(h)} and expectStateDir ${JSON.stringify(y)} name different directories. The state directory decides which token is read; the expected one decides which daemon that token may be sent to. Reconcile them, or pass only one.`)}let o=U(e.configPath,f(t,"OURS_CONFIG")),a=o?_(o.value,s):{},i=T(e.port,k(f(t,"OURS_PORT")),a.port,O),c=T(e.stateDir??e.expectStateDir,f(t,"OURS_STATE_DIR"),a.stateDir,E(n,R)),d={value:p(c.value),source:c.source},g=e.endpoint!==void 0?{value:A(e.endpoint),source:"explicit"}:{value:`http://127.0.0.1:${i.value}`,source:i.source},S=f(t,"OURS_API_TOKEN");x({endpointSelected:e.endpoint!==void 0||i.source!=="default",endpointSource:g.source,stateDirIntentional:w.includes(d.source),stateDirSource:d.source,hasExplicitToken:e.token!==void 0&&e.token!=="",hasEnvToken:S!==void 0,requireExplicitSelection:e.requireExplicitSelection===!0,portSource:i.source});let D=C(e.token,S,a,d,s);return{baseUrl:g,port:i,stateDir:d,expectStateDir:e.expectStateDir!==void 0?p(e.expectStateDir):d.value,...D?{token:D}:{},...o?{configPath:o}:{}}}function J(e){return{baseUrl:e.baseUrl.value,baseUrlSource:e.baseUrl.source,port:e.port.value,portSource:e.port.source,stateDir:e.stateDir.value,stateDirSource:e.stateDir.source,expectStateDir:e.expectStateDir,tokenSource:e.token?.source??"none",configPath:e.configPath?.value??null}}function x(e){if(e.requireExplicitSelection){if(e.endpointSource==="default"&&e.portSource==="default")throw u(`requireExplicitSelection is set, but no daemon was selected. Pass endpoint/port, set OURS_PORT, or point OURS_CONFIG at a config file. Refusing the built-in default 127.0.0.1:${O}.`);if(!e.stateDirIntentional)throw u("requireExplicitSelection is set, but the state directory is the built-in default. Every auth-affecting field must be chosen deliberately: pass stateDir or expectStateDir, set OURS_STATE_DIR, or name a config file. Refusing before reading any token or opening any socket.")}if(e.endpointSelected&&!e.stateDirIntentional)throw u(`the endpoint was selected (source: ${e.endpointSource}) but the state directory is the built-in default. A daemon's API token belongs to one state directory, so reading the default token and sending it to a separately chosen endpoint would disclose a credential to it. Select the state directory too: stateDir, expectStateDir, OURS_STATE_DIR, or one config file. An explicit token alone is not enough \u2014 without an expected state directory there is nothing to assert the endpoint against before the token is sent.`);if(e.hasEnvToken&&!e.stateDirIntentional)throw u("OURS_API_TOKEN is set, but the state directory is the built-in default. An environment token is process-wide and authenticates to every daemon it is offered to, so it requires an explicitly expected state directory: pass stateDir or expectStateDir, or set OURS_STATE_DIR.");if(e.hasExplicitToken&&!e.stateDirIntentional)throw u("an explicit token was given, but the state directory is the built-in default, so there would be nothing to assert the daemon against before the token is sent. Pass expectStateDir (or stateDir) naming the state directory that token belongs to.")}function u(e){return new r("INCOHERENT_SELECTION",e)}function C(e,t,s,n,l){if(e!==void 0&&e!=="")return{value:e,source:"explicit"};if(t!==void 0)return{value:t,source:"environment"};let o=s.apiToken?.trim();if(o)return{value:o,source:"config-file"};try{let a=l(E(n.value,b)).trim();if(a)return{value:a,source:"token-file"}}catch{}}function _(e,t){let s;try{s=t(e)}catch{throw new r("CONFIG_UNREADABLE",`the daemon config file ${JSON.stringify(e)} could not be read.`)}let n;try{n=JSON.parse(s)}catch{throw new r("CONFIG_INVALID",`the daemon config file ${JSON.stringify(e)} is not valid JSON.`)}if(n===null||typeof n!="object"||Array.isArray(n))throw new r("CONFIG_INVALID",`the daemon config file ${JSON.stringify(e)} is not a JSON object.`);let l=n,o={},a=l.port;if(a!==void 0){if(typeof a!="number"||!Number.isInteger(a)||a<1||a>65535)throw new r("CONFIG_INVALID",`the daemon config file ${JSON.stringify(e)} declares an invalid port; expected an integer 1-65535.`);o.port=a}let i=l.stateDir;if(i!==void 0){if(typeof i!="string"||i.trim()==="")throw new r("CONFIG_INVALID",`the daemon config file ${JSON.stringify(e)} declares an invalid stateDir; expected a non-empty string.`);o.stateDir=i}let c=l.apiToken;if(c!==void 0){if(typeof c!="string"||c.trim()==="")throw new r("CONFIG_INVALID",`the daemon config file ${JSON.stringify(e)} declares an invalid apiToken; expected a non-empty string.`);o.apiToken=c}let d=l.apiVisibility;if(d!==void 0){if(d!=="owner"&&d!=="shared"&&d!=="open")throw new r("CONFIG_INVALID",`the daemon config file ${JSON.stringify(e)} declares an unknown apiVisibility ${JSON.stringify(d)}; expected "owner", "shared" or "open".`);o.apiVisibility=d}return o}function f(e,t){let s=e[t];if(s===void 0)return;let n=s.trim();return n===""?void 0:n}function k(e){if(e===void 0)return;let t=Number.parseInt(e,10);if(!Number.isInteger(t)||t<1||t>65535)throw new r("INCOHERENT_SELECTION",`OURS_PORT=${JSON.stringify(e)} is not a TCP port between 1 and 65535.`);return t}function A(e){return e.endsWith("/")?e.slice(0,-1):e}function T(e,t,s,n){return e!==void 0?{value:e,source:"explicit"}:t!==void 0?{value:t,source:"environment"}:s!==void 0?{value:s,source:"config-file"}:{value:n,source:"default"}}function U(e,t){if(e!==void 0)return{value:e,source:"explicit"};if(t!==void 0)return{value:t,source:"environment"}}async function G(e,t={}){let s=t.fetch??globalThis.fetch,n=new AbortController,l=setTimeout(()=>n.abort(),t.timeoutMs??5e3),o;try{let i=await s(`${e.baseUrl.value}/state-dir`,{signal:n.signal});if(!i.ok)throw new r("INCOHERENT_SELECTION",`${e.baseUrl.value}/state-dir answered HTTP ${i.status}, so the daemon at that address could not be identified. Refusing to send a credential to it.`);o=await i.json()}catch(i){throw i instanceof r?i:new r("INCOHERENT_SELECTION",`${e.baseUrl.value}/state-dir could not be reached (${String(i)}), so the daemon at that address could not be identified. Refusing to send a credential to it.`)}finally{clearTimeout(l)}let a=typeof o.stateDir=="string"?p(o.stateDir):null;if(a===null)throw new r("INCOHERENT_SELECTION",`${e.baseUrl.value}/state-dir did not report a state directory, so this is not an ours daemon or not one this client understands. Refusing to send a credential to it.`);if(a!==e.expectStateDir)throw new r("INCOHERENT_SELECTION",`the daemon at ${e.baseUrl.value} owns state directory ${JSON.stringify(a)}, but this selection expects ${JSON.stringify(e.expectStateDir)}. The token belongs to the expected directory, so it is NOT being sent. Point the endpoint and the state directory at the same daemon.`)}export{r as a,O as b,b as c,$ as d,J as e,G as f};
@@ -1,2 +0,0 @@
1
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a as he}from"./chunk-NBEWKZG4.js";import{d as $}from"./chunk-V64IUVSS.js";import{a as z}from"./chunk-37D5PCFY.js";import{a as ue,b as G}from"./chunk-D7I2EFNP.js";import{a as ge,d as ye}from"./chunk-5UEWBTIG.js";import{b as me}from"./chunk-JAT7EOYH.js";import{e as pe,f as le,h as fe}from"./chunk-FC4ERYFN.js";import{b as ce}from"./chunk-VXVW4KJU.js";import{b as re,c as ae}from"./chunk-FYYBC5Q4.js";import{b as de}from"./chunk-G2ODDJ4Z.js";import{F as se,a as ne,b as U,o as oe,q as ie}from"./chunk-POTB37MR.js";import{a as M,b as ee,c as w,e as L,f as A,g as te}from"./chunk-RJ36BIMK.js";import{c as I,o as Z,v as q}from"./chunk-FNASW6T5.js";import{a as P,b as Q,c as H,d as W,e as N,g as X,h as b,i as p,m as v,p as Y}from"./chunk-4TASOWGY.js";import{createServer as ke}from"node:http";import{randomUUID as Re}from"node:crypto";import*as D from"node:fs";he();function Ne(r){if(!r||typeof r!="object"||Array.isArray(r))return!1;let f=r;return f.jsonrpc==="2.0"&&f.method==="initialize"}var Oe=["brokerUrl","port","stateDir","gcIntervalMs","apiVisibility"];function we(r){return new Promise((f,u)=>{let O="";r.on("data",g=>O+=g),r.on("end",()=>{try{f(JSON.parse(O))}catch(g){u(g)}}),r.on("error",u)})}async function Ve(r={}){try{return await Ce(r)}catch(f){throw b?.failed(),p(`fatal startup error: ${f?.stack??f}`),f}}async function Ce(r){let f=r.handleSignals!==!1;if(process.env.OURS_TEST_STARTUP_FAIL==="1")throw new Error("forced startup failure (OURS_TEST_STARTUP_FAIL)");if(r.config){let t=Oe.filter(e=>r.config[e]!==Q[e]);if(t.length>0)throw new Error(`startDaemon(config) disagrees with the config resolved at module load (${t.join(", ")}). The engine reads its config when src/runtime/env.ts is imported, so a later override cannot move the state dir, port or broker \u2014 set OURS_* env or config.json before importing the SDK.`)}let u=r.mcp,O=u?.isInitializeRequest??Ne,g=null;if(typeof r.onIdentityNotify=="function"){let t=r.onIdentityNotify;g=(e,i)=>{t(e,i,M.get(e)?.sid??null)},ne(g)}p("booting wrapper\u2026");try{await me(),ue()}catch(t){throw g&&U(g),G(),t}p(`wrapper ready (identities=${I.size}), starting HTTP server\u2026`),b?.update("server");let l={},T=new Map,k=new Map,Se=3e4,J=t=>{let e=k.get(t);e?e.n++:k.set(t,{n:1,since:Date.now()})},B=t=>{let e=k.get(t);e&&--e.n<=0&&k.delete(t)},F=()=>{let t=0;for(let e of[...T.keys()]){if(e==="stdio")continue;let i=w.get(e)?.pid;if(i===void 0||i<=1||L(i))continue;let n=k.get(e);if(n&&n.n>0&&Date.now()-n.since<Se)continue;let o=T.get(e);T.delete(e),delete l[e],w.delete(e),k.delete(e),o?.close().catch(()=>{}),u?.onSessionClosed?.(e),t++,p(`session ${e.slice(0,8)}\u2026 reaped (client pid ${i} dead)`)}return t},V=setInterval(()=>{F(),ae(),fe()},6e4);V.unref?.();let _=1e3,Ie=10*6e4,y=new Map,ve=(t,e)=>{let i=Array.isArray(e)?e:[e];for(let n of i){let o=n;!o||typeof o!="object"||o.id===void 0||o.id===null||typeof o.method!="string"||y.set(`${t}:${String(o.id)}`,{method:o.method,at:Date.now()})}if(y.size>_){let n=Date.now()-Ie;for(let[o,a]of y)if(a.at<n&&y.delete(o),y.size<=_)break;for(;y.size>_;){let o=y.keys().next();if(o.done)break;y.delete(o.value)}}},Te=(t,e)=>{try{let i=e instanceof Error?e.message:String(e),n=/No connection established for request ID:\s*(\S+)/.exec(i);if(!n)return;let o=n[1],a=y.get(`${t}:${o}`);y.delete(`${t}:${o}`),p(`UNDELIVERABLE RESPONSE session=${t.slice(0,8)}\u2026 request_id=${o} method=${a?.method??"unknown"} age_ms=${a?Date.now()-a.at:"unknown"} at=${new Date().toISOString()} \u2014 the answer was produced but its stream was already gone`)}catch{}},S=ke(async(t,e)=>{let i=new URL(t.url,`http://localhost:${N}`);if(t.method==="GET"&&i.pathname==="/state-dir"){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({stateDir:H,version:P,compat:1}));return}if(t.method==="GET"&&(i.pathname==="/version"||i.pathname==="/info")){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({name:"ours",version:P,compat:1,protocol:de,pid:process.pid,stateDir:H}));return}if(t.method==="GET"&&i.pathname==="/identities"){if(!v(t,e))return;e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({identities:[...I.values()].map(n=>({name:n.name,...n.temp?{temporary:!0,stale:!L(n.temp.owner.pid)}:{}}))}));return}if(t.method==="GET"&&i.pathname==="/unread"){if(!v(t,e))return;e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify(ie()));return}{let n=/^\/identities\/([^/]+)\/notifications$/.exec(i.pathname);if(t.method==="GET"&&n){if(!v(t,e))return;let o=decodeURIComponent(n[1]);if(Y(o)!==null){e.writeHead(400,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"invalid identity name"}));return}await oe(t,e,o,i.searchParams.get("since"),i.searchParams.get("kinds"));return}}if(t.method==="POST"&&i.pathname==="/files/upload"){if(!v(t,e))return;let n=t.headers["x-ours-lease-token"],o=typeof n=="string"&&n?A(n):void 0,a=o?I.get(o.identity):void 0;if(!a){e.writeHead(401,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"no identity bound to this session"}));return}let h=t.headers["content-length"],d=typeof h=="string"?Number(h):NaN,m=t.headers["x-ours-filename"];try{let s=await le(a,t,{filename:typeof m=="string"?decodeURIComponent(m):"",mime:typeof t.headers["content-type"]=="string"?t.headers["content-type"]:"",declaredBytes:Number.isInteger(d)&&d>=0?d:null,cap:ce()});e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify(s))}catch(s){let R=s instanceof pe?s.status:500;e.headersSent||(e.writeHead(R,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:s instanceof Error?s.message:String(s)})))}return}{let n=/^\/files\/([^/]+)$/.exec(i.pathname);if(t.method==="GET"&&n){if(!v(t,e))return;let o=decodeURIComponent(n[1]),a=t.headers["x-ours-lease-token"],h=typeof a=="string"&&a?A(a):void 0,d=h?I.get(h.identity):void 0;if(!d){e.writeHead(401,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"no identity bound to this session"}));return}let m=q(d,o);if(!m){e.writeHead(404,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:"no such file for the bound identity (run get_files first, or it belongs to another identity)"}));return}try{let s=D.statSync(m);e.writeHead(200,{"Content-Type":"application/octet-stream","Content-Length":String(s.size)});let R=D.createReadStream(m);R.on("error",()=>{try{e.destroy()}catch{}}),R.pipe(e)}catch(s){e.writeHead(500,{"Content-Type":"application/json"}),e.end(JSON.stringify({error:`failed to read file: ${String(s)}`}))}return}}if(i.pathname.startsWith(ge)){await ye(t,e,i.pathname,we);return}if(i.pathname!=="/mcp"||!u){e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Not found");return}if(v(t,e))try{if(t.method==="POST"){let n=await we(t),o=t.headers["mcp-session-id"],a=t.headers["x-ours-lease-token"],h=t.headers["x-ours-client-pid"],d=h?parseInt(h,10):void 0,m={token:a,pid:Number.isInteger(d)?d:void 0};if(o&&l[o]){w.set(o,m),ve(o,n),J(o),$(e);try{await l[o].handleRequest(t,e,n)}finally{B(o)}}else if(!o&&O(n)){F();let s=u.createTransport({sessionIdGenerator:()=>Re(),onsessioninitialized:c=>{l[c]=s,w.set(c,m),T.set(c,E),u.onSessionInitialized?.(c,E),p(`session ${c.slice(0,8)}\u2026 initialized`)}}),R={sessionId:()=>s.sessionId??"pending",leaseToken:()=>w.get(s.sessionId??"pending")?.token,clientPid:()=>w.get(s.sessionId??"pending")?.pid},E=u.createServer(R);E.server.onerror=c=>Te(s.sessionId??"pending",c),s.onclose=()=>{let c=s.sessionId;c&&(delete l[c],T.delete(c),w.delete(c),u.onSessionClosed?.(c),p(`session ${c.slice(0,8)}\u2026 closed (lease kept)`))},await E.connect(s),$(e),await s.handleRequest(t,e,n)}else e.writeHead(400,{"Content-Type":"application/json"}),e.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32e3,message:"Bad Request: No valid session ID"},id:null}))}else if(t.method==="GET"){let n=t.headers["mcp-session-id"];if(!n||!l[n]){e.writeHead(400,{"Content-Type":"text/plain"}),e.end("Invalid or missing session ID");return}J(n),$(e);try{await l[n].handleRequest(t,e)}finally{B(n)}}else if(t.method==="DELETE"){let n=t.headers["mcp-session-id"];if(!n||!l[n]){e.writeHead(400,{"Content-Type":"text/plain"}),e.end("Invalid or missing session ID");return}let o=w.get(n)?.token??t.headers["x-ours-lease-token"];if(o){for(let[a,h]of[...M]){if(h.token!==o)continue;M.delete(a);let d=I.get(a);d?.temp&&d.temp.owner.tokenHash===Z(o)&&!d.temp.closing&&re(d,"owning session released its lease").catch(m=>p(`[${a}] close on lease release failed:`,String(m)))}ee.delete(o),te(),p(`lease released by token \u2026${o.slice(-6)}`)}await l[n].handleRequest(t,e)}else e.writeHead(405,{"Content-Type":"text/plain"}),e.end("Method not allowed")}catch(n){p("HTTP handler error:",String(n)),e.headersSent||(e.writeHead(500,{"Content-Type":"application/json"}),e.end(JSON.stringify({jsonrpc:"2.0",error:{code:-32603,message:"Internal server error"},id:null})))}});S.requestTimeout=0;let K=!1,x=async()=>{if(!K){K=!0,clearInterval(V),G(),g&&U(g);for(let t of Object.keys(l)){try{await l[t].close()}catch{}delete l[t]}T.clear();for(let t of I.values())try{se(t)}catch(e){p(`[${t.name}] shutdown save failed:`,String(e))}S.closeAllConnections?.()}};try{await new Promise((t,e)=>{let i=n=>e(n);S.once("error",i),S.listen(N,"127.0.0.1",()=>{S.off("error",i),b?.ready(),p(`MCP server v${r.version??P} ready (transport=http, port=${N}, visibility=${X}, identities=${I.size}, state=${H}, broker=${W})`),t()})})}catch(t){throw await x(),t}let C=async()=>{p("shutting down\u2026"),await x(),S.close(),process.exit(0)};f&&(process.on("SIGINT",C),process.on("SIGTERM",C));let j=S.address();return{port:typeof j=="object"&&j!==null?j.port:N,close:async()=>{f&&(process.off("SIGINT",C),process.off("SIGTERM",C)),await x(),await new Promise(t=>S.close(()=>t()))}}}export{Ve as a};
package/dist/daemon.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export { bootWrapper } from './boot.js';
2
- export { startDaemon } from './http/server.js';
3
- export { startupProgress } from './runtime/env.js';
4
- export type { StartupProgressReporter } from './startup-progress.js';
5
- export type { DaemonHandle, DaemonOptions, McpIntegration, McpServerLike, McpTransportInit, McpTransportLike, } from './http/server.js';
package/dist/daemon.js DELETED
@@ -1,2 +0,0 @@
1
- import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
- import{a as e}from"./chunk-V7OPRCZ3.js";import"./chunk-NBEWKZG4.js";import"./chunk-V64IUVSS.js";import"./chunk-37D5PCFY.js";import"./chunk-D7I2EFNP.js";import"./chunk-5UEWBTIG.js";import{b as t}from"./chunk-JAT7EOYH.js";import"./chunk-IU6MOFTJ.js";import"./chunk-ZNDBLX5J.js";import"./chunk-RNIN2NDZ.js";import"./chunk-4L37F7EA.js";import"./chunk-3CS6SGYE.js";import"./chunk-FC4ERYFN.js";import"./chunk-VXVW4KJU.js";import"./chunk-MGCRONNT.js";import"./chunk-EVP7IDZJ.js";import"./chunk-AGWCGBCT.js";import"./chunk-FYYBC5Q4.js";import"./chunk-65KGEJBX.js";import"./chunk-G2ODDJ4Z.js";import"./chunk-2AGDAI76.js";import"./chunk-6MGSS5ZO.js";import"./chunk-POTB37MR.js";import"./chunk-YRPUM6JG.js";import"./chunk-JGOJHX3P.js";import"./chunk-DIRW7I4S.js";import"./chunk-RJ36BIMK.js";import"./chunk-FNASW6T5.js";import{h as r}from"./chunk-4TASOWGY.js";import"./chunk-ZHH3PWEW.js";import"./chunk-LKFYUCN7.js";import"./chunk-P55RJGZU.js";import"./chunk-XYU2DSWR.js";import"./chunk-IB2U7K6Y.js";export{t as bootWrapper,e as startDaemon,r as startupProgress};