@loxtep/sdk 0.2.3 → 0.4.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 (239) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +255 -4
  3. package/dist/authoring/agent.d.ts +164 -0
  4. package/dist/authoring/agent.d.ts.map +1 -0
  5. package/dist/authoring/agent.js +376 -0
  6. package/dist/authoring/agent.js.map +1 -0
  7. package/dist/authoring/compiler.d.ts +103 -0
  8. package/dist/authoring/compiler.d.ts.map +1 -0
  9. package/dist/authoring/compiler.js +305 -0
  10. package/dist/authoring/compiler.js.map +1 -0
  11. package/dist/authoring/define-data-workflow.d.ts +24 -0
  12. package/dist/authoring/define-data-workflow.d.ts.map +1 -0
  13. package/dist/authoring/define-data-workflow.js +93 -0
  14. package/dist/authoring/define-data-workflow.js.map +1 -0
  15. package/dist/authoring/index.d.ts +19 -0
  16. package/dist/authoring/index.d.ts.map +1 -0
  17. package/dist/authoring/index.js +15 -0
  18. package/dist/authoring/index.js.map +1 -0
  19. package/dist/authoring/toolbox.d.ts +133 -0
  20. package/dist/authoring/toolbox.d.ts.map +1 -0
  21. package/dist/authoring/toolbox.js +166 -0
  22. package/dist/authoring/toolbox.js.map +1 -0
  23. package/dist/authoring/triggers.d.ts +41 -0
  24. package/dist/authoring/triggers.d.ts.map +1 -0
  25. package/dist/authoring/triggers.js +60 -0
  26. package/dist/authoring/triggers.js.map +1 -0
  27. package/dist/authoring/types.d.ts +111 -0
  28. package/dist/authoring/types.d.ts.map +1 -0
  29. package/dist/authoring/types.js +9 -0
  30. package/dist/authoring/types.js.map +1 -0
  31. package/dist/cli/commands/activity-cmd.d.ts +28 -0
  32. package/dist/cli/commands/activity-cmd.d.ts.map +1 -0
  33. package/dist/cli/commands/activity-cmd.js +78 -0
  34. package/dist/cli/commands/activity-cmd.js.map +1 -0
  35. package/dist/cli/commands/attach-cmd.d.ts +38 -0
  36. package/dist/cli/commands/attach-cmd.d.ts.map +1 -0
  37. package/dist/cli/commands/attach-cmd.js +141 -0
  38. package/dist/cli/commands/attach-cmd.js.map +1 -0
  39. package/dist/cli/commands/data-contracts-cmd.d.ts +8 -0
  40. package/dist/cli/commands/data-contracts-cmd.d.ts.map +1 -1
  41. package/dist/cli/commands/data-contracts-cmd.js +11 -0
  42. package/dist/cli/commands/data-contracts-cmd.js.map +1 -1
  43. package/dist/cli/commands/data-products-cmd.d.ts +2 -0
  44. package/dist/cli/commands/data-products-cmd.d.ts.map +1 -1
  45. package/dist/cli/commands/data-products-cmd.js +35 -0
  46. package/dist/cli/commands/data-products-cmd.js.map +1 -1
  47. package/dist/cli/commands/deploy-cmd.d.ts +101 -0
  48. package/dist/cli/commands/deploy-cmd.d.ts.map +1 -0
  49. package/dist/cli/commands/deploy-cmd.js +461 -0
  50. package/dist/cli/commands/deploy-cmd.js.map +1 -0
  51. package/dist/cli/commands/generate-cmd.d.ts +35 -0
  52. package/dist/cli/commands/generate-cmd.d.ts.map +1 -0
  53. package/dist/cli/commands/generate-cmd.js +134 -0
  54. package/dist/cli/commands/generate-cmd.js.map +1 -0
  55. package/dist/cli/commands/improvements-cmd.d.ts +44 -0
  56. package/dist/cli/commands/improvements-cmd.d.ts.map +1 -0
  57. package/dist/cli/commands/improvements-cmd.js +215 -0
  58. package/dist/cli/commands/improvements-cmd.js.map +1 -0
  59. package/dist/cli/commands/init-cmd.d.ts +78 -0
  60. package/dist/cli/commands/init-cmd.d.ts.map +1 -0
  61. package/dist/cli/commands/init-cmd.js +250 -0
  62. package/dist/cli/commands/init-cmd.js.map +1 -0
  63. package/dist/cli/commands/instances-cmd.d.ts +37 -0
  64. package/dist/cli/commands/instances-cmd.d.ts.map +1 -0
  65. package/dist/cli/commands/instances-cmd.js +150 -0
  66. package/dist/cli/commands/instances-cmd.js.map +1 -0
  67. package/dist/cli/commands/test-cmd.d.ts +89 -0
  68. package/dist/cli/commands/test-cmd.d.ts.map +1 -0
  69. package/dist/cli/commands/test-cmd.js +378 -0
  70. package/dist/cli/commands/test-cmd.js.map +1 -0
  71. package/dist/cli/index.d.ts +5 -2
  72. package/dist/cli/index.d.ts.map +1 -1
  73. package/dist/cli/index.js +240 -8
  74. package/dist/cli/index.js.map +1 -1
  75. package/dist/cli/project-context.d.ts +153 -0
  76. package/dist/cli/project-context.d.ts.map +1 -0
  77. package/dist/cli/project-context.js +190 -0
  78. package/dist/cli/project-context.js.map +1 -0
  79. package/dist/client/activity-types.d.ts +66 -0
  80. package/dist/client/activity-types.d.ts.map +1 -0
  81. package/dist/client/activity-types.js +9 -0
  82. package/dist/client/activity-types.js.map +1 -0
  83. package/dist/client/activity.d.ts +22 -0
  84. package/dist/client/activity.d.ts.map +1 -0
  85. package/dist/client/activity.js +43 -0
  86. package/dist/client/activity.js.map +1 -0
  87. package/dist/client/data-products-types.d.ts +23 -0
  88. package/dist/client/data-products-types.d.ts.map +1 -1
  89. package/dist/client/data-products.d.ts +3 -1
  90. package/dist/client/data-products.d.ts.map +1 -1
  91. package/dist/client/data-products.js +20 -98
  92. package/dist/client/data-products.js.map +1 -1
  93. package/dist/client/{consumptions-types.d.ts → delivery-types.d.ts} +25 -8
  94. package/dist/client/delivery-types.d.ts.map +1 -0
  95. package/dist/client/delivery-types.js +10 -0
  96. package/dist/client/delivery-types.js.map +1 -0
  97. package/dist/client/delivery.d.ts +23 -0
  98. package/dist/client/delivery.d.ts.map +1 -0
  99. package/dist/client/delivery.js +105 -0
  100. package/dist/client/delivery.js.map +1 -0
  101. package/dist/client/flow-types.d.ts +4 -2
  102. package/dist/client/flow-types.d.ts.map +1 -1
  103. package/dist/client/flows.d.ts +1 -1
  104. package/dist/client/flows.d.ts.map +1 -1
  105. package/dist/client/flows.js +49 -124
  106. package/dist/client/flows.js.map +1 -1
  107. package/dist/client/improvements-types.d.ts +55 -0
  108. package/dist/client/improvements-types.d.ts.map +1 -0
  109. package/dist/client/improvements-types.js +9 -0
  110. package/dist/client/improvements-types.js.map +1 -0
  111. package/dist/client/improvements.d.ts +29 -0
  112. package/dist/client/improvements.d.ts.map +1 -0
  113. package/dist/client/improvements.js +50 -0
  114. package/dist/client/improvements.js.map +1 -0
  115. package/dist/client/index.d.ts +8 -3
  116. package/dist/client/index.d.ts.map +1 -1
  117. package/dist/client/index.js.map +1 -1
  118. package/dist/client/instances-types.d.ts +92 -0
  119. package/dist/client/instances-types.d.ts.map +1 -1
  120. package/dist/client/instances.d.ts +26 -4
  121. package/dist/client/instances.d.ts.map +1 -1
  122. package/dist/client/instances.js +94 -3
  123. package/dist/client/instances.js.map +1 -1
  124. package/dist/client/loxtep-client.d.ts +48 -3
  125. package/dist/client/loxtep-client.d.ts.map +1 -1
  126. package/dist/client/loxtep-client.js +73 -5
  127. package/dist/client/loxtep-client.js.map +1 -1
  128. package/dist/client/projects-types.d.ts +25 -0
  129. package/dist/client/projects-types.d.ts.map +1 -1
  130. package/dist/client/projects.d.ts +2 -1
  131. package/dist/client/projects.d.ts.map +1 -1
  132. package/dist/client/projects.js +17 -0
  133. package/dist/client/projects.js.map +1 -1
  134. package/dist/client/promises.d.ts +11 -0
  135. package/dist/client/promises.d.ts.map +1 -1
  136. package/dist/client/promises.js +11 -0
  137. package/dist/client/promises.js.map +1 -1
  138. package/dist/client/queue-types.d.ts +15 -2
  139. package/dist/client/queue-types.d.ts.map +1 -1
  140. package/dist/client/queues.d.ts.map +1 -1
  141. package/dist/client/queues.js +3 -14
  142. package/dist/client/queues.js.map +1 -1
  143. package/dist/client/schemas.d.ts +1 -0
  144. package/dist/client/schemas.d.ts.map +1 -1
  145. package/dist/client/schemas.js +4 -0
  146. package/dist/client/schemas.js.map +1 -1
  147. package/dist/client/thesaurus.d.ts +5 -0
  148. package/dist/client/thesaurus.d.ts.map +1 -1
  149. package/dist/client/thesaurus.js +12 -0
  150. package/dist/client/thesaurus.js.map +1 -1
  151. package/dist/codegen/emit.d.ts +25 -0
  152. package/dist/codegen/emit.d.ts.map +1 -0
  153. package/dist/codegen/emit.js +158 -0
  154. package/dist/codegen/emit.js.map +1 -0
  155. package/dist/codegen/index.d.ts +17 -0
  156. package/dist/codegen/index.d.ts.map +1 -0
  157. package/dist/codegen/index.js +16 -0
  158. package/dist/codegen/index.js.map +1 -0
  159. package/dist/codegen/load-workspace-context.d.ts +30 -0
  160. package/dist/codegen/load-workspace-context.d.ts.map +1 -0
  161. package/dist/codegen/load-workspace-context.js +127 -0
  162. package/dist/codegen/load-workspace-context.js.map +1 -0
  163. package/dist/codegen/normalize.d.ts +35 -0
  164. package/dist/codegen/normalize.d.ts.map +1 -0
  165. package/dist/codegen/normalize.js +77 -0
  166. package/dist/codegen/normalize.js.map +1 -0
  167. package/dist/codegen/types.d.ts +89 -0
  168. package/dist/codegen/types.d.ts.map +1 -0
  169. package/dist/codegen/types.js +9 -0
  170. package/dist/codegen/types.js.map +1 -0
  171. package/dist/codegen/write-artifact.d.ts +40 -0
  172. package/dist/codegen/write-artifact.d.ts.map +1 -0
  173. package/dist/codegen/write-artifact.js +74 -0
  174. package/dist/codegen/write-artifact.js.map +1 -0
  175. package/dist/config/index.d.ts +1 -0
  176. package/dist/config/index.d.ts.map +1 -1
  177. package/dist/config/index.js +1 -0
  178. package/dist/config/index.js.map +1 -1
  179. package/dist/config/workspace-config.d.ts +76 -0
  180. package/dist/config/workspace-config.d.ts.map +1 -0
  181. package/dist/config/workspace-config.js +129 -0
  182. package/dist/config/workspace-config.js.map +1 -0
  183. package/dist/index.d.ts +3 -0
  184. package/dist/index.d.ts.map +1 -1
  185. package/dist/index.js +3 -0
  186. package/dist/index.js.map +1 -1
  187. package/dist/rstreams/event-bridge.d.ts +16 -2
  188. package/dist/rstreams/event-bridge.d.ts.map +1 -1
  189. package/dist/rstreams/event-bridge.js +38 -5
  190. package/dist/rstreams/event-bridge.js.map +1 -1
  191. package/dist/skills/check-scope.d.ts +42 -0
  192. package/dist/skills/check-scope.d.ts.map +1 -0
  193. package/dist/skills/check-scope.js +84 -0
  194. package/dist/skills/check-scope.js.map +1 -0
  195. package/dist/skills/index.d.ts +14 -0
  196. package/dist/skills/index.d.ts.map +1 -0
  197. package/dist/skills/index.js +12 -0
  198. package/dist/skills/index.js.map +1 -0
  199. package/dist/skills/loader.d.ts +79 -0
  200. package/dist/skills/loader.d.ts.map +1 -0
  201. package/dist/skills/loader.js +102 -0
  202. package/dist/skills/loader.js.map +1 -0
  203. package/dist/skills/types.d.ts +55 -0
  204. package/dist/skills/types.d.ts.map +1 -0
  205. package/dist/skills/types.js +9 -0
  206. package/dist/skills/types.js.map +1 -0
  207. package/dist/skills/validate-references.d.ts +54 -0
  208. package/dist/skills/validate-references.d.ts.map +1 -0
  209. package/dist/skills/validate-references.js +80 -0
  210. package/dist/skills/validate-references.js.map +1 -0
  211. package/docs/getting-started.md +7 -0
  212. package/package.json +7 -5
  213. package/dist/cli/commands/data-assets-cmd.d.ts +0 -12
  214. package/dist/cli/commands/data-assets-cmd.d.ts.map +0 -1
  215. package/dist/cli/commands/data-assets-cmd.js +0 -75
  216. package/dist/cli/commands/data-assets-cmd.js.map +0 -1
  217. package/dist/cli/commands/pipelines-cmd.d.ts +0 -17
  218. package/dist/cli/commands/pipelines-cmd.d.ts.map +0 -1
  219. package/dist/cli/commands/pipelines-cmd.js +0 -52
  220. package/dist/cli/commands/pipelines-cmd.js.map +0 -1
  221. package/dist/cli/commands/promises-cmd.d.ts +0 -11
  222. package/dist/cli/commands/promises-cmd.d.ts.map +0 -1
  223. package/dist/cli/commands/promises-cmd.js +0 -53
  224. package/dist/cli/commands/promises-cmd.js.map +0 -1
  225. package/dist/client/consumptions-types.d.ts.map +0 -1
  226. package/dist/client/consumptions-types.js +0 -5
  227. package/dist/client/consumptions-types.js.map +0 -1
  228. package/dist/client/consumptions.d.ts +0 -14
  229. package/dist/client/consumptions.d.ts.map +0 -1
  230. package/dist/client/consumptions.js +0 -47
  231. package/dist/client/consumptions.js.map +0 -1
  232. package/dist/client/data-assets-types.d.ts +0 -150
  233. package/dist/client/data-assets-types.d.ts.map +0 -1
  234. package/dist/client/data-assets-types.js +0 -5
  235. package/dist/client/data-assets-types.js.map +0 -1
  236. package/dist/client/data-assets.d.ts +0 -31
  237. package/dist/client/data-assets.d.ts.map +0 -1
  238. package/dist/client/data-assets.js +0 -182
  239. package/dist/client/data-assets.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Stage 4: Write — atomic file overwrite returning per-type counts.
