@anthropic-ai/sdk 0.123.0 → 0.124.0

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 (358) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/client.d.mts +6 -5
  3. package/client.d.mts.map +1 -1
  4. package/client.d.ts +6 -5
  5. package/client.d.ts.map +1 -1
  6. package/client.js +2 -1
  7. package/client.js.map +1 -1
  8. package/client.mjs +2 -1
  9. package/client.mjs.map +1 -1
  10. package/core/streaming.js +4 -2
  11. package/core/streaming.js.map +1 -1
  12. package/core/streaming.mjs +4 -2
  13. package/core/streaming.mjs.map +1 -1
  14. package/package.json +1 -1
  15. package/resources/beta/agents/agents.d.mts +45 -0
  16. package/resources/beta/agents/agents.d.mts.map +1 -1
  17. package/resources/beta/agents/agents.d.ts +45 -0
  18. package/resources/beta/agents/agents.d.ts.map +1 -1
  19. package/resources/beta/agents/agents.js +25 -10
  20. package/resources/beta/agents/agents.js.map +1 -1
  21. package/resources/beta/agents/agents.mjs +25 -10
  22. package/resources/beta/agents/agents.mjs.map +1 -1
  23. package/resources/beta/agents/versions.d.mts +9 -0
  24. package/resources/beta/agents/versions.d.mts.map +1 -1
  25. package/resources/beta/agents/versions.d.ts +9 -0
  26. package/resources/beta/agents/versions.d.ts.map +1 -1
  27. package/resources/beta/agents/versions.js +5 -2
  28. package/resources/beta/agents/versions.js.map +1 -1
  29. package/resources/beta/agents/versions.mjs +5 -2
  30. package/resources/beta/agents/versions.mjs.map +1 -1
  31. package/resources/beta/deployment-runs.d.mts +18 -0
  32. package/resources/beta/deployment-runs.d.mts.map +1 -1
  33. package/resources/beta/deployment-runs.d.ts +18 -0
  34. package/resources/beta/deployment-runs.d.ts.map +1 -1
  35. package/resources/beta/deployment-runs.js +10 -4
  36. package/resources/beta/deployment-runs.js.map +1 -1
  37. package/resources/beta/deployment-runs.mjs +10 -4
  38. package/resources/beta/deployment-runs.mjs.map +1 -1
  39. package/resources/beta/deployments.d.mts +72 -0
  40. package/resources/beta/deployments.d.mts.map +1 -1
  41. package/resources/beta/deployments.d.ts +72 -0
  42. package/resources/beta/deployments.d.ts.map +1 -1
  43. package/resources/beta/deployments.js +40 -16
  44. package/resources/beta/deployments.js.map +1 -1
  45. package/resources/beta/deployments.mjs +40 -16
  46. package/resources/beta/deployments.mjs.map +1 -1
  47. package/resources/beta/dreams.d.mts +45 -0
  48. package/resources/beta/dreams.d.mts.map +1 -1
  49. package/resources/beta/dreams.d.ts +45 -0
  50. package/resources/beta/dreams.d.ts.map +1 -1
  51. package/resources/beta/dreams.js +25 -10
  52. package/resources/beta/dreams.js.map +1 -1
  53. package/resources/beta/dreams.mjs +25 -10
  54. package/resources/beta/dreams.mjs.map +1 -1
  55. package/resources/beta/environments/environments.d.mts +54 -0
  56. package/resources/beta/environments/environments.d.mts.map +1 -1
  57. package/resources/beta/environments/environments.d.ts +54 -0
  58. package/resources/beta/environments/environments.d.ts.map +1 -1
  59. package/resources/beta/environments/environments.js +30 -12
  60. package/resources/beta/environments/environments.js.map +1 -1
  61. package/resources/beta/environments/environments.mjs +30 -12
  62. package/resources/beta/environments/environments.mjs.map +1 -1
  63. package/resources/beta/environments/work.d.mts +36 -0
  64. package/resources/beta/environments/work.d.mts.map +1 -1
  65. package/resources/beta/environments/work.d.ts +36 -0
  66. package/resources/beta/environments/work.d.ts.map +1 -1
  67. package/resources/beta/environments/work.js +20 -8
  68. package/resources/beta/environments/work.js.map +1 -1
  69. package/resources/beta/environments/work.mjs +20 -8
  70. package/resources/beta/environments/work.mjs.map +1 -1
  71. package/resources/beta/files.d.mts +48 -1
  72. package/resources/beta/files.d.mts.map +1 -1
  73. package/resources/beta/files.d.ts +48 -1
  74. package/resources/beta/files.d.ts.map +1 -1
  75. package/resources/beta/files.js +22 -9
  76. package/resources/beta/files.js.map +1 -1
  77. package/resources/beta/files.mjs +22 -9
  78. package/resources/beta/files.mjs.map +1 -1
  79. package/resources/beta/memory-stores/memories.d.mts +45 -0
  80. package/resources/beta/memory-stores/memories.d.mts.map +1 -1
  81. package/resources/beta/memory-stores/memories.d.ts +45 -0
  82. package/resources/beta/memory-stores/memories.d.ts.map +1 -1
  83. package/resources/beta/memory-stores/memories.js +25 -10
  84. package/resources/beta/memory-stores/memories.js.map +1 -1
  85. package/resources/beta/memory-stores/memories.mjs +25 -10
  86. package/resources/beta/memory-stores/memories.mjs.map +1 -1
  87. package/resources/beta/memory-stores/memory-stores.d.mts +54 -0
  88. package/resources/beta/memory-stores/memory-stores.d.mts.map +1 -1
  89. package/resources/beta/memory-stores/memory-stores.d.ts +54 -0
  90. package/resources/beta/memory-stores/memory-stores.d.ts.map +1 -1
  91. package/resources/beta/memory-stores/memory-stores.js +30 -12
  92. package/resources/beta/memory-stores/memory-stores.js.map +1 -1
  93. package/resources/beta/memory-stores/memory-stores.mjs +30 -12
  94. package/resources/beta/memory-stores/memory-stores.mjs.map +1 -1
  95. package/resources/beta/memory-stores/memory-versions.d.mts +31 -4
  96. package/resources/beta/memory-stores/memory-versions.d.mts.map +1 -1
  97. package/resources/beta/memory-stores/memory-versions.d.ts +31 -4
  98. package/resources/beta/memory-stores/memory-versions.d.ts.map +1 -1
  99. package/resources/beta/memory-stores/memory-versions.js +15 -6
  100. package/resources/beta/memory-stores/memory-versions.js.map +1 -1
  101. package/resources/beta/memory-stores/memory-versions.mjs +15 -6
  102. package/resources/beta/memory-stores/memory-versions.mjs.map +1 -1
  103. package/resources/beta/messages/batches.d.mts +54 -0
  104. package/resources/beta/messages/batches.d.mts.map +1 -1
  105. package/resources/beta/messages/batches.d.ts +54 -0
  106. package/resources/beta/messages/batches.d.ts.map +1 -1
  107. package/resources/beta/messages/batches.js +25 -11
  108. package/resources/beta/messages/batches.js.map +1 -1
  109. package/resources/beta/messages/batches.mjs +25 -11
  110. package/resources/beta/messages/batches.mjs.map +1 -1
  111. package/resources/beta/messages/messages.d.mts +18 -0
  112. package/resources/beta/messages/messages.d.mts.map +1 -1
  113. package/resources/beta/messages/messages.d.ts +18 -0
  114. package/resources/beta/messages/messages.d.ts.map +1 -1
  115. package/resources/beta/messages/messages.js +4 -2
  116. package/resources/beta/messages/messages.js.map +1 -1
  117. package/resources/beta/messages/messages.mjs +4 -2
  118. package/resources/beta/messages/messages.mjs.map +1 -1
  119. package/resources/beta/models.d.mts +18 -0
  120. package/resources/beta/models.d.mts.map +1 -1
  121. package/resources/beta/models.d.ts +18 -0
  122. package/resources/beta/models.d.ts.map +1 -1
  123. package/resources/beta/models.js +10 -4
  124. package/resources/beta/models.js.map +1 -1
  125. package/resources/beta/models.mjs +10 -4
  126. package/resources/beta/models.mjs.map +1 -1
  127. package/resources/beta/organization/compliance-settings.d.mts +5 -3
  128. package/resources/beta/organization/compliance-settings.d.mts.map +1 -1
  129. package/resources/beta/organization/compliance-settings.d.ts +5 -3
  130. package/resources/beta/organization/compliance-settings.d.ts.map +1 -1
  131. package/resources/beta/organization/index.d.mts +1 -1
  132. package/resources/beta/organization/index.d.mts.map +1 -1
  133. package/resources/beta/organization/index.d.ts +1 -1
  134. package/resources/beta/organization/index.d.ts.map +1 -1
  135. package/resources/beta/organization/index.js.map +1 -1
  136. package/resources/beta/organization/index.mjs.map +1 -1
  137. package/resources/beta/organization/organization.d.mts +2 -2
  138. package/resources/beta/organization/organization.d.mts.map +1 -1
  139. package/resources/beta/organization/organization.d.ts +2 -2
  140. package/resources/beta/organization/organization.d.ts.map +1 -1
  141. package/resources/beta/organization/organization.js.map +1 -1
  142. package/resources/beta/organization/organization.mjs.map +1 -1
  143. package/resources/beta/sessions/events.d.mts +27 -0
  144. package/resources/beta/sessions/events.d.mts.map +1 -1
  145. package/resources/beta/sessions/events.d.ts +27 -0
  146. package/resources/beta/sessions/events.d.ts.map +1 -1
  147. package/resources/beta/sessions/events.js +15 -6
  148. package/resources/beta/sessions/events.js.map +1 -1
  149. package/resources/beta/sessions/events.mjs +15 -6
  150. package/resources/beta/sessions/events.mjs.map +1 -1
  151. package/resources/beta/sessions/resources.d.mts +45 -0
  152. package/resources/beta/sessions/resources.d.mts.map +1 -1
  153. package/resources/beta/sessions/resources.d.ts +45 -0
  154. package/resources/beta/sessions/resources.d.ts.map +1 -1
  155. package/resources/beta/sessions/resources.js +25 -10
  156. package/resources/beta/sessions/resources.js.map +1 -1
  157. package/resources/beta/sessions/resources.mjs +25 -10
  158. package/resources/beta/sessions/resources.mjs.map +1 -1
  159. package/resources/beta/sessions/sessions.d.mts +54 -0
  160. package/resources/beta/sessions/sessions.d.mts.map +1 -1
  161. package/resources/beta/sessions/sessions.d.ts +54 -0
  162. package/resources/beta/sessions/sessions.d.ts.map +1 -1
  163. package/resources/beta/sessions/sessions.js +30 -12
  164. package/resources/beta/sessions/sessions.js.map +1 -1
  165. package/resources/beta/sessions/sessions.mjs +30 -12
  166. package/resources/beta/sessions/sessions.mjs.map +1 -1
  167. package/resources/beta/sessions/threads/events.d.mts +18 -0
  168. package/resources/beta/sessions/threads/events.d.mts.map +1 -1
  169. package/resources/beta/sessions/threads/events.d.ts +18 -0
  170. package/resources/beta/sessions/threads/events.d.ts.map +1 -1
  171. package/resources/beta/sessions/threads/events.js +10 -4
  172. package/resources/beta/sessions/threads/events.js.map +1 -1
  173. package/resources/beta/sessions/threads/events.mjs +10 -4
  174. package/resources/beta/sessions/threads/events.mjs.map +1 -1
  175. package/resources/beta/sessions/threads/threads.d.mts +27 -0
  176. package/resources/beta/sessions/threads/threads.d.mts.map +1 -1
  177. package/resources/beta/sessions/threads/threads.d.ts +27 -0
  178. package/resources/beta/sessions/threads/threads.d.ts.map +1 -1
  179. package/resources/beta/sessions/threads/threads.js +15 -6
  180. package/resources/beta/sessions/threads/threads.js.map +1 -1
  181. package/resources/beta/sessions/threads/threads.mjs +15 -6
  182. package/resources/beta/sessions/threads/threads.mjs.map +1 -1
  183. package/resources/beta/skills/skills.d.mts +36 -0
  184. package/resources/beta/skills/skills.d.mts.map +1 -1
  185. package/resources/beta/skills/skills.d.ts +36 -0
  186. package/resources/beta/skills/skills.d.ts.map +1 -1
  187. package/resources/beta/skills/skills.js +20 -8
  188. package/resources/beta/skills/skills.js.map +1 -1
  189. package/resources/beta/skills/skills.mjs +20 -8
  190. package/resources/beta/skills/skills.mjs.map +1 -1
  191. package/resources/beta/skills/versions.d.mts +45 -0
  192. package/resources/beta/skills/versions.d.mts.map +1 -1
  193. package/resources/beta/skills/versions.d.ts +45 -0
  194. package/resources/beta/skills/versions.d.ts.map +1 -1
  195. package/resources/beta/skills/versions.js +22 -9
  196. package/resources/beta/skills/versions.js.map +1 -1
  197. package/resources/beta/skills/versions.mjs +22 -9
  198. package/resources/beta/skills/versions.mjs.map +1 -1
  199. package/resources/beta/tunnels/certificates.d.mts +36 -0
  200. package/resources/beta/tunnels/certificates.d.mts.map +1 -1
  201. package/resources/beta/tunnels/certificates.d.ts +36 -0
  202. package/resources/beta/tunnels/certificates.d.ts.map +1 -1
  203. package/resources/beta/tunnels/certificates.js +20 -8
  204. package/resources/beta/tunnels/certificates.js.map +1 -1
  205. package/resources/beta/tunnels/certificates.mjs +20 -8
  206. package/resources/beta/tunnels/certificates.mjs.map +1 -1
  207. package/resources/beta/tunnels/tunnels.d.mts +54 -0
  208. package/resources/beta/tunnels/tunnels.d.mts.map +1 -1
  209. package/resources/beta/tunnels/tunnels.d.ts +54 -0
  210. package/resources/beta/tunnels/tunnels.d.ts.map +1 -1
  211. package/resources/beta/tunnels/tunnels.js +30 -12
  212. package/resources/beta/tunnels/tunnels.js.map +1 -1
  213. package/resources/beta/tunnels/tunnels.mjs +30 -12
  214. package/resources/beta/tunnels/tunnels.mjs.map +1 -1
  215. package/resources/beta/vaults/credentials.d.mts +63 -0
  216. package/resources/beta/vaults/credentials.d.mts.map +1 -1
  217. package/resources/beta/vaults/credentials.d.ts +63 -0
  218. package/resources/beta/vaults/credentials.d.ts.map +1 -1
  219. package/resources/beta/vaults/credentials.js +35 -14
  220. package/resources/beta/vaults/credentials.js.map +1 -1
  221. package/resources/beta/vaults/credentials.mjs +35 -14
  222. package/resources/beta/vaults/credentials.mjs.map +1 -1
  223. package/resources/beta/vaults/vaults.d.mts +54 -0
  224. package/resources/beta/vaults/vaults.d.mts.map +1 -1
  225. package/resources/beta/vaults/vaults.d.ts +54 -0
  226. package/resources/beta/vaults/vaults.d.ts.map +1 -1
  227. package/resources/beta/vaults/vaults.js +30 -12
  228. package/resources/beta/vaults/vaults.js.map +1 -1
  229. package/resources/beta/vaults/vaults.mjs +30 -12
  230. package/resources/beta/vaults/vaults.mjs.map +1 -1
  231. package/resources/completions.d.mts +9 -0
  232. package/resources/completions.d.mts.map +1 -1
  233. package/resources/completions.d.ts +9 -0
  234. package/resources/completions.d.ts.map +1 -1
  235. package/resources/completions.js +5 -2
  236. package/resources/completions.js.map +1 -1
  237. package/resources/completions.mjs +5 -2
  238. package/resources/completions.mjs.map +1 -1
  239. package/resources/files.d.mts +104 -15
  240. package/resources/files.d.mts.map +1 -1
  241. package/resources/files.d.ts +104 -15
  242. package/resources/files.d.ts.map +1 -1
  243. package/resources/files.js +79 -10
  244. package/resources/files.js.map +1 -1
  245. package/resources/files.mjs +79 -10
  246. package/resources/files.mjs.map +1 -1
  247. package/resources/index.d.mts +2 -2
  248. package/resources/index.d.mts.map +1 -1
  249. package/resources/index.d.ts +2 -2
  250. package/resources/index.d.ts.map +1 -1
  251. package/resources/index.js.map +1 -1
  252. package/resources/index.mjs.map +1 -1
  253. package/resources/messages/batches.d.mts +68 -6
  254. package/resources/messages/batches.d.mts.map +1 -1
  255. package/resources/messages/batches.d.ts +68 -6
  256. package/resources/messages/batches.d.ts.map +1 -1
  257. package/resources/messages/batches.js +52 -13
  258. package/resources/messages/batches.js.map +1 -1
  259. package/resources/messages/batches.mjs +52 -13
  260. package/resources/messages/batches.mjs.map +1 -1
  261. package/resources/messages/index.d.mts +1 -1
  262. package/resources/messages/index.d.mts.map +1 -1
  263. package/resources/messages/index.d.ts +1 -1
  264. package/resources/messages/index.d.ts.map +1 -1
  265. package/resources/messages/index.js.map +1 -1
  266. package/resources/messages/index.mjs.map +1 -1
  267. package/resources/messages/messages.d.mts +20 -2
  268. package/resources/messages/messages.d.mts.map +1 -1
  269. package/resources/messages/messages.d.ts +20 -2
  270. package/resources/messages/messages.d.ts.map +1 -1
  271. package/resources/messages/messages.js +10 -4
  272. package/resources/messages/messages.js.map +1 -1
  273. package/resources/messages/messages.mjs +10 -4
  274. package/resources/messages/messages.mjs.map +1 -1
  275. package/resources/models.d.mts +31 -0
  276. package/resources/models.d.mts.map +1 -1
  277. package/resources/models.d.ts +31 -0
  278. package/resources/models.d.ts.map +1 -1
  279. package/resources/models.js +23 -4
  280. package/resources/models.js.map +1 -1
  281. package/resources/models.mjs +23 -4
  282. package/resources/models.mjs.map +1 -1
  283. package/resources/skills/index.d.mts +1 -1
  284. package/resources/skills/index.d.mts.map +1 -1
  285. package/resources/skills/index.d.ts +1 -1
  286. package/resources/skills/index.d.ts.map +1 -1
  287. package/resources/skills/index.js.map +1 -1
  288. package/resources/skills/index.mjs.map +1 -1
  289. package/resources/skills/skills.d.mts +75 -10
  290. package/resources/skills/skills.d.mts.map +1 -1
  291. package/resources/skills/skills.d.ts +75 -10
  292. package/resources/skills/skills.d.ts.map +1 -1
  293. package/resources/skills/skills.js +64 -8
  294. package/resources/skills/skills.js.map +1 -1
  295. package/resources/skills/skills.mjs +64 -8
  296. package/resources/skills/skills.mjs.map +1 -1
  297. package/resources/skills/versions.d.mts +75 -5
  298. package/resources/skills/versions.d.mts.map +1 -1
  299. package/resources/skills/versions.d.ts +75 -5
  300. package/resources/skills/versions.d.ts.map +1 -1
  301. package/resources/skills/versions.js +67 -7
  302. package/resources/skills/versions.js.map +1 -1
  303. package/resources/skills/versions.mjs +67 -7
  304. package/resources/skills/versions.mjs.map +1 -1
  305. package/src/client.ts +12 -1
  306. package/src/core/streaming.ts +4 -2
  307. package/src/resources/beta/agents/agents.ts +75 -10
  308. package/src/resources/beta/agents/versions.ts +15 -2
  309. package/src/resources/beta/deployment-runs.ts +30 -4
  310. package/src/resources/beta/deployments.ts +120 -16
  311. package/src/resources/beta/dreams.ts +75 -10
  312. package/src/resources/beta/environments/environments.ts +90 -12
  313. package/src/resources/beta/environments/work.ts +60 -8
  314. package/src/resources/beta/files.ts +75 -11
  315. package/src/resources/beta/memory-stores/memories.ts +75 -10
  316. package/src/resources/beta/memory-stores/memory-stores.ts +90 -12
  317. package/src/resources/beta/memory-stores/memory-versions.ts +49 -10
  318. package/src/resources/beta/messages/batches.ts +85 -11
  319. package/src/resources/beta/messages/messages.ts +24 -2
  320. package/src/resources/beta/models.ts +30 -4
  321. package/src/resources/beta/organization/compliance-settings.ts +12 -2
  322. package/src/resources/beta/organization/index.ts +2 -0
  323. package/src/resources/beta/organization/organization.ts +4 -0
  324. package/src/resources/beta/sessions/events.ts +45 -6
  325. package/src/resources/beta/sessions/resources.ts +75 -10
  326. package/src/resources/beta/sessions/sessions.ts +90 -12
  327. package/src/resources/beta/sessions/threads/events.ts +30 -4
  328. package/src/resources/beta/sessions/threads/threads.ts +45 -6
  329. package/src/resources/beta/skills/skills.ts +60 -8
  330. package/src/resources/beta/skills/versions.ts +72 -9
  331. package/src/resources/beta/tunnels/certificates.ts +60 -8
  332. package/src/resources/beta/tunnels/tunnels.ts +90 -12
  333. package/src/resources/beta/vaults/credentials.ts +105 -14
  334. package/src/resources/beta/vaults/vaults.ts +90 -12
  335. package/src/resources/completions.ts +15 -2
  336. package/src/resources/files.ts +161 -18
  337. package/src/resources/index.ts +5 -0
  338. package/src/resources/messages/batches.ts +137 -13
  339. package/src/resources/messages/index.ts +4 -0
  340. package/src/resources/messages/messages.ts +38 -4
  341. package/src/resources/models.ts +43 -4
  342. package/src/resources/skills/index.ts +2 -0
  343. package/src/resources/skills/skills.ts +127 -13
  344. package/src/resources/skills/versions.ts +115 -11
  345. package/src/tools/agent-toolset/fs-util.ts +16 -4
  346. package/src/version.ts +1 -1
  347. package/tools/agent-toolset/fs-util.d.mts +11 -4
  348. package/tools/agent-toolset/fs-util.d.mts.map +1 -1
  349. package/tools/agent-toolset/fs-util.d.ts +11 -4
  350. package/tools/agent-toolset/fs-util.d.ts.map +1 -1
  351. package/tools/agent-toolset/fs-util.js +14 -4
  352. package/tools/agent-toolset/fs-util.js.map +1 -1
  353. package/tools/agent-toolset/fs-util.mjs +14 -4
  354. package/tools/agent-toolset/fs-util.mjs.map +1 -1
  355. package/version.d.mts +1 -1
  356. package/version.d.ts +1 -1
  357. package/version.js +1 -1
  358. package/version.mjs +1 -1
