@nativestudio/sdk 0.3.0-rc.2 → 0.3.0-rc.21

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 (282) hide show
  1. package/COMPATIBILITY.json +4 -4
  2. package/LICENSE +201 -21
  3. package/dist/_chunks/chunk-2QDPFLIO.js +1 -0
  4. package/dist/_chunks/chunk-7DXSLHXW.js +1 -0
  5. package/dist/_chunks/chunk-AFUVP2DC.js +1 -0
  6. package/dist/_chunks/chunk-ASUZJSEP.js +1 -0
  7. package/dist/_chunks/chunk-K3TIFCD3.js +1 -0
  8. package/dist/_chunks/chunk-NNDKZ5H5.js +1 -0
  9. package/dist/_chunks/chunk-Q53Q74OP.js +1 -0
  10. package/dist/_chunks/chunk-QVP4AMRJ.js +1 -0
  11. package/dist/_chunks/chunk-TT7IA5HB.js +1 -0
  12. package/dist/_chunks/chunk-UKPD77FB.js +1 -0
  13. package/dist/_chunks/chunk-V636KA7B.js +1 -0
  14. package/dist/_chunks/chunk-VXBIT7XN.js +1 -0
  15. package/dist/_chunks/chunk-WNXKJRZ6.js +1 -0
  16. package/dist/_types/contracts/agent-execution-lifecycle.d.ts +55 -43
  17. package/dist/_types/contracts/agent-execution-oauth.d.ts +2 -2
  18. package/dist/_types/contracts/agent-execution-registration.d.ts +59 -15
  19. package/dist/_types/contracts/agent-execution-selection.d.ts +7 -7
  20. package/dist/_types/contracts/agent-host-contract.d.ts +189 -0
  21. package/dist/_types/contracts/agent-host-execution.d.ts +92 -61
  22. package/dist/_types/contracts/agent-host-generic-transport.d.ts +4 -4
  23. package/dist/_types/contracts/agent-host-legacy-release.d.ts +31 -0
  24. package/dist/_types/contracts/agent-host-protocol.d.ts +71 -0
  25. package/dist/_types/contracts/agent-host-wire.d.ts +263 -0
  26. package/dist/_types/contracts/agent-host.d.ts +126 -65
  27. package/dist/_types/contracts/artifact-discovery.d.ts +143 -11
  28. package/dist/_types/contracts/audio.d.ts +166 -0
  29. package/dist/_types/contracts/component-status.d.ts +241 -0
  30. package/dist/_types/contracts/composition-authoring.d.ts +8 -8
  31. package/dist/_types/contracts/composition-frame-render.d.ts +4 -4
  32. package/dist/_types/contracts/composition-observation.d.ts +1 -1
  33. package/dist/_types/contracts/composition-render-base.d.ts +5 -4
  34. package/dist/_types/contracts/composition-render.d.ts +8 -8
  35. package/dist/_types/contracts/composition-repair.d.ts +10 -10
  36. package/dist/_types/contracts/composition-source-review.d.ts +13 -13
  37. package/dist/_types/contracts/consistency-profile.d.ts +102 -6
  38. package/dist/_types/contracts/continuity-evaluation.d.ts +1 -1
  39. package/dist/_types/contracts/delivery-completion.d.ts +1 -1
  40. package/dist/_types/contracts/delivery-manifest.d.ts +25 -11729
  41. package/dist/_types/contracts/delivery-operations.d.ts +207 -3915
  42. package/dist/_types/contracts/delivery-summary.d.ts +4 -4
  43. package/dist/_types/contracts/delivery-validation.d.ts +25 -2
  44. package/dist/_types/contracts/device-onboarding.d.ts +35 -0
  45. package/dist/_types/contracts/device-render.d.ts +113 -0
  46. package/dist/_types/contracts/editor-intelligence.d.ts +392 -2531
  47. package/dist/_types/contracts/enterprise-brand.d.ts +302 -0
  48. package/dist/_types/contracts/exploration-recommendation.d.ts +263 -11607
  49. package/dist/_types/contracts/external-agent-access.d.ts +4 -6
  50. package/dist/_types/contracts/federation-event-link-receiver.d.ts +200 -0
  51. package/dist/_types/contracts/federation-event-link.d.ts +485 -0
  52. package/dist/_types/contracts/federation-result.d.ts +239 -0
  53. package/dist/_types/contracts/final-ready.d.ts +24 -24
  54. package/dist/_types/contracts/final-render.d.ts +1742 -6949
  55. package/dist/_types/contracts/human-identity.d.ts +13 -0
  56. package/dist/_types/contracts/human-links.d.ts +58 -0
  57. package/dist/_types/contracts/index.d.ts +26 -0
  58. package/dist/_types/contracts/interface/common.d.ts +18 -0
  59. package/dist/_types/contracts/interface/execution-output.d.ts +9 -6
  60. package/dist/_types/contracts/interface/media-output.d.ts +118 -0
  61. package/dist/_types/contracts/interface/operation.d.ts +89 -0
  62. package/dist/_types/contracts/interface/production-snapshot.d.ts +106 -199
  63. package/dist/_types/contracts/interface/query.d.ts +85 -0
  64. package/dist/_types/contracts/keyframe-generation.d.ts +31 -2
  65. package/dist/_types/contracts/keyframe-review.d.ts +7 -7
  66. package/dist/_types/contracts/lifecycle-event-projections.d.ts +19 -4
  67. package/dist/_types/contracts/lifecycle-events.d.ts +54 -2
  68. package/dist/_types/contracts/local-execution/agent-component-status.d.ts +109 -0
  69. package/dist/_types/contracts/local-execution/agent-context.d.ts +385 -0
  70. package/dist/_types/contracts/local-execution/agent-evidence.d.ts +79 -0
  71. package/dist/_types/contracts/local-execution/agent-grant.d.ts +31 -0
  72. package/dist/_types/contracts/local-execution/agent-review.d.ts +529 -71
  73. package/dist/_types/contracts/local-execution/audio-profile.d.ts +6 -0
  74. package/dist/_types/contracts/local-execution/common.d.ts +12 -11
  75. package/dist/_types/contracts/local-execution/completion.d.ts +41 -45
  76. package/dist/_types/contracts/local-execution/components.d.ts +45 -0
  77. package/dist/_types/contracts/local-execution/cpu-preparation.d.ts +46 -0
  78. package/dist/_types/contracts/local-execution/cpu-resources.d.ts +55 -0
  79. package/dist/_types/contracts/local-execution/cpu-speech-job.d.ts +70 -0
  80. package/dist/_types/contracts/local-execution/cpu-speech.d.ts +161 -0
  81. package/dist/_types/contracts/local-execution/descriptor.d.ts +38 -0
  82. package/dist/_types/contracts/local-execution/device-authority.d.ts +31 -0
  83. package/dist/_types/contracts/local-execution/device-inventory.d.ts +108 -0
  84. package/dist/_types/contracts/local-execution/device-workspace.d.ts +11 -0
  85. package/dist/_types/contracts/local-execution/device.d.ts +24 -55
  86. package/dist/_types/contracts/local-execution/enrollment-credential.d.ts +141 -0
  87. package/dist/_types/contracts/local-execution/enrollment-handoff.d.ts +44 -0
  88. package/dist/_types/contracts/local-execution/external-generation.d.ts +199 -0
  89. package/dist/_types/contracts/local-execution/index.d.ts +36 -0
  90. package/dist/_types/contracts/local-execution/ipc.d.ts +2809 -231
  91. package/dist/_types/contracts/local-execution/library-command.d.ts +620 -0
  92. package/dist/_types/contracts/local-execution/library-result.d.ts +428 -0
  93. package/dist/_types/contracts/local-execution/library.d.ts +873 -0
  94. package/dist/_types/contracts/local-execution/lifecycle.d.ts +262 -48
  95. package/dist/_types/contracts/local-execution/local-navigation.d.ts +304 -67
  96. package/dist/_types/contracts/local-execution/management.d.ts +407 -0
  97. package/dist/_types/contracts/local-execution/media-recipe.d.ts +207 -0
  98. package/dist/_types/contracts/local-execution/media-validation-request.d.ts +232 -0
  99. package/dist/_types/contracts/local-execution/media-validation.d.ts +262 -0
  100. package/dist/_types/contracts/local-execution/object-transfer.d.ts +155 -0
  101. package/dist/_types/contracts/local-execution/offline.d.ts +59 -0
  102. package/dist/_types/contracts/local-execution/preview.d.ts +177 -3561
  103. package/dist/_types/contracts/local-execution/processor-capability.d.ts +49 -0
  104. package/dist/_types/contracts/local-execution/processor-direct.d.ts +290 -0
  105. package/dist/_types/contracts/local-execution/processor-recipes.d.ts +1194 -0
  106. package/dist/_types/contracts/local-execution/processor-toolchain.d.ts +47 -0
  107. package/dist/_types/contracts/local-execution/processor.d.ts +6424 -0
  108. package/dist/_types/contracts/local-execution/project-source-direct.d.ts +201 -0
  109. package/dist/_types/contracts/local-execution/qwen-tts.d.ts +31 -0
  110. package/dist/_types/contracts/local-execution/recognition.d.ts +170 -0
  111. package/dist/_types/contracts/local-execution/speech.d.ts +95 -0
  112. package/dist/_types/contracts/local-execution/tool-selection.d.ts +71 -5
  113. package/dist/_types/contracts/local-execution/whisper.d.ts +24 -0
  114. package/dist/_types/contracts/local-execution/work.d.ts +124 -3402
  115. package/dist/_types/contracts/local-execution/workspace.d.ts +141 -0
  116. package/dist/_types/contracts/mcp-capabilities.d.ts +16 -0
  117. package/dist/_types/contracts/media-category.d.ts +11 -0
  118. package/dist/_types/contracts/media-observation.d.ts +930 -9
  119. package/dist/_types/contracts/native-speech-model.d.ts +53 -0
  120. package/dist/_types/contracts/native-speech-options.d.ts +25 -0
  121. package/dist/_types/contracts/native-tool-authority.d.ts +25 -21
  122. package/dist/_types/contracts/native-tool-execution.d.ts +60 -39
  123. package/dist/_types/contracts/navigation-context.d.ts +76 -8
  124. package/dist/_types/contracts/navigation-groups.d.ts +2 -2
  125. package/dist/_types/contracts/navigation.d.ts +79 -26
  126. package/dist/_types/contracts/observation-profile.d.ts +3 -3
  127. package/dist/_types/contracts/production-creation.d.ts +30 -0
  128. package/dist/_types/contracts/production-feedback.d.ts +452 -0
  129. package/dist/_types/contracts/production.d.ts +30 -0
  130. package/dist/_types/contracts/programmatic-composition.d.ts +24 -24
  131. package/dist/_types/contracts/programmatic-exploration.d.ts +362 -5999
  132. package/dist/_types/contracts/programmatic-video-review.d.ts +5 -5
  133. package/dist/_types/contracts/project-library.d.ts +30 -0
  134. package/dist/_types/contracts/project.d.ts +30 -0
  135. package/dist/_types/contracts/provider-catalog.d.ts +3 -3
  136. package/dist/_types/contracts/provider-models.d.ts +209 -8
  137. package/dist/_types/contracts/provider.d.ts +66 -1
  138. package/dist/_types/contracts/reference-preview.d.ts +20 -0
  139. package/dist/_types/contracts/render-readiness.d.ts +175 -0
  140. package/dist/_types/contracts/repair-lifecycle.d.ts +64 -396
  141. package/dist/_types/contracts/repair-plan.d.ts +18 -100
  142. package/dist/_types/contracts/repair-strategy.d.ts +163 -4478
  143. package/dist/_types/contracts/review-intelligence-final-output.d.ts +418 -8150
  144. package/dist/_types/contracts/review-intelligence.d.ts +455 -11423
  145. package/dist/_types/contracts/review1-repair-source.d.ts +6 -6
  146. package/dist/_types/contracts/review1-repair-strategy.d.ts +4 -4
  147. package/dist/_types/contracts/rough-cut-manifest.d.ts +27 -7
  148. package/dist/_types/contracts/rough-cut-profile.d.ts +12 -3
  149. package/dist/_types/contracts/rough-cut-review.d.ts +144 -12495
  150. package/dist/_types/contracts/rough-cut.d.ts +1170 -5673
  151. package/dist/_types/contracts/series-canon.d.ts +97 -0
  152. package/dist/_types/contracts/series-character.d.ts +23 -0
  153. package/dist/_types/contracts/series-improvement.d.ts +1639 -0
  154. package/dist/_types/contracts/series-standard.d.ts +1641 -0
  155. package/dist/_types/contracts/shares.d.ts +135 -0
  156. package/dist/_types/contracts/shot-preparation-basis.d.ts +2 -2
  157. package/dist/_types/contracts/shot-preparation.d.ts +4 -4
  158. package/dist/_types/contracts/sound-making-plan.d.ts +210 -2
  159. package/dist/_types/contracts/speech-cost.d.ts +96 -0
  160. package/dist/_types/contracts/speech-parameters.d.ts +39 -0
  161. package/dist/_types/contracts/speech.d.ts +603 -23
  162. package/dist/_types/contracts/temporal-evidence-operation.d.ts +2 -1
  163. package/dist/_types/contracts/timeline-audio.d.ts +20 -4
  164. package/dist/_types/contracts/timeline-manifest.d.ts +40 -8
  165. package/dist/_types/contracts/timeline-source-sound.d.ts +42 -4
  166. package/dist/_types/contracts/timeline-v2.d.ts +124 -16
  167. package/dist/_types/contracts/timeline-version-reader.d.ts +288 -40
  168. package/dist/_types/contracts/timeline-visual-layers.d.ts +124 -16
  169. package/dist/_types/contracts/timeline.d.ts +50 -4850
  170. package/dist/_types/contracts/transcription.d.ts +1 -1
  171. package/dist/_types/contracts/video-generation.d.ts +35 -2
  172. package/dist/_types/contracts/video-review.d.ts +7 -7
  173. package/dist/_types/contracts/visual-exploration.d.ts +3 -3
  174. package/dist/_types/contracts/visual-layer-render.d.ts +298 -47
  175. package/dist/_types/contracts/visual-sequence.d.ts +22 -0
  176. package/dist/_types/contracts/voice-consistency.d.ts +183 -0
  177. package/dist/_types/contracts/voice-profile/contracts.d.ts +821 -0
  178. package/dist/_types/contracts/voice-profile/identity.d.ts +27 -0
  179. package/dist/_types/contracts/voice-profile/interface.d.ts +89 -0
  180. package/dist/_types/contracts/voice-profile/reference.d.ts +106 -0
  181. package/dist/_types/contracts/voice-review.d.ts +1194 -0
  182. package/dist/_types/contracts/workspace.d.ts +83 -0
  183. package/dist/_types/sdk/account.d.ts +13 -0
  184. package/dist/_types/sdk/auxiliary-media.d.ts +1 -0
  185. package/dist/_types/sdk/catalog/agent-host-execution.d.ts +324 -112
  186. package/dist/_types/sdk/catalog/agent-host.d.ts +222 -70
  187. package/dist/_types/sdk/catalog/assembly.d.ts +26 -37628
  188. package/dist/_types/sdk/catalog/audio-caption.d.ts +126 -22
  189. package/dist/_types/sdk/catalog/canonical-repair.d.ts +132 -132
  190. package/dist/_types/sdk/catalog/carriers.d.ts +59 -0
  191. package/dist/_types/sdk/catalog/composition-source.d.ts +14 -14
  192. package/dist/_types/sdk/catalog/composition.d.ts +17 -2813
  193. package/dist/_types/sdk/catalog/core.d.ts +636 -18
  194. package/dist/_types/sdk/catalog/delivery.d.ts +12 -14167
  195. package/dist/_types/sdk/catalog/device-library.d.ts +1024 -0
  196. package/dist/_types/sdk/catalog/device-management.d.ts +921 -0
  197. package/dist/_types/sdk/catalog/discovery.d.ts +38 -4
  198. package/dist/_types/sdk/catalog/editor.d.ts +23 -6538
  199. package/dist/_types/sdk/catalog/enterprise-brand.d.ts +462 -0
  200. package/dist/_types/sdk/catalog/federation.d.ts +4164 -0
  201. package/dist/_types/sdk/catalog/generation.d.ts +284 -8
  202. package/dist/_types/sdk/catalog/imported-visual.d.ts +246 -816
  203. package/dist/_types/sdk/catalog/keyframe-review.d.ts +10 -10
  204. package/dist/_types/sdk/catalog/lifecycle-events.d.ts +442 -16
  205. package/dist/_types/sdk/catalog/mcp.d.ts +115 -7
  206. package/dist/_types/sdk/catalog/media-descriptors.d.ts +214 -11
  207. package/dist/_types/sdk/catalog/media-observation.d.ts +1031 -14
  208. package/dist/_types/sdk/catalog/native-tool-authority.d.ts +54 -24
  209. package/dist/_types/sdk/catalog/navigation.d.ts +379 -28
  210. package/dist/_types/sdk/catalog/planning-intelligence.d.ts +136 -8
  211. package/dist/_types/sdk/catalog/programmatic-exploration.d.ts +327 -9853
  212. package/dist/_types/sdk/catalog/programmatic-review.d.ts +8 -8
  213. package/dist/_types/sdk/catalog/provider.d.ts +394 -20
  214. package/dist/_types/sdk/catalog/reference-preview.d.ts +94 -30
  215. package/dist/_types/sdk/catalog/repair-strategy.d.ts +180 -8914
  216. package/dist/_types/sdk/catalog/reviewer.d.ts +276 -23131
  217. package/dist/_types/sdk/catalog/series-standard.d.ts +5402 -0
  218. package/dist/_types/sdk/catalog/shares.d.ts +305 -0
  219. package/dist/_types/sdk/catalog/shot-preparation.d.ts +51 -2972
  220. package/dist/_types/sdk/catalog/sound-making-plan.d.ts +6 -1776
  221. package/dist/_types/sdk/catalog/source-sync.d.ts +8 -498
  222. package/dist/_types/sdk/catalog/spec.d.ts +10 -2
  223. package/dist/_types/sdk/catalog/speech.d.ts +856 -4
  224. package/dist/_types/sdk/catalog/temporal-evidence.d.ts +4 -2
  225. package/dist/_types/sdk/catalog/video-review.d.ts +10 -10
  226. package/dist/_types/sdk/catalog/visual-exploration.d.ts +556 -440
  227. package/dist/_types/sdk/catalog/voice-profile.d.ts +1547 -0
  228. package/dist/_types/sdk/catalog/voice-review.d.ts +1125 -0
  229. package/dist/_types/sdk/client.d.ts +30 -3
  230. package/dist/_types/sdk/desktop-previews.d.ts +3 -3
  231. package/dist/_types/sdk/desktop-releases.d.ts +2 -2
  232. package/dist/_types/sdk/device-enrollment-handoff.d.ts +249 -0
  233. package/dist/_types/sdk/device-renders.d.ts +3751 -0
  234. package/dist/_types/sdk/direct-source.d.ts +147 -0
  235. package/dist/_types/sdk/errors.d.ts +9 -3
  236. package/dist/_types/sdk/federation-notice-result.d.ts +22 -0
  237. package/dist/_types/sdk/feedback-observer.d.ts +10 -0
  238. package/dist/_types/sdk/host-protocol.d.ts +8 -0
  239. package/dist/_types/sdk/image-media.d.ts +2 -2
  240. package/dist/_types/sdk/immutable-media.d.ts +24 -0
  241. package/dist/_types/sdk/index.d.ts +16 -1
  242. package/dist/_types/sdk/local-runtime/components.d.ts +2 -0
  243. package/dist/_types/sdk/local-runtime/device-client.d.ts +181 -19
  244. package/dist/_types/sdk/local-runtime/library.d.ts +268 -0
  245. package/dist/_types/sdk/local-runtime/workspace.d.ts +186 -0
  246. package/dist/_types/sdk/local-runtime-client.d.ts +1934 -96
  247. package/dist/_types/sdk/mcp-client.d.ts +13 -5
  248. package/dist/_types/sdk/mcp-discovery.d.ts +14 -0
  249. package/dist/_types/sdk/mcp-image.d.ts +4 -4
  250. package/dist/_types/sdk/mcp-port.d.ts +73 -0
  251. package/dist/_types/sdk/media.d.ts +11 -9
  252. package/dist/_types/sdk/navigation-client.d.ts +56 -122
  253. package/dist/_types/sdk/navigation-facade.d.ts +191 -17
  254. package/dist/_types/sdk/observe.d.ts +31 -0
  255. package/dist/_types/sdk/runtime-authority.d.ts +18 -8
  256. package/dist/_types/sdk/transport/http.d.ts +2 -0
  257. package/dist/_types/sdk/webhook-receiver.d.ts +38 -0
  258. package/dist/account.js +1 -1
  259. package/dist/errors.js +1 -1
  260. package/dist/host-protocol.d.ts +1 -0
  261. package/dist/host-protocol.js +1 -0
  262. package/dist/index.d.ts +2 -2
  263. package/dist/index.js +1 -1
  264. package/dist/local-runtime.js +1 -1
  265. package/dist/mcp-discovery.d.ts +1 -0
  266. package/dist/mcp-discovery.js +1 -0
  267. package/dist/native/helper.exe +0 -0
  268. package/dist/native/helper.json +1 -0
  269. package/dist/runtime-authority.js +1 -1
  270. package/package.json +10 -8
  271. package/README.md +0 -75
  272. package/dist/_chunks/chunk-34KSWLCI.js +0 -1
  273. package/dist/_chunks/chunk-4IOFVNFG.js +0 -1
  274. package/dist/_chunks/chunk-4M3AGNTZ.js +0 -1
  275. package/dist/_chunks/chunk-6NVIN2NI.js +0 -1
  276. package/dist/_chunks/chunk-7YCEMDNZ.js +0 -1
  277. package/dist/native/Bootstrap.ps1 +0 -90
  278. package/dist/native/JobNative.cs +0 -127
  279. package/dist/native/JobRunner.cs +0 -360
  280. package/dist/native/NativeMain.cs +0 -146
  281. package/dist/native/PipeBridge.cs +0 -260
  282. package/dist/native/PrivateAccess.cs +0 -152