3
+ *
4
+ * This I/O stage takes the emitted TypeScript source string and writes it
5
+ * atomically to the target path. "Atomic" means: write to a temporary file
6
+ * in the same directory, then rename over the target. If the process crashes
7
+ * or the write fails at any point, the prior artifact remains unchanged (R2.8).
8
+ *
9
+ * The function also computes and returns per-resource-type counts from the
10
+ * provided NormalizedContext so the CLI can print them (R2.7).
11
+ *
12
+ * Requirements: R2.6, R2.7, R2.8
13
+ *
14
+ * @module codegen/write-artifact
15
+ */
16
+ import { writeFile, rename, mkdir, unlink } from 'node:fs/promises';
17
+ import { dirname, join } from 'node:path';
18
+ import { randomBytes } from 'node:crypto';
19
+ /**
20
+ * Computes per-resource-type counts from a NormalizedContext.
21
+ * Returns 0 for each resource type that has no resources (R2.7).
22
+ */
23
+ export function computeCounts(norm) {
24
+ return {
25
+ dataProducts: norm.dataProducts.length,
26
+ connectors: norm.connectors.length,
27
+ domains: norm.domains.length,
28
+ queues: norm.queues.length,
29
+ flows: norm.flows.length,
30
+ workflows: norm.workflows.length,
31
+ };
32
+ }
33
+ /**
34
+ * Writes the generated artifact source to disk atomically and returns per-type counts.
35
+ *
36
+ * Atomicity strategy:
37
+ * 1. Ensure the target directory exists.
38
+ * 2. Write the full source to a temporary file in the same directory (same filesystem).
39
+ * 3. Rename the temporary file over the target path (atomic on POSIX filesystems).
40
+ *
41
+ * If any step fails, the temporary file is cleaned up (best-effort) and the
42
+ * prior artifact at `targetPath` remains unchanged (R2.8). The error is re-thrown
43
+ * so the caller can handle it (e.g. exit non-zero, print the failure reason).
44
+ *
45
+ * @param targetPath - Absolute or relative path to the generated artifact file.
46
+ * @param source - The TypeScript source string produced by `emitArtifact`.
47
+ * @param norm - The NormalizedContext used to compute resource counts.
48
+ * @returns Per-resource-type counts written to the artifact (R2.7).
49
+ */
50
+ export async function writeArtifact(targetPath, source, norm) {
51
+ const dir = dirname(targetPath);
52
+ const tempName = `.loxtep-gen-${randomBytes(8).toString('hex')}.tmp`;
53
+ const tempPath = join(dir, tempName);
54
+ try {
55
+ // Ensure target directory exists
56
+ await mkdir(dir, { recursive: true });
57
+ // Write full content to temp file (same directory → same filesystem for rename)
58
+ await writeFile(tempPath, source, 'utf-8');
59
+ // Atomic rename over the target (R2.8: prior artifact unchanged on failure above)
60
+ await rename(tempPath, targetPath);
61
+ }
62
+ catch (err) {
63
+ // Best-effort cleanup of the temp file
64
+ try {
65
+ await unlink(tempPath);
66
+ }
67
+ catch {
68
+ // Ignore cleanup errors — the temp file may not have been created
69
+ }
70
+ throw err;
71
+ }
72
+ return computeCounts(norm);
73
+ }
74
+ //# sourceMappingURL=write-artifact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-artifact.js","sourceRoot":"","sources":["../../src/codegen/write-artifact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAuB;IACnD,OAAO;QACL,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM;QACtC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;QAClC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;QAC5B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;QAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;QACxB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;KACjC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,UAAkB,EAClB,MAAc,EACd,IAAuB;IAEvB,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,eAAe,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC;IACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAErC,IAAI,CAAC;QACH,iCAAiC;QACjC,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAEtC,gFAAgF;QAChF,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAE3C,kFAAkF;QAClF,MAAM,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,uCAAuC;QACvC,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QAAC,MAAM,CAAC;YACP,kEAAkE;QACpE,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -7,4 +7,5 @@ export { DEFAULT_CONFIG } from './types.js';
7
7
  export { buildAuthServiceUrl, extendClientBaseUrl } from './api-path.js';
