@stigmer/server 3.22.1-dev.20260922095755 → 3.22.1

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 (268) hide show
  1. package/dist/authorization/authorizer.d.ts +8 -4
  2. package/dist/authorization/authorizer.d.ts.map +1 -1
  3. package/dist/authorization/authorizer.js +9 -5
  4. package/dist/authorization/authorizer.js.map +1 -1
  5. package/dist/authorization/derived-tuples.d.ts.map +1 -1
  6. package/dist/authorization/derived-tuples.js +25 -10
  7. package/dist/authorization/derived-tuples.js.map +1 -1
  8. package/dist/authorization/evaluator.d.ts +8 -7
  9. package/dist/authorization/evaluator.d.ts.map +1 -1
  10. package/dist/authorization/evaluator.js +20 -4
  11. package/dist/authorization/evaluator.js.map +1 -1
  12. package/dist/authorization/list-read-scope.d.ts.map +1 -1
  13. package/dist/authorization/list-read-scope.js +9 -5
  14. package/dist/authorization/list-read-scope.js.map +1 -1
  15. package/dist/authorization/model/agent.d.ts.map +1 -1
  16. package/dist/authorization/model/agent.js +5 -4
  17. package/dist/authorization/model/agent.js.map +1 -1
  18. package/dist/authorization/model/agent_instance.d.ts.map +1 -1
  19. package/dist/authorization/model/agent_instance.js +2 -2
  20. package/dist/authorization/model/agent_instance.js.map +1 -1
  21. package/dist/authorization/model/mcp_server.d.ts.map +1 -1
  22. package/dist/authorization/model/mcp_server.js +2 -2
  23. package/dist/authorization/model/mcp_server.js.map +1 -1
  24. package/dist/authorization/model/plugin.d.ts.map +1 -1
  25. package/dist/authorization/model/plugin.js +4 -3
  26. package/dist/authorization/model/plugin.js.map +1 -1
  27. package/dist/authorization/model/rewrite.d.ts +10 -8
  28. package/dist/authorization/model/rewrite.d.ts.map +1 -1
  29. package/dist/authorization/model/rewrite.js +3 -0
  30. package/dist/authorization/model/rewrite.js.map +1 -1
  31. package/dist/authorization/model/skill.d.ts.map +1 -1
  32. package/dist/authorization/model/skill.js +2 -2
  33. package/dist/authorization/model/skill.js.map +1 -1
  34. package/dist/authorization/model/workflow.d.ts.map +1 -1
  35. package/dist/authorization/model/workflow.js +2 -2
  36. package/dist/authorization/model/workflow.js.map +1 -1
  37. package/dist/authorization/model/workflow_instance.d.ts.map +1 -1
  38. package/dist/authorization/model/workflow_instance.js +2 -2
  39. package/dist/authorization/model/workflow_instance.js.map +1 -1
  40. package/dist/authorization/organization-directory.d.ts.map +1 -1
  41. package/dist/authorization/organization-directory.js +3 -2
  42. package/dist/authorization/organization-directory.js.map +1 -1
  43. package/dist/authorization/store-test-kit.d.ts +6 -0
  44. package/dist/authorization/store-test-kit.d.ts.map +1 -1
  45. package/dist/authorization/store-test-kit.js +62 -16
  46. package/dist/authorization/store-test-kit.js.map +1 -1
  47. package/dist/authorization/tuples.d.ts +32 -13
  48. package/dist/authorization/tuples.d.ts.map +1 -1
  49. package/dist/authorization/tuples.js +11 -3
  50. package/dist/authorization/tuples.js.map +1 -1
  51. package/dist/domain/agent/controller.d.ts.map +1 -1
  52. package/dist/domain/agent/controller.js +4 -4
  53. package/dist/domain/agent/controller.js.map +1 -1
  54. package/dist/domain/agentchannel/controller.d.ts.map +1 -1
  55. package/dist/domain/agentchannel/controller.js +1 -3
  56. package/dist/domain/agentchannel/controller.js.map +1 -1
  57. package/dist/domain/agentexecution/controller.d.ts.map +1 -1
  58. package/dist/domain/agentexecution/controller.js +1 -3
  59. package/dist/domain/agentexecution/controller.js.map +1 -1
  60. package/dist/domain/agentinstance/controller.d.ts.map +1 -1
  61. package/dist/domain/agentinstance/controller.js +4 -3
  62. package/dist/domain/agentinstance/controller.js.map +1 -1
  63. package/dist/domain/agentshare/constants.d.ts +11 -6
  64. package/dist/domain/agentshare/constants.d.ts.map +1 -1
  65. package/dist/domain/agentshare/constants.js +16 -8
  66. package/dist/domain/agentshare/constants.js.map +1 -1
  67. package/dist/domain/agentshare/controller.d.ts.map +1 -1
  68. package/dist/domain/agentshare/controller.js +1 -3
  69. package/dist/domain/agentshare/controller.js.map +1 -1
  70. package/dist/domain/agentshare/steps.d.ts +25 -18
  71. package/dist/domain/agentshare/steps.d.ts.map +1 -1
  72. package/dist/domain/agentshare/steps.js +142 -41
  73. package/dist/domain/agentshare/steps.js.map +1 -1
  74. package/dist/domain/environment/controller.d.ts.map +1 -1
  75. package/dist/domain/environment/controller.js +3 -2
  76. package/dist/domain/environment/controller.js.map +1 -1
  77. package/dist/domain/executioncontext/controller.d.ts.map +1 -1
  78. package/dist/domain/executioncontext/controller.js +1 -2
  79. package/dist/domain/executioncontext/controller.js.map +1 -1
  80. package/dist/domain/mcpserver/controller.d.ts.map +1 -1
  81. package/dist/domain/mcpserver/controller.js +4 -3
  82. package/dist/domain/mcpserver/controller.js.map +1 -1
  83. package/dist/domain/plugin/controller.d.ts.map +1 -1
  84. package/dist/domain/plugin/controller.js +3 -1
  85. package/dist/domain/plugin/controller.js.map +1 -1
  86. package/dist/domain/plugin/push.d.ts +5 -7
  87. package/dist/domain/plugin/push.d.ts.map +1 -1
  88. package/dist/domain/plugin/push.js +14 -8
  89. package/dist/domain/plugin/push.js.map +1 -1
  90. package/dist/domain/schedule/controller.d.ts.map +1 -1
  91. package/dist/domain/schedule/controller.js +1 -3
  92. package/dist/domain/schedule/controller.js.map +1 -1
  93. package/dist/domain/session/controller.d.ts.map +1 -1
  94. package/dist/domain/session/controller.js +2 -3
  95. package/dist/domain/session/controller.js.map +1 -1
  96. package/dist/domain/skill/controller.d.ts.map +1 -1
  97. package/dist/domain/skill/controller.js +2 -0
  98. package/dist/domain/skill/controller.js.map +1 -1
  99. package/dist/domain/workflow/controller.d.ts.map +1 -1
  100. package/dist/domain/workflow/controller.js +6 -14
  101. package/dist/domain/workflow/controller.js.map +1 -1
  102. package/dist/domain/workflow/registry/data/task-kind-registry.json +1 -1
  103. package/dist/domain/workflow/validation/task-config-constraints.d.ts +1 -10
  104. package/dist/domain/workflow/validation/task-config-constraints.d.ts.map +1 -1
  105. package/dist/domain/workflow/validation/task-config-constraints.js +2 -3
  106. package/dist/domain/workflow/validation/task-config-constraints.js.map +1 -1
  107. package/dist/domain/workflowexecution/controller.d.ts.map +1 -1
  108. package/dist/domain/workflowexecution/controller.js +2 -4
  109. package/dist/domain/workflowexecution/controller.js.map +1 -1
  110. package/dist/domain/workflowinstance/controller.d.ts.map +1 -1
  111. package/dist/domain/workflowinstance/controller.js +4 -3
  112. package/dist/domain/workflowinstance/controller.js.map +1 -1
  113. package/dist/extensions/authorization-queries.d.ts +5 -6
  114. package/dist/extensions/authorization-queries.d.ts.map +1 -1
  115. package/dist/extensions/list-read-scope.d.ts +1 -1
  116. package/dist/extensions/resource-authorization.d.ts +2 -3
  117. package/dist/extensions/resource-authorization.d.ts.map +1 -1
  118. package/dist/index.d.ts +3 -1
  119. package/dist/index.d.ts.map +1 -1
  120. package/dist/index.js +13 -0
  121. package/dist/index.js.map +1 -1
  122. package/dist/pipeline/apiresource-meta.d.ts +3 -12
  123. package/dist/pipeline/apiresource-meta.d.ts.map +1 -1
  124. package/dist/pipeline/apiresource-meta.js +10 -21
  125. package/dist/pipeline/apiresource-meta.js.map +1 -1
  126. package/dist/pipeline/steps/authorization-tuples.d.ts +3 -9
  127. package/dist/pipeline/steps/authorization-tuples.d.ts.map +1 -1
  128. package/dist/pipeline/steps/authorization-tuples.js +11 -9
  129. package/dist/pipeline/steps/authorization-tuples.js.map +1 -1
  130. package/dist/pipeline/steps/references.d.ts +20 -178
  131. package/dist/pipeline/steps/references.d.ts.map +1 -1
  132. package/dist/pipeline/steps/references.js +43 -344
  133. package/dist/pipeline/steps/references.js.map +1 -1
  134. package/dist/pipeline/steps/visibility-gates.d.ts +27 -0
  135. package/dist/pipeline/steps/visibility-gates.d.ts.map +1 -0
  136. package/dist/pipeline/steps/visibility-gates.js +139 -0
  137. package/dist/pipeline/steps/visibility-gates.js.map +1 -0
  138. package/dist/query/search/controller.js +1 -0
  139. package/dist/query/search/controller.js.map +1 -1
  140. package/dist/query/search/criteria.d.ts +5 -1
  141. package/dist/query/search/criteria.d.ts.map +1 -1
  142. package/dist/query/search/criteria.js +13 -3
  143. package/dist/query/search/criteria.js.map +1 -1
  144. package/dist/query/search/handler.d.ts +4 -5
  145. package/dist/query/search/handler.d.ts.map +1 -1
  146. package/dist/query/search/handler.js +6 -7
  147. package/dist/query/search/handler.js.map +1 -1
  148. package/dist/query/search/query-store.d.ts.map +1 -1
  149. package/dist/query/search/query-store.js +2 -0
  150. package/dist/query/search/query-store.js.map +1 -1
  151. package/dist/store/interface.d.ts +6 -3
  152. package/dist/store/interface.d.ts.map +1 -1
  153. package/dist/store/interface.js.map +1 -1
  154. package/dist/store/postgres/migrations.d.ts +1 -3
  155. package/dist/store/postgres/migrations.d.ts.map +1 -1
  156. package/dist/store/postgres/migrations.js +1 -35
  157. package/dist/store/postgres/migrations.js.map +1 -1
  158. package/dist/store/postgres/store.d.ts.map +1 -1
  159. package/dist/store/postgres/store.js +9 -4
  160. package/dist/store/postgres/store.js.map +1 -1
  161. package/dist/store/sqlite/migrations.d.ts +1 -3
  162. package/dist/store/sqlite/migrations.d.ts.map +1 -1
  163. package/dist/store/sqlite/migrations.js +1 -36
  164. package/dist/store/sqlite/migrations.js.map +1 -1
  165. package/dist/store/sqlite/store.d.ts.map +1 -1
  166. package/dist/store/sqlite/store.js +8 -4
  167. package/dist/store/sqlite/store.js.map +1 -1
  168. package/package.json +6 -6
  169. package/src/authorization/README.md +26 -24
  170. package/src/authorization/__tests__/authorizer.test.ts +9 -10
  171. package/src/authorization/__tests__/derived-tuples.test.ts +11 -4
  172. package/src/authorization/__tests__/evaluator.test.ts +73 -14
  173. package/src/authorization/__tests__/facts.test.ts +2 -2
  174. package/src/authorization/__tests__/fixtures/fga/agent-instance-creation.fga.yaml +185 -0
  175. package/src/authorization/__tests__/fixtures/fga/blueprint-private-visibility.fga.yaml +98 -6
  176. package/src/authorization/__tests__/fixtures/fga/cross-org-share-creation.fga.yaml +98 -0
  177. package/src/authorization/__tests__/fixtures/fga/default-instance-inheritance.fga.yaml +61 -4
  178. package/src/authorization/__tests__/fixtures/fga/mcp-server-authoring.fga.yaml +143 -0
  179. package/src/authorization/__tests__/fixtures/fga/org-admin-owner-inheritance.fga.yaml +21 -1
  180. package/src/authorization/__tests__/fixtures/fga/platform-visibility.fga.yaml +25 -1
  181. package/src/authorization/__tests__/fixtures/fga/public-visibility-setter.fga.yaml +52 -0
  182. package/src/authorization/__tests__/fixtures/fga/workflow-execution-sharing.fga.yaml +3 -1
  183. package/src/authorization/__tests__/list-read-scope.test.ts +17 -18
  184. package/src/authorization/__tests__/store-tests.test.ts +8 -1
  185. package/src/authorization/__tests__/tuples.test.ts +11 -12
  186. package/src/authorization/authorizer.ts +9 -4
  187. package/src/authorization/derived-tuples.ts +31 -14
  188. package/src/authorization/evaluator.ts +44 -8
  189. package/src/authorization/list-read-scope.ts +11 -5
  190. package/src/authorization/model/agent.ts +5 -2
  191. package/src/authorization/model/agent_instance.ts +2 -0
  192. package/src/authorization/model/mcp_server.ts +2 -0
  193. package/src/authorization/model/plugin.ts +4 -1
  194. package/src/authorization/model/rewrite.ts +13 -8
  195. package/src/authorization/model/skill.ts +2 -0
  196. package/src/authorization/model/workflow.ts +2 -0
  197. package/src/authorization/model/workflow_instance.ts +2 -0
  198. package/src/authorization/organization-directory.ts +3 -1
  199. package/src/authorization/store-test-kit.ts +75 -16
  200. package/src/authorization/tuples.ts +39 -16
  201. package/src/domain/agent/__tests__/agent.test.ts +4 -11
  202. package/src/domain/agent/controller.ts +7 -7
  203. package/src/domain/agentchannel/__tests__/agentchannel.test.ts +48 -223
  204. package/src/domain/agentchannel/controller.ts +1 -6
  205. package/src/domain/agentexecution/controller.ts +1 -6
  206. package/src/domain/agentinstance/controller.ts +12 -6
  207. package/src/domain/agentshare/__tests__/agentshare.test.ts +172 -196
  208. package/src/domain/agentshare/__tests__/create-authorization.test.ts +31 -16
  209. package/src/domain/agentshare/constants.ts +26 -14
  210. package/src/domain/agentshare/controller.ts +1 -6
  211. package/src/domain/agentshare/steps.ts +194 -41
  212. package/src/domain/environment/controller.ts +8 -5
  213. package/src/domain/executioncontext/controller.ts +1 -5
  214. package/src/domain/mcpserver/__tests__/mcpserver.test.ts +28 -115
  215. package/src/domain/mcpserver/__tests__/oauth-handshake.test.ts +18 -53
  216. package/src/domain/mcpserver/controller.ts +12 -6
  217. package/src/domain/plugin/controller.ts +8 -1
  218. package/src/domain/plugin/push.ts +16 -8
  219. package/src/domain/schedule/controller.ts +1 -6
  220. package/src/domain/session/controller.ts +4 -12
  221. package/src/domain/skill/controller.ts +7 -0
  222. package/src/domain/workflow/controller.ts +10 -28
  223. package/src/domain/workflow/registry/data/task-kind-registry.json +1 -1
  224. package/src/domain/workflow/validation/task-config-constraints.ts +3 -7
  225. package/src/domain/workflowexecution/controller.ts +2 -7
  226. package/src/domain/workflowinstance/controller.ts +12 -6
  227. package/src/extensions/__tests__/built-in-authorization-composed.test.ts +19 -32
  228. package/src/extensions/__tests__/extension-composition.test.ts +4 -4
  229. package/src/extensions/__tests__/list-read-scope-composed.test.ts +6 -9
  230. package/src/extensions/authorization-queries.ts +5 -6
  231. package/src/extensions/list-read-scope.ts +1 -1
  232. package/src/extensions/resource-authorization.ts +5 -3
  233. package/src/index.ts +14 -0
  234. package/src/pipeline/apiresource-meta.ts +10 -21
  235. package/src/pipeline/steps/__tests__/authorization-tuples.test.ts +31 -18
  236. package/src/pipeline/steps/__tests__/visibility-gates.test.ts +187 -0
  237. package/src/pipeline/steps/authorization-tuples.ts +11 -9
  238. package/src/pipeline/steps/references.ts +70 -578
  239. package/src/pipeline/steps/visibility-gates.ts +174 -0
  240. package/src/query/search/__tests__/criteria.test.ts +4 -0
  241. package/src/query/search/__tests__/query-store.test.ts +40 -11
  242. package/src/query/search/controller.ts +1 -0
  243. package/src/query/search/criteria.ts +14 -0
  244. package/src/query/search/handler.ts +7 -6
  245. package/src/query/search/query-store.ts +2 -0
  246. package/src/store/__tests__/store-contract.ts +51 -6
  247. package/src/store/interface.ts +6 -3
  248. package/src/store/postgres/__tests__/migrations.test.ts +6 -187
  249. package/src/store/postgres/__tests__/store-contract.test.ts +2 -0
  250. package/src/store/postgres/migrations.ts +1 -48
  251. package/src/store/postgres/store.ts +11 -4
  252. package/src/store/sqlite/__tests__/migrations.test.ts +5 -191
  253. package/src/store/sqlite/migrations.ts +1 -45
  254. package/src/store/sqlite/store.ts +10 -4
  255. package/dist/domain/workflow/agent-call-references.d.ts +0 -54
  256. package/dist/domain/workflow/agent-call-references.d.ts.map +0 -1
  257. package/dist/domain/workflow/agent-call-references.js +0 -97
  258. package/dist/domain/workflow/agent-call-references.js.map +0 -1
  259. package/dist/store/public-visibility-retired.d.ts +0 -67
  260. package/dist/store/public-visibility-retired.d.ts.map +0 -1
  261. package/dist/store/public-visibility-retired.js +0 -55
  262. package/dist/store/public-visibility-retired.js.map +0 -1
  263. package/src/domain/workflow/__tests__/agent-call-references.test.ts +0 -222
  264. package/src/domain/workflow/agent-call-references.ts +0 -157
  265. package/src/pipeline/__tests__/supports-visibility.test.ts +0 -112
  266. package/src/pipeline/steps/__tests__/references.test.ts +0 -703
  267. package/src/store/__tests__/public-visibility-retired.test.ts +0 -127
  268. package/src/store/public-visibility-retired.ts +0 -119
