tirtc-devtools-cli 0.0.12 → 0.0.14

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 (138) hide show
  1. package/README.md +42 -46
  2. package/USAGE.md +90 -311
  3. package/dist/cli/src/embedded_paths.d.ts +0 -2
  4. package/dist/cli/src/embedded_paths.js +3 -25
  5. package/dist/cli/src/index.js +82 -584
  6. package/dist/cli/src/role_driver.d.ts +33 -0
  7. package/dist/cli/src/role_driver.js +500 -0
  8. package/dist/cli/src/token_command.js +29 -14
  9. package/dist/cli/src/token_issue.d.ts +9 -0
  10. package/dist/cli/src/token_issue.js +138 -0
  11. package/dist/cli/src/token_tool.d.ts +4 -4
  12. package/dist/cli/src/token_tool.js +66 -182
  13. package/package.json +1 -1
  14. package/vendor/devtools/driver/macos-arm64/devtools_driver_probe +0 -0
  15. package/vendor/devtools/driver/macos-arm64/runtime_validation_client_bin +0 -0
  16. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio.h +83 -2
  17. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io.h +9 -0
  18. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/av.h +74 -0
  19. package/vendor/runtime/macos-arm64/include/tirtc/error.h +63 -0
  20. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/media_downlink.h +58 -5
  21. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/media_uplink.h +4 -0
  22. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/transport.h +52 -15
  23. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/trp.h +17 -5
  24. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_codec.h +41 -0
  25. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io.h +7 -0
  26. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_android.h +2 -0
  27. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libmatrix_runtime_audio.a +0 -0
  28. package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
  29. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libmatrix_runtime_foundation_http.a +0 -0
  30. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libmatrix_runtime_foundation_logging.a +0 -0
  31. package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
  32. package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
  33. package/vendor/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
  34. package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/manifest.txt +20 -25
  35. package/vendor/runtime/script/prepare_runtime_media_dataset.sh +308 -12
  36. package/dist/app-server/protocol-client/index.d.ts +0 -25
  37. package/dist/app-server/protocol-client/index.js +0 -114
  38. package/dist/cli/src/bootstrap_flows.d.ts +0 -46
  39. package/dist/cli/src/bootstrap_flows.js +0 -249
  40. package/dist/cli/src/config.d.ts +0 -26
  41. package/dist/cli/src/config.js +0 -62
  42. package/dist/cli/src/facade.d.ts +0 -430
  43. package/dist/cli/src/facade.js +0 -170
  44. package/dist/cli/src/guide.d.ts +0 -1
  45. package/dist/cli/src/guide.js +0 -47
  46. package/dist/cli/src/session_manager.d.ts +0 -25
  47. package/dist/cli/src/session_manager.js +0 -391
  48. package/dist/cli/src/transport.d.ts +0 -30
  49. package/dist/cli/src/transport.js +0 -84
  50. package/vendor/app-server/bin/native/linux-x64/credential_napi.node +0 -0
  51. package/vendor/app-server/bin/native/macos-arm64/credential_napi.node +0 -0
  52. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/credential.h +0 -34
  53. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/error.h +0 -33
  54. package/vendor/app-server/bin/runtime/linux-x64/lib/libcrypto.a +0 -0
  55. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_credential.a +0 -0
  56. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_http.a +0 -0
  57. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_logging.a +0 -0
  58. package/vendor/app-server/bin/runtime/linux-x64/lib/libssl.a +0 -0
  59. package/vendor/app-server/bin/runtime/linux-x64/lib/libxlog.a +0 -0
  60. package/vendor/app-server/bin/runtime/linux-x64/manifest.txt +0 -4
  61. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/credential.h +0 -34
  62. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/error.h +0 -33
  63. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/foundation/build_info.h +0 -27
  64. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/http.h +0 -57
  65. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/logging.h +0 -55
  66. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_av_sync.h +0 -61
  67. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_source.h +0 -77
  68. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_live_source.h +0 -71
  69. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_credential.a +0 -0
  70. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
  71. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
  72. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
  73. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
  74. package/vendor/app-server/bin/tirtc-devtool-host.js +0 -2
  75. package/vendor/app-server/dist/host/ArtifactManager.d.ts +0 -18
  76. package/vendor/app-server/dist/host/ArtifactManager.js +0 -98
  77. package/vendor/app-server/dist/host/HostCommandCoordinator.d.ts +0 -19
  78. package/vendor/app-server/dist/host/HostCommandCoordinator.js +0 -196
  79. package/vendor/app-server/dist/host/HostProtocol.d.ts +0 -103
  80. package/vendor/app-server/dist/host/HostProtocol.js +0 -239
  81. package/vendor/app-server/dist/host/HostServer.d.ts +0 -52
  82. package/vendor/app-server/dist/host/HostServer.js +0 -727
  83. package/vendor/app-server/dist/host/HostState.d.ts +0 -69
  84. package/vendor/app-server/dist/host/HostState.js +0 -19
  85. package/vendor/app-server/dist/host/RuntimeAdapter.d.ts +0 -95
  86. package/vendor/app-server/dist/host/RuntimeAdapter.js +0 -636
  87. package/vendor/app-server/dist/host/RuntimeReceiveWorker.d.ts +0 -37
  88. package/vendor/app-server/dist/host/RuntimeReceiveWorker.js +0 -186
  89. package/vendor/app-server/dist/host/RuntimeSendWorker.d.ts +0 -58
  90. package/vendor/app-server/dist/host/RuntimeSendWorker.js +0 -438
  91. package/vendor/app-server/dist/host/TokenTool.d.ts +0 -15
  92. package/vendor/app-server/dist/host/TokenTool.js +0 -84
  93. package/vendor/app-server/dist/host/WebPreviewGateway.d.ts +0 -28
  94. package/vendor/app-server/dist/host/WebPreviewGateway.js +0 -815
  95. package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.d.ts +0 -26
  96. package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.js +0 -118
  97. package/vendor/app-server/dist/host/native/RuntimeHostBridge.d.ts +0 -32
  98. package/vendor/app-server/dist/host/native/RuntimeHostBridge.js +0 -157
  99. package/vendor/app-server/dist/host/runtime_backed_preflight.d.ts +0 -10
  100. package/vendor/app-server/dist/host/runtime_backed_preflight.js +0 -78
  101. package/vendor/app-server/dist/host/tests/helpers/host_socket_client.d.ts +0 -28
  102. package/vendor/app-server/dist/host/tests/helpers/host_socket_client.js +0 -85
  103. package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.d.ts +0 -10
  104. package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.js +0 -41
  105. package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.d.ts +0 -11
  106. package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.js +0 -32
  107. package/vendor/app-server/dist/protocol/contract.d.ts +0 -1128
  108. package/vendor/app-server/dist/protocol/contract.js +0 -217
  109. package/vendor/app-server/dist/protocol-client/index.d.ts +0 -25
  110. package/vendor/app-server/dist/protocol-client/index.js +0 -114
  111. package/vendor/app-server/dist/src/index.d.ts +0 -1
  112. package/vendor/app-server/dist/src/index.js +0 -294
  113. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_codec.h +0 -0
  114. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_frame.h +0 -0
  115. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_android.h +0 -0
  116. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_apple.h +0 -0
  117. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_harmony.h +0 -0
  118. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_io_windows.h +0 -0
  119. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_processing.h +0 -0
  120. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/audio_sample_rate.h +0 -0
  121. /package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/foundation/build_info.h +0 -0
  122. /package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/http.h +0 -0
  123. /package/vendor/{app-server/bin/runtime/linux-x64 → runtime/macos-arm64}/include/tirtc/logging.h +0 -0
  124. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/media_codec.h +0 -0
  125. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_frame.h +0 -0
  126. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_apple.h +0 -0
  127. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_harmony.h +0 -0
  128. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_io_windows.h +0 -0
  129. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/include/tirtc/video_processing.h +0 -0
  130. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libTGTRP.a +0 -0
  131. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libTiRTC.a +0 -0
  132. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libcrypto.a +0 -0
  133. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libcrypto.dylib +0 -0
  134. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libssl.a +0 -0
  135. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libssl.dylib +0 -0
  136. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libtgrtc.dylib +0 -0
  137. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libwebrtc_apm.a +0 -0
  138. /package/vendor/{app-server/bin/runtime → runtime}/macos-arm64/lib/libxlog.a +0 -0