8
8
  export { buildPlatformRequestUrl, getGatewayMicroserviceId, SDK_HTTP_PATHS_BY_FEATURE, } from './platform-request-url.js';
9
9
  export { resolveSdkApiPaths, resolveConfigSdkPath, SDK_EXAMPLE_PATHS, type ResolvedSdkApiPaths, } from './resolve-sdk-urls.js';
10
+ export { loadWorkspaceConfig, resolveAutoConfig, type WorkspaceResolvedFields, type WorkspaceConfigResult, type ExplicitConfigFields, type AutoConfigResult, } from './workspace-config.js';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,GACtB,MAAM,uBAAuB,CAAC"}
@@ -6,4 +6,5 @@ export { DEFAULT_CONFIG } from './types.js';
6
6
  export { buildAuthServiceUrl, extendClientBaseUrl } from './api-path.js';
7
7
  export { buildPlatformRequestUrl, getGatewayMicroserviceId, SDK_HTTP_PATHS_BY_FEATURE, } from './platform-request-url.js';
8
8
  export { resolveSdkApiPaths, resolveConfigSdkPath, SDK_EXAMPLE_PATHS, } from './resolve-sdk-urls.js';
9
+ export { loadWorkspaceConfig, resolveAutoConfig, } from './workspace-config.js';
9
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GAElB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GAElB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAKlB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Workspace-aware config resolution for the SDK auto-config feature (R13).
3
+ *
4
+ * Resolution precedence: env vars > explicit config > `.loxtep/project.json` + `~/.loxtep/credentials.json`.
5
+ *
6
+ * This module provides:
7
+ * - {@link loadWorkspaceConfig} — resolves config from workspace files (project.json + credentials.json)
8
+ * - {@link resolveAutoConfig} — merges all layers (env, explicit, workspace) following the precedence
9
+ * - {@link WorkspaceConfigResult} — the resolved config with metadata about which files were used
10
+ */
11
+ /**
12
+ * Fields that auto-config resolves from workspace files.
13
+ */
14
+ export interface WorkspaceResolvedFields {
15
+ api_url?: string;
16
+ project_id?: string;
17
+ instance_id?: string;
18
+ token?: string;
19
+ }
20
+ /**
21
+ * Result of loading workspace config, including which files were found.
22
+ */
23
+ export interface WorkspaceConfigResult {
24
+ /** Resolved fields from workspace files. */
25
+ fields: WorkspaceResolvedFields;
26
+ /** Files that were found and used. */
27
+ resolvedFiles: string[];
28
+ /** Files that were looked for but missing. */
29
+ missingFiles: string[];
30
+ }
31
+ /**
32
+ * Load workspace-resolved configuration from `.loxtep/project.json` (local project)
33
+ * and `~/.loxtep/credentials.json` (user credentials).
34
+ *
35
+ * This does NOT check env vars or explicit config — it only resolves from files.
36
+ * The caller is responsible for merging with the correct precedence.
37
+ *
38
+ * @param cwd - The working directory to search from (defaults to `process.cwd()`).
39
+ * @returns Resolved fields and metadata about which files were used.
40
+ */
41
+ export declare function loadWorkspaceConfig(cwd?: string): WorkspaceConfigResult;
42
+ /**
43
+ * Options that can be explicitly passed to override auto-resolved config.
44
+ */
45
+ export interface ExplicitConfigFields {
46
+ api_url?: string;
47
+ project_id?: string;
48
+ instance_id?: string;
49
+ token?: string;
50
+ }
51
+ /**
52
+ * Resolved auto-config result with full precedence applied.
53
+ */
54
+ export interface AutoConfigResult {
55
+ /** Final resolved api_url. */
56
+ api_url?: string;
57
+ /** Final resolved project_id. */
58
+ project_id?: string;
59
+ /** Final resolved instance_id. */
60
+ instance_id?: string;
61
+ /** Final resolved auth token. */
62
+ token?: string;
63
+ /** Files that were resolved (for debug log). */
64
+ resolvedFiles: string[];
65
+ /** Files that were missing. */
66
+ missingFiles: string[];
67
+ }
68
+ /**
69
+ * Resolve configuration with full precedence: env > explicit > workspace files.
70
+ *
71
+ * @param explicit - Explicitly passed config (overrides workspace but not env).
72
+ * @param cwd - Working directory to search for `.loxtep/project.json`.
73
+ * @returns The merged config with metadata about resolution sources.
74
+ */
75
+ export declare function resolveAutoConfig(explicit?: ExplicitConfigFields, cwd?: string): AutoConfigResult;
76
+ //# sourceMappingURL=workspace-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-config.d.ts","sourceRoot":"","sources":["../../src/config/workspace-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4CAA4C;IAC5C,MAAM,EAAE,uBAAuB,CAAC;IAChC,sCAAsC;IACtC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,8CAA8C;IAC9C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAKD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAkEvE;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAUD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,+BAA+B;IAC/B,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,CAAC,EAAE,oBAAoB,EAC/B,GAAG,CAAC,EAAE,MAAM,GACX,gBAAgB,CA0BlB"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Workspace-aware config resolution for the SDK auto-config feature (R13).
3
+ *
4
+ * Resolution precedence: env vars > explicit config > `.loxtep/project.json` + `~/.loxtep/credentials.json`.
5
+ *
6
+ * This module provides:
7
+ * - {@link loadWorkspaceConfig} — resolves config from workspace files (project.json + credentials.json)
8
+ * - {@link resolveAutoConfig} — merges all layers (env, explicit, workspace) following the precedence
9
+ * - {@link WorkspaceConfigResult} — the resolved config with metadata about which files were used
10
+ */
11
+ import { existsSync, readFileSync } from 'node:fs';
12
+ import { join } from 'node:path';
13
+ import { getConfigDir } from './paths.js';
14
+ import { findProjectDir, getProjectFilePath, PROJECT_DIR_NAME, PROJECT_FILE_NAME } from '../cli/project-context.js';
15
+ /** Credentials file name within `~/.loxtep/`. */
16
+ const CREDENTIALS_FILE_NAME = 'credentials.json';
17
+ /**
18
+ * Load workspace-resolved configuration from `.loxtep/project.json` (local project)
19
+ * and `~/.loxtep/credentials.json` (user credentials).
20
+ *
21
+ * This does NOT check env vars or explicit config — it only resolves from files.
22
+ * The caller is responsible for merging with the correct precedence.
23
+ *
24
+ * @param cwd - The working directory to search from (defaults to `process.cwd()`).
25
+ * @returns Resolved fields and metadata about which files were used.
26
+ */
27
+ export function loadWorkspaceConfig(cwd) {
28
+ const workDir = cwd ?? process.cwd();
29
+ const resolvedFiles = [];
30
+ const missingFiles = [];
31
+ const fields = {};
32
+ // 1. Resolve .loxtep/project.json (search upward from cwd)
33
+ const projectDir = findProjectDir(workDir);
34
+ const projectFilePath = projectDir ? getProjectFilePath(projectDir) : null;
35
+ if (projectFilePath && existsSync(projectFilePath)) {
36
+ try {
37
+ const raw = readFileSync(projectFilePath, 'utf-8');
38
+ const parsed = JSON.parse(raw);
39
+ if (typeof parsed === 'object' && parsed !== null) {
40
+ if (typeof parsed.api_url === 'string' && parsed.api_url.trim()) {
41
+ fields.api_url = parsed.api_url.trim();
42
+ }
43
+ if (typeof parsed.project_id === 'string' && parsed.project_id.trim()) {
44
+ fields.project_id = parsed.project_id.trim();
45
+ }
46
+ if (typeof parsed.instance_id === 'string' && parsed.instance_id.trim()) {
47
+ fields.instance_id = parsed.instance_id.trim();
48
+ }
49
+ }
50
+ resolvedFiles.push(projectFilePath);
51
+ }
52
+ catch {
53
+ // File exists but can't be read/parsed — treat as missing
54
+ missingFiles.push(projectFilePath);
55
+ }
56
+ }
57
+ else {
58
+ // Project file not found in any parent directory
59
+ const searchedPath = join(workDir, PROJECT_DIR_NAME, PROJECT_FILE_NAME);
60
+ missingFiles.push(searchedPath);
61
+ }
62
+ // 2. Resolve ~/.loxtep/credentials.json (user-level credentials)
63
+ const credentialsPath = join(getConfigDir(), CREDENTIALS_FILE_NAME);
64
+ if (existsSync(credentialsPath)) {
65
+ try {
66
+ const raw = readFileSync(credentialsPath, 'utf-8');
67
+ const parsed = JSON.parse(raw);
68
+ if (typeof parsed === 'object' && parsed !== null) {
69
+ if (typeof parsed.access_token === 'string' && parsed.access_token.trim()) {
70
+ fields.token = parsed.access_token.trim();
71
+ }
72
+ // credentials.json can also carry api_base_url (from login)
73
+ if (!fields.api_url &&
74
+ typeof parsed.api_base_url === 'string' &&
75
+ parsed.api_base_url.trim()) {
76
+ fields.api_url = parsed.api_base_url.trim();
77
+ }
78
+ }
79
+ resolvedFiles.push(credentialsPath);
80
+ }
81
+ catch {
82
+ // File exists but can't be read/parsed — treat as missing
83
+ missingFiles.push(credentialsPath);
84
+ }
85
+ }
86
+ else {
87
+ missingFiles.push(credentialsPath);
88
+ }
89
+ return { fields, resolvedFiles, missingFiles };
90
+ }
91
+ /**
92
+ * Env var names that take precedence over everything.
93
+ */
94
+ const ENV_API_URL = 'LOXTEP_API_URL';
95
+ const ENV_PROJECT_ID = 'LOXTEP_PROJECT_ID';
96
+ const ENV_INSTANCE_ID = 'LOXTEP_INSTANCE_ID';
97
+ const ENV_TOKEN = 'LOXTEP_TOKEN';
98
+ /**
99
+ * Resolve configuration with full precedence: env > explicit > workspace files.
100
+ *
101
+ * @param explicit - Explicitly passed config (overrides workspace but not env).
102
+ * @param cwd - Working directory to search for `.loxtep/project.json`.
103
+ * @returns The merged config with metadata about resolution sources.
104
+ */
105
+ export function resolveAutoConfig(explicit, cwd) {
106
+ // Layer 1: workspace files (lowest precedence)
107
+ const workspace = loadWorkspaceConfig(cwd);
108
+ // Layer 2: explicit config (overrides workspace)
109
+ const afterExplicit = {
110
+ api_url: explicit?.api_url || workspace.fields.api_url,
111
+ project_id: explicit?.project_id || workspace.fields.project_id,
112
+ instance_id: explicit?.instance_id || workspace.fields.instance_id,
113
+ token: explicit?.token || workspace.fields.token,
114
+ };
115
+ // Layer 3: env vars (highest precedence)
116
+ const envApiUrl = process.env[ENV_API_URL]?.trim() || undefined;
117
+ const envProjectId = process.env[ENV_PROJECT_ID]?.trim() || undefined;
118
+ const envInstanceId = process.env[ENV_INSTANCE_ID]?.trim() || undefined;
119
+ const envToken = process.env[ENV_TOKEN]?.trim() || undefined;
120
+ return {
121
+ api_url: envApiUrl || afterExplicit.api_url,
122
+ project_id: envProjectId || afterExplicit.project_id,
123
+ instance_id: envInstanceId || afterExplicit.instance_id,
124
+ token: envToken || afterExplicit.token,
125
+ resolvedFiles: workspace.resolvedFiles,
126
+ missingFiles: workspace.missingFiles,
127
+ };
128
+ }
129
+ //# sourceMappingURL=workspace-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-config.js","sourceRoot":"","sources":["../../src/config/workspace-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAwBpH,iDAAiD;AACjD,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAEjD;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAY;IAC9C,MAAM,OAAO,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IACrC,MAAM,aAAa,GAAa,EAAE,CAAC;I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AAE,YAAY,IAAI,aAAa,CAAC,UAAU;QACpD,WAAW,EAAE,aAAa,IAAI,aAAa,CAAC,WAAW;QACvD,KAAK,EAAE,QAAQ,IAAI,aAAa,CAAC,KAAK;QACtC,aAAa,EAAE,SAAS,CAAC,aAAa;QACtC,YAAY,EAAE,SAAS,CAAC,YAAY;KACrC,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -10,4 +10,7 @@ export * from './http/index.js';
10
10
  export * from './checkpoint/index.js';
