From be17544f2db178509c16d4b0145ab88a230a45dd Mon Sep 17 00:00:00 2001 From: PeymanHonarjoo Date: Sat, 10 Oct 2026 15:12:57 +0330 Subject: [PATCH] feat(voice): enhance streaming engine and improve system reliability Improve the PCM playback worklet with robust resampling and buffer management. Refactor the voice-stream service for better session teardown and error handling. Fix authentication issues by enabling credentials in HttpService and using relative URLs. Add Jalali date support and an AI model configuration tab in settings. Enhance diagnostics for voice transport and the audio engine. --- .kilo/skills/ponytail/SKILL.md | 90 ++++++ package-lock.json | 191 +++++++---- package.json | 3 + proxy.conf.json | 11 +- .../assets/worklets/pcm-playback.worklet.js | 169 +++++++--- src/app/app.routes.ts | 4 +- src/app/layout/layout.component.ts | 8 +- src/app/pages/call-center/call-center.page.ts | 14 +- .../chat-questions/chat-questions.page.css | 2 +- .../chat-questions/chat-questions.page.html | 24 +- .../chat-questions.page.spec.ts | 2 +- src/app/pages/settings/settings.page.css | 20 +- src/app/pages/settings/settings.page.html | 299 ++++++++++++------ src/app/pages/settings/settings.page.ts | 21 +- src/app/pages/wallboard/wallboard.page.html | 3 +- src/app/services/http-request/http.service.ts | 26 +- .../voice-stream/pcm-playback.worklet.spec.ts | 225 +++++++++++++ .../voice-stream/voice-api.service.ts | 63 +++- .../voice-audio-engine.service.ts | 35 +- .../voice-stream/voice-stream.service.spec.ts | 84 ++++- .../voice-stream/voice-stream.service.ts | 250 +++++++++++---- .../voice-stream/voice-stream.types.ts | 8 +- .../services/voice-stream/voice-transport.ts | 69 +++- src/app/shared/styles/demo-page.css | 15 +- .../ai-model-config-card.component.css | 8 +- .../ai-model-config-card.component.ts | 98 +++--- .../shared/ui/sidebar/sidebar.component.ts | 6 +- src/app/shared/utils/format.util.ts | 11 + src/index.html | 2 +- src/styles.css | 8 + 30 files changed, 1379 insertions(+), 390 deletions(-) create mode 100644 .kilo/skills/ponytail/SKILL.md create mode 100644 src/app/services/voice-stream/pcm-playback.worklet.spec.ts diff --git a/.kilo/skills/ponytail/SKILL.md b/.kilo/skills/ponytail/SKILL.md new file mode 100644 index 0000000..069d745 --- /dev/null +++ b/.kilo/skills/ponytail/SKILL.md @@ -0,0 +1,90 @@ +--- +name: ponytail +description: > + Forces the laziest solution that actually works, simplest, shortest, most + minimal. Channels a senior dev who has seen everything: question whether the + task needs to exist at all (YAGNI), reach for the standard library before + custom code, native platform features before dependencies, one line before + fifty. Use whenever the user says "ponytail", "be lazy", "lazy mode", + "simplest solution", "minimal solution", "yagni", "do less", or "shortest + path", and whenever they complain about over-engineering, bloat, boilerplate, + or unnecessary dependencies. +license: MIT +metadata: + category: development + source: + repository: 'https://github.com/DietrichGebert/ponytail' + path: skills/ponytail + commit: a945778b4a73b0b78c3c781a594b62cd3a324637 +--- + +# Ponytail + +You are a lazy senior developer. Lazy means efficient, not careless. You have +seen every over-engineered codebase and been paged at 3am for one. The best +code is the code never written. + +## Persistence + +ACTIVE EVERY RESPONSE. No drift back to over-building. Still active if +unsure. Off only: "stop ponytail" / "normal mode". + +## The ladder + +Stop at the first rung that holds: + +1. **Does this need to exist at all?** Speculative need = skip it, say so in one line. (YAGNI) +2. **Stdlib does it?** Use it. +3. **Native platform feature covers it?** `` over a picker lib, CSS over JS, DB constraint over app code. +4. **Already-installed dependency solves it?** Use it. Never add a new one for what a few lines can do. +5. **Can it be one line?** One line. +6. **Only then:** the minimum code that works. + +The ladder is a reflex, not a research project. Two rungs work → take the +higher one and move on. The first lazy solution that works is the right one. + +## Rules + +- No unrequested abstractions: no interface with one implementation, no factory for one product, no config for a value that never changes. +- No boilerplate, no scaffolding "for later", later can scaffold for itself. +- Deletion over addition. Boring over clever, clever is what someone decodes at 3am. +- Fewest files possible. Shortest working diff wins. +- Complex request? Ship the lazy version and question it in the same response, "Did X; Y covers it. Need full X? Say so." Never stall on an answer you can default. +- Two stdlib options, same size? Take the one that's correct on edge cases. Lazy means writing less code, not picking the flimsier algorithm. +- Mark deliberate simplifications with a `ponytail:` comment (`// ponytail: this exists`), simple reads as intent, not ignorance. Shortcut with a known ceiling (global lock, O(n²) scan, naive heuristic)? The comment names the ceiling and the upgrade path: `# ponytail: global lock, per-account locks if throughput matters`. + +## Output + +Code first. Then at most three short lines: what was skipped, when to add it. +No essays, no feature tours, no design notes. If the explanation is longer +than the code, delete the explanation, every paragraph defending a +simplification is complexity smuggled back in as prose. Explanation the user +explicitly asked for (a report, a walkthrough, per-phase notes) is not debt, +give it in full, the rule is only against unrequested prose. + +Pattern: `[code] → skipped: [X], add when [Y].` + +## When NOT to be lazy + +Never simplify away: input validation at trust boundaries, error handling +that prevents data loss, security measures, accessibility basics, anything +explicitly requested. User insists on the full version → build it, no +re-arguing. + +Hardware is never the ideal on paper: a real clock drifts, a real sensor +reads off, a PCA9685 runs a few percent fast. Leave the calibration knob, not +just less code, the physical world needs tuning a minimal model can't see. + +Lazy code without its check is unfinished. Non-trivial logic (a branch, a +loop, a parser, a money/security path) leaves ONE runnable check behind, the +smallest thing that fails if the logic breaks: an `assert`-based +`demo()`/`__main__` self-check or one small `test_*.py`. No frameworks, no +fixtures, no per-function suites unless asked. Trivial one-liners need no +test, YAGNI applies to tests too. + +## Boundaries + +Ponytail governs what you build, not how you talk (pair with Caveman for +terse prose). "stop ponytail" / "normal mode": revert. + +The shortest path to done is the right path. diff --git a/package-lock.json b/package-lock.json index bc4c4d9..ea0d976 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@popperjs/core": "^2.11.8", "ag-grid-angular": "^36.2.0", "ag-grid-community": "^36.2.0", + "moment-jalaali": "^0.10.5", "ngx-toastr": "^14.3.0", "papaparse": "^5.7.0", "rxjs": "~7.8.0", @@ -34,6 +35,8 @@ "@playwright/test": "^1.63.0", "@tailwindcss/postcss": "^4.3.3", "@types/audioworklet": "^0.0.100", + "@types/moment": "^2.11.29", + "@types/moment-jalaali": "^0.7.9", "@types/papaparse": "^5.5.2", "@types/three": "^0.186.0", "jsdom": "^30.1.2", @@ -541,7 +544,6 @@ "version": "20.3.33", "resolved": "https://registry.npmjs.org/@angular/compiler-cli/-/compiler-cli-20.3.33.tgz", "integrity": "sha512-NKE4N4ssXysHLJQ7xVqvAv/yf3JfJxaFz5H+Ue+EnYToAmTxXe7uyt2MPRIydef/H63n7O9uphVp5P5GkRxVuA==", - "dev": true, "license": "MIT", "dependencies": { "@babel/core": "7.29.7", @@ -613,6 +615,31 @@ "rxjs": "^6.5.3 || ^7.4.0" } }, + "node_modules/@angular/localize": { + "version": "20.3.33", + "resolved": "https://registry.npmjs.org/@angular/localize/-/localize-20.3.33.tgz", + "integrity": "sha512-2Rr23xegscTKOwSNJE4O/vqpK+owLPH6Z7MojctI/cIcu5RSE7RVw/r9Hs5XS4fhr81yHRWp/jRFQzzm3i6F4g==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/core": "7.29.7", + "@types/babel__core": "7.20.5", + "tinyglobby": "^0.2.12", + "yargs": "^18.0.0" + }, + "bin": { + "localize-extract": "tools/bundles/src/extract/cli.js", + "localize-migrate": "tools/bundles/src/migrate/cli.js", + "localize-translate": "tools/bundles/src/translate/cli.js" + }, + "engines": { + "node": "^20.19.0 || ^22.12.0 || >=24.0.0" + }, + "peerDependencies": { + "@angular/compiler": "20.3.33", + "@angular/compiler-cli": "20.3.33" + } + }, "node_modules/@angular/platform-browser": { "version": "20.3.33", "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-20.3.33.tgz", @@ -710,7 +737,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", "integrity": "sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==", - "dev": true, "license": "MIT", "dependencies": { "@babel/helper-validator-identifier": "^7.29.7", @@ -725,7 +751,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.29.7.tgz", "integrity": "sha512-locTkQyKvwIEgBzVrn8693ebc97F2U8ZHjbXwDXJ5Fn2TCpNwTlKcaKLkdHop5c/icOFE7qt7Q9JC5hnKNa6Gg==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -735,7 +760,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.7.tgz", "integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==", - "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.29.7", @@ -766,14 +790,12 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", - "dev": true, "license": "MIT" }, "node_modules/@babel/core/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", - "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -783,7 +805,6 @@ "version": "7.29.8", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.29.8.tgz", "integrity": "sha512-gZbepsdh3WDtgZKWL+vTPh71LSBrm/Y4/QDZBVCcYfmeTEEuoOYwlSy+G1StfJg+/Zy550u/3TATbm7qDbbMtg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/parser": "^7.29.8", @@ -813,7 +834,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.29.7.tgz", "integrity": "sha512-wem6WaBj4NaVYVdNhLPPVacES6ZJ+KBBfSkTMD3YZxbP3rm3Di85tJU5ljaUNhaOynt+Aj0xruhYuzQBt8n71g==", - "dev": true, "license": "MIT", "dependencies": { "@babel/compat-data": "^7.29.7", @@ -830,7 +850,6 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", - "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -840,7 +859,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.29.7.tgz", "integrity": "sha512-3nQVUAtvkKH9zahfWgw96Jc/uFOmjACE1kQz82E2lqWmHBgjzbNlsC22nuQTfahmWeQtTq5nQ/4Nnd2A1wj4zA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -850,7 +868,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.29.7.tgz", "integrity": "sha512-ejHwrQQYcm9xnTivShn2IDOlIzInN34AXskvq9QicvCtEzq1Vzclu/tKF8Jq1Cg8JG2GL6/EmjgsCT7lXepE3g==", - "dev": true, "license": "MIT", "dependencies": { "@babel/traverse": "^7.29.7", @@ -864,7 +881,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.29.7.tgz", "integrity": "sha512-UPUVSyXbOh627KiCIGQSgwWzGeBKLkaJ9PJEdrngIwMSzxLR4jS4+f1f1jb7VzBbg8nFLaYotvVPFCTqdrmTAg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/helper-module-imports": "^7.29.7", @@ -895,7 +911,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.7.tgz", "integrity": "sha512-Pb5ijPrZ89GDH8223L4UP8i6QApWxs04RbPQJTeWDV0/keR2E36MeKnyr6LYmUUvqRRI+Iv87SuF1W6ErINzYw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -905,7 +920,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.29.7.tgz", "integrity": "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -915,7 +929,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.29.7.tgz", "integrity": "sha512-N9ZErrD+yW5geCDtBqnOoxmR8+tNKiGuxKlDpuJxfsqpa2dFcexaziGAE/qoHLiDDreVNMupxGmSoNlyvsA3gw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -925,7 +938,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.29.7.tgz", "integrity": "sha512-1k2lAGRMfHTcwuNYcCNUmaUffmQv8KWMfh2iJUUeRlwlwH4FdNG7mfPI10NPfLHJFThE4Tyr4mv7kTNZOiPuBg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/template": "^7.29.7", @@ -939,7 +951,6 @@ "version": "7.29.9", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.9.tgz", "integrity": "sha512-CjXrNHTnvqBVqHgdBysY3vk2T8tpJHb5/RMeHJBTyVa9xgugCB0CJTx/3oO8RV2QRQP391RWpB7D6hLjm8V9uA==", - "dev": true, "license": "MIT", "dependencies": { "@babel/types": "^7.29.8" @@ -955,7 +966,6 @@ "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.29.7.tgz", "integrity": "sha512-puq+Gf35oI24FeN11LkoUQFqv9uwNeWpxXZi/Ji3rRIoKAzKnxRaZ+Gkj0vKS9ZCiTESfng1N9LyOyXvo+m+Gg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.29.7", @@ -970,7 +980,6 @@ "version": "7.29.8", "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.29.8.tgz", "integrity": "sha512-I5z7H3bf/41ktsNVLtpN0wAa336HkqIHQ5BuPLEhTkt1jVSyZpeNKIzTgEWmlxjdg81R0IgUCcaE+Ok3NvrfZg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.29.7", @@ -989,7 +998,6 @@ "version": "7.29.8", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.8.tgz", "integrity": "sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==", - "dev": true, "license": "MIT", "dependencies": { "@babel/helper-string-parser": "^7.29.7", @@ -2019,7 +2027,6 @@ "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", @@ -2030,7 +2037,6 @@ "version": "2.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", @@ -2041,7 +2047,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.0.0" @@ -2051,14 +2056,12 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", - "dev": true, "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.31", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", - "dev": true, "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", @@ -4100,6 +4103,51 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/@types/babel__core": { + "version": "7.20.5", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", + "integrity": "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/parser": "^7.20.7", + "@babel/types": "^7.20.7", + "@types/babel__generator": "*", + "@types/babel__template": "*", + "@types/babel__traverse": "*" + } + }, + "node_modules/@types/babel__generator": { + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.27.0.tgz", + "integrity": "sha512-ufFd2Xi92OAVPYsy+P4n7/U7e68fex0+Ee8gSG9KX7eo084CWiQ4sdxktvdl0bOPupXtVJPY19zk6EwWqUQ8lg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__template": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.4.tgz", + "integrity": "sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/parser": "^7.1.0", + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__traverse": { + "version": "7.28.0", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.28.0.tgz", + "integrity": "sha512-8PvcXf70gTDZBgt9ptxJ8elBeBjcLOAcOtoO/mPJjtji1+CdGbHgm77om1GrsPxsiE+uXIpNSK64UYaIwQXd4Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/types": "^7.28.2" + } + }, "node_modules/@types/chai": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", @@ -4125,6 +4173,23 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/moment": { + "version": "2.11.29", + "resolved": "https://registry.npmjs.org/@types/moment/-/moment-2.11.29.tgz", + "integrity": "sha512-D5WIgbLYQzvgfsDnBhZFSTnt/BjGPOE+Jsh3k1BYYijJAkrn7ceeLvU4jtjKKXXuXN42O3ARlU4D/P9ezbQYFA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/moment-jalaali": { + "version": "0.7.9", + "resolved": "https://registry.npmjs.org/@types/moment-jalaali/-/moment-jalaali-0.7.9.tgz", + "integrity": "sha512-gsDOoAzRnCfQTbfdlUrCvX6R0wIto6CvwfvV2C3j4qJLK+DEiTK8Rl/xlOCBO9C6qeUfX8oyZ2UfjnXJTOvHSA==", + "dev": true, + "license": "MIT", + "dependencies": { + "moment": ">=2.14.0" + } + }, "node_modules/@types/node": { "version": "26.6.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.4.tgz", @@ -4460,7 +4525,6 @@ "version": "6.4.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.4.0.tgz", "integrity": "sha512-KzTVk2tCWAHtYrvvvaP8bJKJq2pVinhLcGEQdtLIYPbmNGNyYe8QwNaTUYQp2J7/vIsUKt5QCqAfUkYyG9DkOw==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -4473,7 +4537,6 @@ "version": "6.2.3", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz", "integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -4496,7 +4559,6 @@ "version": "2.11.27", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.27.tgz", "integrity": "sha512-ElY12DaROGuan+lMmZ8Cvo/ZUbXPe7Enc/9VU/b1T3Kp4dwytRcNdR8DoSJN5SNJT/CuvcCA0DHDVmMOCePdRQ==", - "dev": true, "license": "Apache-2.0", "bin": { "baseline-browser-mapping": "dist/cli.cjs" @@ -4585,7 +4647,6 @@ "version": "4.29.3", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.29.3.tgz", "integrity": "sha512-1R4kiYKXGViqEN0CnoDrXc1StD9niAwu+j2dukWzrD4bJgsD4lDmEp0CRbc6E/vYJIfTHwPmwyaKtVSudICdPA==", - "dev": true, "funding": [ { "type": "opencollective", @@ -4766,7 +4827,6 @@ "version": "1.0.30001814", "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001814.tgz", "integrity": "sha512-/Uaf1lAzr59XcMpW0o96WoEfr+VXK2OX4U9AgFoiSHsVJ4HppnIFUjtYzsyDH2+tgANaQb2/oxYGwCPapN1FpA==", - "dev": true, "funding": [ { "type": "opencollective", @@ -4834,7 +4894,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", - "dev": true, "license": "MIT", "dependencies": { "readdirp": "^4.0.1" @@ -4916,7 +4975,6 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-9.0.1.tgz", "integrity": "sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w==", - "dev": true, "license": "ISC", "dependencies": { "string-width": "^7.2.0", @@ -4931,7 +4989,6 @@ "version": "9.0.2", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.2.tgz", "integrity": "sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^6.2.1", @@ -5000,7 +5057,6 @@ "version": "1.9.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz", "integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==", - "dev": true, "license": "MIT" }, "node_modules/cookie": { @@ -5118,7 +5174,6 @@ "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", - "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -5254,14 +5309,12 @@ "version": "1.5.444", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.444.tgz", "integrity": "sha512-5ss/uJfoDYDHT0lfJzT6FbcskIzROIOPf0BbbFkGcvDzoJU7i//9GDrwwIHQVmIsrAGiF3ihpADBRIsrEFt1rQ==", - "dev": true, "license": "ISC" }, "node_modules/emoji-regex": { "version": "10.6.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.6.0.tgz", "integrity": "sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==", - "dev": true, "license": "MIT" }, "node_modules/encodeurl": { @@ -5410,7 +5463,6 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -5575,7 +5627,6 @@ "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", - "dev": true, "license": "MIT", "engines": { "node": ">=12.0.0" @@ -5680,7 +5731,6 @@ "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", - "dev": true, "license": "MIT", "engines": { "node": ">=6.9.0" @@ -5690,7 +5740,6 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true, "license": "ISC", "engines": { "node": "6.* || 8.* || >= 10.*" @@ -5700,7 +5749,6 @@ "version": "1.7.0", "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.7.0.tgz", "integrity": "sha512-XjH1AECxf0giL2V1aU8vKyRR2ppRUb5c0EvT7zuJTokQ74bNo52zOtghqdWIqrhUD79fo3x0WfKZdOqxF6LG1Q==", - "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -6177,6 +6225,12 @@ "node": ">=10" } }, + "node_modules/jalaali-js": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/jalaali-js/-/jalaali-js-1.2.8.tgz", + "integrity": "sha512-Jl/EwY84JwjW2wsWqeU4pNd22VNQ7EkjI36bDuLw31wH98WQW4fPjD0+mG7cdCK+Y8D6s9R3zLiQ3LaKu6bD8A==", + "license": "MIT" + }, "node_modules/jiti": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz", @@ -6201,7 +6255,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true, "license": "MIT" }, "node_modules/jsdom": { @@ -6268,7 +6321,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", - "dev": true, "license": "MIT", "bin": { "jsesc": "bin/jsesc" @@ -6305,7 +6357,6 @@ "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", - "dev": true, "license": "MIT", "bin": { "json5": "lib/cli.js" @@ -6775,7 +6826,6 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", - "dev": true, "license": "ISC", "dependencies": { "yallist": "^3.0.2" @@ -7049,6 +7099,38 @@ "node": ">= 18" } }, + "node_modules/moment": { + "version": "2.31.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.31.0.tgz", + "integrity": "sha512-0acOTfMiWOheYS4eoWb80yYMb/JLvVv9SHbs2PehaDzfUG0Bw855SKyk0IKTnPGa5+U2bmi3W68l1+sGLX/pvw==", + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/moment-jalaali": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/moment-jalaali/-/moment-jalaali-0.10.5.tgz", + "integrity": "sha512-Xp0FsC0+jWG89/xcOrL880f97Tq7197P3saoMAqSIaF8vKr4Atr9XKtIOREGHTLUjOzJksfTHhQgxMgUJQupuw==", + "license": "MIT", + "dependencies": { + "jalaali-js": "^1.2.8", + "moment": "^2.30.1", + "moment-timezone": "^0.6.2" + } + }, + "node_modules/moment-timezone": { + "version": "0.6.5", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.6.5.tgz", + "integrity": "sha512-KKzZAxGv2Qx4cnk6eSlvf4C+DLFW52vmMY5MN7UARY7GONbozkutylQG3DrrtmLCTXdQ5XZrqao9cI16bLFzXA==", + "license": "MIT", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/mrmime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", @@ -7063,7 +7145,6 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, "license": "MIT" }, "node_modules/msgpackr": { @@ -7263,7 +7344,6 @@ "version": "2.0.57", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.57.tgz", "integrity": "sha512-kQK9LGGFiHtrWiNhZtA7Qbw17AQz+dmsEKODRIVTXA9+e5MS/2gZEBhYJt13GrAz5/IOZKddH/0Z3TP/Zgo+yw==", - "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -7726,14 +7806,12 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "dev": true, "license": "ISC" }, "node_modules/picomatch": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", - "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -8004,7 +8082,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", - "dev": true, "license": "MIT", "engines": { "node": ">= 14.18.0" @@ -8018,7 +8095,6 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.2.tgz", "integrity": "sha512-urBwgfrvVP/eAyXx4hluJivBKzuEbSQs9rKWCrCkbSxNv8mxPcUZKeuoF3Uy4mJl3Lwprp6yy5/39VWigZ4K6Q==", - "dev": true, "license": "Apache-2.0" }, "node_modules/require-from-string": { @@ -8192,7 +8268,6 @@ "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", - "dev": true, "license": "ISC", "bin": { "semver": "bin/semver.js" @@ -8570,7 +8645,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", - "dev": true, "license": "MIT", "dependencies": { "emoji-regex": "^10.3.0", @@ -8588,7 +8662,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz", "integrity": "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^6.2.2" @@ -8705,7 +8778,6 @@ "version": "0.2.14", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz", "integrity": "sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==", - "dev": true, "license": "MIT", "dependencies": { "fdir": "^6.4.4", @@ -8872,7 +8944,7 @@ "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "dev": true, + "devOptional": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -8913,7 +8985,6 @@ "version": "1.3.3", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.3.3.tgz", "integrity": "sha512-pJ2sYawQS0R/WI928Gj5GlPhTGzbMelq0+4INtSYNDV9ErKJcX6xjGWkoG/VnB3dpUm00zALaqkrUD77pO5TDQ==", - "dev": true, "funding": [ { "type": "opencollective", @@ -9365,7 +9436,6 @@ "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, "license": "ISC", "engines": { "node": ">=10" @@ -9375,14 +9445,12 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", - "dev": true, "license": "ISC" }, "node_modules/yargs": { "version": "18.0.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-18.0.0.tgz", "integrity": "sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg==", - "dev": true, "license": "MIT", "dependencies": { "cliui": "^9.0.1", @@ -9400,7 +9468,6 @@ "version": "22.0.0", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-22.0.0.tgz", "integrity": "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw==", - "dev": true, "license": "ISC", "engines": { "node": "^20.19.0 || ^22.12.0 || >=23" diff --git a/package.json b/package.json index d33b21f..a68b280 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@popperjs/core": "^2.11.8", "ag-grid-angular": "^36.2.0", "ag-grid-community": "^36.2.0", + "moment-jalaali": "^0.10.5", "ngx-toastr": "^14.3.0", "papaparse": "^5.7.0", "rxjs": "~7.8.0", @@ -48,6 +49,8 @@ "@playwright/test": "^1.63.0", "@tailwindcss/postcss": "^4.3.3", "@types/audioworklet": "^0.0.100", + "@types/moment": "^2.11.29", + "@types/moment-jalaali": "^0.7.9", "@types/papaparse": "^5.5.2", "@types/three": "^0.186.0", "jsdom": "^30.1.2", diff --git a/proxy.conf.json b/proxy.conf.json index 3c6fb54..607df9e 100644 --- a/proxy.conf.json +++ b/proxy.conf.json @@ -1,7 +1,14 @@ { "/api": { - "target": "http://127.0.0.1:8080", + "target": "http://10.2.8.3:8080", + "secure": false, + "changeOrigin": true, "ws": true, - "changeOrigin": false + "logLevel": "debug" + }, + "/users": { + "target": "http://10.2.8.3:8080", + "secure": false, + "changeOrigin": true } } diff --git a/public/assets/worklets/pcm-playback.worklet.js b/public/assets/worklets/pcm-playback.worklet.js index 596676a..8e09667 100644 --- a/public/assets/worklets/pcm-playback.worklet.js +++ b/public/assets/worklets/pcm-playback.worklet.js @@ -1,40 +1,57 @@ /** * Streaming PCM16 playback (contract: 24 kHz mono PCM16LE output, no WAV header). * - * Bounded playout queue: at most BOUND_SAMPLES (96,000 bytes) of source audio is admitted. - * When it fills, the processor reports `overflow` and the call must fail safely — PCM is - * never silently dropped to keep the same context alive. + * Bounded playout queue. The cap is on OUTSTANDING SOURCE PCM — BOUND_BYTES (96,000 bytes + * = 48,000 source samples ≈ 2 s at 24 kHz mono PCM16) — and each stage uses ONE unit + * consistently: + * admission + progress are booked in SOURCE samples (the contract/wire unit); + * the ring stores the RESAMPLED OUTPUT samples the AudioContext actually consumes. + * The output ring is sized to hold the source bound at the worst-case ratio + * (source bound ÷ ratio), so the SAME 2 s source cap holds at any real context rate + * (24k / 44.1k / 48k …) without widening the source limit, suppressing overflow or + * silently dropping PCM. If the queue fills anyway the processor posts `overflow` and the + * call fails safely. * - * Real playback progress: `played_ms` is computed from the source samples actually - * consumed by `process()` per audio_ref (never an elapsed timer), kept cumulative per ref - * and reported roughly 4×/s, on ref changes, and on clear/flush/idle — so the main thread - * can send the contract's `playback_progress` control message. + * Real playback progress: played_ms for a server audio_ref is the cumulative SOURCE + * samples of THAT ref actually consumed by process(), never a timer. Queued audio keeps + * its own audio_ref when a different ref arrives (a FIFO of per-ref source spans), so + * progress is never credited to the wrong turn. Reported ~4×/s, on ref completion, and on + * clear/flush/idle, so the main thread can send the contract's playback_progress message. * * Messages in: { type: 'push', pcm: ArrayBuffer (Int16 mono), sampleRate, audioRef } * { type: 'clear' } barge-in: drop everything immediately * { type: 'flush' } end of turn: play what is left, then report 'idle' * Messages out: { type: 'progress', audioRef, playedMs } - * { type: 'idle' } buffer ran dry after playing + * { type: 'idle' } buffer ran dry after playing * { type: 'overflow' } bounded queue filled — caller fails the session safely */ -const BOUND_BYTES = 96000; // contract cap for the playback queue +const BOUND_BYTES = 96000; // contract cap on outstanding SOURCE PCM16 +const RESAMPLE_MARGIN = 64; // slack for fractional-boundary rounding (never widens the source bound) const REPORT_INTERVAL_MS = 250; class PcmPlaybackProcessor extends AudioWorkletProcessor { constructor() { super(); - this.capacity = Math.floor(BOUND_BYTES / 2); // source samples (PCM16) + this.sourceCapacity = Math.floor(BOUND_BYTES / 2); // 48,000 SOURCE samples (the admission bound) + this.ratio = 1; // SOURCE samples per OUTPUT sample (resolved on first push) + this.sized = false; // true once the output ring matches the real context rate + this.capacity = this.sourceCapacity; // OUTPUT slots currently allocated (grows for upsampling) this.buf = new Float32Array(this.capacity); this.r = 0; this.w = 0; - this.count = 0; + this.count = 0; // OUTPUT samples currently queued + this.queuedSource = 0; // SOURCE samples currently queued (the admission bound unit) this.prebuffer = Math.floor(sampleRate * 0.08); // jitter buffer before (re)starting this.started = false; this.prev = 0; this.pos = 1; - this.ratio = 1; // source samples per output sample, set per push - this.currentRef = null; - this.refPlayedSamples = new Map(); // cumulative consumed source samples per audio_ref + // Per-audio_ref attribution. `refQueue` keeps the still-queued SOURCE span of each ref + // (merged per ref so it stays ≤ the number of turns); `refPlayedSamples` keeps each + // ref's cumulative consumed source. Together they tie queued audio to its own ref and + // keep progress cumulative and correct across ref changes. + this.refQueue = []; // [{ ref, src }] src = remaining SOURCE samples of that ref + this.refPlayedSamples = new Map(); + this.playingRef = null; // ref currently being consumed / reported this.unreportedSamples = 0; this.overflowPosted = false; this.port.onmessage = (e) => { @@ -46,18 +63,36 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor { }; } + /** Resolve the source→output ratio and size the output ring to hold the source bound. */ + configure(ratio) { + if (this.sized && ratio === this.ratio) return; + this.ratio = ratio > 0 ? ratio : 1; + const need = Math.ceil(this.sourceCapacity / this.ratio) + RESAMPLE_MARGIN; + // Only grow while the ring is empty (first push): never drop queued audio. + if (need > this.capacity && this.count === 0) { + this.capacity = need; + this.buf = new Float32Array(this.capacity); + this.r = 0; + this.w = 0; + } + this.sized = true; + } + clear() { + this.reportFinal(); // final cumulative report for the interrupted ref this.r = this.w = this.count = 0; + this.queuedSource = 0; + this.refQueue.length = 0; this.started = false; this.prev = 0; this.pos = 1; - this.reportProgress(true); // final report for the interrupted ref + this.playingRef = null; } flush() { if (this.count === 0) { this.started = false; - this.reportProgress(true); + this.reportFinal(); this.port.postMessage({ type: 'idle' }); } else { this.started = true; // short tail: do not wait for the prebuffer @@ -68,16 +103,26 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor { const n = int16.length; if (!n) return; - // Bounded queue: admitting this chunk past the cap is a safe failure, not a silent drop. - if (this.count + n > this.capacity) { - if (!this.overflowPosted) { - this.overflowPosted = true; - this.port.postMessage({ type: 'overflow' }); - } - return; - } + const ratio = srcRate / sampleRate; // SOURCE samples per OUTPUT sample + this.configure(ratio); + + // OUTPUT samples this chunk will add — the exact count the resample loop performs. + const produced = this.pos < n ? Math.ceil((n - this.pos) / this.ratio) : 0; + + // Bounded queue — two consistent guards, each in its own unit: + // 1) SOURCE bound: the contract 96,000-byte cap, invariant across context rates. + if (this.queuedSource + n > this.sourceCapacity) return this.overflow(); + // 2) OUTPUT storage: never let the ring overrun because a chunk resampled larger. + if (this.count + produced > this.capacity) return this.overflow(); + + this.queuedSource += n; + + // Keep the audio_ref of the queued source span so consumption is credited correctly + // even when the next ref arrives while this one is still playing. + const last = this.refQueue[this.refQueue.length - 1]; + if (last && last.ref === audioRef) last.src += n; + else this.refQueue.push({ ref: audioRef, src: n }); - this.ratio = srcRate / sampleRate; // source samples per output sample const src = new Float32Array(n + 1); src[0] = this.prev; for (let i = 0; i < n; i++) src[i + 1] = int16[i] / 32768; @@ -91,15 +136,19 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor { } this.prev = src[n]; this.pos = pos - n; + } - if (audioRef !== this.currentRef) { - this.reportProgress(true); // final report for the ref that just ended - this.currentRef = audioRef; - this.reportProgress(true); + overflow() { + if (!this.overflowPosted) { + this.overflowPosted = true; + this.port.postMessage({ type: 'overflow' }); } } write(v) { + // Defense in depth: admission already reserves the room, so this never discards in + // normal flow — but it guarantees the ring is never overwritten nor exceeds capacity. + if (this.count >= this.capacity) return; this.buf[this.w] = v; this.w = (this.w + 1) % this.capacity; this.count++; @@ -123,20 +172,15 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor { ch0[i] = 0; } } - if (this.currentRef && played > 0) { - // Convert consumed output samples back to contract (source) samples. - const consumed = played * this.ratio; - const ref = this.currentRef; - this.refPlayedSamples.set(ref, (this.refPlayedSamples.get(ref) ?? 0) + consumed); - this.unreportedSamples += consumed; - const srcRate = this.ratio * sampleRate; - if ((this.unreportedSamples / srcRate) * 1000 >= REPORT_INTERVAL_MS) { - this.reportProgress(false); - } + if (played > 0) { + const consumedSource = played * this.ratio; // OUTPUT played → SOURCE consumed + this.queuedSource = Math.max(0, this.queuedSource - consumedSource); + this.consumeSpans(consumedSource); + this.reportCadence(); } if (this.count === 0) { this.started = false; - this.reportProgress(true); + this.reportFinal(); this.port.postMessage({ type: 'idle' }); } } else { @@ -147,14 +191,49 @@ class PcmPlaybackProcessor extends AudioWorkletProcessor { return true; } - reportProgress(force) { + /** Draw `amount` SOURCE samples off the front of the ref FIFO, crediting each ref. */ + consumeSpans(amount) { + while (amount > 1e-6 && this.refQueue.length) { + const span = this.refQueue[0]; + const take = amount < span.src ? amount : span.src; + span.src -= take; + amount -= take; + this.creditRef(span.ref, take); + if (span.src <= 1e-6) { + this.refQueue.shift(); + this.postProgress(span.ref); // ref finished: post its final cumulative before the next ref + } + } + } + + creditRef(ref, sourceSamples) { + this.refPlayedSamples.set(ref, (this.refPlayedSamples.get(ref) ?? 0) + sourceSamples); + this.playingRef = ref; + this.unreportedSamples += sourceSamples; + } + + /** Final cumulative report for the ref currently playing (interruption / drain / clear). */ + reportFinal() { this.unreportedSamples = 0; - const ref = this.currentRef; - if (!ref) return; + if (!this.playingRef) return; + this.postProgress(this.playingRef); + } + + /** Cadence report for the ref currently playing (~REPORT_INTERVAL_MS of consumed source). */ + reportCadence() { + if (!this.playingRef) return; const srcRate = this.ratio * sampleRate; + if ((this.unreportedSamples / srcRate) * 1000 >= REPORT_INTERVAL_MS) { + this.reportFinal(); + } + } + + postProgress(ref) { const playedSamples = this.refPlayedSamples.get(ref) ?? 0; - const playedMs = Math.max(0, Math.round((playedSamples / srcRate) * 1000)); - if (playedMs <= 0) return; // nothing has actually been heard for this ref yet + const srcRate = this.ratio * sampleRate; + // floor: never claims an unheard millisecond; monotonic because it is cumulative. + const playedMs = Math.floor((playedSamples / srcRate) * 1000); + if (playedMs <= 0) return; this.port.postMessage({ type: 'progress', audioRef: ref, playedMs }); } } diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 5d2cfe7..5ac1f9c 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -32,7 +32,7 @@ export const routes: Routes = [ }, { path: '', - title: 'دستیار هوشمند', + title: 'دستیار هوش مصنوعی', component: HomePage, canActivate: [authGuard], }, @@ -68,7 +68,7 @@ export const routes: Routes = [ }, { path: 'chat-questions', - title: 'سوالات چت سایت و اپلیکیشن', + title: 'سوالات چت وب اپلیکیشن', component: ChatQuestionsPage, canActivate: [authGuard], }, diff --git a/src/app/layout/layout.component.ts b/src/app/layout/layout.component.ts index 8151fd0..09455f6 100644 --- a/src/app/layout/layout.component.ts +++ b/src/app/layout/layout.component.ts @@ -21,9 +21,13 @@ const BASE_NAV_ITEMS: NavItem[] = [ label: 'بازخوانی تماس‌ها از کال سنتر', route: '/call-center/calls', }, - { icon: 'M7.9 20A9 9 0 1 0 4 16.1L2 22Z', label: 'سوالات چت سایت و اپلیکیشن', route: '/chat-questions' }, { - icon: 'M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37.996.608 2.296.07 2.573-1.066zM15 12a3 3 0 11-6 0 0 3 3 0 016 0z', + icon: 'M7.9 20A9 9 0 1 0 4 16.1L2 22Z', + label: 'سوالات چت وب اپلیکیشن', + route: '/chat-questions', + }, + { + icon: 'M19.14 12.94c.04-.3.06-.61.06-.94s-.02-.64-.07-.94l2.03-1.58a.5.5 0 0 0 .12-.64l-1.92-3.32a.5.5 0 0 0-.61-.22l-2.39.96a7.3 7.3 0 0 0-1.63-.94l-.36-2.54A.49.49 0 0 0 13.87 2h-3.84a.49.49 0 0 0-.49.42L9.18 4.96c-.59.23-1.14.55-1.63.94l-2.39-.96a.5.5 0 0 0-.61.22L2.63 8.48a.5.5 0 0 0 .12.64l2.03 1.58a7 7 0 0 0 0 1.88l-2.03 1.58a.5.5 0 0 0-.12.64l1.92 3.32c.13.22.39.31.61.22l2.39-.96c.49.39 1.04.71 1.63.94l.36 2.54c.03.24.24.42.49.42h3.84c.25 0 .46-.18.49-.42l.36-2.54c.59-.23 1.14-.55 1.63-.94l2.39.96c.22.09.48 0 .61-.22l1.92-3.32a.5.5 0 0 0-.12-.64zM12 15.5a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z', label: 'تنظیمات', route: '/settings', }, diff --git a/src/app/pages/call-center/call-center.page.ts b/src/app/pages/call-center/call-center.page.ts index 63f0066..8b1e898 100644 --- a/src/app/pages/call-center/call-center.page.ts +++ b/src/app/pages/call-center/call-center.page.ts @@ -63,12 +63,12 @@ export class CallCenterPage { description: 'تماس‌هایی که هوش مصنوعی نتوانسته پاسخ دهد، به همراه سابقه گفتگو به کارشناس ارجاع می‌شود.', }, - { - id: 'sync', - icon: 'M21 12A9 9 0 0 0 6.6 7.5l-3 3m0 0 3 3-3-3Z', - title: 'همگام‌سازی وضعیت کارشناسان', - description: - 'حاضر بودن، مرخصی و خارج‌شدن کارشناسان بین برنامه و سامانه کال سنتر همگام می‌شود.', - }, + { + id: 'sync', + icon: 'M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8M21 3v5h-5M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16M8 16H3v5', + title: 'همگام‌سازی وضعیت کارشناسان', + description: + 'حاضر بودن، مرخصی و خارج‌شدن کارشناسان بین برنامه و سامانه کال سنتر همگام می‌شود.', +}, ]; } diff --git a/src/app/pages/chat-questions/chat-questions.page.css b/src/app/pages/chat-questions/chat-questions.page.css index 9e32c8f..f301e2f 100644 --- a/src/app/pages/chat-questions/chat-questions.page.css +++ b/src/app/pages/chat-questions/chat-questions.page.css @@ -1,4 +1,4 @@ -/* Page-specific styles for «سوالات چت سایت و اپلیکیشن» (shared chrome: shared/styles/demo-page.css) */ +/* Page-specific styles for «سوالات چت وب اپلیکیشن» (shared chrome: shared/styles/demo-page.css) */ .demo-list-main { flex: 1 1 22rem; diff --git a/src/app/pages/chat-questions/chat-questions.page.html b/src/app/pages/chat-questions/chat-questions.page.html index 66429fe..b4286d4 100644 --- a/src/app/pages/chat-questions/chat-questions.page.html +++ b/src/app/pages/chat-questions/chat-questions.page.html @@ -16,8 +16,8 @@
-

