mastracode 0.21.2-alpha.4 → 0.21.2-alpha.6
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.
- package/CHANGELOG.md +18 -0
- package/dist/HarnessCompat.d.ts +41 -0
- package/dist/HarnessCompat.d.ts.map +1 -0
- package/dist/{chunk-2TQ5QO5H.cjs → chunk-A4TDK7QP.cjs} +337 -124
- package/dist/chunk-A4TDK7QP.cjs.map +1 -0
- package/dist/{chunk-U3WP3AYZ.js → chunk-DI26VPRS.js} +29 -10
- package/dist/chunk-DI26VPRS.js.map +1 -0
- package/dist/{chunk-535FCN2X.js → chunk-J4DYNVTI.js} +335 -122
- package/dist/chunk-J4DYNVTI.js.map +1 -0
- package/dist/{chunk-HQQAEUJG.cjs → chunk-LTD4R5UZ.cjs} +28 -9
- package/dist/chunk-LTD4R5UZ.cjs.map +1 -0
- package/dist/cli.cjs +8 -8
- package/dist/cli.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/tui/commands/threads.d.ts.map +1 -1
- package/dist/tui/components/ask-question-inline.d.ts.map +1 -1
- package/dist/tui/components/plan-approval-inline.d.ts.map +1 -1
- package/dist/tui/components/user-message.d.ts.map +1 -1
- package/dist/tui.cjs +11 -11
- package/dist/tui.js +1 -1
- package/package.json +10 -10
- package/dist/chunk-2TQ5QO5H.cjs.map +0 -1
- package/dist/chunk-535FCN2X.js.map +0 -1
- package/dist/chunk-HQQAEUJG.cjs.map +0 -1
- package/dist/chunk-U3WP3AYZ.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# mastracode
|
|
2
2
|
|
|
3
|
+
## 0.21.2-alpha.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed TUI crash on narrow terminals when prompt dialogs render lines wider than terminal width ([#17431](https://github.com/mastra-ai/mastra/pull/17431))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b0771a4`](https://github.com/mastra-ai/mastra/commit/b0771a48b46e46d270fca208a587922f3b7104a8), [`19a8658`](https://github.com/mastra-ai/mastra/commit/19a86589c788ef48bb6c1b0612cc82a201857379), [`a659a77`](https://github.com/mastra-ai/mastra/commit/a659a779bdebe3a52a518c56d2260592d0240fe0), [`3332be9`](https://github.com/mastra-ai/mastra/commit/3332be9701ecd77aba840959d9a1d1ce7aef02d3)]:
|
|
10
|
+
- @mastra/agent-browser@0.3.0-alpha.1
|
|
11
|
+
- @mastra/core@1.38.0-alpha.6
|
|
12
|
+
|
|
13
|
+
## 0.21.2-alpha.5
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`a18775a`](https://github.com/mastra-ai/mastra/commit/a18775a693172546ee2378d39b67d4e32895b251), [`1baf2d1`](https://github.com/mastra-ai/mastra/commit/1baf2d152c6881338ff8f114633d5316fe13dd15), [`8260167`](https://github.com/mastra-ai/mastra/commit/8260167431f98400f3acef4bbb7bd6027efd7a4b)]:
|
|
18
|
+
- @mastra/core@1.38.0-alpha.5
|
|
19
|
+
- @mastra/duckdb@1.4.1-alpha.0
|
|
20
|
+
|
|
3
21
|
## 0.21.2-alpha.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Agent } from '@mastra/core/agent';
|
|
2
|
+
import { Harness as HarnessLegacy } from '@mastra/core/harness';
|
|
3
|
+
import type { HarnessConfig, HarnessMode as HarnessModeLegacy, HarnessThread } from '@mastra/core/harness';
|
|
4
|
+
import type { Session, HarnessMode, Harness } from '@mastra/core/harness/v1';
|
|
5
|
+
type CloneSessionOptions = {
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
threadId?: string;
|
|
8
|
+
resourceId?: string;
|
|
9
|
+
parentSessionId?: string;
|
|
10
|
+
origin?: 'top-level' | 'subagent-tool';
|
|
11
|
+
modeId?: string;
|
|
12
|
+
modelId?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function v1ModeToLegacy<TState = {}>(mode: HarnessMode, agent: Agent): HarnessModeLegacy<TState>;
|
|
15
|
+
export declare class HarnessCompat<TState = {}> extends HarnessLegacy<TState> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(args: HarnessConfig<TState>, harnessV1: Harness<HarnessMode[]>);
|
|
18
|
+
switchThread({ threadId }: {
|
|
19
|
+
threadId: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
listThreads(options?: {
|
|
22
|
+
allResources?: boolean;
|
|
23
|
+
includeForkedSubagents?: boolean;
|
|
24
|
+
}): Promise<HarnessThread[]>;
|
|
25
|
+
cloneSession(opts?: CloneSessionOptions): Promise<Session>;
|
|
26
|
+
cloneThread({ sourceThreadId, title, resourceId, }?: {
|
|
27
|
+
sourceThreadId?: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
resourceId?: string;
|
|
30
|
+
}): Promise<HarnessThread>;
|
|
31
|
+
getCurrentMode(): HarnessModeLegacy<TState>;
|
|
32
|
+
/**
|
|
33
|
+
* Switch to a different mode.
|
|
34
|
+
* Aborts any in-progress generation and switches to the mode's default model.
|
|
35
|
+
*/
|
|
36
|
+
switchMode({ modeId }: {
|
|
37
|
+
modeId: string;
|
|
38
|
+
}): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=HarnessCompat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HarnessCompat.d.ts","sourceRoot":"","sources":["../src/HarnessCompat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,IAAI,iBAAiB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC3G,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAE7E,KAAK,mBAAmB,GAAG;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,GAAG,eAAe,CAAC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAIF,wBAAgB,cAAc,CAAC,MAAM,GAAG,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAUtG;AAED,qBAAa,aAAa,CAAC,MAAM,GAAG,EAAE,CAAE,SAAQ,aAAa,CAAC,MAAM,CAAC;;gBAIvD,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;IAMpE,YAAY,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB/D,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IA4C7G,YAAY,CAAC,IAAI,GAAE,mBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC;IAS9D,WAAW,CAAC,EAChB,cAAc,EACd,KAAK,EACL,UAAU,GACX,GAAE;QACD,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,aAAa,CAAC;IAiC/B,cAAc,IAAI,iBAAiB,CAAC,MAAM,CAAC;IAc3C;;;OAGG;IACG,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAchE"}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
var chunkDJBUYADN_cjs = require('./chunk-DJBUYADN.cjs');
|
|
4
4
|
var chunkJ3ISOP5J_cjs = require('./chunk-J3ISOP5J.cjs');
|
|
5
5
|
var chunkAWYGW5ZV_cjs = require('./chunk-AWYGW5ZV.cjs');
|
|
6
|
+
var crypto = require('crypto');
|
|
7
|
+
var os = require('os');
|
|
6
8
|
var path = require('path');
|
|
7
9
|
var agent = require('@mastra/core/agent');
|
|
8
|
-
var
|
|
10
|
+
var v1 = require('@mastra/core/harness/v1');
|
|
9
11
|
var llm = require('@mastra/core/llm');
|
|
10
12
|
var processors = require('@mastra/core/processors');
|
|
11
13
|
var storage = require('@mastra/core/storage');
|
|
@@ -15,7 +17,6 @@ var child_process = require('child_process');
|
|
|
15
17
|
var tools = require('@mastra/core/tools');
|
|
16
18
|
var tavily = require('@mastra/tavily');
|
|
17
19
|
var tokenx = require('tokenx');
|
|
18
|
-
var os = require('os');
|
|
19
20
|
var workspace = require('@mastra/core/workspace');
|
|
20
21
|
var zod = require('zod');
|
|
21
22
|
var fs = require('fs');
|
|
@@ -25,6 +26,7 @@ var memory = require('@mastra/memory');
|
|
|
25
26
|
var anthropic = require('@ai-sdk/anthropic');
|
|
26
27
|
var openai = require('@ai-sdk/openai');
|
|
27
28
|
var evals = require('@mastra/core/evals');
|
|
29
|
+
var harness = require('@mastra/core/harness');
|
|
28
30
|
var mcp = require('@mastra/mcp');
|
|
29
31
|
var promises = require('fs/promises');
|
|
30
32
|
var events = require('@mastra/core/events');
|
|
@@ -50,8 +52,8 @@ function _interopNamespace(e) {
|
|
|
50
52
|
return Object.freeze(n);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
54
55
|
var os__namespace = /*#__PURE__*/_interopNamespace(os);
|
|
56
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
55
57
|
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
56
58
|
|
|
57
59
|
var COMMON_BINARIES = [
|
|
@@ -599,7 +601,7 @@ function getDynamicWorkspace({ requestContext, mastra: mastra2 }) {
|
|
|
599
601
|
return existing;
|
|
600
602
|
}
|
|
601
603
|
const userLsp = chunkDJBUYADN_cjs.loadSettings().lsp ?? {};
|
|
602
|
-
const mcModulePath = path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
604
|
+
const mcModulePath = path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-A4TDK7QP.cjs', document.baseURI).href)))), "..");
|
|
603
605
|
const lspConfig = {
|
|
604
606
|
...userLsp,
|
|
605
607
|
packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath),
|
|
@@ -1916,6 +1918,134 @@ function createEfficiencyScorer() {
|
|
|
1916
1918
|
return parts.join("\n");
|
|
1917
1919
|
});
|
|
1918
1920
|
}
|
|
1921
|
+
function v1ModeToLegacy(mode, agent) {
|
|
1922
|
+
const meta = mode.metadata ?? {};
|
|
1923
|
+
return {
|
|
1924
|
+
id: mode.id,
|
|
1925
|
+
name: mode.description,
|
|
1926
|
+
default: meta.default === true,
|
|
1927
|
+
defaultModelId: mode.defaultModelId,
|
|
1928
|
+
color: typeof meta.color === "string" ? meta.color : void 0,
|
|
1929
|
+
agent
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
var HarnessCompat = class extends harness.Harness {
|
|
1933
|
+
#session;
|
|
1934
|
+
#harnessV1;
|
|
1935
|
+
constructor(args, harnessV1) {
|
|
1936
|
+
super(args);
|
|
1937
|
+
this.#harnessV1 = harnessV1;
|
|
1938
|
+
}
|
|
1939
|
+
async switchThread({ threadId }) {
|
|
1940
|
+
const modes = this.listModes();
|
|
1941
|
+
this.#session = await this.#harnessV1.session({
|
|
1942
|
+
threadId,
|
|
1943
|
+
resourceId: this.getResourceId()
|
|
1944
|
+
});
|
|
1945
|
+
const defaultModelId = modes.find((mode) => mode.id === this.#session.getMode().id)?.defaultModelId;
|
|
1946
|
+
if (defaultModelId) {
|
|
1947
|
+
this.#session.setModelId(defaultModelId);
|
|
1948
|
+
}
|
|
1949
|
+
await super.switchThread({ threadId });
|
|
1950
|
+
}
|
|
1951
|
+
async listThreads(options) {
|
|
1952
|
+
const [sessions, legacyThreads] = await Promise.all([this.#harnessV1.listSessions(), super.listThreads(options)]);
|
|
1953
|
+
const resourceId = this.getResourceId();
|
|
1954
|
+
const sessionThreads = sessions.filter((session) => options?.allResources || session.resourceId === resourceId).map((session) => {
|
|
1955
|
+
const legacyThread = legacyThreads.find(
|
|
1956
|
+
(thread) => thread.id === session.threadId && (!thread.resourceId || thread.resourceId === session.resourceId)
|
|
1957
|
+
);
|
|
1958
|
+
const metadata = legacyThread?.metadata;
|
|
1959
|
+
if (!options?.includeForkedSubagents && metadata?.forkedSubagent === true) {
|
|
1960
|
+
return void 0;
|
|
1961
|
+
}
|
|
1962
|
+
return {
|
|
1963
|
+
id: session.threadId,
|
|
1964
|
+
resourceId: session.resourceId,
|
|
1965
|
+
createdAt: session.createdAt,
|
|
1966
|
+
updatedAt: session.lastActivityAt,
|
|
1967
|
+
metadata: {
|
|
1968
|
+
...metadata,
|
|
1969
|
+
sessionId: session.id,
|
|
1970
|
+
modeId: session.modeId,
|
|
1971
|
+
modelId: session.modelId,
|
|
1972
|
+
parentSessionId: session.parentSessionId,
|
|
1973
|
+
origin: session.origin
|
|
1974
|
+
}
|
|
1975
|
+
};
|
|
1976
|
+
}).filter((thread) => thread !== void 0);
|
|
1977
|
+
const sessionKeys = new Set(sessionThreads.map((thread) => `${thread.resourceId}:${thread.id}`));
|
|
1978
|
+
const sessionThreadIds = new Set(sessionThreads.map((thread) => thread.id));
|
|
1979
|
+
return [
|
|
1980
|
+
...sessionThreads,
|
|
1981
|
+
...legacyThreads.filter(
|
|
1982
|
+
(thread) => !sessionKeys.has(`${thread.resourceId}:${thread.id}`) && !(!thread.resourceId && sessionThreadIds.has(thread.id))
|
|
1983
|
+
)
|
|
1984
|
+
];
|
|
1985
|
+
}
|
|
1986
|
+
async cloneSession(opts = {}) {
|
|
1987
|
+
const session = this.#session;
|
|
1988
|
+
if (!session) {
|
|
1989
|
+
throw new Error("No active session to clone");
|
|
1990
|
+
}
|
|
1991
|
+
return this.#harnessV1.cloneSession(session, opts);
|
|
1992
|
+
}
|
|
1993
|
+
async cloneThread({
|
|
1994
|
+
sourceThreadId,
|
|
1995
|
+
title,
|
|
1996
|
+
resourceId
|
|
1997
|
+
} = {}) {
|
|
1998
|
+
const sourceId = sourceThreadId ?? this.getCurrentThreadId();
|
|
1999
|
+
if (!sourceId) {
|
|
2000
|
+
throw new Error("No source thread to clone");
|
|
2001
|
+
}
|
|
2002
|
+
const sourceResourceId = resourceId ?? this.getResourceId();
|
|
2003
|
+
const currentSession = this.#session;
|
|
2004
|
+
const sourceSession = currentSession?.threadId === sourceId && currentSession.resourceId === sourceResourceId ? currentSession : await this.#harnessV1.session({
|
|
2005
|
+
threadId: sourceId,
|
|
2006
|
+
resourceId: sourceResourceId
|
|
2007
|
+
});
|
|
2008
|
+
this.#session = await this.#harnessV1.cloneSession(sourceSession, { title });
|
|
2009
|
+
const thread = await this.#session.getThread();
|
|
2010
|
+
if (!thread) {
|
|
2011
|
+
throw new Error("Failed to load cloned thread");
|
|
2012
|
+
}
|
|
2013
|
+
return {
|
|
2014
|
+
id: thread.id,
|
|
2015
|
+
resourceId: thread.resourceId,
|
|
2016
|
+
title: title ?? thread.title ?? "Cloned Thread",
|
|
2017
|
+
createdAt: thread.createdAt,
|
|
2018
|
+
updatedAt: thread.updatedAt,
|
|
2019
|
+
metadata: thread.metadata
|
|
2020
|
+
};
|
|
2021
|
+
}
|
|
2022
|
+
getCurrentMode() {
|
|
2023
|
+
if (!this.#session) {
|
|
2024
|
+
return super.getCurrentMode();
|
|
2025
|
+
}
|
|
2026
|
+
const mode = this.#session.getMode();
|
|
2027
|
+
const mastra2 = this.getMastra();
|
|
2028
|
+
if (!mastra2) {
|
|
2029
|
+
throw new Error("HarnessCompat requires an initialized Mastra instance");
|
|
2030
|
+
}
|
|
2031
|
+
return v1ModeToLegacy(mode, mastra2.getAgentById(mode.agentId));
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* Switch to a different mode.
|
|
2035
|
+
* Aborts any in-progress generation and switches to the mode's default model.
|
|
2036
|
+
*/
|
|
2037
|
+
async switchMode({ modeId }) {
|
|
2038
|
+
const mode = this.#harnessV1.getMode(modeId);
|
|
2039
|
+
if (!mode) {
|
|
2040
|
+
throw new Error(`Mode not found: ${modeId}`);
|
|
2041
|
+
}
|
|
2042
|
+
if (!this.#session) {
|
|
2043
|
+
throw new Error("No active session to switch mode");
|
|
2044
|
+
}
|
|
2045
|
+
this.#session.setMode(mode);
|
|
2046
|
+
await super.switchMode({ modeId });
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
1919
2049
|
var VALID_EVENTS = [
|
|
1920
2050
|
"PreToolUse",
|
|
1921
2051
|
"PostToolUse",
|
|
@@ -3027,6 +3157,37 @@ var PROVIDER_TO_OAUTH_ID = {
|
|
|
3027
3157
|
openai: "openai-codex",
|
|
3028
3158
|
"github-copilot": "github-copilot"
|
|
3029
3159
|
};
|
|
3160
|
+
var CODE_AGENT_ID = "code-agent";
|
|
3161
|
+
function hash(value) {
|
|
3162
|
+
return crypto.createHash("sha256").update(value).digest("hex").slice(0, 32);
|
|
3163
|
+
}
|
|
3164
|
+
function legacyModeToV1(mode, fallbackAgent) {
|
|
3165
|
+
const agent = typeof mode.agent === "function" ? mode.agent({}) : mode.agent;
|
|
3166
|
+
return {
|
|
3167
|
+
id: mode.id,
|
|
3168
|
+
agentId: (agent ?? fallbackAgent).id,
|
|
3169
|
+
defaultModelId: mode.defaultModelId ?? "openai/gpt-5.5",
|
|
3170
|
+
description: mode.name,
|
|
3171
|
+
...mode.id === "plan" ? { transitionsTo: "build" } : {},
|
|
3172
|
+
metadata: {
|
|
3173
|
+
color: mode.color,
|
|
3174
|
+
default: mode.default,
|
|
3175
|
+
name: mode.name
|
|
3176
|
+
}
|
|
3177
|
+
};
|
|
3178
|
+
}
|
|
3179
|
+
function applyEffectiveDefaultsToV1Modes(modes, effectiveDefaults) {
|
|
3180
|
+
return modes.map((mode) => {
|
|
3181
|
+
const savedModel = effectiveDefaults[mode.id];
|
|
3182
|
+
if (!savedModel) {
|
|
3183
|
+
return mode;
|
|
3184
|
+
}
|
|
3185
|
+
return {
|
|
3186
|
+
...mode,
|
|
3187
|
+
defaultModelId: savedModel
|
|
3188
|
+
};
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
3030
3191
|
function createAuthStorage() {
|
|
3031
3192
|
const authStorage = new chunkJ3ISOP5J_cjs.AuthStorage();
|
|
3032
3193
|
chunkDJBUYADN_cjs.setAuthStorage(authStorage);
|
|
@@ -3126,11 +3287,13 @@ async function createMastraCode(config) {
|
|
|
3126
3287
|
}
|
|
3127
3288
|
}
|
|
3128
3289
|
}
|
|
3290
|
+
const harnessStorage = new storage.InMemoryHarness();
|
|
3129
3291
|
const storage$1 = new storage.MastraCompositeStore({
|
|
3130
3292
|
id: "mastra-code-storage",
|
|
3131
3293
|
default: storageResult.storage,
|
|
3132
3294
|
domains: {
|
|
3133
|
-
...observabilityDomain ? { observability: observabilityDomain } : {}
|
|
3295
|
+
...observabilityDomain ? { observability: observabilityDomain } : {},
|
|
3296
|
+
harness: harnessStorage
|
|
3134
3297
|
}
|
|
3135
3298
|
});
|
|
3136
3299
|
const observability$1 = new observability.Observability({
|
|
@@ -3190,7 +3353,7 @@ async function createMastraCode(config) {
|
|
|
3190
3353
|
const outcomeScorer = createOutcomeScorer();
|
|
3191
3354
|
const efficiencyScorer = createEfficiencyScorer();
|
|
3192
3355
|
const codeAgent = new agent.Agent({
|
|
3193
|
-
id:
|
|
3356
|
+
id: CODE_AGENT_ID,
|
|
3194
3357
|
name: "Code Agent",
|
|
3195
3358
|
instructions: getDynamicInstructions,
|
|
3196
3359
|
model: chunkDJBUYADN_cjs.getDynamicModel,
|
|
@@ -3218,28 +3381,35 @@ async function createMastraCode(config) {
|
|
|
3218
3381
|
errorProcessors: [new processors.StreamErrorRetryProcessor(), new processors.PrefillErrorHandler(), new processors.ProviderHistoryCompat()]
|
|
3219
3382
|
});
|
|
3220
3383
|
const defaultSubagents = [exploreSubagent, planSubagent, executeSubagent];
|
|
3221
|
-
const
|
|
3384
|
+
const defaultModesV1 = [
|
|
3222
3385
|
{
|
|
3223
3386
|
id: "build",
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
defaultModelId: "anthropic/claude-opus-4-
|
|
3227
|
-
|
|
3228
|
-
|
|
3387
|
+
agentId: CODE_AGENT_ID,
|
|
3388
|
+
description: "Build",
|
|
3389
|
+
defaultModelId: "anthropic/claude-opus-4-7",
|
|
3390
|
+
metadata: {
|
|
3391
|
+
color: chunkDJBUYADN_cjs.mastra.green,
|
|
3392
|
+
default: true
|
|
3393
|
+
}
|
|
3229
3394
|
},
|
|
3230
3395
|
{
|
|
3231
3396
|
id: "plan",
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3397
|
+
agentId: CODE_AGENT_ID,
|
|
3398
|
+
description: "Plan",
|
|
3399
|
+
transitionsTo: "build",
|
|
3400
|
+
defaultModelId: "openai/gpt-5.5",
|
|
3401
|
+
metadata: {
|
|
3402
|
+
color: chunkDJBUYADN_cjs.mastra.purple
|
|
3403
|
+
}
|
|
3236
3404
|
},
|
|
3237
3405
|
{
|
|
3238
3406
|
id: "fast",
|
|
3239
|
-
|
|
3407
|
+
agentId: CODE_AGENT_ID,
|
|
3408
|
+
description: "Fast",
|
|
3240
3409
|
defaultModelId: "cerebras/zai-glm-4.7",
|
|
3241
|
-
|
|
3242
|
-
|
|
3410
|
+
metadata: {
|
|
3411
|
+
color: chunkDJBUYADN_cjs.mastra.orange
|
|
3412
|
+
}
|
|
3243
3413
|
}
|
|
3244
3414
|
];
|
|
3245
3415
|
const defaultHeartbeatHandlers = [
|
|
@@ -3286,10 +3456,15 @@ async function createMastraCode(config) {
|
|
|
3286
3456
|
const effectiveReflectionThreshold = globalSettings.models.omReflectionThreshold ?? void 0;
|
|
3287
3457
|
const effectiveCavemanObservations = globalSettings.models.omCavemanObservations ?? void 0;
|
|
3288
3458
|
const effectiveObserveAttachments = globalSettings.models.omObserveAttachments ?? "auto";
|
|
3289
|
-
const
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3459
|
+
const modesV1 = applyEffectiveDefaultsToV1Modes(
|
|
3460
|
+
config?.modes ? config.modes.map((mode) => legacyModeToV1(mode, codeAgent)) : defaultModesV1,
|
|
3461
|
+
effectiveDefaults
|
|
3462
|
+
);
|
|
3463
|
+
const defaultModeId = modesV1.find((mode) => mode.metadata?.default === true)?.id ?? modesV1.find((mode) => mode.id === "plan")?.id ?? modesV1[0]?.id;
|
|
3464
|
+
if (!defaultModeId) {
|
|
3465
|
+
throw new Error("MastraCode requires at least one mode");
|
|
3466
|
+
}
|
|
3467
|
+
const modes = modesV1.map((mode) => v1ModeToLegacy(mode, codeAgent));
|
|
3293
3468
|
const subagentModeMap = { explore: "fast", plan: "plan", execute: "build" };
|
|
3294
3469
|
const subagents = (config?.subagents ?? defaultSubagents).map((sa) => {
|
|
3295
3470
|
const modeId = subagentModeMap[sa.id];
|
|
@@ -3344,114 +3519,152 @@ async function createMastraCode(config) {
|
|
|
3344
3519
|
globalInitialState[`subagentModelId_${key}`] = modelId;
|
|
3345
3520
|
}
|
|
3346
3521
|
}
|
|
3347
|
-
const
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3522
|
+
const { threads } = await (await storage$1.getStore("memory"))?.listThreads({
|
|
3523
|
+
perPage: false,
|
|
3524
|
+
filter: {
|
|
3525
|
+
resourceId: project.resourceId
|
|
3526
|
+
}
|
|
3527
|
+
}) ?? { threads: [] };
|
|
3528
|
+
const ownerId = `mastracode-${hash(`${os.hostname()}\0${project.rootPath}`)}`;
|
|
3529
|
+
await Promise.all(
|
|
3530
|
+
threads.map((thread) => {
|
|
3531
|
+
const sessionHash = hash(`${thread.resourceId}\0${thread.id}`);
|
|
3532
|
+
const meta = thread.metadata;
|
|
3533
|
+
const modeId = typeof meta?.currentModeId === "string" ? meta.currentModeId : defaultModeId;
|
|
3534
|
+
const mode = modesV1.find((mode2) => mode2.id === modeId) ?? modesV1.find((mode2) => mode2.id === defaultModeId);
|
|
3535
|
+
const modelId = typeof meta?.currentModelId === "string" ? meta.currentModelId : mode.defaultModelId;
|
|
3536
|
+
return harnessStorage.saveSession({
|
|
3537
|
+
id: `sess-${sessionHash}`,
|
|
3538
|
+
ownerId,
|
|
3539
|
+
resourceId: thread.resourceId,
|
|
3540
|
+
threadId: thread.id,
|
|
3541
|
+
modeId: mode.id,
|
|
3542
|
+
modelId,
|
|
3543
|
+
origin: "top-level",
|
|
3544
|
+
createdAt: thread.createdAt,
|
|
3545
|
+
lastActivityAt: thread.updatedAt
|
|
3546
|
+
});
|
|
3547
|
+
})
|
|
3548
|
+
);
|
|
3549
|
+
const harnessV1 = new v1.Harness({
|
|
3550
|
+
ownerId,
|
|
3551
|
+
agents: { [CODE_AGENT_ID]: codeAgent },
|
|
3353
3552
|
memory,
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3553
|
+
modes: modesV1,
|
|
3554
|
+
defaultModeId,
|
|
3555
|
+
storage: harnessStorage
|
|
3556
|
+
});
|
|
3557
|
+
const typedStateSchema = stateSchema;
|
|
3558
|
+
const harness = new HarnessCompat(
|
|
3559
|
+
{
|
|
3560
|
+
id: "mastra-code",
|
|
3561
|
+
resourceId: project.resourceId,
|
|
3562
|
+
storage: storage$1,
|
|
3563
|
+
observability: observability$1,
|
|
3564
|
+
memory,
|
|
3565
|
+
pubsub: signalsPubSub,
|
|
3566
|
+
stateSchema: typedStateSchema,
|
|
3567
|
+
subagents,
|
|
3568
|
+
resolveModel: (modelId) => chunkDJBUYADN_cjs.resolveModel(modelId),
|
|
3569
|
+
toolCategoryResolver: chunkAWYGW5ZV_cjs.getToolCategory,
|
|
3570
|
+
initialState: {
|
|
3571
|
+
projectPath: project.rootPath,
|
|
3572
|
+
projectName: project.name,
|
|
3573
|
+
gitBranch: project.gitBranch,
|
|
3574
|
+
yolo: true,
|
|
3575
|
+
...globalInitialState,
|
|
3576
|
+
...config?.initialState,
|
|
3577
|
+
// configDir must always win over initialState spreads to stay in sync
|
|
3578
|
+
// with MCP/hooks/storage which were already initialized with this value.
|
|
3579
|
+
configDir
|
|
3580
|
+
},
|
|
3581
|
+
workspace: config?.workspace ?? getDynamicWorkspace,
|
|
3582
|
+
browser: config?.browser,
|
|
3583
|
+
modes,
|
|
3584
|
+
heartbeatHandlers: config?.heartbeatHandlers ?? defaultHeartbeatHandlers,
|
|
3585
|
+
modelAuthChecker: (provider) => {
|
|
3586
|
+
const gatewayKey = authStorage.getStoredApiKey(chunkDJBUYADN_cjs.MEMORY_GATEWAY_PROVIDER) ?? process.env["MASTRA_GATEWAY_API_KEY"];
|
|
3587
|
+
if (gatewayKey) {
|
|
3588
|
+
const providerConfig = gatewayRegistry.getProviders()[provider];
|
|
3589
|
+
if (providerConfig?.gateway === "mastra") return true;
|
|
3590
|
+
}
|
|
3591
|
+
const oauthId = PROVIDER_TO_OAUTH_ID[provider];
|
|
3592
|
+
if (oauthId && authStorage.isLoggedIn(oauthId)) {
|
|
3390
3593
|
return true;
|
|
3391
3594
|
}
|
|
3392
|
-
|
|
3393
|
-
if (provider === "openai") {
|
|
3394
|
-
const cred = authStorage.get("openai-codex");
|
|
3395
|
-
if (cred?.type === "api_key" && cred.key.trim().length > 0) {
|
|
3595
|
+
if (authStorage.hasStoredApiKey(provider)) {
|
|
3396
3596
|
return true;
|
|
3397
3597
|
}
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3598
|
+
if (provider === "anthropic") {
|
|
3599
|
+
const cred = authStorage.get("anthropic");
|
|
3600
|
+
if (cred?.type === "api_key" && cred.key.trim().length > 0) {
|
|
3601
|
+
return true;
|
|
3602
|
+
}
|
|
3603
|
+
}
|
|
3604
|
+
if (provider === "openai") {
|
|
3605
|
+
const cred = authStorage.get("openai-codex");
|
|
3606
|
+
if (cred?.type === "api_key" && cred.key.trim().length > 0) {
|
|
3607
|
+
return true;
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
const customProvider = chunkDJBUYADN_cjs.loadSettings().customProviders.find((entry) => {
|
|
3611
|
+
return provider === chunkDJBUYADN_cjs.getCustomProviderId(entry.name);
|
|
3612
|
+
});
|
|
3613
|
+
if (customProvider) {
|
|
3614
|
+
return true;
|
|
3615
|
+
}
|
|
3616
|
+
return void 0;
|
|
3617
|
+
},
|
|
3618
|
+
modelUseCountProvider: () => chunkDJBUYADN_cjs.loadSettings().modelUseCounts,
|
|
3619
|
+
modelUseCountTracker: (modelId) => {
|
|
3620
|
+
try {
|
|
3621
|
+
const settings = chunkDJBUYADN_cjs.loadSettings();
|
|
3622
|
+
settings.modelUseCounts[modelId] = (settings.modelUseCounts[modelId] ?? 0) + 1;
|
|
3623
|
+
chunkDJBUYADN_cjs.saveSettings(settings);
|
|
3624
|
+
} catch (error) {
|
|
3625
|
+
console.error("Failed to persist model usage count", error);
|
|
3626
|
+
}
|
|
3627
|
+
},
|
|
3628
|
+
customModelCatalogProvider: async () => {
|
|
3410
3629
|
const settings = chunkDJBUYADN_cjs.loadSettings();
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
customModels.push({
|
|
3424
|
-
id: chunkDJBUYADN_cjs.toCustomProviderModelId(provider.name, modelName),
|
|
3425
|
-
provider: providerId,
|
|
3426
|
-
modelName,
|
|
3427
|
-
hasApiKey: true,
|
|
3428
|
-
apiKeyEnvVar: void 0
|
|
3429
|
-
});
|
|
3630
|
+
const customModels = [];
|
|
3631
|
+
for (const provider of settings.customProviders) {
|
|
3632
|
+
const providerId = chunkDJBUYADN_cjs.getCustomProviderId(provider.name);
|
|
3633
|
+
for (const modelName of provider.models) {
|
|
3634
|
+
customModels.push({
|
|
3635
|
+
id: chunkDJBUYADN_cjs.toCustomProviderModelId(provider.name, modelName),
|
|
3636
|
+
provider: providerId,
|
|
3637
|
+
modelName,
|
|
3638
|
+
hasApiKey: true,
|
|
3639
|
+
apiKeyEnvVar: void 0
|
|
3640
|
+
});
|
|
3641
|
+
}
|
|
3430
3642
|
}
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
}
|
|
3643
|
+
try {
|
|
3644
|
+
const copilotModels = await chunkDJBUYADN_cjs.getCopilotModelCatalog({ authStorage });
|
|
3645
|
+
for (const m of copilotModels) {
|
|
3646
|
+
customModels.push({
|
|
3647
|
+
id: `github-copilot/${m.id}`,
|
|
3648
|
+
provider: "github-copilot",
|
|
3649
|
+
modelName: m.id,
|
|
3650
|
+
hasApiKey: true,
|
|
3651
|
+
apiKeyEnvVar: void 0
|
|
3652
|
+
});
|
|
3653
|
+
}
|
|
3654
|
+
} catch (error) {
|
|
3655
|
+
console.warn("Failed to load GitHub Copilot model catalog:", error);
|
|
3442
3656
|
}
|
|
3443
|
-
|
|
3444
|
-
|
|
3657
|
+
return customModels;
|
|
3658
|
+
},
|
|
3659
|
+
threadLock: crossProcessPubSub ? void 0 : {
|
|
3660
|
+
acquire: chunkDJBUYADN_cjs.acquireThreadLock,
|
|
3661
|
+
release: chunkDJBUYADN_cjs.releaseThreadLock
|
|
3445
3662
|
}
|
|
3446
|
-
return customModels;
|
|
3447
3663
|
},
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
release: chunkDJBUYADN_cjs.releaseThreadLock
|
|
3451
|
-
}
|
|
3452
|
-
});
|
|
3664
|
+
harnessV1
|
|
3665
|
+
);
|
|
3453
3666
|
if (hookManager) {
|
|
3454
|
-
harness
|
|
3667
|
+
harness.subscribe((event) => {
|
|
3455
3668
|
if (event.type === "thread_changed") {
|
|
3456
3669
|
hookManager.setSessionId(event.threadId);
|
|
3457
3670
|
} else if (event.type === "thread_created") {
|
|
@@ -3459,12 +3672,12 @@ async function createMastraCode(config) {
|
|
|
3459
3672
|
}
|
|
3460
3673
|
});
|
|
3461
3674
|
}
|
|
3462
|
-
const omThreadStateHarness = harness
|
|
3675
|
+
const omThreadStateHarness = harness;
|
|
3463
3676
|
attachOMThreadStatePersistence(omThreadStateHarness);
|
|
3464
3677
|
await restoreOMThreadStateForCurrentThread(omThreadStateHarness).catch(() => {
|
|
3465
3678
|
});
|
|
3466
3679
|
return {
|
|
3467
|
-
harness
|
|
3680
|
+
harness,
|
|
3468
3681
|
mcpManager,
|
|
3469
3682
|
hookManager,
|
|
3470
3683
|
signalsPubSub,
|
|
@@ -3480,5 +3693,5 @@ async function createMastraCode(config) {
|
|
|
3480
3693
|
|
|
3481
3694
|
exports.createAuthStorage = createAuthStorage;
|
|
3482
3695
|
exports.createMastraCode = createMastraCode;
|
|
3483
|
-
//# sourceMappingURL=chunk-
|
|
3484
|
-
//# sourceMappingURL=chunk-
|
|
3696
|
+
//# sourceMappingURL=chunk-A4TDK7QP.cjs.map
|
|
3697
|
+
//# sourceMappingURL=chunk-A4TDK7QP.cjs.map
|