@stigmer/server 3.20.0 → 3.22.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 (257) hide show
  1. package/dist/authorization/evaluator.d.ts +7 -1
  2. package/dist/authorization/evaluator.d.ts.map +1 -1
  3. package/dist/authorization/evaluator.js.map +1 -1
  4. package/dist/authorization/list-read-scope.d.ts.map +1 -1
  5. package/dist/authorization/list-read-scope.js +19 -11
  6. package/dist/authorization/list-read-scope.js.map +1 -1
  7. package/dist/authorization/model/organization.d.ts.map +1 -1
  8. package/dist/authorization/model/organization.js +2 -0
  9. package/dist/authorization/model/organization.js.map +1 -1
  10. package/dist/boot/compose.d.ts.map +1 -1
  11. package/dist/boot/compose.js +0 -1
  12. package/dist/boot/compose.js.map +1 -1
  13. package/dist/boot/inprocess.d.ts +0 -2
  14. package/dist/boot/inprocess.d.ts.map +1 -1
  15. package/dist/boot/inprocess.js +0 -6
  16. package/dist/boot/inprocess.js.map +1 -1
  17. package/dist/domain/agent/controller.d.ts +2 -2
  18. package/dist/domain/agent/controller.d.ts.map +1 -1
  19. package/dist/domain/agent/controller.js +3 -17
  20. package/dist/domain/agent/controller.js.map +1 -1
  21. package/dist/domain/agent/steps.d.ts +0 -1
  22. package/dist/domain/agent/steps.d.ts.map +1 -1
  23. package/dist/domain/agent/steps.js +1 -40
  24. package/dist/domain/agent/steps.js.map +1 -1
  25. package/dist/domain/agentchannel/controller.d.ts.map +1 -1
  26. package/dist/domain/agentchannel/controller.js +6 -1
  27. package/dist/domain/agentchannel/controller.js.map +1 -1
  28. package/dist/domain/agentchannel/steps.d.ts +19 -0
  29. package/dist/domain/agentchannel/steps.d.ts.map +1 -1
  30. package/dist/domain/agentchannel/steps.js +32 -0
  31. package/dist/domain/agentchannel/steps.js.map +1 -1
  32. package/dist/domain/agentexecution/controller.d.ts.map +1 -1
  33. package/dist/domain/agentexecution/controller.js +7 -9
  34. package/dist/domain/agentexecution/controller.js.map +1 -1
  35. package/dist/domain/agentexecution/create-execution-context-step.d.ts +0 -2
  36. package/dist/domain/agentexecution/create-execution-context-step.d.ts.map +1 -1
  37. package/dist/domain/agentexecution/create-execution-context-step.js +179 -60
  38. package/dist/domain/agentexecution/create-execution-context-step.js.map +1 -1
  39. package/dist/domain/agentexecution/create-steps.d.ts +16 -31
  40. package/dist/domain/agentexecution/create-steps.d.ts.map +1 -1
  41. package/dist/domain/agentexecution/create-steps.js +36 -102
  42. package/dist/domain/agentexecution/create-steps.js.map +1 -1
  43. package/dist/domain/agentexecution/run-target.d.ts +7 -3
  44. package/dist/domain/agentexecution/run-target.d.ts.map +1 -1
  45. package/dist/domain/agentexecution/run-target.js.map +1 -1
  46. package/dist/domain/agentinstance/controller.d.ts +5 -5
  47. package/dist/domain/agentinstance/controller.d.ts.map +1 -1
  48. package/dist/domain/agentinstance/controller.js +6 -1
  49. package/dist/domain/agentinstance/controller.js.map +1 -1
  50. package/dist/domain/agentinstance/steps.d.ts +43 -8
  51. package/dist/domain/agentinstance/steps.d.ts.map +1 -1
  52. package/dist/domain/agentinstance/steps.js +71 -8
  53. package/dist/domain/agentinstance/steps.js.map +1 -1
  54. package/dist/domain/agentshare/controller.d.ts.map +1 -1
  55. package/dist/domain/agentshare/controller.js +7 -1
  56. package/dist/domain/agentshare/controller.js.map +1 -1
  57. package/dist/domain/agentshare/steps.d.ts +58 -0
  58. package/dist/domain/agentshare/steps.d.ts.map +1 -1
  59. package/dist/domain/agentshare/steps.js +109 -4
  60. package/dist/domain/agentshare/steps.js.map +1 -1
  61. package/dist/domain/artifact/controller.js +21 -25
  62. package/dist/domain/artifact/controller.js.map +1 -1
  63. package/dist/domain/channelapp/controller.d.ts.map +1 -1
  64. package/dist/domain/channelapp/controller.js +2 -0
  65. package/dist/domain/channelapp/controller.js.map +1 -1
  66. package/dist/domain/environment/controller.d.ts.map +1 -1
  67. package/dist/domain/environment/controller.js +2 -0
  68. package/dist/domain/environment/controller.js.map +1 -1
  69. package/dist/domain/environment/personal.d.ts +42 -0
  70. package/dist/domain/environment/personal.d.ts.map +1 -0
  71. package/dist/domain/environment/personal.js +96 -0
  72. package/dist/domain/environment/personal.js.map +1 -0
  73. package/dist/domain/executioncontext/controller.d.ts.map +1 -1
  74. package/dist/domain/executioncontext/controller.js +2 -0
  75. package/dist/domain/executioncontext/controller.js.map +1 -1
  76. package/dist/domain/executioncontext/steps.d.ts.map +1 -1
  77. package/dist/domain/executioncontext/steps.js +2 -1
  78. package/dist/domain/executioncontext/steps.js.map +1 -1
  79. package/dist/domain/mcpserver/connect.d.ts +0 -2
  80. package/dist/domain/mcpserver/connect.d.ts.map +1 -1
  81. package/dist/domain/mcpserver/connect.js +24 -79
  82. package/dist/domain/mcpserver/connect.js.map +1 -1
  83. package/dist/domain/mcpserver/controller.d.ts.map +1 -1
  84. package/dist/domain/mcpserver/controller.js +2 -0
  85. package/dist/domain/mcpserver/controller.js.map +1 -1
  86. package/dist/domain/mcpserver/start-connect.d.ts.map +1 -1
  87. package/dist/domain/mcpserver/start-connect.js +8 -7
  88. package/dist/domain/mcpserver/start-connect.js.map +1 -1
  89. package/dist/domain/memory/controller.d.ts.map +1 -1
  90. package/dist/domain/memory/controller.js +6 -1
  91. package/dist/domain/memory/controller.js.map +1 -1
  92. package/dist/domain/memory/steps.d.ts +23 -0
  93. package/dist/domain/memory/steps.d.ts.map +1 -1
  94. package/dist/domain/memory/steps.js +35 -0
  95. package/dist/domain/memory/steps.js.map +1 -1
  96. package/dist/domain/oauthapp/controller.d.ts.map +1 -1
  97. package/dist/domain/oauthapp/controller.js +2 -0
  98. package/dist/domain/oauthapp/controller.js.map +1 -1
  99. package/dist/domain/plugin/controller.d.ts.map +1 -1
  100. package/dist/domain/plugin/controller.js +5 -24
  101. package/dist/domain/plugin/controller.js.map +1 -1
  102. package/dist/domain/plugin/overlay/sanitize.js +2 -2
  103. package/dist/domain/schedule/controller.d.ts.map +1 -1
  104. package/dist/domain/schedule/controller.js +7 -1
  105. package/dist/domain/schedule/controller.js.map +1 -1
  106. package/dist/domain/schedule/steps.d.ts +19 -0
  107. package/dist/domain/schedule/steps.d.ts.map +1 -1
  108. package/dist/domain/schedule/steps.js +32 -0
  109. package/dist/domain/schedule/steps.js.map +1 -1
  110. package/dist/domain/session/controller.d.ts +0 -7
  111. package/dist/domain/session/controller.d.ts.map +1 -1
  112. package/dist/domain/session/controller.js +11 -16
  113. package/dist/domain/session/controller.js.map +1 -1
  114. package/dist/domain/session/run-target.d.ts +9 -8
  115. package/dist/domain/session/run-target.d.ts.map +1 -1
  116. package/dist/domain/session/run-target.js.map +1 -1
  117. package/dist/domain/session/steps.d.ts +8 -36
  118. package/dist/domain/session/steps.d.ts.map +1 -1
  119. package/dist/domain/session/steps.js +27 -172
  120. package/dist/domain/session/steps.js.map +1 -1
  121. package/dist/domain/skill/controller.d.ts.map +1 -1
  122. package/dist/domain/skill/controller.js +8 -17
  123. package/dist/domain/skill/controller.js.map +1 -1
  124. package/dist/domain/workflow/controller.d.ts.map +1 -1
  125. package/dist/domain/workflow/controller.js +30 -107
  126. package/dist/domain/workflow/controller.js.map +1 -1
  127. package/dist/domain/workflow/version-resolution.d.ts +5 -0
  128. package/dist/domain/workflow/version-resolution.d.ts.map +1 -0
  129. package/dist/domain/workflow/version-resolution.js +113 -0
  130. package/dist/domain/workflow/version-resolution.js.map +1 -0
  131. package/dist/domain/workflowexecution/create-steps.d.ts +4 -3
  132. package/dist/domain/workflowexecution/create-steps.d.ts.map +1 -1
  133. package/dist/domain/workflowexecution/create-steps.js +4 -3
  134. package/dist/domain/workflowexecution/create-steps.js.map +1 -1
  135. package/dist/domain/workflowinstance/controller.d.ts.map +1 -1
  136. package/dist/domain/workflowinstance/controller.js +6 -1
  137. package/dist/domain/workflowinstance/controller.js.map +1 -1
  138. package/dist/domain/workflowinstance/steps.d.ts +20 -0
  139. package/dist/domain/workflowinstance/steps.d.ts.map +1 -1
  140. package/dist/domain/workflowinstance/steps.js +39 -0
  141. package/dist/domain/workflowinstance/steps.js.map +1 -1
  142. package/dist/extensions/identity.d.ts +19 -0
  143. package/dist/extensions/identity.d.ts.map +1 -1
  144. package/dist/extensions/identity.js +22 -3
  145. package/dist/extensions/identity.js.map +1 -1
  146. package/dist/extensions/list-read-scope.d.ts +41 -7
  147. package/dist/extensions/list-read-scope.d.ts.map +1 -1
  148. package/dist/extensions/list-read-scope.js +13 -2
  149. package/dist/extensions/list-read-scope.js.map +1 -1
  150. package/dist/pipeline/apiresource-labels.d.ts +2 -2
  151. package/dist/pipeline/apiresource-labels.js +2 -2
  152. package/dist/pipeline/errors.d.ts +2 -2
  153. package/dist/pipeline/errors.js +2 -2
  154. package/dist/pipeline/steps/authorize-resolved-target.d.ts +88 -0
  155. package/dist/pipeline/steps/authorize-resolved-target.d.ts.map +1 -0
  156. package/dist/pipeline/steps/authorize-resolved-target.js +36 -0
  157. package/dist/pipeline/steps/authorize-resolved-target.js.map +1 -0
  158. package/dist/pipeline/steps/authorize.d.ts +27 -0
  159. package/dist/pipeline/steps/authorize.d.ts.map +1 -1
  160. package/dist/pipeline/steps/authorize.js +49 -10
  161. package/dist/pipeline/steps/authorize.js.map +1 -1
  162. package/dist/pipeline/steps/guard-memory-capture.d.ts.map +1 -1
  163. package/dist/pipeline/steps/guard-memory-capture.js +2 -1
  164. package/dist/pipeline/steps/guard-memory-capture.js.map +1 -1
  165. package/dist/pipeline/steps/guard-reserved-labels.d.ts.map +1 -1
  166. package/dist/pipeline/steps/guard-reserved-labels.js +12 -12
  167. package/dist/pipeline/steps/guard-reserved-labels.js.map +1 -1
  168. package/dist/pipeline/steps/helpers.d.ts +9 -5
  169. package/dist/pipeline/steps/helpers.d.ts.map +1 -1
  170. package/dist/pipeline/steps/helpers.js +11 -15
  171. package/dist/pipeline/steps/helpers.js.map +1 -1
  172. package/dist/pipeline/steps/version-history.d.ts +11 -0
  173. package/dist/pipeline/steps/version-history.d.ts.map +1 -1
  174. package/dist/pipeline/steps/version-history.js +26 -0
  175. package/dist/pipeline/steps/version-history.js.map +1 -1
  176. package/package.json +6 -6
  177. package/src/authorization/__tests__/list-read-scope.test.ts +23 -12
  178. package/src/authorization/__tests__/skip-lane-inventory.test.ts +160 -0
  179. package/src/authorization/__tests__/wire-permissions.test.ts +5 -5
  180. package/src/authorization/evaluator.ts +7 -0
  181. package/src/authorization/list-read-scope.ts +22 -11
  182. package/src/authorization/model/__tests__/registry.test.ts +2 -0
  183. package/src/authorization/model/organization.ts +2 -0
  184. package/src/boot/compose.ts +0 -1
  185. package/src/boot/inprocess.ts +0 -9
  186. package/src/domain/agent/__tests__/agent.test.ts +0 -68
  187. package/src/domain/agent/controller.ts +11 -36
  188. package/src/domain/agent/steps.ts +1 -60
  189. package/src/domain/agentchannel/__tests__/create-authorization.test.ts +58 -0
  190. package/src/domain/agentchannel/controller.ts +19 -0
  191. package/src/domain/agentchannel/steps.ts +40 -0
  192. package/src/domain/agentexecution/__tests__/create-execution-context-step.test.ts +216 -0
  193. package/src/domain/agentexecution/__tests__/create-steps.test.ts +70 -145
  194. package/src/domain/agentexecution/controller.ts +6 -10
  195. package/src/domain/agentexecution/create-execution-context-step.ts +271 -83
  196. package/src/domain/agentexecution/create-steps.ts +38 -138
  197. package/src/domain/agentexecution/run-target.ts +7 -3
  198. package/src/domain/agentinstance/__tests__/create-authorization.composed.test.ts +243 -0
  199. package/src/domain/agentinstance/__tests__/create-authorization.test.ts +144 -0
  200. package/src/domain/agentinstance/controller.ts +24 -5
  201. package/src/domain/agentinstance/steps.ts +82 -8
  202. package/src/domain/agentshare/__tests__/create-authorization.test.ts +86 -0
  203. package/src/domain/agentshare/__tests__/member-audience.test.ts +113 -0
  204. package/src/domain/agentshare/controller.ts +21 -0
  205. package/src/domain/agentshare/steps.ts +181 -15
  206. package/src/domain/artifact/controller.ts +18 -22
  207. package/src/domain/channelapp/controller.ts +10 -0
  208. package/src/domain/environment/__tests__/personal.test.ts +143 -0
  209. package/src/domain/environment/controller.ts +10 -0
  210. package/src/domain/environment/personal.ts +141 -0
  211. package/src/domain/executioncontext/__tests__/executioncontext.test.ts +1 -0
  212. package/src/domain/executioncontext/controller.ts +10 -0
  213. package/src/domain/executioncontext/steps.ts +2 -1
  214. package/src/domain/mcpserver/connect.ts +32 -92
  215. package/src/domain/mcpserver/controller.ts +13 -1
  216. package/src/domain/mcpserver/start-connect.ts +17 -11
  217. package/src/domain/memory/__tests__/create-authorization.test.ts +59 -0
  218. package/src/domain/memory/controller.ts +11 -0
  219. package/src/domain/memory/steps.ts +41 -0
  220. package/src/domain/oauthapp/controller.ts +10 -0
  221. package/src/domain/plugin/controller.ts +22 -36
  222. package/src/domain/plugin/overlay/sanitize.ts +2 -2
  223. package/src/domain/schedule/__tests__/create-authorization.test.ts +58 -0
  224. package/src/domain/schedule/controller.ts +20 -0
  225. package/src/domain/schedule/steps.ts +45 -2
  226. package/src/domain/session/__tests__/run-gate.test.ts +19 -52
  227. package/src/domain/session/__tests__/session.test.ts +27 -203
  228. package/src/domain/session/controller.ts +10 -30
  229. package/src/domain/session/run-target.ts +9 -8
  230. package/src/domain/session/steps.ts +33 -267
  231. package/src/domain/skill/controller.ts +24 -23
  232. package/src/domain/workflow/controller.ts +58 -145
  233. package/src/domain/workflow/version-resolution.ts +166 -0
  234. package/src/domain/workflowexecution/create-steps.ts +4 -3
  235. package/src/domain/workflowinstance/__tests__/create-authorization.test.ts +109 -0
  236. package/src/domain/workflowinstance/controller.ts +19 -0
  237. package/src/domain/workflowinstance/steps.ts +49 -1
  238. package/src/extensions/__tests__/composed-support.ts +38 -4
  239. package/src/extensions/__tests__/identity.test.ts +44 -1
  240. package/src/extensions/__tests__/list-read-scope-composed.test.ts +87 -1
  241. package/src/extensions/__tests__/list-read-scope.test.ts +63 -0
  242. package/src/extensions/identity.ts +23 -5
  243. package/src/extensions/list-read-scope.ts +47 -7
  244. package/src/pipeline/apiresource-labels.ts +2 -2
  245. package/src/pipeline/errors.ts +2 -2
  246. package/src/pipeline/steps/__tests__/authorize-resolved-target.test.ts +285 -0
  247. package/src/pipeline/steps/authorize-resolved-target.ts +129 -0
  248. package/src/pipeline/steps/authorize.ts +70 -13
  249. package/src/pipeline/steps/guard-memory-capture.ts +2 -1
  250. package/src/pipeline/steps/guard-reserved-labels.ts +12 -14
  251. package/src/pipeline/steps/helpers.ts +11 -15
  252. package/src/pipeline/steps/version-history.ts +34 -0
  253. package/dist/domain/agent/defaultagent.d.ts +0 -37
  254. package/dist/domain/agent/defaultagent.d.ts.map +0 -1
  255. package/dist/domain/agent/defaultagent.js +0 -104
  256. package/dist/domain/agent/defaultagent.js.map +0 -1
  257. package/src/domain/agent/defaultagent.ts +0 -135
