@mastra/code-sdk 1.9.0 → 1.10.0-alpha.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 (50) hide show
  1. package/README.md +23 -0
  2. package/dist/agent-connections/tools.d.ts.map +1 -1
  3. package/dist/agent-connections/tools.js +5 -5
  4. package/dist/agent-connections/tools.js.map +1 -1
  5. package/dist/analytics.d.ts.map +1 -1
  6. package/dist/analytics.js +2 -3
  7. package/dist/analytics.js.map +1 -1
  8. package/dist/auth/account-rotation-processor.d.ts.map +1 -1
  9. package/dist/auth/account-rotation-processor.js +17 -10
  10. package/dist/auth/account-rotation-processor.js.map +1 -1
  11. package/dist/auth/providers/kimi-coding.d.ts.map +1 -1
  12. package/dist/auth/providers/kimi-coding.js +1 -2
  13. package/dist/auth/providers/kimi-coding.js.map +1 -1
  14. package/dist/auth/providers/openai-codex.d.ts +1 -1
  15. package/dist/auth/providers/openai-codex.d.ts.map +1 -1
  16. package/dist/auth/providers/openai-codex.js +7 -19
  17. package/dist/auth/providers/openai-codex.js.map +1 -1
  18. package/dist/auth/storage.js +3 -3
  19. package/dist/auth/storage.js.map +1 -1
  20. package/dist/experimental-agent.d.ts +11 -0
  21. package/dist/experimental-agent.d.ts.map +1 -0
  22. package/dist/experimental-agent.js +36 -0
  23. package/dist/experimental-agent.js.map +1 -0
  24. package/dist/goal-manager.d.ts.map +1 -1
  25. package/dist/goal-manager.js +3 -4
  26. package/dist/goal-manager.js.map +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +23 -7
  29. package/dist/index.js.map +1 -1
  30. package/dist/knowledge-inspector.d.ts.map +1 -1
  31. package/dist/knowledge-inspector.js +1 -2
  32. package/dist/knowledge-inspector.js.map +1 -1
  33. package/dist/onboarding/settings.d.ts +9 -0
  34. package/dist/onboarding/settings.d.ts.map +1 -1
  35. package/dist/onboarding/settings.js +36 -4
  36. package/dist/onboarding/settings.js.map +1 -1
  37. package/dist/plugins/loader.d.ts.map +1 -1
  38. package/dist/plugins/loader.js +1 -2
  39. package/dist/plugins/loader.js.map +1 -1
  40. package/dist/process-memory-diagnostics.d.ts.map +1 -1
  41. package/dist/process-memory-diagnostics.js +1 -2
  42. package/dist/process-memory-diagnostics.js.map +1 -1
  43. package/dist/tools/workflows/ephemeral-memory.d.ts +21 -0
  44. package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -1
  45. package/dist/tools/workflows/ephemeral-memory.js +1 -2
  46. package/dist/tools/workflows/ephemeral-memory.js.map +1 -1
  47. package/dist/utils/signals-pubsub.d.ts.map +1 -1
  48. package/dist/utils/signals-pubsub.js +1 -2
  49. package/dist/utils/signals-pubsub.js.map +1 -1
  50. package/package.json +11 -11