@@ -1,127 +0,0 @@
1
- using System;
2
- using System.Runtime.InteropServices;
3
- using System.Text;
4
- using Microsoft.Win32.SafeHandles;
5
- namespace NativeStudio.Platform
6
- {
7
- public static class JobNative
8
- {
9
- [StructLayout(LayoutKind.Sequential)]
10
- public struct SecurityAttributes
11
- {
12
- public int size; public IntPtr descriptor; public int inherit;
13
- }
14
- [StructLayout(LayoutKind.Sequential)]
15
- public struct StartupInfo
16
- {
17
- public int size; public string reserved, desktop, title;
18
- public uint x, y, xSize, ySize, xChars, yChars, fill, flags; public ushort show, reservedSize;
19
- public IntPtr reservedBytes, input, output, error;
20
- }
21
- [StructLayout(LayoutKind.Sequential)]
22
- public struct ProcessInfo
23
- {
24
- public IntPtr process, thread; public uint processId, threadId;
25
- }
26
- [StructLayout(LayoutKind.Sequential)]
27
- public struct BasicLimits
28
- {
29
- public long processTime, jobTime; public uint flags; public UIntPtr minWorking, maxWorking;
30
- public uint active; public UIntPtr affinity; public uint priority, scheduling;
31
- }
32
- [StructLayout(LayoutKind.Sequential)]
33
- public struct Counters
34
- {
35
- public ulong readOps, writeOps, otherOps, readBytes, writeBytes, otherBytes;
36
- }
37
- [StructLayout(LayoutKind.Sequential)]
38
- public struct ExtendedLimits
39
- {
40
- public BasicLimits basic; public Counters io; public UIntPtr processMemory, jobMemory, peakProcess, peakJob;
41
- }
42
- [StructLayout(LayoutKind.Sequential)]
43
- public struct CpuLimits
44
- {
45
- public uint flags, rate;
46
- }
47
- [DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr CreateJobObject(IntPtr sa, string name);
48
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool SetInformationJobObject(IntPtr job, int type, IntPtr value, uint size);
49
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool QueryInformationJobObject(IntPtr job, int type, IntPtr value, uint size, out uint length);
50
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
51
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool TerminateJobObject(IntPtr job, uint code);
52
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool TerminateProcess(IntPtr process, uint code);
53
- [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool CreateProcess(string application, StringBuilder command, IntPtr pa, IntPtr ta, bool inherit, uint flags, IntPtr environment, string directory, ref StartupInfo startup, out ProcessInfo info);
54
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool CreatePipe(out IntPtr read, out IntPtr write, ref SecurityAttributes sa, uint size);
55
- [DllImport("kernel32.dll", SetLastError = true)] public static extern bool SetHandleInformation(IntPtr handle, uint mask, uint flags);
56
- [DllImport("kernel32.dll")] public static extern uint ResumeThread(IntPtr thread);
57
- [DllImport("kernel32.dll")] public static extern uint WaitForSingleObject(IntPtr handle, uint ms);
58
- [DllImport("kernel32.dll")] public static extern bool GetExitCodeProcess(IntPtr process, out uint code);
59
- [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr handle);
60
- [DllImport("kernel32.dll", EntryPoint = "TerminateJobObject", SetLastError = true)]
61
- static extern bool TerminateOwnedJob(SafeFileHandle job, uint code);
62
- public static void Kill(SafeFileHandle job)
63
- {
64
- if (job == null)
65
- return;
66
- try
67
- {
68
- TerminateOwnedJob(job, 1);
69
- }
70
- catch (ObjectDisposedException) { }
71
- }
72
- public static void Set<T>(IntPtr job, int kind, T data)
73
- {
74
- int size = Marshal.SizeOf(typeof(T));
75
- IntPtr memory = Marshal.AllocHGlobal(size);
76
- try
77
- {
78
- Marshal.StructureToPtr(data, memory, false);
79
- if (!SetInformationJobObject(job, kind, memory, (uint)size))
80
- throw new Exception("JOB_LIMIT");
81
- }
82
- finally { Marshal.FreeHGlobal(memory); }
83
- }
84
- public static IntPtr Job(bool aggregate)
85
- {
86
- var job = CreateJobObject(IntPtr.Zero, null);
87
- if (job == IntPtr.Zero)
88
- throw new Exception("JOB_CREATE");
89
- try
90
- {
91
- var limits = new ExtendedLimits();
92
- limits.basic.flags = 0x2000; // KILL_ON_JOB_CLOSE; no breakaway.
93
- if (aggregate)
94
- {
95
- limits.basic.flags |= 0x200 | 8 | 0x20;
96
- limits.jobMemory = new UIntPtr(4294967296UL);
97
- limits.basic.active = 64;
98
- limits.basic.priority = 0x4000;
99
- }
100
- Set(job, 9, limits);
101
- if (aggregate)
102
- Set(job, 15, new CpuLimits { flags = 5, rate = (uint)Math.Min(10000, Math.Max(1, 20000 / Environment.ProcessorCount)) });
103
- return job;
104
- }
105
- catch { CloseHandle(job); throw; }
106
- }
107
- public static uint[] Processes(IntPtr job)
108
- {
109
- int size = 8 + 64 * IntPtr.Size;
110
- IntPtr memory = Marshal.AllocHGlobal(size);
111
- try
112
- {
113
- uint length;
114
- if (!QueryInformationJobObject(job, 3, memory, (uint)size, out length))
115
- throw new Exception("JOB_INSPECT");
116
- int count = Marshal.ReadInt32(memory, 4);
117
- if (count < 0 || count > 64)
118
- throw new Exception("JOB_LIMIT");
119
- var ids = new uint[count];
120
- for (int i = 0; i < count; i++)
121
- ids[i] = unchecked((uint)Marshal.ReadIntPtr(memory, 8 + i * IntPtr.Size).ToInt64());
122
- return ids;
123
- }
124
- finally { Marshal.FreeHGlobal(memory); }
125
- }
126
- }
127
- }
@@ -1,360 +0,0 @@
1
- using System;
2
- using System.IO;
3
- using System.Text;
4
- using System.Linq;
5
- using System.Collections;
6
- using System.Collections.Generic;
7
- using System.Diagnostics;
8
- using System.Runtime.InteropServices;
9
- using System.Threading;
10
- using Microsoft.Win32.SafeHandles;
11
- namespace NativeStudio.Platform
12
- {
13
- public static class JobRunner
14
- {
15
- static readonly object Sync = new object();
16
- static readonly Dictionary<string, IntPtr> Jobs = new Dictionary<string, IntPtr>();
17
- static readonly HashSet<string> Cancelled = new HashSet<string>();
18
- static IntPtr aggregate;
19
- static Process parent;
20
- static bool closed;
21
- public static void Parent(int id)
22
- {
23
- parent = Process.GetProcessById(id);
24
- if (parent.Handle == IntPtr.Zero)
25
- throw new Exception("PARENT");
26
- }
27
- public static bool Reserve(string id)
28
- {
29
- lock (Sync)
30
- {
31
- if (closed || Jobs.Count >= 16 || Jobs.ContainsKey(id))
32
- return false;
33
- Jobs.Add(id, IntPtr.Zero);
34
- return true;
35
- }
36
- }
37
- public static void Release(string id)
38
- {
39
- lock (Sync)
40
- {
41
- Jobs.Remove(id);
42
- Cancelled.Remove(id);
43
- }
44
- }
45
- public static void Cancel(string id)
46
- {
47
- lock (Sync)
48
- {
49
- IntPtr job;
50
- if (!Jobs.TryGetValue(id, out job))
51
- return;
52
- Cancelled.Add(id);
53
- if (job != IntPtr.Zero)
54
- JobNative.TerminateJobObject(job, 1); // Handle disposal uses the same lock.
55
- }
56
- }
57
- public static void Close()
58
- {
59
- lock (Sync)
60
- {
61
- closed = true;
62
- if (aggregate != IntPtr.Zero)
63
- {
64
- JobNative.CloseHandle(aggregate);
65
- aggregate = IntPtr.Zero;
66
- }
67
- }
68
- }
69
- static IntPtr Aggregate()
70
- {
71
- lock (Sync)
72
- {
73
- if (closed)
74
- throw new Exception("CLOSED");
75
- if (aggregate == IntPtr.Zero)
76
- {
77
- aggregate = JobNative.Job(true);
78
- var monitor = new Thread(delegate ()
79
- {
80
- try
81
- {
82
- while (!closed)
83
- {
84
- lock (Sync)
85
- {
86
- if (closed)
87
- return;
88
- long rss = Process.GetCurrentProcess().WorkingSet64;
89
- if (parent != null)
90
- {
91
- if (parent.HasExited)
92
- {
93
- Close();
94
- return;
95
- }
96
- parent.Refresh();
97
- rss += parent.WorkingSet64;
98
- }
99
- foreach (uint id in JobNative.Processes(aggregate))
100
- {
101
- try
102
- {
103
- using (var p = Process.GetProcessById((int)id))
104
- rss += p.WorkingSet64;
105
- }
106
- catch (ArgumentException) { } // A command already exited.
107
- }
108
- if (rss > 4294967296L)
109
- {
110
- Close();
111
- return;
112
- }
113
- }
114
- Thread.Sleep(100);
115
- }
116
- }
117
- catch { Close(); }
118
- });
119
- monitor.IsBackground = true;
120
- monitor.Start();
121
- }
122
- return aggregate;
123
- }
124
- }
125
- public static string Quote(string value)
126
- {
127
- if (value.IndexOf('\0') >= 0)
128
- throw new Exception("ARGUMENT");
129
- var b = new StringBuilder("\"");
130
- int slashes = 0;
131
- foreach (char c in value)
132
- {
133
- if (c == '\\')
134
- {
135
- slashes++;
136
- continue;
137
- }
138
- if (c == '\"')
139
- {
140
- b.Append('\\', slashes * 2 + 1);
141
- b.Append(c);
142
- }
143
- else
144
- {
145
- b.Append('\\', slashes);
146
- b.Append(c);
147
- }
148
- slashes = 0;
149
- }
150
- b.Append('\\', slashes * 2);
151
- b.Append('"');
152
- return b.ToString();
153
- }
154
- static IntPtr EnvironmentBlock(IDictionary<string, object> r)
155
- {
156
- var values = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
157
- values["SystemRoot"] = Environment.GetEnvironmentVariable("SystemRoot");
158
- object supplied;
159
- if (r.TryGetValue("environment", out supplied) && supplied != null)
160
- {
161
- var env = (IDictionary<string, object>)supplied;
162
- if (env.Count > 24)
163
- throw new Exception("ENVIRONMENT");
164
- foreach (var entry in env)
165
- {
166
- string key = entry.Key.ToUpperInvariant(), value = entry.Value as string;
167
- if (value == null || value.Length > 4096 || value.IndexOf('\0') >= 0 || !System.Text.RegularExpressions.Regex.IsMatch(key, @"^[A-Z][A-Z0-9_]{0,60}$") || key == "NODE_OPTIONS" || key.StartsWith("LD_") || key.StartsWith("DYLD_"))
168
- throw new Exception("ENVIRONMENT");
169
- if (key != "SYSTEMROOT")
170
- values[key] = value;
171
- }
172
- }
173
- return Marshal.StringToHGlobalUni(String.Join("\0", values.Select(v => v.Key + "=" + v.Value).ToArray()) + "\0\0");
174
- }
175
- static FileStream Stream(IntPtr handle, FileAccess access)
176
- {
177
- return new FileStream(new SafeFileHandle(handle, true), access, 4096, false);
178
- }
179
- public static object Execute(string id, IDictionary<string, object> r)
180
- {
181
- string binary = PrivateAccess.PathOf(NativeMain.Text(r, "binary"));
182
- if (!binary.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
183
- throw new Exception("EXECUTABLE");
184
- PrivateAccess.Check(binary, "file", false);
185
- var args = (IList)r["args"];
186
- if (args.Count > 512)
187
- throw new Exception("ARGUMENT");
188
- var command = new StringBuilder(Quote(binary));
189
- foreach (object arg in args)
190
- {
191
- if (!(arg is string))
192
- throw new Exception("ARGUMENT");
193
- command.Append(' ').Append(Quote((string)arg));
194
- }
195
- if (command.Length > 30000)
196
- throw new Exception("ARGUMENT_LIMIT");
197
- string input = r.ContainsKey("input") ? NativeMain.Text(r, "input") : "";
198
- if (Encoding.UTF8.GetByteCount(input) > 65536)
199
- throw new Exception("INPUT_LIMIT");
200
- int maximum = Convert.ToInt32(r["maxOutputBytes"]);
201
- long expires = Convert.ToInt64(r["expiresAt"]);
202
- if (maximum < 1 || maximum > 524288 || expires <= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
203
- throw new Exception("LIMIT");
204
- string cwd = r.ContainsKey("cwd") && r["cwd"] != null ? PrivateAccess.PathOf(NativeMain.Text(r, "cwd")) : null;
205
- IntPtr job = IntPtr.Zero, environment = IntPtr.Zero, inRead = IntPtr.Zero, inWrite = IntPtr.Zero, outRead = IntPtr.Zero, outWrite = IntPtr.Zero, errRead = IntPtr.Zero, errWrite = IntPtr.Zero;
206
- SafeFileHandle ownedJob = null;
207
- var info = new JobNative.ProcessInfo();
208
- bool assigned = false;
209
- try
210
- {
211
- var root = Aggregate();
212
- job = JobNative.Job(false);
213
- ownedJob = new SafeFileHandle(job, true);
214
- lock (Sync)
215
- {
216
- Jobs[id] = job;
217
- if (Cancelled.Contains(id) || closed)
218
- throw new Exception("CANCELLED");
219
- }
220
- var sa = new JobNative.SecurityAttributes { size = Marshal.SizeOf(typeof(JobNative.SecurityAttributes)), inherit = 1 };
221
- if (!JobNative.CreatePipe(out inRead, out inWrite, ref sa, 0) || !JobNative.CreatePipe(out outRead, out outWrite, ref sa, 0) || !JobNative.CreatePipe(out errRead, out errWrite, ref sa, 0))
222
- throw new Exception("PIPE");
223
- if (!JobNative.SetHandleInformation(inWrite, 1, 0) || !JobNative.SetHandleInformation(outRead, 1, 0) || !JobNative.SetHandleInformation(errRead, 1, 0))
224
- throw new Exception("HANDLE");
225
- var startup = new JobNative.StartupInfo { size = Marshal.SizeOf(typeof(JobNative.StartupInfo)), flags = 0x100, input = inRead, output = outWrite, error = errWrite };
226
- environment = EnvironmentBlock(r);
227
- if (!JobNative.CreateProcess(binary, command, IntPtr.Zero, IntPtr.Zero, true, 4 | 0x400 | 0x8000000, environment, cwd, ref startup, out info))
228
- throw new Exception("SPAWN");
229
- lock (Sync)
230
- {
231
- if (closed || Cancelled.Contains(id))
232
- throw new Exception("CANCELLED");
233
- if (!JobNative.AssignProcessToJobObject(root, info.process) || !JobNative.AssignProcessToJobObject(job, info.process))
234
- throw new Exception("JOB_ASSIGN");
235
- assigned = true;
236
- }
237
- JobNative.CloseHandle(inRead);
238
- inRead = IntPtr.Zero;
239
- JobNative.CloseHandle(outWrite);
240
- outWrite = IntPtr.Zero;
241
- JobNative.CloseHandle(errWrite);
242
- errWrite = IntPtr.Zero;
243
- using (var output = Stream(outRead, FileAccess.Read))
244
- using (var errors = Stream(errRead, FileAccess.Read))
245
- using (var stdin = Stream(inWrite, FileAccess.Write))
246
- using (var bytes = new MemoryStream())
247
- {
248
- outRead = errRead = inWrite = IntPtr.Zero;
249
- int failed = 0;
250
- var reader = new Thread(delegate ()
251
- {
252
- try
253
- {
254
- var buffer = new byte[4096];
255
- int count;
256
- while ((count = output.Read(buffer, 0, buffer.Length)) > 0)
257
- {
258
- if (bytes.Length + count > maximum)
259
- throw new Exception();
260
- bytes.Write(buffer, 0, count);
261
- }
262
- }
263
- catch { Interlocked.Exchange(ref failed, 1); JobNative.Kill(ownedJob); }
264
- });
265
- var diagnostics = new Thread(delegate ()
266
- {
267
- try
268
- {
269
- var buffer = new byte[4096];
270
- int count, total = 0;
271
- while ((count = errors.Read(buffer, 0, buffer.Length)) > 0)
272
- {
273
- total += count;
274
- if (total > 65536)
275
- throw new Exception();
276
- }
277
- }
278
- catch { Interlocked.Exchange(ref failed, 1); JobNative.Kill(ownedJob); }
279
- });
280
- var writer = new Thread(delegate ()
281
- {
282
- try
283
- {
284
- var b = Encoding.UTF8.GetBytes(input);
285
- stdin.Write(b, 0, b.Length);
286
- stdin.Dispose();
287
- }
288
- catch { Interlocked.Exchange(ref failed, 1); JobNative.Kill(ownedJob); }
289
- });
290
- try
291
- {
292
- reader.IsBackground = diagnostics.IsBackground = writer.IsBackground = true;
293
- reader.Start();
294
- diagnostics.Start();
295
- writer.Start();
296
- lock (Sync)
297
- {
298
- if (closed || Cancelled.Contains(id) || JobNative.ResumeThread(info.thread) == 0xffffffff)
299
- throw new Exception("CANCELLED");
300
- }
301
- while (JobNative.WaitForSingleObject(info.process, 50) == 258)
302
- {
303
- lock (Sync)
304
- {
305
- if (closed || Cancelled.Contains(id) || failed != 0 || expires <= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())
306
- throw new Exception("CANCELLED");
307
- }
308
- }
309
- uint code;
310
- if (!JobNative.GetExitCodeProcess(info.process, out code))
311
- throw new Exception("EXIT");
312
- JobNative.Kill(ownedJob); // Dispose every descendant even if it closed its streams.
313
- if (!reader.Join(2000) || !diagnostics.Join(2000) || !writer.Join(2000) || failed != 0 || code != 0)
314
- throw new Exception("EXECUTION");
315
- lock (Sync)
316
- {
317
- if (closed || Cancelled.Contains(id))
318
- throw new Exception("CANCELLED");
319
- }
320
- return new
321
- {
322
- output = Convert.ToBase64String(bytes.ToArray())
323
- };
324
- }
325
- finally
326
- {
327
- JobNative.Kill(ownedJob);
328
- foreach (var worker in new[] { reader, diagnostics, writer })
329
- if (worker.IsAlive)
330
- worker.Join(2000);
331
- }
332
- }
333
- }
334
- finally
335
- {
336
- if (info.process != IntPtr.Zero)
337
- {
338
- if (!assigned)
339
- JobNative.TerminateProcess(info.process, 1);
340
- JobNative.CloseHandle(info.process);
341
- }
342
- if (info.thread != IntPtr.Zero)
343
- JobNative.CloseHandle(info.thread);
344
- lock (Sync)
345
- {
346
- Jobs[id] = IntPtr.Zero;
347
- if (ownedJob != null)
348
- ownedJob.Dispose();
349
- else if (job != IntPtr.Zero)
350
- JobNative.CloseHandle(job);
351
- }
352
- foreach (var handle in new[] { inRead, inWrite, outRead, outWrite, errRead, errWrite })
353
- if (handle != IntPtr.Zero)
354
- JobNative.CloseHandle(handle);
355
- if (environment != IntPtr.Zero)
356
- Marshal.FreeHGlobal(environment);
357
- }
358
- }
359
- }
360
- }
@@ -1,146 +0,0 @@
1
- using System;
2
- using System.Collections.Generic;
3
- using System.Text;
4
- using System.Threading;
5
- using System.Web.Script.Serialization;
6
- namespace NativeStudio.Platform
7
- {
8
- public static class NativeMain
9
- {
10
- static readonly object Output = new object();
11
- public static readonly JavaScriptSerializer Json = new JavaScriptSerializer { MaxJsonLength = 2097152, RecursionLimit = 32 };
12
- public static string Text(IDictionary<string, object> r, string key)
13
- {
14
- object value;
15
- if (!r.TryGetValue(key, out value) || !(value is string) || ((string)value).Length > 1048576)
16
- throw new Exception("INPUT");
17
- return (string)value;
18
- }
19
- public static string Line(int limit)
20
- {
21
- var value = new StringBuilder();
22
- for (; ; )
23
- {
24
- int c = Console.In.Read();
25
- if (c < 0)
26
- return value.Length == 0 ? null : value.ToString();
27
- if (c == 10)
28
- return value.ToString();
29
- if (c != 13)
30
- value.Append((char)c);
31
- if (value.Length > limit)
32
- throw new Exception("INPUT_LIMIT");
33
- }
34
- }
35
- public static void Send(object value)
36
- {
37
- string line;
38
- lock (Json)
39
- line = Json.Serialize(value);
40
- lock (Output)
41
- {
42
- Console.WriteLine(line);
43
- Console.Out.Flush();
44
- }
45
- }
46
- static void Handle(IDictionary<string, object> r)
47
- {
48
- string id = Text(r, "id");
49
- try
50
- {
51
- var operation = Text(r, "operation");
52
- if (operation == "directory")
53
- PrivateAccess.Directory(Text(r, "path"));
54
- else if (operation == "check")
55
- PrivateAccess.Check(Text(r, "path"), Text(r, "kind"), true);
56
- else if (operation == "executable")
57
- PrivateAccess.Check(Text(r, "path"), "file", false);
58
- else if (operation == "move")
59
- PrivateAccess.Move(Text(r, "source"), Text(r, "target"), r.ContainsKey("exclusive") && (bool)r["exclusive"]);
60
- else if (operation == "execute")
61
- {
62
- Send(new
63
- {
64
- id = id,
65
- ok = true,
66
- data = JobRunner.Execute(id, r)
67
- });
68
- return;
69
- }
70
- else
71
- throw new Exception("OPERATION");
72
- Send(new
73
- {
74
- id = id,
75
- ok = true,
76
- data = true
77
- });
78
- }
79
- catch (Exception e)
80
- {
81
- Send(new
82
- {
83
- id = id,
84
- ok = false,
85
- error = e.Message == "EXISTS" ? "EXISTS" : "DENIED"
86
- });
87
- }
88
- }
89
- public static int Main(string[] args)
90
- {
91
- Console.InputEncoding = new UTF8Encoding(false);
92
- Console.OutputEncoding = new UTF8Encoding(false);
93
- try
94
- {
95
- if (args.Length == 2 && args[0] == "pipe")
96
- {
97
- PipeBridge.Run(args[1]);
98
- return 0;
99
- }
100
- if (args.Length != 2 || args[0] != "service")
101
- return 1;
102
- JobRunner.Parent(Int32.Parse(args[1]));
103
- for (; ; )
104
- {
105
- var line = Line(1048576);
106
- if (line == null)
107
- break;
108
- IDictionary<string, object> request;
109
- lock (Json)
110
- request = Json.Deserialize<Dictionary<string, object>>(line);
111
- if (Text(request, "operation") == "cancel")
112
- {
113
- JobRunner.Cancel(Text(request, "target"));
114
- continue;
115
- }
116
- if (Text(request, "operation") == "execute")
117
- {
118
- if (!JobRunner.Reserve(Text(request, "id")))
119
- {
120
- Send(new
121
- {
122
- id = Text(request, "id"),
123
- ok = false,
124
- error = "BUSY"
125
- });
126
- continue;
127
- }
128
- ThreadPool.QueueUserWorkItem(delegate
129
- {
130
- try
131
- {
132
- Handle(request);
133
- }
134
- finally { JobRunner.Release(Text(request, "id")); }
135
- });
136
- }
137
- else
138
- Handle(request);
139
- }
140
- return 0;
141
- }
142
- catch { return 1; }
143
- finally { JobRunner.Close(); }
144
- }
145
- }
146
- }