@ours.network/sdk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/LICENSE +98 -0
  2. package/README.md +41 -0
  3. package/dist/api/contacts.d.ts +31 -0
  4. package/dist/api/contacts.js +2 -0
  5. package/dist/api/files.d.ts +10 -0
  6. package/dist/api/files.js +2 -0
  7. package/dist/api/identity.d.ts +44 -0
  8. package/dist/api/identity.js +2 -0
  9. package/dist/api/messaging.d.ts +23 -0
  10. package/dist/api/messaging.js +2 -0
  11. package/dist/api/profile.d.ts +9 -0
  12. package/dist/api/profile.js +2 -0
  13. package/dist/api/types.d.ts +177 -0
  14. package/dist/api/types.js +1 -0
  15. package/dist/book.d.ts +22 -0
  16. package/dist/book.js +2 -0
  17. package/dist/boot.d.ts +1 -0
  18. package/dist/boot.js +2 -0
  19. package/dist/chunk-37D5PCFY.js +2 -0
  20. package/dist/chunk-3DQSMLVZ.js +2 -0
  21. package/dist/chunk-5EWCIQH6.js +2 -0
  22. package/dist/chunk-7UUFYO6G.js +2 -0
  23. package/dist/chunk-A3SXVUOC.js +2 -0
  24. package/dist/chunk-AJQIWYXG.js +2 -0
  25. package/dist/chunk-DIRW7I4S.js +2 -0
  26. package/dist/chunk-HCIVLHKC.js +2 -0
  27. package/dist/chunk-HSVIKO4D.js +3 -0
  28. package/dist/chunk-IB2U7K6Y.js +5 -0
  29. package/dist/chunk-KZMPGVQM.js +2 -0
  30. package/dist/chunk-LKFYUCN7.js +2 -0
  31. package/dist/chunk-NMYSFQBL.js +2 -0
  32. package/dist/chunk-NQQ4GSVI.js +5 -0
  33. package/dist/chunk-NSPYN5TT.js +2 -0
  34. package/dist/chunk-P55RJGZU.js +2 -0
  35. package/dist/chunk-PCHN744Y.js +2 -0
  36. package/dist/chunk-Q3UVLSCX.js +2 -0
  37. package/dist/chunk-RAGUBE4Y.js +2 -0
  38. package/dist/chunk-T25JIPX5.js +2 -0
  39. package/dist/chunk-TZBRSDND.js +2 -0
  40. package/dist/chunk-UELGY557.js +2 -0
  41. package/dist/chunk-UJGRFV4J.js +2 -0
  42. package/dist/chunk-UM73BGFH.js +2 -0
  43. package/dist/chunk-V64IUVSS.js +4 -0
  44. package/dist/chunk-VOYMK2OO.js +2 -0
  45. package/dist/chunk-VW2KWXSJ.js +2 -0
  46. package/dist/chunk-X4RVJ5VL.js +6 -0
  47. package/dist/chunk-YRPUM6JG.js +2 -0
  48. package/dist/chunk-ZAXRB5MO.js +2 -0
  49. package/dist/chunk-ZHH3PWEW.js +4 -0
  50. package/dist/client/http.d.ts +178 -0
  51. package/dist/client/http.js +2 -0
  52. package/dist/cluster/control.d.ts +5 -0
  53. package/dist/cluster/control.js +2 -0
  54. package/dist/cluster/manifest.d.ts +12 -0
  55. package/dist/cluster/manifest.js +2 -0
  56. package/dist/config.d.ts +37 -0
  57. package/dist/config.js +2 -0
  58. package/dist/connector.d.ts +68 -0
  59. package/dist/connector.js +5 -0
  60. package/dist/daemon.d.ts +5 -0
  61. package/dist/daemon.js +2 -0
  62. package/dist/errors.d.ts +40 -0
  63. package/dist/errors.js +2 -0
  64. package/dist/events.d.ts +144 -0
  65. package/dist/events.js +2 -0
  66. package/dist/files.d.ts +2 -0
  67. package/dist/files.js +2 -0
  68. package/dist/gc.d.ts +2 -0
  69. package/dist/gc.js +2 -0
  70. package/dist/http/api-routes.d.ts +63 -0
  71. package/dist/http/api-routes.js +2 -0
  72. package/dist/http/server.d.ts +120 -0
  73. package/dist/http/server.js +2 -0
  74. package/dist/identity/hierarchy.d.ts +20 -0
  75. package/dist/identity/hierarchy.js +2 -0
  76. package/dist/identity/lease.d.ts +29 -0
  77. package/dist/identity/lease.js +2 -0
  78. package/dist/identity/lifecycle.d.ts +5 -0
  79. package/dist/identity/lifecycle.js +2 -0
  80. package/dist/identity/model.d.ts +67 -0
  81. package/dist/identity/model.js +2 -0
  82. package/dist/identity/provision.d.ts +12 -0
  83. package/dist/identity/provision.js +2 -0
  84. package/dist/inbox.d.ts +38 -0
  85. package/dist/inbox.js +2 -0
  86. package/dist/index.d.ts +11 -0
  87. package/dist/index.js +2 -0
  88. package/dist/messaging/send.d.ts +28 -0
  89. package/dist/messaging/send.js +2 -0
  90. package/dist/mufl/handlers.d.ts +5 -0
  91. package/dist/mufl/handlers.js +2 -0
  92. package/dist/mufl/tx.d.ts +9 -0
  93. package/dist/mufl/tx.js +2 -0
  94. package/dist/mufl_code/8ED6356B41CC689C75DA3302AD7856058131661A6ABBAC961E71BA838D8C97A3.muflo +0 -0
  95. package/dist/notify.d.ts +24 -0
  96. package/dist/notify.js +2 -0
  97. package/dist/process-state.d.ts +2 -0
  98. package/dist/process-state.js +2 -0
  99. package/dist/protocol.d.ts +1 -0
  100. package/dist/protocol.js +2 -0
  101. package/dist/render/adapt-to-json.d.ts +83 -0
  102. package/dist/render/adapt-to-json.js +2 -0
  103. package/dist/runtime/env.d.ts +18 -0
  104. package/dist/runtime/env.js +2 -0
  105. package/dist/runtime/unit.d.ts +15 -0
  106. package/dist/runtime/unit.js +2 -0
  107. package/dist/sse-keepalive.d.ts +18 -0
  108. package/dist/sse-keepalive.js +2 -0
  109. package/dist/startup-progress.d.ts +54 -0
  110. package/dist/startup-progress.js +2 -0
  111. package/dist/state.d.ts +5 -0
  112. package/dist/state.js +2 -0
  113. package/dist/sweeps.d.ts +18 -0
  114. package/dist/sweeps.js +2 -0
  115. package/dist/transcribe.d.ts +113 -0
  116. package/dist/transcribe.js +2 -0
  117. package/dist/version-advisory.d.ts +4 -0
  118. package/dist/version-advisory.js +2 -0
  119. package/dist/voice-setup.d.ts +44 -0
  120. package/dist/voice-setup.js +28 -0
  121. package/package.json +49 -0
