tirtc-devtools-cli 0.0.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 (156) hide show
  1. package/README.md +52 -0
  2. package/USAGE.md +417 -0
  3. package/bin/tirtc-devtool.js +2 -0
  4. package/dist/app-server/protocol-client/index.d.ts +25 -0
  5. package/dist/app-server/protocol-client/index.js +114 -0
  6. package/dist/devtools/cli/src/config.d.ts +46 -0
  7. package/dist/devtools/cli/src/config.js +98 -0
  8. package/dist/devtools/cli/src/dummy.d.ts +0 -0
  9. package/dist/devtools/cli/src/dummy.js +1 -0
  10. package/dist/devtools/cli/src/embedded_paths.d.ts +7 -0
  11. package/dist/devtools/cli/src/embedded_paths.js +85 -0
  12. package/dist/devtools/cli/src/facade.d.ts +723 -0
  13. package/dist/devtools/cli/src/facade.js +194 -0
  14. package/dist/devtools/cli/src/ffmpeg_tool.d.ts +6 -0
  15. package/dist/devtools/cli/src/ffmpeg_tool.js +146 -0
  16. package/dist/devtools/cli/src/guide.d.ts +1 -0
  17. package/dist/devtools/cli/src/guide.js +49 -0
  18. package/dist/devtools/cli/src/index.d.ts +1 -0
  19. package/dist/devtools/cli/src/index.js +753 -0
  20. package/dist/devtools/cli/src/media_assets.d.ts +25 -0
  21. package/dist/devtools/cli/src/media_assets.js +121 -0
  22. package/dist/devtools/cli/src/session_manager.d.ts +25 -0
  23. package/dist/devtools/cli/src/session_manager.js +393 -0
  24. package/dist/devtools/cli/src/token_tool.d.ts +33 -0
  25. package/dist/devtools/cli/src/token_tool.js +217 -0
  26. package/dist/devtools/cli/src/transport.d.ts +30 -0
  27. package/dist/devtools/cli/src/transport.js +84 -0
  28. package/dist/dummy.d.ts +0 -0
  29. package/dist/dummy.js +1 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +48 -0
  32. package/package.json +54 -0
  33. package/script/ensure_ffmpeg.sh +22 -0
  34. package/vendor/app-server/bin/native/macos-arm64/credential_napi.node +0 -0
  35. package/vendor/app-server/bin/native/macos-arm64/libcrypto.dylib +0 -0
  36. package/vendor/app-server/bin/native/macos-arm64/libssl.dylib +0 -0
  37. package/vendor/app-server/bin/native/macos-arm64/libtgrtc.dylib +0 -0
  38. package/vendor/app-server/bin/native/macos-arm64/runtime_host_napi.node +0 -0
  39. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_codec.h +23 -0
  40. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_frame.h +36 -0
  41. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io.h +56 -0
  42. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_android.h +19 -0
  43. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_apple.h +19 -0
  44. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_harmony.h +19 -0
  45. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_io_windows.h +19 -0
  46. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_processing.h +56 -0
  47. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/audio_sample_rate.h +18 -0
  48. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/error.h +20 -0
  49. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/logging.h +53 -0
  50. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_codec.h +21 -0
  51. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_downlink.h +89 -0
  52. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/media_uplink.h +115 -0
  53. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/runtime.h +236 -0
  54. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_codec.h +57 -0
  55. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_frame.h +55 -0
  56. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io.h +46 -0
  57. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_android.h +32 -0
  58. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_apple.h +34 -0
  59. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_harmony.h +32 -0
  60. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_io_windows.h +26 -0
  61. package/vendor/app-server/bin/runtime/linux-x64/include/tirtc/video_processing.h +34 -0
  62. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_audio.a +0 -0
  63. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_facade.a +0 -0
  64. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_foundation_logging.a +0 -0
  65. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_media.a +0 -0
  66. package/vendor/app-server/bin/runtime/linux-x64/lib/libmatrix_runtime_video.a +0 -0
  67. package/vendor/app-server/bin/runtime/linux-x64/lib/libwebrtc_apm.a +0 -0
  68. package/vendor/app-server/bin/runtime/linux-x64/lib/libxlog.a +0 -0
  69. package/vendor/app-server/bin/runtime/linux-x64/manifest.txt +34 -0
  70. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio.h +398 -0
  71. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_codec.h +23 -0
  72. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_frame.h +36 -0
  73. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io.h +56 -0
  74. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_android.h +19 -0
  75. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_apple.h +19 -0
  76. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_harmony.h +19 -0
  77. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_io_windows.h +19 -0
  78. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_processing.h +56 -0
  79. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/audio_sample_rate.h +18 -0
  80. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/av.h +452 -0
  81. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/credential.h +34 -0
  82. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/error.h +30 -0
  83. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/foundation/build_info.h +27 -0
  84. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/http.h +57 -0
  85. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/logging.h +55 -0
  86. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_codec.h +21 -0
  87. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_downlink.h +95 -0
  88. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_av_sync.h +61 -0
  89. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_fixture_source.h +77 -0
  90. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_live_source.h +71 -0
  91. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/media_uplink.h +116 -0
  92. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/transport.h +481 -0
  93. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/trp.h +541 -0
  94. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_codec.h +58 -0
  95. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_frame.h +55 -0
  96. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io.h +46 -0
  97. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_android.h +32 -0
  98. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_apple.h +47 -0
  99. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_harmony.h +32 -0
  100. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_io_windows.h +26 -0
  101. package/vendor/app-server/bin/runtime/macos-arm64/include/tirtc/video_processing.h +34 -0
  102. package/vendor/app-server/bin/runtime/macos-arm64/lib/libcrypto.a +0 -0
  103. package/vendor/app-server/bin/runtime/macos-arm64/lib/libcrypto.dylib +0 -0
  104. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_audio.a +0 -0
  105. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_credential.a +0 -0
  106. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_facade.a +0 -0
  107. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_foundation_http.a +0 -0
  108. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_foundation_logging.a +0 -0
  109. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_media.a +0 -0
  110. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_transport.a +0 -0
  111. package/vendor/app-server/bin/runtime/macos-arm64/lib/libmatrix_runtime_video.a +0 -0
  112. package/vendor/app-server/bin/runtime/macos-arm64/lib/libssl.a +0 -0
  113. package/vendor/app-server/bin/runtime/macos-arm64/lib/libssl.dylib +0 -0
  114. package/vendor/app-server/bin/runtime/macos-arm64/lib/libwebrtc_apm.a +0 -0
  115. package/vendor/app-server/bin/runtime/macos-arm64/lib/libxlog.a +0 -0
  116. package/vendor/app-server/bin/runtime/macos-arm64/manifest.txt +50 -0
  117. package/vendor/app-server/bin/tirtc-devtool-host.js +2 -0
  118. package/vendor/app-server/dist/host/ArtifactManager.d.ts +18 -0
  119. package/vendor/app-server/dist/host/ArtifactManager.js +83 -0
  120. package/vendor/app-server/dist/host/HostProtocol.d.ts +107 -0
  121. package/vendor/app-server/dist/host/HostProtocol.js +256 -0
  122. package/vendor/app-server/dist/host/HostServer.d.ts +49 -0
  123. package/vendor/app-server/dist/host/HostServer.js +635 -0
  124. package/vendor/app-server/dist/host/HostState.d.ts +60 -0
  125. package/vendor/app-server/dist/host/HostState.js +19 -0
  126. package/vendor/app-server/dist/host/RuntimeAdapter.d.ts +81 -0
  127. package/vendor/app-server/dist/host/RuntimeAdapter.js +559 -0
  128. package/vendor/app-server/dist/host/RuntimeCredentialTokenIssuer.d.ts +30 -0
  129. package/vendor/app-server/dist/host/RuntimeCredentialTokenIssuer.js +224 -0
  130. package/vendor/app-server/dist/host/RuntimeReceiveWorker.d.ts +37 -0
  131. package/vendor/app-server/dist/host/RuntimeReceiveWorker.js +186 -0
  132. package/vendor/app-server/dist/host/RuntimeSendWorker.d.ts +42 -0
  133. package/vendor/app-server/dist/host/RuntimeSendWorker.js +274 -0
  134. package/vendor/app-server/dist/host/TokenTool.d.ts +15 -0
  135. package/vendor/app-server/dist/host/TokenTool.js +84 -0
  136. package/vendor/app-server/dist/host/WebPreviewGateway.d.ts +28 -0
  137. package/vendor/app-server/dist/host/WebPreviewGateway.js +815 -0
  138. package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.d.ts +26 -0
  139. package/vendor/app-server/dist/host/native/RuntimeCredentialTokenIssuer.js +118 -0
  140. package/vendor/app-server/dist/host/native/RuntimeHostBridge.d.ts +19 -0
  141. package/vendor/app-server/dist/host/native/RuntimeHostBridge.js +141 -0
  142. package/vendor/app-server/dist/host/runtime_backed_preflight.d.ts +10 -0
  143. package/vendor/app-server/dist/host/runtime_backed_preflight.js +78 -0
  144. package/vendor/app-server/dist/host/tests/helpers/host_socket_client.d.ts +28 -0
  145. package/vendor/app-server/dist/host/tests/helpers/host_socket_client.js +85 -0
  146. package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.d.ts +10 -0
  147. package/vendor/app-server/dist/host/tests/helpers/runtime_e2e_local_config.js +41 -0
  148. package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.d.ts +11 -0
  149. package/vendor/app-server/dist/host/tests/helpers/runtime_test_env.js +32 -0
  150. package/vendor/app-server/dist/protocol/contract.d.ts +983 -0
  151. package/vendor/app-server/dist/protocol/contract.js +198 -0
  152. package/vendor/app-server/dist/protocol-client/index.d.ts +25 -0
  153. package/vendor/app-server/dist/protocol-client/index.js +114 -0
  154. package/vendor/app-server/dist/src/index.d.ts +1 -0
  155. package/vendor/app-server/dist/src/index.js +294 -0
  156. package/vendor/runtime/script/prepare_runtime_media_dataset.sh +427 -0
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DebugTokenQrcodeResultSchema = exports.DebugTokenQrcodeRequestSchema = exports.StreamRequestPolicySetRequestSchema = exports.StreamRequestPolicySchema = exports.EventsSubscribeRequestSchema = exports.CommandSendRequestSchema = exports.OutputAttachRequestSchema = exports.StreamSendStartRequestSchema = exports.ConnectionConnectRequestSchema = exports.ServiceStartRequestSchema = exports.ArtifactExportResultSchema = exports.ReportDocumentSchema = exports.ErrorSummarySchema = exports.CommandSendResultSchema = exports.CommandResponseSchema = exports.OutputAttachmentSchema = exports.HostStatusSchema = exports.ArtifactPathsSchema = exports.StreamSnapshotSchema = exports.StreamSourceSchema = exports.StreamLocalAssetsSchema = exports.ConnectionSnapshotSchema = exports.ServiceSnapshotSchema = exports.EventEnvelopeSchema = exports.ErrorResponseSchema = exports.InitializedNotificationSchema = exports.InitializeResultSchema = exports.InitializeRequestSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.InitializeRequestSchema = zod_1.z.object({
6
+ protocolVersion: zod_1.z.string(),
7
+ clientInfo: zod_1.z.object({
8
+ name: zod_1.z.string(),
9
+ version: zod_1.z.string(),
10
+ title: zod_1.z.string().optional()
11
+ }),
12
+ capabilities: zod_1.z.object({
13
+ experimentalApi: zod_1.z.boolean().optional(),
14
+ optOutNotificationMethods: zod_1.z.array(zod_1.z.string()).optional()
15
+ }).optional()
16
+ });
17
+ exports.InitializeResultSchema = zod_1.z.object({
18
+ serverInfo: zod_1.z.object({
19
+ name: zod_1.z.string(),
20
+ version: zod_1.z.string()
21
+ }),
22
+ protocolVersion: zod_1.z.string(),
23
+ runtimeTarget: zod_1.z.string(),
24
+ hostEndpoint: zod_1.z.string(),
25
+ capabilities: zod_1.z.record(zod_1.z.any())
26
+ });
27
+ exports.InitializedNotificationSchema = zod_1.z.object({});
28
+ exports.ErrorResponseSchema = zod_1.z.object({
29
+ reasonCode: zod_1.z.string(),
30
+ message: zod_1.z.string(),
31
+ retryable: zod_1.z.boolean()
32
+ });
33
+ exports.EventEnvelopeSchema = zod_1.z.object({
34
+ eventId: zod_1.z.string(),
35
+ timestamp: zod_1.z.string(),
36
+ family: zod_1.z.string(),
37
+ kind: zod_1.z.string(),
38
+ payload: zod_1.z.record(zod_1.z.any())
39
+ });
40
+ exports.ServiceSnapshotSchema = zod_1.z.object({
41
+ state: zod_1.z.string(),
42
+ serviceEntry: zod_1.z.string().optional(),
43
+ localEndpoint: zod_1.z.string().optional(),
44
+ startedAt: zod_1.z.string().optional(),
45
+ stoppedAt: zod_1.z.string().optional(),
46
+ reasonCode: zod_1.z.string().optional()
47
+ });
48
+ exports.ConnectionSnapshotSchema = zod_1.z.object({
49
+ state: zod_1.z.string(),
50
+ direction: zod_1.z.string().optional(),
51
+ peerId: zod_1.z.string().optional(),
52
+ connectedAt: zod_1.z.string().optional(),
53
+ disconnectedAt: zod_1.z.string().optional(),
54
+ reasonCode: zod_1.z.string().optional()
55
+ });
56
+ exports.StreamLocalAssetsSchema = zod_1.z.object({
57
+ assets_dir: zod_1.z.string(),
58
+ });
59
+ exports.StreamSourceSchema = zod_1.z.object({
60
+ mode: zod_1.z.literal('local_assets'),
61
+ local_assets: exports.StreamLocalAssetsSchema,
62
+ });
63
+ exports.StreamSnapshotSchema = zod_1.z.object({
64
+ streamId: zod_1.z.number().int(),
65
+ media: zod_1.z.string(),
66
+ direction: zod_1.z.string(),
67
+ state: zod_1.z.string(),
68
+ source: exports.StreamSourceSchema.optional(),
69
+ updatedAt: zod_1.z.string()
70
+ });
71
+ exports.ArtifactPathsSchema = zod_1.z.object({
72
+ rootPath: zod_1.z.string(),
73
+ reportPath: zod_1.z.string(),
74
+ logsPath: zod_1.z.string(),
75
+ eventsPath: zod_1.z.string(),
76
+ receivedMediaPath: zod_1.z.string(),
77
+ prepareCachePath: zod_1.z.string()
78
+ });
79
+ exports.HostStatusSchema = zod_1.z.object({
80
+ hostEndpoint: zod_1.z.string(),
81
+ serverVersion: zod_1.z.string(),
82
+ protocolVersion: zod_1.z.string(),
83
+ runtimeTarget: zod_1.z.string(),
84
+ startedAt: zod_1.z.string(),
85
+ service: exports.ServiceSnapshotSchema,
86
+ connection: exports.ConnectionSnapshotSchema,
87
+ artifactPaths: exports.ArtifactPathsSchema
88
+ });
89
+ exports.OutputAttachmentSchema = zod_1.z.object({
90
+ outputId: zod_1.z.string(),
91
+ streamId: zod_1.z.number().int(),
92
+ consumer: zod_1.z.string(),
93
+ mediaView: zod_1.z.string(),
94
+ format: zod_1.z.string(),
95
+ delivery: zod_1.z.string(),
96
+ target: zod_1.z.string(),
97
+ attachedAt: zod_1.z.string(),
98
+ preview: zod_1.z.object({
99
+ url: zod_1.z.string(),
100
+ token: zod_1.z.string(),
101
+ endpoint: zod_1.z.string(),
102
+ }).optional(),
103
+ });
104
+ exports.CommandResponseSchema = zod_1.z.object({
105
+ sequenceNumber: zod_1.z.number().int(),
106
+ payloadEncoding: zod_1.z.string(),
107
+ payload: zod_1.z.string()
108
+ });
109
+ exports.CommandSendResultSchema = zod_1.z.object({
110
+ sequenceNumber: zod_1.z.number().int(),
111
+ commandId: zod_1.z.number().int(),
112
+ kind: zod_1.z.string(),
113
+ acceptedAt: zod_1.z.string(),
114
+ response: exports.CommandResponseSchema.optional()
115
+ });
116
+ exports.ErrorSummarySchema = zod_1.z.object({
117
+ reasonCode: zod_1.z.string(),
118
+ message: zod_1.z.string(),
119
+ retryable: zod_1.z.boolean()
120
+ });
121
+ exports.ReportDocumentSchema = zod_1.z.object({
122
+ status: zod_1.z.string(),
123
+ reasonCode: zod_1.z.string(),
124
+ summary: zod_1.z.string(),
125
+ service: exports.ServiceSnapshotSchema,
126
+ connection: exports.ConnectionSnapshotSchema,
127
+ streams: zod_1.z.array(exports.StreamSnapshotSchema),
128
+ artifacts: exports.ArtifactPathsSchema,
129
+ lastError: exports.ErrorSummarySchema.optional()
130
+ });
131
+ exports.ArtifactExportResultSchema = zod_1.z.object({
132
+ outputPath: zod_1.z.string(),
133
+ exportedAt: zod_1.z.string()
134
+ });
135
+ exports.ServiceStartRequestSchema = zod_1.z.object({
136
+ serviceEntry: zod_1.z.string().optional(),
137
+ license: zod_1.z.string(),
138
+ timeoutMs: zod_1.z.number().int()
139
+ });
140
+ exports.ConnectionConnectRequestSchema = zod_1.z.object({
141
+ serviceEntry: zod_1.z.string().optional(),
142
+ peerId: zod_1.z.string(),
143
+ token: zod_1.z.string().optional(),
144
+ tokenMode: zod_1.z.enum(["manual", "auto"]).optional(),
145
+ autoToken: zod_1.z.object({
146
+ openapiEntry: zod_1.z.string().optional(),
147
+ accessId: zod_1.z.string(),
148
+ secretKey: zod_1.z.string(),
149
+ localId: zod_1.z.string().optional(),
150
+ userTtlSeconds: zod_1.z.number().int().optional(),
151
+ channelTtlSeconds: zod_1.z.number().int().optional(),
152
+ }).optional(),
153
+ timeoutMs: zod_1.z.number().int()
154
+ }).refine((value) => Boolean(value.token) || Boolean(value.autoToken), {
155
+ message: "token or autoToken is required",
156
+ });
157
+ exports.StreamSendStartRequestSchema = zod_1.z.object({
158
+ streamId: zod_1.z.number().int(),
159
+ media: zod_1.z.string(),
160
+ source: exports.StreamSourceSchema,
161
+ });
162
+ exports.OutputAttachRequestSchema = zod_1.z.object({
163
+ streamId: zod_1.z.number().int(),
164
+ consumer: zod_1.z.string(),
165
+ mediaView: zod_1.z.string(),
166
+ format: zod_1.z.string(),
167
+ delivery: zod_1.z.string(),
168
+ targetPath: zod_1.z.string().optional(),
169
+ maxFiles: zod_1.z.number().int().optional()
170
+ });
171
+ exports.CommandSendRequestSchema = zod_1.z.object({
172
+ commandId: zod_1.z.number().int(),
173
+ kind: zod_1.z.string(),
174
+ payloadEncoding: zod_1.z.string(),
175
+ payload: zod_1.z.string(),
176
+ replyToSequenceNumber: zod_1.z.number().int().optional(),
177
+ awaitResponse: zod_1.z.boolean().optional(),
178
+ timeoutMs: zod_1.z.number().int().optional()
179
+ });
180
+ exports.EventsSubscribeRequestSchema = zod_1.z.object({
181
+ families: zod_1.z.array(zod_1.z.string())
182
+ });
183
+ exports.StreamRequestPolicySchema = zod_1.z.object({
184
+ mode: zod_1.z.enum(['manual', 'auto-if-bound'])
185
+ });
186
+ exports.StreamRequestPolicySetRequestSchema = zod_1.z.object({
187
+ mode: zod_1.z.enum(['manual', 'auto-if-bound'])
188
+ });
189
+ exports.DebugTokenQrcodeRequestSchema = zod_1.z.object({
190
+ payload: zod_1.z.string(),
191
+ outputStem: zod_1.z.string().optional()
192
+ });
193
+ exports.DebugTokenQrcodeResultSchema = zod_1.z.object({
194
+ payload: zod_1.z.string(),
195
+ qrAsciiPath: zod_1.z.string(),
196
+ qrPngPath: zod_1.z.string(),
197
+ generatedAt: zod_1.z.string()
198
+ });
@@ -0,0 +1,25 @@
1
+ import { EventEmitter } from 'events';
2
+ export interface Transport {
3
+ send(data: string): void;
4
+ onMessage(handler: (data: string) => void): void;
5
+ onClose(handler: () => void): void;
6
+ onError(handler: (error: Error) => void): void;
7
+ }
8
+ export declare class AppServerClient extends EventEmitter {
9
+ private transport;
10
+ private pendingRequests;
11
+ initialized: boolean;
12
+ private buffer;
13
+ constructor(transport: Transport);
14
+ private rejectAllPending;
15
+ private handleData;
16
+ private handleMessage;
17
+ sendRequest(method: string, params?: unknown, timeoutMs?: number): Promise<unknown>;
18
+ sendNotification(method: string, params?: unknown): void;
19
+ initialize(clientInfo: {
20
+ name: string;
21
+ version: string;
22
+ title?: string;
23
+ }, capabilities?: unknown): Promise<unknown>;
24
+ subscribeEvents(families: string[]): Promise<unknown>;
25
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppServerClient = void 0;
4
+ const events_1 = require("events");
5
+ const crypto_1 = require("crypto");
6
+ class AppServerClient extends events_1.EventEmitter {
7
+ transport;
8
+ pendingRequests;
9
+ initialized = false;
10
+ buffer = '';
11
+ constructor(transport) {
12
+ super();
13
+ this.transport = transport;
14
+ this.pendingRequests = new Map();
15
+ this.transport.onMessage((data) => this.handleData(data));
16
+ this.transport.onError((error) => {
17
+ this.emit('error', error);
18
+ this.rejectAllPending(error);
19
+ });
20
+ this.transport.onClose(() => {
21
+ const error = new Error('transport closed');
22
+ this.emit('close');
23
+ this.rejectAllPending(error);
24
+ });
25
+ }
26
+ rejectAllPending(error) {
27
+ for (const [id, req] of this.pendingRequests.entries()) {
28
+ this.pendingRequests.delete(id);
29
+ if (req.timeoutTimer) {
30
+ clearTimeout(req.timeoutTimer);
31
+ }
32
+ req.reject(error);
33
+ }
34
+ }
35
+ handleData(chunk) {
36
+ this.buffer += chunk;
37
+ const lines = this.buffer.split('\n');
38
+ this.buffer = lines.pop() || '';
39
+ for (const line of lines) {
40
+ if (!line.trim()) {
41
+ continue;
42
+ }
43
+ try {
44
+ const msg = JSON.parse(line);
45
+ this.handleMessage(msg);
46
+ }
47
+ catch {
48
+ this.emit('error', new Error(`Failed to parse message: ${line}`));
49
+ }
50
+ }
51
+ }
52
+ handleMessage(msg) {
53
+ if (msg.id !== undefined && (msg.result !== undefined || msg.error !== undefined)) {
54
+ const req = this.pendingRequests.get(msg.id);
55
+ if (req) {
56
+ this.pendingRequests.delete(msg.id);
57
+ if (req.timeoutTimer) {
58
+ clearTimeout(req.timeoutTimer);
59
+ }
60
+ if (msg.error !== undefined) {
61
+ req.reject(msg.error);
62
+ }
63
+ else {
64
+ req.resolve(msg.result);
65
+ }
66
+ }
67
+ return;
68
+ }
69
+ if (msg.method !== undefined && msg.id === undefined) {
70
+ this.emit('notification', msg.method, msg.params);
71
+ if (msg.method === 'events/event') {
72
+ this.emit('event', msg.params);
73
+ }
74
+ }
75
+ }
76
+ async sendRequest(method, params, timeoutMs = 30_000) {
77
+ const id = (0, crypto_1.randomUUID)();
78
+ return await new Promise((resolve, reject) => {
79
+ const pending = { resolve, reject };
80
+ pending.timeoutTimer = setTimeout(() => {
81
+ this.pendingRequests.delete(id);
82
+ reject(new Error(`request timeout after ${timeoutMs}ms: ${method}`));
83
+ }, timeoutMs);
84
+ this.pendingRequests.set(id, pending);
85
+ const payload = JSON.stringify({
86
+ id,
87
+ method,
88
+ params,
89
+ });
90
+ this.transport.send(`${payload}\n`);
91
+ });
92
+ }
93
+ sendNotification(method, params) {
94
+ const payload = JSON.stringify({
95
+ method,
96
+ params
97
+ });
98
+ this.transport.send(`${payload}\n`);
99
+ }
100
+ async initialize(clientInfo, capabilities) {
101
+ const result = await this.sendRequest('initialize', {
102
+ protocolVersion: '1.0.0',
103
+ clientInfo,
104
+ capabilities
105
+ });
106
+ this.sendNotification('initialized');
107
+ this.initialized = true;
108
+ return result;
109
+ }
110
+ async subscribeEvents(families) {
111
+ return await this.sendRequest('events/subscribe', { families });
112
+ }
113
+ }
114
+ exports.AppServerClient = AppServerClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const fs = __importStar(require("fs"));
37
+ const net = __importStar(require("net"));
38
+ const os = __importStar(require("os"));
39
+ const path = __importStar(require("path"));
40
+ const readline = __importStar(require("readline"));
41
+ const ArtifactManager_1 = require("../host/ArtifactManager");
42
+ const HostServer_1 = require("../host/HostServer");
43
+ const RuntimeAdapter_1 = require("../host/RuntimeAdapter");
44
+ const HOST_VERSION = '1.0.0';
45
+ const PROTOCOL_VERSION = '1.0.0';
46
+ const args = process.argv.slice(2);
47
+ const kSessionLoggingEventIntervalMs = 500;
48
+ if (args.includes('--version') || args.includes('-v')) {
49
+ console.log('Host Version: ' + HOST_VERSION);
50
+ console.log('Protocol Version: ' + PROTOCOL_VERSION);
51
+ process.exit(0);
52
+ }
53
+ function readFlagValue(flag) {
54
+ const idx = args.indexOf(flag);
55
+ if (idx < 0) {
56
+ return undefined;
57
+ }
58
+ const value = args[idx + 1];
59
+ if (!value || value.startsWith('-')) {
60
+ throw new Error(`Missing value for ${flag}`);
61
+ }
62
+ return value;
63
+ }
64
+ function resolveRuntimePlatform() {
65
+ const raw = process.env.TIRTC_RUNTIME_PLATFORM;
66
+ if (raw && raw.trim().length > 0) {
67
+ return raw.trim();
68
+ }
69
+ if (os.platform() === 'darwin' && os.arch() === 'arm64') {
70
+ return 'macos-arm64';
71
+ }
72
+ return 'linux-x64';
73
+ }
74
+ function resolveRuntimeBundleRoot(platform) {
75
+ const explicit = process.env.TIRTC_RUNTIME_BUNDLE_ROOT;
76
+ if (explicit && explicit.trim().length > 0) {
77
+ return explicit.trim();
78
+ }
79
+ const appServerRoot = process.env.TIRTC_APP_SERVER_ROOT;
80
+ const candidates = [
81
+ appServerRoot ? path.resolve(appServerRoot, 'bin/runtime', platform) : '',
82
+ path.resolve(__dirname, '../bin/runtime', platform),
83
+ path.resolve(__dirname, '../../bin/runtime', platform),
84
+ path.resolve(process.cwd(), 'bin/runtime', platform),
85
+ path.resolve(process.cwd(), '../bin/runtime', platform),
86
+ ].filter((entry) => entry.length > 0);
87
+ for (const candidate of candidates) {
88
+ const manifest = path.join(candidate, 'manifest.txt');
89
+ if (fs.existsSync(manifest)) {
90
+ return candidate;
91
+ }
92
+ }
93
+ return candidates[0];
94
+ }
95
+ function resolveArtifactRoot() {
96
+ const explicit = process.env.TIRTC_HOST_ARTIFACT_DIR;
97
+ if (explicit && explicit.trim().length > 0) {
98
+ return explicit.trim();
99
+ }
100
+ return path.join(os.tmpdir(), 'tirtc-artifacts');
101
+ }
102
+ function resolveHostLogDir() {
103
+ const explicit = process.env.TIRTC_HOST_LOG_DIR;
104
+ if (explicit && explicit.trim().length > 0) {
105
+ return explicit.trim();
106
+ }
107
+ return path.join(resolveArtifactRoot(), 'logs');
108
+ }
109
+ function resolveConsoleMirrorEnabled() {
110
+ const raw = process.env.TIRTC_HOST_LOG_STDOUT_MIRROR;
111
+ if (!raw || raw.trim().length === 0) {
112
+ return true;
113
+ }
114
+ const normalized = raw.trim().toLowerCase();
115
+ return normalized !== '0' && normalized !== 'false' && normalized !== 'off' && normalized !== 'no';
116
+ }
117
+ function ensureArtifactRoot(dir) {
118
+ if (!fs.existsSync(dir)) {
119
+ fs.mkdirSync(dir, { recursive: true });
120
+ }
121
+ }
122
+ function createRuntimeAdapter() {
123
+ const platform = resolveRuntimePlatform();
124
+ const runtimeBundleRoot = resolveRuntimeBundleRoot(platform);
125
+ return new RuntimeAdapter_1.RuntimeBackedAdapter({
126
+ platform,
127
+ runtimeBundleRoot,
128
+ });
129
+ }
130
+ function resolveHostEndpoint(socketPath) {
131
+ const explicit = process.env.TIRTC_HOST_ENDPOINT;
132
+ if (explicit && explicit.trim().length > 0) {
133
+ return explicit.trim();
134
+ }
135
+ if (socketPath && socketPath.trim().length > 0) {
136
+ return `ipc://${socketPath}`;
137
+ }
138
+ return 'stdio://runtime-backed';
139
+ }
140
+ function createSessionLogger(hostServer, logDir, mirrorToConsole) {
141
+ if (!fs.existsSync(logDir)) {
142
+ fs.mkdirSync(logDir, { recursive: true });
143
+ }
144
+ const runtimeLogPath = path.join(logDir, 'runtime.host.log');
145
+ let pending = [];
146
+ const flushTimer = setInterval(() => {
147
+ if (pending.length === 0) {
148
+ return;
149
+ }
150
+ const chunk = pending.join('');
151
+ pending = [];
152
+ try {
153
+ fs.appendFileSync(runtimeLogPath, chunk);
154
+ }
155
+ catch {
156
+ // no-op
157
+ }
158
+ }, kSessionLoggingEventIntervalMs);
159
+ const append = (level, message) => {
160
+ const line = `[${new Date().toISOString()}][${level}] ${message}`;
161
+ pending.push(line.endsWith('\n') ? line : line + '\n');
162
+ hostServer.appendHostLog(line);
163
+ if (mirrorToConsole) {
164
+ if (level === 'error') {
165
+ console.error(message);
166
+ }
167
+ else {
168
+ console.log(message);
169
+ }
170
+ }
171
+ };
172
+ return {
173
+ info: (message) => append('info', message),
174
+ error: (message) => append('error', message),
175
+ stop: () => {
176
+ clearInterval(flushTimer);
177
+ if (pending.length > 0) {
178
+ try {
179
+ fs.appendFileSync(runtimeLogPath, pending.join(''));
180
+ }
181
+ catch {
182
+ // no-op
183
+ }
184
+ }
185
+ pending = [];
186
+ },
187
+ };
188
+ }
189
+ function bindLineProtocol(input, output, hostServer, onClose) {
190
+ const rl = readline.createInterface({
191
+ input,
192
+ terminal: false,
193
+ });
194
+ rl.on('line', async (line) => {
195
+ if (!line.trim()) {
196
+ return;
197
+ }
198
+ const response = await hostServer.handleMessage(line);
199
+ if (response) {
200
+ output.write(response + '\n');
201
+ }
202
+ });
203
+ rl.on('close', () => {
204
+ if (onClose) {
205
+ onClose();
206
+ }
207
+ });
208
+ }
209
+ function startStdio(hostServer, runtimeTarget) {
210
+ bindLineProtocol(process.stdin, process.stdout, hostServer);
211
+ console.error('TiRTC App Server Host v' +
212
+ HOST_VERSION +
213
+ ' (Protocol v' +
214
+ PROTOCOL_VERSION +
215
+ ') started on stdio [runtimeTarget=' +
216
+ runtimeTarget +
217
+ ']');
218
+ }
219
+ function startSocket(socketPath, hostServer, runtimeTarget) {
220
+ if (fs.existsSync(socketPath)) {
221
+ fs.unlinkSync(socketPath);
222
+ }
223
+ const server = net.createServer((socket) => {
224
+ const sink = (event) => {
225
+ if (socket.destroyed) {
226
+ return;
227
+ }
228
+ socket.write(JSON.stringify({ method: 'events/event', params: event }) + '\n');
229
+ };
230
+ hostServer.addEventSink(sink);
231
+ bindLineProtocol(socket, socket, hostServer, () => {
232
+ hostServer.removeEventSink(sink);
233
+ });
234
+ socket.on('close', () => {
235
+ hostServer.removeEventSink(sink);
236
+ });
237
+ socket.on('error', () => {
238
+ hostServer.removeEventSink(sink);
239
+ });
240
+ });
241
+ server.listen(socketPath, () => {
242
+ console.error('TiRTC App Server Host v' +
243
+ HOST_VERSION +
244
+ ' (Protocol v' +
245
+ PROTOCOL_VERSION +
246
+ ') started on ipc://' +
247
+ socketPath +
248
+ ' [runtimeTarget=' +
249
+ runtimeTarget +
250
+ ']');
251
+ });
252
+ const cleanup = () => {
253
+ server.close();
254
+ if (fs.existsSync(socketPath)) {
255
+ fs.unlinkSync(socketPath);
256
+ }
257
+ };
258
+ process.on('SIGINT', cleanup);
259
+ process.on('SIGTERM', cleanup);
260
+ }
261
+ const socketPath = readFlagValue('--socket');
262
+ const artifactRoot = resolveArtifactRoot();
263
+ ensureArtifactRoot(artifactRoot);
264
+ const runtimeAdapter = createRuntimeAdapter();
265
+ const artifactManager = new ArtifactManager_1.ArtifactManager(artifactRoot);
266
+ artifactManager.setupLayout();
267
+ const hostEndpoint = resolveHostEndpoint(socketPath);
268
+ const hostServer = new HostServer_1.HostServer(artifactManager, runtimeAdapter, hostEndpoint);
269
+ const hostLogDir = resolveHostLogDir();
270
+ const sessionLogger = createSessionLogger(hostServer, hostLogDir, resolveConsoleMirrorEnabled());
271
+ sessionLogger.info('TiRTC App Server Host v' +
272
+ HOST_VERSION +
273
+ ' (Protocol v' +
274
+ PROTOCOL_VERSION +
275
+ ') booting [runtimeTarget=' +
276
+ runtimeAdapter.runtimeTarget +
277
+ ']');
278
+ process.on('uncaughtException', (error) => {
279
+ sessionLogger.error('uncaughtException: ' + (error instanceof Error ? error.stack ?? error.message : String(error)));
280
+ });
281
+ process.on('unhandledRejection', (reason) => {
282
+ sessionLogger.error('unhandledRejection: ' + (reason instanceof Error ? reason.stack ?? reason.message : String(reason)));
283
+ });
284
+ process.on('exit', () => {
285
+ sessionLogger.stop();
286
+ });
287
+ if (socketPath) {
288
+ startSocket(socketPath, hostServer, runtimeAdapter.runtimeTarget);
289
+ sessionLogger.info('listening on ipc://' + socketPath);
290
+ }
291
+ else {
292
+ startStdio(hostServer, runtimeAdapter.runtimeTarget);
293
+ sessionLogger.info('listening on stdio');
294
+ }