@@ -1,391 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createSession = createSession;
7
- exports.listSessions = listSessions;
8
- exports.stopSession = stopSession;
9
- exports.stopAllSessions = stopAllSessions;
10
- exports.resolveSession = resolveSession;
11
- exports.setSessionRole = setSessionRole;
12
- const fs_1 = __importDefault(require("fs"));
13
- const os_1 = __importDefault(require("os"));
14
- const path_1 = __importDefault(require("path"));
15
- const crypto_1 = require("crypto");
16
- const child_process_1 = require("child_process");
17
- const default_paths_1 = require("./default_paths");
18
- const embedded_paths_1 = require("./embedded_paths");
19
- const kStartupTimeoutMs = 5000;
20
- const kStartupPollIntervalMs = 100;
21
- function ensureDir(dir) {
22
- if (!fs_1.default.existsSync(dir)) {
23
- fs_1.default.mkdirSync(dir, { recursive: true });
24
- }
25
- }
26
- function sleepMs(ms) {
27
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
28
- }
29
- function getStateDir() {
30
- return (0, default_paths_1.resolveCliStateRootDir)();
31
- }
32
- function getSocketDir() {
33
- const explicit = process.env.TIRTC_DEVTOOL_SOCKET_DIR;
34
- if (explicit && explicit.trim().length > 0) {
35
- return explicit.trim();
36
- }
37
- return '/tmp';
38
- }
39
- function buildSocketPath(sessionId) {
40
- const compact = sessionId.replace(/-/g, '').slice(0, 16);
41
- return path_1.default.join(getSocketDir(), `tirtc-${compact}.sock`);
42
- }
43
- function getRegistryPath() {
44
- return path_1.default.join(getStateDir(), 'sessions.json');
45
- }
46
- function loadRegistry() {
47
- const file = getRegistryPath();
48
- if (!fs_1.default.existsSync(file)) {
49
- return { sessions: [] };
50
- }
51
- const parsed = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
52
- return {
53
- sessions: Array.isArray(parsed.sessions) ? parsed.sessions : [],
54
- };
55
- }
56
- function saveRegistry(registry) {
57
- ensureDir(getStateDir());
58
- fs_1.default.writeFileSync(getRegistryPath(), JSON.stringify(registry, null, 2));
59
- }
60
- function pidAlive(pid) {
61
- if (!Number.isInteger(pid) || pid <= 1) {
62
- return false;
63
- }
64
- try {
65
- process.kill(pid, 0);
66
- return true;
67
- }
68
- catch (error) {
69
- if (error instanceof Error && error.code === 'EPERM') {
70
- return true;
71
- }
72
- return false;
73
- }
74
- }
75
- function tryUnlink(filePath) {
76
- if (!fs_1.default.existsSync(filePath)) {
77
- return;
78
- }
79
- try {
80
- fs_1.default.unlinkSync(filePath);
81
- }
82
- catch {
83
- // no-op
84
- }
85
- }
86
- function socketExists(socketPath) {
87
- return fs_1.default.existsSync(socketPath);
88
- }
89
- function normalizeRole(role) {
90
- return role === 'service' || role === 'client' ? role : 'idle';
91
- }
92
- function purgeDeadSessions(registry) {
93
- const alive = [];
94
- for (const session of registry.sessions) {
95
- if (pidAlive(session.pid) && socketExists(session.socketPath)) {
96
- alive.push({
97
- ...session,
98
- role: normalizeRole(session.role),
99
- });
100
- continue;
101
- }
102
- tryUnlink(session.socketPath);
103
- }
104
- return { sessions: alive };
105
- }
106
- function resolveRuntimePlatform() {
107
- const raw = process.env.TIRTC_RUNTIME_PLATFORM;
108
- if (raw && raw.trim().length > 0) {
109
- return raw.trim();
110
- }
111
- if (process.platform === 'darwin' && process.arch === 'arm64') {
112
- return 'macos-arm64';
113
- }
114
- return 'linux-x64';
115
- }
116
- function resolveRuntimeBundleRoot(runtimePlatform) {
117
- const explicit = process.env.TIRTC_RUNTIME_BUNDLE_ROOT;
118
- if (explicit && explicit.trim().length > 0) {
119
- return explicit.trim();
120
- }
121
- const embedded = (0, embedded_paths_1.resolveEmbeddedRuntimeBundleRoot)(__dirname, runtimePlatform);
122
- if (embedded) {
123
- return embedded;
124
- }
125
- const execDir = path_1.default.dirname(process.execPath);
126
- const candidates = [
127
- path_1.default.resolve(execDir, 'runtime', runtimePlatform),
128
- path_1.default.resolve(execDir, '../runtime', runtimePlatform),
129
- path_1.default.resolve(__dirname, '../bin/runtime', runtimePlatform),
130
- path_1.default.resolve(__dirname, '../../../../bin/runtime', runtimePlatform),
131
- path_1.default.resolve(process.cwd(), 'bin/runtime', runtimePlatform),
132
- path_1.default.resolve(process.cwd(), '../bin/runtime', runtimePlatform),
133
- ];
134
- for (const candidate of candidates) {
135
- const manifest = path_1.default.join(candidate, 'manifest.txt');
136
- if (fs_1.default.existsSync(manifest)) {
137
- return candidate;
138
- }
139
- }
140
- return candidates[0];
141
- }
142
- function getHostBinaryPath() {
143
- const embedded = (0, embedded_paths_1.resolveEmbeddedHostBinary)(__dirname);
144
- if (embedded) {
145
- return embedded;
146
- }
147
- const candidates = [
148
- path_1.default.resolve(__dirname, '../../../products/app-server/bin/tirtc-devtool-host.js'),
149
- path_1.default.resolve(__dirname, '../../../../../../products/app-server/bin/tirtc-devtool-host.js'),
150
- path_1.default.resolve(process.cwd(), '../products/app-server/bin/tirtc-devtool-host.js'),
151
- path_1.default.resolve(process.cwd(), 'products/app-server/bin/tirtc-devtool-host.js'),
152
- ];
153
- for (const candidate of candidates) {
154
- if (fs_1.default.existsSync(candidate)) {
155
- return candidate;
156
- }
157
- }
158
- return 'tirtc-devtool-host';
159
- }
160
- function spawnDetachedHost(env, socketPath, processLogPath) {
161
- const hostPath = getHostBinaryPath();
162
- const appServerRoot = hostPath.endsWith('.js') ? path_1.default.resolve(hostPath, '../..') : undefined;
163
- const hostCmd = hostPath.endsWith('.js') ? process.execPath : hostPath;
164
- const hostArgs = hostPath.endsWith('.js') ? [hostPath, '--socket', socketPath] : ['--socket', socketPath];
165
- ensureDir(path_1.default.dirname(processLogPath));
166
- ensureDir(getSocketDir());
167
- const outFd = fs_1.default.openSync(processLogPath, 'a');
168
- return (0, child_process_1.spawn)(hostCmd, hostArgs, {
169
- env: {
170
- ...env,
171
- ...(appServerRoot ? { TIRTC_APP_SERVER_ROOT: appServerRoot } : {}),
172
- },
173
- detached: true,
174
- stdio: ['ignore', outFd, outFd],
175
- });
176
- }
177
- function waitForSocketReady(socketPath, pid) {
178
- const start = Date.now();
179
- while (Date.now() - start < kStartupTimeoutMs) {
180
- if (fs_1.default.existsSync(socketPath)) {
181
- return;
182
- }
183
- if (!pidAlive(pid)) {
184
- throw new Error('host process exited before socket became ready');
185
- }
186
- sleepMs(kStartupPollIntervalMs);
187
- }
188
- throw new Error(`session startup timeout: socket not ready within ${kStartupTimeoutMs}ms`);
189
- }
190
- function resolveDefaultLogRootDir() {
191
- return (0, default_paths_1.resolveCliLogRootDir)();
192
- }
193
- function createSession(options) {
194
- const runtimePlatform = resolveRuntimePlatform();
195
- const runtimeBundleRoot = resolveRuntimeBundleRoot(runtimePlatform);
196
- const sessionId = (0, crypto_1.randomUUID)();
197
- const artifactDir = path_1.default.join(os_1.default.tmpdir(), `tirtc-session-${sessionId}`);
198
- const socketPath = buildSocketPath(sessionId);
199
- const logRootDir = options?.logRootDir && options.logRootDir.trim().length > 0 ?
200
- path_1.default.resolve(options.logRootDir) :
201
- resolveDefaultLogRootDir();
202
- const logDir = path_1.default.join(logRootDir, sessionId);
203
- const processLogPath = path_1.default.join(logDir, 'host.process.log');
204
- const role = normalizeRole(options?.role);
205
- const registry = purgeDeadSessions(loadRegistry());
206
- if (role === 'service') {
207
- const existingService = registry.sessions.find((session) => session.role === 'service');
208
- if (existingService) {
209
- saveRegistry(registry);
210
- throw new Error(`service session already exists: ${existingService.sessionId}; stop it first with "host stop --all" or "host session stop ${existingService.sessionId}"`);
211
- }
212
- }
213
- ensureDir(logDir);
214
- tryUnlink(socketPath);
215
- const child = spawnDetachedHost({
216
- ...process.env,
217
- TIRTC_RUNTIME_PLATFORM: runtimePlatform,
218
- TIRTC_RUNTIME_BUNDLE_ROOT: runtimeBundleRoot,
219
- TIRTC_HOST_ARTIFACT_DIR: artifactDir,
220
- TIRTC_HOST_ENDPOINT: `ipc://${socketPath}`,
221
- TIRTC_HOST_LOG_DIR: logDir,
222
- TIRTC_HOST_LOG_STDOUT_MIRROR: options?.consoleMirror === false ? '0' : '1',
223
- }, socketPath, processLogPath);
224
- const pid = child.pid ?? -1;
225
- child.unref();
226
- waitForSocketReady(socketPath, pid);
227
- const record = {
228
- sessionId,
229
- hostEndpoint: `ipc://${socketPath}`,
230
- socketPath,
231
- runtimePlatform,
232
- runtimeBundleRoot,
233
- artifactDir,
234
- logDir,
235
- pid,
236
- startedAt: new Date().toISOString(),
237
- role,
238
- };
239
- registry.sessions.push(record);
240
- saveRegistry(registry);
241
- return record;
242
- }
243
- function listSessions() {
244
- const registry = purgeDeadSessions(loadRegistry());
245
- saveRegistry(registry);
246
- return registry.sessions;
247
- }
248
- function stopSessionRecord(target) {
249
- try {
250
- process.kill(target.pid, 'SIGTERM');
251
- }
252
- catch {
253
- // no-op
254
- }
255
- sleepMs(100);
256
- if (pidAlive(target.pid)) {
257
- try {
258
- process.kill(target.pid, 'SIGKILL');
259
- }
260
- catch {
261
- // no-op
262
- }
263
- }
264
- tryUnlink(target.socketPath);
265
- }
266
- function killLingeringHostProcesses() {
267
- const killed = [];
268
- try {
269
- const output = (0, child_process_1.execFileSync)('ps', ['-eo', 'pid=,command='], { encoding: 'utf8' });
270
- const lines = output.split(/\r?\n/);
271
- for (const line of lines) {
272
- const trimmed = line.trim();
273
- if (trimmed.length === 0) {
274
- continue;
275
- }
276
- const match = trimmed.match(/^(\d+)\s+(.+)$/);
277
- if (!match) {
278
- continue;
279
- }
280
- const pid = Number.parseInt(match[1], 10);
281
- const command = match[2];
282
- if (!Number.isInteger(pid) || pid <= 1 || pid === process.pid) {
283
- continue;
284
- }
285
- if (!command.includes('products/app-server/bin/tirtc-devtool-host.js') &&
286
- !command.includes('vendor/app-server/bin/tirtc-devtool-host.js')) {
287
- continue;
288
- }
289
- if (!command.includes('--socket /tmp/tirtc-')) {
290
- continue;
291
- }
292
- try {
293
- process.kill(pid, 'SIGTERM');
294
- }
295
- catch {
296
- // no-op
297
- }
298
- if (pidAlive(pid)) {
299
- try {
300
- process.kill(pid, 'SIGKILL');
301
- }
302
- catch {
303
- // no-op
304
- }
305
- }
306
- if (!pidAlive(pid)) {
307
- killed.push(pid);
308
- }
309
- }
310
- }
311
- catch {
312
- // no-op
313
- }
314
- return killed;
315
- }
316
- function stopSession(sessionId) {
317
- const registry = purgeDeadSessions(loadRegistry());
318
- const idx = registry.sessions.findIndex((session) => session.sessionId === sessionId);
319
- if (idx < 0) {
320
- throw new Error(`session not found: ${sessionId}`);
321
- }
322
- const target = registry.sessions[idx];
323
- stopSessionRecord(target);
324
- registry.sessions.splice(idx, 1);
325
- saveRegistry(registry);
326
- return target;
327
- }
328
- function stopAllSessions() {
329
- const registry = purgeDeadSessions(loadRegistry());
330
- const stopped = [];
331
- for (const session of registry.sessions) {
332
- stopSessionRecord(session);
333
- stopped.push(session);
334
- }
335
- const lingeringPids = killLingeringHostProcesses();
336
- for (const pid of lingeringPids) {
337
- stopped.push({
338
- sessionId: `orphan-pid-${pid}`,
339
- hostEndpoint: '',
340
- socketPath: '',
341
- runtimePlatform: '',
342
- runtimeBundleRoot: '',
343
- artifactDir: '',
344
- logDir: '',
345
- pid,
346
- startedAt: '',
347
- role: 'idle',
348
- });
349
- }
350
- saveRegistry({ sessions: [] });
351
- return stopped;
352
- }
353
- function resolveSession(sessionId) {
354
- const sessions = listSessions();
355
- if (sessionId && sessionId.trim().length > 0) {
356
- const found = sessions.find((session) => session.sessionId === sessionId.trim());
357
- if (!found) {
358
- throw new Error(`session not found: ${sessionId}`);
359
- }
360
- return found;
361
- }
362
- if (sessions.length === 1) {
363
- return sessions[0];
364
- }
365
- if (sessions.length === 0) {
366
- throw new Error('no active session; run "host session start" first');
367
- }
368
- throw new Error('multiple active sessions; please specify --session <sessionId>');
369
- }
370
- function setSessionRole(sessionId, role) {
371
- const registry = purgeDeadSessions(loadRegistry());
372
- const normalizedRole = normalizeRole(role);
373
- const idx = registry.sessions.findIndex((session) => session.sessionId === sessionId);
374
- if (idx < 0) {
375
- throw new Error(`session not found: ${sessionId}`);
376
- }
377
- if (normalizedRole === 'service') {
378
- const existingService = registry.sessions.find((session, index) => index !== idx && session.role === 'service');
379
- if (existingService) {
380
- saveRegistry(registry);
381
- throw new Error(`service session already exists: ${existingService.sessionId}; stop it first with "host stop --all" or "host session stop ${existingService.sessionId}"`);
382
- }
383
- }
384
- const updated = {
385
- ...registry.sessions[idx],
386
- role: normalizedRole,
387
- };
388
- registry.sessions[idx] = updated;
389
- saveRegistry(registry);
390
- return updated;
391
- }
@@ -1,30 +0,0 @@
1
- import { Transport } from '../../app-server/protocol-client';
2
- type ProcessTransportOptions = {
3
- env?: NodeJS.ProcessEnv;
4
- };
5
- export declare class ProcessTransport implements Transport {
6
- private child;
7
- private messageHandler;
8
- private closeHandler;
9
- private errorHandler;
10
- constructor(command: string, args: string[], options?: ProcessTransportOptions);
11
- send(data: string): void;
12
- onMessage(handler: (data: string) => void): void;
13
- onClose(handler: () => void): void;
14
- onError(handler: (error: Error) => void): void;
15
- stop(): void;
16
- getPid(): number;
17
- }
18
- export declare class SocketTransport implements Transport {
19
- private socket;
20
- private messageHandler;
21
- private closeHandler;
22
- private errorHandler;
23
- constructor(socketPath: string);
24
- send(data: string): void;
25
- onMessage(handler: (data: string) => void): void;
26
- onClose(handler: () => void): void;
27
- onError(handler: (error: Error) => void): void;
28
- stop(): void;
29
- }
30
- export {};
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SocketTransport = exports.ProcessTransport = void 0;
7
- const net_1 = __importDefault(require("net"));
8
- const child_process_1 = require("child_process");
9
- class ProcessTransport {
10
- child;
11
- messageHandler = () => { };
12
- closeHandler = () => { };
13
- errorHandler = () => { };
14
- constructor(command, args, options) {
15
- const env = options?.env ? { ...process.env, ...options.env } : process.env;
16
- this.child = (0, child_process_1.spawn)(command, args, {
17
- stdio: ['pipe', 'pipe', 'inherit'],
18
- env,
19
- });
20
- this.child.stdout?.on('data', (data) => {
21
- this.messageHandler(data.toString());
22
- });
23
- this.child.on('error', (err) => {
24
- this.errorHandler(err);
25
- });
26
- this.child.on('close', () => {
27
- this.closeHandler();
28
- });
29
- }
30
- send(data) {
31
- this.child.stdin?.write(data);
32
- }
33
- onMessage(handler) {
34
- this.messageHandler = handler;
35
- }
36
- onClose(handler) {
37
- this.closeHandler = handler;
38
- }
39
- onError(handler) {
40
- this.errorHandler = handler;
41
- }
42
- stop() {
43
- this.child.kill();
44
- }
45
- getPid() {
46
- return this.child.pid ?? -1;
47
- }
48
- }
49
- exports.ProcessTransport = ProcessTransport;
50
- class SocketTransport {
51
- socket;
52
- messageHandler = () => { };
53
- closeHandler = () => { };
54
- errorHandler = () => { };
55
- constructor(socketPath) {
56
- this.socket = net_1.default.createConnection(socketPath);
57
- this.socket.on('data', (data) => {
58
- this.messageHandler(data.toString());
59
- });
60
- this.socket.on('close', () => {
61
- this.closeHandler();
62
- });
63
- this.socket.on('error', (error) => {
64
- this.errorHandler(error);
65
- });
66
- }
67
- send(data) {
68
- this.socket.write(data);
69
- }
70
- onMessage(handler) {
71
- this.messageHandler = handler;
72
- }
73
- onClose(handler) {
74
- this.closeHandler = handler;
75
- }
76
- onError(handler) {
77
- this.errorHandler = handler;
78
- }
79
- stop() {
80
- this.socket.end();
81
- this.socket.destroy();
82
- }
83
- }
84
- exports.SocketTransport = SocketTransport;
@@ -1,34 +0,0 @@
1
- #ifndef TIRTC_CREDENTIAL_H_
2
- #define TIRTC_CREDENTIAL_H_
3
-
4
- #include "tirtc/error.h"
5
-
6
- #ifdef __cplusplus
7
- extern "C" {
8
- #endif
9
-
10
- typedef struct TirtcCredentialIssueTokenOptions {
11
- const char* openapi_entry;
12
- const char* access_id;
13
- const char* secret_key;
14
- const char* local_id;
15
- const char* peer_id;
16
- int user_ttl_seconds;
17
- int channel_ttl_seconds;
18
- } TirtcCredentialIssueTokenOptions;
19
-
20
- typedef struct TirtcCredentialIssueTokenResult {
21
- char* token;
22
- int http_status_code;
23
- } TirtcCredentialIssueTokenResult;
24
-
25
- TirtcError tirtc_credential_issue_token(const TirtcCredentialIssueTokenOptions* options,
26
- TirtcCredentialIssueTokenResult* out_result);
27
-
28
- void tirtc_credential_issue_token_result_dispose(TirtcCredentialIssueTokenResult* result);
29
-
30
- #ifdef __cplusplus
31
- }
32
- #endif
33
-
34
- #endif // TIRTC_CREDENTIAL_H_
@@ -1,33 +0,0 @@
1
- #ifndef TIRTC_FOUNDATION_ERROR_H_
2
- #define TIRTC_FOUNDATION_ERROR_H_
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- typedef enum TirtcError {
9
- TIRTC_ERROR_OK = 0,
10
- TIRTC_ERROR_INVALID_ARGUMENT = 1,
11
- TIRTC_ERROR_NOT_INITIALIZED = 2,
12
- TIRTC_ERROR_INTERNAL = 3,
13
- TIRTC_ERROR_NOT_READY = 4,
14
- TIRTC_ERROR_UNSUPPORTED_LOOP_POLICY = 5,
15
- TIRTC_ERROR_SOURCE_HASH_MISMATCH = 6,
16
- TIRTC_ERROR_STOPPED = 7,
17
- TIRTC_ERROR_DESTROYED = 8,
18
- TIRTC_ERROR_TRANSPORT_INVALID_LICENSE = 9,
19
- TIRTC_ERROR_TRANSPORT_TIMEOUT = 10,
20
- TIRTC_ERROR_TRANSPORT_BUSY = 11,
21
- TIRTC_ERROR_TRANSPORT_CONNECTION_TIMEOUT_CLOSED = 12,
22
- TIRTC_ERROR_TRANSPORT_REMOTE_CLOSED = 13,
23
- TIRTC_ERROR_TRANSPORT_CONNECTION_OTHER_ERROR = 14,
24
- TIRTC_ERROR_TRANSPORT_TOKEN_EXPIRED = 15,
25
- TIRTC_ERROR_DUMP_ROOT_UNAVAILABLE = 16,
26
- TIRTC_ERROR_DUMP_ALREADY_ACTIVE = 17,
27
- } TirtcError;
28
-
29
- #ifdef __cplusplus
30
- }
31
- #endif
32
-
33
- #endif // TIRTC_FOUNDATION_ERROR_H_
@@ -1,4 +0,0 @@
1
- platform=linux-x64
2
- profile=credential
3
- staged_at_utc=2026-04-21T13:44:44Z
4
- source_sdk=/workspace/.build/sdk/linux-x64
@@ -1,34 +0,0 @@
1
- #ifndef TIRTC_CREDENTIAL_H_
2
- #define TIRTC_CREDENTIAL_H_
3
-
4
- #include "tirtc/error.h"
5
-
6
- #ifdef __cplusplus
7
- extern "C" {
8
- #endif
9
-
10
- typedef struct TirtcCredentialIssueTokenOptions {
11
- const char* openapi_entry;
12
- const char* access_id;
13
- const char* secret_key;
14
- const char* local_id;
15
- const char* peer_id;
16
- int user_ttl_seconds;
17
- int channel_ttl_seconds;
18
- } TirtcCredentialIssueTokenOptions;
19
-
20
- typedef struct TirtcCredentialIssueTokenResult {
21
- char* token;
22
- int http_status_code;
23
- } TirtcCredentialIssueTokenResult;
24
-
25
- TirtcError tirtc_credential_issue_token(const TirtcCredentialIssueTokenOptions* options,
26
- TirtcCredentialIssueTokenResult* out_result);
27
-
28
- void tirtc_credential_issue_token_result_dispose(TirtcCredentialIssueTokenResult* result);
29
-
30
- #ifdef __cplusplus
31
- }
32
- #endif
33
-
34
- #endif // TIRTC_CREDENTIAL_H_
@@ -1,33 +0,0 @@
1
- #ifndef TIRTC_FOUNDATION_ERROR_H_
2
- #define TIRTC_FOUNDATION_ERROR_H_
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- typedef enum TirtcError {
9
- TIRTC_ERROR_OK = 0,
10
- TIRTC_ERROR_INVALID_ARGUMENT = 1,
11
- TIRTC_ERROR_NOT_INITIALIZED = 2,
12
- TIRTC_ERROR_INTERNAL = 3,
13
- TIRTC_ERROR_NOT_READY = 4,
14
- TIRTC_ERROR_UNSUPPORTED_LOOP_POLICY = 5,
15
- TIRTC_ERROR_SOURCE_HASH_MISMATCH = 6,
16
- TIRTC_ERROR_STOPPED = 7,
17
- TIRTC_ERROR_DESTROYED = 8,
18
- TIRTC_ERROR_TRANSPORT_INVALID_LICENSE = 9,
19
- TIRTC_ERROR_TRANSPORT_TIMEOUT = 10,
20
- TIRTC_ERROR_TRANSPORT_BUSY = 11,
21
- TIRTC_ERROR_TRANSPORT_CONNECTION_TIMEOUT_CLOSED = 12,
22
- TIRTC_ERROR_TRANSPORT_REMOTE_CLOSED = 13,
23
- TIRTC_ERROR_TRANSPORT_CONNECTION_OTHER_ERROR = 14,
24
- TIRTC_ERROR_TRANSPORT_TOKEN_EXPIRED = 15,
25
- TIRTC_ERROR_DUMP_ROOT_UNAVAILABLE = 16,
26
- TIRTC_ERROR_DUMP_ALREADY_ACTIVE = 17,
27
- } TirtcError;
28
-
29
- #ifdef __cplusplus
30
- }
31
- #endif
32
-
33
- #endif // TIRTC_FOUNDATION_ERROR_H_
@@ -1,27 +0,0 @@
1
- #ifndef TIRTC_FOUNDATION_BUILD_INFO_H_
2
- #define TIRTC_FOUNDATION_BUILD_INFO_H_
3
-
4
- #include "tirtc/error.h"
5
-
6
- #ifdef __cplusplus
7
- extern "C" {
8
- #endif
9
-
10
- typedef struct TirtcBuildInfo {
11
- const char* semver_base;
12
- const char* semver_effective;
13
- const char* commit_hash;
14
- int commit_count;
15
- const char* build_branch;
16
- const char* build_time_utc;
17
- const char* version_string;
18
- } TirtcBuildInfo;
19
-
20
- const TirtcBuildInfo* tirtc_build_info_get(void);
21
- const char* tirtc_build_version_string(void);
22
-
23
- #ifdef __cplusplus
24
- }
25
- #endif
26
-
27
- #endif // TIRTC_FOUNDATION_BUILD_INFO_H_