11
11
  export * from './streaming/index.js';
12
12
  export * from './types/index.js';
13
+ export * from './codegen/index.js';
14
+ export * from './skills/index.js';
15
+ export * from './authoring/index.js';
13
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -10,4 +10,7 @@ export * from './http/index.js';
10
10
  export * from './checkpoint/index.js';
11
11
  export * from './streaming/index.js';
12
12
  export * from './types/index.js';
13
+ export * from './codegen/index.js';
14
+ export * from './skills/index.js';
15
+ export * from './authoring/index.js';
13
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
@@ -2,8 +2,22 @@
2
2
  * Map stream read wrappers to the SDK queue event shape; write payloads via putEvent / putEvents.
3
3
  */
4
4
  import type { RStreamsSdk } from 'leo-sdk';
5
- import type { QueueEvent } from '../client/queue-types.js';
6
- export declare function putPayloadsToQueue(rsdk: RStreamsSdk, botId: string, queueName: string, payloads: unknown[]): Promise<void>;
5
+ import type { QueueEvent, WriteOptions } from '../client/queue-types.js';
6
+ import type { FlowWriter } from '../client/flow-types.js';
7
+ /**
8
+ * Build the rstreams envelope for a business object. The source bot is set by the writer
9
+ * (`rsdk.load(botId, …)`), so we deliberately emit NO top-level `id` — in rstreams that is the
10
+ * SOURCE-BOT identity, and letting a caller's record id land there registers a bogus bot per record
11
+ * in LeoCron. The business object is always the `payload`.
12
+ */
13
+ export declare function toLeoEnvelope(businessObject: unknown, options?: WriteOptions): Record<string, unknown>;
14
+ /**
15
+ * Thin queue writer over the rstreams `load` stream. The rstreams SDK owns buffering, batching,
16
+ * backoff, and checkpointing — this wrapper does NOT buffer or retry; it only wraps each business
17
+ * object into a leo envelope (source = `botId`) and forwards it to `rsdk.load(botId, queueName)`,
18
+ * then flushes on `close()`. Callers pass the business object to `write()`.
19
+ */
20
+ export declare function createQueueWriter(rsdk: RStreamsSdk, botId: string, queueName: string, closedError: () => Error): FlowWriter;
7
21
  /**
8
22
  * Read up to `limit` events from `inQueue` acting as bot `id`, then return (mapped events, last start for next page).
9
23
  * Uses one offloadEvents invocation per batch (stream checkpoints advance between calls).
@@ -1 +1 @@
1
- {"version":3,"file":"event-bridge.d.ts","sourceRoot":"","sources":["../../src/rstreams/event-bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,SAAS,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAwB3D,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,EAAE,GAClB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAE5F,wBAAsB,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9C,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAqB/B"}
1
+ {"version":3,"file":"event-bridge.d.ts","sourceRoot":"","sources":["../../src/rstreams/event-bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,SAAS,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAwB1D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQtG;AAQD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,KAAK,GACvB,UAAU,CAmBZ;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAE5F,wBAAsB,cAAc,CAAC,CAAC,GAAG,OAAO,EAC9C,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,OAAO,CAAC,oBAAoB,CAAC,CAqB/B"}
@@ -15,11 +15,44 @@ function readEventToQueueEvent(wrapper) {
15
15
  correlation_id: w.correlation_id,
16
16
  };
17
17
  }
18
- export async function putPayloadsToQueue(rsdk, botId, queueName, payloads) {
19
- if (payloads.length === 0)
20
- return;
21
- const events = payloads.map(p => p !== null && typeof p === 'object' && 'payload' in p ? p : p);
22
- await rsdk.putEvents(events, { botId, queue: queueName });
18
+ /**
19
+ * Build the rstreams envelope for a business object. The source bot is set by the writer
20
+ * (`rsdk.load(botId, …)`), so we deliberately emit NO top-level `id` — in rstreams that is the
21
+ * SOURCE-BOT identity, and letting a caller's record id land there registers a bogus bot per record
22
+ * in LeoCron. The business object is always the `payload`.
23
+ */
24
+ export function toLeoEnvelope(businessObject, options) {
25
+ const env = { payload: businessObject };
26
+ const ts = options?.event_source_timestamp;
27
+ if (ts != null) {
28
+ const ms = typeof ts === 'number' ? ts : Date.parse(String(ts));
29
+ if (!Number.isNaN(ms))
30
+ env.event_source_timestamp = ms;
31
+ }
32
+ return env;
33
+ }
34
+ /**
35
+ * Thin queue writer over the rstreams `load` stream. The rstreams SDK owns buffering, batching,
36
+ * backoff, and checkpointing — this wrapper does NOT buffer or retry; it only wraps each business
37
+ * object into a leo envelope (source = `botId`) and forwards it to `rsdk.load(botId, queueName)`,
38
+ * then flushes on `close()`. Callers pass the business object to `write()`.
39
+ */
40
+ export function createQueueWriter(rsdk, botId, queueName, closedError) {
41
+ const stream = rsdk.load(botId, queueName);
42
+ let closed = false;
43
+ return {
44
+ write(event, options) {
45
+ if (closed)
46
+ throw closedError();
47
+ stream.write(toLeoEnvelope(event, options));
48
+ },
49
+ async close() {
50
+ if (closed)
51
+ return;
52
+ closed = true;
53
+ await new Promise((resolve, reject) => stream.end(err => (err ? reject(err) : resolve())));
54
+ },
55
+ };
23
56
  }
