mastracode 0.22.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { setAuthStorage, setAuthStorage3, setAuthStorage2, loadSettings, MEMORY_GATEWAY_PROVIDER, GithubSignals, getDynamicModel, getAvailableModePacks, getAvailableOmPacks, resolveModelDefaults, resolveOmRoleModel, resolveModel, releaseThreadLock, acquireThreadLock, getCustomProviderId, toCustomProviderModelId, getCopilotModelCatalog, saveSettings, mastra, OBSERVABILITY_AUTH_PREFIX } from './chunk-7ZTY5SBK.js';
1
+ import { setAuthStorage, setAuthStorage3, setAuthStorage2, loadSettings, MEMORY_GATEWAY_PROVIDER, GithubSignals, getDynamicModel, getAvailableModePacks, getAvailableOmPacks, resolveModelDefaults, resolveOmRoleModel, releaseThreadLock, acquireThreadLock, getCustomProviderId, toCustomProviderModelId, getCopilotModelCatalog, saveSettings, resolveModel, mastra, OBSERVABILITY_AUTH_PREFIX } from './chunk-7ZTY5SBK.js';
2
2
  import { DEFAULT_OM_MODEL_ID, DEFAULT_CONFIG_DIR, AuthStorage, validateConfigDirName, detectProject, getResourceIdOverride, getStorageConfig, getObservabilityDatabasePath, getVectorDatabasePath, getCurrentGitBranchAsync, getOmScope, DEFAULT_REF_THRESHOLD, DEFAULT_OBS_THRESHOLD, getDatabasePath, getAppDataDir } from './chunk-5FT2NNFO.js';
3
3
  import { MC_TOOLS, getToolCategory, TOOL_NAME_OVERRIDES } from './chunk-UOFNLVKF.js';
4
4
  import { createHash } from 'crypto';
@@ -1030,7 +1030,7 @@ ${lines.join("\n")}
1030
1030
  // src/agents/instructions.ts