سوالات چت سایت و اپلیکیشن

-

پرسش‌های ثبت‌شده در چت سایت و اپلیکیشن موبایل

+

سوالات چت وب اپلیکیشن

+

پرسش‌های ثبت‌شده در چت وب اپلیکیشن

نمایشی @@ -53,9 +53,7 @@

نمونه پرسش‌های چت

-

- پرسش‌های دریافتی به همراه منبع ثبت و وضعیت پاسخ‌گویی. -

+

پرسش‌های دریافتی به همراه منبع ثبت و وضعیت پاسخ‌گویی.

داده نمونه
@@ -66,10 +64,18 @@

{{ item.question }}

- + {{ item.source }} - + {{ item.status }} {{ item.date }} @@ -98,8 +104,8 @@

پرسشی از چت ثبت نشده است

- پس از اتصال چت سایت و اپلیکیشن موبایل، پرسش‌های جدید کاربران به‌صورت خودکار در این صفحه نمایش - داده می‌شود تا برای آن‌ها پاسخ ثبت شود. + پس از اتصال چت سایت و اپلیکیشن موبایل، پرسش‌های جدید کاربران به‌صورت خودکار در این صفحه + نمایش داده می‌شود تا برای آن‌ها پاسخ ثبت شود.

diff --git a/src/app/pages/chat-questions/chat-questions.page.spec.ts b/src/app/pages/chat-questions/chat-questions.page.spec.ts index 87d2fb7..18bf8ab 100644 --- a/src/app/pages/chat-questions/chat-questions.page.spec.ts +++ b/src/app/pages/chat-questions/chat-questions.page.spec.ts @@ -30,7 +30,7 @@ describe('ChatQuestionsPage', () => { fixture.detectChanges(); const element: HTMLElement = fixture.nativeElement; - expect(element.querySelector('.demo-title')?.textContent?.trim()).toBe('سوالات چت سایت و اپلیکیشن'); + expect(element.querySelector('.demo-title')?.textContent?.trim()).toBe('سوالات چت وب اپلیکیشن'); expect(element.textContent).toContain('این بخش هنوز فعال نیست'); expect(element.textContent).toContain('داده نمونه'); diff --git a/src/app/pages/settings/settings.page.css b/src/app/pages/settings/settings.page.css index 3a29009..64cc985 100644 --- a/src/app/pages/settings/settings.page.css +++ b/src/app/pages/settings/settings.page.css @@ -261,11 +261,20 @@ .settings-tabs { flex-direction: column; } - + + .tab-divider { + display: none; + } + .tab-btn { justify-content: flex-start; padding: 1rem; } + + .tab-btn span { + white-space: normal; + text-align: right; + } .tab-btn .tab-indicator { display: none; @@ -458,6 +467,15 @@ background: var(--color-danger)/15; color: var(--color-danger); } + +/* Plain text colours for the document active flag (no badge background). */ +.doc-active { + color: var(--color-success); +} + +.doc-inactive { + color: var(--text-muted); +} .status-dot, .dot-queued, .dot-processing, diff --git a/src/app/pages/settings/settings.page.html b/src/app/pages/settings/settings.page.html index 74ee65e..11a7a82 100644 --- a/src/app/pages/settings/settings.page.html +++ b/src/app/pages/settings/settings.page.html @@ -69,6 +69,37 @@ > } + +
+ +
@@ -313,13 +344,16 @@ type="button" class="file-remove-btn p-1 text-[var(--text-muted)] rounded transition-colors hover:text-[var(--color-primary)]" (click)="retryUpload($index)" - aria-label="دوباره‌سعی آپلود" - title="دوباره‌سعی" + aria-label="تلاش مجدد آپلود" + title="تلاش مجدد" > - + + + + } @@ -332,12 +366,20 @@
@if (!isAdmin()) {
- - - - + + + + + +

مدیریت و لیست اسناد فقط برای ادمین‌ها در دسترس است.

} @@ -346,18 +388,19 @@