@@ -31,6 +31,7 @@ import type { DescMessage, Message, MessageShape } from "@bufbuild/protobuf";
31
31
 
32
32
  import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
33
33
  import type { ApiResourceReferenceSchema } from "@stigmer/protos/ai/stigmer/commons/apiresource/io_pb";
34
+ import { IamPermission } from "@stigmer/protos/ai/stigmer/iam/v1/enum_pb";
34
35
 
35
36
  import {
36
37
  internalError,
@@ -42,6 +43,7 @@ import type { RequestContext } from "../request-context.js";
42
43
  import { AuditNotFoundError } from "../../store/interface.js";
43
44
  import type { Store } from "../../store/interface.js";
44
45
  import { findResourceBySlug, requireOrgForReference } from "./helpers.js";
46
+ import type { ResolvedTargetResolver } from "./authorize-resolved-target.js";
45
47
  import { TARGET_RESOURCE_KEY } from "./load-target.js";
46
48
  import { metadataOf } from "./shapes.js";
47
49
 
@@ -192,6 +194,38 @@ export const LIST_VERSIONS_RESOURCE_ID_KEY = "listVersionsResourceId";
192
194
  export const LIST_VERSIONS_HEAD_HASH_KEY = "listVersionsHeadHash";
193
195
  export const LIST_VERSIONS_RESPONSE_KEY = "listVersionsResponse";
194
196
 
197
+ /**
198
+ * The ListVersions lanes' authorization question, for the
199
+ * AuthorizeResolvedTarget step placed after the slug resolver: `can_view`
200
+ * on the resolved head's id (the version history of a row is readable by
201
+ * whoever may read the row), with the lane's byte-pinned copy. The id key
202
+ * is the resolver's own — the shared resolver stashes under
203
+ * LIST_VERSIONS_RESOURCE_ID_KEY; a domain resolver with its own key names
204
+ * it. An id the chain did not stash is a broken invariant and throws.
205
+ */
206
+ export function versionHistoryTarget<Desc extends DescMessage>(
207
+ kind: ApiResourceKind,
208
+ deniedMessage: string,
209
+ idKey: string = LIST_VERSIONS_RESOURCE_ID_KEY,
210
+ ): ResolvedTargetResolver<Desc> {
211
+ return (ctx) => {
212
+ const resourceId = ctx.get(idKey);
213
+ if (typeof resourceId !== "string" || resourceId === "") {
214
+ throw new Error(
215
+ `ListVersions: no resolved resource id under ${idKey}; the slug resolver must run first`,
216
+ );
217
+ }
218
+ return [
219
+ {
220
+ permission: IamPermission.can_view,
221
+ resourceKind: kind,
222
+ resourceId,
223
+ deniedMessage,
224
+ },
225
+ ];
226
+ };
227
+ }
228
+
195
229
  /** The fields every ListVersions input carries; the binding reads them off its own message. */
196
230
  export interface ListVersionsInputShape {
197
231
  readonly org: string;
@@ -1,37 +0,0 @@
1
- import type { Agent } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
2
- import type { Logger } from "../../boot/logger.js";
3
- import type { Store } from "../../store/interface.js";
4
- /** Marks the platform default agent; the value must be DEFAULT_AGENT_LABEL_VALUE. */
5
- export declare const DEFAULT_AGENT_LABEL = "stigmer.ai/default-agent";
6
- /** The only value of DEFAULT_AGENT_LABEL that marks an agent as the default. */
7
- export declare const DEFAULT_AGENT_LABEL_VALUE = "true";
8
- /**
9
- * No agent carries the default-agent label. Call sites map this to
10
- * NotFound with their own caller-facing copy (Go ErrNotConfigured).
11
- */
12
- export declare class DefaultAgentNotConfiguredError extends Error {
13
- constructor();
14
- }
15
- /**
16
- * Labeled agents exist but none is visibility_public. Call sites map this
17
- * to FailedPrecondition — a deliberate divergence from the cloud edition,
18
- * whose SQL predicate collapses this state into "not found": the distinct
19
- * code tells a self-hosting operator the label is present but the
20
- * visibility is wrong (Go ErrNotPublic).
21
- */
22
- export declare class DefaultAgentNotPublicError extends Error {
23
- constructor();
24
- }
25
- /**
26
- * Resolves the platform default agent per the module contract: candidates
27
- * are all agents labeled DEFAULT_AGENT_LABEL=true, only visibility_public
28
- * candidates are eligible, and among those the lowest metadata.id wins.
29
- *
30
- * Throws DefaultAgentNotConfiguredError when nothing carries the label,
31
- * DefaultAgentNotPublicError when labeled agents exist but none is public,
32
- * and lets store/decode failures propagate (a store failure is an internal
33
- * fault, not a "no default agent" condition — callers must not map it to
34
- * NotFound).
35
- */
36
- export declare function findDefaultAgent(store: Store, logger: Logger): Promise<Agent>;
37
- //# sourceMappingURL=defaultagent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultagent.d.ts","sourceRoot":"","sources":["../../../src/domain/agent/defaultagent.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oDAAoD,CAAC;AAIhF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEtD,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAE9D,gFAAgF;AAChF,eAAO,MAAM,yBAAyB,SAAS,CAAC;AAEhD;;;GAGG;AACH,qBAAa,8BAA+B,SAAQ,KAAK;;CAOxD;AAED;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;;CAOpD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC,CAkDhB"}
@@ -1,104 +0,0 @@
1
- /**
2
- * Platform default-agent resolution — ports
3
- * pkg/domain/agent/defaultagent/defaultagent.go: the single resolution
4
- * implementation behind Agent.GetDefault, AgentExecution create (#17), and
5
- * Session create.
6
- *
7
- * The default agent is a platform-level singleton: the agent labeled
8
- * stigmer.ai/default-agent: "true" with visibility_public, seeded in the
9
- * system org and served to callers of every org. Resolution is deliberately
10
- * GLOBAL — GetDefaultAgentRequest.org exists for authorization scoping only
11
- * (see apis/ai/stigmer/agentic/agent/v1/io.proto). It powers the
12
- * session-first UX where a user starts a conversation without picking an
13
- * agent. The cloud twin is AgentRepo.findDefault(); keep the two in sync.
14
- *
15
- * Determinism contract (stigmer/stigmer#356): multiple labeled agents is a
16
- * reachable state, not an error — safe label rotation applies the new
17
- * default before retiring the old one. Among public candidates the winner
18
- * is the one with the LOWEST metadata.id — the incumbent. Rejected
19
- * alternatives (recorded in the Go package doc): first-match depends on row
20
- * insertion order; newest-wins lets any newly labeled public agent capture
21
- * the platform-wide default (nothing guards the reserved stigmer.ai/*
22
- * namespace at OSS write boundaries); creation time is not trustworthy as
23
- * an ordering key (pre-#453 rows may carry rewritten timestamps).
24
- * metadata.id never changes and is time-ordered for server-generated ULIDs.
25
- */
26
- import { fromBinary } from "@bufbuild/protobuf";
27
- import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
28
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
29
- import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
30
- /** Marks the platform default agent; the value must be DEFAULT_AGENT_LABEL_VALUE. */
31
- export const DEFAULT_AGENT_LABEL = "stigmer.ai/default-agent";
32
- /** The only value of DEFAULT_AGENT_LABEL that marks an agent as the default. */
33
- export const DEFAULT_AGENT_LABEL_VALUE = "true";
34
- /**
35
- * No agent carries the default-agent label. Call sites map this to
36
- * NotFound with their own caller-facing copy (Go ErrNotConfigured).
37
- */
38
- export class DefaultAgentNotConfiguredError extends Error {
39
- constructor() {
40
- super(`no agent labeled ${DEFAULT_AGENT_LABEL}=${DEFAULT_AGENT_LABEL_VALUE}`);
41
- this.name = "DefaultAgentNotConfiguredError";
42
- }
43
- }
44
- /**
45
- * Labeled agents exist but none is visibility_public. Call sites map this
46
- * to FailedPrecondition — a deliberate divergence from the cloud edition,
47
- * whose SQL predicate collapses this state into "not found": the distinct
48
- * code tells a self-hosting operator the label is present but the
49
- * visibility is wrong (Go ErrNotPublic).
50
- */
51
- export class DefaultAgentNotPublicError extends Error {
52
- constructor() {
53
- super(`agents labeled ${DEFAULT_AGENT_LABEL}=${DEFAULT_AGENT_LABEL_VALUE} exist but none is visibility_public`);
54
- this.name = "DefaultAgentNotPublicError";
55
- }
56
- }
57
- /**
58
- * Resolves the platform default agent per the module contract: candidates
59
- * are all agents labeled DEFAULT_AGENT_LABEL=true, only visibility_public
60
- * candidates are eligible, and among those the lowest metadata.id wins.
61
- *
62
- * Throws DefaultAgentNotConfiguredError when nothing carries the label,
63
- * DefaultAgentNotPublicError when labeled agents exist but none is public,
64
- * and lets store/decode failures propagate (a store failure is an internal
65
- * fault, not a "no default agent" condition — callers must not map it to
66
- * NotFound).
67
- */
68
- export async function findDefaultAgent(store, logger) {
69
- const raws = await store.findAllByLabel(ApiResourceKind.agent, DEFAULT_AGENT_LABEL, DEFAULT_AGENT_LABEL_VALUE, AgentSchema);
70
- if (raws.length === 0) {
71
- throw new DefaultAgentNotConfiguredError();
72
- }
73
- let publicCount = 0;
74
- let winner;
75
- for (const raw of raws) {
76
- // findAllByLabel already unmarshaled every returned row to match the
77
- // label, so a decode failure here is store corruption. Fail loudly
78
- // (propagate): skipping a row could silently change which agent wins.
79
- const candidate = fromBinary(AgentSchema, raw);
80
- if (candidate.metadata?.visibility !==
81
- ApiResourceVisibility.visibility_public) {
82
- continue;
83
- }
84
- publicCount++;
85
- if (winner === undefined ||
86
- (candidate.metadata?.id ?? "") < (winner.metadata?.id ?? "")) {
87
- winner = candidate;
88
- }
89
- }
90
- if (winner === undefined) {
91
- throw new DefaultAgentNotPublicError();
92
- }
93
- if (publicCount > 1) {
94
- // Expected briefly mid-rotation; persistent duplicates mean someone
95
- // forgot to retire the old label after applying the new default.
96
- logger.warn("Multiple public agents carry the default-agent label; serving the incumbent (lowest id). Retire the stale label to complete rotation.", {
97
- publicLabeledAgents: publicCount,
98
- winnerId: winner.metadata?.id ?? "",
99
- winnerName: winner.metadata?.name ?? "",
100
- });
101
- }
102
- return winner;
103
- }
104
- //# sourceMappingURL=defaultagent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaultagent.js","sourceRoot":"","sources":["../../../src/domain/agent/defaultagent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,oDAAoD,CAAC;AAEjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wDAAwD,CAAC;AAC/F,OAAO,EAAE,eAAe,EAAE,MAAM,qFAAqF,CAAC;AAKtH,qFAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAE9D,gFAAgF;AAChF,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC;AAEhD;;;GAGG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD;QACE,KAAK,CACH,oBAAoB,mBAAmB,IAAI,yBAAyB,EAAE,CACvE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC/C,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD;QACE,KAAK,CACH,kBAAkB,mBAAmB,IAAI,yBAAyB,sCAAsC,CACzG,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,KAAY,EACZ,MAAc;IAEd,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,cAAc,CACrC,eAAe,CAAC,KAAK,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,WAAW,CACZ,CAAC;IACF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,8BAA8B,EAAE,CAAC;IAC7C,CAAC;IAED,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,MAAyB,CAAC;IAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,qEAAqE;QACrE,mEAAmE;QACnE,sEAAsE;QACtE,MAAM,SAAS,GAAG,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;QAC/C,IACE,SAAS,CAAC,QAAQ,EAAE,UAAU;YAC9B,qBAAqB,CAAC,iBAAiB,EACvC,CAAC;YACD,SAAS;QACX,CAAC;QACD,WAAW,EAAE,CAAC;QACd,IACE,MAAM,KAAK,SAAS;YACpB,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,EAC5D,CAAC;YACD,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC;IACH,CAAC;IACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,0BAA0B,EAAE,CAAC;IACzC,CAAC;IAED,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QACpB,oEAAoE;QACpE,iEAAiE;QACjE,MAAM,CAAC,IAAI,CACT,uIAAuI,EACvI;YACE,mBAAmB,EAAE,WAAW;YAChC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE;YACnC,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE;SACxC,CACF,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,135 +0,0 @@
1
- /**
2
- * Platform default-agent resolution — ports
3
- * pkg/domain/agent/defaultagent/defaultagent.go: the single resolution
4
- * implementation behind Agent.GetDefault, AgentExecution create (#17), and
5
- * Session create.
6
- *
7
- * The default agent is a platform-level singleton: the agent labeled
8
- * stigmer.ai/default-agent: "true" with visibility_public, seeded in the
9
- * system org and served to callers of every org. Resolution is deliberately
10
- * GLOBAL — GetDefaultAgentRequest.org exists for authorization scoping only
11
- * (see apis/ai/stigmer/agentic/agent/v1/io.proto). It powers the
12
- * session-first UX where a user starts a conversation without picking an
13
- * agent. The cloud twin is AgentRepo.findDefault(); keep the two in sync.
14
- *
15
- * Determinism contract (stigmer/stigmer#356): multiple labeled agents is a
16
- * reachable state, not an error — safe label rotation applies the new
17
- * default before retiring the old one. Among public candidates the winner
18
- * is the one with the LOWEST metadata.id — the incumbent. Rejected
19
- * alternatives (recorded in the Go package doc): first-match depends on row
20
- * insertion order; newest-wins lets any newly labeled public agent capture
21
- * the platform-wide default (nothing guards the reserved stigmer.ai/*
22
- * namespace at OSS write boundaries); creation time is not trustworthy as
23
- * an ordering key (pre-#453 rows may carry rewritten timestamps).
24
- * metadata.id never changes and is time-ordered for server-generated ULIDs.
25
- */
26
- import { fromBinary } from "@bufbuild/protobuf";
27
-
28
- import { AgentSchema } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
29
- import type { Agent } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
30
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
31
- import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
32
-
33
- import type { Logger } from "../../boot/logger.js";
34
- import type { Store } from "../../store/interface.js";
35
-
36
- /** Marks the platform default agent; the value must be DEFAULT_AGENT_LABEL_VALUE. */
37
- export const DEFAULT_AGENT_LABEL = "stigmer.ai/default-agent";
38
-
39
- /** The only value of DEFAULT_AGENT_LABEL that marks an agent as the default. */
40
- export const DEFAULT_AGENT_LABEL_VALUE = "true";
41
-
42
- /**
43
- * No agent carries the default-agent label. Call sites map this to
44
- * NotFound with their own caller-facing copy (Go ErrNotConfigured).
45
- */
46
- export class DefaultAgentNotConfiguredError extends Error {
47
- constructor() {
48
- super(
49
- `no agent labeled ${DEFAULT_AGENT_LABEL}=${DEFAULT_AGENT_LABEL_VALUE}`,
50
- );
51
- this.name = "DefaultAgentNotConfiguredError";
52
- }
53
- }
54
-
55
- /**
56
- * Labeled agents exist but none is visibility_public. Call sites map this
57
- * to FailedPrecondition — a deliberate divergence from the cloud edition,
58
- * whose SQL predicate collapses this state into "not found": the distinct
59
- * code tells a self-hosting operator the label is present but the
60
- * visibility is wrong (Go ErrNotPublic).
61
- */
62
- export class DefaultAgentNotPublicError extends Error {
63
- constructor() {
64
- super(
65
- `agents labeled ${DEFAULT_AGENT_LABEL}=${DEFAULT_AGENT_LABEL_VALUE} exist but none is visibility_public`,
66
- );
67
- this.name = "DefaultAgentNotPublicError";
68
- }
69
- }
70
-
71
- /**
72
- * Resolves the platform default agent per the module contract: candidates
73
- * are all agents labeled DEFAULT_AGENT_LABEL=true, only visibility_public
74
- * candidates are eligible, and among those the lowest metadata.id wins.
75
- *
76
- * Throws DefaultAgentNotConfiguredError when nothing carries the label,
77
- * DefaultAgentNotPublicError when labeled agents exist but none is public,
78
- * and lets store/decode failures propagate (a store failure is an internal
79
- * fault, not a "no default agent" condition — callers must not map it to
80
- * NotFound).
81
- */
82
- export async function findDefaultAgent(
83
- store: Store,
84
- logger: Logger,
85
- ): Promise<Agent> {
86
- const raws = await store.findAllByLabel(
87
- ApiResourceKind.agent,
88
- DEFAULT_AGENT_LABEL,
89
- DEFAULT_AGENT_LABEL_VALUE,
90
- AgentSchema,
91
- );
92
- if (raws.length === 0) {
93
- throw new DefaultAgentNotConfiguredError();
94
- }
95
-
96
- let publicCount = 0;
97
- let winner: Agent | undefined;
98
- for (const raw of raws) {
99
- // findAllByLabel already unmarshaled every returned row to match the
100
- // label, so a decode failure here is store corruption. Fail loudly
101
- // (propagate): skipping a row could silently change which agent wins.
102
- const candidate = fromBinary(AgentSchema, raw);
103
- if (
104
- candidate.metadata?.visibility !==
105
- ApiResourceVisibility.visibility_public
106
- ) {
107
- continue;
108
- }
109
- publicCount++;
110
- if (
111
- winner === undefined ||
112
- (candidate.metadata?.id ?? "") < (winner.metadata?.id ?? "")
113
- ) {
114
- winner = candidate;
115
- }
116
- }
117
- if (winner === undefined) {
118
- throw new DefaultAgentNotPublicError();
119
- }
120
-
121
- if (publicCount > 1) {
122
- // Expected briefly mid-rotation; persistent duplicates mean someone
123
- // forgot to retire the old label after applying the new default.
124
- logger.warn(
125
- "Multiple public agents carry the default-agent label; serving the incumbent (lowest id). Retire the stale label to complete rotation.",
126
- {
127
- publicLabeledAgents: publicCount,
128
- winnerId: winner.metadata?.id ?? "",
129
- winnerName: winner.metadata?.name ?? "",
130
- },
131
- );
132
- }
133
-
134
- return winner;
135
- }