24
57
  export async function readQueueBatch(rsdk, id, inQueue, limit, start) {
25
58
  const collected = [];
@@ -1 +1 @@
1
- {"version":3,"file":"event-bridge.js","sourceRoot":"","sources":["../../src/rstreams/event-bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,SAAS,qBAAqB,CAAI,OAAqB;IACrD,MAAM,CAAC,GAAG,OAMT,CAAC;IACF,MAAM,QAAQ,GACZ,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,EAAE,CAAC;QAClC,CAAC,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC;QACpC,CAAC,OAAQ,CAA2B,CAAC,QAA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,SAAS;QACzB,SAAS,CAAC,QAAW,EAAE,OAAqB,EAAE,QAAkC;YAC9E,SAAS,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;YAC/C,IAAI,OAAO,QAAQ,KAAK,UAAU;gBAAE,QAAQ,EAAE,CAAC;QACjD,CAAC;KACF,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,OAAO;QACL,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE,IAAI,EAAE,QAAQ,IAAI,SAAS;KACxC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Pure fail-closed scope decision function.
3
+ *
4
+ * `checkScope` determines whether a given operation on a resource is permitted
5
+ * by a skill definition. The function is deny-by-default: if any check fails
6
+ * or cannot complete, the operation is blocked.
7
+ *
8
+ * Decision logic (in order):
9
+ * 1. If the skill definition is undefined → UNKNOWN_SKILL
10
+ * 2. If the resource type has no scope entries, or the resource id is not
11
+ * in the scope list → SCOPE_VIOLATION
12
+ * 3. If the resource type has no permissions, or the operation is not in
13
+ * the permissions list → OPERATION_DENIED
14
+ * 4. Otherwise → allowed
15
+ *
16
+ * Any unexpected error during validation → SCOPE_VALIDATION_FAILED (fail-closed)
17
+ */
18
+ import type { SkillDefinition, SkillScope, Operation, ScopeDecision } from './types.js';
19
+ /**
20
+ * Check whether a specific operation on a resource is permitted by a skill.
21
+ *
22
+ * @param skill - The skill definition to check against, or undefined if not found
23
+ * @param resourceType - The type of resource being accessed (e.g. 'data_products')
24
+ * @param resourceId - The specific resource identifier being accessed
25
+ * @param operation - The operation being attempted (read, write, create, delete)
26
+ * @returns A ScopeDecision indicating whether the operation is allowed or denied
27
+ */
28
+ export declare function checkScope(skill: SkillDefinition | undefined, resourceType: keyof SkillScope, resourceId: string, operation: Operation): ScopeDecision;
29
+ /**
30
+ * Resolve a skill by name from a map and check scope in one step.
31
+ * Convenience wrapper used by both the SDK client-side enforcement and
32
+ * the MCP server-side checker.
33
+ *
34
+ * @param skills - Map of skill name → SkillDefinition
35
+ * @param skillName - The name of the skill to look up
36
+ * @param resourceType - The type of resource being accessed
37
+ * @param resourceId - The specific resource identifier
38
+ * @param operation - The operation being attempted
39
+ * @returns A ScopeDecision
40
+ */
41
+ export declare function checkScopeByName(skills: Map<string, SkillDefinition>, skillName: string, resourceType: keyof SkillScope, resourceId: string, operation: Operation): ScopeDecision;
42
+ //# sourceMappingURL=check-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-scope.d.ts","sourceRoot":"","sources":["../../src/skills/check-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExF;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,eAAe,GAAG,SAAS,EAClC,YAAY,EAAE,MAAM,UAAU,EAC9B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,GACnB,aAAa,CAkCf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,UAAU,EAC9B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,GACnB,aAAa,CAUf"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Pure fail-closed scope decision function.
3
+ *
4
+ * `checkScope` determines whether a given operation on a resource is permitted
5
+ * by a skill definition. The function is deny-by-default: if any check fails
6
+ * or cannot complete, the operation is blocked.
7
+ *
8
+ * Decision logic (in order):
9
+ * 1. If the skill definition is undefined → UNKNOWN_SKILL
10
+ * 2. If the resource type has no scope entries, or the resource id is not
11
+ * in the scope list → SCOPE_VIOLATION
12
+ * 3. If the resource type has no permissions, or the operation is not in
13
+ * the permissions list → OPERATION_DENIED
14
+ * 4. Otherwise → allowed
15
+ *
16
+ * Any unexpected error during validation → SCOPE_VALIDATION_FAILED (fail-closed)
17
+ */
18
+ /**
19
+ * Check whether a specific operation on a resource is permitted by a skill.
20
+ *
21
+ * @param skill - The skill definition to check against, or undefined if not found
22
+ * @param resourceType - The type of resource being accessed (e.g. 'data_products')
23
+ * @param resourceId - The specific resource identifier being accessed
24
+ * @param operation - The operation being attempted (read, write, create, delete)
25
+ * @returns A ScopeDecision indicating whether the operation is allowed or denied
26
+ */
27
+ export function checkScope(skill, resourceType, resourceId, operation) {
28
+ try {
29
+ // 1. Unknown skill — no definition provided
30
+ if (skill === undefined) {
31
+ return { allowed: false, code: 'UNKNOWN_SKILL', skillName: '' };
32
+ }
33
+ // 2. Scope check — is the resource within the skill's declared scope?
34
+ const scopeList = skill.scope[resourceType];
35
+ if (!scopeList || !scopeList.includes(resourceId)) {
36
+ return {
37
+ allowed: false,
38
+ code: 'SCOPE_VIOLATION',
39
+ deniedResource: `${resourceType}/${resourceId}`,
40
+ };
41
+ }
42
+ // 3. Permission check — is the operation allowed for this resource type?
43
+ const permittedOps = skill.permissions[resourceType];
44
+ if (!permittedOps || !permittedOps.includes(operation)) {
45
+ return {
46
+ allowed: false,
47
+ code: 'OPERATION_DENIED',
48
+ deniedOperation: operation,
49
+ resource: `${resourceType}/${resourceId}`,
50
+ };
51
+ }
52
+ // 4. All checks pass
53
+ return { allowed: true };
54
+ }
55
+ catch {
56
+ // Fail-closed: any unexpected error blocks the operation
57
+ return { allowed: false, code: 'SCOPE_VALIDATION_FAILED' };
58
+ }
59
+ }
60
+ /**
61
+ * Resolve a skill by name from a map and check scope in one step.
62
+ * Convenience wrapper used by both the SDK client-side enforcement and
63
+ * the MCP server-side checker.
64
+ *
65
+ * @param skills - Map of skill name → SkillDefinition
66
+ * @param skillName - The name of the skill to look up
67
+ * @param resourceType - The type of resource being accessed
68
+ * @param resourceId - The specific resource identifier
69
+ * @param operation - The operation being attempted
70
+ * @returns A ScopeDecision
71
+ */
72
+ export function checkScopeByName(skills, skillName, resourceType, resourceId, operation) {
73
+ try {
74
+ const skill = skills.get(skillName);
75
+ if (!skill) {
76
+ return { allowed: false, code: 'UNKNOWN_SKILL', skillName };
77
+ }
78
+ return checkScope(skill, resourceType, resourceId, operation);
79
+ }
80
+ catch {
81
+ return { allowed: false, code: 'SCOPE_VALIDATION_FAILED' };
82
+ }
83
+ }
84
+ //# sourceMappingURL=check-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-scope.js","sourceRoot":"","sources":["../../src/skills/check-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,KAAkC,EAClC,YAA8B,EAC9B,UAAkB,EAClB,SAAoB;IAEpB,IAAI,CAAC;QACH,4CAA4C;QAC5C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QAClE,CAAC;QAED,sEAAsE;QACtE,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAClD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,iBAAiB;gBACvB,cAAc,EAAE,GAAG,YAAY,IAAI,UAAU,EAAE;aAChD,CAAC;QACJ,CAAC;QAED,yEAAyE;QACzE,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACrD,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACvD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE,kBAAkB;gBACxB,eAAe,EAAE,SAAS;gBAC1B,QAAQ,EAAE,GAAG,YAAY,IAAI,UAAU,EAAE;aAC1C,CAAC;QACJ,CAAC;QAED,qBAAqB;QACrB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,yDAAyD;QACzD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAC;IAC7D,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAoC,EACpC,SAAiB,EACjB,YAA8B,EAC9B,UAAkB,EAClB,SAAoB;IAEpB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;QAC9D,CAAC;QACD,OAAO,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAC;IAC7D,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Skill scoping model — YAML loader and fail-closed scope decision.
3
+ *
4
+ * A skill is a scoped integration bundle declaring which platform resources
5
+ * and operations an AI agent may reach. The platform enforces scope fail-closed:
6
+ * out-of-scope → SCOPE_VIOLATION, disallowed op → OPERATION_DENIED, unknown
7
+ * skill → rejected, check failure → blocks the operation.
8
+ */
9
+ export type { SkillScope, Operation, SkillDefinition, ScopeDecision, } from './types.js';
10
+ export { checkScope, checkScopeByName } from './check-scope.js';
11
+ export { parseSkillYaml, loadSkillFromFile, loadSkillsFromDirectory, SkillDefinitionSchema, } from './loader.js';
12
+ export type { SkillReferenceError, SkillValidationResult } from './validate-references.js';
13
+ export { validateSkillReferences, formatSkillValidationErrors, } from './validate-references.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/skills/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EACV,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EACL,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Skill scoping model — YAML loader and fail-closed scope decision.
3
+ *
4
+ * A skill is a scoped integration bundle declaring which platform resources
5
+ * and operations an AI agent may reach. The platform enforces scope fail-closed:
6
+ * out-of-scope → SCOPE_VIOLATION, disallowed op → OPERATION_DENIED, unknown
7
+ * skill → rejected, check failure → blocks the operation.
8
+ */
9
+ export { checkScope, checkScopeByName } from './check-scope.js';
10
+ export { parseSkillYaml, loadSkillFromFile, loadSkillsFromDirectory, SkillDefinitionSchema, } from './loader.js';
11
+ export { validateSkillReferences, formatSkillValidationErrors, } from './validate-references.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/skills/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC"}