@@ -1 +1 @@
1
- {"version":3,"file":"goal-manager.js","names":[],"sources":["../src/goal-manager.ts"],"sourcesContent":["/**\n * GoalManager — persistent cross-turn goals, backed by the Agent's native goal\n * mechanism.\n *\n * The objective lives in the durable `threadState` `'goal'` slot (via\n * `agent.setObjective`/`getObjective`/`clearObjective`/`updateObjectiveOptions`)\n * and is judged in-loop by the core goal step. This manager is a thin adapter:\n * it keeps a synchronous in-memory view of the current objective for the TUI\n * (status line, modal, keyboard shortcuts) and delegates persistence to the\n * agent. There is no standalone judge agent and no between-turn re-invocation —\n * the core goal step drives continuation and surfaces progress via `goal` stream\n * chunks.\n */\nimport { randomUUID } from 'node:crypto';\nimport { getGoalActivityDurationMs } from '@mastra/core/agent';\nimport type { Agent } from '@mastra/core/agent';\nimport type { AgentController, Session } from '@mastra/core/agent-controller';\nimport type { GoalObjectiveRecord } from '@mastra/core/storage';\nimport { loadSettings } from './onboarding/settings.js';\n\nexport interface GoalManagerState<TState extends Record<string, unknown> = Record<string, unknown>> {\n controller: AgentController<TState>;\n session: Session<TState>;\n}\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type GoalStatus = 'active' | 'paused' | 'done';\n\n/**\n * TUI-facing view of a goal. Derived from the durable {@link GoalObjectiveRecord}\n * plus the effective judge/max-runs settings, with display-only timer fields and\n * a stable `id` used to match plan-started goals.\n */\nexport interface GoalState {\n id: string;\n objective: string;\n status: GoalStatus;\n turnsUsed: number;\n maxTurns: number;\n judgeModelId: string;\n startedAt: string;\n activeStartedAt?: string;\n activeDurationMs?: number;\n /** Why the goal paused (judge failure, budget exhaustion, ...). Only set while paused. */\n pausedReason?: string;\n}\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nexport const DEFAULT_MAX_TURNS = 50;\nconst THREAD_GOAL_KEY = 'goal';\n\nfunction normalizeActiveDurationMs(value: number | undefined): number {\n return value !== undefined && Number.isFinite(value) && value >= 0 ? value : 0;\n}\n\n// =============================================================================\n// GoalManager\n// =============================================================================\n\nexport class GoalManager {\n /** Synchronous in-memory view of the active objective record (source of truth is ThreadState). */\n private record: (GoalObjectiveRecord & { id: string }) | null = null;\n private threadId: string | undefined;\n private agentId: string | undefined;\n private persistGoalOnNextThreadCreate = false;\n /**\n * Set by {@link clear} to the thread the goal was cleared on: the next save\n * with an empty mirror on that same thread deletes the goal. A goal hydrated\n * from legacy metadata has no known thread, so its clear applies to whichever\n * thread the next save runs on (the pre-existing behaviour).\n */\n private pendingDelete: { threadId: string | undefined; goalId?: string } | null = null;\n\n // ---------------------------------------------------------------------------\n // Synchronous TUI surface\n // ---------------------------------------------------------------------------\n\n getGoal(): GoalState | null {\n if (!this.record) return null;\n const { judgeModelId, maxTurns } = this.effectiveSettings(this.record);\n return {\n id: this.record.id,\n objective: this.record.objective,\n status: this.record.status,\n turnsUsed: this.record.runsUsed,\n maxTurns,\n judgeModelId,\n startedAt: new Date(this.record.startedAt).toISOString(),\n ...(this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}),\n activeDurationMs:\n this.agentId && this.threadId\n ? getGoalActivityDurationMs({\n agentId: this.agentId,\n threadId: this.threadId,\n objectiveId: this.record.id,\n activeDurationMs: this.record.activeDurationMs,\n })\n : normalizeActiveDurationMs(this.record.activeDurationMs),\n };\n }\n\n isActive(): boolean {\n return this.record?.status === 'active';\n }\n\n persistOnNextThreadCreate(): void {\n this.persistGoalOnNextThreadCreate = true;\n }\n\n consumePersistOnNextThreadCreate(): boolean {\n if (!this.persistGoalOnNextThreadCreate) return false;\n this.persistGoalOnNextThreadCreate = false;\n return true;\n }\n\n // ---------------------------------------------------------------------------\n // Objective lifecycle (ThreadState-backed via the agent)\n // ---------------------------------------------------------------------------\n\n /**\n * Set a new objective. Persists to ThreadState via `agent.setObjective` and\n * updates the in-memory view. Only the provided settings are persisted into\n * the record; unset ones fall back to the agent's `goal` config at read time.\n */\n async setGoal(\n state: GoalManagerState,\n objective: string,\n judgeModelId: string,\n maxTurns: number = DEFAULT_MAX_TURNS,\n ): Promise<GoalState | null> {\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n const now = Date.now();\n const id = randomUUID();\n this.pendingDelete = null;\n this.threadId = threadId ?? undefined;\n this.agentId = agent?.id;\n\n if (agent && threadId) {\n const persisted = await agent.setObjective(objective, {\n id,\n threadId,\n resourceId: state.session.identity.getResourceId(),\n ...(judgeModelId ? { judgeModelId } : {}),\n maxRuns: maxTurns,\n });\n this.record = persisted\n ? { ...persisted, id: persisted.id ?? id }\n : this.localRecord(objective, judgeModelId, maxTurns, now, id);\n } else {\n this.record = this.localRecord(objective, judgeModelId, maxTurns, now, id);\n }\n\n return this.getGoal();\n }\n\n /**\n * Update the judge model / max-runs defaults. Persists into the active record\n * (so the override is remembered in thread state) when a goal is set.\n */\n async updateJudgeDefaults(\n state: GoalManagerState,\n judgeModelId: string,\n maxTurns: number,\n ): Promise<GoalState | null> {\n if (!this.record) return null;\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n if (agent && threadId) {\n const updated = await agent.updateObjectiveOptions({\n threadId,\n ...(judgeModelId ? { judgeModelId } : {}),\n maxRuns: maxTurns,\n });\n if (updated) this.record = { ...updated, id: this.record.id };\n } else {\n this.record = {\n ...this.record,\n ...(judgeModelId ? { judgeModelId } : {}),\n maxRuns: maxTurns,\n updatedAt: Date.now(),\n };\n }\n return this.getGoal();\n }\n\n pause(reason?: string): GoalState | null {\n if (this.record && this.record.status === 'active') {\n this.record = { ...this.record, status: 'paused', pausedReason: reason, updatedAt: Date.now() };\n }\n return this.getGoal();\n }\n\n resume(): GoalState | null {\n if (this.record && this.record.status === 'paused') {\n this.record = { ...this.record, status: 'active', pausedReason: undefined, updatedAt: Date.now() };\n }\n return this.getGoal();\n }\n\n markDone(): void {\n if (this.record) {\n this.record = { ...this.record, status: 'done', pausedReason: undefined, updatedAt: Date.now() };\n }\n }\n\n clear(): void {\n this.pendingDelete = { threadId: this.threadId, goalId: this.record?.id };\n this.record = null;\n this.threadId = undefined;\n this.agentId = undefined;\n this.persistGoalOnNextThreadCreate = false;\n }\n\n /**\n * Sync the latest objective record from ThreadState into the in-memory view.\n * Called from the `goal` stream-chunk handler after each evaluation.\n */\n applyEvaluation(update: { runsUsed: number; status: GoalStatus; pausedReason?: string }): GoalState | null {\n if (!this.record) return null;\n const pausedReason =\n update.status === 'paused'\n ? (update.pausedReason ?? (this.record.status === 'paused' ? this.record.pausedReason : undefined))\n : undefined;\n this.record = {\n ...this.record,\n runsUsed: update.runsUsed,\n status: update.status,\n // The cause lasts for one pause; leaving paused retires it.\n pausedReason,\n updatedAt: Date.now(),\n };\n return this.getGoal();\n }\n\n // ---------------------------------------------------------------------------\n // Persistence\n // ---------------------------------------------------------------------------\n\n /**\n * Persist the active objective to ThreadState via the agent. The objective\n * record is the source of truth; the legacy thread-metadata key is cleared on\n * a save that actually wrote, so stale state from older sessions cannot\n * shadow the record — and a save that wrote nothing leaves it alone.\n *\n * An empty in-memory mirror means \"I have nothing *loaded*\", which is not the\n * same statement as \"there is nothing\": the mirror is also emptied by storage\n * failures and thread switches. So a save with an empty mirror deletes the\n * goal (durable record and legacy key) only right after an explicit\n * {@link clear} on the same thread (or any thread, for a legacy-hydrated goal\n * whose thread is unknown), and is a complete no-op otherwise.\n */\n async saveToThread(state: GoalManagerState): Promise<void> {\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n if (!this.record && this.pendingDelete) {\n const clearedThreadId = this.pendingDelete.threadId;\n if (clearedThreadId === undefined || clearedThreadId === threadId) {\n await this.deleteFromThread(state);\n }\n return;\n }\n try {\n if (agent && threadId) {\n if (this.record) {\n // Push the current status/options into the existing record. If no\n // record is persisted yet (e.g. first save), create one.\n const updated = await agent.updateObjectiveOptions({\n threadId,\n status: this.record.status,\n ...(this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}),\n ...(this.record.judgeModelId ? { judgeModelId: this.record.judgeModelId } : {}),\n ...(this.record.maxRuns !== undefined ? { maxRuns: this.record.maxRuns } : {}),\n });\n if (!updated) {\n // No persisted record yet: create one. `setObjective` always writes\n // `status: 'active'`, so re-apply the in-memory status afterwards if\n // the local goal was already paused/done — otherwise the resumed\n // thread state would no longer match the in-memory state.\n const desiredStatus = this.record.status;\n const created = await agent.setObjective(this.record.objective, {\n id: this.record.id,\n threadId,\n resourceId: state.session.identity.getResourceId(),\n activeDurationMs: normalizeActiveDurationMs(this.record.activeDurationMs),\n ...(this.record.judgeModelId ? { judgeModelId: this.record.judgeModelId } : {}),\n ...(this.record.maxRuns !== undefined ? { maxRuns: this.record.maxRuns } : {}),\n });\n // Nothing durable was written (no goal store, or no thread), so\n // there is no record for a legacy key to shadow — and wiping it\n // would take a pre-migration thread's only copy with it.\n if (!created) return;\n if (desiredStatus !== 'active') {\n await agent.updateObjectiveOptions({\n threadId,\n status: desiredStatus,\n ...(this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}),\n });\n }\n }\n // Clear any legacy thread-metadata goal so it can't shadow the\n // record we just wrote. Only on the path that actually wrote: on the\n // no-op path a pre-migration thread's only goal may live in that key.\n await state.session.thread.setSetting({ key: THREAD_GOAL_KEY, value: undefined });\n }\n }\n } catch {\n // Persistence is not critical.\n }\n }\n\n /**\n * Remove the objective from the thread, whatever the in-memory mirror holds.\n *\n * The durable record needs an agent and a thread; the legacy thread-metadata\n * key does not, so it is wiped either way — unlike {@link saveToThread}, which\n * writes nothing with an empty mirror unless {@link clear} ran. That asymmetry is deliberate: a\n * pre-migration goal must not resurface from the legacy key after a clear.\n * Like the save, this is best-effort: a failed durable delete also skips the\n * legacy wipe. A pending {@link clear} stays pending until both writes\n * succeed, so a later save retries it; loading the thread retries it once\n * and then drops it. Resolves to whether the delete landed.\n */\n async deleteFromThread(state: GoalManagerState): Promise<boolean> {\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n try {\n if (agent && threadId) {\n await agent.clearObjective({ threadId });\n }\n await state.session.thread.setSetting({ key: THREAD_GOAL_KEY, value: undefined });\n this.pendingDelete = null;\n return true;\n } catch {\n // Persistence is not critical, but keep the retry scoped to the thread\n // this delete targeted so an empty save elsewhere cannot delete a goal.\n // An unknown thread would widen the retry to every thread, so keep the old scope then.\n if (threadId) this.pendingDelete = { threadId, goalId: this.pendingDelete?.goalId };\n return false;\n }\n }\n\n /**\n * Load the objective from ThreadState (called on thread switch). Falls back to\n * the legacy thread-metadata goal for threads created before this migration.\n *\n * A clear whose delete failed is retried here when it targeted this thread and\n * the stored goal is the one that was cleared; otherwise the stored goal loads,\n * so the mirror never hides a goal core is still judging. Resolves to whether\n * that retried delete landed.\n */\n async loadFromThread(state: GoalManagerState, isCurrent: () => boolean = () => true): Promise<boolean> {\n const pending = this.pendingDelete;\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n let nextRecord: typeof this.record = null;\n let storedId: string | undefined;\n if (agent && threadId) {\n try {\n const record = await agent.getObjective({ threadId });\n if (record) {\n storedId = record.id;\n nextRecord = {\n ...record,\n id: record.id ?? randomUUID(),\n activeDurationMs: normalizeActiveDurationMs(record.activeDurationMs),\n };\n }\n } catch {\n // fall through to legacy metadata\n }\n }\n if (!isCurrent()) return false;\n // A goal set or cleared during the read replaced this intent; keep the newer state.\n if (pending && this.pendingDelete !== pending) return false;\n let retriedDelete = false;\n if (pending?.goalId && pending.threadId === threadId && storedId === pending.goalId) {\n retriedDelete = await this.deleteFromThread(state);\n if (retriedDelete) nextRecord = null;\n if (!isCurrent()) return false;\n }\n this.persistGoalOnNextThreadCreate = false;\n this.pendingDelete = null;\n this.threadId = threadId ?? undefined;\n this.agentId = agent?.id;\n this.record = nextRecord;\n return retriedDelete;\n }\n\n /**\n * Legacy entry point retained for thread-switch call sites that only have the\n * thread metadata available. Hydrates from a previously-persisted GoalState.\n */\n loadFromThreadMetadata(metadata: Record<string, unknown> | undefined): void {\n const saved = metadata?.[THREAD_GOAL_KEY] as Partial<GoalState> | undefined;\n this.persistGoalOnNextThreadCreate = false;\n this.pendingDelete = null;\n this.threadId = undefined;\n this.agentId = undefined;\n if (saved && saved.objective && saved.status) {\n this.record = {\n objective: saved.objective,\n status: saved.status,\n runsUsed: saved.turnsUsed ?? 0,\n activeDurationMs: normalizeActiveDurationMs(saved.activeDurationMs),\n maxRuns: saved.maxTurns ?? DEFAULT_MAX_TURNS,\n judgeModelId: saved.judgeModelId ?? '',\n ...(saved.pausedReason ? { pausedReason: saved.pausedReason } : {}),\n startedAt: saved.startedAt ? Date.parse(saved.startedAt) || Date.now() : Date.now(),\n updatedAt: Date.now(),\n id: saved.id ?? randomUUID(),\n };\n } else {\n this.record = null;\n }\n }\n\n // ---------------------------------------------------------------------------\n // Private\n // ---------------------------------------------------------------------------\n\n private getAgent(state: GoalManagerState): Agent | undefined {\n try {\n return state.controller.getCurrentAgent(state.session);\n } catch {\n return undefined;\n }\n }\n\n /** Resolve effective judge model + max runs (record value → settings default). */\n private effectiveSettings(record: GoalObjectiveRecord): { judgeModelId: string; maxTurns: number } {\n const settings = loadSettings();\n return {\n judgeModelId: record.judgeModelId ?? settings.models.goalJudgeModel ?? '',\n maxTurns: record.maxRuns ?? settings.models.goalMaxTurns ?? DEFAULT_MAX_TURNS,\n };\n }\n\n private localRecord(\n objective: string,\n judgeModelId: string,\n maxTurns: number,\n now: number,\n id: string,\n ): GoalObjectiveRecord & { id: string } {\n return {\n objective,\n status: 'active',\n runsUsed: 0,\n activeDurationMs: 0,\n maxRuns: maxTurns,\n ...(judgeModelId ? { judgeModelId } : {}),\n startedAt: now,\n updatedAt: now,\n id,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsDA,MAAa,oBAAoB;AACjC,MAAM,kBAAkB;AAExB,SAAS,0BAA0B,OAAmC;CACpE,OAAO,UAAU,KAAA,KAAa,OAAO,SAAS,KAAK,KAAK,SAAS,IAAI,QAAQ;AAC/E;AAMA,IAAa,cAAb,MAAyB;;CAEvB,SAAgE;CAChE;CACA;CACA,gCAAwC;;;;;;;CAOxC,gBAAkF;CAMlF,UAA4B;EAC1B,IAAI,CAAC,KAAK,QAAQ,OAAO;EACzB,MAAM,EAAE,cAAc,aAAa,KAAK,kBAAkB,KAAK,MAAM;EACrE,OAAO;GACL,IAAI,KAAK,OAAO;GAChB,WAAW,KAAK,OAAO;GACvB,QAAQ,KAAK,OAAO;GACpB,WAAW,KAAK,OAAO;GACvB;GACA;GACA,WAAW,IAAI,KAAK,KAAK,OAAO,SAAS,CAAC,CAAC,YAAY;GACvD,GAAI,KAAK,OAAO,eAAe,EAAE,cAAc,KAAK,OAAO,aAAa,IAAI,CAAC;GAC7E,kBACE,KAAK,WAAW,KAAK,WACjB,0BAA0B;IACxB,SAAS,KAAK;IACd,UAAU,KAAK;IACf,aAAa,KAAK,OAAO;IACzB,kBAAkB,KAAK,OAAO;GAChC,CAAC,IACD,0BAA0B,KAAK,OAAO,gBAAgB;EAC9D;CACF;CAEA,WAAoB;EAClB,OAAO,KAAK,QAAQ,WAAW;CACjC;CAEA,4BAAkC;EAChC,KAAK,gCAAgC;CACvC;CAEA,mCAA4C;EAC1C,IAAI,CAAC,KAAK,+BAA+B,OAAO;EAChD,KAAK,gCAAgC;EACrC,OAAO;CACT;;;;;;CAWA,MAAM,QACJ,OACA,WACA,cACA,WAAA,IAC2B;EAC3B,MAAM,WAAW,MAAM,QAAQ,OAAO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,YAAA;GACf,cAAc,MAAM,gBAAgB;GACpC,GAAI,MAAM,eAAe,EAAE,cAAc,MAAM,aAAa,IAAI,CAAC;GACjE,WAAW,MAAM,YAAY,KAAK,MAAM,MAAM,SAAS,KAAK,KAAK,IAAI,IAAI,KAAK,IAAI;GAClF,WAAW,KAAK,IAAI;GACpB,IAAI,MAAM,MAAM,WAAW;EAC7B;OAEA,KAAK,SAAS;CAElB;CAMA,SAAiB,OAA4C;EAC3D,IAAI;GACF,OAAO,MAAM,WAAW,gBAAgB,MAAM,OAAO;EACvD,QAAQ;GACN;EACF;CACF;;CAGA,kBAA0B,QAAyE;EACjG,MAAM,WAAW,aAAa;EAC9B,OAAO;GACL,cAAc,OAAO,gBAAgB,SAAS,OAAO,kBAAkB;GACvE,UAAU,OAAO,WAAW,SAAS,OAAO,gBAAA;EAC9C;CACF;CAEA,YACE,WACA,cACA,UACA,KACA,IACsC;EACtC,OAAO;GACL;GACA,QAAQ;GACR,UAAU;GACV,kBAAkB;GAClB,SAAS;GACT,GAAI,eAAe,EAAE,aAAa,IAAI,CAAC;GACvC,WAAW;GACX,WAAW;GACX;EACF;CACF;AACF"}
1
+ {"version":3,"file":"goal-manager.js","names":[],"sources":["../src/goal-manager.ts"],"sourcesContent":["/**\n * GoalManager — persistent cross-turn goals, backed by the Agent's native goal\n * mechanism.\n *\n * The objective lives in the durable `threadState` `'goal'` slot (via\n * `agent.setObjective`/`getObjective`/`clearObjective`/`updateObjectiveOptions`)\n * and is judged in-loop by the core goal step. This manager is a thin adapter:\n * it keeps a synchronous in-memory view of the current objective for the TUI\n * (status line, modal, keyboard shortcuts) and delegates persistence to the\n * agent. There is no standalone judge agent and no between-turn re-invocation —\n * the core goal step drives continuation and surfaces progress via `goal` stream\n * chunks.\n */\nimport { getGoalActivityDurationMs } from '@mastra/core/agent';\nimport type { Agent } from '@mastra/core/agent';\nimport type { AgentController, Session } from '@mastra/core/agent-controller';\nimport type { GoalObjectiveRecord } from '@mastra/core/storage';\nimport { loadSettings } from './onboarding/settings.js';\n\nexport interface GoalManagerState<TState extends Record<string, unknown> = Record<string, unknown>> {\n controller: AgentController<TState>;\n session: Session<TState>;\n}\n\n// =============================================================================\n// Types\n// =============================================================================\n\nexport type GoalStatus = 'active' | 'paused' | 'done';\n\n/**\n * TUI-facing view of a goal. Derived from the durable {@link GoalObjectiveRecord}\n * plus the effective judge/max-runs settings, with display-only timer fields and\n * a stable `id` used to match plan-started goals.\n */\nexport interface GoalState {\n id: string;\n objective: string;\n status: GoalStatus;\n turnsUsed: number;\n maxTurns: number;\n judgeModelId: string;\n startedAt: string;\n activeStartedAt?: string;\n activeDurationMs?: number;\n /** Why the goal paused (judge failure, budget exhaustion, ...). Only set while paused. */\n pausedReason?: string;\n}\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nexport const DEFAULT_MAX_TURNS = 50;\nconst THREAD_GOAL_KEY = 'goal';\n\nfunction normalizeActiveDurationMs(value: number | undefined): number {\n return value !== undefined && Number.isFinite(value) && value >= 0 ? value : 0;\n}\n\n// =============================================================================\n// GoalManager\n// =============================================================================\n\nexport class GoalManager {\n /** Synchronous in-memory view of the active objective record (source of truth is ThreadState). */\n private record: (GoalObjectiveRecord & { id: string }) | null = null;\n private threadId: string | undefined;\n private agentId: string | undefined;\n private persistGoalOnNextThreadCreate = false;\n /**\n * Set by {@link clear} to the thread the goal was cleared on: the next save\n * with an empty mirror on that same thread deletes the goal. A goal hydrated\n * from legacy metadata has no known thread, so its clear applies to whichever\n * thread the next save runs on (the pre-existing behaviour).\n */\n private pendingDelete: { threadId: string | undefined; goalId?: string } | null = null;\n\n // ---------------------------------------------------------------------------\n // Synchronous TUI surface\n // ---------------------------------------------------------------------------\n\n getGoal(): GoalState | null {\n if (!this.record) return null;\n const { judgeModelId, maxTurns } = this.effectiveSettings(this.record);\n return {\n id: this.record.id,\n objective: this.record.objective,\n status: this.record.status,\n turnsUsed: this.record.runsUsed,\n maxTurns,\n judgeModelId,\n startedAt: new Date(this.record.startedAt).toISOString(),\n ...(this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}),\n activeDurationMs:\n this.agentId && this.threadId\n ? getGoalActivityDurationMs({\n agentId: this.agentId,\n threadId: this.threadId,\n objectiveId: this.record.id,\n activeDurationMs: this.record.activeDurationMs,\n })\n : normalizeActiveDurationMs(this.record.activeDurationMs),\n };\n }\n\n isActive(): boolean {\n return this.record?.status === 'active';\n }\n\n persistOnNextThreadCreate(): void {\n this.persistGoalOnNextThreadCreate = true;\n }\n\n consumePersistOnNextThreadCreate(): boolean {\n if (!this.persistGoalOnNextThreadCreate) return false;\n this.persistGoalOnNextThreadCreate = false;\n return true;\n }\n\n // ---------------------------------------------------------------------------\n // Objective lifecycle (ThreadState-backed via the agent)\n // ---------------------------------------------------------------------------\n\n /**\n * Set a new objective. Persists to ThreadState via `agent.setObjective` and\n * updates the in-memory view. Only the provided settings are persisted into\n * the record; unset ones fall back to the agent's `goal` config at read time.\n */\n async setGoal(\n state: GoalManagerState,\n objective: string,\n judgeModelId: string,\n maxTurns: number = DEFAULT_MAX_TURNS,\n ): Promise<GoalState | null> {\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n const now = Date.now();\n const id = globalThis.crypto.randomUUID();\n this.pendingDelete = null;\n this.threadId = threadId ?? undefined;\n this.agentId = agent?.id;\n\n if (agent && threadId) {\n const persisted = await agent.setObjective(objective, {\n id,\n threadId,\n resourceId: state.session.identity.getResourceId(),\n ...(judgeModelId ? { judgeModelId } : {}),\n maxRuns: maxTurns,\n });\n this.record = persisted\n ? { ...persisted, id: persisted.id ?? id }\n : this.localRecord(objective, judgeModelId, maxTurns, now, id);\n } else {\n this.record = this.localRecord(objective, judgeModelId, maxTurns, now, id);\n }\n\n return this.getGoal();\n }\n\n /**\n * Update the judge model / max-runs defaults. Persists into the active record\n * (so the override is remembered in thread state) when a goal is set.\n */\n async updateJudgeDefaults(\n state: GoalManagerState,\n judgeModelId: string,\n maxTurns: number,\n ): Promise<GoalState | null> {\n if (!this.record) return null;\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n if (agent && threadId) {\n const updated = await agent.updateObjectiveOptions({\n threadId,\n ...(judgeModelId ? { judgeModelId } : {}),\n maxRuns: maxTurns,\n });\n if (updated) this.record = { ...updated, id: this.record.id };\n } else {\n this.record = {\n ...this.record,\n ...(judgeModelId ? { judgeModelId } : {}),\n maxRuns: maxTurns,\n updatedAt: Date.now(),\n };\n }\n return this.getGoal();\n }\n\n pause(reason?: string): GoalState | null {\n if (this.record && this.record.status === 'active') {\n this.record = { ...this.record, status: 'paused', pausedReason: reason, updatedAt: Date.now() };\n }\n return this.getGoal();\n }\n\n resume(): GoalState | null {\n if (this.record && this.record.status === 'paused') {\n this.record = { ...this.record, status: 'active', pausedReason: undefined, updatedAt: Date.now() };\n }\n return this.getGoal();\n }\n\n markDone(): void {\n if (this.record) {\n this.record = { ...this.record, status: 'done', pausedReason: undefined, updatedAt: Date.now() };\n }\n }\n\n clear(): void {\n this.pendingDelete = { threadId: this.threadId, goalId: this.record?.id };\n this.record = null;\n this.threadId = undefined;\n this.agentId = undefined;\n this.persistGoalOnNextThreadCreate = false;\n }\n\n /**\n * Sync the latest objective record from ThreadState into the in-memory view.\n * Called from the `goal` stream-chunk handler after each evaluation.\n */\n applyEvaluation(update: { runsUsed: number; status: GoalStatus; pausedReason?: string }): GoalState | null {\n if (!this.record) return null;\n const pausedReason =\n update.status === 'paused'\n ? (update.pausedReason ?? (this.record.status === 'paused' ? this.record.pausedReason : undefined))\n : undefined;\n this.record = {\n ...this.record,\n runsUsed: update.runsUsed,\n status: update.status,\n // The cause lasts for one pause; leaving paused retires it.\n pausedReason,\n updatedAt: Date.now(),\n };\n return this.getGoal();\n }\n\n // ---------------------------------------------------------------------------\n // Persistence\n // ---------------------------------------------------------------------------\n\n /**\n * Persist the active objective to ThreadState via the agent. The objective\n * record is the source of truth; the legacy thread-metadata key is cleared on\n * a save that actually wrote, so stale state from older sessions cannot\n * shadow the record — and a save that wrote nothing leaves it alone.\n *\n * An empty in-memory mirror means \"I have nothing *loaded*\", which is not the\n * same statement as \"there is nothing\": the mirror is also emptied by storage\n * failures and thread switches. So a save with an empty mirror deletes the\n * goal (durable record and legacy key) only right after an explicit\n * {@link clear} on the same thread (or any thread, for a legacy-hydrated goal\n * whose thread is unknown), and is a complete no-op otherwise.\n */\n async saveToThread(state: GoalManagerState): Promise<void> {\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n if (!this.record && this.pendingDelete) {\n const clearedThreadId = this.pendingDelete.threadId;\n if (clearedThreadId === undefined || clearedThreadId === threadId) {\n await this.deleteFromThread(state);\n }\n return;\n }\n try {\n if (agent && threadId) {\n if (this.record) {\n // Push the current status/options into the existing record. If no\n // record is persisted yet (e.g. first save), create one.\n const updated = await agent.updateObjectiveOptions({\n threadId,\n status: this.record.status,\n ...(this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}),\n ...(this.record.judgeModelId ? { judgeModelId: this.record.judgeModelId } : {}),\n ...(this.record.maxRuns !== undefined ? { maxRuns: this.record.maxRuns } : {}),\n });\n if (!updated) {\n // No persisted record yet: create one. `setObjective` always writes\n // `status: 'active'`, so re-apply the in-memory status afterwards if\n // the local goal was already paused/done — otherwise the resumed\n // thread state would no longer match the in-memory state.\n const desiredStatus = this.record.status;\n const created = await agent.setObjective(this.record.objective, {\n id: this.record.id,\n threadId,\n resourceId: state.session.identity.getResourceId(),\n activeDurationMs: normalizeActiveDurationMs(this.record.activeDurationMs),\n ...(this.record.judgeModelId ? { judgeModelId: this.record.judgeModelId } : {}),\n ...(this.record.maxRuns !== undefined ? { maxRuns: this.record.maxRuns } : {}),\n });\n // Nothing durable was written (no goal store, or no thread), so\n // there is no record for a legacy key to shadow — and wiping it\n // would take a pre-migration thread's only copy with it.\n if (!created) return;\n if (desiredStatus !== 'active') {\n await agent.updateObjectiveOptions({\n threadId,\n status: desiredStatus,\n ...(this.record.pausedReason ? { pausedReason: this.record.pausedReason } : {}),\n });\n }\n }\n // Clear any legacy thread-metadata goal so it can't shadow the\n // record we just wrote. Only on the path that actually wrote: on the\n // no-op path a pre-migration thread's only goal may live in that key.\n await state.session.thread.setSetting({ key: THREAD_GOAL_KEY, value: undefined });\n }\n }\n } catch {\n // Persistence is not critical.\n }\n }\n\n /**\n * Remove the objective from the thread, whatever the in-memory mirror holds.\n *\n * The durable record needs an agent and a thread; the legacy thread-metadata\n * key does not, so it is wiped either way — unlike {@link saveToThread}, which\n * writes nothing with an empty mirror unless {@link clear} ran. That asymmetry is deliberate: a\n * pre-migration goal must not resurface from the legacy key after a clear.\n * Like the save, this is best-effort: a failed durable delete also skips the\n * legacy wipe. A pending {@link clear} stays pending until both writes\n * succeed, so a later save retries it; loading the thread retries it once\n * and then drops it. Resolves to whether the delete landed.\n */\n async deleteFromThread(state: GoalManagerState): Promise<boolean> {\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n try {\n if (agent && threadId) {\n await agent.clearObjective({ threadId });\n }\n await state.session.thread.setSetting({ key: THREAD_GOAL_KEY, value: undefined });\n this.pendingDelete = null;\n return true;\n } catch {\n // Persistence is not critical, but keep the retry scoped to the thread\n // this delete targeted so an empty save elsewhere cannot delete a goal.\n // An unknown thread would widen the retry to every thread, so keep the old scope then.\n if (threadId) this.pendingDelete = { threadId, goalId: this.pendingDelete?.goalId };\n return false;\n }\n }\n\n /**\n * Load the objective from ThreadState (called on thread switch). Falls back to\n * the legacy thread-metadata goal for threads created before this migration.\n *\n * A clear whose delete failed is retried here when it targeted this thread and\n * the stored goal is the one that was cleared; otherwise the stored goal loads,\n * so the mirror never hides a goal core is still judging. Resolves to whether\n * that retried delete landed.\n */\n async loadFromThread(state: GoalManagerState, isCurrent: () => boolean = () => true): Promise<boolean> {\n const pending = this.pendingDelete;\n const threadId = state.session.thread.getId();\n const agent = this.getAgent(state);\n let nextRecord: typeof this.record = null;\n let storedId: string | undefined;\n if (agent && threadId) {\n try {\n const record = await agent.getObjective({ threadId });\n if (record) {\n storedId = record.id;\n nextRecord = {\n ...record,\n id: record.id ?? globalThis.crypto.randomUUID(),\n activeDurationMs: normalizeActiveDurationMs(record.activeDurationMs),\n };\n }\n } catch {\n // fall through to legacy metadata\n }\n }\n if (!isCurrent()) return false;\n // A goal set or cleared during the read replaced this intent; keep the newer state.\n if (pending && this.pendingDelete !== pending) return false;\n let retriedDelete = false;\n if (pending?.goalId && pending.threadId === threadId && storedId === pending.goalId) {\n retriedDelete = await this.deleteFromThread(state);\n if (retriedDelete) nextRecord = null;\n if (!isCurrent()) return false;\n }\n this.persistGoalOnNextThreadCreate = false;\n this.pendingDelete = null;\n this.threadId = threadId ?? undefined;\n this.agentId = agent?.id;\n this.record = nextRecord;\n return retriedDelete;\n }\n\n /**\n * Legacy entry point retained for thread-switch call sites that only have the\n * thread metadata available. Hydrates from a previously-persisted GoalState.\n */\n loadFromThreadMetadata(metadata: Record<string, unknown> | undefined): void {\n const saved = metadata?.[THREAD_GOAL_KEY] as Partial<GoalState> | undefined;\n this.persistGoalOnNextThreadCreate = false;\n this.pendingDelete = null;\n this.threadId = undefined;\n this.agentId = undefined;\n if (saved && saved.objective && saved.status) {\n this.record = {\n objective: saved.objective,\n status: saved.status,\n runsUsed: saved.turnsUsed ?? 0,\n activeDurationMs: normalizeActiveDurationMs(saved.activeDurationMs),\n maxRuns: saved.maxTurns ?? DEFAULT_MAX_TURNS,\n judgeModelId: saved.judgeModelId ?? '',\n ...(saved.pausedReason ? { pausedReason: saved.pausedReason } : {}),\n startedAt: saved.startedAt ? Date.parse(saved.startedAt) || Date.now() : Date.now(),\n updatedAt: Date.now(),\n id: saved.id ?? globalThis.crypto.randomUUID(),\n };\n } else {\n this.record = null;\n }\n }\n\n // ---------------------------------------------------------------------------\n // Private\n // ---------------------------------------------------------------------------\n\n private getAgent(state: GoalManagerState): Agent | undefined {\n try {\n return state.controller.getCurrentAgent(state.session);\n } catch {\n return undefined;\n }\n }\n\n /** Resolve effective judge model + max runs (record value → settings default). */\n private effectiveSettings(record: GoalObjectiveRecord): { judgeModelId: string; maxTurns: number } {\n const settings = loadSettings();\n return {\n judgeModelId: record.judgeModelId ?? settings.models.goalJudgeModel ?? '',\n maxTurns: record.maxRuns ?? settings.models.goalMaxTurns ?? DEFAULT_MAX_TURNS,\n };\n }\n\n private localRecord(\n objective: string,\n judgeModelId: string,\n maxTurns: number,\n now: number,\n id: string,\n ): GoalObjectiveRecord & { id: string } {\n return {\n objective,\n status: 'active',\n runsUsed: 0,\n activeDurationMs: 0,\n maxRuns: maxTurns,\n ...(judgeModelId ? { judgeModelId } : {}),\n startedAt: now,\n updatedAt: now,\n id,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqDA,MAAa,oBAAoB;AACjC,MAAM,kBAAkB;AAExB,SAAS,0BAA0B,OAAmC;CACpE,OAAO,UAAU,KAAA,KAAa,OAAO,SAAS,KAAK,KAAK,SAAS,IAAI,QAAQ;AAC/E;AAMA,IAAa,cAAb,MAAyB;;CAEvB,SAAgE;CAChE;CACA;CACA,gCAAwC;;;;;;;CAOxC,gBAAkF;CAMlF,UAA4B;EAC1B,IAAI,CAAC,KAAK,QAAQ,OAAO;EACzB,MAAM,EAAE,cAAc,aAAa,KAAK,kBAAkB,KAAK,MAAM;EACrE,OAAO;GACL,IAAI,KAAK,OAAO;GAChB,WAAW,KAAK,OAAO;GACvB,QAAQ,KAAK,OAAO;GACpB,WAAW,KAAK,OAAO;GACvB;GACA;GACA,WAAW,IAAI,KAAK,KAAK,OAAO,SAAS,CAAC,CAAC,YAAY;GACvD,GAAI,KAAK,OAAO,eAAe,EAAE,cAAc,KAAK,OAAO,aAAa,IAAI,CAAC;GAC7E,kBACE,KAAK,WAAW,KAAK,WACjB,0BAA0B;IACxB,SAAS,KAAK;IACd,UAAU,KAAK;IACf,aAAa,KAAK,OAAO;IACzB,kBAAkB,KAAK,OAAO;GAChC,CAAC,IACD,0BAA0B,KAAK,OAAO,gBAAgB;EAC9D;CACF;CAEA,WAAoB;EAClB,OAAO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js CHANGED
@@ -5,6 +5,7 @@ import { AuthStorage } from "./auth/storage.js";
5
5
  import { setAuthStorage } from "./providers/openai-codex.js";
6
6
  import { getAvailableModePacks, getAvailableOmPacks, selectPreferredOMPack } from "./onboarding/packs.js";
7
7
  import { MASTRA_GATEWAY_PROVIDER, OBSERVABILITY_AUTH_PREFIX, THREAD_ACTIVE_MODEL_PACK_ID_KEY, loadSettings, resolveModelDefaults, resolveOmRoleModel, saveSettings } from "./onboarding/settings.js";
8
+ import { resolveExperimentalAgent, validateExperimentalAgent, wrapExperimentalAgent } from "./experimental-agent.js";
8
9
  import { createSessionThreadAdvertisement } from "./agent-connections/session-advertisement.js";
9
10
  import { AgentConnectionsSignalProvider } from "./agent-connections/signal-provider.js";
10
11
  import { createBackgroundCompletionEvents } from "./agents/background-completion-events.js";
@@ -70,10 +71,10 @@ import { createHash } from "crypto";
70
71
  import { readFile } from "fs/promises";
71
72
  import { AgentController } from "@mastra/core/agent-controller";
72
73
  import { createCodingAgent } from "@mastra/core/coding-agent";
73
- import { PROVIDER_REGISTRY } from "@mastra/core/llm";
74
+ import { PROVIDER_REGISTRY, findGatewayForModel, getGatewayId } from "@mastra/core/llm";
74
75
  import { Mastra } from "@mastra/core/mastra";
75
76
  import { defaultNotificationDeliveryDecision } from "@mastra/core/notifications";
76
- import { AgentsMDInjector, CyberRefusalHandler, PrefillErrorHandler, ProviderHistoryCompat, StreamErrorRetryProcessor, createBackgroundWorkSignalProcessor, isBadRequestError } from "@mastra/core/processors";
77
+ import { AgentsMDInjector, CyberRefusalHandler, ProviderHistoryCompat, StreamErrorRetryProcessor, createBackgroundWorkSignalProcessor, isBadRequestError } from "@mastra/core/processors";
77
78
  import { RequestContext } from "@mastra/core/request-context";
78
79
  import { TaskSignalProvider } from "@mastra/core/signals";
79
80
  import { InMemoryHarness, MastraCompositeStore } from "@mastra/core/storage";
@@ -226,6 +227,15 @@ function resolveInjectedStorageBackend(storage, configuredBackend) {
226
227
  if (storage instanceof PostgresStore || hasAncestorClassNamed(storage, "PostgresStore")) return "pg";
227
228
  throw new Error("storageBackend is required when injecting a custom storage instance.");
228
229
  }
230
+ /** Whether the model router would resolve `modelId` through a gateway outside `sdkGatewayIds`. */
231
+ function routesToOtherGateway(modelId, gateways, sdkGatewayIds) {
232
+ try {
233
+ return !sdkGatewayIds.has(getGatewayId(findGatewayForModel(modelId, gateways)));
234
+ } catch (error) {
235
+ if (error?.id === "MODEL_ROUTER_NO_GATEWAY_FOUND") return false;
236
+ throw error;
237
+ }
238
+ }
229
239
  async function createMastraCodeAgentController(config) {
230
240
  const cwd = config?.cwd ?? process.cwd();
231
241
  const homeDir = config?.homeDir ?? config?.initialState?.homeDir;
@@ -238,6 +248,7 @@ async function createMastraCodeAgentController(config) {
238
248
  } catch {}
239
249
  const authStorage = createAuthStorage();
240
250
  const globalSettings = loadSettings(config?.settingsPath);
251
+ const experimentalAgent = resolveExperimentalAgent(globalSettings);
241
252
  const backgroundToolsEnabled = globalSettings.backgroundTools?.enabled ?? false;
242
253
  const storedGatewayKey = authStorage.getStoredApiKey(MASTRA_GATEWAY_PROVIDER);
243
254
  const storedGatewayUrl = globalSettings.memoryGateway?.baseUrl;
@@ -562,8 +573,7 @@ async function createMastraCodeAgentController(config) {
562
573
  const projectPath = state?.projectPath ?? project.rootPath;
563
574
  return getStaticallyLoadedInstructionPaths(projectPath, void 0, state?.untrustedCheckout === true && typeof state?.baseRef === "string" ? createGitRefInstructionReader(projectPath, state.baseRef) : void 0);
564
575
  }
565
- }),
566
- new ProviderHistoryCompat()
576
+ })
567
577
  ];