@@ -6,7 +6,9 @@ export {
6
6
  type Skill,
7
7
  type SkillSource,
8
8
  type SkillCreateParams,
9
+ type SkillRetrieveParams,
9
10
  type SkillListParams,
11
+ type SkillDeleteParams,
10
12
  type SkillsPageCursor,
11
13
  } from './skills';
12
14
  export {
@@ -15,6 +15,7 @@ import {
15
15
  import { APIPromise } from '../../core/api-promise';
16
16
  import { PageCursor, type PageCursorParams, PagePromise } from '../../core/pagination';
17
17
  import { type Uploadable } from '../../core/uploads';
18
+ import { buildHeaders } from '../../internal/headers';
18
19
  import { RequestOptions } from '../../internal/request-options';
19
20
  import { multipartFormRequestOptions } from '../../internal/uploads';
20
21
  import { path } from '../../internal/utils/path';
@@ -24,36 +25,103 @@ export class Skills extends APIResource {
24
25
 
25
26
  /**
26
27
  * Create Skill
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const skill = await client.skills.create({
32
+ * files: [fs.createReadStream('path/to/file')],
33
+ * });
34
+ * ```
27
35
  */
28
- create(body: SkillCreateParams, options?: RequestOptions): APIPromise<Skill> {
36
+ create(params: SkillCreateParams, options?: RequestOptions): APIPromise<Skill> {
37
+ const { workspace_id, ...body } = params;
29
38
  return this._client.post(
30
39
  '/v1/skills',
31
- multipartFormRequestOptions({ body, ...options }, this._client, false),
40
+ multipartFormRequestOptions(
41
+ {
42
+ body,
43
+ ...options,
44
+ headers: buildHeaders([
45
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
46
+ options?.headers,
47
+ ]),
48
+ },
49
+ this._client,
50
+ false,
51
+ ),
32
52
  );
33
53
  }
34
54
 
35
55
  /**
36
56
  * Get Skill
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const skill = await client.skills.retrieve('skill_id');
61
+ * ```
37
62
  */
38
- retrieve(skillID: string, options?: RequestOptions): APIPromise<Skill> {
39
- return this._client.get(path`/v1/skills/${skillID}`, options);
63
+ retrieve(
64
+ skillID: string,
65
+ params: SkillRetrieveParams | null | undefined = {},
66
+ options?: RequestOptions,
67
+ ): APIPromise<Skill> {
68
+ const { workspace_id } = params ?? {};
69
+ return this._client.get(path`/v1/skills/${skillID}`, {
70
+ ...options,
71
+ headers: buildHeaders([
72
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
73
+ options?.headers,
74
+ ]),
75
+ });
40
76
  }
41
77
 
42
78
  /**
43
79
  * List Skills
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * // Automatically fetches more pages as needed.
84
+ * for await (const skill of client.skills.list()) {
85
+ * // ...
86
+ * }
87
+ * ```
44
88
  */
45
89
  list(
46
- query: SkillListParams | null | undefined = {},
90
+ params: SkillListParams | null | undefined = {},
47
91
  options?: RequestOptions,
48
92
  ): PagePromise<SkillsPageCursor, Skill> {
49
- return this._client.getAPIList('/v1/skills', PageCursor<Skill>, { query, ...options });
93
+ const { workspace_id, ...query } = params ?? {};
94
+ return this._client.getAPIList('/v1/skills', PageCursor<Skill>, {
95
+ query,
96
+ ...options,
97
+ headers: buildHeaders([
98
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
99
+ options?.headers,
100
+ ]),
101
+ });
50
102
  }
51
103
 
52
104
  /**
53
105
  * Delete Skill
106
+ *
107
+ * @example
108
+ * ```ts
109
+ * const deletedSkill = await client.skills.delete('skill_id');
110
+ * ```
54
111
  */
55
- delete(skillID: string, options?: RequestOptions): APIPromise<DeletedSkill> {
56
- return this._client.delete(path`/v1/skills/${skillID}`, options);
112
+ delete(
113
+ skillID: string,
114
+ params: SkillDeleteParams | null | undefined = {},
115
+ options?: RequestOptions,
116
+ ): APIPromise<DeletedSkill> {
117
+ const { workspace_id } = params ?? {};
118
+ return this._client.delete(path`/v1/skills/${skillID}`, {
119
+ ...options,
120
+ headers: buildHeaders([
121
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
122
+ options?.headers,
123
+ ]),
124
+ });
57
125
  }
58
126
  }
59
127
 
@@ -142,7 +210,7 @@ export interface SkillSource {
142
210
 
143
211
  export interface SkillCreateParams {
144
212
  /**
145
- * Files to upload for the skill.
213
+ * Body param: Files to upload for the skill.
146
214
  *
147
215
  * All files must be in the same top-level directory and must include a SKILL.md
148
216
  * file at the root of that directory.
@@ -150,16 +218,38 @@ export interface SkillCreateParams {
150
218
  files: Array<Uploadable>;
151
219
 
152
220
  /**
153
- * Human-readable, single-line label for the Skill. Maximum 255 characters. Always
154
- * set: derived from the SKILL.md frontmatter `name` when omitted at creation. Not
155
- * unique.
221
+ * Body param: Human-readable, single-line label for the Skill. Maximum 255
222
+ * characters. Always set: derived from the SKILL.md frontmatter `name` when
223
+ * omitted at creation. Not unique.
156
224
  */
157
225
  display_name?: string | null;
226
+
227
+ /**
228
+ * Header param: Optional header to select the Workspace for this request. The
229
+ * value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
230
+ *
231
+ * Only needed for credentials that can act on more than one Workspace. A
232
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
233
+ * match that Workspace.
234
+ */
235
+ workspace_id?: string;
236
+ }
237
+
238
+ export interface SkillRetrieveParams {
239
+ /**
240
+ * Optional header to select the Workspace for this request. The value is a
241
+ * Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
242
+ *
243
+ * Only needed for credentials that can act on more than one Workspace. A
244
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
245
+ * match that Workspace.
246
+ */
247
+ workspace_id?: string;
158
248
  }
159
249
 
160
250
  export interface SkillListParams extends PageCursorParams {
161
251
  /**
162
- * Filter skills by source.
252
+ * Query param: Filter skills by source.
163
253
  *
164
254
  * If provided, only skills from the specified source will be returned:
165
255
  *
@@ -167,6 +257,28 @@ export interface SkillListParams extends PageCursorParams {
167
257
  * - `"anthropic"`: only return Anthropic-created skills
168
258
  */
169
259
  source?: string | null;
260
+
261
+ /**
262
+ * Header param: Optional header to select the Workspace for this request. The
263
+ * value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
264
+ *
265
+ * Only needed for credentials that can act on more than one Workspace. A
266
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
267
+ * match that Workspace.
268
+ */
269
+ workspace_id?: string;
270
+ }
271
+
272
+ export interface SkillDeleteParams {
273
+ /**
274
+ * Optional header to select the Workspace for this request. The value is a
275
+ * Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
276
+ *
277
+ * Only needed for credentials that can act on more than one Workspace. A
278
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
279
+ * match that Workspace.
280
+ */
281
+ workspace_id?: string;
170
282
  }
171
283
 
172
284
  Skills.Versions = Versions;
@@ -178,7 +290,9 @@ export declare namespace Skills {
178
290
  type SkillSource as SkillSource,
179
291
  type SkillsPageCursor as SkillsPageCursor,
180
292
  type SkillCreateParams as SkillCreateParams,
293
+ type SkillRetrieveParams as SkillRetrieveParams,
181
294
  type SkillListParams as SkillListParams,
295
+ type SkillDeleteParams as SkillDeleteParams,
182
296
  };
183
297
 
184
298
  export {
@@ -4,6 +4,7 @@ import { APIResource } from '../../core/resource';
4
4
  import { APIPromise } from '../../core/api-promise';
5
5
  import { PageCursor, type PageCursorParams, PagePromise } from '../../core/pagination';
6
6
  import { type Uploadable } from '../../core/uploads';
7
+ import { buildHeaders } from '../../internal/headers';
7
8
  import { RequestOptions } from '../../internal/request-options';
8
9
  import { multipartFormRequestOptions } from '../../internal/uploads';
9
10
  import { path } from '../../internal/utils/path';
@@ -11,50 +12,113 @@ import { path } from '../../internal/utils/path';
11
12
  export class Versions extends APIResource {
12
13
  /**
13
14
  * Create Skill Version
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const skillVersion = await client.skills.versions.create(
19
+ * 'skill_id',
20
+ * { files: [fs.createReadStream('path/to/file')] },
21
+ * );
22
+ * ```
14
23
  */
15
- create(skillID: string, body: VersionCreateParams, options?: RequestOptions): APIPromise<SkillVersion> {
24
+ create(skillID: string, params: VersionCreateParams, options?: RequestOptions): APIPromise<SkillVersion> {
25
+ const { workspace_id, ...body } = params;
16
26
  return this._client.post(
17
27
  path`/v1/skills/${skillID}/versions`,
18
- multipartFormRequestOptions({ body, ...options }, this._client, false),
28
+ multipartFormRequestOptions(
29
+ {
30
+ body,
31
+ ...options,
32
+ headers: buildHeaders([
33
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
34
+ options?.headers,
35
+ ]),
36
+ },
37
+ this._client,
38
+ false,
39
+ ),
19
40
  );
20
41
  }
21
42
 
22
43
  /**
23
44
  * Get Skill Version
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const skillVersion = await client.skills.versions.retrieve(
49
+ * 'version',
50
+ * { skill_id: 'skill_id' },
51
+ * );
52
+ * ```
24
53
  */
25
54
  retrieve(
26
55
  version: string,
27
56
  params: VersionRetrieveParams,
28
57
  options?: RequestOptions,
29
58
  ): APIPromise<SkillVersion> {
30
- const { skill_id } = params;
31
- return this._client.get(path`/v1/skills/${skill_id}/versions/${version}`, options);
59
+ const { skill_id, workspace_id } = params;
60
+ return this._client.get(path`/v1/skills/${skill_id}/versions/${version}`, {
61
+ ...options,
62
+ headers: buildHeaders([
63
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
64
+ options?.headers,
65
+ ]),
66
+ });
32
67
  }
33
68
 
34
69
  /**
35
70
  * List Skill Versions
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * // Automatically fetches more pages as needed.
75
+ * for await (const skillVersion of client.skills.versions.list(
76
+ * 'skill_id',
77
+ * )) {
78
+ * // ...
79
+ * }
80
+ * ```
36
81
  */
37
82
  list(
38
83
  skillID: string,
39
- query: VersionListParams | null | undefined = {},
84
+ params: VersionListParams | null | undefined = {},
40
85
  options?: RequestOptions,
41
86
  ): PagePromise<SkillVersionsPageCursor, SkillVersion> {
87
+ const { workspace_id, ...query } = params ?? {};
42
88
  return this._client.getAPIList(path`/v1/skills/${skillID}/versions`, PageCursor<SkillVersion>, {
43
89
  query,
44
90
  ...options,
91
+ headers: buildHeaders([
92
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
93
+ options?.headers,
94
+ ]),
45
95
  });
46
96
  }
47
97
 
48
98
  /**
49
99
  * Delete Skill Version
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const deletedSkillVersion =
104
+ * await client.skills.versions.delete('version', {
105
+ * skill_id: 'skill_id',
106
+ * });
107
+ * ```
50
108
  */
51
109
  delete(
52
110
  version: string,
53
111
  params: VersionDeleteParams,
54
112
  options?: RequestOptions,
55
113
  ): APIPromise<DeletedSkillVersion> {
56
- const { skill_id } = params;
57
- return this._client.delete(path`/v1/skills/${skill_id}/versions/${version}`, options);
114
+ const { skill_id, workspace_id } = params;
115
+ return this._client.delete(path`/v1/skills/${skill_id}/versions/${version}`, {
116
+ ...options,
117
+ headers: buildHeaders([
118
+ { ...(workspace_id != null ? { 'anthropic-workspace-id': workspace_id } : undefined) },
119
+ options?.headers,
120
+ ]),
121
+ });
58
122
  }
59
123
  }
60
124
 
@@ -119,32 +183,72 @@ export interface SkillVersion {
119
183
 
120
184
  export interface VersionCreateParams {
121
185
  /**
122
- * Files to upload for the skill.
186
+ * Body param: Files to upload for the skill.
123
187
  *
124
188
  * All files must be in the same top-level directory and must include a SKILL.md
125
189
  * file at the root of that directory.
126
190
  */
127
191
  files: Array<Uploadable>;
192
+
193
+ /**
194
+ * Header param: Optional header to select the Workspace for this request. The
195
+ * value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
196
+ *
197
+ * Only needed for credentials that can act on more than one Workspace. A
198
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
199
+ * match that Workspace.
200
+ */
201
+ workspace_id?: string;
128
202
  }
129
203
 
130
204
  export interface VersionRetrieveParams {
131
205
  /**
132
- * Unique identifier for the skill.
206
+ * Path param: Unique identifier for the skill.
133
207
  *
134
208
  * The format and length of IDs may change over time.
135
209
  */
136
210
  skill_id: string;
211
+
212
+ /**
213
+ * Header param: Optional header to select the Workspace for this request. The
214
+ * value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
215
+ *
216
+ * Only needed for credentials that can act on more than one Workspace. A
217
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
218
+ * match that Workspace.
219
+ */
220
+ workspace_id?: string;
137
221
  }
138
222
 
139
- export interface VersionListParams extends PageCursorParams {}
223
+ export interface VersionListParams extends PageCursorParams {
224
+ /**
225
+ * Header param: Optional header to select the Workspace for this request. The
226
+ * value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
227
+ *
228
+ * Only needed for credentials that can act on more than one Workspace. A
229
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
230
+ * match that Workspace.
231
+ */
232
+ workspace_id?: string;
233
+ }
140
234
 
141
235
  export interface VersionDeleteParams {
142
236
  /**
143
- * Unique identifier for the skill.
237
+ * Path param: Unique identifier for the skill.
144
238
  *
145
239
  * The format and length of IDs may change over time.
146
240
  */
147
241
  skill_id: string;
242
+
243
+ /**
244
+ * Header param: Optional header to select the Workspace for this request. The
245
+ * value is a Workspace ID (for example, `wrkspc_011CZkZaBF1tNoB5wlCeusgy`).
246
+ *
247
+ * Only needed for credentials that can act on more than one Workspace. A
248
+ * credential that belongs to a specific Workspace may omit it; if sent, it must
249
+ * match that Workspace.
250
+ */
251
+ workspace_id?: string;
148
252
  }
149
253
 
150
254
  export declare namespace Versions {
@@ -11,10 +11,13 @@ import { ToolError } from '../../lib/tools/ToolError';
11
11
 
12
12
  const fs = nodefs.promises;
13
13
 
14
- /** Mode for directories the file tools create — not world-writable under a 0 umask. */
15
- export const DIR_CREATE_MODE = 0o755;
16
- /** Mode for files the file tools create. */
17
- export const FILE_CREATE_MODE = 0o644;
14
+ /** Mode for directories the file tools create: owner-only under any umask, like the memory tool. */
15
+ export const DIR_CREATE_MODE = 0o700;
16
+ /**
17
+ * Mode for files the file tools create: owner-only, so other local users can't
18
+ * read what an agent wrote. A file that already exists keeps its own mode.
19
+ */
20
+ export const FILE_CREATE_MODE = 0o600;
18
21
 
19
22
  /** True when `p` is `root` itself or lexically contained within it. */
20
23
  export function isWithin(root: string, p: string): boolean {
@@ -138,13 +141,22 @@ export async function confineToRoot(
138
141
  * Atomically write `content` to `targetPath`: write a sibling temp file, fsync
139
142
  * it, then rename over the target. The rename is atomic on most filesystems, so
140
143
  * a crash mid-write never leaves the target half-written.
144
+ *
145
+ * A new file is created {@link FILE_CREATE_MODE}; an existing one keeps its
146
+ * permission bits (the rename replaces the inode, so they are copied onto the
147
+ * temp file first) — an edit must not strip `+x` or sharing the owner chose.
141
148
  */
142
149
  export async function atomicWriteFile(targetPath: string, content: string): Promise<void> {
143
150
  const dir = path.dirname(targetPath);
144
151
  const tempPath = path.join(dir, `.tmp-${process.pid}-${crypto.randomUUID()}`);
152
+ const existingMode = await fs.stat(targetPath).then(
153
+ (st) => st.mode & 0o777,
154
+ () => undefined,
155
+ );
145
156
  let handle: FileHandle | undefined;
146
157
  try {
147
158
  handle = await fs.open(tempPath, 'wx', FILE_CREATE_MODE);
159
+ if (existingMode !== undefined) await handle.chmod(existingMode);
148
160
  await handle.writeFile(content, 'utf-8');
149
161
  await handle.sync();
150
162
  await handle.close();
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.123.0'; // x-release-please-version
1
+ export const VERSION = '0.124.0'; // x-release-please-version
@@ -4,10 +4,13 @@
4
4
  * error messages. Kept out of `node.ts` so the tool implementations stay focused
5
5
  * and these helpers can be reused by every file tool.
6
6
  */
7
- /** Mode for directories the file tools create — not world-writable under a 0 umask. */
8
- export declare const DIR_CREATE_MODE = 493;
9
- /** Mode for files the file tools create. */
10
- export declare const FILE_CREATE_MODE = 420;
7
+ /** Mode for directories the file tools create: owner-only under any umask, like the memory tool. */
8
+ export declare const DIR_CREATE_MODE = 448;
9
+ /**
10
+ * Mode for files the file tools create: owner-only, so other local users can't
11
+ * read what an agent wrote. A file that already exists keeps its own mode.
12
+ */
13
+ export declare const FILE_CREATE_MODE = 384;
11
14
  /** True when `p` is `root` itself or lexically contained within it. */
12
15
  export declare function isWithin(root: string, p: string): boolean;
13
16
  /**
@@ -62,6 +65,10 @@ export declare function confineToRoot(root: string, p: string, opts?: {
62
65
  * Atomically write `content` to `targetPath`: write a sibling temp file, fsync
63
66
  * it, then rename over the target. The rename is atomic on most filesystems, so
64
67
  * a crash mid-write never leaves the target half-written.
68
+ *
69
+ * A new file is created {@link FILE_CREATE_MODE}; an existing one keeps its
70
+ * permission bits (the rename replaces the inode, so they are copied onto the
71
+ * temp file first) — an edit must not strip `+x` or sharing the owner chose.
65
72
  */
66
73
  export declare function atomicWriteFile(targetPath: string, content: string): Promise<void>;
67
74
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"fs-util.d.mts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,uFAAuF;AACvF,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAEtC,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,C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,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA8B/D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBxF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}
@@ -4,10 +4,13 @@
4
4
  * error messages. Kept out of `node.ts` so the tool implementations stay focused
5
5
  * and these helpers can be reused by every file tool.
6
6
  */
7
- /** Mode for directories the file tools create — not world-writable under a 0 umask. */
8
- export declare const DIR_CREATE_MODE = 493;
9
- /** Mode for files the file tools create. */
10
- export declare const FILE_CREATE_MODE = 420;
7
+ /** Mode for directories the file tools create: owner-only under any umask, like the memory tool. */
8
+ export declare const DIR_CREATE_MODE = 448;
9
+ /**
10
+ * Mode for files the file tools create: owner-only, so other local users can't
11
+ * read what an agent wrote. A file that already exists keeps its own mode.
12
+ */
13
+ export declare const FILE_CREATE_MODE = 384;
11
14
  /** True when `p` is `root` itself or lexically contained within it. */
12
15
  export declare function isWithin(root: string, p: string): boolean;
13
16
  /**
@@ -62,6 +65,10 @@ export declare function confineToRoot(root: string, p: string, opts?: {
62
65
  * Atomically write `content` to `targetPath`: write a sibling temp file, fsync
63
66
  * it, then rename over the target. The rename is atomic on most filesystems, so
64
67
  * a crash mid-write never leaves the target half-written.
68
+ *
69
+ * A new file is created {@link FILE_CREATE_MODE}; an existing one keeps its
70
+ * permission bits (the rename replaces the inode, so they are copied onto the
71
+ * temp file first) — an edit must not strip `+x` or sharing the owner chose.
65
72
  */
66
73
  export declare function atomicWriteFile(targetPath: string, content: string): Promise<void>;
67
74
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"fs-util.d.ts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,uFAAuF;AACvF,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAEtC,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK1G;AAKD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA8B/D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}
1
+ {"version":3,"file":"fs-util.d.ts","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,oGAAoG;AACpG,eAAO,MAAM,eAAe,MAAQ,CAAC;AACrC;;;GAGG;AACH,eAAO,MAAM,gBAAgB,MAAQ,CAAC;AAEtC,uEAAuE;AACvE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAGzD;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK1G;AAKD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG1D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA8B/D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,IAAI,CAAC,EAAE;IAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBxF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAwBjE"}
@@ -17,10 +17,13 @@ exports.fsErrorMessage = fsErrorMessage;
17
17
  const node_1 = require("../../internal/node.js");
18
18
  const ToolError_1 = require("../../lib/tools/ToolError.js");
19
19
  const fs = node_1.fs.promises;
20
- /** Mode for directories the file tools create — not world-writable under a 0 umask. */
21
- exports.DIR_CREATE_MODE = 0o755;
22
- /** Mode for files the file tools create. */
23
- exports.FILE_CREATE_MODE = 0o644;
20
+ /** Mode for directories the file tools create: owner-only under any umask, like the memory tool. */
21
+ exports.DIR_CREATE_MODE = 0o700;
22
+ /**
23
+ * Mode for files the file tools create: owner-only, so other local users can't
24
+ * read what an agent wrote. A file that already exists keeps its own mode.
25
+ */
26
+ exports.FILE_CREATE_MODE = 0o600;
24
27
  /** True when `p` is `root` itself or lexically contained within it. */
25
28
  function isWithin(root, p) {
26
29
  const rel = node_1.path.relative(root, p);
@@ -139,13 +142,20 @@ async function confineToRoot(root, p, opts) {
139
142
  * Atomically write `content` to `targetPath`: write a sibling temp file, fsync
140
143
  * it, then rename over the target. The rename is atomic on most filesystems, so
141
144
  * a crash mid-write never leaves the target half-written.
145
+ *
146
+ * A new file is created {@link FILE_CREATE_MODE}; an existing one keeps its
147
+ * permission bits (the rename replaces the inode, so they are copied onto the
148
+ * temp file first) — an edit must not strip `+x` or sharing the owner chose.
142
149
  */
143
150
  async function atomicWriteFile(targetPath, content) {
144
151
  const dir = node_1.path.dirname(targetPath);
145
152
  const tempPath = node_1.path.join(dir, `.tmp-${process.pid}-${node_1.crypto.randomUUID()}`);
153
+ const existingMode = await fs.stat(targetPath).then((st) => st.mode & 0o777, () => undefined);
146
154
  let handle;
147
155
  try {
148
156
  handle = await fs.open(tempPath, 'wx', exports.FILE_CREATE_MODE);
157
+ if (existingMode !== undefined)
158
+ await handle.chmod(existingMode);
149
159
  await handle.writeFile(content, 'utf-8');
150
160
  await handle.sync();
151
161
  await handle.close();
@@ -1 +1 @@
1
- {"version":3,"file":"fs-util.js","sourceRoot":"","sources":["../../src/tools/agent-toolset/fs-util.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAcH,4BAGC;AAUD,wCAKC;AAMD,8BAGC;AAeD,oCA8BC;AAsBD,sCAqBC;AAOD,0CA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
9
9
  const fs = nodefs.promises;
10
- /** Mode for directories the file tools create — not world-writable under a 0 umask. */
11
- export const DIR_CREATE_MODE = 0o755;
12
- /** Mode for files the file tools create. */
13
- export const FILE_CREATE_MODE = 0o644;
10
+ /** Mode for directories the file tools create: owner-only under any umask, like the memory tool. */
11
+ export const DIR_CREATE_MODE = 0o700;
12
+ /**
13
+ * Mode for files the file tools create: owner-only, so other local users can't
14
+ * read what an agent wrote. A file that already exists keeps its own mode.
15
+ */
16
+ export const FILE_CREATE_MODE = 0o600;
14
17
  /** True when `p` is `root` itself or lexically contained within it. */
15
18
  export function isWithin(root, p) {
16
19
  const rel = path.relative(root, p);
@@ -129,13 +132,20 @@ export async function confineToRoot(root, p, opts) {
129
132
  * Atomically write `content` to `targetPath`: write a sibling temp file, fsync
130
133
  * it, then rename over the target. The rename is atomic on most filesystems, so
131
134
  * a crash mid-write never leaves the target half-written.
135
+ *
136
+ * A new file is created {@link FILE_CREATE_MODE}; an existing one keeps its
137
+ * permission bits (the rename replaces the inode, so they are copied onto the
138
+ * temp file first) — an edit must not strip `+x` or sharing the owner chose.
132
139
  */
133
140
  export async function atomicWriteFile(targetPath, content) {
134
141
  const dir = path.dirname(targetPath);
135
142
  const tempPath = path.join(dir, `.tmp-${process.pid}-${crypto.randomUUID()}`);
143
+ const existingMode = await fs.stat(targetPath).then((st) => st.mode & 0o777, () => undefined);
136
144
  let handle;
137
145
  try {
138
146
  handle = await fs.open(tempPath, 'wx', FILE_CREATE_MODE);
147
+ if (existingMode !== undefined)
148
+ await handle.chmod(existingMode);
139
149
  await handle.writeFile(content, 'utf-8');
140
150
  await handle.sync();
141
151
  await handle.close();