fix_als.py 708 B

1234567891011121314151617
  1. PATH = '/data/ai/audio/server/dist/services/llm/index.js'
  2. with open(PATH, 'r', encoding='utf-8') as f:
  3. src = f.read()
  4. # 在 'use strict' 后插入 ALS require
  5. if '_triedNodesStorage' not in src:
  6. src = src.replace(
  7. '"use strict";',
  8. '"use strict";\nconst { AsyncLocalStorage: _ALS } = require(\'async_hooks\');\nconst _triedNodesStorage = new _ALS();\nfunction _runWithTriedNodes(triedSet, fn) { return _triedNodesStorage.run(triedSet, fn); }\nfunction _currentTriedNodes() { return _triedNodesStorage.getStore() || new Set(); }',
  9. 1
  10. )
  11. print("OK: ALS injected")
  12. else:
  13. print("WARN: ALS already present")
  14. with open(PATH, 'w', encoding='utf-8') as f:
  15. f.write(src)