568
578
  const taskSignalProvider = new TaskSignalProvider();
569
579
  const agentConnectionsSignalProvider = useCrossAgentSignals ? new AgentConnectionsSignalProvider(config?.agentConnections) : void 0;
@@ -597,7 +607,7 @@ async function createMastraCodeAgentController(config) {
597
607
  return NO_PLUGIN_PROCESSORS;
598
608
  }
599
609
  };
600
- const codeAgent = createCodingAgent({
610
+ const codeAgent = wrapExperimentalAgent(createCodingAgent({
601
611
  id: CODE_AGENT_ID,
602
612
  name: "Code Agent",
603
613
  workspace: void 0,
@@ -687,7 +697,6 @@ async function createMastraCodeAgentController(config) {
687
697
  onRetry: ({ error, retryCount, delayMs, requestContext }) => emitTransientRetry(error, retryCount, delayMs, requestContext)
688
698
  }
689
699
  ] }),
690
- new PrefillErrorHandler(),
691
700
  new AccountRotationProcessor({
692
701
  credentialStore: authStorage,
693
702
  maxProcessorRetries: MASTRACODE_MAX_PROCESSOR_RETRIES,
@@ -695,7 +704,7 @@ async function createMastraCodeAgentController(config) {
695
704
  })
696
705
  ],
697
706
  maxProcessorRetries: MASTRACODE_MAX_PROCESSOR_RETRIES
698
- });
707
+ }), experimentalAgent);
699
708
  const defaultModes = [
700
709
  {
701
710
  ...buildMode,
@@ -813,6 +822,11 @@ async function createMastraCodeAgentController(config) {
813
822
  stateSchema: typedStateSchema,
814
823
  agent: codeAgent,
815
824
  subagents,
825
+ resolveSubagentModel: (modelId, { requestContext }) => routesToOtherGateway(modelId, Object.values(controller.getMastra()?.listGateways() ?? {}), /* @__PURE__ */ new Set([
826
+ mastraCodeGateway.id,
827
+ amazonBedrockGateway.id,
828
+ "models.dev"
829
+ ])) ? modelId : resolveModel(modelId, { requestContext }),
816
830
  gateways: [amazonBedrockGateway, mastraCodeGateway],
817
831
  workspace: config?.workspace ?? ((args) => getDynamicWorkspace({
818
832
  ...args,
@@ -1008,6 +1022,7 @@ async function bootLocalAgentController(config) {
1008
1022
  const base = await createMastraCodeAgentController(config);
1009
1023
  const { controller, sessionId, ownerId, projectPath, codeAgent, mcpManager } = base;
1010
1024
  await controller.init();
1025
+ validateExperimentalAgent(codeAgent, controller.getMastra());
1011
1026
  const mastra = controller.getMastra();
1012
1027
  if (mastra) await registerWorkflowBuilderPrimitives(mastra, {
1013
1028
  projectPath,
@@ -1103,6 +1118,7 @@ async function prepareAgentControllerMount(config) {
1103
1118
  };
1104
1119
  const finalize = async () => {
1105
1120
  await controller.init();
1121
+ validateExperimentalAgent(codeAgent, controller.getMastra());
1106
1122
  if (weOwnTheMastra) {
1107
1123
  const mastra = controller.getMastra();
1108
1124
  if (mastra) await registerWorkflowBuilderPrimitives(mastra, {