effect 4.1.5 → 4.1.6

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 (309) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/dist/Channel.d.ts +104 -7
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +73 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Codegen.d.ts +7 -2
  7. package/dist/Codegen.d.ts.map +1 -1
  8. package/dist/Codegen.js +7 -2
  9. package/dist/Codegen.js.map +1 -1
  10. package/dist/Effect.d.ts +139 -18
  11. package/dist/Effect.d.ts.map +1 -1
  12. package/dist/Effect.js +10 -2
  13. package/dist/Effect.js.map +1 -1
  14. package/dist/Equal.d.ts +4 -4
  15. package/dist/Equal.d.ts.map +1 -1
  16. package/dist/Equal.js +78 -65
  17. package/dist/Equal.js.map +1 -1
  18. package/dist/Hash.d.ts.map +1 -1
  19. package/dist/Hash.js +24 -17
  20. package/dist/Hash.js.map +1 -1
  21. package/dist/LayerRef.d.ts +1 -1
  22. package/dist/LayerRef.d.ts.map +1 -1
  23. package/dist/LayerRef.js +3 -3
  24. package/dist/LayerRef.js.map +1 -1
  25. package/dist/Logger.d.ts +37 -13
  26. package/dist/Logger.d.ts.map +1 -1
  27. package/dist/Logger.js +39 -10
  28. package/dist/Logger.js.map +1 -1
  29. package/dist/Match.d.ts +23 -23
  30. package/dist/Match.d.ts.map +1 -1
  31. package/dist/Match.js.map +1 -1
  32. package/dist/Order.js +1 -1
  33. package/dist/Order.js.map +1 -1
  34. package/dist/Schema.d.ts +41 -0
  35. package/dist/Schema.d.ts.map +1 -1
  36. package/dist/Schema.js +51 -390
  37. package/dist/Schema.js.map +1 -1
  38. package/dist/SchemaAST.d.ts.map +1 -1
  39. package/dist/SchemaAST.js +0 -3
  40. package/dist/SchemaAST.js.map +1 -1
  41. package/dist/ScopedCache.d.ts.map +1 -1
  42. package/dist/ScopedCache.js +6 -4
  43. package/dist/ScopedCache.js.map +1 -1
  44. package/dist/Stream.d.ts +128 -5
  45. package/dist/Stream.d.ts.map +1 -1
  46. package/dist/Stream.js +124 -29
  47. package/dist/Stream.js.map +1 -1
  48. package/dist/String.js +1 -1
  49. package/dist/String.js.map +1 -1
  50. package/dist/Tracer.d.ts +10 -0
  51. package/dist/Tracer.d.ts.map +1 -1
  52. package/dist/Tracer.js +2 -0
  53. package/dist/Tracer.js.map +1 -1
  54. package/dist/ai/McpSchema.d.ts +88 -88
  55. package/dist/ai/McpSchema.d.ts.map +1 -1
  56. package/dist/ai/McpServer.d.ts +152 -2
  57. package/dist/ai/McpServer.d.ts.map +1 -1
  58. package/dist/ai/McpServer.js +8 -2
  59. package/dist/ai/McpServer.js.map +1 -1
  60. package/dist/ai/Prompt.d.ts +3 -1
  61. package/dist/ai/Prompt.d.ts.map +1 -1
  62. package/dist/ai/Prompt.js +17 -3
  63. package/dist/ai/Prompt.js.map +1 -1
  64. package/dist/ai/Skill.d.ts +172 -0
  65. package/dist/ai/Skill.d.ts.map +1 -0
  66. package/dist/ai/Skill.js +209 -0
  67. package/dist/ai/Skill.js.map +1 -0
  68. package/dist/ai/index.d.ts +5 -0
  69. package/dist/ai/index.d.ts.map +1 -1
  70. package/dist/ai/index.js +5 -0
  71. package/dist/ai/index.js.map +1 -1
  72. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  73. package/dist/cluster/ClusterWorkflowEngine.js +155 -83
  74. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  75. package/dist/cluster/MessageStorage.d.ts +56 -0
  76. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  77. package/dist/cluster/MessageStorage.js +18 -2
  78. package/dist/cluster/MessageStorage.js.map +1 -1
  79. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  80. package/dist/cluster/SqlMessageStorage.js +45 -22
  81. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  82. package/dist/cluster/internal/entityActivation.js +2 -0
  83. package/dist/cluster/internal/entityActivation.js.map +1 -1
  84. package/dist/cluster/internal/entityManager.js +8 -5
  85. package/dist/cluster/internal/entityManager.js.map +1 -1
  86. package/dist/encoding/Base64.js +5 -1
  87. package/dist/encoding/Base64.js.map +1 -1
  88. package/dist/encoding/Base64Url.d.ts.map +1 -1
  89. package/dist/encoding/Base64Url.js +6 -1
  90. package/dist/encoding/Base64Url.js.map +1 -1
  91. package/dist/encoding/Xml.d.ts +38 -9
  92. package/dist/encoding/Xml.d.ts.map +1 -1
  93. package/dist/encoding/Xml.js +63 -31
  94. package/dist/encoding/Xml.js.map +1 -1
  95. package/dist/http/FetchHttpClient.d.ts +2 -1
  96. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  97. package/dist/http/FetchHttpClient.js +14 -10
  98. package/dist/http/FetchHttpClient.js.map +1 -1
  99. package/dist/http/Headers.d.ts +201 -3
  100. package/dist/http/Headers.d.ts.map +1 -1
  101. package/dist/http/Headers.js +205 -3
  102. package/dist/http/Headers.js.map +1 -1
  103. package/dist/http/HttpClient.d.ts.map +1 -1
  104. package/dist/http/HttpClient.js +11 -7
  105. package/dist/http/HttpClient.js.map +1 -1
  106. package/dist/http/HttpClientError.d.ts +1 -0
  107. package/dist/http/HttpClientError.d.ts.map +1 -1
  108. package/dist/http/HttpClientError.js +32 -9
  109. package/dist/http/HttpClientError.js.map +1 -1
  110. package/dist/http/HttpClientRequest.d.ts +46 -0
  111. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  112. package/dist/http/HttpClientRequest.js +15 -0
  113. package/dist/http/HttpClientRequest.js.map +1 -1
  114. package/dist/http/HttpClientResponse.d.ts +132 -0
  115. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  116. package/dist/http/HttpClientResponse.js +83 -0
  117. package/dist/http/HttpClientResponse.js.map +1 -1
  118. package/dist/http/HttpMiddleware.js +1 -1
  119. package/dist/http/HttpMiddleware.js.map +1 -1
  120. package/dist/http/HttpServerResponse.d.ts +118 -0
  121. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  122. package/dist/http/HttpServerResponse.js +43 -0
  123. package/dist/http/HttpServerResponse.js.map +1 -1
  124. package/dist/http/Multipart.d.ts.map +1 -1
  125. package/dist/http/Multipart.js +0 -5
  126. package/dist/http/Multipart.js.map +1 -1
  127. package/dist/http/MultipartParser/internal/contentType.d.ts +6 -0
  128. package/dist/http/MultipartParser/internal/contentType.d.ts.map +1 -1
  129. package/dist/http/MultipartParser/internal/contentType.js +1 -1
  130. package/dist/http/MultipartParser/internal/contentType.js.map +1 -1
  131. package/dist/http/internal/clientPath.d.ts +2 -0
  132. package/dist/http/internal/clientPath.d.ts.map +1 -0
  133. package/dist/http/internal/clientPath.js +24 -0
  134. package/dist/http/internal/clientPath.js.map +1 -0
  135. package/dist/http/internal/redactedPath.js +2 -0
  136. package/dist/http/internal/redactedPath.js.map +1 -1
  137. package/dist/http/internal/tracing.js +5 -3
  138. package/dist/http/internal/tracing.js.map +1 -1
  139. package/dist/http-api/HttpApi.d.ts +2 -2
  140. package/dist/http-api/HttpApi.d.ts.map +1 -1
  141. package/dist/http-api/HttpApi.js +30 -7
  142. package/dist/http-api/HttpApi.js.map +1 -1
  143. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  144. package/dist/http-api/HttpApiBuilder.js +5 -2
  145. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  146. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  147. package/dist/http-api/HttpApiClient.js +23 -6
  148. package/dist/http-api/HttpApiClient.js.map +1 -1
  149. package/dist/http-api/internal/redactedKeys.d.ts +2 -0
  150. package/dist/http-api/internal/redactedKeys.d.ts.map +1 -0
  151. package/dist/http-api/internal/redactedKeys.js +37 -0
  152. package/dist/http-api/internal/redactedKeys.js.map +1 -0
  153. package/dist/internal/base64.js +34 -2
  154. package/dist/internal/base64.js.map +1 -1
  155. package/dist/internal/dateTime.js +35 -17
  156. package/dist/internal/dateTime.js.map +1 -1
  157. package/dist/internal/effect.js +9 -1
  158. package/dist/internal/effect.js.map +1 -1
  159. package/dist/internal/equal.js +14 -13
  160. package/dist/internal/equal.js.map +1 -1
  161. package/dist/internal/hash.js +4 -1
  162. package/dist/internal/hash.js.map +1 -1
  163. package/dist/internal/matcher.js +17 -17
  164. package/dist/internal/matcher.js.map +1 -1
  165. package/dist/internal/schema/schemaCodegen.js +3 -2
  166. package/dist/internal/schema/schemaCodegen.js.map +1 -1
  167. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts +2 -0
  168. package/dist/internal/schema/schemaCodegenBuiltIns.d.ts.map +1 -0
  169. package/dist/internal/schema/schemaCodegenBuiltIns.js +425 -0
  170. package/dist/internal/schema/schemaCodegenBuiltIns.js.map +1 -0
  171. package/dist/internal/schema/toEquivalence.js +3 -4
  172. package/dist/internal/schema/toEquivalence.js.map +1 -1
  173. package/dist/internal/version.js +1 -1
  174. package/dist/jose/JoseError.d.ts +51 -1
  175. package/dist/jose/JoseError.d.ts.map +1 -1
  176. package/dist/jose/JoseError.js +25 -18
  177. package/dist/jose/JoseError.js.map +1 -1
  178. package/dist/jose/internal/compact.js +10 -5
  179. package/dist/jose/internal/compact.js.map +1 -1
  180. package/dist/observability/Otlp.d.ts +19 -0
  181. package/dist/observability/Otlp.d.ts.map +1 -1
  182. package/dist/observability/Otlp.js +10 -0
  183. package/dist/observability/Otlp.js.map +1 -1
  184. package/dist/observability/OtlpExporter.d.ts +49 -13
  185. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  186. package/dist/observability/OtlpExporter.js +135 -54
  187. package/dist/observability/OtlpExporter.js.map +1 -1
  188. package/dist/observability/OtlpLogger.d.ts +14 -0
  189. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  190. package/dist/observability/OtlpLogger.js +10 -2
  191. package/dist/observability/OtlpLogger.js.map +1 -1
  192. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  193. package/dist/observability/OtlpMetrics.js +2 -0
  194. package/dist/observability/OtlpMetrics.js.map +1 -1
  195. package/dist/observability/OtlpTracer.d.ts +14 -0
  196. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  197. package/dist/observability/OtlpTracer.js +10 -2
  198. package/dist/observability/OtlpTracer.js.map +1 -1
  199. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  200. package/dist/persistence/KeyValueStore.js +6 -4
  201. package/dist/persistence/KeyValueStore.js.map +1 -1
  202. package/dist/reactivity/Atom.d.ts.map +1 -1
  203. package/dist/reactivity/Atom.js +10 -9
  204. package/dist/reactivity/Atom.js.map +1 -1
  205. package/dist/rpc/RpcClient.d.ts.map +1 -1
  206. package/dist/rpc/RpcClient.js +32 -1
  207. package/dist/rpc/RpcClient.js.map +1 -1
  208. package/dist/rpc/RpcGroup.d.ts +1 -1
  209. package/dist/rpc/RpcGroup.d.ts.map +1 -1
  210. package/dist/rpc/RpcGroup.js +4 -0
  211. package/dist/rpc/RpcGroup.js.map +1 -1
  212. package/dist/sql/Migrator.d.ts.map +1 -1
  213. package/dist/sql/Migrator.js +2 -5
  214. package/dist/sql/Migrator.js.map +1 -1
  215. package/dist/sql/SqlClient.d.ts.map +1 -1
  216. package/dist/sql/SqlClient.js +5 -1
  217. package/dist/sql/SqlClient.js.map +1 -1
  218. package/dist/workflow/Activity.d.ts +18 -0
  219. package/dist/workflow/Activity.d.ts.map +1 -1
  220. package/dist/workflow/Activity.js +13 -4
  221. package/dist/workflow/Activity.js.map +1 -1
  222. package/dist/workflow/Workflow.d.ts +10 -9
  223. package/dist/workflow/Workflow.d.ts.map +1 -1
  224. package/dist/workflow/Workflow.js +33 -22
  225. package/dist/workflow/Workflow.js.map +1 -1
  226. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  227. package/dist/workflow/WorkflowEngine.js +26 -12
  228. package/dist/workflow/WorkflowEngine.js.map +1 -1
  229. package/dist/workflow/internal/retry.d.ts +2 -0
  230. package/dist/workflow/internal/retry.d.ts.map +1 -0
  231. package/dist/workflow/internal/retry.js +11 -0
  232. package/dist/workflow/internal/retry.js.map +1 -0
  233. package/dist/workflow/internal/scope.d.ts +2 -0
  234. package/dist/workflow/internal/scope.d.ts.map +1 -0
  235. package/dist/workflow/internal/scope.js +26 -0
  236. package/dist/workflow/internal/scope.js.map +1 -0
  237. package/package.json +3 -3
  238. package/src/Channel.ts +105 -8
  239. package/src/Codegen.ts +7 -2
  240. package/src/Effect.ts +224 -48
  241. package/src/Equal.ts +85 -79
  242. package/src/Hash.ts +30 -22
  243. package/src/LayerRef.ts +6 -4
  244. package/src/Logger.ts +68 -25
  245. package/src/Match.ts +78 -50
  246. package/src/Order.ts +1 -1
  247. package/src/Schema.ts +79 -296
  248. package/src/SchemaAST.ts +0 -1
  249. package/src/ScopedCache.ts +6 -4
  250. package/src/Stream.ts +167 -33
  251. package/src/String.ts +1 -1
  252. package/src/Tracer.ts +10 -0
  253. package/src/ai/McpServer.ts +161 -4
  254. package/src/ai/Prompt.ts +20 -3
  255. package/src/ai/Skill.ts +236 -0
  256. package/src/ai/index.ts +6 -0
  257. package/src/cluster/ClusterWorkflowEngine.ts +172 -96
  258. package/src/cluster/MessageStorage.ts +51 -2
  259. package/src/cluster/SqlMessageStorage.ts +81 -34
  260. package/src/cluster/internal/entityActivation.ts +6 -0
  261. package/src/cluster/internal/entityManager.ts +8 -4
  262. package/src/encoding/Base64.ts +5 -1
  263. package/src/encoding/Base64Url.ts +6 -1
  264. package/src/encoding/Xml.ts +96 -26
  265. package/src/http/FetchHttpClient.ts +8 -5
  266. package/src/http/Headers.ts +309 -3
  267. package/src/http/HttpClient.ts +19 -7
  268. package/src/http/HttpClientError.ts +42 -9
  269. package/src/http/HttpClientRequest.ts +51 -0
  270. package/src/http/HttpClientResponse.ts +156 -0
  271. package/src/http/HttpMiddleware.ts +1 -1
  272. package/src/http/HttpServerResponse.ts +126 -0
  273. package/src/http/Multipart.ts +0 -5
  274. package/src/http/MultipartParser/internal/contentType.ts +1 -1
  275. package/src/http/internal/clientPath.ts +39 -0
  276. package/src/http/internal/redactedPath.ts +4 -0
  277. package/src/http/internal/tracing.ts +6 -3
  278. package/src/http-api/HttpApi.ts +29 -8
  279. package/src/http-api/HttpApiBuilder.ts +7 -2
  280. package/src/http-api/HttpApiClient.ts +30 -7
  281. package/src/http-api/internal/redactedKeys.ts +40 -0
  282. package/src/internal/base64.ts +57 -2
  283. package/src/internal/dateTime.ts +43 -24
  284. package/src/internal/effect.ts +31 -102
  285. package/src/internal/equal.ts +37 -17
  286. package/src/internal/hash.ts +5 -1
  287. package/src/internal/matcher.ts +34 -113
  288. package/src/internal/schema/schemaCodegen.ts +5 -4
  289. package/src/internal/schema/schemaCodegenBuiltIns.ts +343 -0
  290. package/src/internal/schema/toEquivalence.ts +3 -5
  291. package/src/internal/version.ts +1 -1
  292. package/src/jose/JoseError.ts +34 -0
  293. package/src/jose/internal/compact.ts +14 -5
  294. package/src/observability/Otlp.ts +29 -0
  295. package/src/observability/OtlpExporter.ts +206 -75
  296. package/src/observability/OtlpLogger.ts +24 -2
  297. package/src/observability/OtlpMetrics.ts +2 -0
  298. package/src/observability/OtlpTracer.ts +24 -3
  299. package/src/persistence/KeyValueStore.ts +17 -14
  300. package/src/reactivity/Atom.ts +12 -18
  301. package/src/rpc/RpcClient.ts +26 -1
  302. package/src/rpc/RpcGroup.ts +4 -1
  303. package/src/sql/Migrator.ts +2 -11
  304. package/src/sql/SqlClient.ts +14 -8
  305. package/src/workflow/Activity.ts +28 -4
  306. package/src/workflow/Workflow.ts +68 -44
  307. package/src/workflow/WorkflowEngine.ts +38 -15
  308. package/src/workflow/internal/retry.ts +12 -0
  309. package/src/workflow/internal/scope.ts +36 -0
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Standalone Agent Skill value and schema for local agents and MCP servers.
3
+ *
4
+ * A `Skill` models an Agent Skill (https://agentskills.io/specification) as
5
+ * plain data — validated YAML `frontmatter`, markdown `instructions`, and
6
+ * supporting `files` — with `SKILL.md` as its serialization format via
7
+ * {@link toFiles} and {@link fromFiles}.
8
+ *
9
+ * @stability unstable
10
+ * @since 4.1.6
11
+ */
12
+ import * as Cause from "../Cause.ts"
13
+ import * as Effect from "../Effect.ts"
14
+ import * as Yaml from "../encoding/Yaml.ts"
15
+ import * as Predicate from "../Predicate.ts"
16
+ import * as Schema from "../Schema.ts"
17
+ import * as SchemaTransformation from "../SchemaTransformation.ts"
18
+
19
+ const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
20
+
21
+ /**
22
+ * Schema for the YAML frontmatter of an Agent Skill's `SKILL.md`, as the
23
+ * Agent Skills specification defines it (https://agentskills.io/specification).
24
+ *
25
+ * **Details**
26
+ *
27
+ * Fields the specification does not define are kept unchanged.
28
+ *
29
+ * @stability unstable
30
+ * @category schemas
31
+ * @since 4.1.6
32
+ */
33
+ export const Frontmatter = Schema.StructWithRest(
34
+ Schema.Struct({
35
+ /**
36
+ * 1 to 64 lowercase letters, digits and hyphens, with no leading, trailing
37
+ * or consecutive hyphen. It names the directory holding `SKILL.md`.
38
+ */
39
+ name: Schema.String.check(Schema.isMaxLength(64), Schema.isPattern(SKILL_NAME)),
40
+ /**
41
+ * What the skill does and when to use it, in 1 to 1024 characters.
42
+ */
43
+ description: Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(1024)),
44
+ /**
45
+ * The skill's license, or the name of a bundled license file.
46
+ */
47
+ license: Schema.optionalKey(Schema.String),
48
+ /**
49
+ * Environment requirements, in 1 to 500 characters.
50
+ */
51
+ compatibility: Schema.optionalKey(Schema.String.check(Schema.isNonEmpty(), Schema.isMaxLength(500))),
52
+ /**
53
+ * Additional properties not defined by the specification.
54
+ */
55
+ metadata: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
56
+ /**
57
+ * Space-separated tools the skill asks to run without approval. Hosts must
58
+ * ignore it for a skill served over MCP unless the user approved the grant.
59
+ */
60
+ "allowed-tools": Schema.optionalKey(Schema.String)
61
+ }),
62
+ [Schema.JsonObject]
63
+ )
64
+
65
+ /**
66
+ * The YAML frontmatter of an Agent Skill's `SKILL.md`.
67
+ *
68
+ * @stability unstable
69
+ * @category models
70
+ * @since 4.1.6
71
+ */
72
+ export type Frontmatter = typeof Frontmatter.Type
73
+
74
+ const isSafeSkillFilePath = (path: string): boolean =>
75
+ path !== "" &&
76
+ path !== "SKILL.md" &&
77
+ !path.includes("\\") &&
78
+ !/^[A-Za-z]:/.test(path) &&
79
+ path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..")
80
+
81
+ const Bytes = Schema.Uint8Array.annotate({
82
+ toCodecJson: () =>
83
+ Schema.link<Uint8Array<ArrayBufferLike>>()(
84
+ Schema.Struct({ base64: Schema.Uint8ArrayFromBase64 }),
85
+ SchemaTransformation.transform({
86
+ decode: ({ base64 }) => base64,
87
+ encode: (base64) => ({ base64 })
88
+ })
89
+ )
90
+ })
91
+
92
+ const SkillFiles = Schema.Record(Schema.String, Schema.Union([Schema.String, Bytes])).check(
93
+ Schema.makeFilter((files) => {
94
+ const path = Object.keys(files).find((path) => !isSafeSkillFilePath(path))
95
+ return path === undefined || `Invalid skill file path "${path}"`
96
+ })
97
+ )
98
+
99
+ /**
100
+ * Schema and class for an Agent Skill bundle.
101
+ *
102
+ * **Details**
103
+ *
104
+ * Holds validated {@link Frontmatter}, markdown `instructions`, and supporting
105
+ * `files` keyed by safe relative paths (excluding `SKILL.md`). When encoded
106
+ * with `Schema.toCodecJson`, binary `Uint8Array` files are represented as
107
+ * `{ base64: string }` so text and binary files stay distinct.
108
+ *
109
+ * @see {@link make} for constructing a skill
110
+ * @see {@link toFiles} for rendering a skill to a file map including `SKILL.md`
111
+ * @see {@link fromFiles} for parsing a skill from a file map containing `SKILL.md`
112
+ *
113
+ * @stability unstable
114
+ * @category models
115
+ * @since 4.1.6
116
+ */
117
+ export class Skill extends Schema.Class<Skill>("effect/ai/Skill")({
118
+ frontmatter: Frontmatter,
119
+ instructions: Schema.String,
120
+ files: SkillFiles
121
+ }) {}
122
+
123
+ /**
124
+ * Constructs a validated {@link Skill}.
125
+ *
126
+ * **Gotchas**
127
+ *
128
+ * Throws an `Error` (with the validation issue on `cause`) when `frontmatter`
129
+ * fails validation or any key in `files` is `"SKILL.md"` or an unsafe path.
130
+ * Use {@link fromFiles} or `Schema.decodeUnknownEffect(Skill)` for untrusted input.
131
+ *
132
+ * @see {@link fromFiles} for effectful construction from a raw file map
133
+ *
134
+ * @stability unstable
135
+ * @category constructors
136
+ * @since 4.1.6
137
+ */
138
+ export const make = (options: {
139
+ readonly frontmatter: Frontmatter
140
+ readonly instructions: string
141
+ readonly files?: Readonly<Record<string, string | Uint8Array>> | undefined
142
+ }): Skill => new Skill({ ...options, files: options.files ?? {} })
143
+
144
+ /**
145
+ * Renders a {@link Skill} into a file map that includes the generated
146
+ * `SKILL.md` along with all supporting files.
147
+ *
148
+ * **Details**
149
+ *
150
+ * Frontmatter keys and values are JSON-encoded so YAML edge cases round-trip
151
+ * cleanly through {@link fromFiles}.
152
+ *
153
+ * @see {@link fromFiles} for parsing a file map back into a {@link Skill}
154
+ *
155
+ * @stability unstable
156
+ * @category conversions
157
+ * @since 4.1.6
158
+ */
159
+ export const toFiles = (
160
+ self: Skill
161
+ ): { readonly "SKILL.md": string } & Readonly<Record<string, string | Uint8Array>> => {
162
+ const frontmatter = Object.entries(self.frontmatter)
163
+ .map(([key, value]) => `${JSON.stringify(key)}: ${JSON.stringify(value)}`)
164
+ .join("\n")
165
+ return { "SKILL.md": `---\n${frontmatter}\n---\n\n${self.instructions}`, ...self.files }
166
+ }
167
+
168
+ const utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true })
169
+
170
+ const decodeUtf8 = (content: Uint8Array): string | undefined => {
171
+ try {
172
+ return utf8.decode(content)
173
+ } catch {
174
+ return undefined
175
+ }
176
+ }
177
+
178
+ const FRONTMATTER = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/
179
+
180
+ const parseSkillMarkdown = (
181
+ markdown: string
182
+ ): { readonly frontmatter: Record<string, unknown>; readonly instructions: string } | undefined => {
183
+ const match = FRONTMATTER.exec(markdown)
184
+ if (match === null) return undefined
185
+ try {
186
+ const parsed = Yaml.parse(match[1])
187
+ if (!Predicate.isObject(parsed)) return undefined
188
+ // Keep only JSON values so `.inf` and `.nan` normalize to `null`.
189
+ const frontmatter: Record<string, unknown> = JSON.parse(JSON.stringify(parsed))
190
+ const instructions = markdown.slice(match[0].length).replace(/^\r?\n/, "")
191
+ return { frontmatter, instructions }
192
+ } catch {
193
+ return undefined
194
+ }
195
+ }
196
+
197
+ const decodeSkill = Schema.decodeUnknownEffect(Skill)
198
+
199
+ /**
200
+ * Parses a {@link Skill} from a file map containing `SKILL.md` and optional
201
+ * supporting files.
202
+ *
203
+ * **Details**
204
+ *
205
+ * Fails with `Cause.IllegalArgumentError` when `SKILL.md` is missing, not
206
+ * valid UTF-8, lacks a valid YAML frontmatter block, or fails {@link Skill}
207
+ * schema validation.
208
+ *
209
+ * @see {@link toFiles} for the inverse conversion
210
+ * @see {@link make} for constructing a skill from structured fields
211
+ *
212
+ * @stability unstable
213
+ * @category constructors
214
+ * @since 4.1.6
215
+ */
216
+ export const fromFiles = (
217
+ files: Readonly<Record<string, string | Uint8Array>>
218
+ ): Effect.Effect<Skill, Cause.IllegalArgumentError> =>
219
+ Effect.suspend(() => {
220
+ // Rest destructuring defines own properties, so a file named `__proto__` survives.
221
+ const { "SKILL.md": skillMd, ...supportingFiles } = files
222
+ if (skillMd === undefined) {
223
+ return Effect.fail(new Cause.IllegalArgumentError("Skill is missing SKILL.md"))
224
+ }
225
+ const markdown = typeof skillMd === "string" ? skillMd : decodeUtf8(skillMd)
226
+ if (markdown === undefined) {
227
+ return Effect.fail(new Cause.IllegalArgumentError("SKILL.md is not valid UTF-8"))
228
+ }
229
+ const parsed = parseSkillMarkdown(markdown)
230
+ if (parsed === undefined) {
231
+ return Effect.fail(new Cause.IllegalArgumentError("SKILL.md is missing valid YAML frontmatter"))
232
+ }
233
+ return decodeSkill({ ...parsed, files: supportingFiles }).pipe(
234
+ Effect.mapError((error) => new Cause.IllegalArgumentError(error.message))
235
+ )
236
+ })
package/src/ai/index.ts CHANGED
@@ -137,6 +137,12 @@ export * as Response from "./Response.ts"
137
137
  */
138
138
  export * as ResponseIdTracker from "./ResponseIdTracker.ts"
139
139
 
140
+ /**
141
+ * @stability unstable
142
+ * @since 4.1.6
143
+ */
144
+ export * as Skill from "./Skill.ts"
145
+
140
146
  /**
141
147
  * @stability unstable
142
148
  * @since 4.0.0