- - - - + class="w-5 h-5 text-primary" + viewBox="0 0 24 24" + fill="none" + stroke="currentColor" + stroke-width="2" + stroke-linecap="round" + stroke-linejoin="round" +> + + + + + اسناد آپلود شده

@@ -367,13 +410,20 @@ @if (documentsLoading() && documents().length === 0) {

- - - - - در حال بارگذاری اسناد... -
+ + در حال بارگذاری اسناد... +
} @if (documentsError() && documents().length === 0) { @@ -389,7 +439,7 @@
- @for (provider of providers(); track provider.value) { - - } - +
- +
- +
@if (connected() && config().apiKey) { - تنظیم شده — مقدار فعلی نمایش داده نمی‌شود + تنظیم شده — مقدار فعلی نمایش داده نمی‌شود } @else { - کلید در حافظه نگهداری می‌شود و ذخیره نمی‌شود + کلید در حافظه نگهداری می‌شود و ذخیره نمی‌شود }
@@ -131,14 +151,21 @@ interface ModelOption { [attr.aria-label]="'آدرس سرویس ' + title()" /> @if (!serviceUrlEditable()) { - آدرس استاندارد {{ config().provider === 'local' ? 'سرویس محلی' : 'سرویس' }} به‌صورت پیش‌فرض به کار می‌رود + آدرس استاندارد {{ config().provider === 'local' ? 'سرویس محلی' : 'سرویس' }} به‌صورت + پیش‌فرض به کار می‌رود }
- - + +
@@ -240,10 +267,7 @@ const DEFAULT_CONFIG_FOR: Record ({ value, label }); -const MODELS_BY_TASK: Record< - AiTask, - Partial> -> = { +const MODELS_BY_TASK: Record>> = { text: { openai: [ MODEL_OPTION('gpt-4o', 'GPT-4o'), diff --git a/src/app/shared/ui/sidebar/sidebar.component.ts b/src/app/shared/ui/sidebar/sidebar.component.ts index aa49e8b..4e35a4f 100644 --- a/src/app/shared/ui/sidebar/sidebar.component.ts +++ b/src/app/shared/ui/sidebar/sidebar.component.ts @@ -21,7 +21,7 @@ export interface ChatHistoryItem { imports: [CommonModule, RouterModule, CdkMenuModule], changeDetection: ChangeDetectionStrategy.OnPush, templateUrl: './sidebar.component.html', - styleUrl: './sidebar.component.css' + styleUrl: './sidebar.component.css', }) export class SidebarComponent { private readonly themeService = inject(ThemeService); @@ -56,11 +56,11 @@ export class SidebarComponent { }, { icon: 'M7.9 20A9 9 0 1 0 4 16.1L2 22Z', - label: 'سوالات چت سایت و اپلیکیشن', + label: 'سوالات چت وب اپلیکیشن', route: '/chat-questions', }, { - icon: 'M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.066 2.573c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.573 1.066c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.066-2.573c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.573-1.066zM15 12a3 3 0 11-6 0 3 3 0 016 0z', + icon: 'M19.14 12.94c.04-.3.06-.61.06-.94s-.02-.64-.07-.94l2.03-1.58a.5.5 0 0 0 .12-.64l-1.92-3.32a.5.5 0 0 0-.61-.22l-2.39.96a7.3 7.3 0 0 0-1.63-.94l-.36-2.54A.49.49 0 0 0 13.87 2h-3.84a.49.49 0 0 0-.49.42L9.18 4.96c-.59.23-1.14.55-1.63.94l-2.39-.96a.5.5 0 0 0-.61.22L2.63 8.48a.5.5 0 0 0 .12.64l2.03 1.58a7 7 0 0 0 0 1.88l-2.03 1.58a.5.5 0 0 0-.12.64l1.92 3.32c.13.22.39.31.61.22l2.39-.96c.49.39 1.04.71 1.63.94l.36 2.54c.03.24.24.42.49.42h3.84c.25 0 .46-.18.49-.42l.36-2.54c.59-.23 1.14-.55 1.63-.94l2.39.96c.22.09.48 0 .61-.22l1.92-3.32a.5.5 0 0 0-.12-.64zM12 15.5a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z', label: 'تنظیمات', route: '/settings', }, diff --git a/src/app/shared/utils/format.util.ts b/src/app/shared/utils/format.util.ts index 80b9231..92ff7a9 100644 --- a/src/app/shared/utils/format.util.ts +++ b/src/app/shared/utils/format.util.ts @@ -1,3 +1,5 @@ +import moment from 'moment-jalaali'; + const PERSIAN_DIGITS = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; export function toPersianDigits(value: string | number): string { @@ -18,3 +20,12 @@ export function formatDecimal(value: number, fractionDigits = 1): string { export function formatPercent(value: number): string { return `${toPersianDigits(Math.round(value))}٪`; } + +/** 2026-10-10 -> «۱۴۰۵/۰۷/۱۸ ۱۰:۲۵» */ +export function formatJalaliDateTime(value: string | Date): string { + const date = typeof value === 'string' ? new Date(value) : value; + if (Number.isNaN(date.getTime())) { + return '—'; + } + return toPersianDigits(moment(date).format('jYYYY/jMM/jDD HH:mm')); +} diff --git a/src/index.html b/src/index.html index 0a14ad5..7826c72 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ - FaqChatbot + دستیار هوش مصنوعی diff --git a/src/styles.css b/src/styles.css index 456bf21..d282d5e 100644 --- a/src/styles.css +++ b/src/styles.css @@ -21,6 +21,7 @@ } :root { + color-scheme: light; --app-bg: #f8fafc; --app-text: #122033; --sidebar-bg: #f8fafc; @@ -52,6 +53,7 @@ } [data-bs-theme="dark"] { + color-scheme: dark; --app-bg: #212121; --app-text: #ececec; --sidebar-bg: #171717; @@ -128,6 +130,12 @@ background-color: var(--scrollbar-track); } +select option, +select optgroup { + background-color: var(--color-input-bg); + color: var(--color-text-secondary); +} + body { direction: rtl; font-family: "Lahze", sans-serif;