1031
1031
  async function getDynamicInstructions({ requestContext }) {
1032
1032
  const harnessContext = requestContext.get("harness");
1033
- const state = harnessContext?.getState?.();
1033
+ const state = harnessContext?.state;
1034
1034
  const modeId = harnessContext?.modeId ?? "build";
1035
1035
  const projectPath = state?.projectPath ?? process.cwd();
1036
1036
  const promptCtx = {
@@ -1380,7 +1380,7 @@ function wrapToolWithHooks(toolName, tool, hookManager) {
1380
1380
  function createDynamicTools(mcpManager, extraTools, hookManager, disabledTools, storage) {
1381
1381
  return function getDynamicTools({ requestContext }) {
1382
1382
  const ctx = requestContext.get("harness");
1383
- const state = ctx?.getState?.();
1383
+ const state = ctx?.getState();
1384
1384
  const modelId = state?.currentModelId;
1385
1385
  const isAnthropicModel = modelId?.startsWith("anthropic/");
1386
1386
  const isOpenAIModel = modelId?.startsWith("openai/");
@@ -1961,62 +1961,15 @@ var HarnessCompat = class extends Harness$1 {
1961
1961
  super(args);
1962
1962
  this.#harnessV1 = harnessV1;
1963
1963
  }
1964
- getState() {
1965
- const state = super.getState();
1966
- let session;
1967
- try {
1968
- session = this.#session;
1969
- } catch {
1970
- session = void 0;
1971
- }
1972
- if (!session) {
1973
- return state;
1974
- }
1975
- return {
1976
- ...state,
1977
- ...session.getState(),
1978
- currentModelId: session.getModelId(),
1979
- modeId: session.getMode().id
1980
- };
1981
- }
1982
- async setState(updates) {
1983
- const { currentModelId, modeId, ...harnessUpdates } = updates;
1984
- let session;
1985
- try {
1986
- session = this.#session;
1987
- } catch {
1988
- session = void 0;
1989
- }
1990
- if (session) {
1991
- if (typeof currentModelId === "string") {
1992
- session.setModelId(currentModelId);
1993
- }
1994
- if (typeof modeId === "string" && modeId !== session.getMode().id) {
1995
- await this.switchMode({ modeId });
1996
- }
1997
- }
1998
- if (Object.keys(harnessUpdates).length > 0) {
1999
- if (session) {
2000
- await session.setState(harnessUpdates);
2001
- }
2002
- await super.setState(harnessUpdates);
2003
- }
2004
- }
2005
- getSubagentModelId({ agentType } = {}) {
2006
- return super.getSubagentModelId({ agentType });
2007
- }
2008
- async setSubagentModelId({ modelId, agentType }) {
2009
- await super.setSubagentModelId({ modelId, agentType });
2010
- }
2011
1964
  async switchThread({ threadId }) {
2012
- const currentModelId = this.getState().currentModelId;
2013
- const session = await this.#harnessV1.session({
1965
+ const modes = this.listModes();
1966
+ this.#session = await this.#harnessV1.session({
2014
1967
  threadId,
2015
1968
  resourceId: this.getResourceId()
2016
1969
  });
2017
- this.#session = session;
2018
- if (typeof currentModelId === "string" && currentModelId.length > 0) {
2019
- session.setModelId(currentModelId);
1970
+ const defaultModelId = modes.find((mode) => mode.id === this.#session.getMode().id)?.defaultModelId;
1971
+ if (defaultModelId) {
1972
+ this.#session.setModelId(defaultModelId);
2020
1973
  }
2021
1974
  await super.switchThread({ threadId });
2022
1975
  }
@@ -2116,19 +2069,6 @@ var HarnessCompat = class extends Harness$1 {
2116
2069
  }
2117
2070
  await super.switchMode({ modeId });
2118
2071
  }
2119
- /**
2120
- * Activate a skill on the current v1 session.
2121
- *
2122
- * Pass-through to `Session.useSkill` — returns the resolved instructions
2123
- * string, or throws `HarnessSkillNotFoundError` if the skill is missing.
2124
- * Throws if there is no active session.
2125
- */
2126
- async useSkill(name, opts) {
2127
- if (!this.#session) {
2128
- throw new Error("No active session to use skill");
2129
- }
2130
- return this.#session.useSkill(name, opts);
2131
- }
2132
2072
  };
2133
2073
  var VALID_EVENTS = [
2134
2074
  "PreToolUse",
@@ -2973,12 +2913,15 @@ function createMcpManager(projectDir, configDirName = DEFAULT_CONFIG_DIR, extraS
2973
2913
  };
2974
2914
  }
2975
2915
  var stateSchema = z.object({
2976
- subagentModelId: z.string().optional(),
2977
2916
  projectPath: z.string().optional(),
2978
2917
  projectName: z.string().optional(),
2979
2918
  configDir: z.string().default(DEFAULT_CONFIG_DIR),
2980
2919
  gitBranch: z.string().optional(),
2981
2920
  lastCommand: z.string().optional(),
2921
+ currentModelId: z.string().default(""),
2922
+ // Subagent model settings (per-thread/per-mode)
2923
+ subagentModelId: z.string().optional(),
2924
+ // Thread-level default for subagents
2982
2925
  // Observational Memory model settings
2983
2926
  observerModelId: z.string().default(DEFAULT_OM_MODEL_ID),
2984
2927
  reflectorModelId: z.string().default(DEFAULT_OM_MODEL_ID),
@@ -3390,7 +3333,7 @@ async function createMastraCode(config) {
3390
3333
  // Environment & project:
3391
3334
  // state.projectName, state.gitBranch
3392
3335
  // Model configuration:
3393
- // state.currentModelId
3336
+ // state.currentModelId, state.subagentModelId
3394
3337
  // Agent settings:
3395
3338
  // state.yolo, state.thinkingLevel, state.smartEditing
3396
3339
  // Observational memory settings:
@@ -3407,6 +3350,7 @@ async function createMastraCode(config) {
3407
3350
  "harness.state.gitBranch",
3408
3351
  // Model configuration
3409
3352
  "harness.state.currentModelId",
3353
+ "harness.state.subagentModelId",
3410
3354
  // Agent settings
3411
3355
  "harness.state.yolo",
3412
3356
  "harness.state.thinkingLevel",
@@ -3656,32 +3600,15 @@ async function createMastraCode(config) {
3656
3600
  });
3657
3601
  })
3658
3602
  );
3659
- const typedStateSchema = stateSchema;
3660
- const initialState = {
3661
- projectPath: project.rootPath,
3662
- projectName: project.name,
3663
- gitBranch: project.gitBranch,
3664
- yolo: true,
3665
- ...globalInitialState,
3666
- ...config?.initialState,
3667
- // configDir must always win over initialState spreads to stay in sync
3668
- // with MCP/hooks/storage which were already initialized with this value.
3669
- configDir
3670
- };
3671
- const workspace = config?.workspace ?? getDynamicWorkspace;
3672
3603
  const harnessV1 = new Harness({
3673
3604
  ownerId,
3674
3605
  agents: { [CODE_AGENT_ID]: codeAgent },
3675
3606
  memory,
3676
3607
  modes: modesV1,
3677
3608
  defaultModeId,
3678
- storage: harnessStorage,
3679
- stateSchema: typedStateSchema,
3680
- initialState,
3681
- workspace,
3682
- resolveModel: (modelId) => resolveModel(modelId),
3683
- toolCategoryResolver: (name) => getToolCategory(name) ?? null
3609
+ storage: harnessStorage
3684
3610
  });
3611
+ const typedStateSchema = stateSchema;
3685
3612
  const harness = new HarnessCompat(
3686
3613
  {
3687
3614
  id: "mastra-code",
@@ -3694,8 +3621,18 @@ async function createMastraCode(config) {
3694
3621
  subagents,
3695
3622
  resolveModel: (modelId) => resolveModel(modelId),
3696
3623
  toolCategoryResolver: getToolCategory,
3697
- initialState,
3698
- workspace,
3624
+ initialState: {
3625
+ projectPath: project.rootPath,
3626
+ projectName: project.name,
3627
+ gitBranch: project.gitBranch,
3628
+ yolo: true,
3629
+ ...globalInitialState,
3630
+ ...config?.initialState,
3631
+ // configDir must always win over initialState spreads to stay in sync
3632
+ // with MCP/hooks/storage which were already initialized with this value.
3633
+ configDir
3634
+ },
3635
+ workspace: config?.workspace ?? getDynamicWorkspace,
3699
3636
  browser: config?.browser,
3700
3637
  modes,
3701
3638
  heartbeatHandlers,
@@ -3834,5 +3771,5 @@ async function createMastraCode(config) {
3834
3771
  }
3835
3772
 
3836
3773
  export { createAuthStorage, createMastraCode };
3837
- //# sourceMappingURL=chunk-Y5AUV6T3.js.map
3838
- //# sourceMappingURL=chunk-Y5AUV6T3.js.map
3774
+ //# sourceMappingURL=chunk-G76EJQC6.js.map
3775
+ //# sourceMappingURL=chunk-G76EJQC6.js.map