@@ -1,54 +0,0 @@
1
- /**
2
- * ValidateAgentCallReferences — the second collector for the reference rule
3
- * (pipeline/steps/references.ts): a workflow's `agent_call` tasks name their
4
- * agent as a STRING, `"slug"` or `"org/slug"`, inside a `google.protobuf.Struct`
5
- * config the generic spec walker cannot see, so the rule would never meet
6
- * them. This step parses each task's config through the converter's own
7
- * strict decoder (`unmarshalTaskConfig`, the one reader of a task config),
8
- * walks nested control-flow tasks exactly as the constraint validator does,
9
- * turns every `agent` string into a reference with the workflow as parent,
10
- * and asks the rule's one function — same clauses, same copy. It lives in
11
- * the workflow domain and not inside `InProcessValidator` because the
12
- * validator is pure over the spec by design and a rule that reads the
13
- * target's row cannot be.
14
- *
15
- * The parser here is STRICT: exactly `slug` or `org/slug`, both segments
16
- * non-empty, anything else refused at write naming the task. Two lenient
17
- * readers of the same string exist downstream and disagree with each other
18
- * (the runner's `parseAgentReference` in activities/call-agent.ts splits on
19
- * the first `/` and drops a third segment; the CLI's `parseReference` in
20
- * client-apps/cli/src/resources/reference.ts refuses a leading slash);
21
- * refusing every malformed shape here means neither ever meets one. The
22
- * three cannot share code — the packages share only the protos — so the
23
- * execution conformance suite is where their agreement is proven.
24
- *
25
- * Runs after NormalizeReferences and ValidateReferences on the workflow
26
- * create and update chains, so the org the walk sees is the workflow's own
27
- * for a bare slug. Proven by __tests__/agent-call-references.test.ts and
28
- * the workflow conformance suite's reference arm.
29
- */
30
- import type { WorkflowSchema } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/api_pb";
31
- import type { WorkflowSpec } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/spec_pb";
32
- import type { Store } from "../../store/interface.js";
33
- import type { PipelineStep } from "../../pipeline/pipeline.js";
34
- import type { SpecReference } from "../../pipeline/steps/references.js";
35
- /** The one sentence for an `agent` string that is neither `slug` nor `org/slug`. */
36
- export declare function malformedAgentReferenceMessage(taskName: string, agent: string): string;
37
- /**
38
- * `slug` or `org/slug` → the reference, with `org` empty for the bare form
39
- * (the caller fills the parent's). Returns undefined for any other shape.
40
- */
41
- export declare function parseAgentReference(agent: string): {
42
- readonly org: string;
43
- readonly slug: string;
44
- } | undefined;
45
- /**
46
- * Every `agent_call` task's agent as a reference, nested tasks included in
47
- * declaration order, the bare form resolved to `parentOrg`. Throws
48
- * INVALID_ARGUMENT on the first malformed string. A config that does not
49
- * decode is skipped: the spec validation step has already refused the
50
- * workflow for it, and this collector never double-reports.
51
- */
52
- export declare function collectAgentCallReferences(spec: WorkflowSpec | undefined, parentOrg: string): SpecReference[];
53
- export declare function newValidateAgentCallReferencesStep(store: Store): PipelineStep<typeof WorkflowSchema>;
54
- //# sourceMappingURL=agent-call-references.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-call-references.d.ts","sourceRoot":"","sources":["../../../src/domain/workflow/agent-call-references.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uDAAuD,CAAC;AAE5F,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,wDAAwD,CAAC;AAIhE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,KAAK,EAEV,aAAa,EACd,MAAM,oCAAoC,CAAC;AAM5C,oFAAoF;AACpF,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACZ,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,GACZ;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,SAAS,EAAE,MAAM,GAChB,aAAa,EAAE,CAyCjB;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,KAAK,GACX,YAAY,CAAC,OAAO,cAAc,CAAC,CAyBrC"}
@@ -1,97 +0,0 @@
1
- import { WorkflowTaskKind } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/enum_pb";
2
- import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
3
- import { internalError, invalidArgumentError } from "../../pipeline/errors.js";
4
- import { checkReferences } from "../../pipeline/steps/references.js";
5
- import { metadataOf } from "../../pipeline/steps/shapes.js";
6
- import { unmarshalTaskConfig } from "./converter/unmarshal.js";
7
- import { nestedTasks } from "./validation/task-config-constraints.js";
8
- /** The one sentence for an `agent` string that is neither `slug` nor `org/slug`. */
9
- export function malformedAgentReferenceMessage(taskName, agent) {
10
- return `task '${taskName}': agent '${agent}' is not a reference; write 'slug' for an agent of this organization or 'org/slug' for another organization's.`;
11
- }
12
- /**
13
- * `slug` or `org/slug` → the reference, with `org` empty for the bare form
14
- * (the caller fills the parent's). Returns undefined for any other shape.
15
- */
16
- export function parseAgentReference(agent) {
17
- const parts = agent.split("/");
18
- if (parts.length === 1) {
19
- return parts[0] === "" ? undefined : { org: "", slug: parts[0] };
20
- }
21
- if (parts.length === 2 && parts[0] !== "" && parts[1] !== "") {
22
- return { org: parts[0], slug: parts[1] };
23
- }
24
- return undefined;
25
- }
26
- /**
27
- * Every `agent_call` task's agent as a reference, nested tasks included in
28
- * declaration order, the bare form resolved to `parentOrg`. Throws
29
- * INVALID_ARGUMENT on the first malformed string. A config that does not
30
- * decode is skipped: the spec validation step has already refused the
31
- * workflow for it, and this collector never double-reports.
32
- */
33
- export function collectAgentCallReferences(spec, parentOrg) {
34
- const refs = [];
35
- if (spec === undefined) {
36
- return refs;
37
- }
38
- const visit = (task) => {
39
- if (task.taskConfig !== undefined) {
40
- let config;
41
- try {
42
- config = unmarshalTaskConfig(task.kind, task.taskConfig);
43
- }
44
- catch {
45
- config = undefined;
46
- }
47
- if (config !== undefined) {
48
- if (task.kind === WorkflowTaskKind.agent_call) {
49
- const agent = config.agent;
50
- const parsed = parseAgentReference(agent);
51
- if (parsed === undefined) {
52
- throw invalidArgumentError(malformedAgentReferenceMessage(task.name, agent));
53
- }
54
- refs.push({
55
- kind: ApiResourceKind.agent,
56
- org: parsed.org === "" ? parentOrg : parsed.org,
57
- slug: parsed.slug,
58
- });
59
- }
60
- for (const nested of nestedTasks(config)) {
61
- visit(nested);
62
- }
63
- }
64
- }
65
- for (const compensate of task.compensate) {
66
- visit(compensate);
67
- }
68
- };
69
- for (const task of spec.tasks) {
70
- visit(task);
71
- }
72
- return refs;
73
- }
74
- export function newValidateAgentCallReferencesStep(store) {
75
- return {
76
- name: "ValidateAgentCallReferences",
77
- async execute(ctx) {
78
- const metadata = metadataOf(ctx.newState);
79
- if (metadata === undefined) {
80
- throw internalError(new Error("resource metadata is nil"), "validate agent_call references");
81
- }
82
- const refs = collectAgentCallReferences(ctx.newState.spec, metadata.org);
83
- if (refs.length === 0) {
84
- return;
85
- }
86
- const parent = {
87
- org: metadata.org,
88
- visibility: metadata.visibility,
89
- };
90
- const refusal = await checkReferences(store, parent, refs);
91
- if (refusal !== undefined) {
92
- throw refusal;
93
- }
94
- },
95
- };
96
- }
97
- //# sourceMappingURL=agent-call-references.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-call-references.js","sourceRoot":"","sources":["../../../src/domain/workflow/agent-call-references.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wDAAwD,CAAC;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AAGtH,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAO/E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAEtE,oFAAoF;AACpF,MAAM,UAAU,8BAA8B,CAC5C,QAAgB,EAChB,KAAa;IAEb,OAAO,SAAS,QAAQ,aAAa,KAAK,gHAAgH,CAAC;AAC7J,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAa;IAEb,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG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U,EAAE,QAAQ,CAAC,UAAU;aAChC,CAAC;YACF,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAC3D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,OAAO,CAAC;YAChB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,67 +0,0 @@
1
- /**
2
- * The one data migration both store drivers run when the public visibility
3
- * level is retired: every stored row that holds `visibility_public` is moved
4
- * to `visibility_org`, once, in place. The drivers own the SQL (which rows
5
- * to read, how to write them back, the transaction); this module owns what
6
- * is edition- and driver-neutral: WHICH kinds could hold the level and HOW
7
- * one row's bytes are moved.
8
- *
9
- * Why a migration and not a sweep. The migration chain is the one place
10
- * that runs exactly once per database, before any request is served. A
11
- * public row nobody can set again would otherwise stay readable by every
12
- * account on a self-hosted install forever, because the level's grant was
13
- * derived from the row itself; on the hosted edition the rows are moved
14
- * through the API before this release deploys (the tuple lifecycle is
15
- * row-driven, and only that path deletes the grant's stored tuple), so the
16
- * migration there finds none and is the safety net, never the mechanism.
17
- *
18
- * Why the kind table is frozen here and not read from the live kind
19
- * configuration. A migration is a statement about the store AS IT WAS when
20
- * the level was retired: the seven kinds whose VisibilityConfig declared
21
- * `supports_public` at that moment are the only kinds a public row can
22
- * exist under, and a later release that adds or removes a kind must not
23
- * change what this step does. The list is spelled out with its schemas, the
24
- * per-consumer kind-to-schema idiom the tree already uses; nothing here
25
- * reads `kind_meta`. The `kind` strings are the enum NAMES the drivers'
26
- * `kind` column holds (proto-fields.ts `apiResourceKindName`).
27
- *
28
- * Why decode and re-encode rather than patch bytes. `resources.data` is the
29
- * marshaled proto message; the level is one enum field on the metadata
30
- * message, and only a decode knows where it is. protobuf-es keeps unknown
31
- * fields through `fromBinary` and writes them back in `toBinary`, so a row
32
- * written by a newer or older release than this one loses nothing it
33
- * carried; every other field is re-encoded from the same values. A row this
34
- * step cannot decode is a fault that fails the whole transaction (the
35
- * driver's `applyInTransaction` rolls back and the boot stops): skipping it
36
- * would leave the one row the migration exists for readable by everyone,
37
- * silently.
38
- *
39
- * `resource_audit` is deliberately untouched: it is the version history,
40
- * and a snapshot that said "public" at the time is true history. The search
41
- * index is left to boot's rebuild, which re-derives it from the rows.
42
- */
43
- import type { DescMessage } from "@bufbuild/protobuf";
44
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
45
- /** One kind that could hold the public level, with the schema its rows decode through. */
46
- export interface PublicRowKind {
47
- /** The enum NAME the drivers' `kind` column holds. */
48
- readonly kind: string;
49
- readonly schema: DescMessage;
50
- }
51
- /**
52
- * The seven kinds whose VisibilityConfig declared `supports_public` when the
53
- * level was retired — frozen (the module header). Order is the order the
54
- * drivers walk the kinds; it has no other meaning.
55
- */
56
- export declare const PUBLIC_ROW_KINDS_AT_RETIREMENT: ReadonlyArray<PublicRowKind>;
57
- /** The level every moved row takes: the widest level that stays inside the owning organization. */
58
- export declare const LEVEL_AFTER_RETIREMENT = ApiResourceVisibility.visibility_org;
59
- /**
60
- * The moved bytes of one row when it holds the public level, or undefined
61
- * when it does not (the driver then leaves the row's bytes exactly as they
62
- * are; a row with no metadata holds no level and is one of these). Throws
63
- * when the bytes do not decode as the kind's message: a row this migration
64
- * cannot read is a row it must not pass over (the module header).
65
- */
66
- export declare function movePublicRowToOrg(entry: PublicRowKind, data: Uint8Array): Uint8Array | undefined;
67
- //# sourceMappingURL=public-visibility-retired.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-visibility-retired.d.ts","sourceRoot":"","sources":["../../src/store/public-visibility-retired.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAWtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AAE/F,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,EAAE,aAAa,CAAC,aAAa,CAQvE,CAAC;AAEF,mGAAmG;AACnG,eAAO,MAAM,sBAAsB,uCAAuC,CAAC;AAE3E;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,UAAU,GACf,UAAU,GAAG,SAAS,CA4BxB"}
@@ -1,55 +0,0 @@
1
- import { fromBinary, toBinary } from "@bufbuild/protobuf";
2
- import { reflect } from "@bufbuild/protobuf/reflect";
3
- import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
4
- import { AgentInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/agentinstance/v1/api_pb";
5
- import { McpServerSchema } from "@stigmer/protos/ai/stigmer/agentic/mcpserver/v1/api_pb";
6
- import { PluginSchema } from "@stigmer/protos/ai/stigmer/agentic/plugin/v1/api_pb";
7
- import { SkillSchema } from "@stigmer/protos/ai/stigmer/agentic/skill/v1/api_pb";
8
- import { WorkflowSchema } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/api_pb";
9
- import { WorkflowInstanceSchema } from "@stigmer/protos/ai/stigmer/agentic/workflowinstance/v1/api_pb";
10
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
11
- /**
12
- * The seven kinds whose VisibilityConfig declared `supports_public` when the
13
- * level was retired — frozen (the module header). Order is the order the
14
- * drivers walk the kinds; it has no other meaning.
15
- */
16
- export const PUBLIC_ROW_KINDS_AT_RETIREMENT = [
17
- { kind: "agent", schema: AgentSchema },
18
- { kind: "skill", schema: SkillSchema },
19
- { kind: "mcp_server", schema: McpServerSchema },
20
- { kind: "agent_instance", schema: AgentInstanceSchema },
21
- { kind: "workflow", schema: WorkflowSchema },
22
- { kind: "workflow_instance", schema: WorkflowInstanceSchema },
23
- { kind: "plugin", schema: PluginSchema },
24
- ];
25
- /** The level every moved row takes: the widest level that stays inside the owning organization. */
26
- export const LEVEL_AFTER_RETIREMENT = ApiResourceVisibility.visibility_org;
27
- /**
28
- * The moved bytes of one row when it holds the public level, or undefined
29
- * when it does not (the driver then leaves the row's bytes exactly as they
30
- * are; a row with no metadata holds no level and is one of these). Throws
31
- * when the bytes do not decode as the kind's message: a row this migration
32
- * cannot read is a row it must not pass over (the module header).
33
- */
34
- export function movePublicRowToOrg(entry, data) {
35
- const message = fromBinary(entry.schema, data);
36
- const root = reflect(entry.schema, message);
37
- const metadataField = root.fields.find((field) => field.name === "metadata");
38
- if (metadataField === undefined || metadataField.fieldKind !== "message") {
39
- throw new Error(`${entry.kind}: the schema declares no metadata message field`);
40
- }
41
- if (!root.isSet(metadataField)) {
42
- return undefined;
43
- }
44
- const metadata = root.get(metadataField);
45
- const visibilityField = metadata.fields.find((field) => field.name === "visibility");
46
- if (visibilityField === undefined || visibilityField.fieldKind !== "enum") {
47
- throw new Error(`${entry.kind}: the metadata message declares no visibility enum field`);
48
- }
49
- if (metadata.get(visibilityField) !== ApiResourceVisibility.visibility_public) {
50
- return undefined;
51
- }
52
- metadata.set(visibilityField, LEVEL_AFTER_RETIREMENT);
53
- return toBinary(entry.schema, message);
54
- }
55
- //# sourceMappingURL=public-visibility-retired.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-visibility-retired.js","sourceRoot":"","sources":["../../src/store/public-visibility-retired.ts"],"names":[],"mappings":"AA2CA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,oDAAoD,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,MAAM,4DAA4D,CAAC;AACjG,OAA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,CAAC,CAAC;IAC7E,IAAI,aAAa,KAAK,SAAS,IAAI,aAAa,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACzE,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,CAAC,IAAI,iDAAiD,CAC/D,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACzC,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAC1C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,CACvC,CAAC;IACF,IAAI,eAAe,KAAK,SAAS,IAAI,eAAe,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;QAC1E,MAAM,IAAI,KAAK,CACb,GAAG,KAAK,CAAC,IAAI,0DAA0D,CACxE,CAAC;IACJ,CAAC;IACD,IACE,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,qBAAqB,CAAC,iBAAiB,EACzE,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,sBAAsB,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -1,222 +0,0 @@
1
- /**
2
- * Pins the workflow domain's collector for the reference rule
3
- * (../agent-call-references.ts): the strict `slug` / `org/slug` parser and
4
- * its refusal copy, the walk over top-level, nested and compensate tasks
5
- * in declaration order with the bare form resolved to the workflow's
6
- * organization, a config that does not decode skipped rather than
7
- * double-reported, and the step over a real store answering the rule's
8
- * verdicts — a missing agent with the rule's copy, another organization's
9
- * org-visible agent with the one cross-organization sentence, a
10
- * platform-visible one admitted.
11
- */
12
- import { create } from "@bufbuild/protobuf";
13
- import { Code, ConnectError } from "@connectrpc/connect";
14
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
15
-
16
- import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
17
- import { WorkflowSchema } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/api_pb";
18
- import { WorkflowTaskKind } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/enum_pb";
19
- import type { WorkflowSpec } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/spec_pb";
20
- import { WorkflowSpecSchema } from "@stigmer/protos/ai/stigmer/agentic/workflow/v1/spec_pb";
21
- import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
22
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
23
-
24
- import { RequestContext } from "../../../pipeline/request-context.js";
25
- import { testCallerIdentity } from "../../../pipeline/__tests__/support.js";
26
- import {
27
- missingReferencesMessage,
28
- notAvailableReferenceMessage,
29
- referenceTargetKind,
30
- } from "../../../pipeline/steps/references.js";
31
- import type { SqliteStore } from "../../../store/sqlite/store.js";
32
- import { tempStore } from "../../../store/sqlite/__tests__/support.js";
33
- import {
34
- collectAgentCallReferences,
35
- malformedAgentReferenceMessage,
36
- newValidateAgentCallReferencesStep,
37
- parseAgentReference,
38
- } from "../agent-call-references.js";
39
-
40
- const V = ApiResourceVisibility;
41
- const AGENT = referenceTargetKind(ApiResourceKind.agent)!;
42
-
43
- function agentCall(name: string, agent: string) {
44
- return {
45
- name,
46
- kind: WorkflowTaskKind.agent_call,
47
- taskConfig: { agent, message: "do the thing" },
48
- };
49
- }
50
-
51
- function specOf(tasks: ReadonlyArray<Record<string, unknown>>): WorkflowSpec {
52
- return create(WorkflowSpecSchema, { tasks } as never);
53
- }
54
-
55
- describe("parseAgentReference", () => {
56
- it("accepts `slug` and `org/slug` and nothing else", () => {
57
- expect(parseAgentReference("reviewer")).toEqual({
58
- org: "",
59
- slug: "reviewer",
60
- });
61
- expect(parseAgentReference("acme/reviewer")).toEqual({
62
- org: "acme",
63
- slug: "reviewer",
64
- });
65
- for (const malformed of ["", "/reviewer", "acme/", "a/b/c", "//"]) {
66
- expect(parseAgentReference(malformed), malformed).toBeUndefined();
67
- }
68
- });
69
- });
70
-
71
- describe("collectAgentCallReferences", () => {
72
- it("collects top-level, nested and compensate agent_call tasks in declaration order, the bare form resolved to the workflow's organization", () => {
73
- const spec = specOf([
74
- agentCall("first", "reviewer"),
75
- {
76
- name: "loop",
77
- kind: WorkflowTaskKind.for_each,
78
- taskConfig: {
79
- each: "item",
80
- in: "${ .items }",
81
- // A nested task inside the Struct is JSON: proto field names.
82
- do: [
83
- {
84
- name: "inner",
85
- kind: "agent_call",
86
- task_config: { agent: "globex/summarizer", message: "sum" },
87
- },
88
- ],
89
- },
90
- compensate: [agentCall("undo", "cleaner")],
91
- },
92
- {
93
- name: "pause",
94
- kind: WorkflowTaskKind.wait,
95
- taskConfig: { duration: {} },
96
- },
97
- ]);
98
- expect(collectAgentCallReferences(spec, "acme")).toEqual([
99
- { kind: ApiResourceKind.agent, org: "acme", slug: "reviewer" },
100
- { kind: ApiResourceKind.agent, org: "globex", slug: "summarizer" },
101
- { kind: ApiResourceKind.agent, org: "acme", slug: "cleaner" },
102
- ]);
103
- });
104
-
105
- it("refuses a malformed agent string naming the task", () => {
106
- const spec = specOf([agentCall("broken", "a/b/c")]);
107
- expect(() => collectAgentCallReferences(spec, "acme")).toThrow(
108
- malformedAgentReferenceMessage("broken", "a/b/c"),
109
- );
110
- let error: unknown;
111
- try {
112
- collectAgentCallReferences(spec, "acme");
113
- } catch (e) {
114
- error = e;
115
- }
116
- expect((error as ConnectError).code).toBe(Code.InvalidArgument);
117
- });
118
-
119
- it("skips a config that does not decode — the spec validation step has already refused it", () => {
120
- const spec = specOf([
121
- {
122
- name: "odd",
123
- kind: WorkflowTaskKind.agent_call,
124
- taskConfig: { agent: "reviewer", not_a_field: true },
125
- },
126
- ]);
127
- expect(collectAgentCallReferences(spec, "acme")).toEqual([]);
128
- expect(collectAgentCallReferences(undefined, "acme")).toEqual([]);
129
- });
130
- });
131
-
132
- describe("ValidateAgentCallReferences over a store", () => {
133
- let store: SqliteStore;
134
- let cleanup: () => Promise<void>;
135
-
136
- beforeEach(() => {
137
- const temp = tempStore();
138
- store = temp.store;
139
- cleanup = temp.cleanup;
140
- });
141
-
142
- afterEach(async () => {
143
- await cleanup();
144
- });
145
-
146
- async function seedAgent(
147
- id: string,
148
- org: string,
149
- slug: string,
150
- visibility: ApiResourceVisibility,
151
- ): Promise<void> {
152
- await store.saveResource(
153
- ApiResourceKind.agent,
154
- id,
155
- AgentSchema,
156
- create(AgentSchema, {
157
- apiVersion: "agentic.stigmer.ai/v1",
158
- kind: "Agent",
159
- metadata: { id, name: slug, slug, org, visibility },
160
- spec: { instructions: "a conformant instruction body" },
161
- }),
162
- );
163
- }
164
-
165
- function workflowCalling(...agents: string[]) {
166
- return create(WorkflowSchema, {
167
- apiVersion: "agentic.stigmer.ai/v1",
168
- kind: "Workflow",
169
- metadata: { name: "Pipeline", org: "acme", visibility: V.visibility_org },
170
- spec: specOf(agents.map((agent, i) => agentCall(`call_${i}`, agent))),
171
- });
172
- }
173
-
174
- async function run(workflow: ReturnType<typeof workflowCalling>) {
175
- const ctx = new RequestContext(
176
- WorkflowSchema,
177
- workflow,
178
- testCallerIdentity(),
179
- ApiResourceKind.workflow,
180
- );
181
- try {
182
- await newValidateAgentCallReferencesStep(store).execute(ctx);
183
- return undefined;
184
- } catch (error) {
185
- return error;
186
- }
187
- }
188
-
189
- it("a missing agent is refused with the rule's copy; an existing one passes", async () => {
190
- const error = await run(workflowCalling("reviewer"));
191
- expect(error).toBeInstanceOf(ConnectError);
192
- expect((error as ConnectError).code).toBe(Code.FailedPrecondition);
193
- expect((error as ConnectError).rawMessage).toBe(
194
- missingReferencesMessage(AGENT, [{ slug: "reviewer", org: "acme" }]),
195
- );
196
- await seedAgent("agt_1", "acme", "reviewer", V.visibility_org);
197
- expect(await run(workflowCalling("reviewer"))).toBeUndefined();
198
- });
199
-
200
- it("another organization's agent is admitted only at platform visibility, with the one sentence otherwise", async () => {
201
- await seedAgent("agt_shared", "globex", "shared", V.visibility_platform);
202
- await seedAgent("agt_internal", "globex", "internal", V.visibility_org);
203
- expect(await run(workflowCalling("globex/shared"))).toBeUndefined();
204
- const error = await run(workflowCalling("globex/internal"));
205
- expect((error as ConnectError).rawMessage).toBe(
206
- notAvailableReferenceMessage(AGENT, {
207
- kind: ApiResourceKind.agent,
208
- org: "globex",
209
- slug: "internal",
210
- }),
211
- );
212
- });
213
-
214
- it("the floor holds for the agent a workflow calls: an org-visible workflow may not call a private agent", async () => {
215
- await seedAgent("agt_mine", "acme", "mine", V.visibility_private);
216
- const error = await run(workflowCalling("mine"));
217
- expect((error as ConnectError).code).toBe(Code.FailedPrecondition);
218
- expect((error as ConnectError).rawMessage).toContain(
219
- "referenced agent 'acme/mine' is visibility_private while this resource is visibility_org",
220
- );
221
- });
222
- });