@psnext/slingcli 2.4.20260525-4 → 2.4.20260527-2

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 (243) hide show
  1. package/bin/sling.js +4 -1
  2. package/node_modules/@aws-sdk/core/package.json +2 -2
  3. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  4. package/node_modules/@aws-sdk/credential-provider-http/dist-cjs/fromHttp/fromHttp.js +12 -6
  5. package/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js +12 -6
  6. package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -2
  7. package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
  8. package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
  9. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  10. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  11. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +3 -3
  12. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  13. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  14. package/node_modules/@aws-sdk/middleware-websocket/package.json +2 -2
  15. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  16. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  17. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  18. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  19. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  20. package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
  21. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +1 -2
  22. package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
  23. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +18 -24
  24. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  25. package/node_modules/@earendil-works/pi-ai/dist/cli.js +14 -0
  26. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +78 -63
  27. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +2 -1
  28. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +8 -22
  29. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +1 -1
  30. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js +1 -1
  31. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +60 -40
  32. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js +1 -1
  33. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js +1 -1
  34. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js +55 -0
  35. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +45 -69
  36. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +1 -0
  37. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +5 -2
  38. package/node_modules/@earendil-works/pi-ai/package.json +4 -3
  39. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.js +2 -3
  40. package/node_modules/@earendil-works/pi-coding-agent/dist/config.js +18 -12
  41. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.js +2 -1
  42. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.js +3 -2
  43. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js +8 -2
  44. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.js +2 -1
  45. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.js +18 -24
  46. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.js +8 -6
  47. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/template.js +6 -3
  48. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js +12 -29
  49. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.js +5 -1
  50. package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.js +52 -22
  51. package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js +63 -36
  52. package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.js +6 -20
  53. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.js +38 -31
  54. package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.js +9 -4
  55. package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.js +32 -24
  56. package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.js +6 -13
  57. package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.js +8 -22
  58. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js +54 -53
  59. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.js +8 -1
  60. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js +44 -81
  61. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/file-mutation-queue.js +27 -12
  62. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js +2 -3
  63. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js +3 -3
  64. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js +5 -5
  65. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.js +9 -3
  66. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js +39 -21
  67. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js +9 -8
  68. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +12 -2
  69. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.js +20 -35
  70. package/node_modules/@earendil-works/pi-coding-agent/dist/main.js +5 -6
  71. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.js +1 -1
  72. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.js +14 -5
  73. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +29 -4
  74. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message.js +1 -1
  75. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js +4 -4
  76. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js +37 -28
  77. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js +64 -7
  78. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js +15 -3
  79. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.js +14 -8
  80. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.js +124 -0
  81. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.js +31 -0
  82. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js +75 -115
  83. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js +33 -7
  84. package/node_modules/@earendil-works/pi-coding-agent/npm-shrinkwrap.json +13 -26
  85. package/node_modules/@earendil-works/pi-coding-agent/package.json +6 -6
  86. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +40 -55
  87. package/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
  88. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +12 -2
  89. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +53 -0
  90. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +4 -1
  91. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +38 -16
  92. package/node_modules/@earendil-works/pi-tui/dist/utils.js +19 -12
  93. package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  94. package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  95. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  96. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  97. package/node_modules/@earendil-works/pi-tui/package.json +3 -5
  98. package/node_modules/@smithy/node-http-handler/package.json +2 -2
  99. package/node_modules/undici/lib/api/api-request.js +1 -1
  100. package/node_modules/undici/lib/cache/sqlite-cache-store.js +3 -3
  101. package/node_modules/undici/lib/core/connect.js +16 -0
  102. package/node_modules/undici/lib/core/request.js +17 -2
  103. package/node_modules/undici/lib/core/socks5-client.js +10 -5
  104. package/node_modules/undici/lib/core/socks5-utils.js +17 -22
  105. package/node_modules/undici/lib/dispatcher/client-h1.js +64 -20
  106. package/node_modules/undici/lib/dispatcher/client.js +6 -2
  107. package/node_modules/undici/lib/dispatcher/h2c-client.js +1 -1
  108. package/node_modules/undici/lib/mock/mock-call-history.js +15 -15
  109. package/node_modules/undici/lib/util/cache.js +8 -7
  110. package/node_modules/undici/lib/web/fetch/formdata-parser.js +17 -6
  111. package/node_modules/undici/lib/web/fetch/index.js +5 -2
  112. package/node_modules/undici/lib/web/webidl/index.js +5 -5
  113. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +1 -7
  114. package/node_modules/undici/package.json +1 -1
  115. package/package.json +6 -6
  116. package/slingshot/index.js +269 -266
  117. package/node_modules/koffi/CHANGELOG.md +0 -1093
  118. package/node_modules/koffi/LICENSE.txt +0 -22
  119. package/node_modules/koffi/README.md +0 -43
  120. package/node_modules/koffi/build/koffi/darwin_arm64/koffi.node +0 -0
  121. package/node_modules/koffi/build/koffi/darwin_x64/koffi.node +0 -0
  122. package/node_modules/koffi/build/koffi/freebsd_arm64/koffi.node +0 -0
  123. package/node_modules/koffi/build/koffi/freebsd_ia32/koffi.node +0 -0
  124. package/node_modules/koffi/build/koffi/freebsd_x64/koffi.node +0 -0
  125. package/node_modules/koffi/build/koffi/linux_arm64/koffi.node +0 -0
  126. package/node_modules/koffi/build/koffi/linux_armhf/koffi.node +0 -0
  127. package/node_modules/koffi/build/koffi/linux_ia32/koffi.node +0 -0
  128. package/node_modules/koffi/build/koffi/linux_loong64/koffi.node +0 -0
  129. package/node_modules/koffi/build/koffi/linux_riscv64d/koffi.node +0 -0
  130. package/node_modules/koffi/build/koffi/linux_x64/koffi.node +0 -0
  131. package/node_modules/koffi/build/koffi/musl_arm64/koffi.node +0 -0
  132. package/node_modules/koffi/build/koffi/musl_x64/koffi.node +0 -0
  133. package/node_modules/koffi/build/koffi/openbsd_ia32/koffi.node +0 -0
  134. package/node_modules/koffi/build/koffi/openbsd_x64/koffi.node +0 -0
  135. package/node_modules/koffi/build/koffi/win32_arm64/koffi.exp +0 -0
  136. package/node_modules/koffi/build/koffi/win32_arm64/koffi.lib +0 -0
  137. package/node_modules/koffi/build/koffi/win32_arm64/koffi.node +0 -0
  138. package/node_modules/koffi/build/koffi/win32_ia32/koffi.exp +0 -0
  139. package/node_modules/koffi/build/koffi/win32_ia32/koffi.lib +0 -0
  140. package/node_modules/koffi/build/koffi/win32_ia32/koffi.node +0 -0
  141. package/node_modules/koffi/build/koffi/win32_x64/koffi.exp +0 -0
  142. package/node_modules/koffi/build/koffi/win32_x64/koffi.lib +0 -0
  143. package/node_modules/koffi/build/koffi/win32_x64/koffi.node +0 -0
  144. package/node_modules/koffi/doc/benchmarks.md +0 -126
  145. package/node_modules/koffi/doc/callbacks.md +0 -210
  146. package/node_modules/koffi/doc/contribute.md +0 -148
  147. package/node_modules/koffi/doc/functions.md +0 -250
  148. package/node_modules/koffi/doc/index.md +0 -61
  149. package/node_modules/koffi/doc/input.md +0 -471
  150. package/node_modules/koffi/doc/migration.md +0 -159
  151. package/node_modules/koffi/doc/misc.md +0 -180
  152. package/node_modules/koffi/doc/output.md +0 -305
  153. package/node_modules/koffi/doc/packaging.md +0 -88
  154. package/node_modules/koffi/doc/platforms.md +0 -36
  155. package/node_modules/koffi/doc/pointers.md +0 -328
  156. package/node_modules/koffi/doc/start.md +0 -118
  157. package/node_modules/koffi/doc/unions.md +0 -186
  158. package/node_modules/koffi/doc/variables.md +0 -102
  159. package/node_modules/koffi/index.d.ts +0 -288
  160. package/node_modules/koffi/index.js +0 -634
  161. package/node_modules/koffi/indirect.js +0 -533
  162. package/node_modules/koffi/lib/native/base/base.cc +0 -11015
  163. package/node_modules/koffi/lib/native/base/base.hh +0 -6003
  164. package/node_modules/koffi/lib/native/base/crc.inc +0 -2214
  165. package/node_modules/koffi/lib/native/base/crc_gen.py +0 -72
  166. package/node_modules/koffi/lib/native/base/mimetypes.inc +0 -1248
  167. package/node_modules/koffi/lib/native/base/mimetypes_gen.py +0 -58
  168. package/node_modules/koffi/lib/native/base/tower.cc +0 -821
  169. package/node_modules/koffi/lib/native/base/tower.hh +0 -81
  170. package/node_modules/koffi/lib/native/base/unicode.inc +0 -408
  171. package/node_modules/koffi/lib/native/base/unicode_gen.py +0 -152
  172. package/node_modules/koffi/package.json +0 -38
  173. package/node_modules/koffi/src/cnoke/LICENSE.txt +0 -22
  174. package/node_modules/koffi/src/cnoke/README.md +0 -99
  175. package/node_modules/koffi/src/cnoke/assets/FindCNoke.cmake +0 -127
  176. package/node_modules/koffi/src/cnoke/assets/toolchains.json +0 -126
  177. package/node_modules/koffi/src/cnoke/assets/win_delay_hook.c +0 -36
  178. package/node_modules/koffi/src/cnoke/cnoke.js +0 -170
  179. package/node_modules/koffi/src/cnoke/package.json +0 -24
  180. package/node_modules/koffi/src/cnoke/src/builder.js +0 -511
  181. package/node_modules/koffi/src/cnoke/src/index.js +0 -10
  182. package/node_modules/koffi/src/cnoke/src/tools.js +0 -407
  183. package/node_modules/koffi/src/koffi/CMakeLists.txt +0 -182
  184. package/node_modules/koffi/src/koffi/src/abi_arm32.cc +0 -1018
  185. package/node_modules/koffi/src/koffi/src/abi_arm32_asm.S +0 -169
  186. package/node_modules/koffi/src/koffi/src/abi_arm64.cc +0 -1295
  187. package/node_modules/koffi/src/koffi/src/abi_arm64_asm.S +0 -195
  188. package/node_modules/koffi/src/koffi/src/abi_arm64_asm.asm +0 -174
  189. package/node_modules/koffi/src/koffi/src/abi_loong64.cc +0 -5
  190. package/node_modules/koffi/src/koffi/src/abi_loong64_asm.S +0 -204
  191. package/node_modules/koffi/src/koffi/src/abi_riscv64.cc +0 -915
  192. package/node_modules/koffi/src/koffi/src/abi_riscv64_asm.S +0 -203
  193. package/node_modules/koffi/src/koffi/src/abi_x64_sysv.cc +0 -939
  194. package/node_modules/koffi/src/koffi/src/abi_x64_sysv_asm.S +0 -231
  195. package/node_modules/koffi/src/koffi/src/abi_x64_win.cc +0 -715
  196. package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.S +0 -166
  197. package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.asm +0 -192
  198. package/node_modules/koffi/src/koffi/src/abi_x86.cc +0 -860
  199. package/node_modules/koffi/src/koffi/src/abi_x86_asm.S +0 -193
  200. package/node_modules/koffi/src/koffi/src/abi_x86_asm.asm +0 -177
  201. package/node_modules/koffi/src/koffi/src/call.cc +0 -1326
  202. package/node_modules/koffi/src/koffi/src/call.hh +0 -179
  203. package/node_modules/koffi/src/koffi/src/errno.inc +0 -462
  204. package/node_modules/koffi/src/koffi/src/ffi.cc +0 -2702
  205. package/node_modules/koffi/src/koffi/src/ffi.hh +0 -354
  206. package/node_modules/koffi/src/koffi/src/init.js +0 -105
  207. package/node_modules/koffi/src/koffi/src/parser.cc +0 -220
  208. package/node_modules/koffi/src/koffi/src/parser.hh +0 -54
  209. package/node_modules/koffi/src/koffi/src/util.cc +0 -1807
  210. package/node_modules/koffi/src/koffi/src/util.hh +0 -221
  211. package/node_modules/koffi/src/koffi/src/uv.cc +0 -193
  212. package/node_modules/koffi/src/koffi/src/uv.def +0 -10
  213. package/node_modules/koffi/src/koffi/src/uv.hh +0 -40
  214. package/node_modules/koffi/src/koffi/src/win32.cc +0 -198
  215. package/node_modules/koffi/src/koffi/src/win32.hh +0 -119
  216. package/node_modules/koffi/src/koffi/tools/write_trampolines.js +0 -77
  217. package/node_modules/koffi/vendor/node-addon-api/LICENSE.md +0 -9
  218. package/node_modules/koffi/vendor/node-addon-api/README.md +0 -95
  219. package/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +0 -186
  220. package/node_modules/koffi/vendor/node-addon-api/napi-inl.h +0 -7033
  221. package/node_modules/koffi/vendor/node-addon-api/napi.h +0 -3309
  222. package/node_modules/koffi/vendor/node-api-headers/LICENSE +0 -21
  223. package/node_modules/koffi/vendor/node-api-headers/README.md +0 -95
  224. package/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +0 -125
  225. package/node_modules/koffi/vendor/node-api-headers/def/node_api.def +0 -157
  226. package/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +0 -591
  227. package/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +0 -210
  228. package/node_modules/koffi/vendor/node-api-headers/include/node_api.h +0 -265
  229. package/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +0 -58
  230. package/node_modules/koffi/vendor/node-api-headers/include/uv/aix.h +0 -32
  231. package/node_modules/koffi/vendor/node-api-headers/include/uv/bsd.h +0 -34
  232. package/node_modules/koffi/vendor/node-api-headers/include/uv/darwin.h +0 -61
  233. package/node_modules/koffi/vendor/node-api-headers/include/uv/errno.h +0 -483
  234. package/node_modules/koffi/vendor/node-api-headers/include/uv/linux.h +0 -34
  235. package/node_modules/koffi/vendor/node-api-headers/include/uv/os390.h +0 -33
  236. package/node_modules/koffi/vendor/node-api-headers/include/uv/posix.h +0 -31
  237. package/node_modules/koffi/vendor/node-api-headers/include/uv/sunos.h +0 -44
  238. package/node_modules/koffi/vendor/node-api-headers/include/uv/threadpool.h +0 -37
  239. package/node_modules/koffi/vendor/node-api-headers/include/uv/tree.h +0 -521
  240. package/node_modules/koffi/vendor/node-api-headers/include/uv/unix.h +0 -512
  241. package/node_modules/koffi/vendor/node-api-headers/include/uv/version.h +0 -43
  242. package/node_modules/koffi/vendor/node-api-headers/include/uv/win.h +0 -698
  243. package/node_modules/koffi/vendor/node-api-headers/include/uv.h +0 -1990
