@stigmer/server 3.20.0 → 3.21.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 (90) hide show
  1. package/dist/boot/compose.d.ts.map +1 -1
  2. package/dist/boot/compose.js +0 -1
  3. package/dist/boot/compose.js.map +1 -1
  4. package/dist/boot/inprocess.d.ts +0 -2
  5. package/dist/boot/inprocess.d.ts.map +1 -1
  6. package/dist/boot/inprocess.js +0 -6
  7. package/dist/boot/inprocess.js.map +1 -1
  8. package/dist/domain/agent/controller.d.ts +2 -2
  9. package/dist/domain/agent/controller.d.ts.map +1 -1
  10. package/dist/domain/agent/controller.js +1 -17
  11. package/dist/domain/agent/controller.js.map +1 -1
  12. package/dist/domain/agent/steps.d.ts +0 -1
  13. package/dist/domain/agent/steps.d.ts.map +1 -1
  14. package/dist/domain/agent/steps.js +1 -40
  15. package/dist/domain/agent/steps.js.map +1 -1
  16. package/dist/domain/agentexecution/controller.d.ts.map +1 -1
  17. package/dist/domain/agentexecution/controller.js +7 -9
  18. package/dist/domain/agentexecution/controller.js.map +1 -1
  19. package/dist/domain/agentexecution/create-execution-context-step.d.ts +0 -2
  20. package/dist/domain/agentexecution/create-execution-context-step.d.ts.map +1 -1
  21. package/dist/domain/agentexecution/create-execution-context-step.js +179 -60
  22. package/dist/domain/agentexecution/create-execution-context-step.js.map +1 -1
  23. package/dist/domain/agentexecution/create-steps.d.ts +16 -31
  24. package/dist/domain/agentexecution/create-steps.d.ts.map +1 -1
  25. package/dist/domain/agentexecution/create-steps.js +36 -102
  26. package/dist/domain/agentexecution/create-steps.js.map +1 -1
  27. package/dist/domain/agentexecution/run-target.d.ts +7 -3
  28. package/dist/domain/agentexecution/run-target.d.ts.map +1 -1
  29. package/dist/domain/agentexecution/run-target.js.map +1 -1
  30. package/dist/domain/environment/personal.d.ts +42 -0
  31. package/dist/domain/environment/personal.d.ts.map +1 -0
  32. package/dist/domain/environment/personal.js +96 -0
  33. package/dist/domain/environment/personal.js.map +1 -0
  34. package/dist/domain/mcpserver/connect.d.ts +0 -2
  35. package/dist/domain/mcpserver/connect.d.ts.map +1 -1
  36. package/dist/domain/mcpserver/connect.js +16 -72
  37. package/dist/domain/mcpserver/connect.js.map +1 -1
  38. package/dist/domain/plugin/overlay/sanitize.js +2 -2
  39. package/dist/domain/session/controller.d.ts +0 -7
  40. package/dist/domain/session/controller.d.ts.map +1 -1
  41. package/dist/domain/session/controller.js +11 -16
  42. package/dist/domain/session/controller.js.map +1 -1
  43. package/dist/domain/session/run-target.d.ts +9 -8
  44. package/dist/domain/session/run-target.d.ts.map +1 -1
  45. package/dist/domain/session/run-target.js.map +1 -1
  46. package/dist/domain/session/steps.d.ts +0 -27
  47. package/dist/domain/session/steps.d.ts.map +1 -1
  48. package/dist/domain/session/steps.js +10 -151
  49. package/dist/domain/session/steps.js.map +1 -1
  50. package/dist/domain/workflowexecution/create-steps.d.ts +4 -3
  51. package/dist/domain/workflowexecution/create-steps.d.ts.map +1 -1
  52. package/dist/domain/workflowexecution/create-steps.js +4 -3
  53. package/dist/domain/workflowexecution/create-steps.js.map +1 -1
  54. package/dist/pipeline/apiresource-labels.d.ts +2 -2
  55. package/dist/pipeline/apiresource-labels.js +2 -2
  56. package/dist/pipeline/errors.d.ts +2 -2
  57. package/dist/pipeline/errors.js +2 -2
  58. package/dist/pipeline/steps/guard-reserved-labels.d.ts.map +1 -1
  59. package/dist/pipeline/steps/guard-reserved-labels.js +6 -5
  60. package/dist/pipeline/steps/guard-reserved-labels.js.map +1 -1
  61. package/package.json +6 -6
  62. package/src/boot/compose.ts +0 -1
  63. package/src/boot/inprocess.ts +0 -9
  64. package/src/domain/agent/__tests__/agent.test.ts +0 -68
  65. package/src/domain/agent/controller.ts +3 -38
  66. package/src/domain/agent/steps.ts +1 -60
  67. package/src/domain/agentexecution/__tests__/create-execution-context-step.test.ts +216 -0
  68. package/src/domain/agentexecution/__tests__/create-steps.test.ts +70 -145
  69. package/src/domain/agentexecution/controller.ts +6 -10
  70. package/src/domain/agentexecution/create-execution-context-step.ts +271 -83
  71. package/src/domain/agentexecution/create-steps.ts +38 -138
  72. package/src/domain/agentexecution/run-target.ts +7 -3
  73. package/src/domain/environment/__tests__/personal.test.ts +143 -0
  74. package/src/domain/environment/personal.ts +141 -0
  75. package/src/domain/mcpserver/connect.ts +21 -82
  76. package/src/domain/plugin/overlay/sanitize.ts +2 -2
  77. package/src/domain/session/__tests__/run-gate.test.ts +19 -52
  78. package/src/domain/session/__tests__/session.test.ts +27 -203
  79. package/src/domain/session/controller.ts +10 -30
  80. package/src/domain/session/run-target.ts +9 -8
  81. package/src/domain/session/steps.ts +9 -235
  82. package/src/domain/workflowexecution/create-steps.ts +4 -3
  83. package/src/pipeline/apiresource-labels.ts +2 -2
  84. package/src/pipeline/errors.ts +2 -2
  85. package/src/pipeline/steps/guard-reserved-labels.ts +6 -5
  86. package/dist/domain/agent/defaultagent.d.ts +0 -37
  87. package/dist/domain/agent/defaultagent.d.ts.map +0 -1
  88. package/dist/domain/agent/defaultagent.js +0 -104
  89. package/dist/domain/agent/defaultagent.js.map +0 -1
  90. package/src/domain/agent/defaultagent.ts +0 -135
@@ -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
- }