@@ -0,0 +1,28 @@
1
+ import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
2
+ import{h as O}from"./chunk-DIRW7I4S.js";import{chmodSync as A,closeSync as K,existsSync as C,mkdirSync as Y,openSync as U,readFileSync as I,readSync as L,renameSync as M,statSync as H,unlinkSync as V,writeFileSync as W,writeSync as q}from"node:fs";import{spawnSync as w}from"node:child_process";import{dirname as G}from"node:path";var d=[{value:"openai-compatible",label:"OpenAI-compatible",detail:"an OpenAI-style /v1 transcription endpoint"},{value:"elevenlabs",label:"ElevenLabs",detail:"ElevenLabs speech-to-text"},{value:"deepgram",label:"Deepgram",detail:"Deepgram speech-to-text"},{value:"custom",label:"Custom HTTP endpoint",detail:"a fully specified transcription URL"}],l=class extends Error{constructor(o){super(o);this.reason=o}};function z(e){if(!C(e))return{};let n=JSON.parse(I(e,"utf8"));if(!n||typeof n!="object"||Array.isArray(n))throw new Error("config root must be a JSON object");return n}function Z(e){return C(e)?{exists:!0,text:I(e,"utf8"),mode:H(e).mode&511}:{exists:!1}}function Q(e,n){D(e,`${JSON.stringify(n,null,2)}
3
+ `,384)}function D(e,n,o){Y(G(e),{recursive:!0,mode:448});let t=`${e}.tmp-${process.pid}-${Date.now()}`;try{W(t,n,{encoding:"utf8",mode:o,flag:"wx"}),A(t,o),M(t,e),A(e,o)}catch(s){try{V(t)}catch{}throw s}}function X(e,n){if(!n.exists){try{V(e)}catch{}return}D(e,n.text,n.mode)}async function ee(e,n,o,t){let s=Z(e);try{Q(e,n)}catch{return{ok:!1,stage:"write",rolledBack:!0,daemonRestored:!0}}if(o!=="managed")return{ok:!0,stage:"write"};let r;try{r=t?await t():{ok:!1}}catch{r={ok:!1}}if(r.ok)return{ok:!0,stage:"apply"};try{X(e,s)}catch{return{ok:!1,stage:"rollback",rolledBack:!1,daemonRestored:!1}}let i;try{i=t?await t():{ok:!1}}catch{i={ok:!1}}return{ok:!1,stage:i.ok?"apply":"rollback",rolledBack:!0,daemonRestored:i.ok}}function P(e,n){let o={...e},t=[["provider",n.OURS_STT_PROVIDER],["apiKey",n.OURS_STT_API_KEY],["model",n.OURS_STT_MODEL],["baseUrl",n.OURS_STT_BASE_URL],["language",n.OURS_STT_LANGUAGE]];for(let[s,r]of t)r?.trim()&&(o[s]=r.trim());return o}function te(e){let n=e.trim();return n.length<8?{ok:!1,reason:"API key must contain at least 8 characters"}:/[\s\x00-\x1f\x7f]/.test(n)?{ok:!1,reason:"API key must not contain whitespace or control characters"}:{ok:!0,value:n}}function ne(){try{return U("/dev/tty","r+")}catch{if(process.stdin.isTTY&&process.stdout.isTTY)try{return U("/dev/stdin","r+")}catch{}return null}}function f(e,n){q(e,n)}function _(e){let n=Buffer.alloc(1);try{return L(e,n,0,1,null)===1?n[0]:null}catch(o){throw o.code==="EINTR"?new l("cancel"):o}}function B(e){let n="";for(let o=0;o<12;o++){let t=_(e);if(t===null)break;let s=String.fromCharCode(t);if(n+=s,/[A-Za-z~]$/.test(n))break}return n}function N(e,n){let o=w("stty",["-g"],{stdio:[e,"pipe","ignore"],encoding:"utf8"}),t=(o.stdout||"").trim();if(o.status!==0||!t)throw new l("unavailable");if(w("stty",["-icanon","-echo","-isig","min","1","time","0"],{stdio:[e,"ignore","ignore"]}).status!==0)throw new l("unavailable");let r=!1,i=()=>{if(r)return;r=!0,w("stty",[t],{stdio:[e,"ignore","ignore"]}).status!==0&&w("stty",["sane"],{stdio:[e,"ignore","ignore"]})};process.once("exit",i);try{return n()}finally{process.removeListener("exit",i),i()}}function re(e,n,o,t){return N(e,()=>{f(e,n);let s="";for(;;){let i=_(e);if(i===null||i===4)throw new l("eof");if(i===3)throw new l("cancel");if(i===10||i===13){f(e,`
4
+ `);break}if(i===127||i===8){s.length&&(s=s.slice(0,-1),t||f(e,"\b \b"));continue}if(i===27){B(e);continue}if(i<32||s.length>=16384)continue;let a=String.fromCharCode(i);s+=a,t||f(e,a)}let r=s.trim();return r===""?o:r})}function k(e,n,o=""){f(e,n);let t=[],s=0;for(;;){let i=Buffer.alloc(1024),a;try{a=L(e,i,0,i.length,null)}catch(b){throw b.code==="EINTR"?new l("cancel"):b}if(a===0)throw new l("eof");let m=i.subarray(0,a).indexOf(10),S=m>=0?i.subarray(0,m):i.subarray(0,a);if(t.push(S),s+=S.length,s>16384)throw new Error("prompt input too long");if(m>=0)break}let r=Buffer.concat(t).toString("utf8").replace(/\r$/,"").trim();return r===""?o:r}function p(e,n,o="",t=!1){try{return re(e,n,o,t)}catch(s){if(s instanceof l&&s.reason==="unavailable"&&!t)return k(e,n,o);throw s}}function oe(e,n,o){let t=p(e,`${n} ${o?"[Y/n]":"[y/N]"} `,o?"y":"n");return/^y(?:es)?$/i.test(t)}function ie(e,n){let o=d.findIndex(t=>t.value===n);o<0&&(o=0);try{return N(e,()=>{f(e,`Choose one transcription provider (\u2191/\u2193 or j/k, then Enter; q cancels):
5
+ `);let t=!1,s=()=>{t&&f(e,`\x1B[${d.length}A`),t=!0,d.forEach((r,i)=>{f(e,`\r\x1B[K ${i===o?">":" "} ${i===o?"(*)":"( )"} ${r.label} \u2014 ${r.detail}
6
+ `)})};for(s();;){let r=_(e);if(r===null||r===4)throw new l("eof");if(r===3||r===113||r===81)throw new l("cancel");if(r===10||r===13)return f(e,`
7
+ `),d[o].value;if(r>=49&&r<=52)o=r-49;else if(r===107||r===75)o=(o-1+d.length)%d.length;else if(r===106||r===74)o=(o+1)%d.length;else if(r===27){let i=B(e);i==="[A"||i==="OA"?o=(o-1+d.length)%d.length:(i==="[B"||i==="OB")&&(o=(o+1)%d.length)}else continue;s()}})}catch(t){if(!(t instanceof l)||t.reason!=="unavailable")throw t;f(e,`Choose one transcription provider:
8
+ `),d.forEach((r,i)=>{f(e,` ${i+1}. ${r.label} \u2014 ${r.detail}
9
+ `)});let s=k(e,`Select 1-${d.length}: `);if(!/^[1-4]$/.test(s))throw new l("cancel");return d[Number(s)-1].value}}function se(e){let n=e.stt;return n&&typeof n=="object"&&!Array.isArray(n)?{...n}:{}}async function fe(e){let n=e.env??process.env,o=e.stdout??(i=>process.stdout.write(i)),t=(i="")=>o(`${i}
10
+ `),s=e.daemonState??"stopped",r=null;try{let i;try{i=z(e.configFile)}catch{return t(`voice setup: ${e.configFile} is not valid JSON; no changes made.`),1}let a=se(i),m=O(P(a,n)),S=n.OURS_STT_API_KEY?.trim()?"environment":a.apiKey?.trim()?"config":"missing";if(r=n.OURS_ASSUME_YES?null:ne(),t(`ours-mcp voice-setup \u2014 ${e.configFile}`),m.ready){if(t(`voice transcription is already ready (${m.provider}; API key from ${S}).`),r===null)return 0;if(!oe(r,"Change the current voice settings?",!1))return t("kept the current voice settings; no changes made."),0}else if(t("Voice transcription is not ready. This command keeps the provider key hidden."),r===null)return t("No interactive terminal is available; no changes made."),t("Run `ours-mcp voice-setup` in a terminal, or configure OURS_STT_* environment values."),0;t("");let b=String(n.OURS_STT_PROVIDER||a.provider||"").trim().toLowerCase(),g=ie(r,b),c=String(n.OURS_STT_MODEL||a.model||"").trim(),u=String(n.OURS_STT_BASE_URL||a.baseUrl||"").trim(),y=String(a.custom?.url||"").trim();g==="openai-compatible"?(u=p(r,`Provider /v1 base URL${u?` [${u}]`:""}: `,u),c=p(r,`Model name (sent verbatim)${c?` [${c}]`:""}: `,c)):g==="elevenlabs"?(c=p(r,`ElevenLabs model id${c?` [${c}]`:""}: `,c),u=p(r,`Custom base URL (Enter for provider default)${u?` [${u}]`:""}: `,u)):g==="deepgram"?(c=p(r,`Model (optional; Enter for provider default)${c?` [${c}]`:""}: `,c),u=p(r,`Custom base URL (optional)${u?` [${u}]`:""}: `,u)):(y=p(r,`Full transcription endpoint URL${y?` [${y}]`:""}: `,y),c=p(r,`Model (optional unless URL contains {model})${c?` [${c}]`:""}: `,c));let J=n.OURS_STT_API_KEY?.trim(),h=String(a.apiKey||"").trim();if(J)t("API key: using OURS_STT_API_KEY from the environment; it will not be copied to config.");else{let j=h?"Provider API key [configured; Enter keeps it]: ":"Provider API key (input hidden): ",x;try{x=p(r,j,h,!0)}catch(T){if(!(T instanceof l)||T.reason!=="unavailable")throw T;if(f(r,`
11
+ Secure hidden input is unavailable on this terminal.
12
+ `),f(r,`Visible fallback will echo the token on screen and may leave it in scrollback.
13
+ `),k(r,"Type SHOW to enter the token visibly, or press Enter to cancel: ")!=="SHOW")throw new l("cancel");x=k(r,"Provider API key (VISIBLE): ",h)}let R=te(x);if(!R.ok)return t(`Voice setup was not saved: ${R.reason}.`),1;h=R.value}let E={...a,provider:g,...h?{apiKey:h}:{},...c?{model:c}:{},...u?{baseUrl:u}:{},...g==="custom"&&y?{custom:{...a.custom??{},url:y}}:{}},$=O(P(E,n));if(!$.ready)return t(`Voice setup was not saved: ${$.reason}.`),1;if(e.dryRun)return t(`voice transcription would be configured (${g}); API key stays hidden.`),t("dry-run: config, daemon, and existing settings were not changed."),0;let F={...i,stt:E};s==="managed"&&t("Restarting ours-mcp to apply and verify voice transcription\u2026");let v=await ee(e.configFile,F,s,e.apply);return!v.ok&&v.stage==="write"?(t(`Could not write ${e.configFile}; the prior config is intact.`),1):s==="stopped"?(t(`voice transcription configured (${g}); API key saved in mode-0600 config.`),t("The daemon is stopped; run `ours-mcp start` to apply it."),0):s==="external"?(t(`voice transcription configured (${g}); API key saved in mode-0600 config.`),t("The daemon has no managed PID; restart its external launcher to apply the new settings."),0):v.ok?(t(`voice transcription: ready (${g}).`),t("API key saved in mode-0600 config and never displayed."),0):v.rolledBack?(t("Voice readiness check failed; restored the exact prior config."),v.daemonRestored?(t("The prior config and daemon state were restored; voice setup was not changed."),2):(t("The prior config is restored, but the daemon did not restart; run `ours-mcp status`."),2)):(t("Voice setup failed and automatic config rollback also failed; inspect the config before restarting."),2)}catch(i){return i instanceof l?i.reason==="cancel"?(t(""),t("voice setup cancelled; no configuration changes were made."),130):i.reason==="eof"?(t(""),t("voice setup ended at EOF; no configuration changes were made."),1):(t("Secure interactive input is unavailable on this terminal; no changes made."),1):(t("voice setup failed unexpectedly; no credential was displayed."),1)}finally{if(r!==null)try{K(r)}catch{}}}var pe=`ours-mcp voice-setup \u2014 configure voice transcription securely
14
+
15
+ Usage: ours-mcp voice-setup [--dry-run]
16
+
17
+ Interactively choose exactly one provider, collect provider-specific fields, and
18
+ read the provider API key with hidden input. The key is never accepted as a CLI
19
+ argument. Configuration is written atomically with mode 0600. When the managed
20
+ daemon is running, it is restarted and readiness-checked; a failure restores the
21
+ exact prior config.
22
+
23
+ --dry-run walk the prompts without writing config or restarting the daemon
24
+ --help show this help and exit
25
+
26
+ Headless automation remains environment-driven through OURS_STT_PROVIDER,
27
+ OURS_STT_API_KEY, OURS_STT_MODEL, OURS_STT_BASE_URL, and OURS_STT_LANGUAGE.
28
+ Exit 2 means restart/readiness failed after a write and rollback was attempted.`;export{d as VOICE_PROVIDER_CHOICES,pe as VOICE_SETUP_HELP,Q as atomicWriteVoiceConfig,fe as runVoiceSetup,ee as transactVoiceConfig};
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@ours.network/sdk",
3
+ "version": "0.1.1",
4
+ "types": "./dist/index.d.ts",
5
+ "type": "module",
6
+ "license": "FSL-1.1-Apache-2.0",
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./daemon": {
16
+ "types": "./dist/daemon.d.ts",
17
+ "default": "./dist/daemon.js"
18
+ },
19
+ "./connector": {
20
+ "types": "./dist/connector.d.ts",
21
+ "default": "./dist/connector.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "build": "node build.mjs",
33
+ "typecheck": "tsc -p tsconfig.json --noEmit",
34
+ "//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.",
35
+ "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/mufl-integrity.test.mjs && node test/verbatim-moves.test.mjs && node test/errors.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/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/mig1867-verify.test.mjs && node test/boot-smoke.test.mjs && node test/api-identity.test.mjs && node test/api-contacts.test.mjs && node test/api-messaging.test.mjs && node test/api-files.test.mjs && node test/daemon-routes.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/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/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"
36
+ },
37
+ "dependencies": {
38
+ "@adapt-toolkit/sdk": "0.10.12",
39
+ "@adapt-toolkit/sdk-native": "0.10.12"
40
+ },
41
+ "devDependencies": {
42
+ "@adapt-toolkit/broker": "0.10.12",
43
+ "@adapt-toolkit/mufl": "0.10.12",
44
+ "@types/node": "^20.14.0",
45
+ "esbuild": "^0.24.2",
46
+ "tsx": "^4.19.0",
47
+ "typescript": "^5.5.4"
48
+ }
49
+ }