@@ -1,102 +0,0 @@
1
- # Variable definitions
2
-
3
- *New in Koffi 2.6*
4
-
5
- To find an exported and declare a variable, use `lib.symbol(name, type)`. You need to specify its name and its type.
6
-
7
- ```c
8
- int my_int = 42;
9
- const char *my_string = NULL;
10
- ```
11
-
12
- ```js
13
- const my_int = lib.symbol('my_int', 'int');
14
- const my_string = lib.symbol('my_string', 'const char *');
15
- ```
16
-
17
- You cannot directly manipulate these variables, use:
18
-
19
- - [koffi.decode()](#decode-to-js-values) to read their value
20
- - [koffi.encode()](#encode-to-c-memory) to change their valuèe
21
-
22
- # Decode to JS values
23
-
24
- *New in Koffi 2.2, changed in Koffi 2.3*
25
-
26
- Use `koffi.decode()` to decode C pointers, wrapped as external objects or as simple numbers.
27
-
28
- Some arguments are optional and this function can be called in several ways:
29
-
30
- - `koffi.decode(value, type)`: no offset
31
- - `koffi.decode(value, offset, type)`: explicit offset to add to the pointer before decoding
32
-
33
- By default, Koffi expects NUL terminated strings when decoding them. See below if you need to specify the string length.
34
-
35
- The following example illustrates how to decode an integer and a C string variable.
36
-
37
- ```c
38
- int my_int = 42;
39
- const char *my_string = "foobar";
40
- ```
41
-
42
- ```js
43
- const my_int = lib.symbol('my_int', 'int');
44
- const my_string = lib.symbol('my_string', 'const char *');
45
-
46
- console.log(koffi.decode(my_int, 'int')) // Prints 42
47
- console.log(koffi.decode(my_string, 'const char *')) // Prints "foobar"
48
- ```
49
-
50
- There is also an optional ending `length` argument that you can use in two cases:
51
-
52
- - Use it to give the number of bytes to decode in non-NUL terminated strings: `koffi.decode(value, 'char *', 5)`
53
- - Decode consecutive values into an array. For example, here is how you can decode an array with 3 float values: `koffi.decode(value, 'float', 3)`. This is equivalent to `koffi.decode(value, koffi.array('float', 3))`.
54
-
55
- The example below will decode the symbol `my_string` defined above but only the first three bytes.
56
-
57
- ```js
58
- // Only decode 3 bytes from the C string my_string
59
- console.log(koffi.decode(my_string, 'const char *', 3)) // Prints "foo"
60
- ```
61
-
62
- > [!NOTE]
63
- > In Koffi 2.2 and earlier versions, the length argument is only used to decode strings and is ignored otherwise.
64
-
65
- # Encode to C memory
66
-
67
- *New in Koffi 2.6*
68
-
69
- Use `koffi.encode()` to encode JS values into C symbols or pointers, wrapped as external objects or as simple numbers.
70
-
71
- Some arguments are optional and this function can be called in several ways:
72
-
73
- - `koffi.encode(ref, type, value)`: no offset
74
- - `koffi.encode(ref, offset, type, value)`: explicit offset to add to the pointer before encoding
75
-
76
- We'll reuse the examples shown above and change the variable values with `koffi.encode()`.
77
-
78
- ```c
79
- int my_int = 42;
80
- const char *my_string = NULL;
81
- ```
82
-
83
- ```js
84
- const my_int = lib.symbol('my_int', 'int');
85
- const my_string = lib.symbol('my_string', 'const char *');
86
-
87
- console.log(koffi.decode(my_int, 'int')) // Prints 42
88
- console.log(koffi.decode(my_string, 'const char *')) // Prints null
89
-
90
- koffi.encode(my_int, 'int', -1);
91
- koffi.encode(my_string, 'const char *', 'Hello World!');
92
-
93
- console.log(koffi.decode(my_int, 'int')) // Prints -1
94
- console.log(koffi.decode(my_string, 'const char *')) // Prints "Hello World!"
95
- ```
96
-
97
- When encoding strings (either directly or embedded in arrays or structs), the memory will be bound to the raw pointer value and managed by Koffi. You can assign to the same string again and again without any leak or risk of use-after-free.
98
-
99
- There is also an optional ending `length` argument that you can use to encode an array. For example, here is how you can encode an array with 3 float values: `koffi.encode(symbol, 'float', [1, 2, 3], 3)`. This is equivalent to `koffi.encode(symbol, koffi.array('float', 3), [1, 2, 3])`.
100
-
101
- > [!NOTE]
102
- > The length argument did not work correctly before Koffi 2.6.11.
@@ -1,288 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
3
-
4
- type LoadOptions = {
5
- lazy?: boolean,
6
- global?: boolean,
7
- deep?: boolean
8
- };
9
-
10
- export function load(path: string | null, options?: LoadOptions): IKoffiLib;
11
-
12
- interface IKoffiCType { __brand: 'IKoffiCType' }
13
- interface IKoffiPointerCast { __brand: 'IKoffiPointerCast' }
14
- interface IKoffiRegisteredCallback { __brand: 'IKoffiRegisteredCallback' }
15
-
16
- type PrimitiveKind = 'Void' | 'Bool' | 'Int8' | 'UInt8' | 'Int16' | 'Int16S' | 'UInt16' | 'UInt16S' |
17
- 'Int32' | 'Int32S' | 'UInt32' | 'UInt32S' | 'Int64' | 'Int64S' | 'UInt64' | 'UInt64S' |
18
- 'String' | 'String16' | 'Pointer' | 'Record' | 'Union' | 'Array' | 'Float32' | 'Float64' |
19
- 'Prototype' | 'Callback';
20
- type ArrayHint = 'Array' | 'Typed' | 'String';
21
-
22
- type TypeSpec = string | IKoffiCType;
23
- type TypeSpecWithAlignment = TypeSpec | [number, TypeSpec];
24
- type TypeInfo = {
25
- name: string;
26
- primitive: PrimitiveKind;
27
- size: number;
28
- alignment: number;
29
- disposable: boolean;
30
- length?: number;
31
- hint?: ArrayHint;
32
- ref?: IKoffiCType;
33
- members?: Record<string, { name: string, type: IKoffiCType, offset: number }>;
34
- };
35
- type KoffiFunction = {
36
- (...args: any[]) : any;
37
- async: (...args: any[]) => any;
38
- info: {
39
- name: string,
40
- arguments: IKoffiCType[],
41
- result: IKoffiCType
42
- };
43
- };
44
-
45
- export type KoffiFunc<T extends (...args: any) => any> = T & {
46
- async: (...args: [...Parameters<T>, (err: any, result: ReturnType<T>) => void]) => void;
47
- info: {
48
- name: string;
49
- arguments: IKoffiCType[];
50
- result: IKoffiCType;
51
- };
52
- };
53
-
54
- export interface IKoffiLib {
55
- func(definition: string): KoffiFunction;
56
- func(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
57
- func(convention: string, name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
58
-
59
- /** @deprecated */ cdecl(definition: string): KoffiFunction;
60
- /** @deprecated */ cdecl(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
61
- /** @deprecated */ stdcall(definition: string): KoffiFunction;
62
- /** @deprecated */ stdcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
63
- /** @deprecated */ fastcall(definition: string): KoffiFunction;
64
- /** @deprecated */ fastcall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
65
- /** @deprecated */ thiscall(definition: string): KoffiFunction;
66
- /** @deprecated */ thiscall(name: string | number, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
67
-
68
- symbol(name: string, type: TypeSpec): any;
69
-
70
- unload(): void;
71
- }
72
-
73
- export function struct(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
74
- export function struct(ref: IKoffiCType, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
75
- export function struct(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
76
- export function pack(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
77
- export function pack(ref: IKoffiCType, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
78
- export function pack(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
79
-
80
- export function union(name: string | null | undefined, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
81
- export function union(ref: IKoffiCType, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
82
- export function union(def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
83
-
84
- export class Union {
85
- constructor(type: TypeSpec);
86
- [s: string]: any;
87
- }
88
-
89
- export function array(ref: TypeSpec, len: number, hint?: ArrayHint | null): IKoffiCType;
90
- export function array(ref: TypeSpec, countedBy: string, maxLen: number, hint?: ArrayHint | null): IKoffiCType;
91
-
92
- export function opaque(name: string | null | undefined): IKoffiCType;
93
- export function opaque(): IKoffiCType;
94
- /** @deprecated */ export function handle(name: string | null | undefined): IKoffiCType;
95
- /** @deprecated */ export function handle(): IKoffiCType;
96
-
97
- export function pointer(ref: TypeSpec): IKoffiCType;
98
- export function pointer(ref: TypeSpec, count: number): IKoffiCType;
99
- export function pointer(name: string | null | undefined, ref: TypeSpec, countedBy?: string | null): IKoffiCType;
100
- export function pointer(name: string | null | undefined, ref: TypeSpec, count: number): IKoffiCType;
101
-
102
- export function out(type: TypeSpec): IKoffiCType;
103
- export function inout(type: TypeSpec): IKoffiCType;
104
-
105
- export function disposable(type: TypeSpec): IKoffiCType;
106
- export function disposable(type: TypeSpec, freeFunction: Function): IKoffiCType;
107
- export function disposable(name: string | null | undefined, type: TypeSpec): IKoffiCType;
108
- export function disposable(name: string | null | undefined, type: TypeSpec, freeFunction: Function): IKoffiCType;
109
-
110
- export function proto(definition: string): IKoffiCType;
111
- export function proto(result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
112
- export function proto(convention: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
113
- export function proto(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
114
- export function proto(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
115
- /** @deprecated */ export function callback(definition: string): IKoffiCType;
116
- /** @deprecated */ export function callback(result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
117
- /** @deprecated */ export function callback(convention: string, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
118
- /** @deprecated */ export function callback(name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
119
- /** @deprecated */ export function callback(convention: string, name: string | null | undefined, result: TypeSpec, arguments: TypeSpec[]): IKoffiCType;
120
-
121
- export function register(callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
122
- export function register(thisValue: any, callback: Function, type: TypeSpec): IKoffiRegisteredCallback;
123
- export function unregister(callback: IKoffiRegisteredCallback): void;
124
-
125
- export function as(value: any, type: TypeSpec): IKoffiPointerCast;
126
- export function decode(value: any, type: TypeSpec): any;
127
- export function decode(value: any, type: TypeSpec, len: number): any;
128
- export function decode(value: any, offset: number, type: TypeSpec): any;
129
- export function decode(value: any, offset: number, type: TypeSpec, len: number): any;
130
- export function address(value: any): bigint;
131
- export function call(value: any, type: TypeSpec, ...args: any[]): any;
132
- export function encode(ref: any, type: TypeSpec, value: any): void;
133
- export function encode(ref: any, type: TypeSpec, value: any, len: number): void;
134
- export function encode(ref: any, offset: number, type: TypeSpec): void;
135
- export function encode(ref: any, offset: number, type: TypeSpec, value: any): void;
136
- export function encode(ref: any, offset: number, type: TypeSpec, value: any, len: number): void;
137
- export function view(ref: any, len: number): ArrayBuffer;
138
-
139
- export function sizeof(type: TypeSpec): number;
140
- export function alignof(type: TypeSpec): number;
141
- export function offsetof(type: TypeSpec, member_name: string): number;
142
- export function resolve(type: TypeSpec): IKoffiCType;
143
- export function introspect(type: TypeSpec): TypeInfo;
144
-
145
- export function alias(name: string, type: TypeSpec): IKoffiCType;
146
-
147
- type KoffiConfig = {
148
- sync_stack_size?: number
149
- sync_heap_size?: number
150
- async_stack_size?: number
151
- async_heap_size?: number
152
- resident_async_pools?: number
153
- max_async_calls?: number
154
- max_type_size?: number
155
- };
156
- type KoffiStats = {
157
- disposed: number
158
- };
159
-
160
- export function config(): KoffiConfig;
161
- export function config(cfg: KoffiConfig): KoffiConfig;
162
- export function stats(): KoffiStats;
163
-
164
- export function alloc(type: TypeSpec, length: number): any;
165
- export function free(value: any): void;
166
-
167
- export function errno(): number;
168
- export function errno(value: number): number;
169
-
170
- export function reset(): void;
171
-
172
- export const internal: Boolean;
173
- export const extension: String;
174
-
175
- export const os: {
176
- errno: Record<string, number>
177
- };
178
-
179
- // https://koffi.dev/input#standard-types
180
- type PrimitiveTypes =
181
- | 'bool'
182
- | 'char'
183
- | 'char16_t'
184
- | 'char16'
185
- | 'char32_t'
186
- | 'char32'
187
- | 'double'
188
- | 'float'
189
- | 'float32'
190
- | 'float64'
191
- | 'int'
192
- | 'int8_t'
193
- | 'int8'
194
- | 'int16_be_t'
195
- | 'int16_be'
196
- | 'int16_le_t'
197
- | 'int16_le'
198
- | 'int16_t'
199
- | 'int16'
200
- | 'int32_be_t'
201
- | 'int32_be'
202
- | 'int32_le_t'
203
- | 'int32_le'
204
- | 'int32_t'
205
- | 'int32'
206
- | 'int64_be_t'
207
- | 'int64_be'
208
- | 'int64_le_t'
209
- | 'int64_le'
210
- | 'int64_t'
211
- | 'int64'
212
- | 'intptr_t'
213
- | 'intptr'
214
- | 'long long'
215
- | 'long'
216
- | 'longlong'
217
- | 'short'
218
- | 'size_t'
219
- | 'str'
220
- | 'str16'
221
- | 'str32'
222
- | 'string'
223
- | 'string16'
224
- | 'string32'
225
- | 'uchar'
226
- | 'uint'
227
- | 'uint8_t'
228
- | 'uint8'
229
- | 'uint16_be_t'
230
- | 'uint16_be'
231
- | 'uint16_le_t'
232
- | 'uint16_le'
233
- | 'uint16_t'
234
- | 'uint16'
235
- | 'uint32_be_t'
236
- | 'uint32_be'
237
- | 'uint32_le_t'
238
- | 'uint32_le'
239
- | 'uint32_t'
240
- | 'uint32'
241
- | 'uint64_be_t'
242
- | 'uint64_be'
243
- | 'uint64_le_t'
244
- | 'uint64_le'
245
- | 'uint64_t'
246
- | 'uint64'
247
- | 'uintptr_t'
248
- | 'uintptr'
249
- | 'ulong'
250
- | 'ulonglong'
251
- | 'unsigned char'
252
- | 'unsigned int'
253
- | 'unsigned long long'
254
- | 'unsigned long'
255
- | 'unsigned short'
256
- | 'ushort'
257
- | 'void'
258
- | 'wchar'
259
- | 'wchar_t';
260
- export const types: Record<PrimitiveTypes, IKoffiCType>;
261
-
262
- export interface IKoffiPollOptions {
263
- readable?: boolean;
264
- writable?: boolean;
265
- disconnect?: boolean;
266
- }
267
-
268
- export interface IKoffiPollEvents {
269
- readable: boolean;
270
- writable: boolean;
271
- disconnect: boolean;
272
- }
273
-
274
- export namespace node {
275
- export const env: { __brand: 'IKoffiNodeEnv' };
276
-
277
- export class PollHandle {
278
- start(opts: IKoffiPollOptions, callback: (ev: IKoffiPollEvents) => void): void;
279
- start(callback: (ev: IKoffiPollEvents) => void): void;
280
- stop(): void;
281
- close(): void;
282
- unref(): void;
283
- ref(): void;
284
- }
285
-
286
- export function poll(fd: number, opts: IKoffiPollOptions, callback: (ev: IKoffiPollEvents) => void): PollHandle;
287
- export function poll(fd: number, callback: (ev: IKoffiPollEvents) => void): PollHandle;
288
- }